Skip to content

Commit 3ab477d

Browse files
author
Jiri Benc
committed
selftests: add prepare_system.sh
Bugzilla: https://bugzilla.redhat.com/2177177 Upstream-status: RHEL9 only The selftests do not necessarily run out of box. Add a script to configure the system for the selftests. As this can be fairly destructive to the system, three levels of safety/destructiveness are available. Of course, some tests will fail if you don't apply the most destructive level. This is not upstream for two major reasons: 1. We use different kernel config than the one mandated upstream. At least for bpf selftests, upstream is refusing to accommodate systems that differ to selftests/bpf/config. 2. Some of the setup is inherently RHEL specific. This is not applied to ARK, since the necessary modifications evolve over time and are tied to the particular RHEL version. Signed-off-by: Jiri Benc <jbenc@redhat.com>
1 parent 63b5a3e commit 3ab477d

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

tools/testing/selftests/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ ifdef INSTALL_PATH
219219
install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/
220220
install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/
221221
install -m 744 run_kselftest.sh $(INSTALL_PATH)/
222+
install -m 744 prepare_system.sh $(INSTALL_PATH)/
222223
rm -f $(TEST_LIST)
223224
@ret=1; \
224225
for TARGET in $(TARGETS); do \
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
# Copyright Red Hat
4+
# author: Jiri Benc <jbenc@redhat.com>
5+
6+
set -e
7+
8+
function print_help
9+
{
10+
{
11+
echo "Usage: $0 OPTIONS collection..."
12+
echo
13+
echo "Prepares the system to execute kernel selftests for the given collection(s)."
14+
echo "To list the available collections, run ./run_kselftest.sh -l. Alternatively,"
15+
echo "specify 'all' to prepare for all collections."
16+
echo
17+
echo "Options:"
18+
echo " -s safe modifications only"
19+
echo " -m load kernel modules; -s is implied"
20+
echo " -d destructive modifications; -m and -s is implied"
21+
echo
22+
echo "Note that if you use -d, your system will not be useful for anything else"
23+
echo "than the selftests afterwards."
24+
} >&2
25+
exit $1
26+
}
27+
28+
# If you need to add a particular modification for a test collection, just
29+
# add a new function with the name prepare_collection_safe,
30+
# prepare_collection_modules and/or prepare_collection_destructive. The rest
31+
# will be taken care of automatically. The - and / characters in collection
32+
# names are translated to underscore. Beware that "set -e" is enabled.
33+
34+
function prepare_bpf_safe
35+
{
36+
echo 1 > /proc/sys/net/mptcp/enabled
37+
}
38+
39+
function prepare_bpf_modules
40+
{
41+
modprobe nf_conntrack
42+
modprobe nf_nat
43+
}
44+
45+
function prepare_bpf_destructive
46+
{
47+
dnf install -y --allowerasing \
48+
https://kojipkgs.fedoraproject.org/packages/iptables/1.8.7/15.fc36/x86_64/iptables-libs-1.8.7-15.fc36.x86_64.rpm \
49+
https://kojipkgs.fedoraproject.org/packages/iptables/1.8.7/15.fc36/x86_64/iptables-legacy-libs-1.8.7-15.fc36.x86_64.rpm \
50+
https://kojipkgs.fedoraproject.org/packages/iptables/1.8.7/15.fc36/x86_64/iptables-legacy-1.8.7-15.fc36.x86_64.rpm
51+
}
52+
53+
level=0
54+
while getopts smdh opt; do
55+
case $opt in
56+
s) (( level > 1 )) || level=1 ;;
57+
m) (( level > 2 )) || level=2 ;;
58+
d) (( level > 3 )) || level=3 ;;
59+
h) print_help 0 ;;
60+
?) exit 1 ;;
61+
esac
62+
done
63+
shift $((OPTIND - 1))
64+
[[ $# -gt 0 ]] || print_help 1
65+
if (( level == 0 )); then
66+
echo "You must specify -s, -m or -d. See $0 -h for help." >&2
67+
exit 1
68+
fi
69+
70+
if (( UID != 0 )); then
71+
echo "Please run this as root.">&2
72+
exit 1
73+
fi
74+
75+
unset available
76+
declare -A available
77+
for func in $(compgen -A function); do
78+
[[ $func == prepare_* ]] || continue
79+
available[$func]=1
80+
done
81+
82+
for component in "$@"; do
83+
# convert characters not valid in function names to _
84+
component=${component//[-\/]/_}
85+
if [[ $component == all ]]; then
86+
for func in "${!available[@]}"; do
87+
if [[ ( $func == *_safe && $level -ge 1 ) || \
88+
( $func == *_modules && $level -ge 2 ) || \
89+
( $func == *_destructive && $level -ge 3 ) ]]; then
90+
$func
91+
fi
92+
done
93+
else
94+
if [[ $level -ge 1 && ${available[prepare_${component}_safe]} ]]; then
95+
prepare_${component}_safe
96+
fi
97+
if [[ $level -ge 2 && ${available[prepare_${component}_modules]} ]]; then
98+
prepare_${component}_modules
99+
fi
100+
if [[ $level -ge 3 && ${available[prepare_${component}_destructive]} ]]; then
101+
prepare_${component}_destructive
102+
fi
103+
fi
104+
done

0 commit comments

Comments
 (0)