fix(main): 补齐 SIGINT/SIGTERM 处理,网页模式可优雅退出;新增覆盖率脚本与 A8 验收
- main.c 注册信号处理(异步信号安全,仅置停止标志):Ctrl+C/kill 后主循环正常收尾, 配置/设备表/日志落盘,gcov 数据也能写出。此前 SIGINT 走默认动作直接终止进程 (退出码 -2),"Ctrl+C 退出"的提示与事实不符,优雅停机路径从未被执行 - tools/coverage.sh:coverage 预设 → 跑 CTest → 回放/菜单/网页三条路径 → gcov 逐文件汇总 (本机无 gcovr/lcov;GCC14 的 gcov 期望 <名>.gcno 而 CMake 产出 <名>.c.gcno,脚本用软链兼容) - scripts/acceptance.sh 增补 A8(优雅退出 + 三份数据落盘),验收 21 项全通过 - 覆盖率:45.6% → 63.7%(网页层从 0% 到 55~95%,menu.c 仍低,待交互测试补齐)
This commit is contained in:
1 parent
582b7d19bf
commit
09bbe23697
9 files changed
+2165
-1
No files matched your search
+17
@@ -21,6 +21,7 @@
|
||||
#include "shs/num_utils.h"
|
||||
#include "shs/string_utils.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -39,6 +40,18 @@
|
||||
* --bind 与 --selftest 在冻结的 AppOptions(app.h)里没有对应字段,
|
||||
* 因此用文件作用域静态变量保存,只供本文件的 main() 使用(项目六 静态变量)。
|
||||
*/
|
||||
/**
|
||||
* @brief 信号处理:Ctrl+C / kill 只置停止标志,由主循环优雅退出
|
||||
*
|
||||
* 教材对应:项目十 整体测试与调试——异常中止路径也要保证数据落盘。
|
||||
* 说明:处理函数里只调用异步信号安全的 app_request_stop(),不做 IO。
|
||||
*/
|
||||
static void on_stop_signal(int signo)
|
||||
{
|
||||
(void)signo;
|
||||
app_request_stop();
|
||||
}
|
||||
|
||||
static char s_bind_addr[24]; /**< 与 SystemConfig.bind_addr 同容量 */
|
||||
static bool s_selftest_only = false;
|
||||
|
||||
@@ -231,6 +244,10 @@ static int run_selftest_only(SmartHomeSystem *sys)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* 注册 Ctrl+C / SIGTERM:中断时优雅退出(保存配置与设备表、关闭监听) */
|
||||
(void)signal(SIGINT, on_stop_signal);
|
||||
(void)signal(SIGTERM, on_stop_signal);
|
||||
|
||||
AppOptions opts;
|
||||
SmartHomeSystem *sys;
|
||||
shs_err_t err;
|
||||
|
||||
Reference in new issue
Block a user