Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
614f452d23 | ||
|
|
675b55aea0 | ||
|
|
3b41543fba | ||
|
|
be753f1453 |
@@ -3,7 +3,9 @@
|
||||
# busybox reboot/poweroff/halt, which only signal PID 1. Runs the real
|
||||
# helpers from qemu/rootfs/etc/warden-lib.sh in a plain sh with stub
|
||||
# commands, idles it the way /sbin/init does, sends each signal and requires
|
||||
# the matching action within two seconds.
|
||||
# the matching action within two seconds. Each signal goes out only once the
|
||||
# shell has its handler installed (SigCgt), so a slow start cannot turn the
|
||||
# signal's default action into a false failure (bfe-core1106-sdk#22).
|
||||
set -uo pipefail
|
||||
# Job control: each case's shell leads its own process group, so cleanup can
|
||||
# kill the whole group. An orphaned `sleep 3600` would otherwise keep this
|
||||
@@ -16,15 +18,41 @@ SH="${WARDEN_TEST_SH:-sh}"
|
||||
WORK="$(mktemp -d)" || exit 1
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
FAIL=0
|
||||
# Hang backstop for the handler install; a quiet host takes milliseconds.
|
||||
TRAP_WAIT_S="${WARDEN_TEST_TRAP_WAIT_S:-10}"
|
||||
|
||||
run_case() { # run_case <signal> <expected marker> <label>
|
||||
local sig="$1" want="$2" label="$3" out="$WORK/$1.out"
|
||||
# Succeeds once <pid> catches <signal>: its bit is set in /proc SigCgt.
|
||||
catches() { # catches <pid> <signal name>
|
||||
local mask num
|
||||
mask="$(awk '/^SigCgt:/ { print $2 }' "/proc/$1/status" 2>/dev/null)"
|
||||
num="$(kill -l "$2")" || return 1
|
||||
[ -n "$mask" ] && (( (16#$mask >> (num - 1)) & 1 ))
|
||||
}
|
||||
|
||||
# Waits up to TRAP_WAIT_S for <pid> to catch <signal>.
|
||||
wait_trapped() { # wait_trapped <pid> <signal name>
|
||||
local n=0 limit=$((TRAP_WAIT_S * 10))
|
||||
until catches "$1" "$2"; do
|
||||
[ "$n" -ge "$limit" ] && return 1
|
||||
sleep 0.1; n=$((n + 1))
|
||||
done
|
||||
}
|
||||
|
||||
# <delay> holds the handler install back, as a loaded runner does.
|
||||
run_case() { # run_case <signal> <expected marker> <label> [delay s]
|
||||
local sig="$1" want="$2" label="$3" delay="${4:-0}" out="$WORK/$1.out"
|
||||
: > "$out"
|
||||
WARDEN_REBOOT_CMD="eval echo reboot >> $out; exit 0" \
|
||||
WARDEN_POWEROFF_CMD="eval echo poweroff >> $out; exit 0" \
|
||||
"$SH" -c ". '$LIB'; warden_trap_power_signals; warden_idle_forever" &
|
||||
"$SH" -c "sleep $delay; . '$LIB'; warden_trap_power_signals; warden_idle_forever" &
|
||||
local pid=$!
|
||||
sleep 0.5
|
||||
if ! wait_trapped "$pid" "$sig"; then
|
||||
echo "[FAIL] $label (SIG$sig handler not installed within ${TRAP_WAIT_S} s)"
|
||||
FAIL=1
|
||||
kill -KILL -- "-$pid" 2>/dev/null
|
||||
wait "$pid" 2>/dev/null
|
||||
return
|
||||
fi
|
||||
kill -"$sig" "$pid"
|
||||
local n=0
|
||||
while ! grep -qx "$want" "$out" && [ "$n" -lt 20 ]; do
|
||||
@@ -42,5 +70,19 @@ run_case() { # run_case <signal> <expected marker> <label>
|
||||
run_case TERM reboot "SIGTERM (busybox reboot) reboots at once"
|
||||
run_case USR2 poweroff "SIGUSR2 (busybox poweroff) powers off at once"
|
||||
run_case USR1 poweroff "SIGUSR1 (busybox halt) powers off at once"
|
||||
# Regression for bfe-core1106-sdk#22: the old fixed 0.5 s sleep sent SIGTERM
|
||||
# before this shell installed its trap, killing it with nothing written.
|
||||
run_case TERM reboot "SIGTERM after a slow handler install still reboots" 1.5
|
||||
|
||||
# The wait itself must fail, not hang or pass, when no handler ever appears.
|
||||
"$SH" -c 'sleep 3600' &
|
||||
pid=$!
|
||||
if TRAP_WAIT_S=1 wait_trapped "$pid" TERM; then
|
||||
echo "[FAIL] wait_trapped reported a handler a plain shell never installs"; FAIL=1
|
||||
else
|
||||
echo "[PASS] wait_trapped gives up on a shell without a handler"
|
||||
fi
|
||||
kill -KILL -- "-$pid" 2>/dev/null
|
||||
wait "$pid" 2>/dev/null
|
||||
|
||||
exit "$FAIL"
|
||||
|
||||
+34
-9
@@ -154,7 +154,13 @@ def _load_imgtools():
|
||||
|
||||
AXIS_MAX = 32767
|
||||
TAP_HOLD_S = 0.35
|
||||
TAP_OBSERVE_TIMEOUT_S = 2.0
|
||||
# How long the runner waits for the guest to count an injected press or
|
||||
# release. A behaviour check, not a budget: a loaded runner (two TCG VMs on a
|
||||
# shared host) has taken longer than 2 s to count the release that opens the
|
||||
# drawer (flare-edge#1138), so the wait is a hang backstop. A wait longer than
|
||||
# INPUT_SLOW_NOTE_S still passes and says so in the step's detail.
|
||||
TAP_OBSERVE_TIMEOUT_S = 20.0
|
||||
INPUT_SLOW_NOTE_S = 2.0
|
||||
|
||||
# Bounds every blocking read on the QMP socket -- the greeting banner, the
|
||||
# qmp_capabilities handshake, and every screendump/tap/quit round trip --
|
||||
@@ -223,19 +229,36 @@ def do_tap(s, f, ax, ay, hold=TAP_HOLD_S):
|
||||
|
||||
|
||||
def wait_input_count(ctx, field, before):
|
||||
"""Wait until one guest input counter advances."""
|
||||
"""Wait until one guest input counter advances.
|
||||
|
||||
Records the longest wait of the current verb in ctx.input_wait_s, so a
|
||||
slow guest shows in the results without failing the step."""
|
||||
if before is None:
|
||||
time.sleep(0.05)
|
||||
return True
|
||||
deadline = time.monotonic() + TAP_OBSERVE_TIMEOUT_S
|
||||
start = time.monotonic()
|
||||
deadline = start + TAP_OBSERVE_TIMEOUT_S
|
||||
while time.monotonic() < deadline:
|
||||
now = parse_stats(ctx.ctl.send("stats")).get(field)
|
||||
if now is not None and now != before:
|
||||
waited = time.monotonic() - start
|
||||
ctx.input_wait_s = max(getattr(ctx, "input_wait_s", 0.0), waited)
|
||||
return True
|
||||
time.sleep(0.02)
|
||||
return False
|
||||
|
||||
|
||||
def input_verdict(ctx, observed):
|
||||
"""The (status, detail) of a tap, swipe or fling from its observation."""
|
||||
if not observed:
|
||||
return ("fail", "input press or release was not consumed within "
|
||||
f"{TAP_OBSERVE_TIMEOUT_S:g} seconds")
|
||||
waited = getattr(ctx, "input_wait_s", 0.0)
|
||||
if waited > INPUT_SLOW_NOTE_S:
|
||||
return "ok", f"slow guest: input consumed after {waited:.1f} s"
|
||||
return "ok", ""
|
||||
|
||||
|
||||
def do_observed_tap(ctx, ax, ay):
|
||||
"""Wait until the guest consumes both halves of a tap."""
|
||||
before = parse_stats(ctx.ctl.send("stats"))
|
||||
@@ -733,6 +756,8 @@ class Ctx:
|
||||
# console size when the step before this one began (flare-edge#233).
|
||||
self.next_cmd = None
|
||||
self.prev_step_console = 0
|
||||
# The longest input-count wait of the current tap, swipe or fling.
|
||||
self.input_wait_s = 0.0
|
||||
|
||||
def need_ctl(self, lineno, cmd):
|
||||
if self.ctl is None:
|
||||
@@ -792,6 +817,7 @@ def verb_shot(ctx, lineno, cmd, args, line):
|
||||
def verb_tap(ctx, lineno, cmd, args, line):
|
||||
x, y = int(args[0]), int(args[1])
|
||||
ctx.tap_sent = False
|
||||
ctx.input_wait_s = 0.0
|
||||
try:
|
||||
observed = do_observed_tap(ctx, to_axis(x, ctx.size), to_axis(y, ctx.size))
|
||||
except (RuntimeError, OSError):
|
||||
@@ -804,23 +830,22 @@ def verb_tap(ctx, lineno, cmd, args, line):
|
||||
if ctx.next_cmd == "expect_reboot" and ctx.tap_sent:
|
||||
return "ok", "tap sent; the control channel closed as the guest went down"
|
||||
raise
|
||||
return (("ok", "") if observed else
|
||||
("fail", "input press or release was not consumed within 2 seconds"))
|
||||
return input_verdict(ctx, observed)
|
||||
|
||||
|
||||
def verb_swipe(ctx, lineno, cmd, args, line):
|
||||
ms = int(args[4]) if len(args) > 4 else 400
|
||||
ctx.input_wait_s = 0.0
|
||||
observed = do_observed_swipe(
|
||||
ctx, int(args[0]), int(args[1]), int(args[2]), int(args[3]), ms)
|
||||
return (("ok", "") if observed else
|
||||
("fail", "input press or release was not consumed within 2 seconds"))
|
||||
return input_verdict(ctx, observed)
|
||||
|
||||
|
||||
def verb_fling(ctx, lineno, cmd, args, line):
|
||||
ctx.input_wait_s = 0.0
|
||||
observed = do_observed_swipe(
|
||||
ctx, int(args[0]), int(args[1]), int(args[2]), int(args[3]), ms=120)
|
||||
return (("ok", "") if observed else
|
||||
("fail", "input press or release was not consumed within 2 seconds"))
|
||||
return input_verdict(ctx, observed)
|
||||
|
||||
|
||||
def verb_sleep(ctx, lineno, cmd, args, line):
|
||||
|
||||
@@ -339,6 +339,52 @@ class PureHelpers(unittest.TestCase):
|
||||
self.assertEqual(len(calls), 2)
|
||||
self.assertEqual(calls[-1], [qmp.btn_ev(False)])
|
||||
|
||||
def _swipe_on_fake_clock(self, release_at_s):
|
||||
"""verb_swipe against a guest that counts the press at once and the
|
||||
release only once release_at_s of fake time has passed (None: never).
|
||||
Returns the verdict and the fake time the verb took."""
|
||||
clock = [0.0]
|
||||
replies = iter(["presses: 0\nreleases: 0"]) # the baseline read
|
||||
|
||||
def send(cmd):
|
||||
late = release_at_s is not None and clock[0] >= release_at_s
|
||||
return next(replies, f"presses: 1\nreleases: {1 if late else 0}")
|
||||
|
||||
ctx = SimpleNamespace(s=None, f=None, size=720,
|
||||
ctl=SimpleNamespace(send=send), input_wait_s=0.0)
|
||||
|
||||
def sleep(seconds):
|
||||
clock[0] += seconds
|
||||
|
||||
saved = qmp.send_events, qmp.time.sleep, qmp.time.monotonic
|
||||
qmp.send_events = lambda _s, _f, _events: None
|
||||
qmp.time.sleep = sleep
|
||||
qmp.time.monotonic = lambda: clock[0]
|
||||
try:
|
||||
verdict = qmp.verb_swipe(ctx, 1, "swipe", ["2", "350", "520", "352", "3000"], "")
|
||||
finally:
|
||||
qmp.send_events, qmp.time.sleep, qmp.time.monotonic = saved
|
||||
return verdict, clock[0]
|
||||
|
||||
def test_swipe_release_counted_late_on_a_loaded_guest_passes(self):
|
||||
# flare-edge#1138: the release that opens the drawer was counted
|
||||
# after more than 2 s on a loaded runner; the old 2 s bound failed
|
||||
# the swipe although the guest handled it. It passes, with a note.
|
||||
(status, detail), _ = self._swipe_on_fake_clock(release_at_s=3.0 + 2.5)
|
||||
self.assertEqual(status, "ok")
|
||||
self.assertIn("slow guest: input consumed after 2.5 s", detail)
|
||||
|
||||
def test_swipe_release_counted_promptly_has_no_note(self):
|
||||
(status, detail), _ = self._swipe_on_fake_clock(release_at_s=3.0 + 0.5)
|
||||
self.assertEqual((status, detail), ("ok", ""))
|
||||
|
||||
def test_swipe_release_never_counted_fails_at_the_backstop(self):
|
||||
(status, detail), took = self._swipe_on_fake_clock(release_at_s=None)
|
||||
self.assertEqual(status, "fail")
|
||||
self.assertIn(f"within {qmp.TAP_OBSERVE_TIMEOUT_S:g} seconds", detail)
|
||||
# Bounded: the 3 s drag plus the backstop, and not much more.
|
||||
self.assertLess(took, 3.0 + qmp.TAP_OBSERVE_TIMEOUT_S + 1.0)
|
||||
|
||||
def test_every_pixel_round_trips_through_lvgl_calibration(self):
|
||||
# lv_evdev.c _evdev_calibrate: px = axis * (width - 1) / AXIS_MAX,
|
||||
# integer division. A tap requested at px must land at px, for every
|
||||
|
||||
Reference in New Issue
Block a user