2 # SPDX-License-Identifier: GPL-2.0
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"
31 #check to see if the host has the required packages to generate a gcov report
34 if ! which "$GCOV_CMD" > /dev
/null
2>&1; then
35 echo "Warning: Could not find gcov. "
36 GENERATE_GCOV_REPORT
=0
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
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
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
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"
87 # if we have the required kernel configs, proceed to check the environment to
88 # ensure we have the required gcov packages
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"
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"
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
119 if ! test -d "$obj_dir"; then
120 echo "selftests: [SKIP] This test requires a kernel source tree"
123 if ! test -e "$kconfig"; then
124 echo "selftests: [SKIP] This test requires a configured kernel source tree"
127 if ! which strace
> /dev
/null
2>&1; then
128 echo "selftests: [SKIP] Could not run test without strace"
131 if ! which tcpdump
> /dev
/null
2>&1; then
132 echo "selftests: [SKIP] Could not run test without tcpdump"
136 if ! which python3
> /dev
/null
2>&1; then
137 echo "selftests: [SKIP] Could not run test without python3"
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"
150 LOG_DIR
="$current_dir"/rds_logs
154 GENERATE_GCOV_REPORT
=1
155 while getopts "d:l:c:u:" opt
; do
170 echo "USAGE: run.sh [-d logdir] [-l packet_loss] [-c packet_corruption]" \
171 "[-u packet_duplcate] [-g]"
175 echo "Invalid option: -${OPTARG}."
188 TRACE_FILE
="${LOG_DIR}/rds-strace.txt"
189 COVR_DIR
="${LOG_DIR}/coverage/"
194 echo running RDS tests...
195 echo Traces will be logged to
"$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"
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' | \
208 cat < "/sys/kernel/debug/gcov/$f" > "/$f"
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/"
215 echo "Coverage report will be skipped"
218 if [ "$test_rc" -eq 0 ]; then
219 echo "PASS: Test completed successfully"
221 echo "FAIL: Test failed"