mirror of
https://github.com/esphome/esphome.git
synced 2026-05-25 02:16:13 +08:00
[api] Fix CI errors in MAC varint unit tests
- Test file: declare proto_debug_end_ locally instead of misusing PROTO_ENCODE_DEBUG_INIT (which expands to a comma+expression for appending to a function call, not a standalone statement). Add NOLINTNEXTLINE on the deterministic mt19937_64 seed so clang-tidy cert-msc32-c stops failing the build (the seed is intentional for reproducible test runs). - socket FILTER_SOURCE_FILES: tolerate non-dict CORE.config['socket'] (e.g. C++ unit-test builds where socket isn't validated as a mapping). Returning [] is safe -- all impl files are guarded by USE_SOCKET_IMPL_* defines so only the selected one contributes code.
This commit is contained in:
@@ -177,7 +177,14 @@ async def to_code(config):
|
||||
|
||||
def FILTER_SOURCE_FILES() -> list[str]:
|
||||
"""Return list of socket implementation files that aren't selected by the user."""
|
||||
impl = CORE.config["socket"][CONF_IMPLEMENTATION]
|
||||
socket_config = CORE.config.get("socket")
|
||||
if not isinstance(socket_config, dict):
|
||||
# Config has not been validated yet (or socket isn't configured as a
|
||||
# mapping for this build, e.g. a C++ unit test build that skips config
|
||||
# validation). Don't filter -- all impl files are guarded by USE_*
|
||||
# defines so only the selected implementation contributes code anyway.
|
||||
return []
|
||||
impl = socket_config[CONF_IMPLEMENTATION]
|
||||
|
||||
# Build list of files to exclude based on selected implementation
|
||||
excluded = []
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <ios>
|
||||
#include <random>
|
||||
|
||||
#include "esphome/components/api/api_buffer.h"
|
||||
@@ -55,7 +56,9 @@ static void verify_mac(uint64_t mac, size_t expected_bytes) {
|
||||
APIBuffer api_buf;
|
||||
api_buf.resize(16);
|
||||
uint8_t *pos = api_buf.data();
|
||||
PROTO_ENCODE_DEBUG_INIT(&api_buf);
|
||||
#ifdef ESPHOME_DEBUG_API
|
||||
uint8_t *proto_debug_end_ = api_buf.data() + api_buf.size();
|
||||
#endif
|
||||
ProtoEncode::encode_varint_raw_48bit(pos PROTO_ENCODE_DEBUG_ARG, mac);
|
||||
size_t new_len = pos - api_buf.data();
|
||||
|
||||
@@ -109,6 +112,7 @@ TEST(ProtoMacVarint, AllOnes) { verify_mac(0xFFFFFFFFFFFFULL, 7); } // F
|
||||
|
||||
// 100 deterministic-random 48-bit MACs to catch regressions across the space.
|
||||
TEST(ProtoMacVarint, RandomSample) {
|
||||
// NOLINTNEXTLINE(cert-msc32-c,cert-msc51-cpp) -- intentional fixed seed for reproducibility.
|
||||
std::mt19937_64 rng(0xC0FFEE);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
uint64_t mac = rng() & 0xFFFFFFFFFFFFULL;
|
||||
|
||||
Reference in New Issue
Block a user