Skip to content

eBPF-based security platform

tests: cover script regex filters

Mahe Tardy6a3fdfe17ee8
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index 5ba53eb1..3ffc4df8 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -97,6 +97,9 @@ signed config image.
- The upatch build compiles for BPF instruction set v4, and a
``-mcpu`` in ``--extra-cflags`` replaces it; a dense ``switch``
compiles to branches, not a table in ``.rodata``
+ * - ``t1010-test-filter``
+ - Script regex matching through ``-t`` and ``TEST_FILTER``, command-line
+ precedence, empty and invalid patterns, ordering and failure status
``signing`` (2)
~~~~~~~~~~~~~~~
diff --git a/testing/functional/build/t1010-test-filter.sh b/testing/functional/build/t1010-test-filter.sh
new file mode 100755
index 00000000..fcf31029
--- /dev/null
+++ b/testing/functional/build/t1010-test-filter.sh
@@ -0,0 +1,78 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+
+cd "$(dirname "$0")/../.."
+. ./test-lib.sh
+
+WORK=$(mktemp -d)
+trap 'rm -rf "$WORK"' EXIT
+MOCK=$WORK/testing
+mkdir -p "$MOCK/functional/build" "$MOCK/functional/sample"
+cp run-tests.sh run-target-tests.sh test-filter.sh "$MOCK/"
+printf 'echo alpha\n' >"$MOCK/functional/build/t1001-alpha.sh"
+printf 'echo beta\n' >"$MOCK/functional/build/t1002-beta.sh"
+printf 'echo other\n' >"$MOCK/functional/build/t1003-other.sh"
+touch "$MOCK/functional/sample/t9101-alpha.sh"
+
+test_expect_success '-t supports anchors and alternation over script basenames' '
+ sh "$MOCK/run-tests.sh" -t "^t100(1|2)-(alpha|beta)\.sh$" functional/build \
+ >"$WORK/operator.out" &&
+ printf "alpha\nbeta\n" >"$WORK/expected" &&
+ cmp "$WORK/expected" "$WORK/operator.out"
+'
+
+test_expect_success 'TEST_FILTER selects scripts for make-driven runs' '
+ TEST_FILTER=alpha sh "$MOCK/run-tests.sh" functional/build \
+ >"$WORK/operator.out" &&
+ printf "alpha\n" >"$WORK/expected" &&
+ cmp "$WORK/expected" "$WORK/operator.out"
+'
+
+test_expect_success '-t overrides the environment filter' '
+ TEST_FILTER=other sh "$MOCK/run-tests.sh" -t alpha functional/build \
+ >"$WORK/operator.out" &&
+ printf "alpha\n" >"$WORK/expected" &&
+ cmp "$WORK/expected" "$WORK/operator.out"
+'
+
+test_expect_success 'an empty pattern selects every script in order' '
+ sh "$MOCK/run-tests.sh" -t "" functional/build >"$WORK/operator.out" &&
+ printf "alpha\nbeta\nother\n" >"$WORK/expected" &&
+ cmp "$WORK/expected" "$WORK/operator.out"
+'
+
+test_expect_success 'a pattern with no matches executes no scripts' '
+ sh "$MOCK/run-tests.sh" -t "^missing$" functional/build \
+ >"$WORK/operator.out" &&
+ [ ! -s "$WORK/operator.out" ]
+'
+
+test_expect_success 'the target runner parses -t before checking target setup' '
+ ! SHIRUDO_BIN= sh "$MOCK/run-target-tests.sh" -t alpha sample \
+ >"$WORK/target.out" 2>&1 &&
+ grep -q "runtime command is required" "$WORK/target.out"
+'
+
+test_expect_success 'both runners reject invalid expressions and missing -t arguments' '
+ for runner in run-tests.sh run-target-tests.sh; do
+ for pattern in "[" "("; do
+ ret=0
+ sh "$MOCK/$runner" -t "$pattern" \
+ >"$WORK/invalid.out" 2>&1 || ret=$?
+ [ "$ret" -eq 2 ] || return 1
+ done
+ ret=0
+ sh "$MOCK/$runner" -t >"$WORK/invalid.out" 2>&1 || ret=$?
+ [ "$ret" -eq 2 ] || return 1
+ done
+'
+
+test_expect_success 'a selected failing script still fails the runner' '
+ printf "exit 7\n" >"$MOCK/functional/build/t1003-other.sh" &&
+ ret=0 &&
+ { sh "$MOCK/run-tests.sh" -t other functional/build || ret=$?; } &&
+ [ "$ret" -eq 1 ]
+'
+
+test_done