# 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() {
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
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[@]}"
--thread=1 --direct=1
}
+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))
+ 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 fio on the first four sequential zones of the disk.
run_fio_on_seq() {
local opts=()
# Sequential write to sequential zones.
test5() {
- local size
+ local size off capacity
+ off=$((first_sequential_zone_sector * 512))
+ capacity=$(total_zone_capacity 4 $off $dev)
size=$((4 * zone_size))
run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write \
--bs="$(max $((zone_size / 64)) "$logical_block_size")"\
--do_verify=1 --verify=md5 \
>>"${logfile}.${test_number}" 2>&1 || return $?
- check_written $size || return $?
- check_read $size || return $?
+ check_written $capacity || return $?
+ check_read $capacity || return $?
}
-# Sequential read from sequential zones. Must be run after test5.
+# Sequential read from sequential zones.
test6() {
- local size
+ local size off capacity
+ off=$((first_sequential_zone_sector * 512))
+ capacity=$(total_zone_capacity 4 $off $dev)
size=$((4 * zone_size))
- run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=read \
- --bs="$(max $((zone_size / 64)) "$logical_block_size")"\
- >>"${logfile}.${test_number}" 2>&1 || return $?
- check_read $size || return $?
+ write_and_run_one_fio_job \
+ $((first_sequential_zone_sector * 512)) "${size}" \
+ --offset="${off}" \
+ --size="${size}" --zonemode=zbd --zonesize="${zone_size}" \
+ "$(ioengine "psync")" --iodepth=1 --rw=read \
+ --bs="$(max $((zone_size / 64)) "$logical_block_size")" \
+ >>"${logfile}.${test_number}" 2>&1 || return $?
+ check_read $capacity || return $?
}
# Random write to sequential zones, libaio, queue depth 1.
test7() {
local size=$((zone_size))
+ local off capacity
+ off=$((first_sequential_zone_sector * 512))
+ capacity=$(total_zone_capacity 1 $off $dev)
run_fio_on_seq "$(ioengine "libaio")" --iodepth=1 --rw=randwrite \
--bs="$(min 16384 "${zone_size}")" \
--do_verify=1 --verify=md5 --size="$size" \
>>"${logfile}.${test_number}" 2>&1 || return $?
- check_written $size || return $?
- check_read $size || return $?
+ check_written $capacity || return $?
+ check_read $capacity || return $?
}
# Random write to sequential zones, libaio, queue depth 64.
test8() {
- local size
+ local size off capacity
size=$((4 * zone_size))
+ off=$((first_sequential_zone_sector * 512))
+ capacity=$(total_zone_capacity 4 $off $dev)
run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite \
--bs="$(min 16384 "${zone_size}")" \
--do_verify=1 --verify=md5 \
>>"${logfile}.${test_number}" 2>&1 || return $?
- check_written $size || return $?
- check_read $size || return $?
+ check_written $capacity || return $?
+ check_read $capacity || return $?
}
# Random write to sequential zones, sg, queue depth 1.
# Random write to sequential zones, libaio, queue depth 64, random block size.
test11() {
- local size
+ local size off capacity
size=$((4 * zone_size))
+ off=$((first_sequential_zone_sector * 512))
+ capacity=$(total_zone_capacity 4 $off $dev)
run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite \
--bsrange=4K-64K --do_verify=1 --verify=md5 \
--debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $?
- check_written $size || return $?
- check_read $size || return $?
+ check_written $capacity || return $?
+ check_read $capacity || return $?
}
# Random write to sequential zones, libaio, queue depth 64, max 1 open zone.
test12() {
- local size
+ local size off capacity
size=$((8 * zone_size))
+ off=$((first_sequential_zone_sector * 512))
+ capacity=$(total_zone_capacity 8 $off $dev)
run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
--max_open_zones=1 --size=$size --do_verify=1 --verify=md5 \
--debug=zbd >>"${logfile}.${test_number}" 2>&1 || return $?
- check_written $size || return $?
- check_read $size || return $?
+ check_written $capacity || return $?
+ check_read $capacity || return $?
}
# Random write to sequential zones, libaio, queue depth 64, max 4 open zones.
test13() {
- local size
+ local size off capacity
size=$((8 * zone_size))
+ off=$((first_sequential_zone_sector * 512))
+ capacity=$(total_zone_capacity 8 $off $dev)
run_fio_on_seq "$(ioengine "libaio")" --iodepth=64 --rw=randwrite --bs=16K \
--max_open_zones=4 --size=$size --do_verify=1 --verify=md5 \
--debug=zbd \
>>"${logfile}.${test_number}" 2>&1 || return $?
- check_written $size || return $?
- check_read $size || return $?
+ check_written $capacity || return $?
+ check_read $capacity || return $?
}
# Random write to conventional zones.
# Sequential read on a mix of empty and full zones.
test15() {
local i off size
+ local w_off w_size w_capacity
for ((i=0;i<4;i++)); do
[ -n "$is_zbd" ] &&
reset_zone "$dev" $((first_sequential_zone_sector +
i*sectors_per_zone))
done
- off=$(((first_sequential_zone_sector + 2 * sectors_per_zone) * 512))
- size=$((2 * zone_size))
- run_one_fio_job "$(ioengine "psync")" --rw=write --bs=$((zone_size / 16))\
- --zonemode=zbd --zonesize="${zone_size}" --offset=$off \
- --size=$size >>"${logfile}.${test_number}" 2>&1 ||
- return $?
- check_written $size || return $?
+ 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)
off=$((first_sequential_zone_sector * 512))
size=$((4 * zone_size))
- run_one_fio_job "$(ioengine "psync")" --rw=read --bs=$((zone_size / 16)) \
+ write_and_run_one_fio_job "${w_off}" "${w_size}" \
+ "$(ioengine "psync")" --rw=read --bs=$((zone_size / 16)) \
--zonemode=zbd --zonesize="${zone_size}" --offset=$off \
--size=$((size)) >>"${logfile}.${test_number}" 2>&1 ||
return $?
- if [ -n "$is_zbd" ]; then
- check_read $((size / 2))
- else
- check_read $size
- fi
+ check_written $((w_capacity)) || return $?
+ check_read $((w_capacity))
}
-# Random read on a mix of empty and full zones. Must be run after test15.
+# Random read on a mix of empty and full zones.
test16() {
local off size
+ local i w_off w_size w_capacity
+ for ((i=0;i<4;i++)); do
+ [ -n "$is_zbd" ] &&
+ reset_zone "$dev" $((first_sequential_zone_sector +
+ i*sectors_per_zone))
+ done
+ 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)
off=$((first_sequential_zone_sector * 512))
size=$((4 * zone_size))
- run_one_fio_job "$(ioengine "libaio")" --iodepth=64 --rw=randread --bs=16K \
+ write_and_run_one_fio_job "${w_off}" "${w_size}" \
+ "$(ioengine "libaio")" --iodepth=64 --rw=randread --bs=16K \
--zonemode=zbd --zonesize="${zone_size}" --offset=$off \
--size=$size >>"${logfile}.${test_number}" 2>&1 || return $?
+ check_written $w_capacity || return $?
check_read $size || return $?
}
off=$(((disk_size / zone_size - 1) * zone_size))
size=$((disk_size - off))
- # Overwrite the last zone to avoid that reading from that zone fails.
if [ -n "$is_zbd" ]; then
reset_zone "$dev" $((off / 512)) || return $?
fi
- run_one_fio_job "$(ioengine "psync")" --rw=write --offset="$off" \
- --zonemode=zbd --zonesize="${zone_size}" \
- --bs="$zone_size" --size="$zone_size" \
- >>"${logfile}.${test_number}" 2>&1 || return $?
- check_written "$zone_size" || return $?
run_one_fio_job "$(ioengine "libaio")" --iodepth=8 --rw=randrw --bs=4K \
--zonemode=zbd --zonesize="${zone_size}" \
--offset=$off --loops=2 --norandommap=1\
test24() {
local bs loops=9 size=$((zone_size))
+ local off capacity
+
+ off=$((first_sequential_zone_sector * 512))
+ capacity=$(total_zone_capacity 1 $off $dev)
bs=$(min $((256*1024)) "$zone_size")
run_fio_on_seq "$(ioengine "psync")" --rw=write --bs="$bs" \
--size=$size --loops=$loops \
--zone_reset_frequency=.01 --zone_reset_threshold=.90 \
>> "${logfile}.${test_number}" 2>&1 || return $?
- check_written $((size * loops)) || return $?
+ check_written $((capacity * loops)) || return $?
check_reset_count -eq 8 ||
check_reset_count -eq 9 ||
check_reset_count -eq 10 || return $?
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 $?
}
write_to_first_seq_zone() {
local loops=4 r
+ local off capacity
+
+ off=$((first_sequential_zone_sector * 512))
+ capacity=$(total_zone_capacity 1 $off $dev)
r=$(((RANDOM << 16) | RANDOM))
run_fio --name="$dev" --filename="$dev" "$(ioengine "psync")" --rw="$1" \
--thread=1 --do_verify=1 --verify=md5 --direct=1 --bs=4K \
- --offset=$((first_sequential_zone_sector * 512)) \
- "--size=$zone_size" --loops=$loops --randseed="$r" \
+ --offset=$off \
+ --size=$zone_size --loops=$loops --randseed="$r" \
--zonemode=zbd --zonesize="${zone_size}" --group_reporting=1 \
--gtod_reduce=1 >> "${logfile}.${test_number}" 2>&1 || return $?
- check_written $((loops * zone_size)) || return $?
+ check_written $((loops * capacity)) || return $?
}
# Overwrite the first sequential zone four times sequentially.
off=$((first_sequential_zone_sector * 512 + 64 * zone_size))
[ -n "$is_zbd" ] && reset_zone "$dev" $((off / 512))
opts=("--debug=zbd")
+ capacity=$(total_zone_capacity 1 $off $dev)
for ((i=0;i<jobs;i++)); do
opts+=("--name=job$i" "--filename=$dev" "--offset=$off" "--bs=16K")
- opts+=("--size=$zone_size" "$(ioengine "psync")" "--rw=randwrite")
+ 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 * zone_size)) || return $?
+ check_written $((jobs * $capacity)) || return $?
check_reset_count -eq $jobs ||
check_reset_count -eq $((jobs - 1)) ||
return $?
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 $?
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 $?
}
# zone size.
test33() {
local bs io_size size
+ local off capacity=0;
+ off=$((first_sequential_zone_sector * 512))
+ capacity=$(total_zone_capacity 1 $off $dev)
size=$((2 * zone_size))
- io_size=$((5 * zone_size))
- bs=$((3 * zone_size / 4))
+ io_size=$((5 * capacity))
+ bs=$((3 * capacity / 4))
run_fio_on_seq "$(ioengine "psync")" --iodepth=1 --rw=write \
--size=$size --io_size=$io_size --bs=$bs \
>> "${logfile}.${test_number}" 2>&1 || return $?
# Test 3/4 for the I/O boundary rounding code: $size > $zone_size.
test37() {
- local bs off size
+ local bs off size capacity
+ capacity=$(total_zone_capacity 1 $first_sequential_zone_sector $dev)
if [ "$first_sequential_zone_sector" = 0 ]; then
off=0
else
--iodepth=1 --rw=write --do_verify=1 --verify=md5 \
--bs=$bs --zonemode=zbd --zonesize="${zone_size}" \
>> "${logfile}.${test_number}" 2>&1
- check_written $((zone_size)) || return $?
+ check_written $capacity || return $?
}
# Test 4/4 for the I/O boundary rounding code: $offset > $disk_size - $zone_size
test47() {
local bs
- [ -z "$is_zbd" ] && return 0
bs=$((logical_block_size))
- run_one_fio_job "$(ioengine "psync")" --rw=write --bs=$bs \
- --zonemode=zbd --zoneskip=1 \
+ run_fio_on_seq "$(ioengine "psync")" --rw=write --bs=$bs --zoneskip=1 \
>> "${logfile}.${test_number}" 2>&1 && return 1
grep -q 'zoneskip 1 is not a multiple of the device zone size' "${logfile}.${test_number}"
}
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
>> "${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
-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")
case "$(<"/sys/class/block/$basename/queue/zoned")" in
host-managed|host-aware)
is_zbd=true
+ if ! check_blkzone "${dev}"; then
+ exit 1
+ fi
if ! result=($(first_sequential_zone "$dev")); then
echo "Failed to determine first sequential zone"
exit 1
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"
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++))