From 63c262fe2c3f1d26de1e8e45b9fd64207c5579db Mon Sep 17 00:00:00 2001 From: Wanderingss <1624155937@qq.com> Date: Sat, 10 Oct 2026 17:48:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B8=E9=87=8F=E5=B1=82=E5=8D=95=E6=B5=8B?= =?UTF-8?q?=EF=BC=9A=E8=A1=A5=20phasor=5Fzero/init=20=E6=B8=85=E9=9B=B6?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=EF=BC=88L1/L2=20=E5=87=BD=E6=95=B0=E8=A6=86?= =?UTF-8?q?=E7=9B=96=2020/20=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 函数级覆盖审计发现 phasor_zero() 仅被 phasor_init() 间接执行、其效果 无可观测断言(init 同时把 s_ready 清 0,公开 API 看不到清零)。补直接 白盒用例: - TC-PH-030 直接调 phasor_zero,四字段(含 fAm/fAmSQ)全清零 - TC-PH-031/032/033 先把双区写脏,init 后双区全零 + 使用区复位 + 就绪标志清(get -> -2) - TC-PH-034 init 幂等 审计结果:App/algo 三个源共 20 个函数,0 个未覆盖。 相量层单测 57/57 PASSED(原 52)。 --- test/host/phasor/phasor_test.c | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/host/phasor/phasor_test.c b/test/host/phasor/phasor_test.c index f32b028e..0a14e669 100644 --- a/test/host/phasor/phasor_test.c +++ b/test/host/phasor/phasor_test.c @@ -26,6 +26,7 @@ * TC-PH-020 L2-2 实例层:实例数/实例表/未攒满一周波不产出 * TC-PH-021 L2-6 滑动窗:连续滑动 20 拍基波读数恒定 * TC-PH-022 L2-7 双区交换:使用区交替 + get 返回**最后一次** run 的结果(非陈旧) + * TC-PH-030..034 phasor_zero 四字段清零 / phasor_init 双区清零 + 使用区与就绪标志复位 + 幂等 * * 通过:全部 TC PASS(main 返回 0)。 * 入口:int main(void),返回 0=PASS / 1=FAIL(由 run 脚本判读)。 @@ -432,6 +433,45 @@ static void tc_instances(void) { CHECK(ok, "L2-2/L2-6 instance results == phasor_calc() on the same ring window"); } +/* ===================== TC-PH-030..034:phasor_zero / init 清零 ===================== */ + +static void tc_zero(void) { + phasor_t p; + uint8_t i; + int zones_dirty = 0; + + /* 1) 直接白盒:phasor_zero 把四个字段(含 fAm / fAmSQ)全部清零 */ + p.fRe = 1.0f; p.fIm = -2.0f; p.fAm = 3.0f; p.fAmSQ = 4.0f; + phasor_zero(&p); + CHECK((p.fRe == 0.0f) && (p.fIm == 0.0f) && (p.fAm == 0.0f) && (p.fAmSQ == 0.0f), + "TC-PH-030 phasor_zero clears all four fields"); + + /* 2) 经 phasor_init:先把双区写成脏值,init 后必须全零,使用区复位、就绪标志清 */ + for (i = 0u; i < (uint8_t)PHASOR_INST_N; i++) { + s_zone[0][i].fRe = 9.0f; s_zone[0][i].fIm = 9.0f; + s_zone[0][i].fAm = 9.0f; s_zone[0][i].fAmSQ = 9.0f; + s_zone[1][i].fRe = 9.0f; s_zone[1][i].fIm = 9.0f; + s_zone[1][i].fAm = 9.0f; s_zone[1][i].fAmSQ = 9.0f; + } + s_use_zone = 1u; + (void)phasor_init(); + for (i = 0u; i < (uint8_t)PHASOR_INST_N; i++) { + if ((s_zone[0][i].fRe != 0.0f) || (s_zone[0][i].fIm != 0.0f) || + (s_zone[0][i].fAm != 0.0f) || (s_zone[0][i].fAmSQ != 0.0f) || + (s_zone[1][i].fRe != 0.0f) || (s_zone[1][i].fIm != 0.0f) || + (s_zone[1][i].fAm != 0.0f) || (s_zone[1][i].fAmSQ != 0.0f)) { + zones_dirty = 1; + } + } + CHECK(zones_dirty == 0, "TC-PH-031 phasor_init zeroes both result zones"); + CHECK(s_use_zone == 0u, "TC-PH-032 phasor_init resets use zone to 0"); + CHECK(phasor_get(0u, &p) == -2, "TC-PH-033 phasor_init clears ready (get -> -2)"); + + /* 3) 幂等:重复 init 不改变结果 */ + (void)phasor_init(); + CHECK((s_use_zone == 0u) && (phasor_get(0u, &p) == -2), "TC-PH-034 phasor_init is idempotent"); +} + /* ===================== TC-PH-022:L2-7 双区指针原子交换 ===================== */ static void tc_dualzone(void) { @@ -504,6 +544,8 @@ int main(void) { tc_instances(); printf("-- L2-7 dual-zone swap --\n"); tc_dualzone(); + printf("-- L2 zero / init --\n"); + tc_zero(); printf("\n=== Phasor Tests: %d/%d PASSED (failed=%d) ===\n", s_passed, s_total, s_failed);