~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/net/rds/run.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #! /bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 set -e
  5 set -u
  6 
  7 unset KBUILD_OUTPUT
  8 
  9 current_dir="$(realpath "$(dirname "$0")")"
 10 build_dir="$current_dir"
 11 
 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
 17 
 18         source "$build_include"
 19         build_dir="$mk_build_dir"
 20 fi
 21 
 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"
 28 
 29 GCOV_CMD=gcov
 30 
 31 #check to see if the host has the required packages to generate a gcov report
 32 check_gcov_env()
 33 {
 34         if ! which "$GCOV_CMD" > /dev/null 2>&1; then
 35                 echo "Warning: Could not find gcov. "
 36                 GENERATE_GCOV_REPORT=0
 37                 return
 38         fi
 39 
 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)
 46 
 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
 52                 fi
 53 
 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"
 63                 fi
 64         fi
 65 }
 66 
 67 # Check to see if the kconfig has the required configs to generate a coverage report
 68 check_gcov_conf()
 69 {
 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
 73         fi
 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
 77         fi
 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
 81         fi
 82 
 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
 90         fi
 91 }
 92 
 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
 99         fi
100 }
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
106         fi
107 }
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
115 }
116 
117 check_env()
118 {
119         if ! test -d "$obj_dir"; then
120                 echo "selftests: [SKIP] This test requires a kernel source tree"
121                 exit 4
122         fi
123         if ! test -e "$kconfig"; then
124                 echo "selftests: [SKIP] This test requires a configured kernel source tree"
125                 exit 4
126         fi
127         if ! which strace > /dev/null 2>&1; then
128                 echo "selftests: [SKIP] Could not run test without strace"
129                 exit 4
130         fi
131         if ! which tcpdump > /dev/null 2>&1; then
132                 echo "selftests: [SKIP] Could not run test without tcpdump"
133                 exit 4
134         fi
135 
136         if ! which python3 > /dev/null 2>&1; then
137                 echo "selftests: [SKIP] Could not run test without python3"
138                 exit 4
139         fi
140 
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
147         fi
148 }
149 
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
157     d)
158       LOG_DIR=${OPTARG}
159       ;;
160     l)
161       PLOSS=${OPTARG}
162       ;;
163     c)
164       PCORRUPT=${OPTARG}
165       ;;
166     u)
167       PDUP=${OPTARG}
168       ;;
169     :)
170       echo "USAGE: run.sh [-d logdir] [-l packet_loss] [-c packet_corruption]" \
171            "[-u packet_duplcate] [-g]"
172       exit 1
173       ;;
174     ?)
175       echo "Invalid option: -${OPTARG}."
176       exit 1
177       ;;
178   esac
179 done
180 
181 
182 check_env
183 check_conf
184 check_gcov_conf
185 
186 
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"
192 
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"
199 
200 test_rc=$?
201 dmesg > "${LOG_DIR}/dmesg.out"
202 
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
207        do
208                cat < "/sys/kernel/debug/gcov/$f" > "/$f"
209        done)
210 
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"
216 fi
217 
218 if [ "$test_rc" -eq 0 ]; then
219         echo "PASS: Test completed successfully"
220 else
221         echo "FAIL: Test failed"
222 fi
223 
224 exit "$test_rc"

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php