From bdfe6d388bb54e57ca57872974e61a716e265f95 Mon Sep 17 00:00:00 2001 From: kartikey1306 Date: Mon, 9 Nov 2026 16:22:31 +0530 Subject: [PATCH] fix(tests): print the real total in test_boot_log's summary test_boot_log ended with printf("\n%d/%d tests passed\n", tests_passed): two conversions, one argument. The second %d read whatever was in the next argument register, so every run printed "11/ tests passed" (11/-1999466112 on macOS arm64, the same on three runs). The compiler warned about it on every build (-Wformat-insufficient-args) and nothing failed. Count the tests as RUN starts them and print tests_passed/tests_run. Guard the class as well: on GCC and Clang, the unit-test programs registered in tests/CMakeLists.txt now compile with -Werror=format, so a format warning in a test's output fails the build. That includes the non-test sources those programs compile directly (core/keystore.c, stage0/jump_stage1.c, stage0/recovery_entry.c, stage0/watchdog.c and the generated test_production_key.c). The eboot_core, eboot_hal and eboot_stage1 libraries, every firmware/cross build and the fuzz harnesses in tests/fuzz are unchanged. On GCC, -Werror=format also makes -Wformat-overflow and -Wformat-truncation errors in those programs. Fail before / pass after (macOS arm64, Apple clang, Release, tests on): - guard + old test_boot_log.c: build fails at test_boot_log.c:303:19, "more '%' conversions than data arguments" - guard + this fix: build OK, 0 format warnings, summary "11/11 tests passed", ctest 36/36 --- tests/CMakeLists.txt | 14 ++++++++++++++ tests/unit/test_boot_log.c | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 651e778..c757a11 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -327,3 +327,17 @@ foreach(_t IN LISTS _eboot_test_targets) endif() endforeach() +# --- printf format guard --- +# +# A format warning in a unit-test program is an error: test_boot_log once +# printed "11/ tests passed" behind a warning nobody acted on. +# Applies to the unit-test programs in this directory (and the sources they +# compile directly); the libraries, firmware and tests/fuzz are unchanged. +if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") + foreach(_t IN LISTS _eboot_test_targets) + get_target_property(_type ${_t} TYPE) + if(_type STREQUAL "EXECUTABLE") + target_compile_options(${_t} PRIVATE -Werror=format) + endif() + endforeach() +endif() diff --git a/tests/unit/test_boot_log.c b/tests/unit/test_boot_log.c index 0bde90f..c2207b8 100644 --- a/tests/unit/test_boot_log.c +++ b/tests/unit/test_boot_log.c @@ -18,6 +18,7 @@ #include #include +static int tests_run = 0; static int tests_passed = 0; #define ASSERT(condition) \ @@ -32,6 +33,7 @@ static int tests_passed = 0; #define RUN(test) \ do { \ reset_fixture(); \ + tests_run++; \ test(); \ tests_passed++; \ printf("[PASS] %s\n", #test); \ @@ -300,6 +302,6 @@ int main(void) RUN(test_clear_reports_erase_failure); RUN(test_append_does_not_advance_head_when_write_fails); RUN(test_entry_layout_is_stable); - printf("\n%d/%d tests passed\n", tests_passed); + printf("\n%d/%d tests passed\n", tests_passed, tests_run); return 0; }