On Tue, 28 Jun 2022 at 10:35, Sam Li <faithilike...@gmail.com> wrote: > > Stefan Hajnoczi <stefa...@redhat.com> 于2022年6月28日周二 16:20写道: > > > > On Mon, Jun 27, 2022 at 08:19:17AM +0800, Sam Li wrote: > > > diff --git a/tests/qemu-iotests/tests/zoned.sh > > > b/tests/qemu-iotests/tests/zoned.sh > > > new file mode 100755 > > > index 0000000000..262c0b5427 > > > --- /dev/null > > > +++ b/tests/qemu-iotests/tests/zoned.sh > > > @@ -0,0 +1,49 @@ > > > +#!/usr/bin/env bash > > > +# > > > +# Test zone management operations. > > > +# > > > + > > > +QEMU_IO="build/qemu-io" > > > +IMG="--image-opts driver=zoned_host_device,filename=/dev/nullb0" > > > +QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT > > > + > > > +echo "Testing a null_blk device" > > > +echo "Simple cases: if the operations work" > > > +sudo modprobe null_blk nr_devices=1 zoned=1 > > > > Please use bash's "trap" command to remove null_blk on exit. That way > > cleanup happens whether the script exits successfully or not. See > > tests/qemu-iotests/108 for an example. > > Noted. Should I just include "rmmod null_blk" in _cleanup()? I'm a > little confused about the normal way to write qemu-iotests.
Yes, please. There are a few related issues here: 1. Cleaning up qemu-iotests must not assume the environment is set up in a specific way before ./check is launched and they must clean up after themselves (whether the test succeeds or fails). This is important so that tests are idempotent and do not leak resources or change the state of the system, which could affect future test runs. 2. Parallelism Multiple instances of tests should be able to run at the same time. This is a problem with null_blk because two tests that change the state of /dev/nullb0 at the same time will interfere with each other and fail. I don't know if there is a good solution already implemented in qemu-iotests. Maybe Kevin can answer this question? 3. Skipping tests on unsupported systems Tests with specific requirements can use the following functions to run only when the configuration is supported: _supported_fmt raw _supported_proto file _supported_os Linux This means the test only runs on Linux hosts with raw image files. On BSD, macOS, etc the test will be skipped. It will also be skipped if ./check was invoked with -qcow2 or another disk image format that is not raw. The test script can also check whether the system supports necessary features and then skip tests when they are not available: if ! ...check for foo ...; then _notrun "cannot find dependency foo" fi > > > > > +# success, all done > > > +sudo rmmod null_blk > > > +echo "*** done" > > > +#rm -f $seq.full > > > > Why is this commented out? > I should just remove it. seq is not used. Okay. I only found small remnants of $seq.full in common.rc and the tests themselves don't seem to use it. It may be something that early qemu-iotests or event xfstests had that's no longer needed. Stefan