Files
smart-home-control-system/scripts/acceptance.sh
T
sambu 8e7fc5015a docs(S2): 冻结接口并补齐概要设计文档与工程脚本
- docs/01 需求规格说明书:FR-01~FR-20 + NFR-01~NFR-10
- docs/02 概要设计:分层架构、模块清单、关键决策(含不引入数据库的理由)
- include/shs/ 17 个头文件接口冻结(tools/header_check.sh 全通过)
- README:快速开始、命令参考、网页接口一览、知识点索引
- scripts:build/test/run_cli/run_web/demo.txt/acceptance.sh
- .idea 运行配置 5 个(CLI/网页/回放/测试/详细测试)
2026-09-14 19:37:22 +08:00

45 lines
2.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 验收脚本:一键跑通 A1~A7 验收项并打印结论
# 用法:bash scripts/acceptance.sh
set -uo pipefail
cd "$(dirname "$0")/.."
PASS=0; FAIL=0
ok() { printf ' [通过] %s\n' "$1"; PASS=$((PASS+1)); }
bad() { printf ' [失败] %s\n' "$1"; FAIL=$((FAIL+1)); }
echo "== A1 debug 预设构建(告警即错误) =="
if cmake --preset debug >/dev/null && cmake --build --preset debug >/tmp/shs_build.log 2>&1; then
if grep -qE 'warning:' /tmp/shs_build.log; then bad "构建出现告警(见 /tmp/shs_build.log)"; else ok "零告警构建成功"; fi
else bad "构建失败(见 /tmp/shs_build.log)"; fi
echo "== A2 release 预设构建 =="
if cmake --preset release >/dev/null && cmake --build --preset release >/tmp/shs_build_rel.log 2>&1; then ok "release 构建成功"; else bad "release 构建失败"; fi
echo "== A3 头文件接口检查 =="
if bash tools/header_check.sh >/tmp/shs_headers.log 2>&1; then ok "全部头文件可独立编译"; else bad "头文件检查失败"; fi
echo "== A4 CTest 全量测试 =="
if ctest --preset debug --output-on-failure >/tmp/shs_ctest.log 2>&1; then
ok "$(grep -cE 'Test #' /tmp/shs_ctest.log || echo 0) 个测试全部通过"
else bad "测试未全部通过(见 /tmp/shs_ctest.log)"; fi
echo "== A5 ASan/UBSan 预设 =="
if cmake --preset asan >/dev/null && cmake --build --preset asan >/tmp/shs_asan_build.log 2>&1 && ctest --preset asan >/tmp/shs_asan.log 2>&1; then
ok "ASan/UBSan 下测试通过"
else bad "ASan/UBSan 检查失败"; fi
echo "== A6 回放演示 =="
if ./build/debug/smart_home --replay scripts/demo.txt --data /tmp/shs_demo_data >/tmp/shs_demo.log 2>&1; then
ok "演示脚本执行完成(输出 /tmp/shs_demo.log)"
else bad "演示脚本执行失败"; fi
echo "== A7 网页接口冒烟 =="
./build/debug/smart_home --web --port 18080 --data /tmp/shs_web_data >/tmp/shs_web.log 2>&1 &
WEB_PID=$!; sleep 1
if curl -fsS http://127.0.0.1:18080/api/devices >/tmp/shs_web_api.json; then ok "GET /api/devices 返回数据"; else bad "网页接口无响应"; fi
kill $WEB_PID 2>/dev/null || true
echo
echo "验收汇总:通过 $PASS 项,失败 $FAIL 项"
[ "$FAIL" -eq 0 ]