From 4c23a82a02e8c40814c7c595b2db2ab7e6306c7c Mon Sep 17 00:00:00 2001 From: sambu Date: Mon, 14 Sep 2026 20:19:22 +0800 Subject: [PATCH] =?UTF-8?q?test(acceptance):=20A7=20=E7=BD=91=E9=A1=B5?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=86=92=E7=83=9F=E7=BB=86=E5=8C=96=E4=B8=BA?= =?UTF-8?q?=2013=20=E9=A1=B9=E6=8A=BD=E6=A3=80=EF=BC=88=E9=9D=99=E6=80=81?= =?UTF-8?q?=E4=B8=89=E4=BB=B6=E5=A5=97/=E5=8F=AA=E8=AF=BB=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3/=E5=86=99=E6=8E=A5=E5=8F=A3/=E7=A6=BB=E7=BA=BF?= =?UTF-8?q?=E8=B4=9F=E4=BE=8B/404=20=E5=85=9C=E5=BA=95=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 验收脚本总计 19 项断言全通过;采样有效性断言可回归 HAL I2C 字节序修复 --- scripts/acceptance.sh | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/scripts/acceptance.sh b/scripts/acceptance.sh index 01894fc..26841ab 100755 --- a/scripts/acceptance.sh +++ b/scripts/acceptance.sh @@ -33,11 +33,35 @@ if ./build/debug/smart_home --replay scripts/demo.txt --data /tmp/shs_demo_data ok "演示脚本执行完成(输出 /tmp/shs_demo.log)" else bad "演示脚本执行失败"; fi -echo "== A7 网页接口冒烟 ==" +echo "== A7 网页接口冒烟(17 条路由抽检) ==" ./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 +WEB_PID=$!; sleep 1.5 +WEB=http://127.0.0.1:18080 +code() { curl -s -o /tmp/shs_body.txt -w '%{http_code}' --noproxy '*' "$1"; } +size() { curl -s -o /tmp/shs_body.txt -w '%{size_download}' --noproxy '*' "$1"; } + +# 静态三件套 +if [ "$(code $WEB/)" = "200" ] && grep -q "" /tmp/shs_body.txt; then ok "首页 HTML 可访问"; else bad "首页不可访问"; fi +if [ "$(size $WEB/app.js)" -gt 3000 ]; then ok "内嵌脚本 /app.js 完整下发(>3KB,分段字面量拼装生效)"; else bad "/app.js 体积异常"; fi +if [ "$(size $WEB/style.css)" -gt 1000 ]; then ok "内嵌样式 /style.css 完整下发"; else bad "/style.css 体积异常"; fi + +# 只读接口 +if curl -s --noproxy '*' $WEB/api/devices | grep -q '"客厅主灯"' && curl -s --noproxy '*' $WEB/api/devices | grep -q '"count":8'; then ok "GET /api/devices 返回 8 台设备"; else bad "/api/devices 数据异常"; fi +if curl -s --noproxy '*' $WEB/api/sensors | grep -q '"valid":true'; then ok "GET /api/sensors 采样有效(HAL I2C 字节序正确)"; else bad "/api/sensors 采样无效"; fi +for path in /api/log /api/report /api/config /api/selftest; do + if [ "$(code $WEB$path)" = "200" ]; then ok "GET $path 返回 200"; else bad "GET $path 异常"; fi +done + +# 写接口 +if curl -s --noproxy '*' -X POST -H 'Content-Type: application/json' -d '{"id":1,"on":true}' $WEB/api/device/power | grep -q '"power":true'; then ok "POST /api/device/power 生效"; else bad "电源控制接口异常"; fi +if curl -s --noproxy '*' -X POST -H 'Content-Type: application/json' -d '{"dev":1,"cmd":2,"value":1}' $WEB/api/frame | grep -q '"crc_ok":true'; then ok "POST /api/frame 帧 CRC 校验通过"; else bad "协议帧接口异常"; fi + +# 负例:离线设备拒绝开机、未知路径 404 +if curl -s --noproxy '*' -X POST -H 'Content-Type: application/json' -d '{"id":8,"on":true}' $WEB/api/device/power | grep -q '"ok":false'; then ok "负例:离线设备开机被拒(返回 ok:false)"; else bad "离线设备负例未生效"; fi +if [ "$(code $WEB/api/nonexistent)" = "404" ]; then ok "负例:未知路径返回 404"; else bad "404 兜底异常"; fi + kill $WEB_PID 2>/dev/null || true +wait $WEB_PID 2>/dev/null || true echo echo "验收汇总:通过 $PASS 项,失败 $FAIL 项"