kvm-again.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0+
  3. #
  4. # Rerun a series of tests under KVM.
  5. #
  6. # Usage: kvm-again.sh /path/to/old/run [ options ]
  7. #
  8. # Copyright (C) 2021 Facebook, Inc.
  9. #
  10. # Authors: Paul E. McKenney <paulmck@kernel.org>
  11. scriptname=$0
  12. args="$*"
  13. T="`mktemp -d ${TMPDIR-/tmp}/kvm-again.sh.XXXXXX`"
  14. trap 'rm -rf $T' 0
  15. if ! test -d tools/testing/selftests/rcutorture/bin
  16. then
  17. echo $scriptname must be run from top-level directory of kernel source tree.
  18. exit 1
  19. fi
  20. oldrun=$1
  21. shift
  22. if ! test -d "$oldrun"
  23. then
  24. echo "Usage: $scriptname /path/to/old/run [ options ]"
  25. exit 1
  26. fi
  27. if ! cp "$oldrun/scenarios" $T/scenarios.oldrun
  28. then
  29. # Later on, can reconstitute this from console.log files.
  30. echo Prior run batches file does not exist: $oldrun/batches
  31. exit 1
  32. fi
  33. if test -f "$oldrun/torture_suite"
  34. then
  35. torture_suite="`cat $oldrun/torture_suite`"
  36. elif test -f "$oldrun/TORTURE_SUITE"
  37. then
  38. torture_suite="`cat $oldrun/TORTURE_SUITE`"
  39. else
  40. echo "Prior run torture_suite file does not exist: $oldrun/{torture_suite,TORTURE_SUITE}"
  41. exit 1
  42. fi
  43. RCUTORTURE="`pwd`/tools/testing/selftests/rcutorture"; export RCUTORTURE
  44. PATH=${RCUTORTURE}/bin:$PATH; export PATH
  45. . functions.sh
  46. bootargs=
  47. dryrun=
  48. dur=
  49. default_link="cp -R"
  50. resdir="`pwd`/tools/testing/selftests/rcutorture/res"
  51. rundir="$resdir/`date +%Y.%m.%d-%H.%M.%S-again`"
  52. got_datestamp=
  53. got_rundir=
  54. startdate="`date`"
  55. starttime="`get_starttime`"
  56. usage () {
  57. echo "Usage: $scriptname $oldrun [ arguments ]:"
  58. echo " --bootargs kernel-boot-arguments"
  59. echo " --datestamp string"
  60. echo " --dryrun"
  61. echo " --duration minutes | <seconds>s | <hours>h | <days>d"
  62. echo " --link hard|soft|copy"
  63. echo " --remote"
  64. echo " --rundir /new/res/path"
  65. echo "Command line: $scriptname $args"
  66. exit 1
  67. }
  68. while test $# -gt 0
  69. do
  70. case "$1" in
  71. --bootargs|--bootarg)
  72. checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
  73. bootargs="$bootargs $2"
  74. shift
  75. ;;
  76. --datestamp)
  77. checkarg --datestamp "(relative pathname)" "$#" "$2" '^[a-zA-Z0-9._/-]*$' '^--'
  78. if test -n "$got_rundir" || test -n "$got_datestamp"
  79. then
  80. echo Only one of --datestamp or --rundir may be specified
  81. usage
  82. fi
  83. got_datestamp=y
  84. ds=$2
  85. rundir="$resdir/$ds"
  86. if test -e "$rundir"
  87. then
  88. echo "--datestamp $2: Already exists."
  89. usage
  90. fi
  91. shift
  92. ;;
  93. --dryrun)
  94. dryrun=1
  95. ;;
  96. --duration)
  97. checkarg --duration "(minutes)" $# "$2" '^[0-9][0-9]*\(s\|m\|h\|d\|\)$' '^error'
  98. mult=60
  99. if echo "$2" | grep -q 's$'
  100. then
  101. mult=1
  102. elif echo "$2" | grep -q 'h$'
  103. then
  104. mult=3600
  105. elif echo "$2" | grep -q 'd$'
  106. then
  107. mult=86400
  108. fi
  109. ts=`echo $2 | sed -e 's/[smhd]$//'`
  110. dur=$(($ts*mult))
  111. shift
  112. ;;
  113. --link)
  114. checkarg --link "hard|soft|copy" "$#" "$2" 'hard\|soft\|copy' '^--'
  115. case "$2" in
  116. copy)
  117. arg_link="cp -R"
  118. ;;
  119. hard)
  120. arg_link="cp -Rl"
  121. ;;
  122. soft)
  123. arg_link="cp -Rs"
  124. ;;
  125. esac
  126. shift
  127. ;;
  128. --remote)
  129. arg_remote=1
  130. default_link="cp -as"
  131. ;;
  132. --rundir)
  133. checkarg --rundir "(absolute pathname)" "$#" "$2" '^/' '^error'
  134. if test -n "$got_rundir" || test -n "$got_datestamp"
  135. then
  136. echo Only one of --datestamp or --rundir may be specified
  137. usage
  138. fi
  139. got_rundir=y
  140. rundir=$2
  141. if test -e "$rundir"
  142. then
  143. echo "--rundir $2: Already exists."
  144. usage
  145. fi
  146. shift
  147. ;;
  148. *)
  149. if test -n "$1"
  150. then
  151. echo Unknown argument $1
  152. usage
  153. fi
  154. ;;
  155. esac
  156. shift
  157. done
  158. if test -z "$arg_link"
  159. then
  160. arg_link="$default_link"
  161. fi
  162. echo ---- Re-run results directory: $rundir
  163. # Copy old run directory tree over and adjust.
  164. mkdir -p "`dirname "$rundir"`"
  165. if ! $arg_link "$oldrun" "$rundir"
  166. then
  167. echo "Cannot copy from $oldrun to $rundir."
  168. usage
  169. fi
  170. rm -f "$rundir"/*/{console.log,console.log.diags,qemu_pid,qemu-pid,qemu-retval,Warnings,kvm-test-1-run.sh.out,kvm-test-1-run-qemu.sh.out,vmlinux} "$rundir"/log
  171. touch "$rundir/log"
  172. echo $scriptname $args | tee -a "$rundir/log"
  173. echo $oldrun > "$rundir/re-run"
  174. if ! test -d "$rundir/../../bin"
  175. then
  176. $arg_link "$oldrun/../../bin" "$rundir/../.."
  177. fi
  178. for i in $rundir/*/qemu-cmd
  179. do
  180. cp "$i" $T
  181. qemu_cmd_dir="`dirname "$i"`"
  182. kernel_dir="`echo $qemu_cmd_dir | sed -e 's/\.[0-9]\+$//'`"
  183. jitter_dir="`dirname "$kernel_dir"`"
  184. kvm-transform.sh "$kernel_dir/bzImage" "$qemu_cmd_dir/console.log" "$jitter_dir" "$dur" "$bootargs" < $T/qemu-cmd > $i
  185. if test -n "$arg_remote"
  186. then
  187. echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i
  188. fi
  189. done
  190. # Extract settings from the last qemu-cmd file transformed above.
  191. grep '^#' $i | sed -e 's/^# //' > $T/qemu-cmd-settings
  192. . $T/qemu-cmd-settings
  193. grep -v '^#' $T/scenarios.oldrun | awk '
  194. {
  195. curbatch = "";
  196. for (i = 2; i <= NF; i++)
  197. curbatch = curbatch " " $i;
  198. print "kvm-test-1-run-batch.sh" curbatch;
  199. }' > $T/runbatches.sh
  200. if test -n "$dryrun"
  201. then
  202. echo ---- Dryrun complete, directory: $rundir | tee -a "$rundir/log"
  203. else
  204. ( cd "$rundir"; sh $T/runbatches.sh ) | tee -a "$rundir/log"
  205. kvm-end-run-stats.sh "$rundir" "$starttime"
  206. fi