Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / net / rds / run.sh
blob8aee244f582a3eac34f53651125fb43a25e0b8f1
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 set -e
5 set -u
7 unset KBUILD_OUTPUT
9 current_dir="$(realpath "$(dirname "$0")")"
10 build_dir="$current_dir"
12 build_include="$current_dir/include.sh"
13 if test -f "$build_include"; then
14 # this include will define "$mk_build_dir" as the location the test was
15 # built. We will need this if the tests are installed in a location
16 # other than the kernel source
18 source "$build_include"
19 build_dir="$mk_build_dir"
22 # This test requires kernel source and the *.gcda data therein
23 # Locate the top level of the kernel source, and the net/rds
24 # subfolder with the appropriate *.gcno object files
25 ksrc_dir="$(realpath "$build_dir"/../../../../../)"
26 kconfig="$ksrc_dir/.config"
27 obj_dir="$ksrc_dir/net/rds"
29 GCOV_CMD=gcov
31 #check to see if the host has the required packages to generate a gcov report
32 check_gcov_env()
34 if ! which "$GCOV_CMD" > /dev/null 2>&1; then
35 echo "Warning: Could not find gcov. "
36 GENERATE_GCOV_REPORT=0
37 return
40 # the gcov version must match the gcc version
41 GCC_VER=$(gcc -dumpfullversion)
42 GCOV_VER=$($GCOV_CMD -v | grep gcov | awk '{print $3}'| awk 'BEGIN {FS="-"}{print $1}')
43 if [ "$GCOV_VER" != "$GCC_VER" ]; then
44 #attempt to find a matching gcov version
45 GCOV_CMD=gcov-$(gcc -dumpversion)
47 if ! which "$GCOV_CMD" > /dev/null 2>&1; then
48 echo "Warning: Could not find an appropriate gcov installation. \
49 gcov version must match gcc version"
50 GENERATE_GCOV_REPORT=0
51 return
54 #recheck version number of found gcov executable
55 GCOV_VER=$($GCOV_CMD -v | grep gcov | awk '{print $3}'| \
56 awk 'BEGIN {FS="-"}{print $1}')
57 if [ "$GCOV_VER" != "$GCC_VER" ]; then
58 echo "Warning: Could not find an appropriate gcov installation. \
59 gcov version must match gcc version"
60 GENERATE_GCOV_REPORT=0
61 else
62 echo "Warning: Mismatched gcc and gcov detected. Using $GCOV_CMD"
67 # Check to see if the kconfig has the required configs to generate a coverage report
68 check_gcov_conf()
70 if ! grep -x "CONFIG_GCOV_PROFILE_RDS=y" "$kconfig" > /dev/null 2>&1; then
71 echo "INFO: CONFIG_GCOV_PROFILE_RDS should be enabled for coverage reports"
72 GENERATE_GCOV_REPORT=0
74 if ! grep -x "CONFIG_GCOV_KERNEL=y" "$kconfig" > /dev/null 2>&1; then
75 echo "INFO: CONFIG_GCOV_KERNEL should be enabled for coverage reports"
76 GENERATE_GCOV_REPORT=0
78 if grep -x "CONFIG_GCOV_PROFILE_ALL=y" "$kconfig" > /dev/null 2>&1; then
79 echo "INFO: CONFIG_GCOV_PROFILE_ALL should be disabled for coverage reports"
80 GENERATE_GCOV_REPORT=0
83 if [ "$GENERATE_GCOV_REPORT" -eq 0 ]; then
84 echo "To enable gcov reports, please run "\
85 "\"tools/testing/selftests/net/rds/config.sh -g\" and rebuild the kernel"
86 else
87 # if we have the required kernel configs, proceed to check the environment to
88 # ensure we have the required gcov packages
89 check_gcov_env
93 # Kselftest framework requirement - SKIP code is 4.
94 check_conf_enabled() {
95 if ! grep -x "$1=y" "$kconfig" > /dev/null 2>&1; then
96 echo "selftests: [SKIP] This test requires $1 enabled"
97 echo "Please run tools/testing/selftests/net/rds/config.sh and rebuild the kernel"
98 exit 4
101 check_conf_disabled() {
102 if grep -x "$1=y" "$kconfig" > /dev/null 2>&1; then
103 echo "selftests: [SKIP] This test requires $1 disabled"
104 echo "Please run tools/testing/selftests/net/rds/config.sh and rebuild the kernel"
105 exit 4
108 check_conf() {
109 check_conf_enabled CONFIG_NET_SCH_NETEM
110 check_conf_enabled CONFIG_VETH
111 check_conf_enabled CONFIG_NET_NS
112 check_conf_enabled CONFIG_RDS_TCP
113 check_conf_enabled CONFIG_RDS
114 check_conf_disabled CONFIG_MODULES
117 check_env()
119 if ! test -d "$obj_dir"; then
120 echo "selftests: [SKIP] This test requires a kernel source tree"
121 exit 4
123 if ! test -e "$kconfig"; then
124 echo "selftests: [SKIP] This test requires a configured kernel source tree"
125 exit 4
127 if ! which strace > /dev/null 2>&1; then
128 echo "selftests: [SKIP] Could not run test without strace"
129 exit 4
131 if ! which tcpdump > /dev/null 2>&1; then
132 echo "selftests: [SKIP] Could not run test without tcpdump"
133 exit 4
136 if ! which python3 > /dev/null 2>&1; then
137 echo "selftests: [SKIP] Could not run test without python3"
138 exit 4
141 python_major=$(python3 -c "import sys; print(sys.version_info[0])")
142 python_minor=$(python3 -c "import sys; print(sys.version_info[1])")
143 if [[ python_major -lt 3 || ( python_major -eq 3 && python_minor -lt 9 ) ]] ; then
144 echo "selftests: [SKIP] Could not run test without at least python3.9"
145 python3 -V
146 exit 4
150 LOG_DIR="$current_dir"/rds_logs
151 PLOSS=0
152 PCORRUPT=0
153 PDUP=0
154 GENERATE_GCOV_REPORT=1
155 while getopts "d:l:c:u:" opt; do
156 case ${opt} in
158 LOG_DIR=${OPTARG}
161 PLOSS=${OPTARG}
164 PCORRUPT=${OPTARG}
167 PDUP=${OPTARG}
170 echo "USAGE: run.sh [-d logdir] [-l packet_loss] [-c packet_corruption]" \
171 "[-u packet_duplcate] [-g]"
172 exit 1
175 echo "Invalid option: -${OPTARG}."
176 exit 1
178 esac
179 done
182 check_env
183 check_conf
184 check_gcov_conf
187 rm -fr "$LOG_DIR"
188 TRACE_FILE="${LOG_DIR}/rds-strace.txt"
189 COVR_DIR="${LOG_DIR}/coverage/"
190 mkdir -p "$LOG_DIR"
191 mkdir -p "$COVR_DIR"
193 set +e
194 echo running RDS tests...
195 echo Traces will be logged to "$TRACE_FILE"
196 rm -f "$TRACE_FILE"
197 strace -T -tt -o "$TRACE_FILE" python3 "$(dirname "$0")/test.py" --timeout 400 -d "$LOG_DIR" \
198 -l "$PLOSS" -c "$PCORRUPT" -u "$PDUP"
200 test_rc=$?
201 dmesg > "${LOG_DIR}/dmesg.out"
203 if [ "$GENERATE_GCOV_REPORT" -eq 1 ]; then
204 echo saving coverage data...
205 (set +x; cd /sys/kernel/debug/gcov; find ./* -name '*.gcda' | \
206 while read -r f
208 cat < "/sys/kernel/debug/gcov/$f" > "/$f"
209 done)
211 echo running gcovr...
212 gcovr -s --html-details --gcov-executable "$GCOV_CMD" --gcov-ignore-parse-errors \
213 -o "${COVR_DIR}/gcovr" "${ksrc_dir}/net/rds/"
214 else
215 echo "Coverage report will be skipped"
218 if [ "$test_rc" -eq 0 ]; then
219 echo "PASS: Test completed successfully"
220 else
221 echo "FAIL: Test failed"
224 exit "$test_rc"