Testing
Comprehensive test suite verifies correctness, memory safety, endianness, pointer sizes, and round-trip integration.
Host Tests
Tests that run on the build machine (native compilation).
Test Harness
Plain C: No frameworks, custom macros (TEST_ASSERT_EQ, etc.).
Guarded Buffers: Stack-allocated with canaries for overflow detection.
Zero Alloc Check: Static scan forbids malloc/free in libraries.
Mock Device/Memory: Client/host integration without real hardware.
Test Categories
Client Builder/Parser: RIFF construction/parsing, buffer boundaries.
Host Parser/Response: CALL/RETN/ERRO handling.
Round-Trip: Full client-host via mock memory (all syscalls).
Endianness/Pointer Sizes: Manual vectors for cross-arch.
Errors: Protocol/host errno propagation.
Memory Safety: Canary checks, no stomps.
Run Host Tests
cmake -B build
cmake --build build
ctest --test-dir build -V
On-Target Tests
Cross-compiled tests run on emulated ZBC platforms via MAME.
Test Suite
test/target/zbc_target_test.c exercises all 23 semihosting syscalls:
File I/O: OPEN, CLOSE, READ, WRITE, SEEK, FLEN, REMOVE, RENAME, TMPNAM
Console: WRITEC, WRITE0, READC
Time: CLOCK, TIME, ELAPSED, TICKFREQ
System: ISERROR, ISTTY, ERRNO, GET_CMDLINE, HEAPINFO, SYSTEM
Exit: EXIT (used to report test results)
Supported Platforms
Platform |
Compiler |
MAME Machine |
|---|---|---|
i386 |
gcc -m32 (gcc-multilib) |
zbci386 |
m6502 |
mos-clang (llvm-mos) |
zbcm6502 |
Building On-Target Tests
cmake -B build -DZBC_TARGET_TESTS=ON
cmake --build build
ctest --test-dir build -L target
Requirements:
MAME: With ZBC machine support (set
MAME_PATHif not in PATH)i386:
apt install gcc-multilibor equivalentm6502: Install llvm-mos, set
LLVM_MOS_PATH
Target Test Harness
test/target/zbc_target_harness.h provides bare-metal test macros:
TARGET_INIT(): Initialize client and test stateTARGET_PRINT(msg): Output via SH_SYS_WRITE0TARGET_ASSERT(cond): Assert conditionTARGET_ASSERT_EQ(a, b): Assert equality with hex outputTARGET_BEGIN_TEST(name)/TARGET_END_TEST(): Test boundariesTARGET_EXIT(): Exit with pass/fail status code
Fuzzing
RIFF Parser: libFuzzer + ClusterFuzzLite (fuzz/fuzz_riff_parser.c).
Corpus: gen_malformed_corpus.py creates malformed RIFF inputs.
cmake -B build-fuzz -DENABLE_FUZZING=ON -DCMAKE_C_COMPILER=clang
cmake --build build-fuzz
./build-fuzz/fuzz/fuzz_riff_parser corpus/
Sanitizers
CI runs ASan/UBSan on Linux/macOS/Windows:
cmake -B build-san -DCMAKE_BUILD_TYPE=Debug
cmake --build build-san
Coverage
Target: >90% lines, >80% branches.