myxce/src/controller/testsuite/test_persist_schema.c
Rongsong Shen a81f2a249c fix(controller-tests): make Unity test-file attribution and counters consistent suite-wide
Only 21 of 86 test_*.c group functions called their own nested
UNITY_BEGIN()/UNITY_END(). Each nested call reset Unity's global
NumberOfTests/TestFailures counters, so controller_test.c's final
`return UNITY_END();` -- the value meson test actually gates on --
only ever reflected whichever small window of tests ran since the
LAST nested reset, silently discarding pass/fail evidence for
everything before it (measured: 16 of 972 total tests in one run).
The same nested-BEGIN calls also caused PASS/FAIL banners to show
the wrong source file for tests in files that don't reset it
themselves (Unity.TestFile just carries over from whichever group
last called UNITY_BEGIN()).

Fix: replace every nested UNITY_BEGIN() with UnitySetTestFile(__FILE__)
(sets file attribution only, no counter reset) and drop the matching
UNITY_END(); add the same UnitySetTestFile(__FILE__) as the first
statement to the other group functions that had neither. The 2
genuinely standalone binaries (test_job_array_sched_push.c,
test_job_array_apiserver_push.c -- each has its own int main(), not
registered via controller_test.c's TEST() macro) are untouched.

Verified: single consolidated summary now reads
"972 Tests 0 Failures 0 Ignored OK", exactly matching the
ground-truth RUN_TEST call-site count across all 83 registered
group files (976 total minus 4 belonging to the 2 standalone
binaries). Every PASS/FAIL banner now names its own true source
file. Full xce-build.sh all regression pass clean (Ok: 9, Fail: 0).

No production code touched -- test-harness plumbing only.
2026-07-17 14:49:12 +00:00

111 lines
4.1 KiB
C

/* Test that generated Cap'n Proto types for persistence exist and have correct
* fields. This is a compile-time / linkage test — the real assertion is that
* ninja succeeds with the new schema additions. */
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unity/unity.h>
#include "controller.capnp.h"
/* ------------------------------------------------------------------ */
/* PersistConfig */
/* ------------------------------------------------------------------ */
static void test_persist_config_schema_fields(void)
{
/* Verify struct is defined and has the expected word/byte counts.
* c-capnproto generates <Struct>_struct_bytes_count constants. */
(void)PersistConfig_struct_bytes_count;
printf("test_persist_config_schema_fields: PASS\n");
}
/* ------------------------------------------------------------------ */
/* SnapshotHeader */
/* ------------------------------------------------------------------ */
static void test_snapshot_header_schema_fields(void)
{
(void)SnapshotHeader_struct_bytes_count;
printf("test_snapshot_header_schema_fields: PASS\n");
}
/* ------------------------------------------------------------------ */
/* WALEntry */
/* ------------------------------------------------------------------ */
static void test_wal_entry_schema_fields(void)
{
/* Schema struct is named ReplEnvelope to avoid collision with the
* on-disk wal_entry_hdr_t C type and the WALEntry_ generator symbol. */
(void)ReplEnvelope_struct_bytes_count;
printf("test_wal_entry_schema_fields: PASS\n");
}
/* ------------------------------------------------------------------ */
/* Replication opcodes */
/* ------------------------------------------------------------------ */
static void test_repl_opcodes_exist(void)
{
/* These enum values must be present in the generated header. */
int repl_entry = OPCode_replEntry;
int repl_ack = OPCode_replAck;
int redirect_op = OPCode_redirect;
int heartbeat_op = OPCode_heartbeat;
int stepping = OPCode_steppingDown;
int repl_snap = OPCode_replSnapshot;
int catchup_done = OPCode_replCatchUpDone;
/* All values must be > 21 (highest existing opcode clrpreason=21). */
TEST_ASSERT_TRUE(repl_entry > 21);
TEST_ASSERT_TRUE(repl_ack > 21);
TEST_ASSERT_TRUE(redirect_op > 21);
TEST_ASSERT_TRUE(heartbeat_op > 21);
TEST_ASSERT_TRUE(stepping > 21);
TEST_ASSERT_TRUE(repl_snap > 21);
TEST_ASSERT_TRUE(catchup_done > 21);
printf("test_repl_opcodes_exist: PASS\n");
}
/* ------------------------------------------------------------------ */
/* Job.transientSince and Worker.deadSince fields */
/* ------------------------------------------------------------------ */
static void test_job_transient_since_field(void)
{
/* c-capnproto preserves camelCase field names from the schema directly. */
struct Job j;
memset(&j, 0, sizeof(j));
j.transientSince = 12345ULL;
TEST_ASSERT_EQUAL_UINT64(12345ULL, j.transientSince);
printf("test_job_transient_since_field: PASS\n");
}
static void test_worker_dead_since_field(void)
{
struct Worker w;
memset(&w, 0, sizeof(w));
w.deadSince = 99999ULL;
TEST_ASSERT_EQUAL_UINT64(99999ULL, w.deadSince);
printf("test_worker_dead_since_field: PASS\n");
}
/* ------------------------------------------------------------------ */
/* Suite entry point (called from controller_test.c) */
/* ------------------------------------------------------------------ */
void test_persist_schema(void)
{
UnitySetTestFile(__FILE__);
printf("\n>> persist Cap'n Proto schema test\n\n");
RUN_TEST(test_persist_config_schema_fields);
RUN_TEST(test_snapshot_header_schema_fields);
RUN_TEST(test_wal_entry_schema_fields);
RUN_TEST(test_repl_opcodes_exist);
RUN_TEST(test_job_transient_since_field);
RUN_TEST(test_worker_dead_since_field);
}