1
1
#! /bin/bash
2
2
3
+ # run_selftest.sh will run the tests within /${PROJECT_NAME}/selftests/bpf
4
+ # If no specific test names are given, all test will be ran, otherwise, it will
5
+ # run the test passed as parameters.
6
+ # There is 2 ways to pass test names.
7
+ # 1) command-line arguments to this script
8
+ # 2) a comma-separated list of test names passed as `run_tests` boot parameters.
9
+ # test names passed as any of those methods will be ran.
10
+
3
11
set -euo pipefail
4
12
5
13
source $( cd $( dirname $0 ) && pwd) /helpers.sh
@@ -8,6 +16,8 @@ ARCH=$(uname -m)
8
16
9
17
STATUS_FILE=/exitstatus
10
18
19
+ declare -a TEST_NAMES=()
20
+
11
21
read_lists () {
12
22
(for path in " $@ " ; do
13
23
if [[ -s " $path " ]]; then
@@ -22,6 +32,28 @@ TEST_PROGS_ARGS=""
22
32
# TEST_PROGS_ARGS="-j"
23
33
# fi
24
34
35
+ read_test_names () {
36
+ foldable start read_test_names " Reading test names from boot parameters and command line arguments"
37
+ # Check if test names were passed as boot parameter.
38
+ # We expect `run_tests` to be a comma-separated list of test names.
39
+ IFS=' ,' read -r -a test_names_from_boot <<< \
40
+ "$( sed -n ' s/.*run_tests=\([^ ]*\).*/\1/p' /proc/cmdline) "
41
+
42
+ echo "${# test_names_from_boot[@]} tests extracted from boot parameters: ${test_names_from_boot[*]} "
43
+ # Sort and only keep unique test names from both boot params and arguments
44
+ # TEST_NAMES will contain a sorted list of uniq tests to be ran.
45
+ # Only do this if any of $test_names_from_boot [@] or $@ has elements as
46
+ # "printf '%s\0'" will otherwise generate an empty element.
47
+ if [[ ${# test_names_from_boot[@]} -gt 0 || $# -gt 0 ]]
48
+ then
49
+ readarray -t TEST_NAMES < \
50
+ <(printf '%s\0' "${test_names_from_boot[@]} " "$@ " | \
51
+ sort --zero-terminated --unique | \
52
+ xargs --null --max-args=1)
53
+ fi
54
+ foldable end read_test_names
55
+ }
56
+
25
57
test_progs() {
26
58
foldable start test_progs "Testing test_progs"
27
59
# "&& true" does not change the return code (it is not executed
@@ -81,13 +113,18 @@ echo "ALLOWLIST: ${ALLOWLIST}"
81
113
82
114
cd ${PROJECT_NAME} /selftests/bpf
83
115
84
- if [ $# -eq 0 ]; then
116
+ # populate TEST_NAMES
117
+ read_test_names "$@ "
118
+ # if we don't have any test name provided to the script, we run all tests.
119
+ if [ ${# TEST_NAMES[@]} -eq 0 ]; then
85
120
test_progs
86
121
test_progs_no_alu32
87
122
test_maps
88
123
test_verifier
89
124
else
90
- for test_name in " $@ " ; do
125
+ # else we run the tests passed as command-line arguments and through boot
126
+ # parameter.
127
+ for test_name in "${TEST_NAMES[@]} "; do
91
128
"${test_name} "
92
129
done
93
130
fi
0 commit comments