SHELLCHECK_EXCLUDE := SC2119
check:
- shellcheck -x -e $(SHELLCHECK_EXCLUDE) -f gcc check new common/* \
+ shellcheck -x -e $(SHELLCHECK_EXCLUDE) -f gcc check common/* \
tests/*/rc tests/*/[0-9]*[0-9] src/*.sh
+ shellcheck --exclude=$(SHELLCHECK_EXCLUDE),SC2154 --format=gcc new
! grep TODO tests/*/rc tests/*/[0-9]*[0-9]
! find -name '*.out' -perm /u=x+g=x+o=x -printf '%p is executable\n' | grep .
local test_name="$1"
local explicit="$2"
- unset CAN_BE_ZONED DESCRIPTION QUICK TIMED requires device_requires test test_device fallback_device cleanup_fallback_device
+ unset CAN_BE_ZONED DESCRIPTION QUICK TIMED requires device_requires \
+ test test_device fallback_device cleanup_fallback_device \
+ set_conditions
# shellcheck disable=SC1090
if ! . "tests/${test_name}"; then
_output_status() {
local test="$1"
local status="$2"
- local zoned=" "
+ local str="${test} "
- if (( RUN_FOR_ZONED )); then zoned=" (zoned) "; fi
-
- if [[ "${DESCRIPTION:-}" ]]; then
- printf '%-60s' "${test}${zoned}($DESCRIPTION)"
- else
- printf '%-60s' "${test}${zoned}"
- fi
+ (( RUN_FOR_ZONED )) && str="$str(zoned) "
+ [[ ${COND_DESC:-} ]] && str="$str(${COND_DESC}) "
+ [[ ${DESCRIPTION:-} ]] && str="$str(${DESCRIPTION})"
+ printf '%-60s' "${str}"
if [[ -z $status ]]; then
echo
return
}
_check_and_call_test() {
+ local postfix
local ret
if declare -fF requires >/dev/null; then
requires
fi
- RESULTS_DIR="$OUTPUT/nodev"
+ [[ -n $COND_DESC ]] && postfix=_${COND_DESC//[ =]/_}
+ RESULTS_DIR="$OUTPUT/nodev${postfix}"
_call_test test
ret=$?
if (( RUN_ZONED_TESTS && CAN_BE_ZONED )); then
- RESULTS_DIR="$OUTPUT/nodev_zoned"
+ RESULTS_DIR="$OUTPUT/nodev_zoned${postfix}"
RUN_FOR_ZONED=1
_call_test test
ret=$(( ret || $? ))
}
_check_and_call_test_device() {
+ local postfix
local unset_skip_reason
local ret
requires
fi
+ [[ -n $COND_DESC ]] && postfix=_${COND_DESC//[ =]/_}
for TEST_DEV in "${TEST_DEVS[@]}"; do
TEST_DEV_SYSFS="${TEST_DEV_SYSFS_DIRS["$TEST_DEV"]}"
TEST_DEV_PART_SYSFS="${TEST_DEV_PART_SYSFS_DIRS["$TEST_DEV"]}"
device_requires
fi
fi
- RESULTS_DIR="$OUTPUT/$(basename "$TEST_DEV")"
+ RESULTS_DIR="$OUTPUT/$(basename "$TEST_DEV")""$postfix"
if ! _call_test test_device; then
ret=1
fi
CHECK_DMESG=1
DMESG_FILTER="cat"
RUN_FOR_ZONED=0
+ COND_DESC=""
FALLBACK_DEVICE=0
MODULES_TO_UNLOAD=()
+ local nr_conds cond_i
local ret=0
# Ensure job control monitor mode is off in the sub-shell for test case
. "tests/${TEST_NAME}"
if declare -fF test >/dev/null; then
- _check_and_call_test
- ret=$?
+ if declare -fF set_conditions >/dev/null; then
+ nr_conds=$(set_conditions)
+ for ((cond_i = 0; cond_i < nr_conds; cond_i++)); do
+ set_conditions $cond_i
+ _check_and_call_test
+ ret=$(( ret || $? ))
+ unset SKIP_REASONS
+ done
+ else
+ _check_and_call_test
+ ret=$?
+ fi
else
if [[ ${#TEST_DEVS[@]} -eq 0 ]] && \
declare -fF fallback_device >/dev/null; then
return 0
fi
- _check_and_call_test_device
- ret=$?
+ if declare -fF set_conditions >/dev/null; then
+ nr_conds=$(set_conditions)
+ for ((cond_i = 0; cond_i < nr_conds; cond_i++)); do
+ set_conditions $cond_i
+ _check_and_call_test_device
+ ret=$(( ret || $? ))
+ unset SKIP_REASONS
+ done
+ else
+ _check_and_call_test_device
+ ret=$?
+ fi
if (( FALLBACK_DEVICE )); then
cleanup_fallback_device
# _require_test_dev_is_foo && _require_test_dev_supports_bar
# }
+# TODO: if the test case can run the same test for different conditions, define
+# the helper function "set_conditions". When no argument is specified, return
+# the number of condition variations. Blktests repeats the test case as many
+# times as the returned number. When its argument is specified, refer to it as
+# the condition variation index and set up the conditions for it. Also set the
+# global variable COND_DESC which is printed at the test case run and used for
+# the result directory name. Blktests calls set_conditions() before each run of
+# the test case incrementing the argument index from 0.
+# set_conditions() {
+# local index=\$1
+#
+# if [[ -z \$index ]]; then
+# echo 2 # return number of condition variations
+# return
+# fi
+#
+# # Set test conditions based on the $index
+# ...
+# COND_DESC="Describe the conditions shortly"
+# }
+
# TODO: define the test. The output of this function (stdout and stderr) will
# be compared to tests/\${TEST_NAME}.out. If it does not match, the test is
# considered a failure. If the test runs a command which has unnecessary