]> www.infradead.org Git - users/hch/blktests.git/commitdiff
check: Add configuration file option
authorAndré Almeida <andrealmeid@collabora.com>
Wed, 30 Oct 2019 22:27:06 +0000 (19:27 -0300)
committerOmar Sandoval <osandov@fb.com>
Wed, 13 Nov 2019 20:16:16 +0000 (12:16 -0800)
Add an option to be possible to use a different configuration file
rather than the default "config" file.

Signed-off-by: André Almeida <andrealmeid@collabora.com>
[Omar: rework so command line options still take precedence over config,
 document precedence]
Signed-off-by: Omar Sandoval <osandov@fb.com>
Documentation/running-tests.md
check

index 675dac70ac435880f75816135884b91ebed721d9..cda75eb897ccce5309c05f1a4b57513c573d6b52 100644 (file)
@@ -20,8 +20,13 @@ will run all tests in the `loop` group and the `block/002` test.
 ## Configuration
 
 Test configuration goes in the `config` file at the top-level directory of the
-blktests repository. Test configuration options can also be set as environment
-variables instead of in the `config` file.
+blktests repository. A different file can be specified with the `-c` command
+line option. The `-c` option can be used multiple times; the files will all be
+loaded in the order that they are specified on the command line.
+
+Test configuration options can also be set as environment variables. The
+configuration file has precedence over environment variables, and command line
+options have precedence over the configuration file.
 
 ### Test Devices
 
diff --git a/check b/check
index a19b9dc65d1e476cc4a13f55a6f6b2db9dc88ef1..5153dcd8645467f722993eddd16a5d87aa308077 100755 (executable)
--- a/check
+++ b/check
@@ -636,6 +636,10 @@ Test runs:
                         tests to run
 
 Miscellaneous:
+  -c, --config=FILE     load configuration from FILE instead of the default
+                        (\"./config\"); if this option is used multiple times,
+                        all of the given files are loaded
+
   -h, --help             display this help message and exit"
 
        case "$1" in
@@ -650,60 +654,39 @@ Miscellaneous:
        esac
 }
 
-if ! TEMP=$(getopt -o 'do:q::x:h' --long 'device-only,quick::,exclude:,output:,help' -n "$0" -- "$@"); then
+if ! TEMP=$(getopt -o 'do:q::x:c:h' --long 'device-only,quick::,exclude:,output:,config:,help' -n "$0" -- "$@"); then
        exit 1
 fi
 
 eval set -- "$TEMP"
 unset TEMP
 
-LOGGER_PROG="$(type -P logger)" || LOGGER_PROG=true
-
-if [[ -r config ]]; then
-       # shellcheck disable=SC1091
-       . config
-fi
-
-# Default configuration.
-: "${DEVICE_ONLY:=0}"
-: "${QUICK_RUN:=0}"
-: "${RUN_ZONED_TESTS:=0}"
-: "${OUTPUT:=results}"
-if [[ "${EXCLUDE:-}" ]] && ! declare -p EXCLUDE | grep -q '^declare -a'; then
-       # If EXCLUDE was not defined as an array, convert it to one.
-       # shellcheck disable=SC2128,SC2190,SC2206
-       EXCLUDE=($EXCLUDE)
-elif [[ ! "${EXCLUDE:-}" ]]; then
-       EXCLUDE=()
-fi
-if [[ "${TEST_DEVS:-}" ]] && ! declare -p TEST_DEVS | grep -q '^declare -a'; then
-       # If TEST_DEVS was not defined as an array, convert it to one.
-       # shellcheck disable=SC2128,SC2206
-       TEST_DEVS=($TEST_DEVS)
-elif [[ ! "${TEST_DEVS:-}" ]]; then
-       TEST_DEVS=()
-fi
-
+LOADED_CONFIG=0
+OPTION_EXCLUDE=()
 while true; do
        case "$1" in
                '-d'|'--device-only')
-                       DEVICE_ONLY=1
+                       OPTION_DEVICE_ONLY=1
                        shift
                        ;;
                '-o'|'--output')
-                       OUTPUT="$2"
+                       OPTION_OUTPUT="$2"
                        shift 2
                        ;;
                '-q'|'--quick')
