Naresh Kamboju | c646273 | 2017-01-11 16:26:30 +0530 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Linux kernel self test |
| 3 | |
| 4 | # shellcheck disable=SC1091 |
| 5 | . ../../lib/sh-test-lib |
| 6 | OUTPUT="$(pwd)/output" |
| 7 | RESULT_FILE="${OUTPUT}/result.txt" |
| 8 | LOGFILE="${OUTPUT}/kselftest.txt" |
Milosz Wasilewski | 597e24c | 2017-09-04 14:06:36 +0100 | [diff] [blame] | 9 | KSELFTEST_PATH="/opt/kselftests/mainline/" |
Naresh Kamboju | 687ede4 | 2017-05-30 15:02:23 +0530 | [diff] [blame] | 10 | |
| 11 | SCRIPT="$(readlink -f "${0}")" |
| 12 | SCRIPTPATH="$(dirname "${SCRIPT}")" |
| 13 | # List of known unsupported test cases to be skipped |
| 14 | SKIPFILE="" |
Dan Rue | a12a838 | 2018-03-05 12:03:15 -0600 | [diff] [blame] | 15 | # List of test cases to be skipped in yaml/skipgen format |
| 16 | SKIPFILE_YAML="" |
| 17 | BOARD="" |
| 18 | BRANCH="" |
| 19 | ENVIRONMENT="" |
Naresh Kamboju | 687ede4 | 2017-05-30 15:02:23 +0530 | [diff] [blame] | 20 | SKIPLIST="" |
Naresh Kamboju | 92375fe | 2017-06-27 17:16:21 +0530 | [diff] [blame] | 21 | TESTPROG_URL="" |
Naresh Kamboju | 7b9fd95 | 2020-12-03 17:26:53 +0530 | [diff] [blame^] | 22 | TST_CMDFILES="" |
| 23 | TST_CASENAME="" |
Naresh Kamboju | 687ede4 | 2017-05-30 15:02:23 +0530 | [diff] [blame] | 24 | |
Kees Cook | 888eda4 | 2020-09-14 22:52:00 -0700 | [diff] [blame] | 25 | # Architecture-specific tarball name defaults. |
| 26 | if [ "$(uname -m)" = "aarch64" ]; then |
Riku Voipio | 85cdee4 | 2017-05-15 16:01:06 +0300 | [diff] [blame] | 27 | TESTPROG="kselftest_aarch64.tar.gz" |
Kees Cook | 888eda4 | 2020-09-14 22:52:00 -0700 | [diff] [blame] | 28 | else |
| 29 | TESTPROG="kselftest_armhf.tar.gz" |
Riku Voipio | 85cdee4 | 2017-05-15 16:01:06 +0300 | [diff] [blame] | 30 | fi |
Naresh Kamboju | c646273 | 2017-01-11 16:26:30 +0530 | [diff] [blame] | 31 | |
| 32 | usage() { |
Naresh Kamboju | 7b9fd95 | 2020-12-03 17:26:53 +0530 | [diff] [blame^] | 33 | echo "Usage: $0 [-c bpf cpufreq net timers] |
| 34 | [-T cpu-hotplug:cpu-on-off-test.sh] |
| 35 | [-t kselftest_aarch64.tar.gz | kselftest_armhf.tar.gz] |
Naresh Kamboju | 687ede4 | 2017-05-30 15:02:23 +0530 | [diff] [blame] | 36 | [-s True|False] |
Naresh Kamboju | 92375fe | 2017-06-27 17:16:21 +0530 | [diff] [blame] | 37 | [-u url] |
Milosz Wasilewski | 597e24c | 2017-09-04 14:06:36 +0100 | [diff] [blame] | 38 | [-p path] |
Naresh Kamboju | 687ede4 | 2017-05-30 15:02:23 +0530 | [diff] [blame] | 39 | [-L List of skip test cases] |
Dan Rue | a12a838 | 2018-03-05 12:03:15 -0600 | [diff] [blame] | 40 | [-S kselftest-skipfile] |
| 41 | [-b board] |
| 42 | [-g branch] |
| 43 | [-e environment]" 1>&2 |
Naresh Kamboju | c646273 | 2017-01-11 16:26:30 +0530 | [diff] [blame] | 44 | exit 1 |
| 45 | } |
| 46 | |
Naresh Kamboju | 7b9fd95 | 2020-12-03 17:26:53 +0530 | [diff] [blame^] | 47 | while getopts "c:T:t:s:u:p:L:S:b:g:e:h" opt; do |
Naresh Kamboju | c646273 | 2017-01-11 16:26:30 +0530 | [diff] [blame] | 48 | case "${opt}" in |
Naresh Kamboju | 7b9fd95 | 2020-12-03 17:26:53 +0530 | [diff] [blame^] | 49 | c) TST_CMDFILES="${OPTARG}" ;; |
| 50 | T) TST_CASENAME="${OPTARG}" ;; |
Naresh Kamboju | c646273 | 2017-01-11 16:26:30 +0530 | [diff] [blame] | 51 | t) TESTPROG="${OPTARG}" ;; |
| 52 | s) SKIP_INSTALL="${OPTARG}" ;; |
Naresh Kamboju | 92375fe | 2017-06-27 17:16:21 +0530 | [diff] [blame] | 53 | # Download kselftest tarball from given URL |
| 54 | u) TESTPROG_URL="${OPTARG}" ;; |
Naresh Kamboju | 687ede4 | 2017-05-30 15:02:23 +0530 | [diff] [blame] | 55 | # List of known unsupported test cases to be skipped |
| 56 | L) SKIPLIST="${OPTARG}" ;; |
Milosz Wasilewski | 597e24c | 2017-09-04 14:06:36 +0100 | [diff] [blame] | 57 | p) KSELFTEST_PATH="${OPTARG}" ;; |
Naresh Kamboju | 687ede4 | 2017-05-30 15:02:23 +0530 | [diff] [blame] | 58 | S) |
Dan Rue | a12a838 | 2018-03-05 12:03:15 -0600 | [diff] [blame] | 59 | |
| 60 | #OPT=$(echo "${OPTARG}" | grep "http") |
| 61 | #if [ -z "${OPT}" ] ; then |
| 62 | ## kselftest skipfile |
| 63 | # SKIPFILE="${SCRIPTPATH}/${OPTARG}" |
| 64 | #else |
| 65 | ## Download kselftest skipfile from speficied URL |
| 66 | # wget "${OPTARG}" -O "skipfile" |
| 67 | # SKIPFILE="skipfile" |
| 68 | # SKIPFILE="${SCRIPTPATH}/${SKIPFILE}" |
| 69 | #fi |
| 70 | |
| 71 | if [ -z "${OPTARG##*http*}" ]; then |
| 72 | if [ -z "${OPTARG##*yaml*}" ]; then |
| 73 | # Skipfile is of type yaml |
| 74 | SKIPFILE_TMP="http-skipfile.yaml" |
| 75 | SKIPFILE_YAML="${SCRIPTPATH}/${SKIPFILE_TMP}" |
| 76 | else |
| 77 | # Skipfile is normal skipfile |
| 78 | SKIPFILE_TMP="http-skipfile" |
| 79 | SKIPFILE="${SCRIPTPATH}/${SKIPFILE_TMP}" |
| 80 | fi |
| 81 | # Download LTP skipfile from specified URL |
| 82 | if ! wget "${OPTARG}" -O "${SKIPFILE_TMP}"; then |
| 83 | error_msg "Failed to fetch ${OPTARG}" |
| 84 | exit 1 |
| 85 | fi |
| 86 | elif [ "${OPTARG##*.}" = "yaml" ]; then |
| 87 | # yaml skipfile; use skipgen to generate a skipfile |
| 88 | SKIPFILE_YAML="${SCRIPTPATH}/${OPTARG}" |
Naresh Kamboju | 687ede4 | 2017-05-30 15:02:23 +0530 | [diff] [blame] | 89 | else |
Dan Rue | a12a838 | 2018-03-05 12:03:15 -0600 | [diff] [blame] | 90 | # Regular LTP skipfile |
| 91 | SKIPFILE="${SCRIPTPATH}/${OPTARG}" |
Naresh Kamboju | 687ede4 | 2017-05-30 15:02:23 +0530 | [diff] [blame] | 92 | fi |
| 93 | ;; |
Dan Rue | a12a838 | 2018-03-05 12:03:15 -0600 | [diff] [blame] | 94 | |
| 95 | b) |
| 96 | export BOARD="${OPTARG}" |
| 97 | ;; |
| 98 | g) |
| 99 | export BRANCH="${OPTARG}" |
| 100 | ;; |
| 101 | e) |
| 102 | export ENVIRONMENT="${OPTARG}" |
| 103 | ;; |
Naresh Kamboju | c646273 | 2017-01-11 16:26:30 +0530 | [diff] [blame] | 104 | h|*) usage ;; |
| 105 | esac |
| 106 | done |
| 107 | |
Kees Cook | 888eda4 | 2020-09-14 22:52:00 -0700 | [diff] [blame] | 108 | # If no explicit URL given, use the default URL for the kselftest tarball. |
| 109 | if [ -z "${TESTPROG_URL}" ]; then |
| 110 | TESTPROG_URL=http://testdata.validation.linaro.org/tests/kselftest/"${TESTPROG}" |
| 111 | fi |
| 112 | |
Dan Rue | a12a838 | 2018-03-05 12:03:15 -0600 | [diff] [blame] | 113 | if [ -n "${SKIPFILE_YAML}" ]; then |
| 114 | export SKIPFILE_PATH="${SCRIPTPATH}/generated_skipfile" |
| 115 | generate_skipfile |
| 116 | if [ ! -f "${SKIPFILE_PATH}" ]; then |
| 117 | error_msg "Skipfile ${SKIPFILE} does not exist"; |
| 118 | exit 1 |
| 119 | fi |
| 120 | SKIPFILE="${SKIPFILE_PATH}" |
| 121 | fi |
| 122 | |
| 123 | |
Naresh Kamboju | c646273 | 2017-01-11 16:26:30 +0530 | [diff] [blame] | 124 | parse_output() { |
Kees Cook | 8bd338b | 2020-09-15 00:49:06 -0700 | [diff] [blame] | 125 | perl -ne ' |
| 126 | if (m|^# selftests: (.*)$|) { |
| 127 | $testdir = $1; |
| 128 | $testdir =~ s|[:/]\s*|.|g; |
| 129 | } elsif (m|^(?:# )*(not )?ok (?:\d+) ([^#]+)(# (SKIP)?)?|) { |
| 130 | $not = $1; |
| 131 | $test = $2; |
| 132 | $skip = $4; |
| 133 | $test =~ s|\s+$||; |
| 134 | # If the test name starts with "selftests: " it is "fully qualified". |
| 135 | if ($test =~ /selftests: (.*)/) { |
| 136 | $test = $1; |
| 137 | $test =~ s|[:/]\s*|.|g; |
| 138 | } else { |
| 139 | # Otherwise, it likely needs the testdir prepended. |
| 140 | $test = "$testdir.$test"; |
| 141 | } |
| 142 | # Any appearance of the SKIP is a skip. |
| 143 | if ($skip eq "SKIP") { |
| 144 | $result="skip"; |
| 145 | } elsif ($not eq "not ") { |
| 146 | $result="fail"; |
| 147 | } else { |
| 148 | $result="pass"; |
| 149 | } |
| 150 | print "$test $result\n"; |
| 151 | } |
Kees Cook | eb1a467 | 2020-09-15 01:28:05 -0700 | [diff] [blame] | 152 | ' "${LOGFILE}" >> "${RESULT_FILE}" |
Naresh Kamboju | c646273 | 2017-01-11 16:26:30 +0530 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | install() { |
| 156 | dist_name |
| 157 | # shellcheck disable=SC2154 |
| 158 | case "${dist}" in |
Kees Cook | 528efb0 | 2020-09-14 23:55:48 -0700 | [diff] [blame] | 159 | debian|ubuntu) install_deps "sed perl wget xz-utils iproute2" "${SKIP_INSTALL}" ;; |
| 160 | centos|fedora) install_deps "sed perl wget xz iproute" "${SKIP_INSTALL}" ;; |
Naresh Kamboju | c646273 | 2017-01-11 16:26:30 +0530 | [diff] [blame] | 161 | unknown) warn_msg "Unsupported distro: package install skipped" ;; |
| 162 | esac |
| 163 | } |
| 164 | |
| 165 | ! check_root && error_msg "You need to be root to run this script." |
| 166 | create_out_dir "${OUTPUT}" |
| 167 | # shellcheck disable=SC2164 |
| 168 | cd "${OUTPUT}" |
| 169 | |
| 170 | install |
| 171 | |
| 172 | if [ -d "${KSELFTEST_PATH}" ]; then |
| 173 | echo "kselftests found on rootfs" |
| 174 | # shellcheck disable=SC2164 |
| 175 | cd "${KSELFTEST_PATH}" |
| 176 | else |
Kees Cook | 888eda4 | 2020-09-14 22:52:00 -0700 | [diff] [blame] | 177 | # Fetch whatever we have been aimed at, assuming only that it can |
| 178 | # be handled by "tar". Do not assume anything about the compression. |
| 179 | wget "${TESTPROG_URL}" |
| 180 | tar -xaf "$(basename "${TESTPROG_URL}")" |
Naresh Kamboju | c646273 | 2017-01-11 16:26:30 +0530 | [diff] [blame] | 181 | # shellcheck disable=SC2164 |
Kevin Hilman | 96efe16 | 2020-07-14 11:59:30 -0700 | [diff] [blame] | 182 | if [ ! -e "run_kselftest.sh" ]; then cd "kselftest"; fi |
Naresh Kamboju | c646273 | 2017-01-11 16:26:30 +0530 | [diff] [blame] | 183 | fi |
| 184 | |
Kees Cook | 528efb0 | 2020-09-14 23:55:48 -0700 | [diff] [blame] | 185 | skips=$(mktemp -p . -t skip-XXXXXX) |
| 186 | |
Naresh Kamboju | 687ede4 | 2017-05-30 15:02:23 +0530 | [diff] [blame] | 187 | if [ -n "${SKIPLIST}" ]; then |
| 188 | # shellcheck disable=SC2086 |
Kees Cook | 528efb0 | 2020-09-14 23:55:48 -0700 | [diff] [blame] | 189 | for skip_regex in ${SKIPLIST}; do |
| 190 | echo "${skip_regex}" >> "$skips" |
Naresh Kamboju | 687ede4 | 2017-05-30 15:02:23 +0530 | [diff] [blame] | 191 | done |
| 192 | fi |
| 193 | |
| 194 | # Ignore SKIPFILE when SKIPLIST provided |
| 195 | if [ -f "${SKIPFILE}" ] && [ -z "${SKIPLIST}" ]; then |
Kees Cook | 528efb0 | 2020-09-14 23:55:48 -0700 | [diff] [blame] | 196 | while read -r skip_regex; do |
| 197 | case "${skip_regex}" in \#*) continue ;; esac |
| 198 | echo "${skip_regex}" >> "$skips" |
Naresh Kamboju | 687ede4 | 2017-05-30 15:02:23 +0530 | [diff] [blame] | 199 | done < "${SKIPFILE}" |
| 200 | fi |
| 201 | |
Kees Cook | 3aa6752 | 2020-10-15 14:55:43 -0700 | [diff] [blame] | 202 | cp kselftest-list.txt kselftest-list.txt.orig |
Anders Roxell | 5c160f7 | 2019-05-14 13:38:36 +0200 | [diff] [blame] | 203 | echo "skiplist:" |
Kees Cook | 3aa6752 | 2020-10-15 14:55:43 -0700 | [diff] [blame] | 204 | echo "========================================" |
Kees Cook | 528efb0 | 2020-09-14 23:55:48 -0700 | [diff] [blame] | 205 | while read -r skip_regex; do |
Kees Cook | 3aa6752 | 2020-10-15 14:55:43 -0700 | [diff] [blame] | 206 | echo "$skip_regex" |
| 207 | # Remove matching tests from list of tests to run and report it as skipped |
| 208 | perl -i -ne 'if (s|^('"${skip_regex}"')$|\1 skip|) { print STDERR; } else { print; }' kselftest-list.txt 2>>"${RESULT_FILE}" |
Kees Cook | 528efb0 | 2020-09-14 23:55:48 -0700 | [diff] [blame] | 209 | done < "${skips}" |
Anders Roxell | 5c160f7 | 2019-05-14 13:38:36 +0200 | [diff] [blame] | 210 | echo "========================================" |
Kees Cook | 528efb0 | 2020-09-14 23:55:48 -0700 | [diff] [blame] | 211 | rm -f "${skips}" |
| 212 | |
Naresh Kamboju | 7b9fd95 | 2020-12-03 17:26:53 +0530 | [diff] [blame^] | 213 | if [ -n "${TST_CASENAME}" ]; then |
| 214 | ./run_kselftest.sh -t "${TST_CASENAME}" 2>&1 | tee -a "${LOGFILE}" |
| 215 | elif [ -n "${TST_CMDFILES}" ]; then |
| 216 | # shellcheck disable=SC2086 |
| 217 | for test in ${TST_CMDFILES}; do |
| 218 | ./run_kselftest.sh -c ${test} 2>&1 | tee -a "${LOGFILE}" |
| 219 | done |
| 220 | else |
| 221 | ./run_kselftest.sh 2>&1 | tee "${LOGFILE}" |
| 222 | fi |
Naresh Kamboju | c646273 | 2017-01-11 16:26:30 +0530 | [diff] [blame] | 223 | parse_output |