eBPF-based security platform
tests: add regex selection for test scripts
Mahe Tardyc52b3df68175
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rstindex e5056de0..c2e7d6c2 100644--- a/Documentation/contribute/testing/testing.rst+++ b/Documentation/contribute/testing/testing.rst@@ -548,6 +548,29 @@ The host side writes to ``build/test-vm/end2end/``. The guest reachesthe registry and collector through QEMU's address for the host. ClickHouseis available to the collector on the test's Docker network.+Select test scripts+~~~~~~~~~~~~~~~~~~~++Pass ``-t <regex>`` to either runner to select test filenames with a+POSIX extended regular expression. The match includes the ``.sh`` suffix+but not the directory. All TAP cases in a selected script run.++.. code-block:: console++ $ testing/run-tests.sh -t '^t100[67]-' functional/build+ target# testing/run-target-tests.sh -t '^t310[12]-' upatch++With make, set ``TEST_FILTER``; it is passed into test VMs as well:++.. code-block:: console++ $ make -C testing functional/build VM=0 TEST_FILTER='^t100[67]-'++An empty filter selects everything; invalid expressions fail with status+2. ``-t`` overrides ``TEST_FILTER``. For unit tests, the filter selects+suite executable names. Filtering preserves order and does not add+prerequisite scripts or skip the normal build and VM setup.+Write a test------------diff --git a/testing/Makefile b/testing/Makefileindex ef7b9a2c..a37c8a69 100644--- a/testing/Makefile+++ b/testing/Makefile@@ -14,6 +14,7 @@ elseQ = @endifexport Q V+export TEST_FILTER# make tests at the top exports the install paths, and dracut takes the# prefix it finds in the environment for the initrd a test VM boots.@@ -357,6 +358,7 @@ help:' make -C testing ci-checks the scripts CI runs' \' make -C testing functional[/<family>] families: $(FAMILIES)' \' make -C testing end2end' \+ ' TEST_FILTER=<regex> selects test filenames (empty runs everything).' \' VM=0 leaves out the tests that boot a VM, which need root;' \' make -j boots several at once.' \' make -C testing fuzz [FUZZ_SECONDS=60] [FUZZ_CORPUS=<dir>]' \diff --git a/testing/run-target-tests.sh b/testing/run-target-tests.shindex 2f9773d3..2b4f8dd3 100755--- a/testing/run-target-tests.sh+++ b/testing/run-target-tests.sh@@ -2,13 +2,14 @@# SPDX-License-Identifier: BSD-2-Clause# Copyright (c) 2026 Authors of shirudo#-# testing/run-target-tests.sh <family> -- the target tests (t?1??) of one+# testing/run-target-tests.sh [-t <regex>] <family> -- the target tests (t?1??) of one# family in number order, in the test VM that family booted for itself.# A test that skips as a whole fails the family: every one is required.set -eucd "$(dirname "$0")"-family=${1:?usage: run-target-tests.sh <family>}+. ./test-filter.sh+family=${1:?usage: run-target-tests.sh [-t <regex>] <family>}case "$family" inend2end) dir=end2end ;;*) dir=functional/$family ;;@@ -70,6 +71,7 @@ test_log_skipped()for t in "$dir"/t[0-9]1[0-9][0-9]-*.sh; do[ -e "$t" ] || continuefound=1+ test_matches "$t" || continuelog="$SHIRUDO_TEST_RESULTS/$(basename "$t").log"rc=0sh "$t" >"$log" 2>&1 || rc=$?diff --git a/testing/run-tests.sh b/testing/run-tests.shindex dbbc5cc7..4a49b7bb 100755--- a/testing/run-tests.sh+++ b/testing/run-tests.sh@@ -2,7 +2,7 @@# SPDX-License-Identifier: BSD-2-Clause# Copyright (c) 2026 Authors of shirudo#-# testing/run-tests.sh [unit[/<suite>]|ci-checks|functional[/<family>]|end2end]...+# testing/run-tests.sh [-t <regex>] [unit[/<suite>]|ci-checks|functional[/<family>]|end2end]...# -- the tests of each tier named, all of them without an argument, that# run on the build host: the unit tests and the operator tests (t?0??) in# number order. The target tests run in the test VM through@@ -12,6 +12,7 @@set -eucd "$(dirname "$0")"+. ./test-filter.sh[ $# -gt 0 ] || set -- unit ci-checks functional end2endunits=@@ -50,6 +51,7 @@ operator_tests()fail=0: "${SHIRUDO_TEST_SUITE_FAILURES_FILE:=}"for t in $(unit_tests) $(operator_tests); do+ test_matches "$t" || continuecase "$t" in*.sh) set -- sh "$t" ;;*) set -- "$t" ;;diff --git a/testing/test-filter.sh b/testing/test-filter.shnew file mode 100644index 00000000..77672126--- /dev/null+++ b/testing/test-filter.sh@@ -0,0 +1,21 @@+# SPDX-License-Identifier: BSD-2-Clause+# shellcheck shell=sh+# Copyright (c) 2026 Authors of shirudo++: "${TEST_FILTER:=}"+while getopts 't:' opt; do+ case "$opt" in+ t) TEST_FILTER=$OPTARG ;;+ *) exit 2 ;;+ esac+done+shift "$((OPTIND - 1))"+export TEST_FILTER++printf '\n' | LC_ALL=C grep -Eq -- "$TEST_FILTER" ||+ [ "$?" -eq 1 ] || exit 2++test_matches() {+ [ -z "$TEST_FILTER" ] ||+ printf '%s\n' "${1##*/}" | LC_ALL=C grep -Eq -- "$TEST_FILTER"+}diff --git a/testing/vm/guest.sh b/testing/vm/guest.shindex 73d90d46..bec39bec 100755--- a/testing/vm/guest.sh+++ b/testing/vm/guest.sh@@ -352,12 +352,13 @@ if [[ "${TEST_VM_SUITE:-}" == register ]]; then: >/mnt/shirudo-out/failed-suites(cd testing- SHIRUDO_TEST_REGISTER_VM=1 \- SHIRUDO_TEST_FAILURES_FILE=/mnt/shirudo-out/failed-tests \- sh functional/tpm/t4003-register.sh- SHIRUDO_TEST_REGISTER_VM=1 \- SHIRUDO_TEST_FAILURES_FILE=/mnt/shirudo-out/failed-tests \- sh functional/tpm/t4004-config-attest.sh+ . ./test-filter.sh+ for t in functional/tpm/t400[34]-*.sh; do+ test_matches "$t" || continue+ SHIRUDO_TEST_REGISTER_VM=1 \+ SHIRUDO_TEST_FAILURES_FILE=/mnt/shirudo-out/failed-tests \+ sh "$t"+ done)exit 0fidiff --git a/testing/vm/run.sh b/testing/vm/run.shindex 40516558..aac2e449 100755--- a/testing/vm/run.sh+++ b/testing/vm/run.sh@@ -1414,6 +1414,7 @@ fiprintf ' export VM_MODE=%q\n' "$VM_MODE" >>"$USER_DATA"printf ' export TEST_VM_MODE=%q\n' "$TEST_MODE" >>"$USER_DATA"printf ' export TEST_VM_SUITE=%q\n' "$VM_SUITE" >>"$USER_DATA"+printf ' export TEST_FILTER=%q\n' "${TEST_FILTER:-}" >>"$USER_DATA"printf ' export TEST_VM_SKIP_SEAL=%q\n' "$SKIP_SEAL" >>"$USER_DATA"printf ' export TEST_VM_INITRD=%q\n' "$VM_INITRD" >>"$USER_DATA"printf ' export TEST_VM_SSH_PUBLIC_KEY=%q\n' "$SSH_PUBLIC_KEY" >>"$USER_DATA"