fix(m52): r1 评审 P2-1 class 缺失 WARN 去刷屏 + 两个 nit(snprintf clamp / 恒真断言)

P2-1(必修):`multi_font: class %s font %s missing, fallback global` 与上一轮修掉的
enabled 行同在 meow_font_reload_multifont() 里、被 main_menu.c:1385 每 2s 调一次;
命中「某个 font.class_* 非空但文件缺失/不可读」时最多 6 行/2s(3 行/s),比 enabled
行凶 6 倍,会让「空转 60s 日志不增长」在 class 缺失形态下失效。
改法:循环内只记「本轮缺失类别位图」,循环外经新纯函数 mf_missing_warn_mask() 做跃迁
判定(缺失集合不变 → 静默;新类别缺失 → 1 条;恢复后再缺失 → 再 1 条)。回退行为不变
(缺失类别照旧回退全局),日志文本/参数不变。另加 _Static_assert 钉住类别数 ≤32(位图宽度)。

nit:wd_log() 的 snprintf 返回值显式 clamp(原「buf≤511+前缀≤23<544」是隐式不变量);
test_wd_fw 的 "scan finds self" 原断言带 `|| np > 0` 恒真、等于没测 → 改为真查表断言
getpid() 在 wd_rg_pid[] 中且 comm 非空、并与 /proc/self/stat 的 pid/ppid 交叉核对。

验证:test_wd_fw 128 pass/0 fail(原 124,+4 来自强化后的自扫断言);
test_mf_logsig 21 pass/0 fail(原 13,+8 为 P2-1 验收:单类缺失 60s@2s 只 1 条、
缺失集合变化再 1 条、恢复后再缺失再 1 条);launcher 宿主测试 ALL PASS;
三处交叉编译 0 warning(watchdog 100,116 B/25f76950、launcherd 902,044 B/75629078、
audiod 68,732 B/ebb9a7ac 未变=bind hunk 未动)。
This commit is contained in:
AskaEth committed 2026-11-12 08:02:22 +08:00
1 parent 166b32d0e5
commit 0d6c56100f
5 files changed
+93 -4

No files matched your search

+21 -2
View File
@@ -436,11 +436,30 @@ static void test_resguard(void)
check("emit warn->crit", wd_rg_should_emit(WD_RG_WARN, WD_RG_CRIT, 0, 0), 1);
check("emit crit->ok (recovery)", wd_rg_should_emit(WD_RG_CRIT, WD_RG_OK, 0, 0), 1);
/* 8) 真机 /proc 冒烟:本进程必须能被扫到,且自身 ppid 合理(Linux 宿主机也适用) */
/* 8) 真机 /proc 冒烟:本进程必须真的被扫进表里(r1 评审 nit:旧断言带 `|| np > 0` 恒真,等于没测) */
{
int np = wd_rg_scan(WD_RG_MAX_PIDS);
check("scan /proc ok", np > 0, 1);
check("scan finds self", wd_rg_name_of(np, getpid())[0] != '?' || np > 0, 1);
int self = getpid(), self_idx = -1;
for (int i = 0; i < np; i++) if (wd_rg_pid[i] == self) { self_idx = i; break; }
check("scan table contains getpid()", self_idx >= 0, 1);
if (self_idx >= 0) {
check("scan self comm non-empty", wd_rg_comm[self_idx][0] != 0, 1);
check("scan self comm not '?'", wd_rg_name_of(np, self)[0] != '?', 1);
/* 本进程的 ppid 必须与 /proc/self/stat 一致(解析链路端到端自证) */
char sbuf[256];
int fd = open("/proc/self/stat", O_RDONLY);
int got = (fd >= 0) ? (int)read(fd, sbuf, sizeof sbuf - 1) : -1;
if (fd >= 0) close(fd);
int pid2 = 0, ppid2 = 0, ok = 0;
char comm2[WD_RG_COMM_LEN];
if (got > 0) {
sbuf[got] = 0;
ok = (wd_rg_parse_stat(sbuf, &pid2, comm2, sizeof comm2, &ppid2) == 0);
}
check("scan self pid matches /proc/self/stat", ok && pid2 == self, 1);
check("scan self ppid matches /proc/self/stat", ok && wd_rg_ppid[self_idx] == ppid2, 1);
}
int tp[WD_RG_TOP_PARENTS], tc[WD_RG_TOP_PARENTS];
int k = wd_rg_top_parents(wd_rg_ppid, np, WD_RG_TOP_PARENTS, tp, tc);
check("scan top parents >=0", k >= 0, 1);