~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/rcutorture/bin/kvm-transform.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0+
  3 #
  4 # Transform a qemu-cmd file to allow reuse.
  5 #
  6 # Usage: kvm-transform.sh bzImage console.log jitter_dir seconds [ bootargs ] < qemu-cmd-in > qemu-cmd-out
  7 #
  8 #       bzImage: Kernel and initrd from the same prior kvm.sh run.
  9 #       console.log: File into which to place console output.
 10 #       jitter_dir: Jitter directory for TORTURE_JITTER_START and
 11 #               TORTURE_JITTER_STOP environment variables.
 12 #       seconds: Run duaration for *.shutdown_secs module parameter.
 13 #       bootargs: New kernel boot parameters.  Beware of Robert Tables.
 14 #
 15 # The original qemu-cmd file is provided on standard input.
 16 # The transformed qemu-cmd file is on standard output.
 17 # The transformation assumes that the qemu command is confined to a
 18 # single line.  It also assumes no whitespace in filenames.
 19 #
 20 # Copyright (C) 2020 Facebook, Inc.
 21 #
 22 # Authors: Paul E. McKenney <paulmck@kernel.org>
 23 
 24 T=`mktemp -d /tmp/kvm-transform.sh.XXXXXXXXXX`
 25 trap 'rm -rf $T' 0 2
 26 
 27 image="$1"
 28 if test -z "$image"
 29 then
 30         echo Need kernel image file.
 31         exit 1
 32 fi
 33 consolelog="$2"
 34 if test -z "$consolelog"
 35 then
 36         echo "Need console log file name."
 37         exit 1
 38 fi
 39 jitter_dir="$3"
 40 if test -z "$jitter_dir" || ! test -d "$jitter_dir"
 41 then
 42         echo "Need valid jitter directory: '$jitter_dir'"
 43         exit 1
 44 fi
 45 seconds="$4"
 46 if test -n "$seconds" && echo $seconds | grep -q '[^0-9]'
 47 then
 48         echo "Invalid duration, should be numeric in seconds: '$seconds'"
 49         exit 1
 50 fi
 51 bootargs="$5"
 52 
 53 # Build awk program.
 54 echo "BEGIN {" > $T/bootarg.awk
 55 echo $bootargs | tr -s ' ' '\012' |
 56         awk -v dq='"' '/./ { print "\tbootarg[" NR "] = " dq $1 dq ";" }' >> $T/bootarg.awk
 57 echo $bootargs | tr -s ' ' '\012' | sed -e 's/=.*$//' |
 58         awk -v dq='"' '/./ { print "\tbootpar[" NR "] = " dq $1 dq ";" }' >> $T/bootarg.awk
 59 cat >> $T/bootarg.awk << '___EOF___'
 60 }
 61 
 62 /^# seconds=/ {
 63         if (seconds == "")
 64                 print $0;
 65         else
 66                 print "# seconds=" seconds;
 67         next;
 68 }
 69 
 70 /^# TORTURE_JITTER_START=/ {
 71         print "# TORTURE_JITTER_START=\". jitterstart.sh " $4 " " jitter_dir " " $6 " " $7;
 72         next;
 73 }
 74 
 75 /^# TORTURE_JITTER_STOP=/ {
 76         print "# TORTURE_JITTER_STOP=\". jitterstop.sh " " " jitter_dir " " $5;
 77         next;
 78 }
 79 
 80 /^#/ {
 81         print $0;
 82         next;
 83 }
 84 
 85 {
 86         line = "";
 87         for (i = 1; i <= NF; i++) {
 88                 if (line == "") {
 89                         line = $i;
 90                 } else {
 91                         line = line " " $i;
 92                 }
 93                 if ($i == "-serial") {
 94                         i++;
 95                         line = line " file:" consolelog;
 96                 } else if ($i == "-kernel") {
 97                         i++;
 98                         line = line " " image;
 99                 } else if ($i == "-append") {
100                         for (i++; i <= NF; i++) {
101                                 arg = $i;
102                                 lq = "";
103                                 rq = "";
104                                 if ("" seconds != "" && $i ~ /\.shutdown_secs=[0-9]*$/)
105                                         sub(/[0-9]*$/, seconds, arg);
106                                 if (arg ~ /^"/) {
107                                         lq = substr(arg, 1, 1);
108                                         arg  = substr(arg, 2);
109                                 }
110                                 if (arg ~ /"$/) {
111                                         rq = substr(arg, length($i), 1);
112                                         arg = substr(arg, 1, length($i) - 1);
113                                 }
114                                 par = arg;
115                                 gsub(/=.*$/, "", par);
116                                 j = 1;
117                                 while (bootpar[j] != "") {
118                                         if (bootpar[j] == par) {
119                                                 arg = "";
120                                                 break;
121                                         }
122                                         j++;
123                                 }
124                                 if (line == "")
125                                         line = lq arg;
126                                 else
127                                         line = line " " lq arg;
128                         }
129                         for (j in bootarg)
130                                 line = line " " bootarg[j];
131                         line = line rq;
132                 }
133         }
134         print line;
135 }
136 ___EOF___
137 
138 awk -v image="$image" -v consolelog="$consolelog" -v jitter_dir="$jitter_dir" \
139     -v seconds="$seconds" -f $T/bootarg.awk

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php