test: clearer BLE scan FAIL; RTT reset; longer UI ACK timeouts

Report missing Smart Guitar MIDI as an explicit FAIL instead of parse noise, reset target when opening RTT sessions, and give ui boot/charge more ACK time for LCD draws.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
yuquanjun 2026-09-14 21:49:37 +08:00
parent 4c6e2122ed
commit cae4eb84a1
5 changed files with 44 additions and 15 deletions

View File

@ -17,7 +17,7 @@ from ..paths import TOOLS_DIR
ROW_RE = re.compile(r"^\[(PASS|FAIL|SKIP|SENT)\s*\]\s*(.+?)(?:\s*\|\s*(.*))?$") ROW_RE = re.compile(r"^\[(PASS|FAIL|SKIP|SENT)\s*\]\s*(.+?)(?:\s*\|\s*(.*))?$")
def _absorb_output(report, suite: str, text: str) -> None: def _absorb_output(report, suite: str, text: str, stderr: str = "") -> None:
n = 0 n = 0
for line in text.splitlines(): for line in text.splitlines():
m = ROW_RE.match(line.strip()) m = ROW_RE.match(line.strip())
@ -25,7 +25,16 @@ def _absorb_output(report, suite: str, text: str) -> None:
report.add(suite, m.group(2), m.group(1), m.group(3) or "") report.add(suite, m.group(2), m.group(1), m.group(3) or "")
n += 1 n += 1
if n == 0: if n == 0:
tail = "\\n".join(text.splitlines()[-5:]) blob = (text or "") + "\n" + (stderr or "")
if "未找到设备" in blob or "扫描 BLE" in blob:
report.add(
suite,
"BLE 扫描连接",
"FAIL",
"未发现 Smart Guitar MIDI确认已开机且蓝牙开勿在软关机态跑 BLE",
)
return
tail = "\\n".join((text or "").splitlines()[-5:])
report.add(suite, "子进程输出解析", "FAIL", f"未找到结果行tail: {tail}") report.add(suite, "子进程输出解析", "FAIL", f"未找到结果行tail: {tail}")
@ -56,6 +65,6 @@ def run(report, ctx) -> None:
if ctx.allow_poweroff: if ctx.allow_poweroff:
cmd.append("--allow-poweroff") cmd.append("--allow-poweroff")
proc = subprocess.run(cmd, capture_output=True, text=True, timeout=600) proc = subprocess.run(cmd, capture_output=True, text=True, timeout=600)
_absorb_output(report, suite, proc.stdout) _absorb_output(report, suite, proc.stdout, proc.stderr or "")
if proc.returncode != 0 and not any(c.suite == suite and c.status == "FAIL" for c in report.cases): if proc.returncode != 0 and not any(c.suite == suite and c.status == "FAIL" for c in report.cases):
report.add(suite, "BLE 协议子进程", "FAIL", f"exit={proc.returncode} {proc.stderr[-300:]}") report.add(suite, "BLE 协议子进程", "FAIL", f"exit={proc.returncode} {proc.stderr[-300:]}")

View File

@ -22,7 +22,7 @@ def run(report, ctx) -> None:
report.add(suite, "BLE smoke", "FAIL", "timeout 180s设备未广播/未配对?)") report.add(suite, "BLE smoke", "FAIL", "timeout 180s设备未广播/未配对?)")
return return
before = len(report.cases) before = len(report.cases)
_absorb_output(report, suite, proc.stdout) _absorb_output(report, suite, proc.stdout, proc.stderr or "")
new = report.cases[before:] new = report.cases[before:]
if not any(c.status == "FAIL" for c in new) and proc.returncode != 0: if not any(c.status == "FAIL" for c in new) and proc.returncode != 0:
report.add(suite, "BLE smoke 退出码", "FAIL", f"exit={proc.returncode} {proc.stderr[-300:]}") report.add(suite, "BLE smoke 退出码", "FAIL", f"exit={proc.returncode} {proc.stderr[-300:]}")

View File

@ -68,9 +68,11 @@ def run(report, ctx) -> None:
else: else:
report.add(SUITE, "TAP 后页面状态", "FAIL", "TAP 后 log status 无响应") report.add(SUITE, "TAP 后页面状态", "FAIL", "TAP 后 log status 无响应")
for cmd, ack, name in (("ui boot", "UI_BOOT_OK", "开机画面绘制"), for cmd, ack, name, to in (
("ui charge", "UI_CHARGE_", "充电画面绘制")): ("ui boot", "UI_BOOT_OK", "开机画面绘制", 5.0),
ok = sess.cmd_ack(cmd, ack, timeout_s=3.0, retries=3) ("ui charge", "UI_CHARGE_", "充电画面绘制", 15.0),
):
ok = sess.cmd_ack(cmd, ack, timeout_s=to, retries=3)
report.add(SUITE, name, "PASS" if ok else "FAIL", "" if ok else f"{ack}*") report.add(SUITE, name, "PASS" if ok else "FAIL", "" if ok else f"{ack}*")
if tap_ack: if tap_ack:

View File

@ -18,11 +18,22 @@ CheckResult = _rtt.CheckResult
@contextmanager @contextmanager
def open_session(device: str = "AT32F403AC"): def open_session(device: str = "AT32F403AC", *, reset: bool = True):
"""连接 J-Link + 启动 RTTyield RttSession退出时清理.""" """连接 J-Link + 启动 RTTyield RttSession退出时清理.
reset=True先硬件复位并等待开机避免前序 LCD/烧写把主循环卡死导致无 ACK
"""
import time
_rtt.import_deps() _rtt.import_deps()
jlink = connect_jlink(device) jlink = connect_jlink(device)
try: try:
if reset:
try:
jlink.reset(halt=False)
except Exception:
pass
time.sleep(5.0)
cb = find_rtt_control_block(jlink) cb = find_rtt_control_block(jlink)
if cb is None: if cb is None:
raise SystemExit("SEGGER RTT control block 未找到(固件未运行?)") raise SystemExit("SEGGER RTT control block 未找到(固件未运行?)")

View File

@ -424,12 +424,19 @@ def main():
sys.exit("缺少 bleak: pip install bleak") sys.exit("缺少 bleak: pip install bleak")
print(f"选项: unpair={args.unpair} transport={args.transport}") print(f"选项: unpair={args.unpair} transport={args.transport}")
try:
sim = BleMidiSim( sim = BleMidiSim(
name=args.ble_name, name=args.ble_name,
address=args.ble_address, address=args.ble_address,
transport=args.transport, transport=args.transport,
unpair=args.unpair, unpair=args.unpair,
) )
except Exception as exc:
R = Results()
R.add("BLE 扫描连接", "FAIL", str(exc))
R.summary()
print(f"[FAIL] BLE 扫描连接 | {exc}")
sys.exit(1)
print( print(
f"=== BLE 测试: {sim.info.get('name')} ({sim.info.get('address')}) " f"=== BLE 测试: {sim.info.get('name')} ({sim.info.get('address')}) "
f"transport={sim.info.get('transport')} payload={sim.info.get('max_payload')} ===" f"transport={sim.info.get('transport')} payload={sim.info.get('max_payload')} ==="