kvm-again.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 scenarios file does not exist: $oldrun/scenarios
  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|inplace|inplace-force"
  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|inplace|inplace-force" "$#" "$2" 'hard\|soft\|copy\|inplace\|inplace-force' '^--'
  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. inplace)
  126. arg_link="inplace"
  127. rundir="$oldrun"
  128. ;;
  129. inplace-force)
  130. arg_link="inplace-force"
  131. rundir="$oldrun"
  132. ;;
  133. esac
  134. shift
  135. ;;
  136. --remote)
  137. arg_remote=1
  138. default_link="cp -as"
  139. ;;
  140. --rundir)
  141. checkarg --rundir "(absolute pathname)" "$#" "$2" '^/' '^error'
  142. if test -n "$got_rundir" || test -n "$got_datestamp"
  143. then
  144. echo Only one of --datestamp or --rundir may be specified
  145. usage
  146. fi
  147. got_rundir=y
  148. rundir=$2
  149. if test -e "$rundir"
  150. then
  151. echo "--rundir $2: Already exists."
  152. usage
  153. fi
  154. shift
  155. ;;
  156. *)
  157. if test -n "$1"
  158. then
  159. echo Unknown argument $1
  160. usage
  161. fi
  162. ;;
  163. esac
  164. shift
  165. done
  166. if test -z "$arg_link"
  167. then
  168. arg_link="$default_link"
  169. fi
  170. echo ---- Re-run results directory: $rundir
  171. if test "$oldrun" != "$rundir"
  172. then
  173. # Copy old run directory tree over and adjust.
  174. mkdir -p "`dirname "$rundir"`"
  175. if ! $arg_link "$oldrun" "$rundir"
  176. then
  177. echo "Cannot copy from $oldrun to $rundir."
  178. usage
  179. fi
  180. 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
  181. touch "$rundir/log"
  182. echo $scriptname $args | tee -a "$rundir/log"
  183. echo $oldrun > "$rundir/re-run"
  184. if ! test -d "$rundir/../../bin"
  185. then
  186. $arg_link "$oldrun/../../bin" "$rundir/../.."
  187. fi
  188. else
  189. # Check for a run having already happened.
  190. find "$rundir" -name console.log -print > $T/oldrun-console.log
  191. if test -s $T/oldrun-console.log
  192. then
  193. echo Run already took place in $rundir
  194. if test "$arg_link" = inplace
  195. then
  196. usage
  197. fi
  198. fi
  199. fi
  200. # Find runs to be done based on their qemu-cmd files.
  201. for i in $rundir/*/qemu-cmd
  202. do
  203. cp "$i" $T
  204. qemu_cmd_dir="`dirname "$i"`"
  205. kernel_dir="`echo $qemu_cmd_dir | sed -e 's/\.[0-9]\+$//'`"
  206. jitter_dir="`dirname "$kernel_dir"`"
  207. kvm-transform.sh "$kernel_dir/bzImage" "$qemu_cmd_dir/console.log" "$jitter_dir" "$dur" "$bootargs" < $T/qemu-cmd > $i
  208. if test -n "$arg_remote"
  209. then
  210. echo "# TORTURE_KCONFIG_GDB_ARG=''" >> $i
  211. fi
  212. done
  213. # Extract settings from the last qemu-cmd file transformed above.
  214. grep '^#' $i | sed -e 's/^# //' > $T/qemu-cmd-settings
  215. . $T/qemu-cmd-settings
  216. grep -v '^#' $T/scenarios.oldrun | awk '
  217. {
  218. curbatch = "";
  219. for (i = 2; i <= NF; i++)
  220. curbatch = curbatch " " $i;
  221. print "kvm-test-1-run-batch.sh" curbatch;
  222. }' > $T/runbatches.sh
  223. if test -n "$dryrun"
  224. then
  225. echo ---- Dryrun complete, directory: $rundir | tee -a "$rundir/log"
  226. else
  227. ( cd "$rundir"; sh $T/runbatches.sh ) | tee -a "$rundir/log"
  228. kvm-end-run-stats.sh "$rundir" "$starttime"
  229. fi