Stefan Hajnoczi <stefa...@redhat.com> 于2023年3月24日周五 03:31写道: > > On Thu, Mar 23, 2023 at 01:08:32PM +0800, Sam Li wrote: > > The new block layer APIs of zoned block devices can be tested by: > > $ tests/qemu-iotests/check zoned > > Run each zone operation on a newly created null_blk device > > and see whether it outputs the same zone information. > > > > Signed-off-by: Sam Li <faithilike...@gmail.com> > > Reviewed-by: Stefan Hajnoczi <stefa...@redhat.com> > > --- > > tests/qemu-iotests/tests/zoned | 86 ++++++++++++++++++++++++++++++ > > tests/qemu-iotests/tests/zoned.out | 53 ++++++++++++++++++ > > 2 files changed, 139 insertions(+) > > create mode 100755 tests/qemu-iotests/tests/zoned > > create mode 100644 tests/qemu-iotests/tests/zoned.out > > > > diff --git a/tests/qemu-iotests/tests/zoned b/tests/qemu-iotests/tests/zoned > > new file mode 100755 > > index 0000000000..53097e44d9 > > --- /dev/null > > +++ b/tests/qemu-iotests/tests/zoned > > @@ -0,0 +1,86 @@ > > +#!/usr/bin/env bash > > +# > > +# Test zone management operations. > > +# > > + > > +seq="$(basename $0)" > > +echo "QA output created by $seq" > > +status=1 # failure is the default! > > + > > +_cleanup() > > +{ > > + _cleanup_test_img > > + sudo rmmod null_blk > > +} > > +trap "_cleanup; exit \$status" 0 1 2 3 15 > > + > > +# get standard environment, filters and checks > > +. ../common.rc > > +. ../common.filter > > +. ../common.qemu > > + > > +# This test only runs on Linux hosts with raw image files. > > +_supported_fmt raw > > +_supported_proto file > > +_supported_os Linux > > + > > +IMG="--image-opts -n driver=host_device,filename=/dev/nullb0" > > +QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT > > + > > +echo "Testing a null_blk device:" > > +echo "case 1: if the operations work" > > +sudo modprobe null_blk nr_devices=1 zoned=1 > > I took a look at how existing qemu-iotests use sudo. The run it in > non-interactive mode and skip the test if sudo is unavailable. > > Please do something like this to check for sudo support: > > sudo -n true || _notrun 'Password-less sudo required' > > Then always use "sudo -n ...".
Ok. Then, passwordless sudo demands setup on Linux otherwise the script will not run just as existing qemu-iotests does. > > > > +sudo chmod 0666 /dev/nullb0 > > + > > +echo "(1) report the first zone:" > > +$QEMU_IO $IMG -c "zrp 0 1" > > +echo > > +echo "report the first 10 zones" > > +$QEMU_IO $IMG -c "zrp 0 10" > > +echo > > +echo "report the last zone:" > > +$QEMU_IO $IMG -c "zrp 0x3e70000000 2" # 0x3e70000000 / 512 = 0x1f380000 > > +echo > > +echo > > +echo "(2) opening the first zone" > > +$QEMU_IO $IMG -c "zo 0 268435456" # 268435456 / 512 = 524288 > > +echo "report after:" > > +$QEMU_IO $IMG -c "zrp 0 1" > > +echo > > +echo "opening the second zone" > > +$QEMU_IO $IMG -c "zo 268435456 268435456" # > > +echo "report after:" > > +$QEMU_IO $IMG -c "zrp 268435456 1" > > +echo > > +echo "opening the last zone" > > +$QEMU_IO $IMG -c "zo 0x3e70000000 268435456" > > +echo "report after:" > > +$QEMU_IO $IMG -c "zrp 0x3e70000000 2" > > +echo > > +echo > > +echo "(3) closing the first zone" > > +$QEMU_IO $IMG -c "zc 0 268435456" > > +echo "report after:" > > +$QEMU_IO $IMG -c "zrp 0 1" > > +echo > > +echo "closing the last zone" > > +$QEMU_IO $IMG -c "zc 0x3e70000000 268435456" > > +echo "report after:" > > +$QEMU_IO $IMG -c "zrp 0x3e70000000 2" > > +echo > > +echo > > +echo "(4) finishing the second zone" > > +$QEMU_IO $IMG -c "zf 268435456 268435456" > > +echo "After finishing a zone:" > > +$QEMU_IO $IMG -c "zrp 268435456 1" > > +echo > > +echo > > +echo "(5) resetting the second zone" > > +$QEMU_IO $IMG -c "zrs 268435456 268435456" > > +echo "After resetting a zone:" > > +$QEMU_IO $IMG -c "zrp 268435456 1" > > + > > +# success, all done > > +echo "*** done" > > +rm -f $seq.full > > +status=0 > > diff --git a/tests/qemu-iotests/tests/zoned.out > > b/tests/qemu-iotests/tests/zoned.out > > new file mode 100644 > > index 0000000000..b2d061da49 > > --- /dev/null > > +++ b/tests/qemu-iotests/tests/zoned.out > > @@ -0,0 +1,53 @@ > > +QA output created by zoned > > +Testing a null_blk device: > > +case 1: if the operations work > > +(1) report the first zone: > > +start: 0x0, len 0x80000, cap 0x80000, wptr 0x0, zcond:1, [type: 2] > > + > > +report the first 10 zones > > +start: 0x0, len 0x80000, cap 0x80000, wptr 0x0, zcond:1, [type: 2] > > +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80000, zcond:1, [type: 2] > > +start: 0x100000, len 0x80000, cap 0x80000, wptr 0x100000, zcond:1, [type: > > 2] > > +start: 0x180000, len 0x80000, cap 0x80000, wptr 0x180000, zcond:1, [type: > > 2] > > +start: 0x200000, len 0x80000, cap 0x80000, wptr 0x200000, zcond:1, [type: > > 2] > > +start: 0x280000, len 0x80000, cap 0x80000, wptr 0x280000, zcond:1, [type: > > 2] > > +start: 0x300000, len 0x80000, cap 0x80000, wptr 0x300000, zcond:1, [type: > > 2] > > +start: 0x380000, len 0x80000, cap 0x80000, wptr 0x380000, zcond:1, [type: > > 2] > > +start: 0x400000, len 0x80000, cap 0x80000, wptr 0x400000, zcond:1, [type: > > 2] > > +start: 0x480000, len 0x80000, cap 0x80000, wptr 0x480000, zcond:1, [type: > > 2] > > + > > +report the last zone: > > +start: 0x1f380000, len 0x80000, cap 0x80000, wptr 0x1f380000, zcond:1, > > [type: 2] > > + > > + > > +(2) opening the first zone > > +report after: > > +start: 0x0, len 0x80000, cap 0x80000, wptr 0x0, zcond:3, [type: 2] > > + > > +opening the second zone > > +report after: > > +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80000, zcond:3, [type: 2] > > + > > +opening the last zone > > +report after: > > +start: 0x1f380000, len 0x80000, cap 0x80000, wptr 0x1f380000, zcond:3, > > [type: 2] > > + > > + > > +(3) closing the first zone > > +report after: > > +start: 0x0, len 0x80000, cap 0x80000, wptr 0x0, zcond:1, [type: 2] > > + > > +closing the last zone > > +report after: > > +start: 0x1f380000, len 0x80000, cap 0x80000, wptr 0x1f380000, zcond:1, > > [type: 2] > > + > > + > > +(4) finishing the second zone > > +After finishing a zone: > > +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x100000, zcond:14, [type: > > 2] > > + > > + > > +(5) resetting the second zone > > +After resetting a zone: > > +start: 0x80000, len 0x80000, cap 0x80000, wptr 0x80000, zcond:1, [type: 2] > > +*** done > > -- > > 2.39.2 > >