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