| 1 | #!/bin/bash |
| 2 | |
| 3 | # |
| 4 | # libseccomp regression test automation script |
| 5 | # |
| 6 | # Copyright IBM Corp. 2012 |
| 7 | # Author: Corey Bryant <[email protected]> |
| 8 | # |
| 9 | |
| 10 | # |
| 11 | # This library is free software; you can redistribute it and/or modify it |
| 12 | # under the terms of version 2.1 of the GNU Lesser General Public License as |
| 13 | # published by the Free Software Foundation. |
| 14 | # |
| 15 | # This library is distributed in the hope that it will be useful, but WITHOUT |
| 16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 18 | # for more details. |
| 19 | # |
| 20 | # You should have received a copy of the GNU Lesser General Public License |
| 21 | # along with this library; if not, see <http://www.gnu.org/licenses>. |
| 22 | # |
| 23 | |
| 24 | GLBL_ARCH_LE_SUPPORT=" \ |
| 25 | x86 x86_64 x32 \ |
| 26 | arm aarch64 \ |
| 27 | loongarch64 \ |
| 28 | mipsel mipsel64 mipsel64n32 \ |
| 29 | ppc64le \ |
| 30 | riscv64 \ |
| 31 | sh" |
| 32 | GLBL_ARCH_BE_SUPPORT=" \ |
| 33 | m68k \ |
| 34 | mips mips64 mips64n32 \ |
| 35 | parisc parisc64 \ |
| 36 | ppc ppc64 \ |
| 37 | s390 s390x \ |
| 38 | sheb" |
| 39 | |
| 40 | GLBL_ARCH_32B_SUPPORT=" \ |
| 41 | x86 x32 \ |
| 42 | arm \ |
| 43 | m68k \ |
| 44 | mips mipsel mips64n32 mipsel64n32 \ |
| 45 | parisc \ |
| 46 | ppc \ |
| 47 | s390 \ |
| 48 | sheb sh" |
| 49 | |
| 50 | GLBL_ARCH_64B_SUPPORT=" \ |
| 51 | x86_64 \ |
| 52 | aarch64 \ |
| 53 | loongarch64 \ |
| 54 | mips64 \ |
| 55 | parisc64 \ |
| 56 | ppc64 \ |
| 57 | riscv64 \ |
| 58 | s390x" |
| 59 | |
| 60 | GLBL_SYS_ARCH="../tools/scmp_arch_detect" |
| 61 | GLBL_SYS_RESOLVER="../tools/scmp_sys_resolver" |
| 62 | GLBL_SYS_SIM="../tools/scmp_bpf_sim" |
| 63 | GLBL_SYS_API="../tools/scmp_api_level" |
| 64 | |
| 65 | #### |
| 66 | # functions |
| 67 | |
| 68 | # |
| 69 | # Dependency check |
| 70 | # |
| 71 | # Arguments: |
| 72 | # 1 Dependency to check for |
| 73 | # |
| 74 | function check_deps() { |
| 75 | [[ -z "$1" ]] && return |
| 76 | type -P "$1" >& /dev/null |
| 77 | return $? |
| 78 | } |
| 79 | |
| 80 | # |
| 81 | # Dependency verification |
| 82 | # |
| 83 | # Arguments: |
| 84 | # 1 Dependency to check for |
| 85 | # |
| 86 | function verify_deps() { |
| 87 | [[ -z "$1" ]] && return |
| 88 | if ! check_deps "$1"; then |
| 89 | echo "error: install \"$1\" and include it in your \$PATH" |
| 90 | exit 1 |
| 91 | fi |
| 92 | } |
| 93 | |
| 94 | # |
| 95 | # Print out script usage details |
| 96 | # |
| 97 | function usage() { |
| 98 | cat << EOF |
| 99 | usage: regression [-h] [-v] [-j JOBS] [-m MODE] [-a] [-b BATCH_NAME] |
| 100 | [-l <LOG>] [-s SINGLE_TEST] [-t <TEMP_DIR>] [-T <TEST_TYPE>] |
| 101 | |
| 102 | libseccomp regression test automation script |
| 103 | optional arguments: |
| 104 | -h show this help message and exit |
| 105 | -j JOBS run up to JOBS test jobs in parallel |
| 106 | can also be set via LIBSECCOMP_TSTCFG_JOBS env variable |
| 107 | -m MODE specified the test mode [c (default), python] |
| 108 | can also be set via LIBSECCOMP_TSTCFG_MODE_LIST env variable |
| 109 | -a specifies all tests are to be run |
| 110 | -b BATCH_NAME specifies batch of tests to be run |
| 111 | can also be set via LIBSECCOMP_TSTCFG_BATCHES env variable |
| 112 | -l [LOG] specifies log file to write test results to |
| 113 | -s SINGLE_TEST specifies individual test number to be run |
| 114 | -t [TEMP_DIR] specifies directory to create temporary files in |
| 115 | -T [TEST_TYPE] only run tests matching the specified type |
| 116 | can also be set via LIBSECCOMP_TSTCFG_TYPE env variable |
| 117 | -v specifies that verbose output be provided |
| 118 | EOF |
| 119 | } |
| 120 | |
| 121 | # |
| 122 | # Match on a single word/column in a CSV string |
| 123 | # |
| 124 | # Arguments: |
| 125 | # 1 string containing the CSV |
| 126 | # 2 string containing the word to match |
| 127 | # |
| 128 | # Returns true/0 if a match is found false/1 otherwise. |
| 129 | # |
| 130 | function match_csv_word() { |
| 131 | [[ -z $1 || -z $2 ]] && return 1 |
| 132 | |
| 133 | echo "$1" | sed 's/,/ /g' | grep -qw "$2" |
| 134 | } |
| 135 | |
| 136 | # |
| 137 | # Generate a string representing the test number |
| 138 | # |
| 139 | # Arguments: |
| 140 | # 1 string containing the batch name |
| 141 | # 2 value of the test number from the input test data file |
| 142 | # 3 value of the subtest number that corresponds to argument 1 |
| 143 | # |
| 144 | # The actual test number from the input test data file is 1 for the first |
| 145 | # test found in the file, 2 for the second, etc. |
| 146 | # |
| 147 | # The subtest number is useful for batches that generate multiple tests based |
| 148 | # on a single line of input from the test data file. The subtest number |
| 149 | # should be set to zero if the corresponding test data is actual test data |
| 150 | # that was read from the input file, and should be set to a value greater than |
| 151 | # zero if the corresponding test data is generated. |
| 152 | # |
| 153 | function generate_test_num() { |
| 154 | local testnumstr=$(printf '%s%%%%%03d-%05d' "$1" $2 $3) |
| 155 | echo "$testnumstr" |
| 156 | } |
| 157 | |
| 158 | # |
| 159 | # Print the test data to the log file |
| 160 | # |
| 161 | # Arguments: |
| 162 | # 1 string containing generated test number |
| 163 | # 2 string containing line of test data |
| 164 | # |
| 165 | function print_data() { |
| 166 | if [[ -n $verbose ]]; then |
| 167 | printf "Test %s data: %s\n" "$1" "$2" >&$logfd |
| 168 | fi |
| 169 | } |
| 170 | |
| 171 | # |
| 172 | # Print the test result to the log file |
| 173 | # |
| 174 | # Arguments: |
| 175 | # 1 string containing generated test number |
| 176 | # 2 string containing the test result (INFO, SUCCESS, ERROR, or FAILURE) |
| 177 | # 3 string containing addition details |
| 178 | # |
| 179 | function print_result() { |
| 180 | if [[ $2 == "INFO" && -z $verbose ]]; then |
| 181 | return |
| 182 | fi |
| 183 | if [[ $3 == "" ]]; then |
| 184 | printf "Test %s result: %s\n" "$1" "$2" >&$logfd |
| 185 | else |
| 186 | printf "Test %s result: %s %s\n" "$1" "$2" "$3" >&$logfd |
| 187 | fi |
| 188 | } |
| 189 | |
| 190 | # |
| 191 | # Print the valgrind header to the log file |
| 192 | # |
| 193 | # Arguments: |
| 194 | # 1 string containing generated test number |
| 195 | # |
| 196 | function print_valgrind() { |
| 197 | if [[ -n $verbose ]]; then |
| 198 | printf "Test %s valgrind output\n" "$1" >&$logfd |
| 199 | fi |
| 200 | } |
| 201 | |
| 202 | # |
| 203 | # Get the low or high range value from a range specification |
| 204 | # |
| 205 | # Arguments: |
| 206 | # 1 value specifying range value to retrieve: low (1) or high (2) |
| 207 | # 2 string containing dash-separated range or a single value |
| 208 | # |
| 209 | function get_range() { |
| 210 | if [[ $2 =~ ^[0-9a-fA-Fx]+-[0-9a-fA-Fx]+$ ]]; then |
| 211 | # if there's a dash, get the low or high range value |
| 212 | range_val=$(echo "$2" | cut -d'-' -f "$1") |
| 213 | else |
| 214 | # otherwise there should just be a single value |
| 215 | range_val="$2" |
| 216 | fi |
| 217 | echo "$range_val" |
| 218 | } |
| 219 | |
| 220 | # |
| 221 | # Get the number sequence for a given range with increments of 1, i.e. |
| 222 | # implement a specialized seq(1). |
| 223 | # |
| 224 | # We use our own implementation based on miniseq in favour to the standard seq |
| 225 | # tool as, at least, seq of coreutils v8.23 and v8.24 has problems on 32 bit |
| 226 | # ARM for large numbers (see the mailing thread at |
| 227 | # https://groups.google.com/forum/#!topic/libseccomp/VtrClkXxLGA). |
| 228 | # |
| 229 | # Arguments: |
| 230 | # 1 starting value |
| 231 | # 2 last value |
| 232 | # |
| 233 | function get_seq() { |
| 234 | # NOTE: this whole thing is a bit hacky, but we need to search around |
| 235 | # for miniseq to fix 'make distcheck', someday we should fix this |
| 236 | if [[ -x ./miniseq ]]; then |
| 237 | ./miniseq "$1" "$2" |
| 238 | elif [[ -x $basedir/miniseq ]]; then |
| 239 | $basedir/miniseq "$1" "$2" |
| 240 | else |
| 241 | # we're often run from a subshell, so we can't simply exit |
| 242 | echo "error: unable to find miniseq" >&2 |
| 243 | kill $pid |
| 244 | fi |
| 245 | } |
| 246 | |
| 247 | # |
| 248 | # Run the specified test command (with valgrind if requested) |
| 249 | # |
| 250 | # Arguments: |
| 251 | # 1 string containing generated test number |
| 252 | # 2 string containing command name |
| 253 | # 3 string containing command options |
| 254 | # 4 number for the stdout fd |
| 255 | # 5 number for the stderr fd |
| 256 | # |
| 257 | function run_test_command() { |
| 258 | local cmd |
| 259 | |
| 260 | if [[ $mode == "python" ]]; then |
| 261 | cmd="PYTHONPATH=$PYTHONPATH" |
| 262 | cmd="$cmd:$(cd $(pwd)/../src/python/build/lib.*; pwd)" |
| 263 | # check and adjust if we are doing a VPATH build |
| 264 | if [[ -e "./$2.py" ]]; then |
| 265 | cmd="$cmd /usr/bin/env python $2.py $3" |
| 266 | else |
| 267 | cmd="$cmd /usr/bin/env python ${srcdir}/$2.py $3" |
| 268 | fi |
| 269 | else |
| 270 | cmd="$2 $3" |
| 271 | fi |
| 272 | |
| 273 | # setup the stdout/stderr redirects |
| 274 | local stdout=$4 |
| 275 | local stderr=$5 |
| 276 | [[ -z $stdout ]] && stdout=$logfd |
| 277 | [[ -z $stderr ]] && stderr=$logfd |
| 278 | |
| 279 | # run the command |
| 280 | eval "$cmd" 1>&$stdout 2>&$stderr |
| 281 | |
| 282 | # return the command's return code |
| 283 | return $? |
| 284 | } |
| 285 | |
| 286 | # |
| 287 | # Generate pseudo-random string of alphanumeric characters |
| 288 | # |
| 289 | # The generated string will be no larger than the corresponding |
| 290 | # architecture's register size. |
| 291 | # |
| 292 | function generate_random_data() { |
| 293 | local rcount |
| 294 | local rdata |
| 295 | if [[ $arch == "x86_64" ]]; then |
| 296 | rcount=$[ ($RANDOM % 16) + 1 ] |
| 297 | else |
| 298 | rcount=$[ ($RANDOM % 8) + 1 ] |
| 299 | fi |
| 300 | rdata=$(dd if=/dev/urandom bs=64 count=1 status=none | \ |
| 301 | md5sum | awk '{ print $1 }' | head -c"$rcount") |
| 302 | echo "$rdata" |
| 303 | } |
| 304 | |
| 305 | # |
| 306 | # Run the specified "bpf-sim-fuzz" test |
| 307 | # |
| 308 | # Tests that belong to the "bpf-sim-fuzz" test type generate a BPF filter and |
| 309 | # then run a simulated system call test with pseudo-random fuzz data for the |
| 310 | # syscall and argument values. Tests that belong to this test type provide the |
| 311 | # following data on a single line in the input batch file: |
| 312 | # |
| 313 | # Testname - The executable test name (e.g. 01-allow, 02-basic, etc.) |
| 314 | # StressCount - The number of fuzz tests to run against the filter |
| 315 | # |
| 316 | # The following test data is output to the logfile for each generated test: |
| 317 | # |
| 318 | # Testname - The executable test name (e.g. 01-allow, 02-basic, etc.) |
| 319 | # Syscall - The fuzzed syscall value to be simulated against the filter |
| 320 | # Arg0-5 - The fuzzed syscall arg values to be simulated against the filter |
| 321 | # |
| 322 | # Arguments: |
| 323 | # 1 string containing the batch name |
| 324 | # 2 value of test number from batch file |
| 325 | # 3 string containing line of test data from batch file |
| 326 | # |
| 327 | function run_test_bpf_sim_fuzz() { |
| 328 | local rc |
| 329 | |
| 330 | # begin splitting the test data from the line into individual variables |
| 331 | local line=($3) |
| 332 | local testname=${line[0]} |
| 333 | local stress_count=${line[1]} |
| 334 | |
| 335 | # check for stress count configuration via environment variables |
| 336 | [[ -n $LIBSECCOMP_TSTCFG_STRESSCNT ]] && \ |
| 337 | stress_count=$LIBSECCOMP_TSTCFG_STRESSCNT |
| 338 | |
| 339 | for i in $(get_seq 1 $stress_count); do |
| 340 | local sys=$(generate_random_data) |
| 341 | local -a arg=($(generate_random_data) $(generate_random_data) \ |
| 342 | $(generate_random_data) $(generate_random_data) \ |
| 343 | $(generate_random_data) $(generate_random_data)) |
| 344 | |
| 345 | # get the generated sub-test num string |
| 346 | local testnumstr=$(generate_test_num "$1" $2 $i) |
| 347 | |
| 348 | # set up log file test data line for this individual test, |
| 349 | # spacing is added to align the output in the correct columns |
| 350 | local -a COL_WIDTH=(26 17 17 17 17 17 17) |
| 351 | local testdata=$(printf "%-${COL_WIDTH[0]}s" $testname) |
| 352 | testdata+=$(printf "%-${COL_WIDTH[1]}s" $sys) |
| 353 | testdata+=$(printf "%-${COL_WIDTH[2]}s" ${arg[0]}) |
| 354 | testdata+=$(printf "%-${COL_WIDTH[3]}s" ${arg[1]}) |
| 355 | testdata+=$(printf "%-${COL_WIDTH[4]}s" ${arg[2]}) |
| 356 | testdata+=$(printf "%-${COL_WIDTH[5]}s" ${arg[3]}) |
| 357 | testdata+=$(printf "%-${COL_WIDTH[6]}s" ${arg[4]}) |
| 358 | testdata+=$(printf "%s" ${arg[5]}) |
| 359 | |
| 360 | # print out the generated test data to the log file |
| 361 | print_data "$testnumstr" "$testdata" |
| 362 | |
| 363 | # set up the syscall argument values to be passed to bpf_sim |
| 364 | for i in {0..5}; do |
| 365 | arg[$i]=" -$i ${arg[$i]} " |
| 366 | done |
| 367 | |
| 368 | # run the test command and put the BPF filter in a temp file |
| 369 | exec 4>$tmpfile |
| 370 | run_test_command "$testnumstr" "./$testname" "-b" 4 "" |
| 371 | rc=$? |
| 372 | exec 4>&- |
| 373 | if [[ $rc -ne 0 ]]; then |
| 374 | print_result $testnumstr "ERROR" "$testname rc=$rc" |
| 375 | stats_error=$(($stats_error+1)) |
| 376 | return |
| 377 | fi |
| 378 | |
| 379 | # simulate the fuzzed syscall data against the BPF filter, we |
| 380 | # don't verify the resulting action since we're just testing for |
| 381 | # stability |
| 382 | allow=$($GLBL_SYS_SIM -f $tmpfile -s $sys \ |
| 383 | ${arg[0]} ${arg[1]} ${arg[2]} ${arg[3]} ${arg[4]} \ |
| 384 | ${arg[5]}) |
| 385 | rc=$? |
| 386 | if [[ $rc -ne 0 ]]; then |
| 387 | print_result $testnumstr "ERROR" "bpf_sim rc=$rc" |
| 388 | stats_error=$(($stats_error+1)) |
| 389 | else |
| 390 | print_result $testnumstr "SUCCESS" "" |
| 391 | stats_success=$(($stats_success+1)) |
| 392 | fi |
| 393 | stats_all=$(($stats_all+1)) |
| 394 | done |
| 395 | } |
| 396 | |
| 397 | # |
| 398 | # Run the specified "bpf-sim" test |
| 399 | # |
| 400 | # Tests that belong to the "bpf-sim" test type generate a BPF filter and then |
| 401 | # run a simulated system call test to validate the filter. Tests that belong to |
| 402 | # this test type provide the following data on a single line in the input batch |
| 403 | # file: |
| 404 | # |
| 405 | # Testname - The executable test name (e.g. 01-allow, 02-basic, etc.) |
| 406 | # Arch - The architecture that the test should be run on (all, x86, x86_64) |
| 407 | # Syscall - The syscall to simulate against the generated filter |
| 408 | # Arg0-5 - The syscall arguments to simulate against the generated filter |
| 409 | # Result - The expected simulation result (ALLOW, KILL, etc.) |
| 410 | # |
| 411 | # If a range of syscall or argument values are specified (e.g. 1-9), a test is |
| 412 | # generated for every combination of range values. Otherwise, the individual |
| 413 | # test is run. |
| 414 | # |
| 415 | # Arguments: |
| 416 | # 1 string containing the batch name |
| 417 | # 2 value of test number from batch file |
| 418 | # 3 string containing line of test data from batch file |
| 419 | # |
| 420 | function run_test_bpf_sim() { |
| 421 | local rc |
| 422 | local LOW=1 |
| 423 | local HIGH=2 |
| 424 | local -a arg_empty=(false false false false false false) |
| 425 | |
| 426 | # begin splitting the test data from the line into individual variables |
| 427 | local line=($3) |
| 428 | local testname=${line[0]} |
| 429 | local testarch=${line[1]} |
| 430 | local low_syscall #line[2] |
| 431 | local high_syscall #line[2] |
| 432 | local -a low_arg #line[3-8] |
| 433 | local -a high_arg #line[3-8] |
| 434 | local result=${line[9]} |
| 435 | |
| 436 | # expand the architecture list |
| 437 | local simarch_tmp |
| 438 | local simarch_avoid |
| 439 | simarch_tmp="" |
| 440 | simarch_avoid="" |
| 441 | for arch_i in $(echo $testarch | sed -e 's/,/ /g'); do |
| 442 | case $arch_i in |
| 443 | all) |
| 444 | # add the native arch |
| 445 | simarch_tmp+=" $arch" |
| 446 | ;; |
| 447 | all_le) |
| 448 | # add the native arch only if it is little endian |
| 449 | if echo "$GLBL_ARCH_LE_SUPPORT" | grep -qw "$arch"; then |
| 450 | simarch_tmp+=" $arch" |
| 451 | fi |
| 452 | ;; |
| 453 | +all_le) |
| 454 | # add all of the little endian architectures |
| 455 | simarch_tmp+=" $GLBL_ARCH_LE_SUPPORT" |
| 456 | ;; |
| 457 | all_be) |
| 458 | # add the native arch only if it is big endian |
| 459 | if echo "$GLBL_ARCH_BE_SUPPORT" | grep -qw "$arch"; then |
| 460 | simarch_tmp+=" $arch" |
| 461 | fi |
| 462 | ;; |
| 463 | +all_be) |
| 464 | # add all of the big endian architectures |
| 465 | simarch_tmp+=" $GLBL_ARCH_BE_SUPPORT" |
| 466 | ;; |
| 467 | all_32) |
| 468 | # add the native arch only if it is 32-bit |
| 469 | if echo "$GLBL_ARCH_32B_SUPPORT" | grep -qw "$arch"; then |
| 470 | simarch_tmp+=" $arch" |
| 471 | fi |
| 472 | ;; |
| 473 | +all_32) |
| 474 | # add all of the 32-bit architectures |
| 475 | simarch_tmp+=" $GLBL_ARCH_32B_SUPPORT" |
| 476 | ;; |
| 477 | all_64) |
| 478 | # add the native arch only if it is 64-bit |
| 479 | if echo "$GLBL_ARCH_64B_SUPPORT" | grep -qw "$arch"; then |
| 480 | simarch_tmp+=" $arch" |
| 481 | fi |
| 482 | ;; |
| 483 | +all_64) |
| 484 | # add all of the 64-bit architectures |
| 485 | simarch_tmp+=" $GLBL_ARCH_64B_SUPPORT" |
| 486 | ;; |
| 487 | +*) |
| 488 | # add the architecture specified |
| 489 | simarch_tmp+=" ${arch_i:1}" |
| 490 | ;; |
| 491 | -*) |
| 492 | # remove the architecture specified |
| 493 | simarch_avoid+=" ${arch_i:1}" |
| 494 | ;; |
| 495 | *) |
| 496 | # add the architecture specified if it is native |
| 497 | if [[ "$arch_i" == "$arch" ]]; then |
| 498 | simarch_tmp+=" $arch_i" |
| 499 | fi |
| 500 | ;; |
| 501 | esac |
| 502 | done |
| 503 | |
| 504 | # make sure we remove any undesired architectures |
| 505 | local simarch_list |
| 506 | simarch_list="" |
| 507 | for arch_i in $simarch_tmp; do |
| 508 | if echo "$simarch_avoid" | grep -q -v -w "$arch_i"; then |
| 509 | simarch_list+=" $arch_i" |
| 510 | fi |
| 511 | done |
| 512 | simarch_list=$(echo $simarch_list | sed -e 's/ / /g;s/^ //;') |
| 513 | |
| 514 | # do we have any architectures remaining in the list? |
| 515 | if [[ $simarch_list == "" ]]; then |
| 516 | print_result $(generate_test_num "$1" $2 1) "SKIPPED" \ |
| 517 | "(architecture difference)" |
| 518 | stats_skipped=$(($stats_skipped+1)) |
| 519 | return |
| 520 | fi |
| 521 | |
| 522 | # get low and high range arg values |
| 523 | line_i=3 |
| 524 | for arg_i in {0..5}; do |
| 525 | low_arg[$arg_i]=$(get_range $LOW "${line[$line_i]}") |
| 526 | high_arg[$arg_i]=$(get_range $HIGH "${line[$line_i]}") |
| 527 | |
| 528 | # fix up empty arg values so the nested loops work |
| 529 | if [[ ${low_arg[$arg_i]} == "N" ]]; then |
| 530 | arg_empty[$arg_i]=true |
| 531 | low_arg[$arg_i]=0 |
| 532 | high_arg[$arg_i]=0 |
| 533 | fi |
| 534 | |
| 535 | line_i=$(($line_i+1)) |
| 536 | done |
| 537 | |
| 538 | # loop through the selected architectures |
| 539 | for simarch in $simarch_list; do |
| 540 | # print architecture header if necessary |
| 541 | if [[ $simarch != $simarch_list ]]; then |
| 542 | echo " test arch: $simarch" >&$logfd |
| 543 | fi |
| 544 | |
| 545 | # reset the subtest number |
| 546 | local subtestnum=1 |
| 547 | |
| 548 | # get low and high syscall values and convert them to numbers |
| 549 | low_syscall=$(get_range $LOW "${line[2]}") |
| 550 | if [[ ! $low_syscall =~ ^\-?[0-9]+$ ]]; then |
| 551 | low_syscall=$($GLBL_SYS_RESOLVER -a $simarch -t \ |
| 552 | $low_syscall) |
| 553 | if [[ $? -ne 0 ]]; then |
| 554 | print_result $(generate_test_num "$1" $2 1) \ |
| 555 | "ERROR" "sys_resolver rc=$?" |
| 556 | stats_error=$(($stats_error+1)) |
| 557 | return |
| 558 | fi |
| 559 | fi |
| 560 | high_syscall=$(get_range $HIGH "${line[2]}") |
| 561 | if [[ ! $high_syscall =~ ^\-?[0-9]+$ ]]; then |
| 562 | high_syscall=$($GLBL_SYS_RESOLVER -a $simarch -t \ |
| 563 | $high_syscall) |
| 564 | if [[ $? -ne 0 ]]; then |
| 565 | print_result $(generate_test_num "$1" $2 1) \ |
| 566 | "ERROR" "sys_resolver rc=$?" |
| 567 | stats_error=$(($stats_error+1)) |
| 568 | return |
| 569 | fi |
| 570 | fi |
| 571 | |
| 572 | # if ranges exist, the following will loop through all syscall |
| 573 | # and arg ranges and generate/run every combination of requested |
| 574 | # tests; if no ranges were specified, then the single test is |
| 575 | # run |
| 576 | for sys in $(get_seq $low_syscall $high_syscall); do |
| 577 | for arg0 in $(get_seq ${low_arg[0]} ${high_arg[0]}); do |
| 578 | for arg1 in $(get_seq ${low_arg[1]} ${high_arg[1]}); do |
| 579 | for arg2 in $(get_seq ${low_arg[2]} ${high_arg[2]}); do |
| 580 | for arg3 in $(get_seq ${low_arg[3]} ${high_arg[3]}); do |
| 581 | for arg4 in $(get_seq ${low_arg[4]} ${high_arg[4]}); do |
| 582 | for arg5 in $(get_seq ${low_arg[5]} ${high_arg[5]}); do |
| 583 | local -a arg=($arg0 $arg1 $arg2 $arg3 $arg4 $arg5) |
| 584 | |
| 585 | # Get the generated sub-test num string |
| 586 | local testnumstr=$(generate_test_num "$1" $2 \ |
| 587 | $subtestnum) |
| 588 | |
| 589 | # format any empty args to print to log file |
| 590 | for i in {0..5}; do |
| 591 | if ${arg_empty[$i]}; then |
| 592 | arg[$i]="N" |
| 593 | fi |
| 594 | done |
| 595 | |
| 596 | # set up log file test data line for this |
| 597 | # individual test, spacing is added to align |
| 598 | # the output in the correct columns |
| 599 | local -a COL_WIDTH=(26 08 14 11 17 21 09 06 06) |
| 600 | local testdata=$(printf "%-${COL_WIDTH[0]}s" $testname) |
| 601 | testdata+=$(printf "%-${COL_WIDTH[1]}s" $simarch) |
| 602 | testdata+=$(printf "%-${COL_WIDTH[2]}s" $sys) |
| 603 | testdata+=$(printf "%-${COL_WIDTH[3]}s" ${arg[0]}) |
| 604 | testdata+=$(printf "%-${COL_WIDTH[4]}s" ${arg[1]}) |
| 605 | testdata+=$(printf "%-${COL_WIDTH[5]}s" ${arg[2]}) |
| 606 | testdata+=$(printf "%-${COL_WIDTH[6]}s" ${arg[3]}) |
| 607 | testdata+=$(printf "%-${COL_WIDTH[7]}s" ${arg[4]}) |
| 608 | testdata+=$(printf "%-${COL_WIDTH[8]}s" ${arg[5]}) |
| 609 | testdata+=$(printf "%-${COL_WIDTH[9]}s" $result) |
| 610 | |
| 611 | # print out the test data to the log file |
| 612 | print_data "$testnumstr" "$testdata" |
| 613 | |
| 614 | # set up the syscall arguments to be passed to bpf_sim |
| 615 | for i in {0..5}; do |
| 616 | if ${arg_empty[$i]}; then |
| 617 | arg[$i]="" |
| 618 | else |
| 619 | arg[$i]=" -$i ${arg[$i]} " |
| 620 | fi |
| 621 | done |
| 622 | |
| 623 | # run the test command and put the BPF in a temp file |
| 624 | exec 4>$tmpfile |
| 625 | run_test_command "$testnumstr" "./$testname" "-b" 4 "" |
| 626 | rc=$? |
| 627 | exec 4>&- |
| 628 | if [[ $rc -ne 0 ]]; then |
| 629 | print_result $testnumstr \ |
| 630 | "ERROR" "$testname rc=$rc" |
| 631 | stats_error=$(($stats_error+1)) |
| 632 | return |
| 633 | fi |
| 634 | |
| 635 | # simulate the specified syscall against the BPF filter |
| 636 | # and verify the results |
| 637 | action=$($GLBL_SYS_SIM -a $simarch -f $tmpfile \ |
| 638 | -s $sys ${arg[0]} ${arg[1]} ${arg[2]} \ |
| 639 | ${arg[3]} ${arg[4]} ${arg[5]}) |
| 640 | rc=$? |
| 641 | if [[ $rc -ne 0 ]]; then |
| 642 | print_result $testnumstr \ |
| 643 | "ERROR" "bpf_sim rc=$rc" |
| 644 | stats_error=$(($stats_error+1)) |
| 645 | elif [[ "$action" != "$result" ]]; then |
| 646 | print_result $testnumstr "FAILURE" \ |
| 647 | "bpf_sim resulted in $action" |
| 648 | stats_failure=$(($stats_failure+1)) |
| 649 | else |
| 650 | print_result $testnumstr "SUCCESS" "" |
| 651 | stats_success=$(($stats_success+1)) |
| 652 | fi |
| 653 | stats_all=$(($stats_all+1)) |
| 654 | |
| 655 | subtestnum=$(($subtestnum+1)) |
| 656 | done # syscall |
| 657 | done # arg0 |
| 658 | done # arg1 |
| 659 | done # arg2 |
| 660 | done # arg3 |
| 661 | done # arg4 |
| 662 | done # arg5 |
| 663 | done # architecture |
| 664 | } |
| 665 | |
| 666 | # |
| 667 | # Run the specified "basic" test |
| 668 | # |
| 669 | # Tests that belong to the "basic" test type will simply have the command |
| 670 | # specified in the input batch file. The command must return zero for success |
| 671 | # and non-zero for failure. |
| 672 | # |
| 673 | # Arguments: |
| 674 | # 1 value of test number from batch file |
| 675 | # 2 string containing line of test data from batch file |
| 676 | # |
| 677 | function run_test_basic() { |
| 678 | local rc |
| 679 | local cmd |
| 680 | |
| 681 | # if the test is a script, only run it in native/c mode |
| 682 | if [[ $mode != "c" && "$2" == *.sh ]]; then |
| 683 | print_result "$1" "SKIPPED" "(only valid in native/c mode)" |
| 684 | stats_skipped=$(($stats_skipped+1)) |
| 685 | return |
| 686 | fi |
| 687 | |
| 688 | # print out the input test data to the log file |
| 689 | print_data "$1" "$2" |
| 690 | |
| 691 | # check and adjust if we are doing a VPATH build |
| 692 | if [[ -x "./$2" ]]; then |
| 693 | cmd="./$2" |
| 694 | else |
| 695 | cmd="${srcdir}/$2" |
| 696 | fi |
| 697 | |
| 698 | # run the command |
| 699 | run_test_command "$1" "$cmd" "" "" "" |
| 700 | rc=$? |
| 701 | if [[ $rc -ne 0 ]]; then |
| 702 | print_result $1 "FAILURE" "$2 rc=$rc" |
| 703 | stats_failure=$(($stats_failure+1)) |
| 704 | else |
| 705 | print_result $1 "SUCCESS" "" |
| 706 | stats_success=$(($stats_success+1)) |
| 707 | fi |
| 708 | stats_all=$(($stats_all+1)) |
| 709 | } |
| 710 | |
| 711 | # |
| 712 | # Run the specified "bpf-valgrind" test |
| 713 | # |
| 714 | # Tests that belong to the "bpf-valgrind" test type generate a BPF filter |
| 715 | # while running under valgrind to detect any memory errors. |
| 716 | # |
| 717 | # Arguments: |
| 718 | # 1 value of test number from batch file |
| 719 | # 2 string containing line of test data from batch file |
| 720 | # |
| 721 | function run_test_bpf_valgrind() { |
| 722 | local rc |
| 723 | |
| 724 | # we only support the native/c test mode here |
| 725 | if [[ $mode != "c" ]]; then |
| 726 | print_result "$1" "SKIPPED" "(only valid in native/c mode)" |
| 727 | stats_skipped=$(($stats_skipped+1)) |
| 728 | return |
| 729 | fi |
| 730 | |
| 731 | # print out the input test data to the log file |
| 732 | print_data "$1" "$2" |
| 733 | |
| 734 | # build the command |
| 735 | testvalgrind="valgrind \ |
| 736 | --tool=memcheck \ |
| 737 | --error-exitcode=1 \ |
| 738 | --leak-check=full \ |
| 739 | --read-var-info=yes \ |
| 740 | --track-origins=yes \ |
| 741 | --suppressions=$basedir/valgrind_test.supp" |
| 742 | if [[ -n $logfile ]]; then |
| 743 | testvalgrind+=" --log-fd=$logfd" |
| 744 | fi |
| 745 | if [[ -z $verbose ]]; then |
| 746 | testvalgrind+=" --quiet --log-fd=4" |
| 747 | fi |
| 748 | |
| 749 | # run the command |
| 750 | exec 4>/dev/null |
| 751 | print_valgrind "$1" |
| 752 | run_test_command "$1" "$testvalgrind --" "./$2 -b" 4 2 |
| 753 | rc=$? |
| 754 | exec 4>&- |
| 755 | if [[ $rc -ne 0 ]]; then |
| 756 | print_result $1 "FAILURE" "$2 rc=$rc" |
| 757 | stats_failure=$(($stats_failure+1)) |
| 758 | else |
| 759 | print_result $1 "SUCCESS" "" |
| 760 | stats_success=$(($stats_success+1)) |
| 761 | fi |
| 762 | stats_all=$(($stats_all+1)) |
| 763 | } |
| 764 | |
| 765 | # |
| 766 | # Run the specified "live" test |
| 767 | # |
| 768 | # Tests that belong to the "live" test type will attempt to run a live test |
| 769 | # of the libseccomp library on the host system; for obvious reasons the host |
| 770 | # system must support seccomp mode 2 for this to work correctly. |
| 771 | # |
| 772 | # Arguments: |
| 773 | # 1 value of test number from batch file |
| 774 | # 2 string containing line of test data from batch file |
| 775 | # |
| 776 | function run_test_live() { |
| 777 | local rc |
| 778 | local api |
| 779 | local line=($2) |
| 780 | |
| 781 | # parse the test line |
| 782 | line_cmd=${line[0]} |
| 783 | line_api=${line[1]} |
| 784 | line_act=${line[2]} |
| 785 | line_test="$line_cmd $line_api $line_act" |
| 786 | |
| 787 | # check the api level |
| 788 | api=$($GLBL_SYS_API) |
| 789 | if [[ $api -lt $line_api ]]; then |
| 790 | # runtime api level is too low |
| 791 | print_result "$1" "SKIPPED" "(api level)" |
| 792 | stats_skipped=$(($stats_skipped+1)) |
| 793 | return |
| 794 | fi |
| 795 | |
| 796 | # print out the input test data to the log file |
| 797 | print_data "$1" "$2" |
| 798 | |
| 799 | # run the command |
| 800 | exec 4>/dev/null |
| 801 | run_test_command "$1" "./$line_cmd" "$line_act" "" 4 |
| 802 | rc=$? |
| 803 | exec 4>&- |
| 804 | stats_all=$(($stats_all+1)) |
| 805 | |
| 806 | # setup the arch specific return values |
| 807 | case "$arch" in |
| 808 | x86|x86_64|x32|arm|aarch64|loongarch64|m68k|parisc|parisc64|ppc|ppc64|ppc64le|ppc|s390|s390x|riscv64|sh|sheb) |
| 809 | rc_kill_process=159 |
| 810 | rc_kill=159 |
| 811 | rc_allow=160 |
| 812 | rc_trap=161 |
| 813 | rc_trace=162 |
| 814 | rc_errno=163 |
| 815 | rc_log=164 |
| 816 | ;; |
| 817 | mips|mipsel|mips64|mips64n32|mipsel64|mipsel64n32) |
| 818 | rc_kill_process=140 |
| 819 | rc_kill=140 |
| 820 | rc_allow=160 |
| 821 | rc_trap=161 |
| 822 | rc_trace=162 |
| 823 | rc_errno=163 |
| 824 | rc_log=164 |
| 825 | ;; |
| 826 | *) |
| 827 | print_result $testnumstr "ERROR" "arch $arch not supported" |
| 828 | stats_error=$(($stats_error+1)) |
| 829 | return |
| 830 | ;; |
| 831 | esac |
| 832 | |
| 833 | # verify the results |
| 834 | if [[ $line_act == "KILL_PROCESS" && $rc -eq $rc_kill_process ]]; then |
| 835 | print_result $1 "SUCCESS" "" |
| 836 | stats_success=$(($stats_success+1)) |
| 837 | elif [[ $line_act == "KILL" && $rc -eq $rc_kill ]]; then |
| 838 | print_result $1 "SUCCESS" "" |
| 839 | stats_success=$(($stats_success+1)) |
| 840 | elif [[ $line_act == "ALLOW" && $rc -eq $rc_allow ]]; then |
| 841 | print_result $1 "SUCCESS" "" |
| 842 | stats_success=$(($stats_success+1)) |
| 843 | elif [[ $line_act == "TRAP" && $rc -eq $rc_trap ]]; then |
| 844 | print_result $1 "SUCCESS" "" |
| 845 | stats_success=$(($stats_success+1)) |
| 846 | elif [[ $line_act == "TRACE" ]]; then |
| 847 | print_result $1 "ERROR" "unsupported action \"$line_act\"" |
| 848 | stats_error=$(($stats_error+1)) |
| 849 | elif [[ $line_act == "ERRNO" && $rc -eq $rc_errno ]]; then |
| 850 | print_result $1 "SUCCESS" "" |
| 851 | stats_success=$(($stats_success+1)) |
| 852 | elif [[ $line_act == "LOG" && $rc -eq $rc_log ]]; then |
| 853 | print_result $1 "SUCCESS" "" |
| 854 | stats_success=$(($stats_success+1)) |
| 855 | else |
| 856 | print_result $1 "FAILURE" "$line_test rc=$rc" |
| 857 | stats_failure=$(($stats_failure+1)) |
| 858 | fi |
| 859 | } |
| 860 | |
| 861 | # |
| 862 | # Run a single test from the specified batch |
| 863 | # |
| 864 | # Arguments: |
| 865 | # 1 string containing the batch name |
| 866 | # 2 value of test number from batch file |
| 867 | # 3 string containing line of test data from batch file |
| 868 | # 4 string containing test type that this test belongs to |
| 869 | # |
| 870 | function run_test() { |
| 871 | # generate the test number string for the line of batch test data |
| 872 | local testnumstr=$(generate_test_num "$1" $2 1) |
| 873 | |
| 874 | # ensure we only run tests which match the specified type |
| 875 | match_csv_word "$type" "$4" |
| 876 | local type_match=$? |
| 877 | [[ -n $type && $type_match -eq 1 ]] && return |
| 878 | |
| 879 | # execute the function corresponding to the test type |
| 880 | if [[ "$4" == "basic" ]]; then |
| 881 | run_test_basic "$testnumstr" "$3" |
| 882 | elif [[ "$4" == "bpf-sim" ]]; then |
| 883 | run_test_bpf_sim "$1" $2 "$3" |
| 884 | elif [[ "$4" == "bpf-sim-fuzz" ]]; then |
| 885 | run_test_bpf_sim_fuzz "$1" $2 "$3" |
| 886 | elif [[ "$4" == "bpf-valgrind" ]]; then |
| 887 | # only run this test if valgrind is installed |
| 888 | if check_deps valgrind; then |
| 889 | run_test_bpf_valgrind "$testnumstr" "$3" |
| 890 | else |
| 891 | print_result $testnumstr "SKIPPED" \ |
| 892 | "(valgrind not installed)" |
| 893 | stats_skipped=$(($stats_skipped+1)) |
| 894 | fi |
| 895 | elif [[ "$4" == "live" ]]; then |
| 896 | # only run this test if explicitly requested |
| 897 | if [[ -n $type ]]; then |
| 898 | run_test_live "$testnumstr" "$3" |
| 899 | else |
| 900 | print_result $testnumstr "SKIPPED" \ |
| 901 | "(must specify live tests)" |
| 902 | stats_skipped=$(($stats_skipped+1)) |
| 903 | fi |
| 904 | else |
| 905 | print_result $testnumstr "ERROR" "test type $4 not supported" |
| 906 | stats_error=$(($stats_error+1)) |
| 907 | fi |
| 908 | } |
| 909 | |
| 910 | # |
| 911 | # Run the requested test batch |
| 912 | # |
| 913 | # Arguments: |
| 914 | # 1 Batch name |
| 915 | # |
| 916 | function run_test_batch() { |
| 917 | local testnum=1 |
| 918 | local batch_name=$1 |
| 919 | |
| 920 | # open temporary file |
| 921 | if [[ -n $tmpdir ]]; then |
| 922 | tmpfile=$(mktemp -t regression_XXXXXX --tmpdir=$tmpdir) |
| 923 | else |
| 924 | tmpfile=$(mktemp -t regression_XXXXXX) |
| 925 | fi |
| 926 | |
| 927 | # reset the stats |
| 928 | stats_all=0 |
| 929 | stats_skipped=0 |
| 930 | stats_success=0 |
| 931 | stats_failure=0 |
| 932 | stats_error=0 |
| 933 | |
| 934 | # print a test batch header |
| 935 | echo " batch name: $batch_name" >&$logfd |
| 936 | |
| 937 | # loop through each line and run the requested tests |
| 938 | while read line; do |
| 939 | # strip whitespace, comments, and blank lines |
| 940 | line=$(echo "$line" | \ |
| 941 | sed -e 's/^[\t ]*//;s/[\t ]*$//;' | \ |
| 942 | sed -e '/^[#].*$/d;/^$/d') |
| 943 | if [[ -z $line ]]; then |
| 944 | continue |
| 945 | fi |
| 946 | |
| 947 | if [[ $line =~ ^"test type": ]]; then |
| 948 | test_type=$(echo "$line" | \ |
| 949 | sed -e 's/^test type: //;') |
| 950 | # print a test mode and type header |
| 951 | echo " test mode: $mode" >&$logfd |
| 952 | echo " test type: $test_type" >&$logfd |
| 953 | continue |
| 954 | fi |
| 955 | |
| 956 | if [[ ${single_list[@]} ]]; then |
| 957 | for i in ${single_list[@]}; do |
| 958 | if [ $i -eq $testnum ]; then |
| 959 | # we're running a single test |
| 960 | run_test "$batch_name" \ |
| 961 | $testnum "$line" \ |
| 962 | "$test_type" |
| 963 | fi |
| 964 | done |
| 965 | else |
| 966 | # we're running a test from a batch |
| 967 | run_test "$batch_name" \ |
| 968 | $testnum "$line" "$test_type" |
| 969 | fi |
| 970 | testnum=$(($testnum+1)) |
| 971 | done < "$file" |
| 972 | |
| 973 | |
| 974 | # dump our stats |
| 975 | local stats=$batch_name.$mode.stats |
| 976 | > $stats |
| 977 | echo -n "$stats_all $stats_skipped $stats_success " >> $stats |
| 978 | echo -n "$stats_failure $stats_error " >> $stats |
| 979 | echo "" >> $stats |
| 980 | |
| 981 | # cleanup the temporary file we created |
| 982 | rm -f $tmpfile |
| 983 | } |
| 984 | |
| 985 | # |
| 986 | # Run the requested test batch |
| 987 | # |
| 988 | # Arguments: |
| 989 | # 1 Log file |
| 990 | # 2 PID to watch |
| 991 | # |
| 992 | function tail_log() { |
| 993 | local log=$1 |
| 994 | local pid=$2 |
| 995 | |
| 996 | # dump the output |
| 997 | tail -n +0 --pid=$pid -f $log |
| 998 | |
| 999 | # accumulate the stats |
| 1000 | local stats=$(echo $log | sed 's/\.log$/.stats/') |
| 1001 | stats_all=$(( $stats_all + $(awk '{ print $1 }' $stats) )) |
| 1002 | stats_skipped=$(( $stats_skipped + $(awk '{ print $2 }' $stats) )) |
| 1003 | stats_success=$(( $stats_success + $(awk '{ print $3 }' $stats) )) |
| 1004 | stats_failure=$(( $stats_failure + $(awk '{ print $4 }' $stats) )) |
| 1005 | stats_error=$(( $stats_error + $(awk '{ print $5 }' $stats) )) |
| 1006 | } |
| 1007 | |
| 1008 | # |
| 1009 | # Run the requested tests |
| 1010 | # |
| 1011 | function run_tests() { |
| 1012 | local job_cnt=0 |
| 1013 | local tail_cnt=0 |
| 1014 | local -a job_pids |
| 1015 | local -a job_logs |
| 1016 | |
| 1017 | # loop through all test files |
| 1018 | for file in $basedir/*.tests; do |
| 1019 | local batch_requested=false |
| 1020 | local batch_name="" |
| 1021 | |
| 1022 | # extract the batch name from the file name |
| 1023 | batch_name=$(basename $file .tests) |
| 1024 | |
| 1025 | # check if this batch was requested |
| 1026 | if [[ ${batch_list[@]} ]]; then |
| 1027 | for b in ${batch_list[@]}; do |
| 1028 | if [[ $b == $batch_name ]]; then |
| 1029 | batch_requested=true |
| 1030 | break |
| 1031 | fi |
| 1032 | done |
| 1033 | if ! $batch_requested; then |
| 1034 | continue |
| 1035 | fi |
| 1036 | fi |
| 1037 | |
| 1038 | # run the test batch |
| 1039 | > $batch_name.$mode.log |
| 1040 | > $batch_name.$mode.stats |
| 1041 | run_test_batch $batch_name >& $batch_name.$mode.log & |
| 1042 | job_pids[job_cnt]=$! |
| 1043 | job_logs[job_cnt]=$batch_name.$mode.log |
| 1044 | job_cnt=$(( $job_cnt + 1 )) |
| 1045 | |
| 1046 | # output the next log if the job queue is full |
| 1047 | if [[ $(jobs | wc -l) -ge $jobs ]]; then |
| 1048 | tail_log ${job_logs[$tail_cnt]} ${job_pids[$tail_cnt]} |
| 1049 | tail_cnt=$(( $tail_cnt + 1 )) |
| 1050 | fi |
| 1051 | done |
| 1052 | |
| 1053 | # output any leftovers |
| 1054 | for i in $(seq $tail_cnt $(( $job_cnt - 1 ))); do |
| 1055 | tail_log ${job_logs[$i]} ${job_pids[$i]} |
| 1056 | done |
| 1057 | } |
| 1058 | |
| 1059 | #### |
| 1060 | # main |
| 1061 | |
| 1062 | # verify general script dependencies |
| 1063 | verify_deps head |
| 1064 | verify_deps sed |
| 1065 | verify_deps awk |
| 1066 | verify_deps tr |
| 1067 | |
| 1068 | # global variables |
| 1069 | declare -a batch_list |
| 1070 | declare -a single_list |
| 1071 | arch= |
| 1072 | batch_count=0 |
| 1073 | logfile= |
| 1074 | logfd= |
| 1075 | mode_list="" |
| 1076 | runall= |
| 1077 | singlecount=0 |
| 1078 | tmpfile="" |
| 1079 | tmpdir="" |
| 1080 | type= |
| 1081 | verbose= |
| 1082 | jobs=1 |
| 1083 | stats_all=0 |
| 1084 | stats_skipped=0 |
| 1085 | stats_success=0 |
| 1086 | stats_failure=0 |
| 1087 | stats_error=0 |
| 1088 | |
| 1089 | # set the test root directory |
| 1090 | basedir=$(dirname $0) |
| 1091 | |
| 1092 | # set the test harness pid |
| 1093 | pid=$$ |
| 1094 | |
| 1095 | # parse the command line |
| 1096 | while getopts "ab:gj:l:m:s:t:T:vh" opt; do |
| 1097 | case $opt in |
| 1098 | a) |
| 1099 | runall=1 |
| 1100 | ;; |
| 1101 | b) |
| 1102 | batch_list[batch_count]="$OPTARG" |
| 1103 | batch_count=$(($batch_count+1)) |
| 1104 | ;; |
| 1105 | j) |
| 1106 | jobs=$OPTARG |
| 1107 | ;; |
| 1108 | l) |
| 1109 | logfile="$OPTARG" |
| 1110 | ;; |
| 1111 | m) |
| 1112 | case $OPTARG in |
| 1113 | c) |
| 1114 | mode_list="$mode_list c" |
| 1115 | ;; |
| 1116 | python) |
| 1117 | verify_deps python |
| 1118 | mode_list="$mode_list python" |
| 1119 | ;; |
| 1120 | *) |
| 1121 | usage |
| 1122 | exit 1 |
| 1123 | esac |
| 1124 | ;; |
| 1125 | s) |
| 1126 | single_list[single_count]=$OPTARG |
| 1127 | single_count=$(($single_count+1)) |
| 1128 | ;; |
| 1129 | t) |
| 1130 | tmpdir="$OPTARG" |
| 1131 | ;; |
| 1132 | T) |
| 1133 | type="$OPTARG" |
| 1134 | ;; |
| 1135 | v) |
| 1136 | verbose=1 |
| 1137 | ;; |
| 1138 | h|*) |
| 1139 | usage |
| 1140 | exit 1 |
| 1141 | ;; |
| 1142 | esac |
| 1143 | done |
| 1144 | |
| 1145 | # use mode list from environment if provided |
| 1146 | [[ -z $mode_list && -n $LIBSECCOMP_TSTCFG_MODE_LIST ]] && mode_list=$LIBSECCOMP_TSTCFG_MODE_LIST |
| 1147 | |
| 1148 | # use job count from environment if provided and do some sanity checking |
| 1149 | [[ -n $LIBSECCOMP_TSTCFG_JOBS ]] && jobs=$LIBSECCOMP_TSTCFG_JOBS |
| 1150 | if [[ $jobs -lt 1 ]]; then |
| 1151 | jobs=$(cat /proc/cpuinfo | grep "^processor" | wc -l) |
| 1152 | fi |
| 1153 | |
| 1154 | # determine the mode test automatically |
| 1155 | if [[ -z $mode_list ]]; then |
| 1156 | # always perform the native c tests |
| 1157 | mode_list="c" |
| 1158 | |
| 1159 | # query the build configuration |
| 1160 | if [[ -r "../configure.h" ]]; then |
| 1161 | # python tests |
| 1162 | [[ "$(grep "ENABLE_PYTHON" ../configure.h | \ |
| 1163 | awk '{ print $3 }')" = "1" ]] && \ |
| 1164 | mode_list="$mode_list python" |
| 1165 | fi |
| 1166 | fi |
| 1167 | |
| 1168 | # check if we specified a list of tests via the environment variable |
| 1169 | if [[ -n $LIBSECCOMP_TSTCFG_BATCHES ]]; then |
| 1170 | for i in $(echo "$LIBSECCOMP_TSTCFG_BATCHES" | sed 's/,/ /g'); do |
| 1171 | batch_list[batch_count]="$i" |
| 1172 | batch_count=$(($batch_count+1)) |
| 1173 | done |
| 1174 | fi |
| 1175 | |
| 1176 | # default to all tests if batch or single tests not requested |
| 1177 | if [[ -z $batch_list ]] && [[ -z $single_list ]]; then |
| 1178 | runall=1 |
| 1179 | fi |
| 1180 | |
| 1181 | # drop any requested batch and single tests if all tests were requested |
| 1182 | if [[ -n $runall ]]; then |
| 1183 | batch_list=() |
| 1184 | single_list=() |
| 1185 | fi |
| 1186 | |
| 1187 | # check for configuration via environment variables |
| 1188 | [[ -z $type && -n $LIBSECCOMP_TSTCFG_TYPE ]] && type=$LIBSECCOMP_TSTCFG_TYPE |
| 1189 | |
| 1190 | # open log file for append (default to stdout) |
| 1191 | if [[ -n $logfile ]]; then |
| 1192 | # force single threaded to preserve the output |
| 1193 | jobs=1 |
| 1194 | |
| 1195 | logfd=3 |
| 1196 | exec 3>>"$logfile" |
| 1197 | else |
| 1198 | logfd=1 |
| 1199 | fi |
| 1200 | |
| 1201 | # determine the current system's architecture |
| 1202 | arch=$($GLBL_SYS_ARCH) |
| 1203 | |
| 1204 | # display the test output and run the requested tests |
| 1205 | echo "=============== $(date) ===============" >&$logfd |
| 1206 | echo "Regression Test Report (\"regression $*\")" >&$logfd |
| 1207 | for mode in $mode_list; do |
| 1208 | run_tests |
| 1209 | done |
| 1210 | echo "Regression Test Summary" >&$logfd |
| 1211 | echo " tests run: $stats_all" >&$logfd |
| 1212 | echo " tests skipped: $stats_skipped" >&$logfd |
| 1213 | echo " tests passed: $stats_success" >&$logfd |
| 1214 | echo " tests failed: $stats_failure" >&$logfd |
| 1215 | echo " tests errored: $stats_error" >&$logfd |
| 1216 | echo "============================================================" >&$logfd |
| 1217 | |
| 1218 | # cleanup and exit |
| 1219 | rc=0 |
| 1220 | [[ $stats_failure -gt 0 ]] && rc=$(($rc + 2)) |
| 1221 | [[ $stats_error -gt 0 ]] && rc=$(($rc + 4)) |
| 1222 | |
| 1223 | exit $rc |