On 8/24/24 01:38, Martin Wilck wrote: > Add a test that repeatedly rescans nvme controllers while doing IO > on an nvme namespace connected to these controllers. The purpose > of the test is to make sure that no I/O errors or data corruption > occurs because of the rescan operations. The test uses sub-second > sleeps, which can't be easily accomplished in bash because of > missing floating-point arithmetic (and because usleep(1) isn't > portable). Therefore an awk program is used to trigger the > device rescans. > > Signed-off-by: Martin Wilck <mwilck@xxxxxxxx> > --- > v2: - don't use usleep (Nilay Shroff). Use an awk program to do floating > point arithmetic and achieve more accurate sub-second sleep times. > - add 053.out (Nilay Shroff). > --- > tests/nvme/053 | 70 ++++++++++++++++++++++++++++++++++++++++++++++ > tests/nvme/053.out | 2 ++ > tests/nvme/rc | 18 ++++++++++++ > 3 files changed, 90 insertions(+) > create mode 100755 tests/nvme/053 > create mode 100644 tests/nvme/053.out > > diff --git a/tests/nvme/053 b/tests/nvme/053 > new file mode 100755 > index 0000000..d32484c > --- /dev/null > +++ b/tests/nvme/053 > @@ -0,0 +1,70 @@ > +#!/bin/bash > +# SPDX-License-Identifier: GPL-3.0+ > +# Copyright (C) 2024 Martin Wilck, SUSE LLC > + > +. tests/nvme/rc > + > +DESCRIPTION="test controller rescan under I/O load" > +TIMED=1 > +: "${TIMEOUT:=60}" > + > +rescan_controller() { > + local path > + path="$1/rescan_controller" > + > + [[ -f "$path" ]] || { > + echo "cannot rescan $1" > + return 1 > + } > + > + awk -f "$TMPDIR/rescan.awk" \ > + -v path="$path" -v timeout="$TIMEOUT" -v seed="$2" & > +} > + > +create_rescan_script() { > + cat >"$TMPDIR/rescan.awk" <<EOF > +@load "time" > + > +BEGIN { > + srand(seed); > + finish = gettimeofday() + strtonum(timeout); > + while (gettimeofday() < finish) { > + sleep(0.1 + 5 * rand()); > + printf("1\n") > path; > + close(path); > + } > +} > +EOF > +} The "rand()" function in 'awk' returns a floating point value between 0 and 1 (i.e. [0, 1]). So it's possible to have sleep for some cases go upto ~5.1 seconds. So if the intention is to sleep between 0.1 and 5 seconds precisely then we may want to use, sleep(0.1 + 4.9 * rand()); However this is not a major problem and we may ignore. Otherwise, code looks good to me. Reviewed-by: Nilay Shroff (nilay@xxxxxxxxxxxxx)