kvm.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. #!/bin/bash
  2. #
  3. # Run a series of 14 tests under KVM. These are not particularly
  4. # well-selected or well-tuned, but are the current set. Run from the
  5. # top level of the source tree.
  6. #
  7. # Edit the definitions below to set the locations of the various directories,
  8. # as well as the test duration.
  9. #
  10. # Usage: kvm.sh [ options ]
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 2 of the License, or
  15. # (at your option) any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. # You should have received a copy of the GNU General Public License
  23. # along with this program; if not, you can access it online at
  24. # http://www.gnu.org/licenses/gpl-2.0.html.
  25. #
  26. # Copyright (C) IBM Corporation, 2011
  27. #
  28. # Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  29. scriptname=$0
  30. args="$*"
  31. T=/tmp/kvm.sh.$$
  32. trap 'rm -rf $T' 0
  33. mkdir $T
  34. dur=30
  35. dryrun=""
  36. KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
  37. PATH=${KVM}/bin:$PATH; export PATH
  38. TORTURE_DEFCONFIG=defconfig
  39. TORTURE_BOOT_IMAGE=""
  40. TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD
  41. TORTURE_KMAKE_ARG=""
  42. TORTURE_SUITE=rcu
  43. resdir=""
  44. configs=""
  45. cpus=0
  46. ds=`date +%Y.%m.%d-%H:%M:%S`
  47. kversion=""
  48. . functions.sh
  49. usage () {
  50. echo "Usage: $scriptname optional arguments:"
  51. echo " --bootargs kernel-boot-arguments"
  52. echo " --bootimage relative-path-to-kernel-boot-image"
  53. echo " --buildonly"
  54. echo " --configs \"config-file list\""
  55. echo " --cpus N"
  56. echo " --datestamp string"
  57. echo " --defconfig string"
  58. echo " --dryrun sched|script"
  59. echo " --duration minutes"
  60. echo " --interactive"
  61. echo " --kmake-arg kernel-make-arguments"
  62. echo " --kversion vN.NN"
  63. echo " --mac nn:nn:nn:nn:nn:nn"
  64. echo " --no-initrd"
  65. echo " --qemu-args qemu-system-..."
  66. echo " --qemu-cmd qemu-system-..."
  67. echo " --results absolute-pathname"
  68. echo " --torture rcu"
  69. exit 1
  70. }
  71. while test $# -gt 0
  72. do
  73. case "$1" in
  74. --bootargs)
  75. checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
  76. TORTURE_BOOTARGS="$2"
  77. shift
  78. ;;
  79. --bootimage)
  80. checkarg --bootimage "(relative path to kernel boot image)" "$#" "$2" '[a-zA-Z0-9][a-zA-Z0-9_]*' '^--'
  81. TORTURE_BOOT_IMAGE="$2"
  82. shift
  83. ;;
  84. --buildonly)
  85. TORTURE_BUILDONLY=1
  86. ;;
  87. --configs)
  88. checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
  89. configs="$2"
  90. shift
  91. ;;
  92. --cpus)
  93. checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
  94. cpus=$2
  95. shift
  96. ;;
  97. --datestamp)
  98. checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
  99. ds=$2
  100. shift
  101. ;;
  102. --defconfig)
  103. checkarg --defconfig "defconfigtype" "$#" "$2" '^[^/][^/]*$' '^--'
  104. TORTURE_DEFCONFIG=$2
  105. shift
  106. ;;
  107. --dryrun)
  108. checkarg --dryrun "sched|script" $# "$2" 'sched\|script' '^--'
  109. dryrun=$2
  110. shift
  111. ;;
  112. --duration)
  113. checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
  114. dur=$2
  115. shift
  116. ;;
  117. --interactive)
  118. TORTURE_QEMU_INTERACTIVE=1; export TORTURE_QEMU_INTERACTIVE
  119. ;;
  120. --kmake-arg)
  121. checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
  122. TORTURE_KMAKE_ARG="$2"
  123. shift
  124. ;;
  125. --kversion)
  126. checkarg --kversion "(kernel version)" $# "$2" '^v[0-9.]*$' '^error'
  127. kversion=$2
  128. shift
  129. ;;
  130. --mac)
  131. checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
  132. TORTURE_QEMU_MAC=$2
  133. shift
  134. ;;
  135. --no-initrd)
  136. TORTURE_INITRD=""; export TORTURE_INITRD
  137. ;;
  138. --qemu-args)
  139. checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
  140. TORTURE_QEMU_ARG="$2"
  141. shift
  142. ;;
  143. --qemu-cmd)
  144. checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
  145. TORTURE_QEMU_CMD="$2"
  146. shift
  147. ;;
  148. --results)
  149. checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
  150. resdir=$2
  151. shift
  152. ;;
  153. --torture)
  154. checkarg --torture "(suite name)" "$#" "$2" '^\(lock\|rcu\)$' '^--'
  155. TORTURE_SUITE=$2
  156. shift
  157. ;;
  158. *)
  159. echo Unknown argument $1
  160. usage
  161. ;;
  162. esac
  163. shift
  164. done
  165. CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
  166. KVPATH=${CONFIGFRAG}/$kversion; export KVPATH
  167. if test -z "$configs"
  168. then
  169. configs="`cat $CONFIGFRAG/$kversion/CFLIST`"
  170. fi
  171. if test -z "$resdir"
  172. then
  173. resdir=$KVM/res
  174. fi
  175. # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
  176. touch $T/cfgcpu
  177. for CF in $configs
  178. do
  179. if test -f "$CONFIGFRAG/$kversion/$CF"
  180. then
  181. cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$kversion/$CF`
  182. cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$kversion/$CF" "$cpu_count"`
  183. echo $CF $cpu_count >> $T/cfgcpu
  184. else
  185. echo "The --configs file $CF does not exist, terminating."
  186. exit 1
  187. fi
  188. done
  189. sort -k2nr $T/cfgcpu > $T/cfgcpu.sort
  190. # Use a greedy bin-packing algorithm, sorting the list accordingly.
  191. awk < $T/cfgcpu.sort > $T/cfgcpu.pack -v ncpus=$cpus '
  192. BEGIN {
  193. njobs = 0;
  194. }
  195. {
  196. # Read file of tests and corresponding required numbers of CPUs.
  197. cf[njobs] = $1;
  198. cpus[njobs] = $2;
  199. njobs++;
  200. }
  201. END {
  202. alldone = 0;
  203. batch = 0;
  204. nc = -1;
  205. # Each pass through the following loop creates on test batch
  206. # that can be executed concurrently given ncpus. Note that a
  207. # given test that requires more than the available CPUs will run in
  208. # their own batch. Such tests just have to make do with what
  209. # is available.
  210. while (nc != ncpus) {
  211. batch++;
  212. nc = ncpus;
  213. # Each pass through the following loop considers one
  214. # test for inclusion in the current batch.
  215. for (i = 0; i < njobs; i++) {
  216. if (done[i])
  217. continue; # Already part of a batch.
  218. if (nc >= cpus[i] || nc == ncpus) {
  219. # This test fits into the current batch.
  220. done[i] = batch;
  221. nc -= cpus[i];
  222. if (nc <= 0)
  223. break; # Too-big test in its own batch.
  224. }
  225. }
  226. }
  227. # Dump out the tests in batch order.
  228. for (b = 1; b <= batch; b++)
  229. for (i = 0; i < njobs; i++)
  230. if (done[i] == b)
  231. print cf[i], cpus[i];
  232. }'
  233. # Generate a script to execute the tests in appropriate batches.
  234. cat << ___EOF___ > $T/script
  235. CONFIGFRAG="$CONFIGFRAG"; export CONFIGFRAG
  236. KVM="$KVM"; export KVM
  237. KVPATH="$KVPATH"; export KVPATH
  238. PATH="$PATH"; export PATH
  239. TORTURE_BOOT_IMAGE="$TORTURE_BOOT_IMAGE"; export TORTURE_BOOT_IMAGE
  240. TORTURE_BUILDONLY="$TORTURE_BUILDONLY"; export TORTURE_BUILDONLY
  241. TORTURE_DEFCONFIG="$TORTURE_DEFCONFIG"; export TORTURE_DEFCONFIG
  242. TORTURE_INITRD="$TORTURE_INITRD"; export TORTURE_INITRD
  243. TORTURE_KMAKE_ARG="$TORTURE_KMAKE_ARG"; export TORTURE_KMAKE_ARG
  244. TORTURE_QEMU_CMD="$TORTURE_QEMU_CMD"; export TORTURE_QEMU_CMD
  245. TORTURE_QEMU_INTERACTIVE="$TORTURE_QEMU_INTERACTIVE"; export TORTURE_QEMU_INTERACTIVE
  246. TORTURE_QEMU_MAC="$TORTURE_QEMU_MAC"; export TORTURE_QEMU_MAC
  247. TORTURE_SUITE="$TORTURE_SUITE"; export TORTURE_SUITE
  248. if ! test -e $resdir
  249. then
  250. mkdir -p "$resdir" || :
  251. fi
  252. mkdir $resdir/$ds
  253. echo Results directory: $resdir/$ds
  254. echo $scriptname $args
  255. touch $resdir/$ds/log
  256. echo $scriptname $args >> $resdir/$ds/log
  257. echo ${TORTURE_SUITE} > $resdir/$ds/TORTURE_SUITE
  258. pwd > $resdir/$ds/testid.txt
  259. if test -d .git
  260. then
  261. git status >> $resdir/$ds/testid.txt
  262. git rev-parse HEAD >> $resdir/$ds/testid.txt
  263. if ! git diff HEAD > $T/git-diff 2>&1
  264. then
  265. cp $T/git-diff $resdir/$ds
  266. fi
  267. fi
  268. ___EOF___
  269. awk < $T/cfgcpu.pack \
  270. -v CONFIGDIR="$CONFIGFRAG/$kversion/" \
  271. -v KVM="$KVM" \
  272. -v ncpus=$cpus \
  273. -v rd=$resdir/$ds/ \
  274. -v dur=$dur \
  275. -v TORTURE_QEMU_ARG="$TORTURE_QEMU_ARG" \
  276. -v TORTURE_BOOTARGS="$TORTURE_BOOTARGS" \
  277. 'BEGIN {
  278. i = 0;
  279. }
  280. {
  281. cf[i] = $1;
  282. cpus[i] = $2;
  283. i++;
  284. }
  285. # Dump out the scripting required to run one test batch.
  286. function dump(first, pastlast)
  287. {
  288. print "echo ----Start batch: `date`";
  289. print "echo ----Start batch: `date` >> " rd "/log";
  290. jn=1
  291. for (j = first; j < pastlast; j++) {
  292. builddir=KVM "/b" jn
  293. cpusr[jn] = cpus[j];
  294. if (cfrep[cf[j]] == "") {
  295. cfr[jn] = cf[j];
  296. cfrep[cf[j]] = 1;
  297. } else {
  298. cfrep[cf[j]]++;
  299. cfr[jn] = cf[j] "." cfrep[cf[j]];
  300. }
  301. if (cpusr[jn] > ncpus && ncpus != 0)
  302. ovf = "(!)";
  303. else
  304. ovf = "";
  305. print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date`";
  306. print "echo ", cfr[jn], cpusr[jn] ovf ": Starting build. `date` >> " rd "/log";
  307. print "rm -f " builddir ".*";
  308. print "touch " builddir ".wait";
  309. print "mkdir " builddir " > /dev/null 2>&1 || :";
  310. print "mkdir " rd cfr[jn] " || :";
  311. print "kvm-test-1-run.sh " CONFIGDIR cf[j], builddir, rd cfr[jn], dur " \"" TORTURE_QEMU_ARG "\" \"" TORTURE_BOOTARGS "\" > " rd cfr[jn] "/kvm-test-1-run.sh.out 2>&1 &"
  312. print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date`";
  313. print "echo ", cfr[jn], cpusr[jn] ovf ": Waiting for build to complete. `date` >> " rd "/log";
  314. print "while test -f " builddir ".wait"
  315. print "do"
  316. print "\tsleep 1"
  317. print "done"
  318. print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date`";
  319. print "echo ", cfr[jn], cpusr[jn] ovf ": Build complete. `date` >> " rd "/log";
  320. jn++;
  321. }
  322. for (j = 1; j < jn; j++) {
  323. builddir=KVM "/b" j
  324. print "rm -f " builddir ".ready"
  325. print "if test -z \"$TORTURE_BUILDONLY\""
  326. print "then"
  327. print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date`";
  328. print "\techo ----", cfr[j], cpusr[j] ovf ": Starting kernel. `date` >> " rd "/log";
  329. print "fi"
  330. }
  331. print "wait"
  332. print "if test -z \"$TORTURE_BUILDONLY\""
  333. print "then"
  334. print "\techo ---- All kernel runs complete. `date`";
  335. print "\techo ---- All kernel runs complete. `date` >> " rd "/log";
  336. print "fi"
  337. for (j = 1; j < jn; j++) {
  338. builddir=KVM "/b" j
  339. print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results:";
  340. print "echo ----", cfr[j], cpusr[j] ovf ": Build/run results: >> " rd "/log";
  341. print "cat " rd cfr[j] "/kvm-test-1-run.sh.out";
  342. print "cat " rd cfr[j] "/kvm-test-1-run.sh.out >> " rd "/log";
  343. }
  344. }
  345. END {
  346. njobs = i;
  347. nc = ncpus;
  348. first = 0;
  349. # Each pass through the following loop considers one test.
  350. for (i = 0; i < njobs; i++) {
  351. if (ncpus == 0) {
  352. # Sequential test specified, each test its own batch.
  353. dump(i, i + 1);
  354. first = i;
  355. } else if (nc < cpus[i] && i != 0) {
  356. # Out of CPUs, dump out a batch.
  357. dump(first, i);
  358. first = i;
  359. nc = ncpus;
  360. }
  361. # Account for the CPUs needed by the current test.
  362. nc -= cpus[i];
  363. }
  364. # Dump the last batch.
  365. if (ncpus != 0)
  366. dump(first, i);
  367. }' >> $T/script
  368. cat << ___EOF___ >> $T/script
  369. echo
  370. echo
  371. echo " --- `date` Test summary:"
  372. echo Results directory: $resdir/$ds
  373. kvm-recheck.sh $resdir/$ds
  374. ___EOF___
  375. if test "$dryrun" = script
  376. then
  377. cat $T/script
  378. exit 0
  379. elif test "$dryrun" = sched
  380. then
  381. # Extract the test run schedule from the script.
  382. egrep 'Start batch|Starting build\.' $T/script |
  383. grep -v ">>" |
  384. sed -e 's/:.*$//' -e 's/^echo //'
  385. exit 0
  386. else
  387. # Not a dryrun, so run the script.
  388. sh $T/script
  389. fi
  390. # Tracing: trace_event=rcu:rcu_grace_period,rcu:rcu_future_grace_period,rcu:rcu_grace_period_init,rcu:rcu_nocb_wake,rcu:rcu_preempt_task,rcu:rcu_unlock_preempted_task,rcu:rcu_quiescent_state_report,rcu:rcu_fqs,rcu:rcu_callback,rcu:rcu_kfree_callback,rcu:rcu_batch_start,rcu:rcu_invoke_callback,rcu:rcu_invoke_kfree_callback,rcu:rcu_batch_end,rcu:rcu_torture_read,rcu:rcu_barrier