K1Guitar/tools/k1_harness/suites/ui_nav.py

75 lines
2.9 KiB
Python
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.

# -*- coding: utf-8 -*-
"""ui 套件UI 页面状态 + 触摸注入导航 + 可选截屏.
- `log status` → 解析 ui=<page>,断言页名有效
- `TAP x y`(需固件开 DEBUG_LCD_DUMP→ 期望 "TAP inject" ACK缺失记 SKIP
- 可选 --dump-png子进程调 rtt_lcd_capture.py 截屏留证(不作像素门禁)
"""
from __future__ import annotations
import os
import re
import subprocess
import sys
from ..paths import TOOLS_DIR
from ..transports.rtt_session import open_session
SUITE = "ui"
UI_RE = re.compile(r"LOG_STATUS .*?ui=(\S+)")
def _read_ui_page(sess) -> str | None:
sess.pump(0.15)
sess.cmd("log status", settle=0.1)
for line in sess.pump(1.5):
m = UI_RE.search(line)
if m:
return m.group(1)
return None
def run(report, ctx) -> None:
with open_session(ctx.device) as sess:
page0 = _read_ui_page(sess)
if page0:
report.add(SUITE, "UI 页面上报", "PASS", f"ui={page0}")
else:
report.add(SUITE, "UI 页面上报", "FAIL", "log status 无 ui= 字段")
# 触摸注入DEBUG_LCD_DUMP 构建才有)
sess.pump(0.15)
sess.cmd("TAP 120 80", settle=0.1)
tap_ack = any("TAP inject" in l for l in sess.pump(2.0))
if not tap_ack:
report.add(SUITE, "触摸注入 TAP", "SKIP",
"'TAP inject':固件未开 DEBUG_LCD_DUMP发布固件默认关闭")
else:
report.add(SUITE, "触摸注入 TAP", "PASS", "TAP inject")
sess.pump(1.0)
page1 = _read_ui_page(sess)
if page1:
report.add(SUITE, "TAP 后页面状态", "PASS", f"ui={page0} -> {page1}")
else:
report.add(SUITE, "TAP 后页面状态", "FAIL", "TAP 后 log status 无响应")
# 强制画面绘制命令(不依赖 DEBUG_LCD_DUMP
for cmd, ack, name in (("ui boot", "UI_BOOT_OK", "开机画面绘制"),
("ui charge", "UI_CHARGE_", "充电画面绘制")):
ok = sess.cmd_ack(cmd, ack, timeout_s=3.0, retries=2)
report.add(SUITE, name, "PASS" if ok else "FAIL", "" if ok else f"{ack}*")
# 回 Idle 附近状态TAP 返回键区域(仅 dump 构建有意义)
if tap_ack:
sess.cmd("TAP 20 20", settle=0.5)
# 可选截屏(独立 J-Link 会话,放在 RTT session 关闭后)
if ctx.dump_png:
proc = subprocess.run(
[sys.executable, os.path.join(TOOLS_DIR, "rtt_lcd_capture.py"),
"--out", ctx.dump_png, "--device", ctx.device],
capture_output=True, text=True, timeout=120)
ok = proc.returncode == 0 and os.path.isfile(ctx.dump_png)
report.add(SUITE, "LCD 截屏", "PASS" if ok else "SKIP",
ctx.dump_png if ok else "截屏失败(需 DEBUG_LCD_DUMP 固件)")