torture: Add --duration argument to kvm-again.sh
authorPaul E. McKenney <paulmck@kernel.org>
Mon, 22 Feb 2021 22:12:58 +0000 (14:12 -0800)
committerPaul E. McKenney <paulmck@kernel.org>
Mon, 22 Mar 2021 15:29:19 +0000 (08:29 -0700)
This commit adds a --duration argument to kvm-again.sh to allow the user
to override the --duration specified for the original kvm.sh run.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/testing/selftests/rcutorture/bin/kvm-again.sh
tools/testing/selftests/rcutorture/bin/kvm-transform.sh

index 4137440..e7e5458 100755 (executable)
@@ -52,6 +52,7 @@ PATH=${KVM}/bin:$PATH; export PATH
 . functions.sh
 
 dryrun=
+dur=
 default_link="cp -R"
 rundir="`pwd`/tools/testing/selftests/rcutorture/res/`date +%Y.%m.%d-%H.%M.%S-again`"
 
@@ -61,6 +62,7 @@ starttime="`get_starttime`"
 usage () {
        echo "Usage: $scriptname $oldrun [ arguments ]:"
        echo "       --dryrun"
+       echo "       --duration minutes | <seconds>s | <hours>h | <days>d"
        echo "       --link hard|soft|copy"
        echo "       --remote"
        echo "       --rundir /new/res/path"
@@ -73,6 +75,23 @@ do
        --dryrun)
                dryrun=1
                ;;
+       --duration)
+               checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'
+               mult=60
+               if echo "$2" | grep -q 's$'
+               then
+                       mult=1
+               elif echo "$2" | grep -q 'h$'
+               then
+                       mult=3600
+               elif echo "$2" | grep -q 'd$'
+               then
+                       mult=86400
+               fi
+               ts=`echo $2 | sed -e 's/[smhd]$//'`
+               dur=$(($ts*mult))
+               shift
+               ;;
        --link)
                checkarg --link "hard|soft|copy" "$#" "$2" 'hard\|soft\|copy' '^--'
                case "$2" in
@@ -134,7 +153,11 @@ do
        cp "$i" $T
        qemu_cmd_dir="`dirname "$i"`"
        kernel_dir="`echo $qemu_cmd_dir | sed -e 's/\.[0-9]\+$//'`"
-       kvm-transform.sh $kernel_dir/bzImage $qemu_cmd_dir/console.log < $T/qemu-cmd > $i
+       kvm-transform.sh $kernel_dir/bzImage $qemu_cmd_dir/console.log $dur < $T/qemu-cmd > $i
+       if test -n "$dur"
+       then
+               echo "# seconds=$dur" >> $i
+       fi
        echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i
 done
 grep -v '^#' $T/batches.oldrun | awk '
index c45a953..162dddb 100755 (executable)
@@ -3,7 +3,7 @@
 #
 # Transform a qemu-cmd file to allow reuse.
 #
-# Usage: kvm-transform.sh bzImage console.log < qemu-cmd-in > qemu-cmd-out
+# Usage: kvm-transform.sh bzImage console.log [ seconds ] < qemu-cmd-in > qemu-cmd-out
 #
 #      bzImage: Kernel and initrd from the same prior kvm.sh run.
 #      console.log: File into which to place console output.
@@ -29,20 +29,37 @@ then
        echo "Need console log file name."
        exit 1
 fi
+seconds=$3
+if test -n "$seconds" && echo $seconds | grep -q '[^0-9]'
+then
+       echo "Invalid duration, should be numeric in seconds: '$seconds'"
+       exit 1
+fi
+
+awk -v image="$image" -v consolelog="$consolelog" -v seconds="$seconds" '
+/^#/ {
+       print $0;
+       next;
+}
 
-awk -v image="$image" -v consolelog="$consolelog" '
 {
        line = "";
        for (i = 1; i <= NF; i++) {
-               if (line == "")
+               if ("" seconds != "" && $i ~ /\.shutdown_secs=[0-9]*$/) {
+                       sub(/[0-9]*$/, seconds, $i);
+                       if (line == "")
+                               line = $i;
+                       else
+                               line = line " " $i;
+               } else if (line == "") {
                        line = $i;
-               else
+               } else {
                        line = line " " $i;
+               }
                if ($i == "-serial") {
                        i++;
                        line = line " file:" consolelog;
-               }
-               if ($i == "-kernel") {
+               } else if ($i == "-kernel") {
                        i++;
                        line = line " " image;
                }