Compare commits
22
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
614f452d23 | ||
|
|
675b55aea0 | ||
|
|
3b41543fba | ||
|
|
be753f1453 | ||
|
|
d22c900fb6 | ||
|
|
b7125fc4a7 | ||
|
|
35f3ca10eb | ||
|
|
8212bf5feb | ||
|
|
8c4870c6fb | ||
|
|
92d601f585 | ||
|
|
65a6800228 | ||
|
|
d01add5646 | ||
|
|
a828667b0f | ||
|
|
45569611da | ||
|
|
b18ed3888b | ||
|
|
d746ceba6d | ||
|
|
5f3db8453b | ||
|
|
85dc1ee04d | ||
|
|
6576a4a506 | ||
|
|
9b0659d30c | ||
|
|
317ae087fd | ||
|
|
07db1b9ec0 |
@@ -149,6 +149,10 @@ jobs:
|
||||
# on the debug channel. All offline (a stub qemu-system-arm on
|
||||
# PATH), so it runs on every push/PR, not only a real boot.
|
||||
run: bash qemu/tests/run-sh-args-test.sh
|
||||
- name: rig init honours reboot/poweroff/halt (#5)
|
||||
run: bash qemu/tests/init-power-signals-test.sh
|
||||
- name: rig init daemon order matches the panel (flare-edge#348)
|
||||
run: bash qemu/tests/init-daemon-order-test.sh
|
||||
- name: mkimage.sh SEED_DIR regression test
|
||||
# Only ui-drive.sh --seed (a real VM boot) exercises this hook
|
||||
# otherwise; this builds the same unprivileged mkfs.ext4 image and
|
||||
|
||||
@@ -121,6 +121,22 @@ command -v "${CROSS_COMPILE}gcc" >/dev/null \
|
||||
|| { echo "cross toolchain ${CROSS_COMPILE}gcc not on PATH (set SDK_TC, or CROSS_COMPILE to one that is)" >&2; exit 1; }
|
||||
make -C "$SRC" ARCH=arm CROSS_COMPILE="$CROSS_COMPILE" olddefconfig >/dev/null
|
||||
|
||||
# Took-effect assertion for the symbols whose silent loss is a security hole,
|
||||
# not a build failure. olddefconfig drops a defconfig line whose dependencies
|
||||
# are unmet without a word, and the panel's firewall then quietly stops
|
||||
# covering IPv6 (flare-edge#533: no ip6tables filter table, so the IPv4
|
||||
# default-drop never applied to IPv6). Every symbol here must be built in
|
||||
# (=y): the panel has no /lib/modules.
|
||||
req_fail=0
|
||||
for sym in CONFIG_NF_DEFRAG_IPV6 CONFIG_IP6_NF_IPTABLES \
|
||||
CONFIG_IP6_NF_IPTABLES_LEGACY CONFIG_IP6_NF_FILTER; do
|
||||
grep -qxF "$sym=y" "$SRC/.config" || {
|
||||
echo "FATAL: required option $sym is not =y in the final .config (unmet Kconfig dependency?)" >&2
|
||||
req_fail=1
|
||||
}
|
||||
done
|
||||
[ "$req_fail" = 0 ] || exit 1
|
||||
|
||||
# Fragment took-effect assertion: merge_config -m only pastes text, and
|
||||
# olddefconfig silently resolves any symbol whose dependencies are unmet:
|
||||
# a fragment option could be dropped without a word. Verify every explicit
|
||||
|
||||
@@ -1372,3 +1372,26 @@ CONFIG_IP_NF_FILTER=y
|
||||
CONFIG_IP_NF_TARGET_REJECT=y
|
||||
CONFIG_IP_NF_NAT=y
|
||||
CONFIG_IP_NF_MANGLE=y
|
||||
#
|
||||
# IPv6 netfilter (flare-edge#533). Without it ip6tables has no filter table
|
||||
# ("Table does not exist"), so the IPv4 default-drop INPUT policy in
|
||||
# S35iptables never applied to IPv6 and every listener bound to :: (dropbear,
|
||||
# telnetd, the web UI) was reachable over IPv6. Four symbols, all built in
|
||||
# because the panel has no /lib/modules:
|
||||
# IP6_NF_IPTABLES + IP6_NF_IPTABLES_LEGACY the ip6tables core, legacy
|
||||
# flavour (the userland is legacy)
|
||||
# IP6_NF_FILTER the filter table; it defaults to
|
||||
# =m under legacy, so =y is explicit
|
||||
# NF_DEFRAG_IPV6 IPv6 reassembly for conntrack, so
|
||||
# the state/conntrack matches work
|
||||
# (NF_CONNTRACK selects it when
|
||||
# IPV6 is on; listed so the set is
|
||||
# visible and guarded)
|
||||
# No new match symbols: the icmp6 match is part of the ip6_tables core
|
||||
# (IP6_NF_IPTABLES); tcp/udp matches are in xt_tcpudp, always built with
|
||||
# XTABLES; state, limit and conntrack are the family-agnostic matches enabled
|
||||
# above.
|
||||
CONFIG_NF_DEFRAG_IPV6=y
|
||||
CONFIG_IP6_NF_IPTABLES=y
|
||||
CONFIG_IP6_NF_IPTABLES_LEGACY=y
|
||||
CONFIG_IP6_NF_FILTER=y
|
||||
|
||||
@@ -82,7 +82,7 @@ tiered:
|
||||
behind a small injectable seam, mock its world, build
|
||||
`-fcondition-coverage`, enforce via the shared `drivers/enforce-mcdc.sh`
|
||||
(gcc-14 `gcov --conditions`) in the CI `mcdc` job (the proven flare-edge
|
||||
`tests/uboot-ab` method). **Done:** `relays.c` (40/40 conditions) and
|
||||
`tests/uboot-ab` method). **Done:** `relays.c` (50/50 conditions) and
|
||||
`freshness.c` (66/66). **Next in:** the modbus master and the RGA
|
||||
dispatch, with the ADR-0005 unification (`drivers/README.md`).
|
||||
- **Tier 2, near-mainline small drivers -> branch coverage + fault
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
|
||||
> **Outcome tested:** A relay is exported transparently and driven without disturbing a held contact.
|
||||
|
||||
**Coverage**: relays.c: 40/40 conditions, 100% MC/DC (CI-enforced)
|
||||
**Coverage**: relays.c: 50/50 conditions, 100% MC/DC (CI-enforced)
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
A[warden_relay_set idx,on] --> B{idx < COUNT?}
|
||||
B -- no --> Z[no-op]
|
||||
B -- yes --> C{exported?}
|
||||
B -- yes --> P{all sysfs paths fit PATH_MAX?}
|
||||
P -- no --> Z3[log to stderr, no-op]
|
||||
P -- yes --> C{exported?}
|
||||
C -- no --> D[write export] --> E{exported now?}
|
||||
E -- no --> Z2[give up]
|
||||
E -- yes --> F
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ Self-contained logic with a clean seam, measured to **100% MC/DC** (gcc-14
|
||||
|
||||
| Driver | Seam | MC/DC |
|
||||
|---|---|---|
|
||||
| `relays/` | `relay_io` vtable (sysfs backend + in-memory fake) | 40/40 conditions, 100% |
|
||||
| `relays/` | `relay_io` vtable (sysfs backend + in-memory fake) | 50/50 conditions, 100% |
|
||||
| `freshness/` | produce/render callbacks (the "no stale numbers" guard) | 66/66 conditions, 100% |
|
||||
|
||||
**Adding a Tier-1 driver:** copy `<name>.{c,h}` here, put the hardware/OS calls behind
|
||||
|
||||
+60
-28
@@ -1,5 +1,6 @@
|
||||
#include "relays.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -8,6 +9,8 @@
|
||||
/* GPIO1_A0 and GPIO1_A1; gpiochip1 base is 32. See relays.h. */
|
||||
static const int s_gpio[WARDEN_RELAY_COUNT] = { 32, 33 };
|
||||
static const char * const s_name[WARDEN_RELAY_COUNT] = { "Relay 1", "Relay 2" };
|
||||
/* The same numbers as the strings written to `export`, so no runtime formatting. */
|
||||
static const char * const s_gpio_str[WARDEN_RELAY_COUNT] = { "32", "33" };
|
||||
|
||||
/* ---- default sysfs backend (Tier-2 plumbing; covered by integration tests) ---- */
|
||||
|
||||
@@ -64,11 +67,46 @@ const char * warden_relay_name(uint32_t idx)
|
||||
return idx < WARDEN_RELAY_COUNT ? s_name[idx] : "-";
|
||||
}
|
||||
|
||||
static bool exported(int gpio)
|
||||
/**
|
||||
* Every sysfs path one relay operation can touch. Each holds PATH_MAX bytes, so
|
||||
* any root the kernel would accept fits.
|
||||
*/
|
||||
struct relay_paths {
|
||||
char gpio[PATH_MAX]; /* <root>/gpioN */
|
||||
char export_[PATH_MAX]; /* <root>/export */
|
||||
char direction[PATH_MAX]; /* <root>/gpioN/direction */
|
||||
char value[PATH_MAX]; /* <root>/gpioN/value */
|
||||
};
|
||||
|
||||
/**
|
||||
* Format the paths for relay @p idx up front. A `$WARDEN_GPIO_ROOT` too long for
|
||||
* any of them is refused with a log line, never truncated: a cut-short path
|
||||
* would silently report both relays unavailable, or name a different node.
|
||||
*/
|
||||
static bool relay_paths(uint32_t idx, struct relay_paths * rp)
|
||||
{
|
||||
char p[80];
|
||||
snprintf(p, sizeof(p), "%s/gpio%d", gpio_root(), gpio);
|
||||
return s_io->exists(p);
|
||||
const char * root = gpio_root();
|
||||
int gpio = s_gpio[idx];
|
||||
const int n[] = {
|
||||
snprintf(rp->gpio, sizeof(rp->gpio), "%s/gpio%d", root, gpio),
|
||||
snprintf(rp->export_, sizeof(rp->export_), "%s/export", root),
|
||||
snprintf(rp->direction, sizeof(rp->direction), "%s/gpio%d/direction", root, gpio),
|
||||
snprintf(rp->value, sizeof(rp->value), "%s/gpio%d/value", root, gpio),
|
||||
};
|
||||
for(size_t i = 0; i < sizeof(n) / sizeof(n[0]); i++) {
|
||||
/* The unsigned cast also maps an encoding error (n < 0) to "does not fit". */
|
||||
if((unsigned)n[i] >= PATH_MAX) {
|
||||
fprintf(stderr, "relays: WARDEN_GPIO_ROOT is too long (%zu bytes): sysfs paths "
|
||||
"under it exceed PATH_MAX (%d), refusing it\n", strlen(root), PATH_MAX);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool exported(const struct relay_paths * rp)
|
||||
{
|
||||
return s_io->exists(rp->gpio);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,28 +115,21 @@ static bool exported(int gpio)
|
||||
* relay the first time this page is opened; reading the current level first and
|
||||
* writing it straight back makes the export transparent.
|
||||
*/
|
||||
static bool ensure_ready(int gpio)
|
||||
static bool ensure_ready(uint32_t idx, const struct relay_paths * rp)
|
||||
{
|
||||
if(!exported(gpio)) {
|
||||
char ex[80], n[16];
|
||||
snprintf(ex, sizeof(ex), "%s/export", gpio_root());
|
||||
snprintf(n, sizeof(n), "%d", gpio);
|
||||
s_io->write(ex, n);
|
||||
if(!exported(gpio)) return false;
|
||||
if(!exported(rp)) {
|
||||
s_io->write(rp->export_, s_gpio_str[idx]);
|
||||
if(!exported(rp)) return false;
|
||||
}
|
||||
|
||||
char p[96];
|
||||
snprintf(p, sizeof(p), "%s/gpio%d/direction", gpio_root(), gpio);
|
||||
char dir[16] = "";
|
||||
if(!s_io->read_line(p, dir, sizeof(dir))) return false;
|
||||
if(!s_io->read_line(rp->direction, dir, sizeof(dir))) return false;
|
||||
|
||||
if(strncmp(dir, "out", 3) != 0) {
|
||||
/* Preserve the level across the switch to output. */
|
||||
char vp[96];
|
||||
int cur;
|
||||
snprintf(vp, sizeof(vp), "%s/gpio%d/value", gpio_root(), gpio);
|
||||
if(!s_io->read_int(vp, &cur)) cur = 0;
|
||||
s_io->write(p, cur ? "high" : "low");
|
||||
if(!s_io->read_int(rp->value, &cur)) cur = 0;
|
||||
s_io->write(rp->direction, cur ? "high" : "low");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -106,27 +137,28 @@ static bool ensure_ready(int gpio)
|
||||
bool warden_relay_available(uint32_t idx)
|
||||
{
|
||||
if(idx >= WARDEN_RELAY_COUNT) return false;
|
||||
return ensure_ready(s_gpio[idx]);
|
||||
struct relay_paths rp;
|
||||
if(!relay_paths(idx, &rp)) return false;
|
||||
return ensure_ready(idx, &rp);
|
||||
}
|
||||
|
||||
bool warden_relay_get(uint32_t idx)
|
||||
{
|
||||
if(idx >= WARDEN_RELAY_COUNT) return false;
|
||||
if(!exported(s_gpio[idx])) return false;
|
||||
struct relay_paths rp;
|
||||
if(!relay_paths(idx, &rp)) return false;
|
||||
if(!exported(&rp)) return false;
|
||||
|
||||
char p[96];
|
||||
int v;
|
||||
snprintf(p, sizeof(p), "%s/gpio%d/value", gpio_root(), s_gpio[idx]);
|
||||
if(!s_io->read_int(p, &v)) v = 0;
|
||||
if(!s_io->read_int(rp.value, &v)) v = 0;
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
void warden_relay_set(uint32_t idx, bool on)
|
||||
{
|
||||
if(idx >= WARDEN_RELAY_COUNT) return;
|
||||
if(!ensure_ready(s_gpio[idx])) return;
|
||||
|
||||
char p[96];
|
||||
snprintf(p, sizeof(p), "%s/gpio%d/value", gpio_root(), s_gpio[idx]);
|
||||
s_io->write(p, on ? "1" : "0");
|
||||
struct relay_paths rp;
|
||||
if(!relay_paths(idx, &rp)) return;
|
||||
if(!ensure_ready(idx, &rp)) return;
|
||||
s_io->write(rp.value, on ? "1" : "0");
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
* the decision logic runs and is measured to 100% MC/DC on the host, and the
|
||||
* gpio root is `$WARDEN_GPIO_ROOT`-overridable so the real backend can run
|
||||
* against a scratch tree in an integration test.
|
||||
*
|
||||
* Paths are built in PATH_MAX buffers. A root too long for its longest path
|
||||
* ("<root>/gpioNN/direction" within PATH_MAX) is refused with a stderr line, and
|
||||
* every call then reports unavailable / off / no-op; it is never truncated.
|
||||
*/
|
||||
#ifndef WARDEN_RELAYS_H
|
||||
#define WARDEN_RELAYS_H
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "../relays.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -30,11 +32,12 @@ static struct {
|
||||
const char *read_line_val;
|
||||
bool read_int_ok;
|
||||
int read_int_val;
|
||||
char last_write_path[160];
|
||||
char last_write_path[PATH_MAX];
|
||||
char last_write_val[32];
|
||||
int exists_calls;
|
||||
} fk;
|
||||
|
||||
static bool fk_exists(const char *p) { (void)p; return fk.exists_ret; }
|
||||
static bool fk_exists(const char *p) { (void)p; fk.exists_calls++; return fk.exists_ret; }
|
||||
static void fk_write(const char *p, const char *v) {
|
||||
snprintf(fk.last_write_path, sizeof fk.last_write_path, "%s", p);
|
||||
snprintf(fk.last_write_val, sizeof fk.last_write_val, "%s", v);
|
||||
@@ -56,6 +59,104 @@ static const struct relay_io FAKE = { fk_exists, fk_write, fk_read_line, fk_read
|
||||
|
||||
static void fk_reset(void) { memset(&fk, 0, sizeof fk); }
|
||||
|
||||
/* ---- stderr capture: proves a refusal is logged, not silent ---- */
|
||||
|
||||
static char g_err[1024];
|
||||
static int g_saved_stderr = -1;
|
||||
static char g_err_path[] = "/tmp/warden-relays-stderr-XXXXXX";
|
||||
|
||||
static void err_begin(void)
|
||||
{
|
||||
int fd = mkstemp(g_err_path);
|
||||
assert(fd >= 0);
|
||||
fflush(stderr);
|
||||
g_saved_stderr = dup(2);
|
||||
dup2(fd, 2);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void err_end(void)
|
||||
{
|
||||
fflush(stderr);
|
||||
dup2(g_saved_stderr, 2);
|
||||
close(g_saved_stderr);
|
||||
FILE *f = fopen(g_err_path, "r");
|
||||
size_t n = f ? fread(g_err, 1, sizeof g_err - 1, f) : 0;
|
||||
g_err[n] = '\0';
|
||||
if(f) fclose(f);
|
||||
unlink(g_err_path);
|
||||
memcpy(g_err_path + strlen(g_err_path) - 6, "XXXXXX", 6);
|
||||
}
|
||||
|
||||
/* A root of exactly @p len bytes ("/" then 'a's); it need not exist for fake io. */
|
||||
static char g_long[PATH_MAX + 64];
|
||||
static const char *long_root(size_t len)
|
||||
{
|
||||
assert(len >= 1 && len < sizeof g_long);
|
||||
g_long[0] = '/';
|
||||
memset(g_long + 1, 'a', len - 1);
|
||||
g_long[len] = '\0';
|
||||
return g_long;
|
||||
}
|
||||
|
||||
/* Root-length bounds (issue #10). The longest path is "<root>/gpio32/direction",
|
||||
* so a root of PATH_MAX - 1 - strlen("/gpio32/direction") bytes is the longest
|
||||
* that fits. One byte more must be refused loudly, never truncated. */
|
||||
static void long_root_unit_tests(void)
|
||||
{
|
||||
const size_t max_root = PATH_MAX - 1 - strlen("/gpio32/direction");
|
||||
|
||||
/* Well past the old 80/96-byte buffers but inside PATH_MAX: works, and the
|
||||
* io sees the full, untruncated path. */
|
||||
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
|
||||
setenv("WARDEN_GPIO_ROOT", long_root(200), 1);
|
||||
warden_relay_set(0, true);
|
||||
EXPECT(strcmp(fk.last_write_val, "1") == 0);
|
||||
EXPECT(strlen(fk.last_write_path) == 200 + strlen("/gpio32/value"));
|
||||
EXPECT(strncmp(fk.last_write_path, g_long, 200) == 0);
|
||||
EXPECT(strcmp(fk.last_write_path + 200, "/gpio32/value") == 0);
|
||||
|
||||
/* Exactly at the bound: still accepted. */
|
||||
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
|
||||
setenv("WARDEN_GPIO_ROOT", long_root(max_root), 1);
|
||||
EXPECT(warden_relay_available(0) == true);
|
||||
|
||||
/* One byte over: "<root>/gpio32" still fits, the direction path does not.
|
||||
* Every entry point refuses, logs, and never touches the io. */
|
||||
setenv("WARDEN_GPIO_ROOT", long_root(max_root + 1), 1);
|
||||
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
|
||||
fk.read_int_ok = true; fk.read_int_val = 1;
|
||||
err_begin();
|
||||
EXPECT(warden_relay_available(0) == false);
|
||||
err_end();
|
||||
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
|
||||
EXPECT(fk.exists_calls == 0);
|
||||
|
||||
err_begin();
|
||||
EXPECT(warden_relay_get(0) == false);
|
||||
err_end();
|
||||
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
|
||||
EXPECT(fk.exists_calls == 0);
|
||||
|
||||
err_begin();
|
||||
warden_relay_set(1, true);
|
||||
err_end();
|
||||
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
|
||||
EXPECT(fk.last_write_path[0] == '\0');
|
||||
EXPECT(fk.exists_calls == 0);
|
||||
|
||||
/* A root longer than PATH_MAX itself: refused the same way. */
|
||||
setenv("WARDEN_GPIO_ROOT", long_root(PATH_MAX + 10), 1);
|
||||
fk_reset(); fk.exists_ret = true;
|
||||
err_begin();
|
||||
EXPECT(warden_relay_available(1) == false);
|
||||
err_end();
|
||||
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
|
||||
EXPECT(fk.exists_calls == 0);
|
||||
|
||||
unsetenv("WARDEN_GPIO_ROOT");
|
||||
}
|
||||
|
||||
static void unit_tests(void)
|
||||
{
|
||||
warden_relay__set_io(&FAKE);
|
||||
@@ -142,18 +243,20 @@ static void unit_tests(void)
|
||||
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
|
||||
warden_relay_set(0, false);
|
||||
EXPECT(strcmp(fk.last_write_val, "0") == 0);
|
||||
|
||||
long_root_unit_tests();
|
||||
}
|
||||
|
||||
/* ---------------- layer 2: real sysfs backend over a scratch tree ---------------- */
|
||||
|
||||
static char g_root[128];
|
||||
static char g_root[PATH_MAX];
|
||||
|
||||
static void wr(const char *rel, const char *content) {
|
||||
char p[256]; snprintf(p, sizeof p, "%s/%s", g_root, rel);
|
||||
char p[PATH_MAX + 64]; snprintf(p, sizeof p, "%s/%s", g_root, rel);
|
||||
FILE *f = fopen(p, "w"); if(f) { fputs(content, f); fclose(f); }
|
||||
}
|
||||
static void mkgpio(int n) {
|
||||
char p[256]; snprintf(p, sizeof p, "%s/gpio%d", g_root, n); mkdir(p, 0777);
|
||||
char p[PATH_MAX + 64]; snprintf(p, sizeof p, "%s/gpio%d", g_root, n); mkdir(p, 0777);
|
||||
}
|
||||
|
||||
static void integration_tests(void)
|
||||
@@ -207,6 +310,24 @@ static void integration_tests(void)
|
||||
wr("gpio33/direction", "in\n");
|
||||
wr("gpio33/value", "1\n");
|
||||
EXPECT(warden_relay_available(1) == true); /* reads value=1, writes direction "high" */
|
||||
|
||||
/* Issue #10: a real scratch tree under a root far longer than the old 80/96-byte
|
||||
* buffers (the simulator's case). Both relays must be available and switchable. */
|
||||
for(int i = 0; i < 5; i++) {
|
||||
size_t l = strlen(g_root);
|
||||
snprintf(g_root + l, sizeof g_root - l, "/%s", "long-scratch-directory-component-for-issue-10");
|
||||
EXPECT(mkdir(g_root, 0777) == 0);
|
||||
}
|
||||
EXPECT(strlen(g_root) > 200);
|
||||
setenv("WARDEN_GPIO_ROOT", g_root, 1);
|
||||
mkgpio(32); mkgpio(33);
|
||||
wr("gpio32/direction", "out\n"); wr("gpio32/value", "0\n");
|
||||
wr("gpio33/direction", "out\n"); wr("gpio33/value", "0\n");
|
||||
EXPECT(warden_relay_available(0) == true);
|
||||
EXPECT(warden_relay_available(1) == true);
|
||||
warden_relay_set(1, true);
|
||||
EXPECT(warden_relay_get(1) == true);
|
||||
EXPECT(warden_relay_get(0) == false);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
||||
@@ -307,6 +307,16 @@ header explains its change.
|
||||
| `0012-drop-s50sshd.patch` | `overlay-luckfox-buildroot-init/etc/init.d/S50sshd` | deletes the generic sshd starter; dropbear provides SSH |
|
||||
| `0013-e2fsprogs-build-cflags.patch` | `sysdrv/tools/board/e2fsprogs/Makefile` | `BUILD_CFLAGS` so the host helpers build with gcc 14 |
|
||||
|
||||
### `board/patches/0014-s50usbdevice-unset-role-is-client.patch`
|
||||
|
||||
0004's S50usbdevice gate read an unset role as router, so a fresh `/userdata`
|
||||
never composed the USB gadget and the panel had no `usb0` until its second
|
||||
boot (flare-edge#278). 0014 makes unset mean client (0), like every other
|
||||
role reader; flare-edge's `tests/guards/run-role-default-tests.sh` pins the
|
||||
gate to them. It is a separate patch, not an edit to 0004, because
|
||||
`build-firmware.sh` would skip an edited 0004 as inconclusive on an SDK that
|
||||
already carries 0004 and 0008.
|
||||
|
||||
## Config fragments
|
||||
|
||||
| fragment | why |
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
Treat an unset USB role as client in S50usbdevice.
|
||||
|
||||
0004 gated the gadget build on `role || echo 1`, so a fresh /userdata (no
|
||||
role file) read as router and S50usbdevice exited before composing the
|
||||
gadget. Every other reader (flare-edge S26usbhost, S35iptables,
|
||||
usb-nic-hotplug.sh, wifi-link-watchdog.sh, flared's schema) defaults an
|
||||
unset role to client (0), so S26usbhost put the port in device role with no
|
||||
gadget to bind: a freshly provisioned or factory-reset panel had no usb0
|
||||
recovery link until its second boot (flare-edge#278).
|
||||
|
||||
A separate patch rather than an edit to 0004: tools/build-firmware.sh
|
||||
applies the series idempotently, and on an SDK that already carries 0004
|
||||
and 0008 an edited 0004 neither applies nor reverse-applies, so it would be
|
||||
skipped as inconclusive and the old gate would keep shipping. This one
|
||||
applies on top of either a pristine replay or an already-patched tree.
|
||||
|
||||
diff --git a/sysdrv/tools/board/android-tools/S50usbdevice b/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
index b521af4..fd8b693 100755
|
||||
--- a/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
+++ b/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
@@ -6,12 +6,19 @@
|
||||
# Load default env variables from profiles
|
||||
. /etc/profile
|
||||
|
||||
-# flare-edge: the OTG port is a USB HOST in router (and the unset-role default),
|
||||
-# so building a gadget here is pointless AND harmful — the dwc3 "failed to add
|
||||
+# flare-edge: only build the gadget in client role. A router's OTG port is a
|
||||
+# USB HOST, where a gadget is pointless AND harmful: the dwc3 "failed to add
|
||||
# gadget" + the usb2-phy "illegal mode" it triggers race with the USB-Ethernet
|
||||
-# host enumeration and intermittently kill eth1 at boot. Only run in client role;
|
||||
-# S26usbhost re-invokes this explicitly when switching to client. (unset -> router)
|
||||
-[ "$(cat /userdata/warden/role 2>/dev/null || echo 1)" = "1" ] && exit 0
|
||||
+# host enumeration and intermittently kill eth1 at boot. S26usbhost re-invokes
|
||||
+# this explicitly when switching to client.
|
||||
+#
|
||||
+# An UNSET role is client (0), the fresh-install default every other reader
|
||||
+# uses (S26usbhost, S35iptables, usb-nic-hotplug.sh, wifi-link-watchdog.sh,
|
||||
+# flared's schema). This gate used to read unset as router, so a fresh store
|
||||
+# set the port to device role with no gadget to bind and came up with no usb0
|
||||
+# until a second boot (flare-edge#278). flare-edge's
|
||||
+# tests/guards/run-role-default-tests.sh pins this line to the other readers.
|
||||
+[ "$(cat /userdata/warden/role 2>/dev/null || echo 0)" = "1" ] && exit 0
|
||||
|
||||
UMS_EN=off
|
||||
ADB_EN=on
|
||||
@@ -85,6 +85,11 @@ does on a panel instead of rejecting every attempt. `qemu_stage_rootfs()`
|
||||
the executable bit, so the checked-out source file's own mode depends on the
|
||||
checking-out umask and cannot be trusted to arrive non-world-readable.
|
||||
|
||||
A flow seed may contain `qemu-flow-setup.sh`. Stage-2 init runs it inside the
|
||||
disposable guest after mounting userdata and before starting daemons or the
|
||||
UI. A nonzero exit stops the boot. Use it only for test devices and commands
|
||||
that the virt machine does not provide.
|
||||
|
||||
## Scenarios
|
||||
|
||||
All take the virt-fragment `<zImage>`; `FLARE_EDGE=<checkout>` where noted.
|
||||
|
||||
+25
-2
@@ -106,8 +106,9 @@ if [ -n "${SEED_DIR:-}" ]; then
|
||||
# on the first bad entry the same way --state fails closed above, rather
|
||||
# than copy it into the image and let it surface as a confusing read
|
||||
# later. Only a top-level plain file matches "one file per settings key"
|
||||
# (the Env note above) -- seed-fixtures.py never nests a subdirectory, and
|
||||
# neither should anything else pointed at this hook.
|
||||
# (the Env note above), with one exception, profiles/rs485/<slug>.w485p
|
||||
# (installed device profiles, checked below); seed-fixtures.py nests
|
||||
# nothing else, and neither should anything else pointed at this hook.
|
||||
#
|
||||
# Charset is seed-fixtures.py's KEY_RE, not --state's stricter
|
||||
# [A-Za-z0-9_.]+ above: seed-fixtures.py deliberately also allows '-' for
|
||||
@@ -126,6 +127,28 @@ if [ -n "${SEED_DIR:-}" ]; then
|
||||
echo "FATAL: SEED_DIR entry '$base' is a symlink (refusing to copy it into userdata verbatim)" >&2
|
||||
exit 1
|
||||
fi
|
||||
# The one directory allowed: installed RS485 device profiles, as
|
||||
# warden-modbus keeps them (/userdata/warden/profiles/rs485/<slug>.w485p),
|
||||
# so a flow can boot with a profile already installed (flare-edge#387).
|
||||
# Nothing in it but plain <slug>.w485p files directly under rs485/.
|
||||
if [ "$base" = profiles ] && [ -d "$entry" ]; then
|
||||
while IFS= read -r -d '' p; do
|
||||
rel="${p#"$entry"/}"
|
||||
if [ "$rel" = rs485 ] && [ -d "$p" ] && [ ! -L "$p" ]; then continue; fi
|
||||
case "$rel" in
|
||||
rs485/*/*) ok=0 ;;
|
||||
rs485/*.w485p) ok=1 ;;
|
||||
*) ok=0 ;;
|
||||
esac
|
||||
name="${rel#rs485/}"
|
||||
case "${name%.w485p}" in ''|*[!a-z0-9-]*) ok=0 ;; esac
|
||||
if [ "$ok" -ne 1 ] || [ -L "$p" ] || [ ! -f "$p" ]; then
|
||||
echo "FATAL: SEED_DIR entry 'profiles/$rel' is not a plain profiles/rs485/<slug>.w485p file" >&2
|
||||
exit 1
|
||||
fi
|
||||
done < <(find "$entry" -mindepth 1 -print0)
|
||||
continue
|
||||
fi
|
||||
[ -f "$entry" ] || {
|
||||
echo "FATAL: SEED_DIR entry '$base' is not a plain file (refusing to copy it into userdata verbatim)" >&2
|
||||
exit 1
|
||||
|
||||
@@ -41,3 +41,24 @@ warden_slot() {
|
||||
esac
|
||||
echo "$slot"
|
||||
}
|
||||
|
||||
# PID 1 must answer busybox's reboot/poweroff/halt itself: they only signal
|
||||
# PID 1 (TERM, USR2, USR1), and the kernel drops any signal PID 1 has no
|
||||
# handler for. A panel's busybox init handles them; without this the rig
|
||||
# ignored a plain `reboot` (bfe-core1106-sdk#5). The -f forms skip init, and
|
||||
# the kernel still prints its orderly "reboot: Restarting system" line.
|
||||
# WARDEN_REBOOT_CMD / WARDEN_POWEROFF_CMD exist for the host test only.
|
||||
warden_trap_power_signals() {
|
||||
trap 'echo "init: reboot requested"; sync; ${WARDEN_REBOOT_CMD:-reboot -f}' TERM
|
||||
trap 'echo "init: poweroff requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR2
|
||||
trap 'echo "init: halt requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR1
|
||||
}
|
||||
|
||||
# Idle forever in a way a trapped signal interrupts at once: a foreground
|
||||
# `sleep` would hold the trap until it returned, up to an hour later.
|
||||
warden_idle_forever() {
|
||||
while :; do
|
||||
sleep 3600 &
|
||||
wait $!
|
||||
done
|
||||
}
|
||||
|
||||
+18
-6
@@ -57,6 +57,16 @@ mount_fatal userdata /userdata
|
||||
mount_fatal "oem${slot}" /oem
|
||||
mkdir -p /userdata/warden
|
||||
|
||||
# A flow may seed an opt-in guest fixture before the UI and payload daemons
|
||||
# start. The file lives only in this disposable QEMU disk image. Fail the
|
||||
# boot if setup fails so a flow cannot pass against an unprepared guest.
|
||||
if [ -f /userdata/warden/qemu-flow-setup.sh ]; then
|
||||
if ! /bin/busybox sh /userdata/warden/qemu-flow-setup.sh; then
|
||||
echo "FATAL: QEMU flow setup failed"
|
||||
poweroff -f
|
||||
fi
|
||||
fi
|
||||
|
||||
# RS485: warden-modbus hardcodes /dev/ttyS4 at compile time; alias it to the
|
||||
# VM's RS485 pci-serial UART (needs the virt.fragment kernel). run.sh lists
|
||||
# the control channel's port first when there is one (warden.ctl on the
|
||||
@@ -105,14 +115,14 @@ if grep -qw warden.fwapply /proc/cmdline; then
|
||||
echo "init: OTA APPLY ENABLED (warden.fwapply)"
|
||||
fi
|
||||
# The same daemons the panel's SysV scripts start, in their S-number order
|
||||
# (S92 ai, S93 automation, S94 modbus, S95 mikrotik, S96 asic/starlink/
|
||||
# stratum, S97 flared), each with no arguments and no environment, exactly
|
||||
# as start-stop-daemon runs them there. A daemon that cannot live on -M virt
|
||||
# (S21 modbus, S22 automation, S92 ai, S95 mikrotik, S96 asic/starlink/
|
||||
# stratum, S97 flared; flare-edge#348), each with no arguments and no
|
||||
# environment, exactly as start-stop-daemon runs them there. A daemon that cannot live on -M virt
|
||||
# (warden-ai wants the NPU) exits into its log and the UI shows the same
|
||||
# "not running" it would show on a panel whose daemon died; that is the
|
||||
# panel's behaviour, not a rig substitute for it. warden-watchdog stays out:
|
||||
# it and a payload flared do not mix (README).
|
||||
for d in /usr/bin/warden-ai /usr/bin/warden-automation /usr/bin/warden-modbus \
|
||||
for d in /usr/bin/warden-modbus /usr/bin/warden-automation /usr/bin/warden-ai \
|
||||
/usr/bin/warden-mikrotik /usr/bin/warden-asic /usr/bin/warden-starlink \
|
||||
/usr/bin/warden-stratum /usr/bin/warden-flared; do
|
||||
if [ -x "$d" ]; then
|
||||
@@ -239,5 +249,7 @@ if grep -qw warden.shell /proc/cmdline; then
|
||||
poweroff -f
|
||||
fi
|
||||
|
||||
# Hold: daemons run, console idles, scenarios drive the VM from outside.
|
||||
while :; do sleep 3600; done
|
||||
# Hold: daemons run, console idles, scenarios drive the VM from outside. As
|
||||
# PID 1 this shell must honour reboot/poweroff/halt itself (#5).
|
||||
warden_trap_power_signals
|
||||
warden_idle_forever
|
||||
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
# The rig's /sbin/init starts the Warden daemons in the panel's S-number
|
||||
# order (flare-edge#348): warden-modbus (S21modbus) before warden-automation
|
||||
# (S22automation), since an automation's device command goes through
|
||||
# warden-modbus, and both before the other app backends and flared. Reads
|
||||
# the daemon list from the init script's own start loop.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
INIT="$HERE/../rootfs/sbin/init"
|
||||
FAIL=0
|
||||
|
||||
order=$(awk '
|
||||
/^for d in \/usr\/bin\/warden-/ { on = 1 }
|
||||
on {
|
||||
last = ($0 ~ /; do$/)
|
||||
for (i = 1; i <= NF; i++) if ($i ~ /^\/usr\/bin\/warden-/) { w = $i; sub(/;$/, "", w); print w }
|
||||
if (last) exit
|
||||
}' "$INIT")
|
||||
|
||||
want="/usr/bin/warden-modbus
|
||||
/usr/bin/warden-automation
|
||||
/usr/bin/warden-ai
|
||||
/usr/bin/warden-mikrotik
|
||||
/usr/bin/warden-asic
|
||||
/usr/bin/warden-starlink
|
||||
/usr/bin/warden-stratum
|
||||
/usr/bin/warden-flared"
|
||||
|
||||
if [ "$order" = "$want" ]; then
|
||||
echo "PASS: rig init starts the daemons in the panel's S-number order"
|
||||
else
|
||||
echo "FAIL: rig init daemon order differs from the panel's S-number order"
|
||||
diff <(printf '%s\n' "$want") <(printf '%s\n' "$order")
|
||||
FAIL=1
|
||||
fi
|
||||
exit "$FAIL"
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression test for bfe-core1106-sdk#5: the rig's PID 1 script ignored
|
||||
# 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. 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
|
||||
# script's output pipe open for an hour when a case fails.
|
||||
set -m
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
LIB="$HERE/../rootfs/etc/warden-lib.sh"
|
||||
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}"
|
||||
|
||||
# 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 "sleep $delay; . '$LIB'; warden_trap_power_signals; warden_idle_forever" &
|
||||
local pid=$!
|
||||
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
|
||||
sleep 0.1; n=$((n + 1))
|
||||
done
|
||||
if grep -qx "$want" "$out"; then
|
||||
echo "[PASS] $label"
|
||||
else
|
||||
echo "[FAIL] $label (got: $(tr '\n' ' ' < "$out"))"; FAIL=1
|
||||
fi
|
||||
kill -KILL -- "-$pid" 2>/dev/null
|
||||
wait "$pid" 2>/dev/null
|
||||
}
|
||||
|
||||
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"
|
||||
+71
-16
@@ -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"))
|
||||
@@ -244,6 +267,7 @@ def do_observed_tap(ctx, ax, ay):
|
||||
return True
|
||||
|
||||
send_events(ctx.s, ctx.f, [abs_ev("x", ax), abs_ev("y", ay), btn_ev(True)])
|
||||
ctx.tap_sent = True
|
||||
pressed = False
|
||||
try:
|
||||
pressed = wait_input_count(ctx, "presses", before.get("presses"))
|
||||
@@ -728,6 +752,12 @@ class Ctx:
|
||||
self.rs485_control = rs485_control
|
||||
self.outdir = outdir
|
||||
self.script_path = script_path
|
||||
# Set by drive() before each step: the command after this one, and the
|
||||
# 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:
|
||||
@@ -786,24 +816,36 @@ def verb_shot(ctx, lineno, cmd, args, line):
|
||||
|
||||
def verb_tap(ctx, lineno, cmd, args, line):
|
||||
x, y = int(args[0]), int(args[1])
|
||||
observed = do_observed_tap(ctx, to_axis(x, ctx.size), to_axis(y, ctx.size))
|
||||
return (("ok", "") if observed else
|
||||
("fail", "input press or release was not consumed within 2 seconds"))
|
||||
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):
|
||||
# A tap whose correct outcome is a reboot (the next step is
|
||||
# expect_reboot) can lose the control channel while its press/release
|
||||
# counts are still being polled: init tears warden-ui down first. Once
|
||||
# the press went out that is the tap working, not failing; the reboot
|
||||
# step judges the outcome (flare-edge#233). Anywhere else, or before
|
||||
# anything was sent, it stays a fatal step.
|
||||
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 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):
|
||||
@@ -829,10 +871,11 @@ def verb_expect_reboot(ctx, lineno, cmd, args, line):
|
||||
timeout = float(args[0])
|
||||
if not ctx.console_path:
|
||||
sys.exit(f"FATAL: {ctx.script_path}:{lineno}: '{cmd}' needs --console")
|
||||
try:
|
||||
start = os.path.getsize(ctx.console_path)
|
||||
except OSError:
|
||||
start = 0
|
||||
# From the start of the step BEFORE this one, not this one: the action
|
||||
# that reboots (a tap, usually) runs in that step, and a fast guest can
|
||||
# print its restart line before expect_reboot even begins (flare-edge#233).
|
||||
# A line from any earlier step still does not count.
|
||||
start = ctx.prev_step_console
|
||||
deadline = time.monotonic() + timeout
|
||||
|
||||
def console_since_start():
|
||||
@@ -1182,12 +1225,24 @@ def drive(s, f, script_path, outdir, size, ctl_path=None, console_path=None, ref
|
||||
console_path)
|
||||
console = ConsoleWatch(console_path)
|
||||
|
||||
def console_size():
|
||||
try:
|
||||
return os.path.getsize(console_path) if console_path else 0
|
||||
except OSError:
|
||||
return 0
|
||||
|
||||
steps = []
|
||||
for lineno, raw in enumerate(lines, 1):
|
||||
line = raw.split("#", 1)[0].strip()
|
||||
if not line:
|
||||
continue
|
||||
if line:
|
||||
steps.append((lineno, line))
|
||||
step_console = console_size()
|
||||
|
||||
for i, (lineno, line) in enumerate(steps):
|
||||
parts = line.split()
|
||||
cmd, args = parts[0], parts[1:]
|
||||
ctx.next_cmd = steps[i + 1][1].split()[0] if i + 1 < len(steps) else None
|
||||
ctx.prev_step_console, step_console = step_console, console_size()
|
||||
|
||||
handler = VERBS.get(cmd)
|
||||
if handler is None:
|
||||
|
||||
@@ -186,5 +186,42 @@ else
|
||||
fail "SEED_DIR: mkimage.sh rejected a valid hyphenated key (see $SCRATCH/mkimage6.log)"
|
||||
fi
|
||||
|
||||
# --- scenario 7: an installed RS485 profile, profiles/rs485/<slug>.w485p,
|
||||
# seeds into userdata/warden/profiles/rs485/ (flare-edge#387) ---
|
||||
SEED7="$SCRATCH/seed7"
|
||||
mkdir -p "$SEED7/profiles/rs485"
|
||||
printf '{"w485p_version":1}\n' > "$SEED7/profiles/rs485/acme-gen-ctl.w485p"
|
||||
OUT7="$SCRATCH/out7"
|
||||
if OUT="$OUT7" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED7" \
|
||||
bash "$QEMU_DIR/mkimage.sh" > "$SCRATCH/mkimage7.log" 2>&1; then
|
||||
UIMG7="$SCRATCH/userdata7.img"
|
||||
extract_userdata "$OUT7/disk.img" "$UIMG7"
|
||||
prof="$(debugfs -R "cat /warden/profiles/rs485/acme-gen-ctl.w485p" "$UIMG7" 2>/dev/null)"
|
||||
if [ "$prof" = '{"w485p_version":1}' ]; then
|
||||
pass "SEED_DIR: an installed profile seeds into profiles/rs485/"
|
||||
else
|
||||
fail "SEED_DIR: profiles/rs485/acme-gen-ctl.w485p = '$prof'"
|
||||
fi
|
||||
else
|
||||
fail "SEED_DIR: mkimage.sh rejected a profiles/rs485/<slug>.w485p seed (see $SCRATCH/mkimage7.log)"
|
||||
fi
|
||||
|
||||
# --- scenario 8: anything else under profiles/ fails closed ---
|
||||
for bad in "rs485/x.json" "rs485/Bad.w485p" "other/x.w485p" "rs485/sub/x.w485p" "rs485/link.w485p"; do
|
||||
SEED8="$SCRATCH/seed8"
|
||||
rm -rf "$SEED8"
|
||||
mkdir -p "$SEED8/profiles/$(dirname "$bad")"
|
||||
if [ "$bad" = rs485/link.w485p ]; then ln -s /etc/passwd "$SEED8/profiles/$bad"; else printf 'x\n' > "$SEED8/profiles/$bad"; fi
|
||||
OUT8="$SCRATCH/out8"
|
||||
rm -rf "$OUT8"
|
||||
err8="$(OUT="$OUT8" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED8" bash "$QEMU_DIR/mkimage.sh" 2>&1 1>/dev/null)"
|
||||
rc8=$?
|
||||
if [ "$rc8" -ne 0 ] && printf '%s' "$err8" | grep -qF "is not a plain profiles/rs485/<slug>.w485p file"; then
|
||||
pass "SEED_DIR: profiles/$bad fails closed"
|
||||
else
|
||||
fail "SEED_DIR: profiles/$bad gave rc=$rc8, stderr='$err8'"
|
||||
fi
|
||||
done
|
||||
|
||||
[ "$FAIL" -eq 0 ] && echo "ALL SEED_DIR TESTS PASSED" || echo "SEED_DIR TESTS FAILED"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
|
||||
@@ -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
|
||||
@@ -924,6 +970,68 @@ class ExpectReboot(unittest.TestCase):
|
||||
self.assertIn("without the kernel's orderly restart line", rows[-1]["detail"])
|
||||
|
||||
|
||||
class RebootTapRace(unittest.TestCase):
|
||||
"""flare-edge#233: a tap whose outcome is a reboot races init tearing
|
||||
warden-ui down. The control channel can close while the tap's press and
|
||||
release counts are still being polled, and the guest can print its restart
|
||||
line before expect_reboot starts. Both are the tap working."""
|
||||
|
||||
CONSOLE_LINE = b"init: reboot requested\n[ 17.8] reboot: Restarting system\n"
|
||||
|
||||
def run_race(self, script, console_before=b""):
|
||||
d = tempfile.mkdtemp(prefix="console.")
|
||||
console = os.path.join(d, "console.log")
|
||||
with open(console, "wb") as fh:
|
||||
fh.write(console_before)
|
||||
line = self.CONSOLE_LINE
|
||||
|
||||
class RebootingCtl(FakeCtl):
|
||||
"""First stats answers (the tap's baseline); the next one, the
|
||||
press poll, finds the guest already going down: the restart line
|
||||
is on the console and the channel is closed."""
|
||||
def send(self, cmd):
|
||||
if cmd == "stats" and self.stats_calls >= 1:
|
||||
with open(console, "ab") as fh:
|
||||
fh.write(line)
|
||||
raise RuntimeError("control channel closed")
|
||||
return super().send(cmd)
|
||||
|
||||
def rpc(sock, sock_file, obj):
|
||||
if obj.get("execute") == "query-status":
|
||||
raise RuntimeError("QMP connection closed")
|
||||
return fake_rpc(sock, sock_file, obj)
|
||||
|
||||
return run_script(script, ctl_cls=RebootingCtl, rpc_fn=rpc, console_path=console)
|
||||
|
||||
def test_reboot_tap_losing_the_channel_then_expect_reboot_passes(self):
|
||||
rc, by, rows = self.run_race("tap 10 10\nexpect_reboot 2\n")
|
||||
self.assertIsNone(rc, rows)
|
||||
self.assertEqual([r["status"] for r in rows], ["ok", "ok"], rows)
|
||||
self.assertIn("control channel closed", rows[0]["detail"])
|
||||
|
||||
def test_the_same_channel_loss_before_any_other_step_is_still_fatal(self):
|
||||
rc, by, rows = self.run_race("tap 10 10\nsleep 0\n")
|
||||
self.assertEqual(rows[0]["status"], "fatal", rows)
|
||||
|
||||
def test_a_restart_line_from_two_steps_back_still_does_not_count(self):
|
||||
# The restart line is already on the console before the script; the
|
||||
# reboot step may look back one step, not to the start of the run.
|
||||
d = tempfile.mkdtemp(prefix="console.")
|
||||
console = os.path.join(d, "console.log")
|
||||
with open(console, "wb") as fh:
|
||||
fh.write(b"reboot: Restarting system\n")
|
||||
|
||||
def rpc(sock, sock_file, obj):
|
||||
if obj.get("execute") == "query-status":
|
||||
raise RuntimeError("QMP connection closed")
|
||||
return fake_rpc(sock, sock_file, obj)
|
||||
|
||||
rc, by, rows = run_script("sleep 0\nexpect_reboot 1\n", rpc_fn=rpc,
|
||||
console_path=console)
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertIn("without the kernel's orderly restart line", rows[-1]["detail"])
|
||||
|
||||
|
||||
class FullscreenToggleTracksRealState(unittest.TestCase):
|
||||
"""qemu/tests/scripts/fullscreen-toggle-tracks-real-state.txt, offline:
|
||||
`home` clears the dashboard's real fullscreen state directly, and a
|
||||
|
||||
Reference in New Issue
Block a user