Compare commits
16
Commits
+27
-7
@@ -34,6 +34,10 @@
|
||||
# `make modules` (the zImage target alone generates no
|
||||
# Module.symvers, so per-dir M= builds cannot link) and
|
||||
# collects the listed dirs' modules into $WORK/modules-out.
|
||||
# Every collected module must carry this kernel's vermagic
|
||||
# (include/config/kernel.release), or the build fails. The
|
||||
# test-only drivers/warden-test directory (bench fault F5) also
|
||||
# enables CONFIG_WARDEN_TEST_HANG; no other caller lists it.
|
||||
#
|
||||
# Requires: `python` (not python3) on PATH: the SDK quirk; the CI runner provides
|
||||
# a project-local venv. Builds are SERIAL on the shared SDK box: never run two.
|
||||
@@ -43,6 +47,8 @@ KVER=6.18.46
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # build/
|
||||
# shellcheck source=build/lib-required-symbols.sh
|
||||
. "$HERE/lib-required-symbols.sh"
|
||||
# shellcheck source=build/lib-module-gate.sh
|
||||
. "$HERE/lib-module-gate.sh"
|
||||
REQ_SYMBOLS="$HERE/required-symbols.txt"
|
||||
PROBE_SYMBOLS="$HERE/probe-symbols.txt"
|
||||
REPO="$(cd "$HERE/.." && pwd)"
|
||||
@@ -133,6 +139,16 @@ if [ -n "${WARDEN_KCONFIG_FRAGMENT:-}" ]; then
|
||||
log "merging kconfig fragment $(basename "$FRAG")"
|
||||
( cd "$SRC" && ARCH=arm ./scripts/kconfig/merge_config.sh -m .config "$FRAG" )
|
||||
fi
|
||||
# Test-only modules. A directory listed in WARDEN_MODULES_COLLECT whose Kconfig
|
||||
# symbol defaults to n is enabled here, before olddefconfig, so the configuration
|
||||
# (and KCONFIG_SHA256) follows the request. A release or debug build never lists
|
||||
# one, so its configuration does not change through this block.
|
||||
for d in ${WARDEN_MODULES_COLLECT:-}; do
|
||||
sym="$(test_symbol_of "$d")"
|
||||
if [ -n "$sym" ]; then
|
||||
( cd "$SRC" && ./scripts/config --file .config --module "$sym" )
|
||||
fi
|
||||
done
|
||||
# CROSS_COMPILE defaults to the Luckfox SDK uclibc prefix (set SDK_TC to its bin/),
|
||||
# but the kernel is freestanding, so a caller may override with a generic arm cross
|
||||
# toolchain instead: e.g. CROSS_COMPILE=arm-linux-gnueabihf- (in Debian's
|
||||
@@ -143,6 +159,11 @@ if [ -n "${SDK_TC:-}" ]; then export PATH="$SDK_TC:$PATH"; fi
|
||||
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
|
||||
# A requested test module whose symbol did not survive olddefconfig (an unmet
|
||||
# dependency drops it without a word) fails here, not as a missing .ko later.
|
||||
for d in ${WARDEN_MODULES_COLLECT:-}; do
|
||||
require_test_config "$SRC/.config" "$d" || exit 1
|
||||
done
|
||||
|
||||
# Took-effect assertion for every symbol the platform needs. olddefconfig drops
|
||||
# a defconfig line whose dependencies are unmet, or whose symbol does not exist,
|
||||
@@ -223,14 +244,13 @@ if [ -n "${WARDEN_MODULES_COLLECT:-}" ]; then
|
||||
rm -rf "$MODOUT"; mkdir -p "$MODOUT"
|
||||
log "building modules (full set: needed for Module.symvers)"
|
||||
make -C "$SRC" ARCH=arm CROSS_COMPILE="$CROSS_COMPILE" CC="$KCC" -j"$JOBS" modules
|
||||
# The kernel's own release string; every collected module must carry it
|
||||
# (lib-module-gate.sh refuses a module that does not, before it is copied).
|
||||
KREL="$(tr -d '[:space:]' < "$SRC/include/config/kernel.release")"
|
||||
[ -n "$KREL" ] || { echo "FATAL: include/config/kernel.release is empty" >&2; exit 1; }
|
||||
for d in $WARDEN_MODULES_COLLECT; do
|
||||
[ -d "$SRC/$d" ] || { echo "FATAL: WARDEN_MODULES_COLLECT dir '$d' not in tree" >&2; exit 1; }
|
||||
n=0
|
||||
while IFS= read -r ko; do
|
||||
cp "$ko" "$MODOUT/"; n=$((n + 1))
|
||||
done < <(find "$SRC/$d" -name '*.ko')
|
||||
[ "$n" -gt 0 ] || { echo "FATAL: no .ko produced under '$d'" >&2; exit 1; }
|
||||
log "collected $n module(s) from $d"
|
||||
collect_modules "$SRC" "$d" "$KREL" "$MODOUT" || exit 1
|
||||
log "collected $COLLECTED module(s) from $d (vermagic $KREL)"
|
||||
done
|
||||
ls -la "$MODOUT"
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
# shellcheck shell=bash
|
||||
# Gate for the kernel modules a build collects (WARDEN_MODULES_COLLECT in
|
||||
# build-kernel.sh). Sourced, not run: reading it changes nothing.
|
||||
#
|
||||
# Every collected module must carry this kernel's vermagic, so a module built
|
||||
# against another tree, or a hand-copied .ko, cannot reach an image. A
|
||||
# directory that needs a test-only Kconfig symbol must find it =m after
|
||||
# olddefconfig. tests/test-hang/run-module-gate-tests.sh runs these functions
|
||||
# against fixtures, including the refusal paths.
|
||||
|
||||
# The test-only Kconfig symbol a collected directory needs (empty for the rest).
|
||||
# Release and debug builds list no test directory, so they get no symbol.
|
||||
test_symbol_of() {
|
||||
case "$1" in
|
||||
drivers/warden-test) echo WARDEN_TEST_HANG ;;
|
||||
*) : ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# module_vermagic_check <kernel release> <module file>: 0 when the module's
|
||||
# vermagic is "<release> " (the release, then a space), else 1 with a FATAL line.
|
||||
module_vermagic_check() {
|
||||
local krel=$1 ko=$2 vm
|
||||
if [ -z "$krel" ]; then
|
||||
echo "FATAL: kernel release is empty" >&2
|
||||
return 1
|
||||
fi
|
||||
# vermagic is a NUL-separated .modinfo string; one printable run per line.
|
||||
vm="$(tr -c '[:print:]' '\n' < "$ko" | grep -m1 '^vermagic=' || true)"
|
||||
case "$vm" in
|
||||
"vermagic=$krel "*) return 0 ;;
|
||||
'') echo "FATAL: $(basename "$ko") has no vermagic" >&2 ;;
|
||||
*) echo "FATAL: $(basename "$ko") vermagic '${vm#vermagic=}' is not this kernel's '$krel'" >&2 ;;
|
||||
esac
|
||||
return 1
|
||||
}
|
||||
|
||||
# collect_modules <source tree> <dir> <kernel release> <out dir>: copies every
|
||||
# .ko under <source tree>/<dir> into <out dir>, each only after it passed
|
||||
# module_vermagic_check. Sets COLLECTED to the count. Returns 1 at the first
|
||||
# module that fails, when the directory is missing, or when it yields none.
|
||||
collect_modules() {
|
||||
local src=$1 d=$2 krel=$3 out=$4 ko
|
||||
COLLECTED=0
|
||||
if [ ! -d "$src/$d" ]; then
|
||||
echo "FATAL: WARDEN_MODULES_COLLECT dir '$d' not in tree" >&2
|
||||
return 1
|
||||
fi
|
||||
while IFS= read -r ko; do
|
||||
module_vermagic_check "$krel" "$ko" || return 1
|
||||
cp "$ko" "$out/" || return 1
|
||||
COLLECTED=$((COLLECTED + 1))
|
||||
done < <(find "$src/$d" -name '*.ko')
|
||||
if [ "$COLLECTED" -eq 0 ]; then
|
||||
echo "FATAL: no .ko produced under '$d'" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# require_test_config <kernel .config> <dir>: a directory with a test symbol
|
||||
# must find it =m in the configuration after olddefconfig (an unmet dependency
|
||||
# drops the symbol without a word). Returns 1 with a FATAL line otherwise.
|
||||
require_test_config() {
|
||||
local cfg=$1 d=$2 sym
|
||||
sym="$(test_symbol_of "$d")"
|
||||
[ -n "$sym" ] || return 0
|
||||
if ! grep -qx "CONFIG_${sym}=m" "$cfg" 2>/dev/null; then
|
||||
echo "FATAL: $d needs CONFIG_${sym}=m, which did not survive olddefconfig" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,122 @@
|
||||
diff --git a/drivers/Kconfig b/drivers/Kconfig
|
||||
index 4915a63..979a6e7 100644
|
||||
--- a/drivers/Kconfig
|
||||
+++ b/drivers/Kconfig
|
||||
@@ -251,4 +251,6 @@ source "drivers/hte/Kconfig"
|
||||
|
||||
source "drivers/cdx/Kconfig"
|
||||
|
||||
+source "drivers/warden-test/Kconfig"
|
||||
+
|
||||
endmenu
|
||||
diff --git a/drivers/Makefile b/drivers/Makefile
|
||||
index 8e1ffa4..e120fc2 100644
|
||||
--- a/drivers/Makefile
|
||||
+++ b/drivers/Makefile
|
||||
@@ -197,3 +197,6 @@ obj-$(CONFIG_DPLL) += dpll/
|
||||
|
||||
obj-$(CONFIG_DIBS) += dibs/
|
||||
obj-$(CONFIG_S390) += s390/
|
||||
+
|
||||
+# Test-only modules (bench fault F5): built only when the test flavour enables them.
|
||||
+obj-$(CONFIG_WARDEN_TEST_HANG) += warden-test/
|
||||
diff --git a/drivers/warden-test/Kconfig b/drivers/warden-test/Kconfig
|
||||
new file mode 100644
|
||||
index 0000000..3c6b7d8
|
||||
--- /dev/null
|
||||
+++ b/drivers/warden-test/Kconfig
|
||||
@@ -0,0 +1,16 @@
|
||||
+# SPDX-License-Identifier: GPL-2.0-only
|
||||
+#
|
||||
+# Test-only modules for the WardenOS bench. The SDK builds a symbol here only
|
||||
+# when the caller lists its directory in WARDEN_MODULES_COLLECT (build/build-kernel.sh),
|
||||
+# which only the test flavour does. Release and debug kernels never enable them.
|
||||
+
|
||||
+config WARDEN_TEST_HANG
|
||||
+ tristate "Warden test: kernel hang on a debugfs write (bench fault F5)"
|
||||
+ depends on DEBUG_FS
|
||||
+ help
|
||||
+ Test-only. Creates /sys/kernel/debug/warden_hang/trigger. A write to it
|
||||
+ turns interrupts off and never returns, so warden-io stops beating and
|
||||
+ the board is reset by its watchdog (d07 fault F5). Never enable this in
|
||||
+ a release or debug kernel.
|
||||
+
|
||||
+ If unsure, say N.
|
||||
diff --git a/drivers/warden-test/Makefile b/drivers/warden-test/Makefile
|
||||
new file mode 100644
|
||||
index 0000000..c586de7
|
||||
--- /dev/null
|
||||
+++ b/drivers/warden-test/Makefile
|
||||
@@ -0,0 +1,4 @@
|
||||
+# SPDX-License-Identifier: GPL-2.0-only
|
||||
+# Test-only modules. Built only when their Kconfig symbol is =m, which build/build-kernel.sh
|
||||
+# sets for the test flavour (WARDEN_MODULES_COLLECT lists this directory).
|
||||
+obj-$(CONFIG_WARDEN_TEST_HANG) += warden_hang.o
|
||||
diff --git a/drivers/warden-test/warden_hang.c b/drivers/warden-test/warden_hang.c
|
||||
new file mode 100644
|
||||
index 0000000..3307532
|
||||
--- /dev/null
|
||||
+++ b/drivers/warden-test/warden_hang.c
|
||||
@@ -0,0 +1,62 @@
|
||||
+// SPDX-License-Identifier: GPL-2.0-only
|
||||
+/*
|
||||
+ * Warden test-only kernel hang (bench fault F5, d07 "Fault Matrix").
|
||||
+ *
|
||||
+ * A write to /sys/kernel/debug/warden_hang/trigger turns interrupts off on the
|
||||
+ * only core and never returns. Nothing runs after that: warden-io stops
|
||||
+ * beating, the HPMCU trips the relays once their deadline passes, and the
|
||||
+ * watchdog resets the board about 90 s after the hang.
|
||||
+ *
|
||||
+ * Test flavour only. build/build-kernel.sh enables CONFIG_WARDEN_TEST_HANG
|
||||
+ * when WARDEN_MODULES_COLLECT lists drivers/warden-test, and the module is
|
||||
+ * then collected into oem.img with the kernel's vermagic. Nothing loads it on
|
||||
+ * its own: the bench runner inserts it for the F5 case.
|
||||
+ */
|
||||
+#include <linux/debugfs.h>
|
||||
+#include <linux/fs.h>
|
||||
+#include <linux/init.h>
|
||||
+#include <linux/irqflags.h>
|
||||
+#include <linux/module.h>
|
||||
+#include <linux/printk.h>
|
||||
+#include <linux/processor.h>
|
||||
+
|
||||
+static struct dentry *hang_dir;
|
||||
+
|
||||
+static void __noreturn warden_hang_spin(void)
|
||||
+{
|
||||
+ local_irq_disable();
|
||||
+ for (;;)
|
||||
+ cpu_relax();
|
||||
+}
|
||||
+
|
||||
+static ssize_t trigger_write(struct file *file, const char __user *buf,
|
||||
+ size_t count, loff_t *ppos)
|
||||
+{
|
||||
+ /* Logged before interrupts go off; the spin below never returns. */
|
||||
+ pr_emerg("warden_hang: F5 kernel hang requested, interrupts off\n");
|
||||
+ warden_hang_spin();
|
||||
+}
|
||||
+
|
||||
+static const struct file_operations trigger_fops = {
|
||||
+ .owner = THIS_MODULE,
|
||||
+ .write = trigger_write,
|
||||
+ .llseek = noop_llseek,
|
||||
+};
|
||||
+
|
||||
+static int __init warden_hang_init(void)
|
||||
+{
|
||||
+ hang_dir = debugfs_create_dir("warden_hang", NULL);
|
||||
+ debugfs_create_file("trigger", 0200, hang_dir, NULL, &trigger_fops);
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static void __exit warden_hang_exit(void)
|
||||
+{
|
||||
+ debugfs_remove_recursive(hang_dir);
|
||||
+}
|
||||
+
|
||||
+module_init(warden_hang_init);
|
||||
+module_exit(warden_hang_exit);
|
||||
+
|
||||
+MODULE_LICENSE("GPL");
|
||||
+MODULE_DESCRIPTION("Warden test-only kernel hang (bench fault F5)");
|
||||
@@ -31,6 +31,7 @@ with `../build/warden_defconfig` -> `zImage` + `rv1106-warden.dtb`).
|
||||
| `80-misc-thermal-rtc-adc.patch` | tsadc, rtc-rockchip, saradc, trng, otp, gmac, goodix touch |
|
||||
| `82-arch-timer-vdso-phys-counter.patch` | arch timer: keep the arm32 vDSO clock off the virtual counter while the kernel times on the physical one (CNTVOFF left non-zero by the boot firmware, #35); checked by `tests/arch-timer/check-vdso-counter.py` |
|
||||
| `90-kconfig-no-python-symbol.patch` | drops `DRM_MSM_VALIDATE_XML` so the expanded `.config` (and `KCONFIG_SHA256`) does not depend on the host python (#19) |
|
||||
| `95-test-hang-module.patch` | test-only kernel hang module for bench fault F5 in `drivers/warden-test/` (`CONFIG_WARDEN_TEST_HANG`, default n); enabled only when `WARDEN_MODULES_COLLECT` lists `drivers/warden-test`, never in a release or debug build |
|
||||
|
||||
## License
|
||||
|
||||
|
||||
Executable
+91
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tests for run-test-hang-tests.sh when a tool its configuration checks need is
|
||||
# missing (the checks SKIP with a notice; they do not FAIL), and for the output
|
||||
# of a failed kernel tarball fetch (the end of its log is printed, because the
|
||||
# EXIT trap deletes the log).
|
||||
#
|
||||
# Hermetic: each case runs the script under a PATH that holds only the base
|
||||
# tools plus the fakes that case needs (python, the cross compiler, flex, bison,
|
||||
# curl), so the result does not depend on what this host has installed. Nothing
|
||||
# is compiled and nothing is downloaded.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TARGET="$HERE/run-test-hang-tests.sh"
|
||||
BASH_BIN="$(command -v bash)"
|
||||
TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
|
||||
FAIL=0
|
||||
ok() { printf '[PASS] %s\n' "$1"; }
|
||||
bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
# Base tools used by the script, its offline checks (the module gate fixtures
|
||||
# and the collection step use find and cp) and the fetch helper.
|
||||
BASE_TOOLS=(bash dirname basename mktemp rm mkdir cat tail grep sed awk tr head wc cut sort cmp sha256sum git tar xz env mv cp find)
|
||||
|
||||
# mkpath <dir> <tool...>: link each named tool found on this host into <dir>.
|
||||
mkpath() {
|
||||
local dir="$1" t p
|
||||
shift
|
||||
mkdir -p "$dir"
|
||||
for t in "$@"; do
|
||||
p="$(command -v "$t")" && ln -sf "$p" "$dir/$t"
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
# stub <dir> <name> <command>: an executable that runs <command>.
|
||||
stub() {
|
||||
printf '#!/bin/sh\n%s\n' "$3" > "$1/$2"
|
||||
chmod 0755 "$1/$2"
|
||||
}
|
||||
|
||||
# run_target <path-dir> <out> <tarball>: run the script with exactly that PATH.
|
||||
run_target() {
|
||||
env -i PATH="$1" TMPDIR="$TMP" HOME="$TMP" KERNEL_TARBALL="$3" CROSS_COMPILE=fake- \
|
||||
"$BASH_BIN" "$TARGET" >"$2" 2>&1
|
||||
}
|
||||
|
||||
# Cases 1 and 2: one of flex and bison is missing. The configuration checks SKIP.
|
||||
for missing in flex bison; do
|
||||
dir="$TMP/no-$missing"
|
||||
mkpath "$dir" "${BASE_TOOLS[@]}"
|
||||
stub "$dir" python 'exit 0'
|
||||
stub "$dir" fake-gcc 'exit 0'
|
||||
for present in flex bison; do
|
||||
[ "$present" = "$missing" ] || stub "$dir" "$present" 'exit 0'
|
||||
done
|
||||
run_target "$dir" "$TMP/no-$missing.out" "$TMP/absent.tar.xz"
|
||||
rc=$?
|
||||
if [ "$rc" -eq 0 ] \
|
||||
&& grep -q '^\[SKIP\] configuration checks: flex and bison' "$TMP/no-$missing.out" \
|
||||
&& ! grep -q '^\[FAIL\]' "$TMP/no-$missing.out"; then
|
||||
ok "without $missing the configuration checks SKIP and the script passes"
|
||||
else
|
||||
bad "without $missing the configuration checks did not SKIP cleanly (rc $rc)"
|
||||
cat "$TMP/no-$missing.out"
|
||||
fi
|
||||
done
|
||||
|
||||
# Case 3: every tool is present, the fetch fails. The script FAILs and prints
|
||||
# the end of the fetch log before it exits.
|
||||
dir="$TMP/bad-fetch"
|
||||
mkpath "$dir" "${BASE_TOOLS[@]}"
|
||||
stub "$dir" python 'exit 0'
|
||||
stub "$dir" fake-gcc 'exit 0'
|
||||
stub "$dir" flex 'exit 0'
|
||||
stub "$dir" bison 'exit 0'
|
||||
stub "$dir" curl 'echo "fake curl: refused in this test" >&2; exit 22'
|
||||
run_target "$dir" "$TMP/bad-fetch.out" "$TMP/nodir/linux.tar.xz"
|
||||
rc=$?
|
||||
if [ "$rc" -eq 1 ] \
|
||||
&& grep -q '^\[FAIL\] pinned kernel tarball could not be fetched' "$TMP/bad-fetch.out" \
|
||||
&& grep -q '^--- last 40 lines of fetch output ---$' "$TMP/bad-fetch.out" \
|
||||
&& grep -q 'fake curl: refused in this test' "$TMP/bad-fetch.out"; then
|
||||
ok "a failed fetch FAILs and prints the end of its log before exit"
|
||||
else
|
||||
bad "a failed fetch did not print its log tail (rc $rc)"
|
||||
cat "$TMP/bad-fetch.out"
|
||||
fi
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then echo "missing-tools: all checks passed"; else echo "missing-tools: FAILED"; fi
|
||||
exit "$FAIL"
|
||||
Executable
+180
@@ -0,0 +1,180 @@
|
||||
#!/usr/bin/env bash
|
||||
# Hermetic tests for the collected-module gate (build/lib-module-gate.sh): a
|
||||
# module whose vermagic is not this kernel's is refused before it is copied,
|
||||
# in the test-only list and in a release list (aic8800), and the test-only
|
||||
# directory needs CONFIG_WARDEN_TEST_HANG=m. Fixtures only: no kernel tree, no
|
||||
# compiler, no network. The refusal paths run with a module of the wrong
|
||||
# vermagic, which the grep-only checks in run-test-hang-tests.sh never did.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO="$(cd "$HERE/../.." && pwd)"
|
||||
TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
|
||||
FAIL=0
|
||||
ok() { printf '[PASS] %s\n' "$1"; }
|
||||
bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
# shellcheck source=build/lib-module-gate.sh
|
||||
. "$REPO/build/lib-module-gate.sh"
|
||||
|
||||
KREL=6.18.46
|
||||
GOOD="6.18.46 SMP preempt mod_unload ARMv7 p2v8"
|
||||
STALE="5.10.0 SMP preempt mod_unload ARMv7"
|
||||
|
||||
# mkko <file> <vermagic>: a fixture module whose .modinfo holds the vermagic as
|
||||
# a NUL-separated string, the way a built .ko does.
|
||||
mkko() {
|
||||
mkdir -p "$(dirname "$1")"
|
||||
printf '\177ELF\000\000\000modinfo\000license=GPL\000vermagic=%s\000depends=\000' "$2" > "$1"
|
||||
}
|
||||
|
||||
# expect <label> <want status> <command...>: the command's status is checked.
|
||||
expect() {
|
||||
local label=$1 want=$2 rc
|
||||
shift 2
|
||||
"$@" > "$TMP/out" 2>&1; rc=$?
|
||||
if [ "$rc" -eq "$want" ]; then ok "$label"; else bad "$label (status $rc, want $want): $(tr '\n' ' ' < "$TMP/out")"; fi
|
||||
}
|
||||
|
||||
# expect_msg <label> <want status> <text> <command...>: the status and the
|
||||
# FATAL text (a fixed string) must both be there.
|
||||
expect_msg() {
|
||||
local label=$1 want=$2 text=$3 rc
|
||||
shift 3
|
||||
"$@" > "$TMP/out" 2>&1; rc=$?
|
||||
if [ "$rc" -eq "$want" ] && grep -qF -- "$text" "$TMP/out"; then
|
||||
ok "$label"
|
||||
else
|
||||
bad "$label (status $rc, want $want, text '$text'): $(tr '\n' ' ' < "$TMP/out")"
|
||||
fi
|
||||
}
|
||||
|
||||
# --- the vermagic of one module ---------------------------------------------
|
||||
|
||||
mkko "$TMP/v/good.ko" "$GOOD"
|
||||
expect "a module of this kernel's vermagic passes" 0 module_vermagic_check "$KREL" "$TMP/v/good.ko"
|
||||
mkko "$TMP/v/stale.ko" "$STALE"
|
||||
expect_msg "a 5.10 module is refused, the vermagic named" 1 "is not this kernel's '6.18.46'" \
|
||||
module_vermagic_check "$KREL" "$TMP/v/stale.ko"
|
||||
mkko "$TMP/v/rc.ko" "6.18.46-rc1 SMP preempt mod_unload ARMv7"
|
||||
expect_msg "a release that only starts with this kernel's string is refused" 1 "is not this kernel's" \
|
||||
module_vermagic_check "$KREL" "$TMP/v/rc.ko"
|
||||
printf '\177ELF\000\000\000modinfo\000license=GPL\000depends=\000' > "$TMP/v/none.ko"
|
||||
expect_msg "a module with no vermagic is refused" 1 "has no vermagic" \
|
||||
module_vermagic_check "$KREL" "$TMP/v/none.ko"
|
||||
expect_msg "an empty kernel release is refused" 1 "kernel release is empty" \
|
||||
module_vermagic_check "" "$TMP/v/good.ko"
|
||||
|
||||
# --- the collected list: copied only when every module passes ----------------
|
||||
|
||||
# The test-only list: a module of this kernel is collected and counted.
|
||||
T1="$TMP/tree-good"
|
||||
mkko "$T1/drivers/warden-test/warden_hang.ko" "$GOOD"
|
||||
mkdir -p "$TMP/out-good"
|
||||
if collect_modules "$T1" drivers/warden-test "$KREL" "$TMP/out-good" \
|
||||
&& [ "$COLLECTED" = 1 ] && [ -f "$TMP/out-good/warden_hang.ko" ]; then
|
||||
ok "the test-only list collects the module of this kernel (count 1, copied)"
|
||||
else
|
||||
bad "the test-only list collects the module of this kernel (count ${COLLECTED:-unset})"
|
||||
fi
|
||||
|
||||
# The test-only list with a stale module: refused, and the stale .ko is not copied.
|
||||
T2="$TMP/tree-stale-test"
|
||||
mkko "$T2/drivers/warden-test/warden_hang.ko" "$STALE"
|
||||
mkdir -p "$TMP/out-stale-test"
|
||||
collect_modules "$T2" drivers/warden-test "$KREL" "$TMP/out-stale-test" > "$TMP/out" 2>&1; rc=$?
|
||||
if [ "$rc" -eq 1 ] && grep -qF "is not this kernel's '6.18.46'" "$TMP/out" \
|
||||
&& [ ! -e "$TMP/out-stale-test/warden_hang.ko" ]; then
|
||||
ok "a stale module in the test-only list is refused and not copied"
|
||||
else
|
||||
bad "a stale module in the test-only list is refused and not copied (status $rc): $(tr '\n' ' ' < "$TMP/out")"
|
||||
fi
|
||||
|
||||
# A release list (aic8800, as ci.yml lists it) gets the same gate: one stale
|
||||
# module among good ones refuses the list and the stale module is not copied.
|
||||
T3="$TMP/tree-stale-release"
|
||||
D3=drivers/net/wireless/aic8800
|
||||
mkko "$T3/$D3/aic8800_fdrv.ko" "$STALE"
|
||||
mkko "$T3/$D3/aic8800_btlpm.ko" "$GOOD"
|
||||
mkdir -p "$TMP/out-stale-release"
|
||||
collect_modules "$T3" "$D3" "$KREL" "$TMP/out-stale-release" > "$TMP/out" 2>&1; rc=$?
|
||||
if [ "$rc" -eq 1 ] && grep -qF "is not this kernel's" "$TMP/out" \
|
||||
&& [ ! -e "$TMP/out-stale-release/aic8800_fdrv.ko" ]; then
|
||||
ok "a stale module in a release list (aic8800) is refused and not copied"
|
||||
else
|
||||
bad "a stale module in a release list (aic8800) is refused and not copied (status $rc)"
|
||||
fi
|
||||
|
||||
# A good release list collects every module.
|
||||
T4="$TMP/tree-good-release"
|
||||
mkko "$T4/$D3/aic8800_fdrv.ko" "$GOOD"
|
||||
mkko "$T4/$D3/aic8800_btlpm.ko" "$GOOD"
|
||||
mkdir -p "$TMP/out-good-release"
|
||||
if collect_modules "$T4" "$D3" "$KREL" "$TMP/out-good-release" && [ "$COLLECTED" = 2 ]; then
|
||||
ok "a good release list collects both modules (count 2)"
|
||||
else
|
||||
bad "a good release list collects both modules (count ${COLLECTED:-unset})"
|
||||
fi
|
||||
|
||||
expect_msg "a listed directory missing from the tree is refused" 1 "not in tree" \
|
||||
collect_modules "$TMP/tree-absent" drivers/warden-test "$KREL" "$TMP/out-good"
|
||||
mkdir -p "$TMP/tree-empty/drivers/warden-test"
|
||||
expect_msg "a listed directory with no module is refused" 1 "no .ko produced" \
|
||||
collect_modules "$TMP/tree-empty" drivers/warden-test "$KREL" "$TMP/out-good"
|
||||
|
||||
# --- the test symbol: which directory needs it, and what it must be ----------
|
||||
|
||||
if [ "$(test_symbol_of drivers/warden-test)" = WARDEN_TEST_HANG ]; then
|
||||
ok "the test-only directory maps to CONFIG_WARDEN_TEST_HANG"
|
||||
else
|
||||
bad "the test-only directory maps to CONFIG_WARDEN_TEST_HANG"
|
||||
fi
|
||||
if [ -z "$(test_symbol_of drivers/net/wireless/aic8800)" ]; then
|
||||
ok "a release directory needs no test symbol"
|
||||
else
|
||||
bad "a release directory needs no test symbol"
|
||||
fi
|
||||
|
||||
printf 'CONFIG_WARDEN_TEST_HANG=m\n' > "$TMP/cfg-m"
|
||||
expect "=m after olddefconfig passes for the test-only directory" 0 \
|
||||
require_test_config "$TMP/cfg-m" drivers/warden-test
|
||||
printf 'CONFIG_WARDEN_TEST_HANG=y\n' > "$TMP/cfg-y"
|
||||
expect_msg "=y is refused (it would not give a .ko)" 1 "needs CONFIG_WARDEN_TEST_HANG=m" \
|
||||
require_test_config "$TMP/cfg-y" drivers/warden-test
|
||||
printf '# CONFIG_WARDEN_TEST_HANG is not set\n' > "$TMP/cfg-unset"
|
||||
expect_msg "an unset symbol is refused (the dependency was unmet)" 1 "did not survive olddefconfig" \
|
||||
require_test_config "$TMP/cfg-unset" drivers/warden-test
|
||||
: > "$TMP/cfg-none"
|
||||
expect_msg "a configuration without the symbol is refused" 1 "did not survive olddefconfig" \
|
||||
require_test_config "$TMP/cfg-none" drivers/warden-test
|
||||
expect "a missing configuration file is refused" 1 \
|
||||
require_test_config "$TMP/cfg-absent" drivers/warden-test
|
||||
expect "a release list needs no symbol in any configuration" 0 \
|
||||
require_test_config "$TMP/cfg-none" drivers/net/wireless/aic8800
|
||||
|
||||
# --- build-kernel.sh runs the gate on every collected list ------------------
|
||||
|
||||
BK="$REPO/build/build-kernel.sh"
|
||||
if grep -q '^\. "\$HERE/lib-module-gate\.sh"$' "$BK"; then
|
||||
ok "build-kernel.sh sources the module gate"
|
||||
else
|
||||
bad "build-kernel.sh sources the module gate"
|
||||
fi
|
||||
if grep -q 'collect_modules "\$SRC" "\$d" "\$KREL" "\$MODOUT" || exit 1' "$BK"; then
|
||||
ok "build-kernel.sh collects every listed directory through collect_modules"
|
||||
else
|
||||
bad "build-kernel.sh collects every listed directory through collect_modules"
|
||||
fi
|
||||
if grep -q 'require_test_config "\$SRC/.config" "\$d" || exit 1' "$BK"; then
|
||||
ok "build-kernel.sh asserts the test symbol after olddefconfig"
|
||||
else
|
||||
bad "build-kernel.sh asserts the test symbol after olddefconfig"
|
||||
fi
|
||||
if grep -v '^[[:space:]]*#' "$BK" | grep -q 'WARDEN_TEST_HANG\|warden-test'; then
|
||||
bad "build-kernel.sh names the test directory or symbol in code (it belongs in the gate)"
|
||||
else
|
||||
ok "build-kernel.sh names the test directory and symbol only in comments"
|
||||
fi
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then echo "module-gate: all checks passed"; else echo "module-gate: FAILED"; fi
|
||||
exit "$FAIL"
|
||||
Executable
+148
@@ -0,0 +1,148 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tests for the test-only kernel hang module (bench fault F5): patch 95,
|
||||
# the WARDEN_MODULES_COLLECT wiring in build/build-kernel.sh, and the vermagic gate.
|
||||
#
|
||||
# What a regression here costs: a release kernel that quietly carries the hang
|
||||
# trigger, or a test image whose module is missing or stale (a hand-copied .ko
|
||||
# that does not match the kernel). The offline checks always run. The checks
|
||||
# that expand the kernel configuration need the pinned tarball, a cross compiler,
|
||||
# python, flex and bison (the kernel's configuration parser). They run only when
|
||||
# KERNEL_TARBALL and CROSS_COMPILE name them and those tools are on PATH (the
|
||||
# build farm does this); otherwise they are skipped with a notice that names the
|
||||
# missing piece (run-missing-tools-tests.sh checks those skips).
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO="$(cd "$HERE/../.." && pwd)"
|
||||
TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
|
||||
FAIL=0
|
||||
ok() { printf '[PASS] %s\n' "$1"; }
|
||||
bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
skip() { printf '[SKIP] %s\n' "$1"; }
|
||||
# The EXIT trap deletes $TMP, so a failing step prints the end of its log here.
|
||||
show_tail() { # <label> <log>
|
||||
[ -s "$2" ] || return 0
|
||||
printf -- '--- last 40 lines of %s ---\n' "$1"
|
||||
tail -n 40 "$2"
|
||||
printf -- '--- end of %s ---\n' "$1"
|
||||
}
|
||||
|
||||
PATCH="$REPO/patches/95-test-hang-module.patch"
|
||||
BK="$REPO/build/build-kernel.sh"
|
||||
|
||||
# --- offline: the patch and the build wiring -------------------------------
|
||||
|
||||
if bash -n "$BK"; then ok "build-kernel.sh parses"; else bad "build-kernel.sh does not parse"; fi
|
||||
|
||||
[ -f "$PATCH" ] && ok "patch 95 present" || bad "patch 95 missing"
|
||||
|
||||
for f in drivers/warden-test/Kconfig drivers/warden-test/Makefile drivers/warden-test/warden_hang.c; do
|
||||
grep -q "^+++ b/$f\$" "$PATCH" && ok "patch 95 adds $f" || bad "patch 95 does not add $f"
|
||||
done
|
||||
grep -q '^+source "drivers/warden-test/Kconfig"$' "$PATCH" \
|
||||
&& ok "drivers/Kconfig sources the test Kconfig" || bad "drivers/Kconfig does not source the test Kconfig"
|
||||
grep -q '^+obj-$(CONFIG_WARDEN_TEST_HANG) += warden-test/$' "$PATCH" \
|
||||
&& ok "drivers/Makefile descends into warden-test only under the symbol" \
|
||||
|| bad "drivers/Makefile does not descend into warden-test under CONFIG_WARDEN_TEST_HANG"
|
||||
grep -q 'config WARDEN_TEST_HANG' "$PATCH" && grep -q 'depends on DEBUG_FS' "$PATCH" \
|
||||
&& ok "CONFIG_WARDEN_TEST_HANG is a tristate under DEBUG_FS" \
|
||||
|| bad "CONFIG_WARDEN_TEST_HANG is missing or not under DEBUG_FS"
|
||||
grep -q 'default y' "$PATCH" && bad "a test symbol defaults to y in patch 95" \
|
||||
|| ok "patch 95 sets no default y"
|
||||
|
||||
if grep -q 'WARDEN_TEST_HANG' "$REPO/build/warden_defconfig" "$REPO/build/required-symbols.txt" \
|
||||
"$REPO/build/probe-symbols.txt"; then
|
||||
bad "a defconfig or symbol list names CONFIG_WARDEN_TEST_HANG (release must not)"
|
||||
else
|
||||
ok "no defconfig or symbol list names CONFIG_WARDEN_TEST_HANG"
|
||||
fi
|
||||
|
||||
# The test symbol and the vermagic gate live in build/lib-module-gate.sh, which
|
||||
# the behavioural checks in run-module-gate-tests.sh drive with fixtures (below).
|
||||
if grep -q '^\. "\$HERE/lib-module-gate\.sh"$' "$BK" \
|
||||
&& grep -q 'collect_modules "\$SRC" "\$d" "\$KREL" "\$MODOUT" || exit 1' "$BK"; then
|
||||
ok "build-kernel.sh collects every listed module through the vermagic gate"
|
||||
else
|
||||
bad "build-kernel.sh does not collect through the vermagic gate"
|
||||
fi
|
||||
|
||||
# The behavioural gate tests: refusals with a module of the wrong vermagic, and the
|
||||
# test symbol that must be =m (run-module-gate-tests.sh, no kernel tree needed).
|
||||
if bash "$HERE/run-module-gate-tests.sh" > "$TMP/gate.log" 2>&1; then
|
||||
ok "module gate: wrong-vermagic refusals and acceptance fixtures pass"
|
||||
else
|
||||
bad "module gate: fixtures fail (run-module-gate-tests.sh)"
|
||||
show_tail "module gate log" "$TMP/gate.log"
|
||||
fi
|
||||
|
||||
# ASCII only in everything this change adds (documentation and comments included).
|
||||
if LC_ALL=C grep -n -P '[^\x09\x0a\x20-\x7e]' "$BK" "$PATCH" "$REPO/patches/README.md" \
|
||||
"$REPO/tests/test-hang/run-test-hang-tests.sh" "$HERE/run-missing-tools-tests.sh" \
|
||||
"$REPO/build/lib-module-gate.sh" "$HERE/run-module-gate-tests.sh" >/dev/null; then
|
||||
bad "non-ASCII byte in a file this change touches"
|
||||
else
|
||||
ok "ASCII only in the files this change touches"
|
||||
fi
|
||||
|
||||
# --- configuration expansion: needs the tarball and a cross compiler ---------
|
||||
|
||||
if [ -z "${KERNEL_TARBALL:-}" ]; then
|
||||
skip "configuration checks: KERNEL_TARBALL not set (run on the build farm)"
|
||||
elif [ -z "${CROSS_COMPILE:-}" ] || ! command -v "${CROSS_COMPILE}gcc" >/dev/null 2>&1; then
|
||||
skip "configuration checks: no cross compiler (set CROSS_COMPILE)"
|
||||
elif ! command -v python >/dev/null 2>&1; then
|
||||
skip "configuration checks: no python on PATH (the SDK quirk)"
|
||||
elif ! command -v flex >/dev/null 2>&1 || ! command -v bison >/dev/null 2>&1; then
|
||||
skip "configuration checks: flex and bison must both be on PATH (the kernel configuration parser needs them)"
|
||||
elif [ ! -f "$KERNEL_TARBALL" ] && ! bash "$REPO/build/fetch-kernel-tarball.sh" "$KERNEL_TARBALL" >"$TMP/fetch.log" 2>&1; then
|
||||
bad "pinned kernel tarball could not be fetched into $KERNEL_TARBALL"
|
||||
show_tail "fetch output" "$TMP/fetch.log"
|
||||
else
|
||||
# Patches 05 and 95 both touch the two hook files; they must apply in order.
|
||||
mkdir -p "$TMP/hooks"
|
||||
tar -C "$TMP/hooks" -xJf "$KERNEL_TARBALL" linux-6.18.46/drivers/Kconfig linux-6.18.46/drivers/Makefile \
|
||||
&& cd "$TMP/hooks/linux-6.18.46" \
|
||||
&& git init -q . && git add -A && git -c user.name=t -c user.email=t@local commit -q -m base \
|
||||
&& git apply --include='drivers/Kconfig' --include='drivers/Makefile' "$REPO/patches/05-build-wiring.patch" \
|
||||
&& git apply --whitespace=nowarn "$PATCH" \
|
||||
&& grep -q '^source "drivers/warden-test/Kconfig"$' drivers/Kconfig \
|
||||
&& grep -q '^obj-$(CONFIG_WARDEN_TEST_HANG) += warden-test/$' drivers/Makefile \
|
||||
&& ok "patch 95 applies after patch 05 on pristine 6.18.46" \
|
||||
|| bad "patch 95 does not apply after patch 05 on pristine 6.18.46"
|
||||
cd "$HERE" || exit 1
|
||||
|
||||
# Release: the symbol stays unset. Test: it is =m only when the directory is listed.
|
||||
cfg() { # <out> <env assignments...>: expand the configuration only
|
||||
local out="$1"; shift
|
||||
env -u WARDEN_KCONFIG_FRAGMENT -u WARDEN_MODULES_COLLECT "$@" \
|
||||
WORK="$TMP/work-$(basename "$out" .config)" CONFIG_OUT="$out" WARDEN_CONFIG_ONLY=1 \
|
||||
KERNEL_TARBALL="$KERNEL_TARBALL" CROSS_COMPILE="$CROSS_COMPILE" \
|
||||
bash "$BK" >"$out.log" 2>&1
|
||||
}
|
||||
if cfg "$TMP/release.config"; then
|
||||
if grep -q '^CONFIG_WARDEN_TEST_HANG=' "$TMP/release.config"; then
|
||||
bad "release configuration enables CONFIG_WARDEN_TEST_HANG"
|
||||
else
|
||||
ok "release configuration leaves CONFIG_WARDEN_TEST_HANG out"
|
||||
fi
|
||||
else
|
||||
bad "release configuration expansion failed"
|
||||
show_tail "release configuration log" "$TMP/release.config.log"
|
||||
fi
|
||||
if cfg "$TMP/test.config" WARDEN_MODULES_COLLECT=drivers/warden-test; then
|
||||
grep -qx 'CONFIG_WARDEN_TEST_HANG=m' "$TMP/test.config" \
|
||||
&& ok "test configuration sets CONFIG_WARDEN_TEST_HANG=m" \
|
||||
|| bad "test configuration does not set CONFIG_WARDEN_TEST_HANG=m"
|
||||
if [ -f "$TMP/release.config" ] && [ "$(sha256sum < "$TMP/test.config")" != "$(sha256sum < "$TMP/release.config")" ]; then
|
||||
ok "test and release configurations differ (KCONFIG_SHA256 follows the request)"
|
||||
else
|
||||
bad "test configuration equals the release configuration"
|
||||
fi
|
||||
else
|
||||
bad "test configuration expansion failed"
|
||||
show_tail "test configuration log" "$TMP/test.config.log"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then echo "test-hang: all checks passed"; else echo "test-hang: FAILED"; fi
|
||||
exit "$FAIL"
|
||||
Reference in New Issue
Block a user