]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
check: add ability to exclude a test or group
authorJohannes Thumshirn <jthumshirn@suse.de>
Fri, 19 May 2017 13:17:10 +0000 (15:17 +0200)
committerOmar Sandoval <osandov@fb.com>
Fri, 19 May 2017 18:44:02 +0000 (11:44 -0700)
Add the ability to exclude a test or whole test group from a test
run. Thus a user can explicitly decide which tests to skip like in
this example where one wants all of the 'block' group but block/001.

block/002 (remove a device while running blktrace)
    0.835s           ...
    runtime  + test  ...
[  363.132053] run blktests block/002 at 2017-05-19 13:01:56
[  363.136844] scsi host0: scsi_debug: version 1.86 [20160430]
[  363.136844]   dev_size_mb=8, opts=0x0, submit_queues=1, statistics=0
[  363.138819] scsi 0:0:0:0: Direct-Access     Linux    scsi_debug       0186 PQ: 0 ANSI: 7
[  363.199172] sd 0:0:0:0: [sda] 16384 512-byte logical blocks: (8.39 MB/8.00 MiB)
[  363.207053] sd 0:0:0:0: [sda] Write Protect is off
block/002 (remove a device while running blktrace)           [passed]

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
[Omar: use associative array, make explicit run take precedence over -x]
Signed-off-by: Omar Sandoval <osandov@fb.com>
check

diff --git a/check b/check
index d445959d50e234cc0a8cd757cf7b66f9f1b5e125..50de0e8832fba3151892a2228b3b328350dbd366 100755 (executable)
--- a/check
+++ b/check
@@ -47,8 +47,13 @@ _found_test() {
                return 1
        fi
 
-       if (( !explicit && QUICK_RUN && !QUICK && !TIMED )); then
-               return
+       if (( ! explicit )); then
+               if (( QUICK_RUN && !QUICK && !TIMED )); then
+                       return
+               fi
+               if [[ -n ${EXCLUDE["$test_name"]} ]]; then
+                       return
+               fi
        fi
 
        printf '%s\0' "$test_name"
@@ -56,8 +61,16 @@ _found_test() {
 
 _found_group() {
        local group="$1"
+       local explicit="$2"
 
        local test_path
+
+       if (( ! explicit )); then
+               if [[ -n ${EXCLUDE["$group"]} ]]; then
+                       return
+               fi
+       fi
+
        while IFS= read -r -d '' test_path; do
                _found_test "${test_path#tests/}" 0
        done < <(find "tests/$group" -type f -name '[0-9][0-9][0-9]' -print0)
@@ -69,7 +82,7 @@ _find_tests() {
                local group_path
                while IFS= read -r -d '' group_path; do
                        if [[ $group_path != tests/meta ]]; then
-                               _found_group "${group_path#tests/}"
+                               _found_group "${group_path#tests/}" 0
                        fi
                done < <(find tests -mindepth 2 -type f -name group -printf '%h\0')
        else
@@ -89,7 +102,7 @@ _find_tests() {
                        filter="${filter#tests/}"
 
                        if [[ -d tests/$filter ]]; then
-                               _found_group "$filter"
+                               _found_group "$filter" 1
                        elif [[ -f tests/$filter ]]; then
                                _found_test "$filter" 1
                        else
@@ -518,6 +531,9 @@ Test runs:
                         runtime of longer tests to the given timeout,
                         defaulting to 30 seconds)
 
+  -x, --exclude=TEST     exclude a test (or test group) from the list of
+                        tests to run
+
 Miscellaneous:
   -h, --help             display this help message and exit"
 
@@ -533,7 +549,7 @@ Miscellaneous:
        esac
 }
 
-TEMP=$(getopt -o 'q::h' --long 'quick::,help' -n "$0" -- "$@")
+TEMP=$(getopt -o 'q::x:h' --long 'quick::,exclude:,help' -n "$0" -- "$@")
 if [[ $? -ne 0 ]]; then
        exit 1
 fi
@@ -542,6 +558,7 @@ eval set -- "$TEMP"
 unset TEMP
 
 QUICK_RUN=0
+EXCLUDE=()
 while true; do
        case "$1" in
                '-q'|'--quick')
@@ -549,6 +566,10 @@ while true; do
                        TIMEOUT="${2:-30}"
                        shift 2
                        ;;
+               '-x'|'--exclude')
+                       EXCLUDE+=("$2")
+                       shift 2
+                       ;;
                '-h'|'--help')
                        usage out
                        ;;
@@ -570,4 +591,13 @@ if [[ ! -v TEST_DEVS ]]; then
        TEST_DEVS=()
 fi
 
+# Convert the exclude list to an associative array.
+TEMP_EXCLUDE=("${EXCLUDE[@]}")
+unset EXCLUDE
+declare -A EXCLUDE
+for filter in "${TEMP_EXCLUDE[@]}"; do
+       EXCLUDE["$filter"]=1
+done
+unset TEMP_EXCLUDE
+
 _check "$@"