t/zbd: skip tests when test prerequisites are not met
[fio.git] / t / zbd / test-zbd-support
index 139495d32dee3bd754e06aab5e608132c137e196..d94b5125f5cd5232685cee8c2e6de88f0d41ec56 100755 (executable)
@@ -5,7 +5,16 @@
 # This file is released under the GPL.
 
 usage() {
-    echo "Usage: $(basename "$0") [-d] [-e] [-l] [-r] [-v] [-t <test>] [-z] <SMR drive device node>"
+       echo "Usage: $(basename "$0") [OPTIONS] <test target device file>"
+       echo "Options:"
+       echo -e "\t-d Run fio with valgrind using DRD tool"
+       echo -e "\t-e Run fio with valgrind using helgrind tool"
+       echo -e "\t-v Run fio with valgrind --read-var-info option"
+       echo -e "\t-l Test with libzbc ioengine"
+       echo -e "\t-r Reset all zones before test start"
+       echo -e "\t-o <max_open_zones> Run fio with max_open_zones limit"
+       echo -e "\t-t <test #> Run only a single test case with specified number"
+       echo -e "\t-z Run fio with debug=zbd option"
 }
 
 max() {
@@ -95,14 +104,41 @@ is_scsi_device() {
     return 1
 }
 
+job_var_opts_exclude() {
+       local o
+       local ex_key="${1}"
+
+       for o in "${job_var_opts[@]}"; do
+               if [[ ${o} =~ "${ex_key}" ]]; then
+                       continue
+               fi
+               echo -n "${o}"
+       done
+}
+
+has_max_open_zones() {
+       while (($# > 1)); do
+               if [[ ${1} =~ "--max_open_zones" ]]; then
+                       return 0
+               fi
+               shift
+       done
+       return 1
+}
+
 run_fio() {
     local fio opts
 
     fio=$(dirname "$0")/../../fio
 
-    opts=("--max-jobs=16" "--aux-path=/tmp" "--allow_file_create=0" \
-         "--significant_figures=10" "$@")
-    opts+=(${var_opts[@]})
+    opts=(${global_var_opts[@]})
+    opts+=("--max-jobs=16" "--aux-path=/tmp" "--allow_file_create=0" \
+                          "--significant_figures=10" "$@")
+    # When max_open_zones option is specified to this test script, add
+    # max_open_zones option to fio command unless the test case already add it.
+    if [[ -n ${max_open_zones_opt} ]] && ! has_max_open_zones "${opts[@]}"; then
+           opts+=("--max_open_zones=${max_open_zones_opt}")
+    fi
     { echo; echo "fio ${opts[*]}"; echo; } >>"${logfile}.${test_number}"
 
     "${dynamic_analyzer[@]}" "$fio" "${opts[@]}"
@@ -120,13 +156,16 @@ write_and_run_one_fio_job() {
     local r
     local write_offset="${1}"
     local write_size="${2}"
+    local -a write_opts
 
     shift 2
     r=$(((RANDOM << 16) | RANDOM))
-    run_fio --filename="$dev" --randseed="$r"  --name="write_job" --rw=write \
-           "$(ioengine "psync")" --bs="${logical_block_size}" \
-           --zonemode=zbd --zonesize="${zone_size}" --thread=1 --direct=1 \
-           --offset="${write_offset}" --size="${write_size}" \
+    write_opts=(--name="write_job" --rw=write "$(ioengine "psync")" \
+                     --bs="${logical_block_size}" --zonemode=zbd \
+                     --zonesize="${zone_size}" --thread=1 --direct=1 \
+                     --offset="${write_offset}" --size="${write_size}")
+    write_opts+=("${job_var_opts[@]}")
+    run_fio --filename="$dev" --randseed="$r" "${write_opts[@]}" \
            --name="$dev" --wait_for="write_job" "$@" --thread=1 --direct=1
 }
 
@@ -142,6 +181,51 @@ run_fio_on_seq() {
     run_one_fio_job "${opts[@]}" "$@"
 }
 
+# Prepare for write test by resetting zones. When max_open_zones option is
+# specified, reset all zones of the test target to ensure that zones out of the
+# test target range do not have open zones. This allows the write test to the
+# target range to be able to open zones up to max_open_zones.
+prep_write() {
+       [[ -n "${max_open_zones_opt}" && -n "${is_zbd}" ]] &&
+               reset_zone "${dev}" -1
+}
+
+SKIP_TESTCASE=255
+
+require_scsi_dev() {
+       if ! is_scsi_device "$dev"; then
+               SKIP_REASON="$dev is not a SCSI device"
+               return 1
+       fi
+       return 0
+}
+
+require_conv_zone_bytes() {
+       local req_bytes=${1}
+
+       if ((req_bytes > first_sequential_zone_sector * 512)); then
+               SKIP_REASON="$dev does not have enough conventional zones"
+               return 1
+       fi
+       return 0
+}
+
+require_zbd() {
+       if [[ -z ${is_zbd} ]]; then
+               SKIP_REASON="$dev is not a zoned block device"
+               return 1
+       fi
+       return 0
+}
+
+require_regular_block_dev() {
+       if [[ -n ${is_zbd} ]]; then
+               SKIP_REASON="$dev is not a regular block device"
+               return 1
+       fi
+       return 0
+}
+
 # Check whether buffered writes are refused.
 test1() {
     run_fio --name=job1 --filename="$dev" --rw=write --direct=0 --bs=4K        \
@@ -173,8 +257,8 @@ test2() {
     if [ -z "$is_zbd" ]; then
        opts+=("--zonesize=${zone_size}")
     fi
-    run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
-    ! grep -q 'WRITE:' "${logfile}.${test_number}"
+    run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 && return 1
+    grep -q 'buflen exceeds zone size' "${logfile}.${test_number}"
 }
 
 # Run fio against an empty zone. This causes fio to report "No I/O performed".
@@ -213,6 +297,7 @@ test4() {
 test5() {
     local size off capacity
 
+    prep_write
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 4 $off $dev)
     size=$((4 * zone_size))
@@ -228,6 +313,7 @@ test5() {
 test6() {
     local size off capacity
 
+    prep_write
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 4 $off $dev)
     size=$((4 * zone_size))
@@ -246,6 +332,7 @@ test7() {
     local size=$((zone_size))
     local off capacity
 
+    prep_write
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 1 $off $dev)
     run_fio_on_seq "$(ioengine "libaio")" --iodepth=1 --rw=randwrite   \
@@ -260,6 +347,7 @@ test7() {
 test8() {
     local size off capacity
 
+    prep_write
     size=$((4 * zone_size))
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 4 $off $dev)
@@ -275,11 +363,9 @@ test8() {
 test9() {
     local size
 
-    if ! is_scsi_device "$dev"; then
-       echo "$dev is not a SCSI device" >>"${logfile}.${test_number}"
-       return 0
-    fi
+    require_scsi_dev || return $SKIP_TESTCASE
 
+    prep_write
     size=$((4 * zone_size))
     run_fio_on_seq --ioengine=sg                                       \
                   --iodepth=1 --rw=randwrite --bs=16K                  \
@@ -293,11 +379,9 @@ test9() {
 test10() {
     local size
 
-    if ! is_scsi_device "$dev"; then
-       echo "$dev is not a SCSI device" >>"${logfile}.${test_number}"
-       return 0
-    fi
+    require_scsi_dev || return $SKIP_TESTCASE
 
+    prep_write
     size=$((4 * zone_size))
     run_fio_on_seq --ioengine=sg                                       \
                   --iodepth=64 --rw=randwrite --bs=16K                 \
@@ -311,6 +395,7 @@ test10() {
 test11() {
     local size off capacity
 
+    prep_write
     size=$((4 * zone_size))
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 4 $off $dev)
@@ -325,6 +410,7 @@ test11() {
 test12() {
     local size off capacity
 
+    prep_write
     size=$((8 * zone_size))
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 8 $off $dev)
@@ -339,6 +425,7 @@ test12() {
 test13() {
     local size off capacity
 
+    prep_write
     size=$((8 * zone_size))
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 8 $off $dev)
@@ -354,12 +441,10 @@ test13() {
 test14() {
     local size
 
+    prep_write
     size=$((16 * 2**20)) # 20 MB
-    if [ $size -gt $((first_sequential_zone_sector * 512)) ]; then
-       echo "$dev does not have enough sequential zones" \
-            >>"${logfile}.${test_number}"
-       return 0
-    fi
+    require_conv_zone_bytes "${size}" || return $SKIP_TESTCASE
+
     run_one_fio_job "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
                    --zonemode=zbd --zonesize="${zone_size}" --do_verify=1 \
                    --verify=md5 --size=$size                              \
@@ -378,6 +463,7 @@ test15() {
            reset_zone "$dev" $((first_sequential_zone_sector +
                                 i*sectors_per_zone))
     done
+    prep_write
     w_off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
     w_size=$((2 * zone_size))
     w_capacity=$(total_zone_capacity 2 $w_off $dev)
@@ -402,6 +488,7 @@ test16() {
            reset_zone "$dev" $((first_sequential_zone_sector +
                                 i*sectors_per_zone))
     done
+    prep_write
     w_off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
     w_size=$((2 * zone_size))
     w_capacity=$(total_zone_capacity 2 $w_off $dev)
@@ -424,6 +511,7 @@ test17() {
     if [ -n "$is_zbd" ]; then
        reset_zone "$dev" $((off / 512)) || return $?
     fi
+    prep_write
     run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw --bs=4K \
                    --zonemode=zbd --zonesize="${zone_size}"            \
                    --offset=$off --loops=2 --norandommap=1\
@@ -477,6 +565,7 @@ test24() {
     local bs loops=9 size=$((zone_size))
     local off capacity
 
+    prep_write
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 1 $off $dev)
 
@@ -499,12 +588,13 @@ test25() {
         [ -n "$is_zbd" ] &&
            reset_zone "$dev" $((first_sequential_zone_sector + i*sectors_per_zone))
     done
+    prep_write
     for ((i=0;i<16;i++)); do
        opts+=("--name=job$i" "--filename=$dev" "--thread=1" "--direct=1")
        opts+=("--offset=$((first_sequential_zone_sector*512 + zone_size*i))")
        opts+=("--size=$zone_size" "$(ioengine "psync")" "--rw=write" "--bs=16K")
        opts+=("--zonemode=zbd" "--zonesize=${zone_size}" "--group_reporting=1")
-       opts+=(${var_opts[@]})
+       opts+=(${job_var_opts[@]})
     done
     run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
 }
@@ -513,6 +603,7 @@ write_to_first_seq_zone() {
     local loops=4 r
     local off capacity
 
+    prep_write
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 1 $off $dev)
 
@@ -542,6 +633,7 @@ test28() {
 
     off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
     [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
+    prep_write
     opts=("--debug=zbd")
     capacity=$(total_zone_capacity 1 $off $dev)
     for ((i=0;i<jobs;i++)); do
@@ -549,7 +641,7 @@ test28() {
        opts+=("--size=$zone_size" "--io_size=$capacity" "$(ioengine "psync")" "--rw=randwrite")
        opts+=("--thread=1" "--direct=1" "--zonemode=zbd")
        opts+=("--zonesize=${zone_size}" "--group_reporting=1")
-       opts+=(${var_opts[@]})
+       opts+=(${job_var_opts[@]})
     done
     run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
     check_written $((jobs * $capacity)) || return $?
@@ -565,7 +657,7 @@ test29() {
 
     off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
     size=$((16*zone_size))
-    [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
+    prep_write
     opts=("--debug=zbd")
     for ((i=0;i<jobs;i++)); do
        opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
@@ -573,7 +665,8 @@ test29() {
        opts+=("$(ioengine "psync")" "--rw=randwrite" "--direct=1")
        opts+=("--max_open_zones=4" "--group_reporting=1")
        opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
-       opts+=(${var_opts[@]})
+       # max_open_zones is already specified
+       opts+=($(job_var_opts_exclude "--max_open_zones"))
     done
     run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
     check_written $((jobs * zone_size)) || return $?
@@ -583,6 +676,7 @@ test29() {
 test30() {
     local off
 
+    prep_write
     off=$((first_sequential_zone_sector * 512))
     run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw     \
                    --bs="$(max $((zone_size / 128)) "$logical_block_size")"\
@@ -596,6 +690,7 @@ test30() {
 test31() {
     local bs inc nz off opts size
 
+    prep_write
     # Start with writing 128 KB to 128 sequential zones.
     bs=128K
     nz=128
@@ -609,7 +704,7 @@ test31() {
        opts+=("--bs=$bs" "--size=$zone_size" "$(ioengine "libaio")")
        opts+=("--rw=write" "--direct=1" "--thread=1" "--stats=0")
        opts+=("--zonemode=zbd" "--zonesize=${zone_size}")
-       opts+=(${var_opts[@]})
+       opts+=(${job_var_opts[@]})
     done
     "$(dirname "$0")/../../fio" "${opts[@]}" >> "${logfile}.${test_number}" 2>&1
     # Next, run the test.
@@ -619,6 +714,7 @@ test31() {
     opts+=("--bs=$bs" "$(ioengine "psync")" "--rw=randread" "--direct=1")
     opts+=("--thread=1" "--time_based" "--runtime=30" "--zonemode=zbd")
     opts+=("--zonesize=${zone_size}")
+    opts+=(${job_var_opts[@]})
     run_fio "${opts[@]}" >> "${logfile}.${test_number}" 2>&1 || return $?
 }
 
@@ -627,6 +723,9 @@ test31() {
 test32() {
     local off opts=() size
 
+    require_zbd || return $SKIP_TESTCASE
+
+    prep_write
     off=$((first_sequential_zone_sector * 512))
     size=$((disk_size - off))
     opts+=("--name=$dev" "--filename=$dev" "--offset=$off" "--size=$size")
@@ -643,6 +742,7 @@ test33() {
     local bs io_size size
     local off capacity=0;
 
+    prep_write
     off=$((first_sequential_zone_sector * 512))
     capacity=$(total_zone_capacity 1 $off $dev)
     size=$((2 * zone_size))
@@ -659,6 +759,7 @@ test33() {
 test34() {
     local size
 
+    prep_write
     size=$((2 * zone_size))
     run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write --size=$size \
                   --do_verify=1 --verify=md5 --bs=$((3 * zone_size / 4)) \
@@ -670,6 +771,7 @@ test34() {
 test35() {
     local bs off io_size size
 
+    prep_write
     off=$(((first_sequential_zone_sector + 1) * 512))
     size=$((zone_size - 2 * 512))
     bs=$((zone_size / 4))
@@ -684,6 +786,7 @@ test35() {
 test36() {
     local bs off io_size size
 
+    prep_write
     off=$(((first_sequential_zone_sector) * 512))
     size=$((zone_size - 512))
     bs=$((zone_size / 4))
@@ -698,6 +801,7 @@ test36() {
 test37() {
     local bs off size capacity
 
+    prep_write
     capacity=$(total_zone_capacity 1 $first_sequential_zone_sector $dev)
     if [ "$first_sequential_zone_sector" = 0 ]; then
        off=0
@@ -717,6 +821,7 @@ test37() {
 test38() {
     local bs off size
 
+    prep_write
     size=$((logical_block_size))
     off=$((disk_size - logical_block_size))
     bs=$((logical_block_size))
@@ -738,7 +843,7 @@ read_one_block() {
 
 # Check whether fio accepts --zonemode=none for zoned block devices.
 test39() {
-    [ -n "$is_zbd" ] || return 0
+    require_zbd || return $SKIP_TESTCASE
     read_one_block --zonemode=none >/dev/null || return $?
     check_read $((logical_block_size)) || return $?
 }
@@ -748,7 +853,7 @@ test40() {
     local bs
 
     bs=$((logical_block_size))
-    [ -n "$is_zbd" ] || return 0
+    require_zbd || return $SKIP_TESTCASE
     read_one_block --zonemode=strided |
        grep -q 'fio: --zonesize must be specified when using --zonemode=strided' ||
        return $?
@@ -758,21 +863,21 @@ test40() {
 
 # Check whether fio checks the zone size for zoned block devices.
 test41() {
-    [ -n "$is_zbd" ] || return 0
+    require_zbd || return $SKIP_TESTCASE
     read_one_block --zonemode=zbd --zonesize=$((2 * zone_size)) |
        grep -q 'job parameter zonesize.*does not match disk zone size'
 }
 
 # Check whether fio handles --zonesize=0 correctly for regular block devices.
 test42() {
-    [ -n "$is_zbd" ] && return 0
+    require_regular_block_dev || return $SKIP_TESTCASE
     read_one_block --zonemode=zbd --zonesize=0 |
        grep -q 'Specifying the zone size is mandatory for regular block devices with --zonemode=zbd'
 }
 
 # Check whether fio handles --zonesize=1 correctly for regular block devices.
 test43() {
-    [ -n "$is_zbd" ] && return 0
+    require_regular_block_dev || return $SKIP_TESTCASE
     read_one_block --zonemode=zbd --zonesize=1 |
        grep -q 'zone size must be at least 512 bytes for --zonemode=zbd'
 }
@@ -786,7 +891,8 @@ test44() {
 test45() {
     local bs i
 
-    [ -z "$is_zbd" ] && return 0
+    require_zbd || return $SKIP_TESTCASE
+    prep_write
     bs=$((logical_block_size))
     run_one_fio_job "$(ioengine "psync")" --iodepth=1 --rw=randwrite --bs=$bs\
                    --offset=$((first_sequential_zone_sector * 512)) \
@@ -799,6 +905,7 @@ test45() {
 test46() {
     local size
 
+    prep_write
     size=$((4 * zone_size))
     run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=4K \
                   --group_reporting=1 --numjobs=8 \
@@ -810,6 +917,7 @@ test46() {
 test47() {
     local bs
 
+    prep_write
     bs=$((logical_block_size))
     run_fio_on_seq "$(ioengine "psync")" --rw=write --bs=$bs --zoneskip=1 \
                    >> "${logfile}.${test_number}" 2>&1 && return 1
@@ -822,9 +930,11 @@ test47() {
 test48() {
     local i jobs=16 off opts=()
 
+    require_zbd || return $SKIP_TESTCASE
+
     off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
     size=$((16*zone_size))
-    [ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
+    prep_write
     opts=("--aux-path=/tmp" "--allow_file_create=0" "--significant_figures=10")
     opts+=("--debug=zbd")
     opts+=("$(ioengine "libaio")" "--rw=randwrite" "--direct=1")
@@ -834,7 +944,9 @@ test48() {
     for ((i=0;i<jobs;i++)); do
        opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
        opts+=("--io_size=$zone_size" "--iodepth=256" "--thread=1")
-       opts+=("--group_reporting=1")
+       opts+=("--size=$size" "--group_reporting=1")
+       # max_open_zones is already specified
+       opts+=($(job_var_opts_exclude "--max_open_zones"))
     done
 
     fio=$(dirname "$0")/../../fio
@@ -849,11 +961,7 @@ test48() {
 # Check if fio handles --zonecapacity on a normal block device correctly
 test49() {
 
-    if [ -n "$is_zbd" ]; then
-       echo "$dev is not a regular block device" \
-            >>"${logfile}.${test_number}"
-       return 0
-    fi
+    require_regular_block_dev || return $SKIP_TESTCASE
 
     size=$((2 * zone_size))
     capacity=$((zone_size * 3 / 4))
@@ -872,6 +980,7 @@ dynamic_analyzer=()
 reset_all_zones=
 use_libzbc=
 zbd_debug=
+max_open_zones_opt=
 
 while [ "${1#-}" != "$1" ]; do
   case "$1" in
@@ -883,6 +992,7 @@ while [ "${1#-}" != "$1" ]; do
     -l) use_libzbc=1; shift;;
     -r) reset_all_zones=1; shift;;
     -t) tests+=("$2"); shift; shift;;
+    -o) max_open_zones_opt="${2}"; shift; shift;;
     -v) dynamic_analyzer=(valgrind "--read-var-info=yes");
        shift;;
     -z) zbd_debug=1; shift;;
@@ -898,9 +1008,10 @@ fi
 # shellcheck source=functions
 source "$(dirname "$0")/functions" || exit $?
 
-var_opts=()
+global_var_opts=()
+job_var_opts=()
 if [ -n "$zbd_debug" ]; then
-    var_opts+=("--debug=zbd")
+    global_var_opts+=("--debug=zbd")
 fi
 dev=$1
 realdev=$(readlink -f "$dev")
@@ -986,6 +1097,12 @@ elif [[ -c "$realdev" ]]; then
        fi
 fi
 
+if [[ -n ${max_open_zones_opt} ]]; then
+       # Override max_open_zones with the script option value
+       max_open_zones="${max_open_zones_opt}"
+       job_var_opts+=("--max_open_zones=${max_open_zones_opt}")
+fi
+
 echo -n "First sequential zone starts at sector $first_sequential_zone_sector;"
 echo " zone size: $((zone_size >> 20)) MB"
 
@@ -997,10 +1114,12 @@ fi
 logfile=$0.log
 
 passed=0
+skipped=0
 failed=0
 if [ -t 1 ]; then
     red="\e[1;31m"
     green="\e[1;32m"
+    cyan="\e[1;36m"
     end="\e[m"
 else
     red=""
@@ -1011,14 +1130,23 @@ rc=0
 
 intr=0
 trap 'intr=1' SIGINT
+ret=0
 
 for test_number in "${tests[@]}"; do
     rm -f "${logfile}.${test_number}"
+    unset SKIP_REASON
     echo -n "Running test $(printf "%02d" $test_number) ... "
-    if eval "test$test_number" && check_log $test_number; then
+    eval "test$test_number"
+    ret=$?
+    if ((!ret)) && check_log $test_number; then
        status="PASS"
        cc_status="${green}${status}${end}"
        ((passed++))
+    elif ((ret==SKIP_TESTCASE)); then
+       status="SKIP"
+       echo "${SKIP_REASON}" >> "${logfile}.${test_number}"
+       cc_status="${cyan}${status}${end}    ${SKIP_REASON}"
+       ((skipped++))
     else
        status="FAIL"
        cc_status="${red}${status}${end}"
@@ -1031,7 +1159,10 @@ for test_number in "${tests[@]}"; do
 done
 
 echo "$passed tests passed"
+if [ $skipped -gt 0 ]; then
+    echo " $skipped tests skipped"
+fi
 if [ $failed -gt 0 ]; then
-    echo " and $failed tests failed"
+    echo " $failed tests failed"
 fi
 exit $rc