t/zbd: Add -o option to t/zbd/test-zoned-support
[fio.git] / t / zbd / test-zbd-support
index 31718c95b4e11915e7e984a00d7503d10c5e3279..c21d6aadf8cc15a77e88e84f5258d829958667f3 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() {
@@ -77,6 +86,13 @@ check_reset_count() {
     eval "[ '$reset_count' '$1' '$2' ]"
 }
 
+# Check log for failed assertions and crashes. Without these checks,
+# a test can succeed even when these events happen, but it must fail.
+check_log() {
+     [ ! -f "${logfile}.${1}" ] && return 0
+     ! grep -q -e "Assertion " -e "Aborted " "${logfile}.${1}"
+}
+
 # Whether or not $1 (/dev/...) is a SCSI device.
 is_scsi_device() {
     local d f
@@ -88,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[@]}"
@@ -113,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
 }
 
@@ -497,7 +543,7 @@ test25() {
        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 $?
 }
@@ -542,7 +588,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 $?
@@ -566,7 +612,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 $?
@@ -602,7 +649,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.
@@ -612,6 +659,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 $?
 }
 
@@ -828,6 +876,8 @@ test48() {
        opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
        opts+=("--io_size=$zone_size" "--iodepth=256" "--thread=1")
        opts+=("--group_reporting=1")
+       # max_open_zones is already specified
+       opts+=($(job_var_opts_exclude "--max_open_zones"))
     done
 
     fio=$(dirname "$0")/../../fio
@@ -839,11 +889,33 @@ test48() {
            >> "${logfile}.${test_number}" 2>&1 || return $?
 }
 
+# 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
+
+    size=$((2 * zone_size))
+    capacity=$((zone_size * 3 / 4))
+
+    run_one_fio_job "$(ioengine "psync")" --rw=write \
+                   --zonemode=zbd --zonesize="${zone_size}" \
+                   --zonecapacity=${capacity} \
+                   --verify=md5  --size=${size} >>"${logfile}.${test_number}" 2>&1 ||
+       return $?
+    check_written $((capacity * 2)) || return $?
+    check_read $((capacity * 2)) || return $?
+}
+
 tests=()
 dynamic_analyzer=()
 reset_all_zones=
 use_libzbc=
 zbd_debug=
+max_open_zones_opt=
 
 while [ "${1#-}" != "$1" ]; do
   case "$1" in
@@ -855,6 +927,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;;
@@ -870,9 +943,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")
@@ -958,6 +1032,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"
 
@@ -987,7 +1067,7 @@ trap 'intr=1' SIGINT
 for test_number in "${tests[@]}"; do
     rm -f "${logfile}.${test_number}"
     echo -n "Running test $(printf "%02d" $test_number) ... "
-    if eval "test$test_number"; then
+    if eval "test$test_number" && check_log $test_number; then
        status="PASS"
        cc_status="${green}${status}${end}"
        ((passed++))