Files
MicrOBU/microbu-esp32c5/external/vanetza-idf/ports/esp_idf/tests/check.hpp
T
Ashin Walpola 0e9525162d Keep the colleague's microbu-esp32c5 tree in this repository
obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but
that tree was gitignored, so a clone of this repository could not build the
firmware it ships. It is now committed here as ordinary files in its own
folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP
bridge's signature verification (--trust) used on the bench. Nothing is
fetched from or pushed to the colleague's repository; this repository and
its remotes carry everything. The folder's own .gitignore keeps build output,
downloaded components and private key material out, as it did there; the
committed file set is identical to that repository's tracked files.

The ESP32-C5 is still flashed from obu-firmware/, which only takes
vanetza-idf from microbu-esp32c5/, so the two stay separate folders.
FLASHING.md says how to take a newer version of the colleague's tree (copy
it over the folder, rebuild, test, commit).
2026-09-23 17:46:40 +02:00

41 lines
1.6 KiB
C++

#pragma once
#include <cstdio>
#include <stdexcept>
#include <string>
#ifdef ESP_PLATFORM
#include <esp_heap_caps.h>
#endif
// Shared assertion helper of the port regression: one counter across all test
// translation units, failures throw so the first broken check stops the run.
namespace vidf_test {
inline unsigned checks = 0;
inline const char* section_name = "";
// Names the running test section so a device log shows where an exception came from;
// on the device the free heap is reported alongside (allocation failures surface as
// asn1c RC_FAIL results, indistinguishable from malformed data without this line).
inline void section(const char* name) {
section_name = name;
#ifdef ESP_PLATFORM
std::printf("-- %s (free heap %u, largest block %u)\n", name,
static_cast<unsigned>(heap_caps_get_free_size(MALLOC_CAP_DEFAULT)),
static_cast<unsigned>(heap_caps_get_largest_free_block(MALLOC_CAP_DEFAULT)));
#else
std::printf("-- %s\n", name);
#endif
std::fflush(stdout);
}
inline void check(bool ok, const char* description) {
++checks;
if (!ok) throw std::runtime_error(description);
}
inline std::string hex(const void* data, std::size_t size) {
std::string result;
const char* digits = "0123456789abcdef";
const auto* bytes = static_cast<const unsigned char*>(data);
for (std::size_t i = 0; i < size; ++i) { result += digits[bytes[i] >> 4]; result += digits[bytes[i] & 15]; }
return result;
}
template<class Container> std::string hex(const Container& bytes) { return hex(bytes.data(), bytes.size()); }
}