Commit 8a3f0e8
unit-test-impl-leader
test(unit): F-Stack lib/ unit-test framework — Stage-2 implementation
Stage-2 of the F-Stack unit-test framework project: spec-to-code phase that
turns the 6 spec docs landed in the previous commit into a fully functional
CMocka-based test harness covering 5 of the 11 host-side glue files declared
in lib/Makefile FF_HOST_SRCS.
Stage-1 (spec phase, commit b488899) covered: 6 spec docs + plan.
This Stage-2 commit covers the executable test harness:
tests/
└── unit/
├── Makefile 130-line GNU make, no cmake/meson
├── common/ 4 files: ff_log_stub.{c,h} + rte_stub.{c,h}
├── fixtures/ 5 .ini files for ff_config end-to-end tests
├── test_hello.c 2-TC sanity (CMocka + pkg-config)
├── test_ff_ini_parser.c 18 TC (P0 #1) — pure-stdlib parser
├── test_ff_log.c 13 TC (P0 #2) — 4 rte_log API wraps
├── test_ff_host_interface.c 8 TC (P1 #1) — libcrypto for RAND_bytes
├── test_ff_epoll.c 7 TC (P1 #2) — ff_kqueue/ff_kevent stubs
└── test_ff_config.c 11 TC (P1 #3) — end-to-end ff_load_config
Test results (final sanity, make clean + make test, on TencentOS 4.4):
==> test_hello : 2/2 PASS
==> test_ff_ini_parser : 17/17 PASS, 1 SKIP (FU-S2-NULLFILE)
==> test_ff_log : 13/13 PASS
==> test_ff_host_interface : 8/8 PASS
==> test_ff_epoll : 7/7 PASS
==> test_ff_config : 11/11 PASS
----
TOTAL: 58 PASS + 1 SKIP / 6 binaries / runtime ~0.4s
(FR-U-6 threshold >=25, NFR-U-5 budget < 30s — both satisfied)
Spec-vs-code corrections (5 found, all per DP-U-12 "代码为准"):
1. ff_log_open_set is `void` argument (header), not (dir, proc_id) (spec text)
2. proc_id field lives in ff_global_cfg.dpdk.proc_id, not log.proc_id
3. ff_host_interface.c rte_malloc/rte_free are commented out (uses glibc
malloc/free directly); spec 02 §4.2 mock matrix updated
4. ini_parse_file(NULL, ...) genuinely SIGSEGVs in glibc 2.x — TC marked
skip() with FU-S2-NULLFILE follow-up; lib/ not modified per DP-U-11
5. ff_get_current_time impl signature uses time_t* whereas header declares
int64_t* (works on x86_64 glibc; FU-S2-PORT noted)
Build pipeline highlights:
- Independent of lib/Makefile (NFR-U-6) — compiles lib/*.c into
tests/unit/lib_objs/ with our own CFLAGS, never invokes lib/ build rules
- Does NOT link libfstack.a (R-U-8) — avoids pulling in the ~16k-line
FreeBSD-kernel subset (KERN_SRCS) that would explode in compile errors
- Per-test --wrap= flags isolate which rte_* APIs each binary intercepts
- BASE_WRAPS = {rte_exit, rte_panic} -> mock_assert via common/rte_stub.c,
so a regression that calls a fatal rte_* path becomes a cmocka FAIL
rather than a SIGABRT killing the test harness (R-U-13)
- make clean uses /data/workspace/rm_tmp_file.sh wrapper exclusively
(NFR-U-7); zero direct rm/kill/chmod throughout the entire tree
Spec-driven sub-agent harness flow (Phase 1..6):
Phase 1 Leader writes Stage-2 plan.md (290 lines, local-only)
Phase 2 skeleton-builder lands Makefile + 4 stubs + hello-world
-> G6 build PASS (test_hello 2/2)
Phase 3 coder-p0-ini + coder-p0-log
-> G7 P0 PASS (30 PASS + 1 SKIP)
Phase 4 coder-p1-hif + coder-p1-epl + coder-p1-cfg
-> G9 P1 PASS (26/26)
Phase 5 reviewer + gate-keeper (12 cross-checks 12/12; 4-axis all A)
-> G_FINAL PASS (BOUNCE 0/4)
Phase 6 README + backup + this commit
Stage-2 review report at:
docs/unit_test_spec/zh_cn/99-stage2-review.md
Stage-1 plan and Stage-2 plan are local-only via .gitignore line 47
(plan.md), consistent with freebsd_13_to_15 / dpdk_23_24 conventions.
A mirror copy of all 18 deliverables lives in
.spec-backup/unit-test-impl/
which is gitignored (.spec-backup/) but kept for re-entry.
Files NOT staged (intentional):
- plan.md : .gitignore:47 plan.md is local-only
- plan-stage1-spec.md : same .gitignore plan*.md rule
(Stage-1 plan retained locally)
- .spec-backup/unit-test-impl/ : .gitignore .spec-backup/
- tests/unit/{lib_objs/, *.o, test_*}: build artifacts (just-added 9
.gitignore lines for tests/)
- config.ini local mods : orthogonal, user decides
- dpdk.bak-23.11.5/ : DPDK upgrade rollback baseline
- config.test-dpdk24-multi.ini : DPDK upgrade transient test config
Follow-up IDs (per Stage-2 plan §10 + 99-stage2-review.md §6):
FU-S2-NULLFILE Re-enable test_ini_parse_file_null after lib/ NULL-guard
FU-S2-VLAN-CFG Document vlan_cfg_handler vlan_filter prerequisite in spec
FU-S2-1 valgrind into `make check`
FU-S2-2 FreeBSD 13/15 compatibility (Stage-3)
FU-S2-3 3 Nice-to-Have items from spec 99 §3
FU-S2-PORT ff_get_current_time time_t/int64_t signature alignment
FU-S2-PROC-ID silence "invalid proc_id:-1" warning during tests
FU-U-4 P2 follow-up tests (5 files)
FU-U-5 CI integration (GitHub Actions / internal CI)
FU-U-6 Coverage tooling (lcov/gcovr -> threshold gating)
FU-U-7 English translation of 6 spec docs (post audit)1 parent b488899 commit 8a3f0e8
19 files changed
Lines changed: 2362 additions & 0 deletions
File tree
- docs/unit_test_spec/zh_cn
- tests
- unit
- common
- fixtures
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
0 commit comments