-                       QUICK_RUN=1
-                       # Use the timeout specified on the command line, from
-                       # the config, or the default.
-                       TIMEOUT="${2:-${TIMEOUT:-30}}"
+                       OPTION_QUICK_RUN=1
+                       OPTION_TIMEOUT="$2"
                        shift 2
                        ;;
                '-x'|'--exclude')
                        # shellcheck disable=SC2190
-                       EXCLUDE+=("$2")
+                       OPTION_EXCLUDE+=("$2")
+                       shift 2
+                       ;;
+               '-c'|'--config')
+                       # shellcheck source=/dev/null
+                       . "$2"
+                       LOADED_CONFIG=1
                        shift 2
                        ;;
                '-h'|'--help')
@@ -719,22 +702,60 @@ while true; do
        esac
 done
 
-if [[ $QUICK_RUN -ne 0 && ! "${TIMEOUT:-}" ]]; then
-       _error "QUICK_RUN specified without TIMEOUT"
+# Load the default configuration file if "-c" was not used.
+if [[ $LOADED_CONFIG -eq 0 && -r config ]]; then
+       # shellcheck source=/dev/null
+       . config
 fi
 
-if [[ $DEVICE_ONLY -ne 0 && ${#TEST_DEVS[@]} -eq 0 ]]; then
-       _error "DEVICE_ONLY specified without TEST_DEVS"
+# Options on the command line take precedence over the configuration file. If
+# neither set the option and we didn't get it from the environment, then we
+# fall back to the default.
+DEVICE_ONLY="${OPTION_DEVICE_ONLY:-${DEVICE_ONLY:-0}}"
+
+OUTPUT="${OPTION_OUTPUT:-${OUTPUT:-results}}"
+
+QUICK_RUN="${OPTION_QUICK_RUN:-${QUICK_RUN:-0}}"
+if [[ -n $OPTION_QUICK_RUN && $OPTION_QUICK_RUN -ne 0 ]]; then
+       TIMEOUT="${OPTION_TIMEOUT:-${TIMEOUT:-30}}"
 fi
 
-# Convert the exclude list to an associative array.
-TEMP_EXCLUDE=("${EXCLUDE[@]}")
+if [[ "${EXCLUDE:-}" ]] && ! declare -p EXCLUDE | grep -q '^declare -a'; then
+       # If EXCLUDE was not defined as an array, convert it to one.
+       # shellcheck disable=SC2128,SC2190,SC2206
+       EXCLUDE=($EXCLUDE)
+elif [[ ! "${EXCLUDE:-}" ]]; then
+       EXCLUDE=()
+fi
+# Convert the exclude list to an associative array. The lists from the
+# configuration file and command line options are merged.
+TEMP_EXCLUDE=("${EXCLUDE[@]}" "${OPTION_EXCLUDE[@]}")
 unset EXCLUDE
 declare -A EXCLUDE
 for filter in "${TEMP_EXCLUDE[@]}"; do
        EXCLUDE["$filter"]=1
 done
-unset TEMP_EXCLUDE
+unset OPTION_EXCLUDE TEMP_EXCLUDE
+
+if [[ "${TEST_DEVS:-}" ]] && ! declare -p TEST_DEVS | grep -q '^declare -a'; then
+       # If TEST_DEVS was not defined as an array, convert it to one.
+       # shellcheck disable=SC2128,SC2206
+       TEST_DEVS=($TEST_DEVS)
+elif [[ ! "${TEST_DEVS:-}" ]]; then
+       TEST_DEVS=()
+fi
+
+: "${LOGGER_PROG:="$(type -P logger || echo true)"}"
+: "${RUN_ZONED_TESTS:=0}"
+
+# Sanity check options.
+if [[ $QUICK_RUN -ne 0 && ! "${TIMEOUT:-}" ]]; then
+       _error "QUICK_RUN specified without TIMEOUT"
+fi
+
+if [[ $DEVICE_ONLY -ne 0 && ${#TEST_DEVS[@]} -eq 0 ]]; then
+       _error "DEVICE_ONLY specified without TEST_DEVS"
+fi
 
 mkdir -p "$OUTPUT"
 OUTPUT="$(realpath "$OUTPUT")"