# 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() {
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[@]}"
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
}
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 \
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".
test5() {
local size off capacity
+ prep_write
off=$((first_sequential_zone_sector * 512))
capacity=$(total_zone_capacity 4 $off $dev)
size=$((4 * zone_size))
test6() {
local size off capacity
+ prep_write
off=$((first_sequential_zone_sector * 512))
capacity=$(total_zone_capacity 4 $off $dev)
size=$((4 * zone_size))
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 \
test8() {
local size off capacity
+ prep_write
size=$((4 * zone_size))
off=$((first_sequential_zone_sector * 512))
capacity=$(total_zone_capacity 4 $off $dev)
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 \
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 \
test11() {
local size off capacity
+ prep_write
size=$((4 * zone_size))
off=$((first_sequential_zone_sector * 512))
capacity=$(total_zone_capacity 4 $off $dev)
test12() {
local size off capacity
+ prep_write
size=$((8 * zone_size))
off=$((first_sequential_zone_sector * 512))
capacity=$(total_zone_capacity 8 $off $dev)
test13() {
local size off capacity
+ prep_write
size=$((8 * zone_size))
off=$((first_sequential_zone_sector * 512))
capacity=$(total_zone_capacity 8 $off $dev)
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 \
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)
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)
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\
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)
[ -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 $?
}
local loops=4 r
local off capacity
+ prep_write
off=$((first_sequential_zone_sector * 512))
capacity=$(total_zone_capacity 1 $off $dev)
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
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 $?
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")
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 $?
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")"\
test31() {
local bs inc nz off opts size
+ prep_write
# Start with writing 128 KB to 128 sequential zones.
bs=128K
nz=128
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.
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 $?
}
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")
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))
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)) \
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))
test36() {
local bs off io_size size
+ prep_write
off=$(((first_sequential_zone_sector) * 512))
size=$((zone_size - 512))
bs=$((zone_size / 4))
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
test38() {
local bs off size
+ prep_write
size=$((logical_block_size))
off=$((disk_size - logical_block_size))
bs=$((logical_block_size))
# 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 $?
}
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 $?
# 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'
}
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)) \
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 \
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
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")
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
# 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))
reset_all_zones=
use_libzbc=
zbd_debug=
+max_open_zones_opt=
while [ "${1#-}" != "$1" ]; do
case "$1" in
-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;;
# 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")
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"
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=""
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}"
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