Compare commits
17
Commits
@@ -170,6 +170,14 @@ jobs:
|
||||
if command -v busybox >/dev/null; then
|
||||
WARDEN_TEST_SH="busybox sh" bash qemu/tests/ctl-bridge-test.sh
|
||||
fi
|
||||
- name: rig agent runs framed scripts under a deadline (flare-edge M9 soak-lite)
|
||||
# warden_agent against request lines on stdin; once more under
|
||||
# busybox sh, the rig's own shell.
|
||||
run: |
|
||||
bash qemu/tests/agent-test.sh
|
||||
if command -v busybox >/dev/null; then
|
||||
WARDEN_TEST_SH="busybox sh" bash qemu/tests/agent-test.sh
|
||||
fi
|
||||
- name: rig init boots through the shipped init chain (flare-edge#2210)
|
||||
# warden_init_chain against stub scripts and the warden.initchain
|
||||
# wiring in sbin/init; once more under busybox sh, the rig's own shell.
|
||||
@@ -274,6 +282,9 @@ jobs:
|
||||
bash qemu/build-busybox.sh
|
||||
QEMU_USER="qemu-arm" bash qemu/tests/busybox-panel-help.sh
|
||||
RIG_BUSYBOX=panel bash qemu/mkinitramfs.sh
|
||||
# A job without the cross compiler takes the binary as BUSYBOX,
|
||||
# checked by its .inputs (flare-edge flow jobs).
|
||||
RIG_BUSYBOX=panel BUSYBOX=qemu/out/busybox-armv7l-panel bash qemu/mkinitramfs.sh
|
||||
|
||||
kernel-symbols:
|
||||
# The symbol gate (rebuild M0, kernel_symbols_exist): expand the real
|
||||
|
||||
@@ -60,6 +60,7 @@ luckfox-sdk-patches/wifi/patches/ diffs against sysdrv/drv_ko/wifi/ (out-of-
|
||||
luckfox-sdk-patches/board/patches/ diffs against project/ and sysdrv/ build files (board .mk,
|
||||
build drivers, Makefiles, init overlays); may delete files
|
||||
luckfox-sdk-patches/buildroot/ our delta on the Buildroot tree (see "Buildroot" below)
|
||||
luckfox-sdk-patches/tests/ regression tests for the series (see "Regression tests")
|
||||
```
|
||||
|
||||
Paths inside each patch are relative to the vendor SDK root, so apply with
|
||||
@@ -102,6 +103,25 @@ tree alone. flare-edge's `tools/build-firmware.sh` runs it right after
|
||||
applying the patches, then stages `buildroot/files/` and applies
|
||||
`buildroot/patches/` onto the tree (issue #4).
|
||||
|
||||
## Regression tests
|
||||
|
||||
`tests/test-adbd-no-tcp.sh BASE_DIR PATCH_FILE|none` applies the board patch to
|
||||
a copy of the base tree and runs the android-tools rule of the Makefile under
|
||||
make. It checks the adbd TCP listener removal (flare-edge#3129), the rule's
|
||||
fail-closed behaviour (bfe-core1106-sdk#45) and the adbd rebuild gate as the
|
||||
Makefile evaluates it, including a changed source tarball (bfe-core1106-sdk#44,
|
||||
#46, #49). `BASE_DIR` is the luckfox base
|
||||
commit 824b817f8, `sysdrv/tools/board/android-tools` only:
|
||||
|
||||
git -C <luckfox-sdk> archive 824b817f8 sysdrv/tools/board/android-tools | tar -C BASE_DIR -xf -
|
||||
sh tests/test-adbd-no-tcp.sh BASE_DIR board/patches/0015-adbd-no-tcp-listener.patch
|
||||
sh tests/adbd-no-tcp-cases.sh BASE_DIR board/patches/0015-adbd-no-tcp-listener.patch
|
||||
|
||||
The toolchain is a stub: the compiler stub only creates its output file, so
|
||||
nothing is compiled. Run the test with `none` as the patch file to see the base
|
||||
fail. `adbd-no-tcp-cases.sh` runs the real patch (must pass), the unpatched base
|
||||
and four mutants of the patch (each must fail for the reason it names).
|
||||
|
||||
## Completeness check
|
||||
|
||||
flare-edge's `tools/verify-sdk-patches.sh` replays this series onto the vendor
|
||||
@@ -123,7 +143,7 @@ had to be fixed before it did. Each was measured on hardware, not inferred.
|
||||
|---|---|
|
||||
| `rockchip_display.c` | `malloc` -> `calloc`. `enabled_at_spl` is only ever assigned under `#ifdef CONFIG_SPL_BUILD`, so in U-Boot proper it read uninitialised heap. Garbage read as truthy meant `display_enable()` skipped the connector pre-enable/enable path -- the only path that reaches `backlight_enable()`. |
|
||||
| `pwm_backlight.c` | `args.args[2] & 1`. The DT has `pwms = <&pwm1 0 100000 50000>`; assigning `50000` to a `bool` polarity field inverted the PWM. Measured `DUTY=0x26e8` (99.6%) with `CTRL=0x13`; after the fix `CTRL=0x0b`. The backlight was running at 0.4%. |
|
||||
| `clk_rv1106.c` | Two bugs. `rv1106_clk_set_rate()` returned a stale `ret` instead of the computed `rate`, so it always reported 0 Hz. And `DCLK_VOP_DIV_MASK` is 5 bits (max ÷32) while `DIV_ROUND_UP(1188 MHz, 30 MHz) = 40` wrote 39, truncated to 7 -- **the VOP was running at 125 MHz, not 30**. Now clamps to 32, picks the closest parent, and retunes CPLL 1000 -> 960 MHz when neither divides evenly, giving exactly 30.000 MHz. |
|
||||
| `clk_rv1106.c` | Two bugs. `rv1106_clk_set_rate()` returned a stale `ret` instead of the computed `rate`, so it always reported 0 Hz. And `DCLK_VOP_DIV_MASK` is 5 bits (max /32) while `DIV_ROUND_UP(1188 MHz, 30 MHz) = 40` wrote 39, truncated to 7 -- **the VOP was running at 125 MHz, not 30**. Now clamps to 32, picks the closest parent, and retunes CPLL 1000 -> 960 MHz when neither divides evenly, giving exactly 30.000 MHz. |
|
||||
| `rockchip_panel.c` | `FLARE_PANEL_SETTLE_MS`: wait after scanout starts before switching the backlight on. See the comment in the file -- it distinguishes two artefacts that look similar and have different causes. |
|
||||
| `board.c` | Release `RGB_RES` (GPIO0_A1) at the top of `board_init()` instead of `board_late_init()`, and `FLARE_TRACE` instrumentation. `setup_download_mode()` is deliberately kept **first** in `board_late_init()`: moving the logo ahead of it pushed BOOT-key sampling from 1.18 s to ~4-5 s and the key had to be held for eight seconds. |
|
||||
| `rv1106-u-boot.dtsi` | `u-boot,spl-boot-order = <&emmc>`. It was `<&sdmmc, &spi_nor, &spi_nand, &emmc>` -- the only fitted medium was last. Walking the dead entries cost **267 ms** every boot: ~212 ms failing to identify a non-existent SPI-NAND (`unknown raw ID 0 0 0`) and ~57 ms probing an SD slot this board does not have (`sdmmc` is wired to the AIC8800 WiFi as SDIO). **This file is shared by every rv1106 U-Boot build in the tree**; an SD- or SPI-NAND-booting variant would no longer boot. |
|
||||
@@ -294,6 +314,28 @@ had masked it (the reproducibility gap `tools/build-firmware.sh` exists to close
|
||||
`sysdrv/source/uboot/u-boot/configs/` (it is a whole new file, not a diff);
|
||||
the board `.mk` patch is what references it by name.
|
||||
|
||||
### `board/patches/0015-adbd-no-tcp-listener.patch` (flare-edge#3129)
|
||||
|
||||
Rockchip's android-tools patch `0015-make-adb-tcp-function-default-enbale.patch`
|
||||
made `adb_main()` open TCP 5555 whenever USB is up, and the non-secure branch
|
||||
opened `tcp:5037` on 127.0.0.1. S50usbdevice starts adbd with no arguments, so
|
||||
every panel ran both (`0.0.0.0:5555` was reachable from the LAN). The patch
|
||||
adds `android-tools-patches/0017-no-adb-tcp-listener.patch`, which removes both
|
||||
calls from the device half of `adb_main()` and runs last in
|
||||
`android-tools.patch.sh`. USB stays the only transport.
|
||||
|
||||
It also changes the Makefile gate. adbd was rebuilt only when `out/usr/bin/adbd`
|
||||
was missing, so a patch-set change never reached an SDK tree that already held
|
||||
the binary (bfe-core1106-sdk#44). `adbd-current.sh` now compares a stamp in
|
||||
`out/.adbd-inputs` with a hash of the Makefile, the gate script, the patch set
|
||||
and the two adbd source tarballs, and the build writes that stamp.
|
||||
|
||||
The rule now stops at the first failed step (a debian series entry, an
|
||||
`android-tools.patch.sh` step run with `-e`, the build, or the copy into
|
||||
`out/usr/bin`), and the stamp is written last. A failed step therefore never
|
||||
leaves a stamp for an adbd that was not built from the patch set
|
||||
(bfe-core1106-sdk#45).
|
||||
|
||||
### `board/patches/0009` to `0013` (issue #4)
|
||||
|
||||
Deltas that lived only in the workstation SDK until issue #4. Each patch
|
||||
@@ -322,7 +364,7 @@ already carries 0004 and 0008.
|
||||
| fragment | why |
|
||||
|---|---|
|
||||
| `uboot/flare-display.config` | the DRM/panel/PWM symbols the logo path needs |
|
||||
| `uboot/flare-verbose.config` | `CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y` -- µs timestamps on every line. ~15 chars/line ~ 1.3 ms/line at 115200, so read instrumented timings as an upper bound |
|
||||
| `uboot/flare-verbose.config` | `CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y` -- us timestamps on every line. ~15 chars/line ~ 1.3 ms/line at 115200, so read instrumented timings as an upper bound |
|
||||
| `uboot/flare-bootcount.config` | boot-failure fallback to `altbootcmd=download` -> MaskRom |
|
||||
| `uboot/flare-spl-brom.config` | builds `spl_bootrom.o`; does *not* set `SPL_ROCKCHIP_BACK_TO_BROM`, which would flip `SPL_MMC_SUPPORT` off |
|
||||
| `kernel/flare-backlight.config` | `CONFIG_BACKLIGHT_PWM=y`. As `=m` the backlight class device does not exist until userspace `insmod`s it at ~3.3-3.7 s, which is when the logo is being replaced anyway |
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
Drop adbd TCP listeners and rebuild on patch change
|
||||
|
||||
Rockchip's 0015 android-tools patch made adbd open TCP 5555 whenever USB is
|
||||
up, and the non-secure branch also opened tcp:5037 on 127.0.0.1. S50usbdevice
|
||||
starts adbd with no arguments, so every panel ran both listeners: 0.0.0.0:5555
|
||||
(reachable from the LAN) and 127.0.0.1:5037. Found on bench panel 10.255.1.55
|
||||
(flare-edge#3129).
|
||||
|
||||
This patch adds android-tools-patches/0017-no-adb-tcp-listener.patch, which
|
||||
removes both calls from the device half of adb_main(), and applies it last in
|
||||
android-tools.patch.sh. USB stays the only transport, so the USB adbd path is
|
||||
unchanged.
|
||||
|
||||
It also closes a build gap (bfe-core1106-sdk#44). The Makefile rebuilt adbd
|
||||
only when out/usr/bin/adbd was missing, so a patch-set change never reached an
|
||||
image built on an SDK tree that already held the binary. The Makefile now
|
||||
gates adbd on adbd-current.sh: the build writes a stamp holding a hash of the
|
||||
Makefile, the gate script, the patch set and the two adbd source tarballs, and
|
||||
a missing or stale stamp rebuilds adbd (bfe-core1106-sdk#49).
|
||||
|
||||
The rule stops at the first failed step: a debian series entry, an
|
||||
android-tools.patch.sh step (run with -e), the build, or the copy into
|
||||
out/usr/bin. The stamp is written last, so no binary that was not built from
|
||||
the patch set gets one (bfe-core1106-sdk#45).
|
||||
|
||||
Regression tests: luckfox-sdk-patches/tests/test-adbd-no-tcp.sh runs the rule
|
||||
under make with stub toolchains. It checks the listeners, the fail-closed
|
||||
cases, the stamp, a source tarball change and the gate that the Makefile
|
||||
evaluates (bfe-core1106-sdk#46, #49). tests/adbd-no-tcp-cases.sh runs the real
|
||||
patch, the unpatched base and mutants that must fail.
|
||||
|
||||
diff --git a/sysdrv/tools/board/android-tools/Makefile b/sysdrv/tools/board/android-tools/Makefile
|
||||
index bb72255..7ec24f7 100644
|
||||
--- a/sysdrv/tools/board/android-tools/Makefile
|
||||
+++ b/sysdrv/tools/board/android-tools/Makefile
|
||||
@@ -23,6 +23,15 @@ PKG_TARBALL_DEBIAN := android-tools_4.2.2+git20130218-3ubuntu41.debian.tar.gz
|
||||
PKG_BIN := out
|
||||
PKG_INSTALL_BIN_DIR := $(CURRENT_DIR)/$(PKG_BIN)/usr/bin
|
||||
|
||||
+# flare-edge#3129: adbd is rebuilt whenever its inputs change. The stamp holds
|
||||
+# the hash of this Makefile, adbd-current.sh, the android-tools patch set and
|
||||
+# the two adbd source tarballs. An adbd without a matching stamp (left in out/
|
||||
+# by a build from other inputs) is built again from the regenerated source.
|
||||
+# The series, patch, build and copy steps stop the rule on failure; the stamp is
|
||||
+# written last, so no binary that was not built from these inputs gets one (bfe-core1106-sdk#45).
|
||||
+ADBD_STAMP := $(CURRENT_DIR)/$(PKG_BIN)/.adbd-inputs
|
||||
+ADBD_INPUTS := $(shell cat $(CURRENT_DIR)/Makefile $(CURRENT_DIR)/adbd-current.sh $(CURRENT_DIR)/$(PKG_PATCHES_ANDROID_TOOLS)/* $(CURRENT_DIR)/$(PKG_TARBALL_ANDROID_TOOLS) $(CURRENT_DIR)/$(PKG_TARBALL_DEBIAN) | sha256sum | cut -d' ' -f1)
|
||||
+
|
||||
PKG_DEP_OPENSSL := $(CURRENT_DIR)/../toolkits/openssl
|
||||
PKG_DEP_ZLIB := $(CURRENT_DIR)/../toolkits/zlib
|
||||
|
||||
@@ -36,7 +45,7 @@ PKG_CONF_OPTS += -mthumb -Wa,-mimplicit-it=thumb -mthumb-interwork
|
||||
endif
|
||||
|
||||
all: dep-openssl
|
||||
- @test -f $(PKG_INSTALL_BIN_DIR)/adbd || (\
|
||||
+ @sh $(CURRENT_DIR)/adbd-current.sh $(PKG_INSTALL_BIN_DIR)/adbd $(ADBD_STAMP) $(ADBD_INPUTS) || (\
|
||||
rm -rf $(CURRENT_DIR)/$(PKG_NAME_ANDROID_TOOLS); \
|
||||
tar -xf $(PKG_TARBALL_ANDROID_TOOLS); \
|
||||
tar -xf $(PKG_TARBALL_DEBIAN) -C $(PKG_NAME_ANDROID_TOOLS); \
|
||||
@@ -45,16 +54,17 @@ all: dep-openssl
|
||||
pushd $(CURRENT_DIR)/$(PKG_NAME_ANDROID_TOOLS)/; \
|
||||
cp -af $(CURRENT_DIR)/$(PKG_PATCHES_ANDROID_TOOLS)/* ./; \
|
||||
for item in `cat ./debian/patches/series`; do \
|
||||
- patch -p1 < ./debian/patches/$$item; \
|
||||
+ patch -p1 < ./debian/patches/$$item || exit 1; \
|
||||
done; \
|
||||
- $(SHELL) ./android-tools.patch.sh; \
|
||||
+ $(SHELL) -e ./android-tools.patch.sh || exit 1; \
|
||||
CC="$(SYSDRV_CROSS)-gcc" GCC="$(SYSDRV_CROSS)-gcc" CXX="$(SYSDRV_CROSS)-g++" CPP="$(SYSDRV_CROSS)-cpp" \
|
||||
CFLAGS="$(PKG_CONF_OPTS)" CPPFLAGS="$(PKG_CONF_OPTS)" \
|
||||
CXXFLAGS="$(PKG_CONF_OPTS)" LDFLAGS="$(PKG_CONF_OPTS) $(PKG_ADBD_BUILD_STATIC)" \
|
||||
make -j$(SYSDRV_JOBS) -C $(CURRENT_DIR)/$(PKG_NAME_ANDROID_TOOLS)/$(PKG_BIN) \
|
||||
SRCDIR=$(CURRENT_DIR)/$(PKG_NAME_ANDROID_TOOLS) \
|
||||
-f $(CURRENT_DIR)/$(PKG_NAME_ANDROID_TOOLS)/debian/makefiles/adbd.mk 1>/dev/null || exit -1; \
|
||||
- cp -f $(CURRENT_DIR)/$(PKG_NAME_ANDROID_TOOLS)/$(PKG_BIN)/adbd $(PKG_INSTALL_BIN_DIR)/ ; \
|
||||
+ cp -f $(CURRENT_DIR)/$(PKG_NAME_ANDROID_TOOLS)/$(PKG_BIN)/adbd $(PKG_INSTALL_BIN_DIR)/ || exit 1; \
|
||||
+ echo $(ADBD_INPUTS) > $(ADBD_STAMP) || exit 1; \
|
||||
popd; )
|
||||
$(SYSDRV_CROSS)-strip -s $(PKG_INSTALL_BIN_DIR)/adbd ;
|
||||
@mkdir -p $(PKG_BIN)/etc/init.d;
|
||||
diff --git a/sysdrv/tools/board/android-tools/adbd-current.sh b/sysdrv/tools/board/android-tools/adbd-current.sh
|
||||
new file mode 100644
|
||||
index 0000000..df4bd81
|
||||
--- /dev/null
|
||||
+++ b/sysdrv/tools/board/android-tools/adbd-current.sh
|
||||
@@ -0,0 +1,14 @@
|
||||
+#!/bin/sh
|
||||
+# adbd-current.sh ADBD STAMP INPUTS
|
||||
+# Exit 0 when the built adbd is current: it exists and its stamp holds the hash
|
||||
+# of the inputs it was built from (see the stamp logic in the Makefile). Any
|
||||
+# other state, including an adbd left by an older patch set, exits 1 so that
|
||||
+# the Makefile regenerates the android-tools source and builds again.
|
||||
+# flare-edge#3129, luckfox-sdk-patches/tests/test-adbd-no-tcp.sh.
|
||||
+adbd=$1
|
||||
+stamp=$2
|
||||
+inputs=$3
|
||||
+[ -f "$adbd" ] || exit 1
|
||||
+[ -f "$stamp" ] || exit 1
|
||||
+[ "$(cat "$stamp")" = "$inputs" ] || exit 1
|
||||
+exit 0
|
||||
diff --git a/sysdrv/tools/board/android-tools/android-tools-patches/0017-no-adb-tcp-listener.patch b/sysdrv/tools/board/android-tools/android-tools-patches/0017-no-adb-tcp-listener.patch
|
||||
new file mode 100644
|
||||
index 0000000..c487482
|
||||
--- /dev/null
|
||||
+++ b/sysdrv/tools/board/android-tools/android-tools-patches/0017-no-adb-tcp-listener.patch
|
||||
@@ -0,0 +1,42 @@
|
||||
+flare-edge#3129: no adbd TCP listener in the image
|
||||
+
|
||||
+Rockchip's 0015 patch made adb_main() open a TCP listener on 5555 whenever
|
||||
+USB is up (local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT)). The non-secure
|
||||
+branch also installs the tcp:5037 smartsocket listener, bound to 127.0.0.1.
|
||||
+S50usbdevice starts adbd with no arguments, so both listeners were live on
|
||||
+every panel: 0.0.0.0:5555 and 127.0.0.1:5037.
|
||||
+
|
||||
+This patch removes both calls. USB stays the only transport, so the USB adbd
|
||||
+path (the shell over the gadget) is unchanged. The regression test is
|
||||
+luckfox-sdk-patches/tests/test-adbd-no-tcp.sh.
|
||||
+
|
||||
+--- a/core/adbd/adb.c
|
||||
++++ b/core/adbd/adb.c
|
||||
+@@ -1298,13 +1298,9 @@
|
||||
+ capset(&header, cap);
|
||||
+
|
||||
+ D("Local port disabled\n");
|
||||
+- } else {
|
||||
+- char local_name[30];
|
||||
+- build_local_name(local_name, sizeof(local_name), server_port);
|
||||
+- if(install_listener(local_name, "*smartsocket*", NULL, 0)) {
|
||||
+- exit(1);
|
||||
+- }
|
||||
+- }
|
||||
++ }
|
||||
++ /* flare-edge#3129: the non-secure branch installs no smartsocket listener
|
||||
++ either (it was tcp:5037, bound to 127.0.0.1). adbd opens no TCP port. */
|
||||
+
|
||||
+ int usb = 0;
|
||||
+ if (access(USB_ADB_PATH, F_OK) == 0 || access(USB_FFS_ADB_EP0, F_OK) == 0) {
|
||||
+@@ -1327,8 +1323,8 @@
|
||||
+ //} else if (!usb)
|
||||
+ if (usb) {
|
||||
+ printf("Using USB\n");
|
||||
+- // listen on default port
|
||||
+- local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
|
||||
++ // flare-edge#3129: the image opens no TCP listener. USB is the only
|
||||
++ // transport; local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT) is not called.
|
||||
+ }
|
||||
+
|
||||
+ D("adb_main(): pre init_jdwp()\n");
|
||||
diff --git a/sysdrv/tools/board/android-tools/android-tools-patches/android-tools.patch.sh b/sysdrv/tools/board/android-tools/android-tools-patches/android-tools.patch.sh
|
||||
index 2cb01e6..1a0470a 100755
|
||||
--- a/sysdrv/tools/board/android-tools/android-tools-patches/android-tools.patch.sh
|
||||
+++ b/sysdrv/tools/board/android-tools/android-tools-patches/android-tools.patch.sh
|
||||
@@ -17,3 +17,4 @@ patch -p1 < 0014-Specify-login-shell-in-standard-way.patch
|
||||
patch -p1 < 0015-make-adb-tcp-function-default-enbale.patch
|
||||
patch -p1 < 0015-support-rsa-key-authentication.patch
|
||||
patch -p1 < 0016-fix-static-link-dl-lll_unlock_wait_private.patch
|
||||
+patch -p1 < 0017-no-adb-tcp-listener.patch
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
#!/bin/sh
|
||||
# adbd-no-tcp-cases.sh BASE_DIR PATCH_FILE
|
||||
#
|
||||
# Runs test-adbd-no-tcp.sh on the real patch (must PASS), on the unpatched base
|
||||
# (must FAIL), and on four mutants of the patch. Each mutant must FAIL, and its
|
||||
# FAIL line must name the reason given here:
|
||||
# gate-makefile-only ADBD_INPUTS hashes only the Makefile; the patch set and
|
||||
# the gate script are dropped (bfe-core1106-sdk#46)
|
||||
# no-fail-fast the rule ignores failed series, patch and copy steps,
|
||||
# so a failed 0017 hunk still stamps adbd (bfe-core1106-sdk#45)
|
||||
# copy-unchecked only the copy into out/usr/bin is unchecked, so a failed
|
||||
# copy still writes the stamp (bfe-core1106-sdk#45)
|
||||
# gate-no-tarballs ADBD_INPUTS drops the two source tarballs, so a changed
|
||||
# tarball keeps a stale adbd (bfe-core1106-sdk#49)
|
||||
# Usage and layout: see test-adbd-no-tcp.sh.
|
||||
# Exit 0 when every case behaves as expected, 1 otherwise, 2 on usage.
|
||||
set -u
|
||||
LC_ALL=C
|
||||
export LC_ALL
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "usage: $0 BASE_DIR PATCH_FILE" >&2
|
||||
exit 2
|
||||
fi
|
||||
HERE=$(cd "$(dirname "$0")" && pwd) || exit 2
|
||||
TEST=$HERE/test-adbd-no-tcp.sh
|
||||
BASE=$(cd "$1" && pwd) || exit 2
|
||||
PATCH=$(cd "$(dirname "$2")" && pwd)/$(basename "$2") || exit 2
|
||||
WORK=$(mktemp -d "${TMPDIR:-/tmp}/adbd-no-tcp-cases.XXXXXX") || exit 2
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
fail=0
|
||||
pass() { echo "PASS $1"; }
|
||||
bad() { echo "FAIL $1"; fail=1; }
|
||||
|
||||
# mutant NAME: writes $WORK/NAME.patch from PATCH with the sed script
|
||||
# $WORK/NAME.sed. Fails when the script changes nothing.
|
||||
mutant() {
|
||||
sed -f "$WORK/$1.sed" "$PATCH" > "$WORK/$1.patch" || return 1
|
||||
if cmp -s "$PATCH" "$WORK/$1.patch"; then return 1; fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# expect WANT LABEL PATCH [REASON]: runs the test on PATCH. The exit status must
|
||||
# be WANT. For a FAIL case, REASON must appear in one of the FAIL lines.
|
||||
expect() {
|
||||
log=$WORK/run-$(echo "$2" | tr -c 'a-zA-Z0-9' '_').log
|
||||
sh "$TEST" "$BASE" "$3" > "$log" 2>&1
|
||||
rc=$?
|
||||
if [ "$rc" != "$1" ]; then
|
||||
bad "$2 (exit $rc, want $1)"
|
||||
return
|
||||
fi
|
||||
if [ -n "${4:-}" ] && ! grep -q "^FAIL.*$4" "$log"; then
|
||||
bad "$2 (exit $rc, no FAIL line names: $4)"
|
||||
return
|
||||
fi
|
||||
pass "$2 (exit $rc)"
|
||||
}
|
||||
|
||||
# The mutant scripts. Each edits only the Makefile hunk of the patch, or the
|
||||
# gate line that carries ADBD_INPUTS.
|
||||
cat > "$WORK/gate-makefile-only.sed" <<'SEDEOF'
|
||||
s#^+ADBD_INPUTS := .*$#+ADBD_INPUTS := $(shell sha256sum $(CURRENT_DIR)/Makefile | cut -c1-64)#
|
||||
SEDEOF
|
||||
cat > "$WORK/no-fail-fast.sed" <<'SEDEOF'
|
||||
/^diff --git a\/sysdrv\/tools\/board\/android-tools\/Makefile /,/^diff --git a\/sysdrv\/tools\/board\/android-tools\/adbd-current.sh /{
|
||||
/^+/{
|
||||
s/ || exit 1//
|
||||
s/\$(SHELL) -e /$(SHELL) /
|
||||
}
|
||||
}
|
||||
SEDEOF
|
||||
cat > "$WORK/copy-unchecked.sed" <<'SEDEOF'
|
||||
/^diff --git a\/sysdrv\/tools\/board\/android-tools\/Makefile /,/^diff --git a\/sysdrv\/tools\/board\/android-tools\/adbd-current.sh /{
|
||||
/^+.*cp -f /s/ || exit 1//
|
||||
}
|
||||
SEDEOF
|
||||
|
||||
cat > "$WORK/gate-no-tarballs.sed" <<'SEDEOF'
|
||||
s#^+ADBD_INPUTS := .*$#+ADBD_INPUTS := $(shell cat $(CURRENT_DIR)/Makefile $(CURRENT_DIR)/adbd-current.sh $(CURRENT_DIR)/$(PKG_PATCHES_ANDROID_TOOLS)/* | sha256sum | cut -d' ' -f1)#
|
||||
SEDEOF
|
||||
|
||||
expect 0 "real patch" "$PATCH"
|
||||
expect 1 "unpatched base" none
|
||||
if mutant gate-makefile-only; then
|
||||
expect 1 "mutant gate-makefile-only" "$WORK/gate-makefile-only.patch" "ADBD_INPUTS is"
|
||||
else
|
||||
bad "mutant gate-makefile-only does not change the patch"
|
||||
fi
|
||||
if mutant no-fail-fast; then
|
||||
expect 1 "mutant no-fail-fast" "$WORK/no-fail-fast.patch" "stops before compile"
|
||||
else
|
||||
bad "mutant no-fail-fast does not change the patch"
|
||||
fi
|
||||
if mutant copy-unchecked; then
|
||||
expect 1 "mutant copy-unchecked" "$WORK/copy-unchecked.patch" "copy into out/usr/bin"
|
||||
else
|
||||
bad "mutant copy-unchecked does not change the patch"
|
||||
fi
|
||||
|
||||
if mutant gate-no-tarballs; then
|
||||
expect 1 "mutant gate-no-tarballs" "$WORK/gate-no-tarballs.patch" "ADBD_INPUTS is"
|
||||
else
|
||||
bad "mutant gate-no-tarballs does not change the patch"
|
||||
fi
|
||||
|
||||
if [ "$fail" = 0 ]; then
|
||||
echo "RESULT PASS"
|
||||
exit 0
|
||||
fi
|
||||
echo "RESULT FAIL"
|
||||
exit 1
|
||||
+293
@@ -0,0 +1,293 @@
|
||||
#!/bin/sh
|
||||
# test-adbd-no-tcp.sh BASE_DIR PATCH_FILE|none
|
||||
#
|
||||
# Regression test for flare-edge#3129 (adbd listened on TCP 5555 and on
|
||||
# 127.0.0.1:5037), bfe-core1106-sdk#44 (a change to the adbd patch set never
|
||||
# reached the image), bfe-core1106-sdk#45 (a failed patch or copy step still
|
||||
# stamped adbd current) and bfe-core1106-sdk#46 (the gate was tested by a copy
|
||||
# of its formula instead of by the Makefile) and bfe-core1106-sdk#49 (a changed
|
||||
# source tarball did not rebuild adbd).
|
||||
#
|
||||
# BASE_DIR holds sysdrv/tools/board/android-tools at the luckfox base commit
|
||||
# 824b817f8, as in the vendor checkout:
|
||||
# git -C <luckfox-sdk> archive 824b817f8 sysdrv/tools/board/android-tools | tar -C BASE_DIR -xf -
|
||||
# PATCH_FILE is luckfox-sdk-patches/board/patches/0015-adbd-no-tcp-listener.patch,
|
||||
# or "none" to check the unpatched base, which must FAIL.
|
||||
#
|
||||
# The android-tools rule of the Makefile runs for real under make, with stub
|
||||
# toolchains, so nothing is compiled: the compiler stub only creates its -o
|
||||
# file. The fail-closed cases each break one step and check that the rule stops
|
||||
# before the stamp is written. tests/adbd-no-tcp-cases.sh runs this test on the
|
||||
# real patch, on the base and on mutants of the patch.
|
||||
# Exit 0 PASS, 1 FAIL, 2 usage or missing input.
|
||||
set -u
|
||||
LC_ALL=C
|
||||
export LC_ALL
|
||||
|
||||
fail=0
|
||||
pass() { echo "PASS $1"; }
|
||||
bad() { echo "FAIL $1"; fail=1; }
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "usage: $0 BASE_DIR PATCH_FILE|none" >&2
|
||||
exit 2
|
||||
fi
|
||||
BASE=$1
|
||||
PATCH=$2
|
||||
if [ ! -d "$BASE/sysdrv/tools/board/android-tools" ]; then
|
||||
echo "no sysdrv/tools/board/android-tools under $BASE" >&2
|
||||
exit 2
|
||||
fi
|
||||
BASE=$(cd "$BASE" && pwd) || exit 2
|
||||
if [ "$PATCH" != none ]; then
|
||||
[ -f "$PATCH" ] || { echo "no patch file $PATCH" >&2; exit 2; }
|
||||
PATCH=$(cd "$(dirname "$PATCH")" && pwd)/$(basename "$PATCH")
|
||||
fi
|
||||
|
||||
WORK=$(mktemp -d "${TMPDIR:-/tmp}/adbd-no-tcp.XXXXXX") || exit 2
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
TREE=$WORK/tree
|
||||
mkdir -p "$TREE/sysdrv/tools/board" || exit 2
|
||||
cp -a "$BASE/sysdrv/tools/board/android-tools" "$TREE/sysdrv/tools/board/" || exit 2
|
||||
AT=$TREE/sysdrv/tools/board/android-tools
|
||||
|
||||
# 1. The board patch applies to the base tree.
|
||||
if [ "$PATCH" != none ]; then
|
||||
if (cd "$TREE" && git apply --check "$PATCH" && git apply "$PATCH") 2>"$WORK/apply.err"; then
|
||||
pass "board patch applies to the base tree"
|
||||
else
|
||||
bad "board patch does not apply to the base tree: $(head -3 "$WORK/apply.err")"
|
||||
echo "RESULT FAIL"; exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Stub toolchain for the rule: the compiler (also CXX and CPP), strip, and the
|
||||
# openssl and zlib sub-makes. The compiler stub logs each run to $STUB_LOG,
|
||||
# creates its -o output, and fails when STUB_CC_FAIL is set.
|
||||
STUB=$WORK/stub
|
||||
mkdir -p "$STUB/dep" || exit 2
|
||||
cat > "$STUB/cross-gcc" <<'STUBEOF'
|
||||
#!/bin/sh
|
||||
[ -n "${STUB_LOG:-}" ] && echo "cc $*" >> "$STUB_LOG"
|
||||
[ -n "${STUB_CC_FAIL:-}" ] && { echo "stub compiler: forced failure" >&2; exit 1; }
|
||||
out=
|
||||
while [ $# -gt 0 ]; do
|
||||
if [ "$1" = -o ]; then out=$2; shift; fi
|
||||
shift
|
||||
done
|
||||
[ -n "$out" ] && : > "$out"
|
||||
exit 0
|
||||
STUBEOF
|
||||
cp "$STUB/cross-gcc" "$STUB/cross-g++" || exit 2
|
||||
cp "$STUB/cross-gcc" "$STUB/cross-cpp" || exit 2
|
||||
printf '#!/bin/sh\nexit 0\n' > "$STUB/cross-strip" || exit 2
|
||||
printf 'all:\n\t@true\n' > "$STUB/dep/Makefile" || exit 2
|
||||
chmod 755 "$STUB/cross-gcc" "$STUB/cross-g++" "$STUB/cross-cpp" "$STUB/cross-strip" || exit 2
|
||||
|
||||
# run_make AT_DIR LOG: runs the rule of the Makefile in AT_DIR under make, with
|
||||
# the stubs. Sets RC (make's exit status) and CC_RUNS (compiler runs).
|
||||
run_make() {
|
||||
rm -f "$2.cc"
|
||||
(cd "$1" && STUB_LOG="$2.cc" make -f Makefile SYSDRV_PARAM=/dev/null \
|
||||
SYSDRV_CROSS="$STUB/cross" SYSDRV_JOBS=1 \
|
||||
PKG_DEP_OPENSSL="$STUB/dep" PKG_DEP_ZLIB="$STUB/dep" all) > "$2" 2>&1
|
||||
RC=$?
|
||||
CC_RUNS=0
|
||||
if [ -s "$2.cc" ]; then CC_RUNS=$(wc -l < "$2.cc" | tr -d ' '); fi
|
||||
}
|
||||
|
||||
# case_at NAME: a fresh copy of the patched android-tools tree; prints its path.
|
||||
case_at() {
|
||||
rm -rf "$WORK/case-$1"
|
||||
mkdir -p "$WORK/case-$1/sysdrv/tools/board" || return 1
|
||||
cp -a "$AT" "$WORK/case-$1/sysdrv/tools/board/" || return 1
|
||||
echo "$WORK/case-$1/sysdrv/tools/board/android-tools"
|
||||
}
|
||||
|
||||
# 2. The rule applies every debian series entry and every android-tools.patch.sh
|
||||
# step, builds adbd, and writes the stamp.
|
||||
GOOD=$(case_at good) || exit 2
|
||||
run_make "$GOOD" "$WORK/good.log"
|
||||
if [ "$RC" = 0 ] && [ "$CC_RUNS" -gt 0 ]; then
|
||||
pass "rule applies the debian series and android-tools.patch.sh, then builds adbd"
|
||||
else
|
||||
bad "rule does not build adbd from the patch set (rc $RC, compiler runs $CC_RUNS): $(grep -m1 -E 'FAILED|No such|Error' "$WORK/good.log")"
|
||||
fi
|
||||
|
||||
# 3. The device half of adb_main(), in the source the rule generated: the TCP
|
||||
# listeners must be gone, and the USB transport must stay.
|
||||
# Comments are stripped first: the source keeps commented-out calls, and a
|
||||
# comment that names a call is not a call.
|
||||
ADB=$GOOD/android-tools/core/adbd/adb.c
|
||||
awk '
|
||||
/^int adb_main\(/ { inmain = 1 }
|
||||
inmain && /^}/ { exit }
|
||||
inmain {
|
||||
if (incom) { if (index($0, "*/")) incom = 0; next }
|
||||
if (index($0, "/*")) { if (!index($0, "*/")) incom = 1; next }
|
||||
line = $0
|
||||
sub(/\/\/.*/, "", line)
|
||||
if (line ~ /^#if ADB_HOST/) { host = 1; next }
|
||||
if (host && line ~ /^#else/) { host = 0; dev = 1; next }
|
||||
if (dev && line ~ /^#endif/) { dev = 0; next }
|
||||
if (dev) print line
|
||||
}' "$ADB" > "$WORK/device-main.txt" 2>/dev/null
|
||||
if [ ! -s "$WORK/device-main.txt" ]; then
|
||||
bad "could not extract the device half of adb_main()"
|
||||
else
|
||||
if grep -q 'local_init' "$WORK/device-main.txt"; then
|
||||
bad "adb_main() device half still calls local_init (TCP 5555 listener)"
|
||||
else
|
||||
pass "adb_main() device half opens no TCP 5555 listener"
|
||||
fi
|
||||
if grep -q 'install_listener' "$WORK/device-main.txt"; then
|
||||
bad "adb_main() device half still installs a smartsocket listener (tcp:5037)"
|
||||
else
|
||||
pass "adb_main() device half installs no smartsocket listener"
|
||||
fi
|
||||
for need in 'usb_init()' 'Using USB' 'init_jdwp()'; do
|
||||
if grep -q "$need" "$WORK/device-main.txt"; then
|
||||
pass "adb_main() device half keeps: $need"
|
||||
else
|
||||
bad "adb_main() device half lost the USB path: $need"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# 4. The gate, as the Makefile evaluates it: ADBD_INPUTS must be the sha256 of
|
||||
# the Makefile, adbd-current.sh, the patch set and the two adbd source
|
||||
# tarballs, the five inputs that the stamp must match.
|
||||
# shellcheck disable=SC2016 # the make text must reach make unexpanded
|
||||
printf '%s\n' '$(info ADBD_INPUTS=$(ADBD_INPUTS))' > "$WORK/probe.mk" || exit 2
|
||||
probe=$(cd "$GOOD" && make -s -f Makefile -f "$WORK/probe.mk" SYSDRV_PARAM=/dev/null no-such-target 2>/dev/null | sed -n 's/^ADBD_INPUTS=//p')
|
||||
want=$(cd "$AT" && cat Makefile adbd-current.sh android-tools-patches/* android-tools_4.2.2+git20130218.orig.tar.xz android-tools_4.2.2+git20130218-3ubuntu41.debian.tar.gz 2>/dev/null | sha256sum | cut -d' ' -f1)
|
||||
if [ -n "$probe" ] && [ "$probe" = "$want" ]; then
|
||||
pass "ADBD_INPUTS is the sha256 of Makefile, adbd-current.sh, the patch set and the source tarballs"
|
||||
else
|
||||
bad "ADBD_INPUTS is '$probe', want '$want' (sha256 of Makefile, adbd-current.sh, the patch set and the source tarballs)"
|
||||
fi
|
||||
|
||||
# 5. The rule itself: a matching stamp with adbd present skips the build, and a
|
||||
# stale or missing stamp rebuilds it. The stamp must hold ADBD_INPUTS.
|
||||
if [ -n "$probe" ] && [ "$(cat "$GOOD/out/.adbd-inputs" 2>/dev/null)" = "$probe" ]; then
|
||||
pass "rule writes the stamp of its inputs after the build"
|
||||
else
|
||||
bad "rule did not write the stamp of its inputs after the build"
|
||||
fi
|
||||
run_make "$GOOD" "$WORK/skip.log"
|
||||
if [ "$RC" = 0 ] && [ "$CC_RUNS" = 0 ] && [ -n "$probe" ] && [ "$(cat "$GOOD/out/.adbd-inputs" 2>/dev/null)" = "$probe" ]; then
|
||||
pass "rule skips adbd when the stamp matches"
|
||||
else
|
||||
bad "rule did not skip adbd with a matching stamp (rc $RC, compiler runs $CC_RUNS)"
|
||||
fi
|
||||
echo "0000000000000000000000000000000000000000000000000000000000000000" > "$GOOD/out/.adbd-inputs" || exit 2
|
||||
run_make "$GOOD" "$WORK/stale.log"
|
||||
if [ "$RC" = 0 ] && [ "$CC_RUNS" -gt 0 ]; then
|
||||
pass "rule rebuilds adbd when the stamp is stale"
|
||||
else
|
||||
bad "rule did not rebuild adbd with a stale stamp (rc $RC, compiler runs $CC_RUNS)"
|
||||
fi
|
||||
rm -f "$GOOD/out/.adbd-inputs"
|
||||
run_make "$GOOD" "$WORK/nostamp.log"
|
||||
if [ "$RC" = 0 ] && [ "$CC_RUNS" -gt 0 ]; then
|
||||
pass "rule rebuilds adbd when there is no stamp"
|
||||
else
|
||||
bad "rule did not rebuild adbd without a stamp (rc $RC, compiler runs $CC_RUNS)"
|
||||
fi
|
||||
|
||||
# 5b. The source tarballs are inputs too: a changed tarball must rebuild adbd
|
||||
# when the Makefile, the gate script and the patch set are unchanged.
|
||||
D=$(case_at tarball) || exit 2
|
||||
run_make "$D" "$WORK/tarball-built.log"
|
||||
first_built=0
|
||||
if [ "$RC" = 0 ] && [ "$CC_RUNS" -gt 0 ]; then first_built=1; fi
|
||||
t=$D/android-tools_4.2.2+git20130218-3ubuntu41.debian.tar.gz
|
||||
tb=$WORK/tarball-edit
|
||||
rm -rf "$tb" && mkdir -p "$tb" || exit 2
|
||||
if [ "$first_built" = 1 ] && tar -xzf "$t" -C "$tb" && : > "$tb/debian/.tarball-changed" && tar -czf "$t.new" -C "$tb" debian && mv "$t.new" "$t"; then
|
||||
run_make "$D" "$WORK/tarball.log"
|
||||
if [ "$RC" = 0 ] && [ "$CC_RUNS" -gt 0 ]; then
|
||||
pass "rule rebuilds adbd when a source tarball changes"
|
||||
else
|
||||
bad "rule did not rebuild adbd after a source tarball change (rc $RC, compiler runs $CC_RUNS)"
|
||||
fi
|
||||
else
|
||||
bad "could not build the tarball case (first build or tarball edit failed)"
|
||||
fi
|
||||
|
||||
# 6. Fail closed. An injected failure must stop the rule with a non-zero status
|
||||
# and leave no stamp. The failures before the compile step must also stop the
|
||||
# rule before the compiler runs.
|
||||
check_closed() { # AT_DIR LOG PRE LABEL
|
||||
run_make "$1" "$2"
|
||||
stamp=absent
|
||||
[ -e "$1/out/.adbd-inputs" ] && stamp=written
|
||||
if [ "$RC" != 0 ] && [ "$stamp" = absent ] && { [ "$3" != pre ] || [ "$CC_RUNS" = 0 ]; }; then
|
||||
pass "$4"
|
||||
else
|
||||
bad "$4 (rc $RC, stamp $stamp, compiler runs $CC_RUNS): $(grep -m1 -E 'FAILED|No such|Error|forced|cannot|Is a directory' "$2")"
|
||||
fi
|
||||
}
|
||||
inject_drift() { # AT_DIR: one removed line of the 0017 hunk stops matching
|
||||
f=$1/android-tools-patches/0017-no-adb-tcp-listener.patch
|
||||
[ -f "$f" ] || return 1
|
||||
awk '{ if ($0 == "- build_local_name(local_name, sizeof(local_name), server_port);") $0 = $0 " /* drift */"; print }' "$f" > "$f.new" || return 1
|
||||
grep -q 'drift' "$f.new" || return 1
|
||||
mv "$f.new" "$f"
|
||||
}
|
||||
inject_middle() { # AT_DIR: a failing patch step ahead of the last step
|
||||
f=$1/android-tools-patches/android-tools.patch.sh
|
||||
[ -f "$f" ] || return 1
|
||||
awk 'NR == 4 { print "patch -p1 < 0000-no-such-patch.patch" } { print }' "$f" > "$f.new" || return 1
|
||||
mv "$f.new" "$f"
|
||||
}
|
||||
inject_series() { # AT_DIR: a debian series entry with no patch file behind it
|
||||
t=$1/android-tools_4.2.2+git20130218-3ubuntu41.debian.tar.gz
|
||||
d=$WORK/deb-series
|
||||
rm -rf "$d" && mkdir -p "$d" || return 1
|
||||
tar -xzf "$t" -C "$d" || return 1
|
||||
printf '\nno-such-debian-patch.patch\n' >> "$d/debian/patches/series" || return 1
|
||||
tar -czf "$t.new" -C "$d" debian || return 1
|
||||
mv "$t.new" "$t"
|
||||
}
|
||||
|
||||
D=$(case_at drift) || exit 2
|
||||
if inject_drift "$D"; then
|
||||
check_closed "$D" "$WORK/drift.log" pre "rule stops before compile when a 0017 hunk does not apply"
|
||||
else
|
||||
bad "could not inject a 0017 failure (no 0017 patch in the tree)"
|
||||
fi
|
||||
D=$(case_at middle) || exit 2
|
||||
if inject_middle "$D"; then
|
||||
check_closed "$D" "$WORK/middle.log" pre "rule stops before compile when a middle android-tools.patch.sh step fails"
|
||||
else
|
||||
bad "could not inject a failing android-tools.patch.sh step"
|
||||
fi
|
||||
D=$(case_at series) || exit 2
|
||||
if inject_series "$D"; then
|
||||
check_closed "$D" "$WORK/series.log" pre "rule stops before compile when a debian series entry does not apply"
|
||||
else
|
||||
bad "could not inject a failing debian series entry"
|
||||
fi
|
||||
D=$(case_at compile) || exit 2
|
||||
export STUB_CC_FAIL=1
|
||||
check_closed "$D" "$WORK/compile.log" any "rule stops and writes no stamp when the compiler fails"
|
||||
unset STUB_CC_FAIL
|
||||
D=$(case_at copy) || exit 2
|
||||
mkdir -p "$D/out/usr/bin/adbd" || exit 2
|
||||
check_closed "$D" "$WORK/copy.log" any "rule stops and writes no stamp when the copy into out/usr/bin fails"
|
||||
|
||||
# 7. The Makefile still parses (a parse error prints something other than
|
||||
# "No rule to make target").
|
||||
if (cd "$AT" && make -f Makefile SYSDRV_PARAM=/dev/null -n no-such-target 2>&1 | grep -q 'No rule to make target'); then
|
||||
pass "Makefile parses"
|
||||
else
|
||||
bad "Makefile does not parse"
|
||||
fi
|
||||
|
||||
if [ "$fail" = 0 ]; then
|
||||
echo "RESULT PASS"
|
||||
exit 0
|
||||
fi
|
||||
echo "RESULT FAIL"
|
||||
exit 1
|
||||
+7
-2
@@ -82,7 +82,11 @@ With a test-flavor `warden-ui` and `wthctl` (flare-edge `tools/wthctl.c`, the
|
||||
test hook client) in the payload as well, a flow's `override` step pins a
|
||||
state document inside the UI: qmp.py hands the request to the control bridge
|
||||
(`@hookdoc` pieces, then `@hook override`), which sends it to `test/req/ui`
|
||||
as bus user `testhook` and answers the hook's reply.
|
||||
as bus user `testhook` and answers the hook's reply. The run's first hook
|
||||
request waits until the hook answers a `ping` (retried while the bridge
|
||||
reports no answer, up to `HOOK_READY_S`): right after boot the UI is still
|
||||
taking the broker's retained replay, and an override sent then was lost
|
||||
(flare-edge #2602).
|
||||
|
||||
The VT cursor is kept off (`vt.global_cursor_default=0`): fbcon shares the
|
||||
virtio-gpu framebuffer with warden-ui and its blinking cursor would otherwise
|
||||
@@ -137,11 +141,12 @@ All take the virt-fragment `<zImage>`; `FLARE_EDGE=<checkout>` where noted.
|
||||
| `rootfs-overlay.sh` | - | offline, no VM: `mkimage.sh`'s `ROOTFS_OVERLAY` hook lays a directory of panel files (flare-edge's S03warden-accounts, S99lvgl, warden-ui-run) over the rootfs of both slots with their modes kept, beside the skeleton's own files; without it there is no `/etc/init.d`; an overlay that is not a directory, names anything but `etc/` and `usr/` at its top, or holds a symlink fails closed and writes no image; `ui-drive.sh --init-chain` refuses a missing directory or one without `etc/init.d/S99lvgl` before boot |
|
||||
| `init-chain-test.sh` | - | offline, no VM: `warden_init_chain` (rootfs/etc/warden-lib.sh) starts the executable `S<NN>*` scripts of a number range in name order, names a failing one and goes on, and counts them; `warden_rig_bus_owners` hands a bus credential to its account only when the rootfs has it; sbin/init runs S00-S09 before the bus and S10-S99 instead of the direct UI start on a `warden.initchain` boot (flare-edge #2210) |
|
||||
| `run-sh-args-test.sh` | - | offline, no VM: a fake `qemu-system-arm` captures run.sh's own argv and pins the ctl/rs485 pci-serial ordering contract rootfs/sbin/init's ttyS0-vs-ttyS1 alias depends on -- the ctl device always enumerates before rs485, warden.ctl only lands on the cmdline when --ctl is given, and an rs485 pci-serial device (real or null-backed) is always present so the port count never shifts |
|
||||
| `busybox-panel-test.sh` | - | offline, no VM: the panel BusyBox inputs (qemu/busybox/). panel.config carries every setting of the image's applet patch, rig.fragment changes only STATIC, USE_BB_PWD_GRP and USE_BB_SHADOW, a Kconfig rewrite of any setting and an applet the panel lacks fail the build, applets.txt and help.txt agree, and RIG_BUSYBOX refuses an unknown value or a prebuilt `BUSYBOX` (flare-edge#2210) |
|
||||
| `busybox-panel-test.sh` | - | offline, no VM: the panel BusyBox inputs (qemu/busybox/). panel.config carries every setting of the image's applet patch, rig.fragment changes only STATIC, USE_BB_PWD_GRP and USE_BB_SHADOW, a Kconfig rewrite of any setting and an applet the panel lacks fail the build, applets.txt and help.txt agree, and RIG_BUSYBOX refuses an unknown value, and accepts a prebuilt panel `BUSYBOX` only when its `.inputs` match this tree (flare-edge#2210) |
|
||||
| `busybox-panel-help.sh [BIN]` | an ARM runner (binfmt or `QEMU_USER=qemu-arm`) | the built panel BusyBox against the bench capture: its applet list and every applet's `--help` equal the panel's own binary's. CI runs it in qemu-tools after `build-busybox.sh` |
|
||||
| `console-shell-test.sh` | - | offline, no VM: `warden_console_shell` (warden.shell) runs `setsid cttyhack sh` where cttyhack exists, else `setsid -c sh` on the console tty read from sysfs (the panel BusyBox has no cttyhack), else a plain sh. CI runs it under bash's `sh` and busybox `sh` |
|
||||
| `ctl-bridge-test.sh` | - | offline, no VM: runs the control bridge (`warden_ctl_bridge` in rootfs/etc/warden-lib.sh) against a fake warden-ui that answers some commands late. A reply slower than the old 5 s bound still arrives (the bound is now 30 s, `WARDEN_CTL_WAIT_S`), a timeout answers `bridge: no reply from warden-ui ...` (qmp.py raises it as a rig fault), and a timed-out command's late reply is drained instead of being read as the next command's answer (flare-edge #1448). A fake `wthctl` stands in for the hook client behind `@hookdoc`/`@hook` (flare-edge #2054): the pieces join into one request whose args are used once, only plain words reach the client, and a missing client or a request with no reply answers a `bridge:` line. CI runs it under bash's `sh` and busybox `sh` |
|
||||
| `init-rig-bus-test.sh` | - | offline, no VM: `warden_rig_bus` in rootfs/etc/warden-lib.sh against stub brokers. No broker in the payload creates nothing; a broker that listens gets the panel's layout (the `bus.sock` link, a 0400 64-hex credential per bus user, a config without password file, ACL or plugin); a broker that exits or never listens is reported within the bound; init starts the bus before the payload daemons. `WARDEN_TEST_MOSQUITTO_DIR` adds a real mosquitto carrying one message between two users logged in by credential file (flare-edge #1754) |
|
||||
| `agent-test.sh` | - | offline, no VM: the rig agent (`warden_agent` in rootfs/etc/warden-lib.sh, armed by `run.sh --agent` and `warden.agent`) answers `@run ID SECS B64` with `<<BEGIN ID>>`, the base64 of the script's output and `<<END ID RC>>`; `@chunk` pieces join into one script used once; a script past its deadline is killed with its process group and answers 124; a malformed request answers one `<<ERR ...>>` line and runs nothing; init puts the agent's port after ctl and RS485. It is the guest shell of flare-edge `tools/soak/rig-qemu.py` (M9 soak-lite). CI runs it under bash's `sh` and busybox `sh` |
|
||||
| watchdog (`run.sh --watchdog`) | - | arm `/dev/watchdog`, don't pet: the VM resets ~30 s later (verified) |
|
||||
|
||||
Scenario fine print:
|
||||
|
||||
+12
-10
@@ -6,7 +6,9 @@
|
||||
#
|
||||
# Env:
|
||||
# OUT output dir (default qemu/out); the binary lands at
|
||||
# $OUT/busybox-armv7l-panel, its input key next to it
|
||||
# $OUT/busybox-armv7l-panel, its rebuild key (.key) and its
|
||||
# source inputs (.inputs, see qemu_busybox_panel_inputs in
|
||||
# lib.sh) next to it
|
||||
# CROSS_COMPILE cross toolchain prefix (default arm-linux-gnueabihf-)
|
||||
# BB_SRC_TARBALL a local busybox-$BB_SRC_VER.tar.bz2 (skips the download;
|
||||
# still verified against BB_SRC_SHA256)
|
||||
@@ -29,12 +31,8 @@ set -euo pipefail
|
||||
QEMU_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
BB_DIR="$QEMU_DIR/busybox"
|
||||
|
||||
BB_SRC_VER=1.37.0
|
||||
BB_SRC_URL="https://busybox.net/downloads/busybox-${BB_SRC_VER}.tar.bz2"
|
||||
# From https://busybox.net/downloads/busybox-1.37.0.tar.bz2.sha256, the same
|
||||
# pin as Buildroot 2025.02.8 package/busybox/busybox.hash.
|
||||
BB_SRC_SHA256=3311dff32e746499f4df0d5df04d7eb396382d7e108bb9250e7b519b837043a4
|
||||
|
||||
# The source pin (BB_SRC_VER, BB_SRC_URL, BB_SRC_SHA256) lives in lib.sh,
|
||||
# beside qemu_busybox_panel_inputs, which a prebuilt binary is checked by.
|
||||
# shellcheck source=qemu/lib.sh disable=SC1091
|
||||
. "$QEMU_DIR/lib.sh"
|
||||
|
||||
@@ -95,9 +93,7 @@ bb_check_applets() {
|
||||
bb_input_key() {
|
||||
local cc="$1"
|
||||
{
|
||||
echo "busybox $BB_SRC_VER $BB_SRC_SHA256"
|
||||
sha256sum "$BB_DIR/panel.config" "$BB_DIR/rig.fragment" "$BB_DIR/applets.txt" \
|
||||
"$BB_DIR"/patches/*.patch | awk '{print $1}'
|
||||
qemu_busybox_panel_inputs
|
||||
echo "$cc"
|
||||
"${cc}gcc" --version | head -n 1
|
||||
} | sha256sum | awk '{print $1}'
|
||||
@@ -117,9 +113,12 @@ bb_main() {
|
||||
mkdir -p "$out"
|
||||
key="$(bb_input_key "$cc")"
|
||||
if [ -f "$bin" ] && [ "$(cat "$bin.key" 2>/dev/null)" = "$key" ]; then
|
||||
qemu_busybox_panel_inputs > "$bin.inputs"
|
||||
qemu_log "panel busybox up to date ($bin)"
|
||||
return
|
||||
fi
|
||||
# A stale .inputs must never vouch for a binary while it is rebuilt.
|
||||
rm -f "$bin.inputs"
|
||||
|
||||
tar="${BB_SRC_TARBALL:-$out/busybox-${BB_SRC_VER}.tar.bz2}"
|
||||
qemu_fetch_verified "$BB_SRC_URL" "$BB_SRC_SHA256" "$tar" "busybox ${BB_SRC_VER} source"
|
||||
@@ -171,6 +170,9 @@ bb_main() {
|
||||
install -m 0755 "$src/busybox" "$bin.tmp"
|
||||
mv -f "$bin.tmp" "$bin"
|
||||
printf '%s\n' "$key" > "$bin.key"
|
||||
# For a job without the cross compiler: qemu_get_busybox accepts this
|
||||
# binary as BUSYBOX under RIG_BUSYBOX=panel when the inputs match its tree.
|
||||
qemu_busybox_panel_inputs > "$bin.inputs"
|
||||
qemu_log "panel busybox: $bin ($(sha256sum "$bin" | awk '{print $1}'))"
|
||||
}
|
||||
|
||||
|
||||
@@ -26,3 +26,11 @@ The inputs are pinned (source tarball sha256, these files); the output is not,
|
||||
because each host's compiler gives a different binary. The cache key in
|
||||
`$OUT/busybox-armv7l-panel.key` covers the tarball, these files and the
|
||||
compiler version.
|
||||
|
||||
A job without the cross compiler (a flare-edge flow job, given the binary its
|
||||
image build job made) sets `RIG_BUSYBOX=panel BUSYBOX=<binary>`. The build
|
||||
writes `<binary>.inputs` next to it: one sha256 over the source pin and these
|
||||
files, without the compiler (`qemu_busybox_panel_inputs` in qemu/lib.sh).
|
||||
`qemu_get_busybox` takes the prebuilt binary only when that file equals the
|
||||
value for its own tree, so a binary built from another config is refused
|
||||
rather than booted.
|
||||
|
||||
+42
-6
@@ -4,6 +4,14 @@
|
||||
|
||||
BB_VER=1.31.0
|
||||
BB_URL="https://busybox.net/downloads/binaries/${BB_VER}-defconfig-multiarch-musl/busybox-armv7l"
|
||||
# The panel BusyBox source (RIG_BUSYBOX=panel, qemu/build-busybox.sh). From
|
||||
# https://busybox.net/downloads/busybox-1.37.0.tar.bz2.sha256, the same pin as
|
||||
# Buildroot 2025.02.8 package/busybox/busybox.hash.
|
||||
BB_SRC_VER=1.37.0
|
||||
# Read by build-busybox.sh, which sources this file.
|
||||
# shellcheck disable=SC2034
|
||||
BB_SRC_URL="https://busybox.net/downloads/busybox-${BB_SRC_VER}.tar.bz2"
|
||||
BB_SRC_SHA256=3311dff32e746499f4df0d5df04d7eb396382d7e108bb9250e7b519b837043a4
|
||||
|
||||
qemu_log() { printf '\033[36m== %s\033[0m\n' "$*"; }
|
||||
|
||||
@@ -50,6 +58,19 @@ qemu_fetch_verified() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# The source inputs of the panel BusyBox, as one sha256: the pinned source
|
||||
# tarball and every committed file under qemu/busybox/ the build reads. The
|
||||
# compiler is not part of it (build-busybox.sh keys its rebuild on that too),
|
||||
# so a job without the cross compiler can check a binary another job built.
|
||||
# build-busybox.sh writes it next to the binary as <binary>.inputs.
|
||||
qemu_busybox_panel_inputs() {
|
||||
local d="$QEMU_DIR/busybox"
|
||||
{
|
||||
echo "busybox $BB_SRC_VER $BB_SRC_SHA256"
|
||||
(cd "$d" && sha256sum panel.config rig.fragment applets.txt patches/*.patch)
|
||||
} | sha256sum | awk '{print $1}'
|
||||
}
|
||||
|
||||
# Provide the rig's static armv7 busybox and set $BB to its path.
|
||||
#
|
||||
# RIG_BUSYBOX picks which one (flare-edge#2210):
|
||||
@@ -58,20 +79,35 @@ qemu_fetch_verified() {
|
||||
# verified against qemu/busybox.sha256
|
||||
# panel the image's BusyBox version and applet config, built
|
||||
# from source by qemu/build-busybox.sh (needs a cross
|
||||
# compiler; checked by its applet list, see there)
|
||||
# compiler; checked by its applet list, see there).
|
||||
# With $BUSYBOX set, that prebuilt panel binary is used
|
||||
# instead (a job without the cross compiler, given the
|
||||
# binary an earlier build job made): it is accepted only
|
||||
# when its $BUSYBOX.inputs, written by build-busybox.sh,
|
||||
# equals qemu_busybox_panel_inputs of this tree, so a
|
||||
# binary built from other config files is refused.
|
||||
# FAILS CLOSED: a missing pin refuses to build, never silently skips
|
||||
# verification, mirroring build/build-kernel.sh's tarball handling; an
|
||||
# unknown RIG_BUSYBOX, or $BUSYBOX with the panel build, is refused.
|
||||
# unknown RIG_BUSYBOX, or a prebuilt panel binary without matching inputs,
|
||||
# is refused.
|
||||
qemu_get_busybox() {
|
||||
local out="${OUT:-$QEMU_DIR/out}"
|
||||
mkdir -p "$out"
|
||||
case "${RIG_BUSYBOX:-multiarch}" in
|
||||
multiarch) ;;
|
||||
panel)
|
||||
[ -z "${BUSYBOX:-}" ] || {
|
||||
echo "FATAL: BUSYBOX=$BUSYBOX names a prebuilt binary; RIG_BUSYBOX=panel builds its own (unset one of them)" >&2
|
||||
exit 1
|
||||
}
|
||||
if [ -n "${BUSYBOX:-}" ]; then
|
||||
local want got
|
||||
want="$(qemu_busybox_panel_inputs)"
|
||||
got="$(cat "$BUSYBOX.inputs" 2>/dev/null || true)"
|
||||
if [ ! -f "$BUSYBOX" ] || [ "$got" != "$want" ]; then
|
||||
echo "FATAL: BUSYBOX=$BUSYBOX is not a panel BusyBox built from this tree's qemu/busybox/ ($BUSYBOX.inputs '${got:-missing}', want '$want'): run qemu/build-busybox.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
BB="$BUSYBOX"
|
||||
qemu_log "panel busybox: prebuilt $BB (inputs $want)"
|
||||
return
|
||||
fi
|
||||
OUT="$out" bash "$QEMU_DIR/build-busybox.sh"
|
||||
BB="$out/busybox-armv7l-panel"
|
||||
return
|
||||
|
||||
+2
-1
@@ -15,7 +15,8 @@
|
||||
# flare-edge build's rootfs.img/oem.img matched pair) into slot A instead of
|
||||
# the busybox skeleton; slot B keeps the skeleton as a known-good fallback.
|
||||
# Env:
|
||||
# BUSYBOX path to a local busybox binary (skips the download; still verified)
|
||||
# BUSYBOX path to a local busybox binary (skips the download; still verified;
|
||||
# with RIG_BUSYBOX=panel a prebuilt panel binary, checked by its .inputs)
|
||||
# RIG_BUSYBOX multiarch (default) or panel: the image's own BusyBox, built by
|
||||
# qemu/build-busybox.sh (see qemu/busybox/README.md)
|
||||
# OUT output dir (default: qemu/out); image at $OUT/disk.img
|
||||
|
||||
+2
-1
@@ -4,7 +4,8 @@
|
||||
# see qemu/lib.sh).
|
||||
#
|
||||
# Env:
|
||||
# BUSYBOX path to a local busybox binary (skips the download; still verified)
|
||||
# BUSYBOX path to a local busybox binary (skips the download; still verified;
|
||||
# with RIG_BUSYBOX=panel a prebuilt panel binary, checked by its .inputs)
|
||||
# RIG_BUSYBOX multiarch (default) or panel: the image's own BusyBox, built by
|
||||
# qemu/build-busybox.sh (see qemu/busybox/README.md)
|
||||
# OUT output dir (default: qemu/out); initramfs at $OUT/initramfs.cpio.gz
|
||||
|
||||
@@ -387,3 +387,113 @@ warden_init_chain() {
|
||||
done
|
||||
echo "$_wic_ran"
|
||||
}
|
||||
|
||||
# The rig agent (flare-edge M9 soak-lite, d10 6.5): a shell inside the guest
|
||||
# for a host-side rig that must read state and change it (tools/soak/rig-qemu.py:
|
||||
# bus reads and writes, the clock, /proc for metrics). /sbin/init runs it on
|
||||
# its own pci-serial port, only on a boot with warden.agent on the command
|
||||
# line (run.sh --agent). It is part of the rig rootfs, which no panel image
|
||||
# carries; the flow channels (ctl bridge, test hook) are untouched by it.
|
||||
#
|
||||
# One request per line on stdin, every answer framed so the host never needs
|
||||
# a timeout to know a reply is complete:
|
||||
#
|
||||
# @ping -> <<PONG>>
|
||||
# @chunk ID B64 -> <<OK ID BYTES>> appends B64 to ID's script text
|
||||
# @run ID SECS [B64] -> <<BEGIN ID>>, the base64 of the script's stdout
|
||||
# and stderr, <<END ID RC>>
|
||||
# anything else -> <<ERR reason>>
|
||||
#
|
||||
# The script is the base64 text of the @chunk lines for ID, then the @run
|
||||
# line's own B64, decoded and run by sh with stdin from /dev/null. The agent
|
||||
# port is a tty in cooked mode, which cuts a line at 4095 bytes, hence the
|
||||
# chunks. ID is [A-Za-z0-9_-] (1 to 32 characters), SECS 1 to 3600. A script
|
||||
# still running after SECS seconds is killed with its whole process group and
|
||||
# answers RC 124, as timeout(1) does; the panel BusyBox has no timeout applet.
|
||||
# WARDEN_AGENT_DIR exists for the host test only.
|
||||
warden_agent() {
|
||||
_wa_dir="${WARDEN_AGENT_DIR:-/tmp/warden-agent}"
|
||||
mkdir -p "$_wa_dir"
|
||||
while IFS= read -r _wa_line; do
|
||||
# A cooked tty may hand the line over with a trailing CR.
|
||||
_wa_line="${_wa_line%"$(printf '\r')"}"
|
||||
[ -n "$_wa_line" ] || continue
|
||||
set -f
|
||||
# shellcheck disable=SC2086 # split into words on purpose, globbing off
|
||||
set -- $_wa_line
|
||||
set +f
|
||||
case "$1" in
|
||||
@ping) echo "<<PONG>>" ;;
|
||||
@chunk)
|
||||
if [ "$#" -ne 3 ] || ! _wa_id_ok "$2" || ! _wa_b64_ok "$3"; then
|
||||
echo "<<ERR bad chunk>>"
|
||||
continue
|
||||
fi
|
||||
printf '%s' "$3" >> "$_wa_dir/$2.b64"
|
||||
echo "<<OK $2 $(wc -c < "$_wa_dir/$2.b64" | tr -d ' ')>>"
|
||||
;;
|
||||
@run)
|
||||
if [ "$#" -lt 3 ] || [ "$#" -gt 4 ] || ! _wa_id_ok "$2" ||
|
||||
! _wa_secs_ok "$3" || { [ "$#" -eq 4 ] && ! _wa_b64_ok "$4"; }; then
|
||||
echo "<<ERR bad run>>"
|
||||
continue
|
||||
fi
|
||||
[ "$#" -eq 4 ] && printf '%s' "$4" >> "$_wa_dir/$2.b64"
|
||||
_wa_run "$2" "$3"
|
||||
;;
|
||||
*) echo "<<ERR unknown request>>" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
_wa_id_ok() {
|
||||
case "$1" in ""|*[!A-Za-z0-9_-]*) return 1 ;; esac
|
||||
[ "${#1}" -le 32 ]
|
||||
}
|
||||
|
||||
_wa_b64_ok() {
|
||||
case "$1" in ""|*[!A-Za-z0-9+/=]*) return 1 ;; esac
|
||||
return 0
|
||||
}
|
||||
|
||||
_wa_secs_ok() {
|
||||
case "$1" in ""|*[!0-9]*) return 1 ;; esac
|
||||
[ "${#1}" -le 4 ] && [ "$1" -ge 1 ] && [ "$1" -le 3600 ]
|
||||
}
|
||||
|
||||
# _wa_run ID SECS: decode, run under the deadline, answer, forget ID.
|
||||
_wa_run() {
|
||||
_wr_b64="$_wa_dir/$1.b64"
|
||||
_wr_sh="$_wa_dir/$1.sh"
|
||||
_wr_out="$_wa_dir/$1.out"
|
||||
if [ ! -s "$_wr_b64" ] || ! base64 -d < "$_wr_b64" > "$_wr_sh" 2>/dev/null ||
|
||||
[ ! -s "$_wr_sh" ]; then
|
||||
rm -f "$_wr_b64" "$_wr_sh"
|
||||
echo "<<ERR bad script $1>>"
|
||||
return 0
|
||||
fi
|
||||
rm -f "$_wr_b64"
|
||||
# setsid: the script leads its own process group, so a timeout kills
|
||||
# every process it started, not only its shell.
|
||||
setsid sh "$_wr_sh" < /dev/null > "$_wr_out" 2>&1 &
|
||||
_wr_pid=$!
|
||||
_wr_n=0
|
||||
_wr_limit=$(($2 * 10))
|
||||
_wr_late=0
|
||||
while kill -0 "$_wr_pid" 2>/dev/null; do
|
||||
if [ "$_wr_n" -ge "$_wr_limit" ]; then
|
||||
kill -KILL "-$_wr_pid" 2>/dev/null || kill -KILL "$_wr_pid" 2>/dev/null
|
||||
_wr_late=1
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
_wr_n=$((_wr_n + 1))
|
||||
done
|
||||
wait "$_wr_pid" 2>/dev/null
|
||||
_wr_rc=$?
|
||||
[ "$_wr_late" = 1 ] && _wr_rc=124
|
||||
echo "<<BEGIN $1>>"
|
||||
[ -s "$_wr_out" ] && base64 < "$_wr_out"
|
||||
echo "<<END $1 $_wr_rc>>"
|
||||
rm -f "$_wr_sh" "$_wr_out"
|
||||
}
|
||||
|
||||
@@ -229,6 +229,28 @@ if grep -qw warden.ctl /proc/cmdline && [ -c /dev/ttyS0 ]; then
|
||||
) &
|
||||
fi
|
||||
|
||||
# Rig agent (run.sh --agent, warden.agent on the command line): a shell for a
|
||||
# host-side rig that reads and changes guest state, such as the QEMU soak rig
|
||||
# (flare-edge tools/soak/rig-qemu.py). Its pci-serial port comes after the
|
||||
# ctl port (when there is one) and the always-present RS485 port, so it is
|
||||
# ttyS2 with warden.ctl and ttyS1 without; the ctl/RS485 order above is
|
||||
# unchanged. Echo is turned off so the host reads only the agent's frames.
|
||||
# The protocol is warden_agent (/etc/warden-lib.sh). Rig rootfs only: no
|
||||
# panel image carries it.
|
||||
if grep -qw warden.agent /proc/cmdline; then
|
||||
if grep -qw warden.ctl /proc/cmdline; then agent=/dev/ttyS2; else agent=/dev/ttyS1; fi
|
||||
if [ -c "$agent" ]; then
|
||||
echo "init: rig agent on $agent"
|
||||
(
|
||||
exec 4<> "$agent"
|
||||
stty -echo <&4 2>/dev/null || echo "init: rig agent: stty -echo failed"
|
||||
warden_agent <&4 >&4 2>/dev/null
|
||||
) &
|
||||
else
|
||||
echo "init: rig agent: $agent missing (needs the virt.fragment kernel)"
|
||||
fi
|
||||
fi
|
||||
|
||||
if grep -qw warden.shell /proc/cmdline; then
|
||||
echo "warden.shell: interactive shell (exit powers off)"
|
||||
warden_console_shell
|
||||
|
||||
+14
-1
@@ -17,6 +17,10 @@
|
||||
# --ctl SOCK unix socket to warden-ui's debug channel (nav/page/hit),
|
||||
# bridged by init from a pci-serial port; the rig-side
|
||||
# twin of tools/warden-ctl over SSH on a real panel
|
||||
# --agent SOCK unix socket to the rig agent (warden_agent in
|
||||
# rootfs/etc/warden-lib.sh): a guest shell for host-side
|
||||
# rigs such as flare-edge tools/soak/rig-qemu.py; a third
|
||||
# pci-serial after ctl and rs485, so their order holds
|
||||
# --watchdog add i6300esb watchdog, reset on expiry (fragment kernel)
|
||||
# --qmp SOCK QMP unix socket (screendump, input-send-event, quit)
|
||||
# --display MODE off (default, -nographic) | on (gtk window) | headless
|
||||
@@ -38,7 +42,7 @@ QEMU_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
OUT="${OUT:-$QEMU_DIR/out}"
|
||||
|
||||
KERNEL="" INITRD="$OUT/initramfs.cpio.gz" DISK="" NO_DISK=0 SLOT="_a"
|
||||
RTC="" RS485="" CTL="" WATCHDOG=0 QMP="" DISPLAY_MODE="off" SHELL_FLAG=0 ALLOW_APPLY=0
|
||||
RTC="" RS485="" CTL="" AGENT="" WATCHDOG=0 QMP="" DISPLAY_MODE="off" SHELL_FLAG=0 ALLOW_APPLY=0
|
||||
SSH_PORT=2222 HTTP_PORT=8080 API_PORT=28443
|
||||
EXTRA=()
|
||||
EXTRA_APPEND=""
|
||||
@@ -53,6 +57,7 @@ while [ $# -gt 0 ]; do
|
||||
--rtc) RTC="${2:?}"; shift 2 ;;
|
||||
--rs485) RS485="${2:?}"; shift 2 ;;
|
||||
--ctl) CTL="${2:?}"; shift 2 ;;
|
||||
--agent) AGENT="${2:?}"; shift 2 ;;
|
||||
--watchdog) WATCHDOG=1; shift ;;
|
||||
--qmp) QMP="${2:?}"; shift 2 ;;
|
||||
--display) DISPLAY_MODE="${2:?}"; shift 2 ;;
|
||||
@@ -143,6 +148,14 @@ if [ -n "$RS485" ]; then
|
||||
else
|
||||
ARGS+=( -chardev "null,id=rs485" -device "pci-serial,chardev=rs485" )
|
||||
fi
|
||||
# The rig agent comes LAST of the pci-serial ports, so ctl stays ttyS0 and
|
||||
# rs485 stays where init looks for it; init finds the agent at ttyS1 (no
|
||||
# ctl) or ttyS2 (with ctl), and only with warden.agent on the cmdline.
|
||||
if [ -n "$AGENT" ]; then
|
||||
APPEND="$APPEND warden.agent"
|
||||
ARGS+=( -chardev "socket,id=agent,path=$AGENT,server=on,wait=off"
|
||||
-device "pci-serial,chardev=agent" )
|
||||
fi
|
||||
[ -n "$QMP" ] && ARGS+=( -qmp "unix:$QMP,server=on,wait=off" )
|
||||
|
||||
case "$DISPLAY_MODE" in
|
||||
|
||||
Executable
+121
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env bash
|
||||
# Host test for the rig agent, warden_agent in qemu/rootfs/etc/warden-lib.sh
|
||||
# (flare-edge M9 soak-lite). Feeds request lines on stdin, as the host rig
|
||||
# does over the agent's serial port, and checks the framed answers: a script
|
||||
# runs and answers its output in base64 with its exit code, chunks join into
|
||||
# one script, a script past its deadline is killed with its children and
|
||||
# answers 124, and malformed requests answer one <<ERR ...>> line and run
|
||||
# nothing.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
LIB="$HERE/../rootfs/etc/warden-lib.sh"
|
||||
# Unquoted where it runs: WARDEN_TEST_SH may be "busybox sh", the rig's shell.
|
||||
SH="${WARDEN_TEST_SH:-sh}"
|
||||
WORK="$(mktemp -d)" || exit 1
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
FAIL=0
|
||||
CHECKS=0
|
||||
|
||||
check() { # check <label> <command...>
|
||||
CHECKS=$((CHECKS + 1))
|
||||
if "${@:2}"; then
|
||||
echo "[PASS] $1"
|
||||
else
|
||||
echo "[FAIL] $1"
|
||||
FAIL=1
|
||||
fi
|
||||
}
|
||||
|
||||
b64() { printf '%s' "$1" | base64 -w0; }
|
||||
|
||||
agent() { # agent <name> <lines...>: run the agent over the lines
|
||||
local name="$1"
|
||||
shift
|
||||
# $SH unquoted (it may be "busybox sh"); the quoted script is meant literally.
|
||||
# shellcheck disable=SC2086,SC2016
|
||||
printf '%s\n' "$@" |
|
||||
env WARDEN_AGENT_DIR="$WORK/agent-$name" \
|
||||
$SH -c '. "$1"; warden_agent' sh "$LIB" > "$WORK/$name.out" 2> "$WORK/$name.err"
|
||||
}
|
||||
|
||||
same() { # same <file> <expected lines...>
|
||||
local file="$1"
|
||||
shift
|
||||
diff <(printf '%s\n' "$@") "$file" > "$WORK/diff" || { cat "$WORK/diff"; return 1; }
|
||||
}
|
||||
|
||||
# The body between <<BEGIN ID>> and <<END ID ...>>, decoded.
|
||||
body() { # body <file> <id>
|
||||
awk -v b="<<BEGIN $2>>" -v e="<<END $2 " '$0 == b {on = 1; next} index($0, e) == 1 {on = 0} on' "$1" |
|
||||
base64 -d
|
||||
}
|
||||
|
||||
agent basic @ping "@run a1 10 $(b64 'echo hello; echo oops >&2; exit 3')"
|
||||
check "ping and a run answer framed lines" \
|
||||
grep -qx '<<PONG>>' "$WORK/basic.out"
|
||||
check "the run ends with its exit code" grep -qx '<<END a1 3>>' "$WORK/basic.out"
|
||||
check "stdout and stderr come back in base64" \
|
||||
same <(body "$WORK/basic.out" a1) hello oops
|
||||
|
||||
# Chunks: the script text arrives in pieces, then @run with no B64 of its own
|
||||
# and once more with a last piece on the run line.
|
||||
# shellcheck disable=SC2016 # the guest's shell expands it, not this one
|
||||
script='i=0; while [ $i -lt 3 ]; do echo line$i; i=$((i + 1)); done'
|
||||
whole="$(b64 "$script")"
|
||||
agent chunks "@chunk c1 ${whole:0:20}" "@chunk c1 ${whole:20}" "@run c1 10" \
|
||||
"@chunk c2 ${whole:0:12}" "@run c2 10 ${whole:12}"
|
||||
check "chunks acknowledge the bytes so far" \
|
||||
grep -qx "<<OK c1 20>>" "$WORK/chunks.out"
|
||||
check "chunked script runs whole" same <(body "$WORK/chunks.out" c1) line0 line1 line2
|
||||
check "a last piece on the run line joins the chunks" \
|
||||
same <(body "$WORK/chunks.out" c2) line0 line1 line2
|
||||
check "a script's text is used once" \
|
||||
test -z "$(ls -A "$WORK/agent-chunks" 2>/dev/null)"
|
||||
|
||||
# Deadline: the script and the child it started both die; RC 124.
|
||||
start=$(date +%s)
|
||||
agent late "@run t1 1 $(b64 "sleep 30 & echo \$! > $WORK/child.pid; sleep 30")" @ping
|
||||
took=$(( $(date +%s) - start ))
|
||||
check "a script past its deadline answers 124" grep -qx '<<END t1 124>>' "$WORK/late.out"
|
||||
check "the deadline holds (took ${took}s)" test "$took" -le 5
|
||||
child="$(cat "$WORK/child.pid" 2>/dev/null)"
|
||||
# Gone or a zombie: in a CI job container PID 1 reaps nothing, so a killed
|
||||
# orphan stays a zombie that kill -0 still finds.
|
||||
gone() { [ ! -r "/proc/$1/stat" ] || [ "$(sed 's/.*) //' "/proc/$1/stat" | cut -d' ' -f1)" = Z ]; }
|
||||
check "the script's child is killed too" bash -c "[ -n '$child' ] && $(declare -f gone); sleep 0.5; gone '$child'"
|
||||
check "the agent answers after a timeout" grep -qx '<<PONG>>' "$WORK/late.out"
|
||||
|
||||
# Malformed requests: one error line each, nothing runs.
|
||||
touch_b64="$(b64 "touch $WORK/ran")"
|
||||
agent bad "@run bad/id 10 $touch_b64" "@run b1 0 $touch_b64" "@run b1 99999 $touch_b64" \
|
||||
"@run b1 10 not*base64" "@chunk b2" "@run b3 10" "frobnicate" "@run b4 10 $(b64 'x') extra" \
|
||||
"@run b5 10 ===="
|
||||
check "malformed requests answer one error line each" \
|
||||
same "$WORK/bad.out" '<<ERR bad run>>' '<<ERR bad run>>' '<<ERR bad run>>' '<<ERR bad run>>' \
|
||||
'<<ERR bad chunk>>' '<<ERR bad script b3>>' '<<ERR unknown request>>' '<<ERR bad run>>' \
|
||||
'<<ERR bad script b5>>'
|
||||
check "no malformed request ran anything" test ! -e "$WORK/ran"
|
||||
|
||||
# A trailing CR (a cooked tty line) is not part of the last word.
|
||||
agent cr "$(printf '@ping\r')" "$(printf '@run r1 10 %s\r' "$(b64 'echo ok')")"
|
||||
check "a trailing CR is ignored" bash -c "grep -qx '<<PONG>>' '$WORK/cr.out' && grep -qx '<<END r1 0>>' '$WORK/cr.out'"
|
||||
|
||||
# A request with glob characters in a word does not expand them.
|
||||
agent glob "@run * 10 $(b64 'echo no')"
|
||||
check "a glob word is not expanded" same "$WORK/glob.out" '<<ERR bad run>>'
|
||||
|
||||
# sbin/init arms the agent only on warden.agent, on the port after ctl and
|
||||
# RS485 (ttyS2 with warden.ctl, ttyS1 without), with echo off.
|
||||
INIT="$HERE/../rootfs/sbin/init"
|
||||
check "init arms the agent only with warden.agent" grep -q 'grep -qw warden.agent /proc/cmdline' "$INIT"
|
||||
check "init picks ttyS2 with ctl and ttyS1 without" \
|
||||
grep -q 'if grep -qw warden.ctl /proc/cmdline; then agent=/dev/ttyS2; else agent=/dev/ttyS1; fi' "$INIT"
|
||||
check "init turns echo off on the agent port" grep -q 'stty -echo <&4' "$INIT"
|
||||
|
||||
if [ "$FAIL" = 0 ]; then
|
||||
echo "agent tests: OK ($CHECKS checks)"
|
||||
else
|
||||
echo "agent tests: FAILED"
|
||||
exit 1
|
||||
fi
|
||||
@@ -108,10 +108,54 @@ if ! RIG_BUSYBOX=bogus run_get && grep -q 'RIG_BUSYBOX must be multiarch or pane
|
||||
else
|
||||
fail "an unknown RIG_BUSYBOX was accepted"
|
||||
fi
|
||||
if ! RIG_BUSYBOX=panel BUSYBOX=/nonexistent run_get && grep -q 'names a prebuilt binary' "$SCRATCH/get.err"; then
|
||||
pass "RIG_BUSYBOX=panel with BUSYBOX set is refused"
|
||||
|
||||
# 7b. A prebuilt panel binary (a flow job without the cross compiler) is taken
|
||||
# only with a .inputs equal to this tree's qemu_busybox_panel_inputs.
|
||||
inputs="$(QEMU_DIR="$QEMU_DIR" qemu_busybox_panel_inputs)"
|
||||
if [[ "$inputs" =~ ^[0-9a-f]{64}$ ]]; then
|
||||
pass "qemu_busybox_panel_inputs is one sha256"
|
||||
else
|
||||
fail "RIG_BUSYBOX=panel accepted a prebuilt BUSYBOX"
|
||||
fail "qemu_busybox_panel_inputs gave '$inputs'"
|
||||
fi
|
||||
mkdir -p "$SCRATCH/pre"
|
||||
printf 'stand-in\n' > "$SCRATCH/pre/bb"
|
||||
if ! RIG_BUSYBOX=panel BUSYBOX="$SCRATCH/pre/bb" run_get && grep -q 'is not a panel BusyBox built from' "$SCRATCH/get.err" &&
|
||||
grep -q "inputs 'missing'" "$SCRATCH/get.err"; then
|
||||
pass "a prebuilt panel BUSYBOX without .inputs is refused"
|
||||
else
|
||||
fail "a prebuilt panel BUSYBOX without .inputs was accepted"
|
||||
fi
|
||||
printf '%s\n' "$(printf '%s' "$inputs" | tr '0-9a-f' '1-9a-f0')" > "$SCRATCH/pre/bb.inputs"
|
||||
if ! RIG_BUSYBOX=panel BUSYBOX="$SCRATCH/pre/bb" run_get && grep -q 'is not a panel BusyBox built from' "$SCRATCH/get.err"; then
|
||||
pass "a prebuilt panel BUSYBOX built from other inputs is refused"
|
||||
else
|
||||
fail "a prebuilt panel BUSYBOX with other inputs was accepted"
|
||||
fi
|
||||
printf '%s\n' "$inputs" > "$SCRATCH/pre/bb.inputs"
|
||||
got_bb="$(RIG_BUSYBOX=panel BUSYBOX="$SCRATCH/pre/bb" QEMU_DIR="$QEMU_DIR" OUT="$SCRATCH/out" \
|
||||
bash -c '. "$QEMU_DIR/lib.sh"; set -euo pipefail; qemu_get_busybox >/dev/null; printf %s "$BB"' 2>"$SCRATCH/get.err")"
|
||||
if [ "$got_bb" = "$SCRATCH/pre/bb" ] && [ ! -e "$SCRATCH/out/busybox-armv7l-panel" ]; then
|
||||
pass "a prebuilt panel BUSYBOX with matching .inputs is used as is, nothing built"
|
||||
else
|
||||
fail "a prebuilt panel BUSYBOX with matching .inputs was not used (BB='$got_bb': $(cat "$SCRATCH/get.err"))"
|
||||
fi
|
||||
if ! RIG_BUSYBOX=panel BUSYBOX="$SCRATCH/pre/none" run_get && grep -q 'is not a panel BusyBox built from' "$SCRATCH/get.err"; then
|
||||
pass "a prebuilt panel BUSYBOX that does not exist is refused"
|
||||
else
|
||||
fail "a missing prebuilt panel BUSYBOX was accepted"
|
||||
fi
|
||||
# Every committed input file is in the inputs hash: a config edit changes it.
|
||||
mkdir -p "$SCRATCH/qcopy"
|
||||
cp -a "$QEMU_DIR/busybox" "$SCRATCH/qcopy/"
|
||||
printf '# CONFIG_TIMEOUT is not set\n' >> "$SCRATCH/qcopy/busybox/panel.config"
|
||||
other="$(QEMU_DIR="$SCRATCH/qcopy" qemu_busybox_panel_inputs)"
|
||||
first_patch="$(find "$SCRATCH/qcopy/busybox/patches" -maxdepth 1 -type f -name '*.patch' | sort | head -n 1)"
|
||||
printf 'x\n' >> "$first_patch"
|
||||
other2="$(QEMU_DIR="$SCRATCH/qcopy" qemu_busybox_panel_inputs)"
|
||||
if [ "$other" != "$inputs" ] && [ "$other2" != "$other" ]; then
|
||||
pass "a panel.config or patch edit changes qemu_busybox_panel_inputs"
|
||||
else
|
||||
fail "qemu_busybox_panel_inputs ignored a panel.config or patch edit"
|
||||
fi
|
||||
|
||||
# 8. No cross compiler: the build fails closed, it never falls back.
|
||||
|
||||
@@ -969,6 +969,8 @@ class Ctx:
|
||||
self.input_wait_s = 0.0
|
||||
# Stall probes run so far (STALL_REPORTS_MAX bounds them).
|
||||
self.stall_reports = 0
|
||||
# The UI's test hook answered a ping (hook_wait_ready).
|
||||
self.hook_ready = False
|
||||
|
||||
def need_ctl(self, lineno, cmd):
|
||||
if self.ctl is None:
|
||||
@@ -1200,6 +1202,49 @@ def hook_request(ctl, words, args):
|
||||
return ctl.send(f"@hook {words}")
|
||||
|
||||
|
||||
# The bridge's line for a hook request whose client got no reply (_wcb_hook
|
||||
# in rootfs/etc/warden-lib.sh).
|
||||
HOOK_NO_ANSWER = "bridge: hook request got no answer"
|
||||
# How long the run's first hook request waits for the UI's hook to answer a
|
||||
# ping, and the pause between two pings. Each ping is bounded by the hook
|
||||
# client itself (wthctl: 5 s for the UI).
|
||||
HOOK_READY_S = 90.0
|
||||
HOOK_READY_POLL_S = 1.0
|
||||
|
||||
|
||||
def hook_wait_ready(ctx):
|
||||
"""Wait, once per run, until the UI's test hook answers a `ping` -> None,
|
||||
or the fatal detail when it never did.
|
||||
|
||||
The hook takes requests from the device bus, which the UI drains under a
|
||||
per-tick budget (libwardenbus WBUS_TICK_PACKETS / WBUS_TICK_BUDGET_US).
|
||||
Right after boot it is still taking the broker's retained replay, and a
|
||||
request queued behind it misses both the client's 5 s bound and its own
|
||||
5 s message expiry: an override sent then was lost, or applied with its
|
||||
reply lost (flare-edge #2602). ping changes nothing, so it is the one
|
||||
request that is safe to repeat; the step's own request is sent once,
|
||||
after a ping came back. Replies come back in request order, so a late
|
||||
answer to an earlier ping is gone before that request goes out.
|
||||
|
||||
Anything other than "no answer" ends the wait: a missing client or a
|
||||
reply that is not JSON is reported by the step's own request."""
|
||||
if ctx.hook_ready:
|
||||
return None
|
||||
deadline = time.monotonic() + HOOK_READY_S
|
||||
pings = 0
|
||||
while True:
|
||||
pings += 1
|
||||
reply = hook_request(ctx.ctl, "ping", {})
|
||||
if not reply.startswith(HOOK_NO_ANSWER):
|
||||
break
|
||||
if time.monotonic() >= deadline:
|
||||
return (f"the UI test hook answered no ping in {HOOK_READY_S:.0f} s "
|
||||
f"({pings} sent): {reply}")
|
||||
time.sleep(HOOK_READY_POLL_S)
|
||||
ctx.hook_ready = judge_hook_reply(reply)[0] == "ok"
|
||||
return None
|
||||
|
||||
|
||||
def judge_hook_reply(reply):
|
||||
"""(status, detail) for a hook reply: ok:true passes, ok:false fails with
|
||||
the hook's err, and anything else (a bridge line, no JSON) is fatal: the
|
||||
@@ -1230,6 +1275,9 @@ def verb_override(ctx, lineno, cmd, args, line):
|
||||
return "fatal", f"override document is not JSON: {doc_text!r}"
|
||||
if doc is not None and not isinstance(doc, (dict, list)):
|
||||
return "fatal", "override document must be an object, an array or null"
|
||||
not_ready = hook_wait_ready(ctx)
|
||||
if not_ready:
|
||||
return "fatal", not_ready
|
||||
return judge_hook_reply(hook_request(ctx.ctl, "override", {"topic": topic, "doc": doc}))
|
||||
|
||||
|
||||
|
||||
@@ -140,6 +140,36 @@ if run_case "$argv" --ctl "$SCRATCH/ctl.sock" --rs485 "$SCRATCH/rs.sock"; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- case: --agent (the rig agent, flare-edge M9 soak-lite) -> its
|
||||
# pci-serial comes LAST, after ctl and rs485, so neither moves, and
|
||||
# warden.agent lands on the cmdline only with the flag -------------------
|
||||
if ! grep -qw 'warden.agent' "$SCRATCH/argv-both.txt" && ! grep -qF 'id=agent' "$SCRATCH/argv-both.txt"; then
|
||||
pass "no --agent: no agent chardev and no warden.agent"
|
||||
else
|
||||
fail "no --agent: an agent chardev or warden.agent appeared unrequested"
|
||||
fi
|
||||
for combo in "agent-ctl:--ctl $SCRATCH/ctl.sock" "agent-alone:"; do
|
||||
name="${combo%%:*}" extra="${combo#*:}"
|
||||
argv="$SCRATCH/argv-$name.txt"
|
||||
# shellcheck disable=SC2086 # extra is a word list on purpose
|
||||
if run_case "$argv" $extra --rs485 "$SCRATCH/rs.sock" --agent "$SCRATCH/agent.sock"; then
|
||||
ag_ln="$(chardev_line "$argv" "socket,id=agent,path=$SCRATCH/agent.sock,")"
|
||||
rs_ln="$(chardev_line "$argv" "socket,id=rs485,path=$SCRATCH/rs.sock,")"
|
||||
ctl_ln="$(chardev_line "$argv" "socket,id=ctl,")"
|
||||
if [ -n "$ag_ln" ] && [ -n "$rs_ln" ] && [ "$rs_ln" -lt "$ag_ln" ] &&
|
||||
{ [ -z "$ctl_ln" ] || [ "$ctl_ln" -lt "$rs_ln" ]; }; then
|
||||
pass "$name: agent chardev (line $ag_ln) comes after rs485 (line $rs_ln) and ctl (${ctl_ln:-none})"
|
||||
else
|
||||
fail "$name: expected ctl < rs485 < agent, got ctl=$ctl_ln rs485=$rs_ln agent=$ag_ln"
|
||||
fi
|
||||
if grep -qF 'pci-serial,chardev=agent' "$argv" && grep -qw 'warden.agent' "$argv"; then
|
||||
pass "$name: agent pci-serial device and warden.agent present"
|
||||
else
|
||||
fail "$name: agent pci-serial device or warden.agent missing"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then
|
||||
echo "ALL RUN.SH ARGV TESTS PASSED"
|
||||
exit 0
|
||||
|
||||
@@ -892,6 +892,11 @@ class OverrideVerb(unittest.TestCase):
|
||||
HookCtl.sent = []
|
||||
HookCtl.answer = staticmethod(lambda words, args: '{"v":1,"ok":true,"data":{}}')
|
||||
HookCtl.refuse_pieces = False
|
||||
self.ready = (qmp.HOOK_READY_S, qmp.HOOK_READY_POLL_S)
|
||||
qmp.HOOK_READY_S, qmp.HOOK_READY_POLL_S = 0.0, 0.0
|
||||
|
||||
def tearDown(self):
|
||||
qmp.HOOK_READY_S, qmp.HOOK_READY_POLL_S = self.ready
|
||||
|
||||
def test_pin_and_unpin_reach_the_hook_as_one_request_each(self):
|
||||
seen = []
|
||||
@@ -906,6 +911,7 @@ class OverrideVerb(unittest.TestCase):
|
||||
self.assertIsNone(rc, rows)
|
||||
self.assertEqual([r["status"] for r in rows], ["ok", "ok"])
|
||||
self.assertEqual(seen, [
|
||||
("ping", {}),
|
||||
("override", {"topic": "io/state/failsafe",
|
||||
"doc": {"last_trip": {"why": "two words"}, "ack": False}}),
|
||||
("override", {"topic": "io/state/failsafe", "doc": None}),
|
||||
@@ -915,7 +921,8 @@ class OverrideVerb(unittest.TestCase):
|
||||
seen = []
|
||||
|
||||
def answer(words, args):
|
||||
seen.append(args)
|
||||
if words != "ping":
|
||||
seen.append(args)
|
||||
return '{"v":1,"ok":true}'
|
||||
HookCtl.answer = staticmethod(answer)
|
||||
doc = {"rows": ["x" * 100] * 120}
|
||||
@@ -924,7 +931,9 @@ class OverrideVerb(unittest.TestCase):
|
||||
ctl_cls=HookCtl)
|
||||
self.assertEqual(rows[0]["status"], "ok", rows)
|
||||
self.assertEqual(seen, [{"topic": "cfg/state/big", "doc": doc}])
|
||||
pieces = [c for c in HookCtl.sent if c.startswith("@hookdoc")]
|
||||
# The pieces after the readiness ping (which sends {} in one piece).
|
||||
after_ping = HookCtl.sent[HookCtl.sent.index("@hook ping") + 1:]
|
||||
pieces = [c for c in after_ping if c.startswith("@hookdoc")]
|
||||
self.assertGreater(len(pieces), 5)
|
||||
self.assertTrue(pieces[0].startswith("@hookdoc {"))
|
||||
self.assertTrue(all(c.startswith("@hookdoc+ ") for c in pieces[1:]))
|
||||
@@ -947,6 +956,53 @@ class OverrideVerb(unittest.TestCase):
|
||||
rc, by, rows = run_script('override io/state/x {"a":1}\n', ctl_cls=HookCtl)
|
||||
self.assertEqual(rows[0]["status"], "fatal", reply)
|
||||
|
||||
def test_the_first_override_waits_for_the_hook_to_answer_a_ping(self):
|
||||
# flare-edge #2602: right after boot the UI's hook answered nothing
|
||||
# for a while; the override must be sent once, after a ping came back.
|
||||
qmp.HOOK_READY_S = 60.0
|
||||
seen = []
|
||||
lost = [2]
|
||||
|
||||
def answer(words, args):
|
||||
seen.append(words)
|
||||
if words == "ping" and lost[0]:
|
||||
lost[0] -= 1
|
||||
return "bridge: hook request got no answer (client exit 2): wthctl: no reply (-5)"
|
||||
return '{"v":1,"ok":true,"data":{}}'
|
||||
HookCtl.answer = staticmethod(answer)
|
||||
rc, by, rows = run_script(
|
||||
'override io/state/failsafe {"a":1}\n'
|
||||
"override io/state/failsafe null\n", ctl_cls=HookCtl)
|
||||
self.assertIsNone(rc, rows)
|
||||
self.assertEqual([r["status"] for r in rows], ["ok", "ok"])
|
||||
self.assertEqual(seen, ["ping", "ping", "ping", "override", "override"])
|
||||
|
||||
def test_a_hook_that_never_answers_a_ping_is_fatal_and_gets_no_override(self):
|
||||
HookCtl.answer = staticmethod(lambda words, args: (
|
||||
"bridge: hook request got no answer (client exit 2): wthctl: no reply (-5)"))
|
||||
rc, by, rows = run_script('override io/state/x {"a":1}\nwake\n', ctl_cls=HookCtl)
|
||||
self.assertEqual([r["status"] for r in rows], ["fatal", "ok"])
|
||||
self.assertIn("answered no ping", rows[0]["detail"])
|
||||
self.assertIn("@hook ping", HookCtl.sent)
|
||||
self.assertNotIn("@hook override", HookCtl.sent)
|
||||
|
||||
def test_a_ping_that_is_not_ok_leaves_the_verdict_to_the_override(self):
|
||||
# A hook that answers but refuses ping (an older hook) is still a
|
||||
# hook: the override goes out and its own reply is judged, and the
|
||||
# next override pings again rather than trusting it.
|
||||
seen = []
|
||||
|
||||
def answer(words, args):
|
||||
seen.append(words)
|
||||
if words == "ping":
|
||||
return '{"v":1,"ok":false,"err":{"code":"E_UNKNOWN_VERB"}}'
|
||||
return '{"v":1,"ok":true}'
|
||||
HookCtl.answer = staticmethod(answer)
|
||||
rc, by, rows = run_script(
|
||||
'override io/state/x {"a":1}\noverride io/state/x null\n', ctl_cls=HookCtl)
|
||||
self.assertEqual([r["status"] for r in rows], ["ok", "ok"])
|
||||
self.assertEqual(seen, ["ping", "override", "ping", "override"])
|
||||
|
||||
def test_a_refused_piece_is_fatal_for_the_step_only(self):
|
||||
HookCtl.refuse_pieces = True
|
||||
rc, by, rows = run_script('override io/state/x {"a":1}\nwake\n', ctl_cls=HookCtl)
|
||||
|
||||
Reference in New Issue
Block a user