#ifndef TEST_UTIL_H #define TEST_UTIL_H // Shared by the host tests: crash reporting, the guard page, and pcap reading and writing. #include #include // What the test is doing right now, printed if it crashes. printf-style. void tu_set_context(const char *fmt, ...); const char *tu_context(void); // Also print these bytes as hex if it crashes (the fuzzer's current input). NULL to clear. void tu_set_crash_input(const uint8_t *bytes, const int *len); void tu_install_crash_handler(void); // One read-write page followed by one no-access page. void tu_guard_init(void); // A buffer of exactly `len` bytes (at most one page) whose end touches the no-access page. uint8_t *tu_guard_buf(int len); // Copy of `frame` whose last byte is the last readable one: reading past it crashes. const uint8_t *tu_guarded(const uint8_t *frame, int len); // Calls `fn` for every record of a pcap file, with its 802.11 frame. Linktype 127 (radiotap, // what its-g5-receiver-firmware records) has the radiotap header removed; linktype 105 is passed // as is. The frame is otherwise exactly as captured, including the 8 bytes the ESP32-C5's // promiscuous RX appends - which is what obu-firmware's callback receives through the same API. // `index` counts every record, including ones skipped for a malformed radiotap header. Returns // the number of records (0 for an empty file), or -1 if the file can't be read or isn't a pcap // of those linktypes. typedef void (*tu_frame_fn)(const uint8_t *frame, int len, int index, void *ctx); int tu_pcap_foreach(const char *path, tu_frame_fn fn, void *ctx); // Writes frames to a pcap, linktype 105 (bare 802.11). bool tu_pcap_open(const char *path); void tu_pcap_add(const uint8_t *frame, int len); void tu_pcap_close(void); #endif