kvm-test-1-run.sh 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. #!/bin/bash
  2. #
  3. # Run a kvm-based test of the specified tree on the specified configs.
  4. # Fully automated run and error checking, no graphics console.
  5. #
  6. # Execute this in the source tree. Do not run it as a background task
  7. # because qemu does not seem to like that much.
  8. #
  9. # Usage: kvm-test-1-run.sh config builddir resdir seconds qemu-args boot_args
  10. #
  11. # qemu-args defaults to "-enable-kvm -nographic", along with arguments
  12. # specifying the number of CPUs and other options
  13. # generated from the underlying CPU architecture.
  14. # boot_args defaults to value returned by the per_version_boot_params
  15. # shell function.
  16. #
  17. # Anything you specify for either qemu-args or boot_args is appended to
  18. # the default values. The "-smp" value is deduced from the contents of
  19. # the config fragment.
  20. #
  21. # More sophisticated argument parsing is clearly needed.
  22. #
  23. # This program is free software; you can redistribute it and/or modify
  24. # it under the terms of the GNU General Public License as published by
  25. # the Free Software Foundation; either version 2 of the License, or
  26. # (at your option) any later version.
  27. #
  28. # This program is distributed in the hope that it will be useful,
  29. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. # GNU General Public License for more details.
  32. #
  33. # You should have received a copy of the GNU General Public License
  34. # along with this program; if not, you can access it online at
  35. # http://www.gnu.org/licenses/gpl-2.0.html.
  36. #
  37. # Copyright (C) IBM Corporation, 2011
  38. #
  39. # Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  40. T=${TMPDIR-/tmp}/kvm-test-1-run.sh.$$
  41. trap 'rm -rf $T' 0
  42. mkdir $T
  43. . functions.sh
  44. . $CONFIGFRAG/ver_functions.sh
  45. config_template=${1}
  46. config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'`
  47. title=`echo $config_template | sed -e 's/^.*\///'`
  48. builddir=${2}
  49. if test -z "$builddir" -o ! -d "$builddir" -o ! -w "$builddir"
  50. then
  51. echo "kvm-test-1-run.sh :$builddir: Not a writable directory, cannot build into it"
  52. exit 1
  53. fi
  54. resdir=${3}
  55. if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"
  56. then
  57. echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it"
  58. exit 1
  59. fi
  60. echo ' ---' `date`: Starting build
  61. echo ' ---' Kconfig fragment at: $config_template >> $resdir/log
  62. touch $resdir/ConfigFragment.input $resdir/ConfigFragment
  63. if test -r "$config_dir/CFcommon"
  64. then
  65. echo " --- $config_dir/CFcommon" >> $resdir/ConfigFragment.input
  66. cat < $config_dir/CFcommon >> $resdir/ConfigFragment.input
  67. config_override.sh $config_dir/CFcommon $config_template > $T/Kc1
  68. grep '#CHECK#' $config_dir/CFcommon >> $resdir/ConfigFragment
  69. else
  70. cp $config_template $T/Kc1
  71. fi
  72. echo " --- $config_template" >> $resdir/ConfigFragment.input
  73. cat $config_template >> $resdir/ConfigFragment.input
  74. grep '#CHECK#' $config_template >> $resdir/ConfigFragment
  75. if test -n "$TORTURE_KCONFIG_ARG"
  76. then
  77. echo $TORTURE_KCONFIG_ARG | tr -s " " "\012" > $T/cmdline
  78. echo " --- --kconfig argument" >> $resdir/ConfigFragment.input
  79. cat $T/cmdline >> $resdir/ConfigFragment.input
  80. config_override.sh $T/Kc1 $T/cmdline > $T/Kc2
  81. # Note that "#CHECK#" is not permitted on commandline.
  82. else
  83. cp $T/Kc1 $T/Kc2
  84. fi
  85. cat $T/Kc2 >> $resdir/ConfigFragment
  86. base_resdir=`echo $resdir | sed -e 's/\.[0-9]\+$//'`
  87. if test "$base_resdir" != "$resdir" -a -f $base_resdir/bzImage -a -f $base_resdir/vmlinux
  88. then
  89. # Rerunning previous test, so use that test's kernel.
  90. QEMU="`identify_qemu $base_resdir/vmlinux`"
  91. BOOT_IMAGE="`identify_boot_image $QEMU`"
  92. KERNEL=$base_resdir/${BOOT_IMAGE##*/} # use the last component of ${BOOT_IMAGE}
  93. ln -s $base_resdir/Make*.out $resdir # for kvm-recheck.sh
  94. ln -s $base_resdir/.config $resdir # for kvm-recheck.sh
  95. # Arch-independent indicator
  96. touch $resdir/builtkernel
  97. elif kvm-build.sh $T/Kc2 $builddir $resdir
  98. then
  99. # Had to build a kernel for this test.
  100. QEMU="`identify_qemu $builddir/vmlinux`"
  101. BOOT_IMAGE="`identify_boot_image $QEMU`"
  102. cp $builddir/vmlinux $resdir
  103. cp $builddir/.config $resdir
  104. cp $builddir/Module.symvers $resdir > /dev/null || :
  105. cp $builddir/System.map $resdir > /dev/null || :
  106. if test -n "$BOOT_IMAGE"
  107. then
  108. cp $builddir/$BOOT_IMAGE $resdir
  109. KERNEL=$resdir/${BOOT_IMAGE##*/}
  110. # Arch-independent indicator
  111. touch $resdir/builtkernel
  112. else
  113. echo No identifiable boot image, not running KVM, see $resdir.
  114. echo Do the torture scripts know about your architecture?
  115. fi
  116. parse-build.sh $resdir/Make.out $title
  117. else
  118. # Build failed.
  119. cp $builddir/Make*.out $resdir
  120. cp $builddir/.config $resdir || :
  121. echo Build failed, not running KVM, see $resdir.
  122. if test -f $builddir.wait
  123. then
  124. mv $builddir.wait $builddir.ready
  125. fi
  126. exit 1
  127. fi
  128. if test -f $builddir.wait
  129. then
  130. mv $builddir.wait $builddir.ready
  131. fi
  132. while test -f $builddir.ready
  133. do
  134. sleep 1
  135. done
  136. seconds=$4
  137. qemu_args=$5
  138. boot_args=$6
  139. cd $KVM
  140. kstarttime=`awk 'BEGIN { print systime() }' < /dev/null`
  141. if test -z "$TORTURE_BUILDONLY"
  142. then
  143. echo ' ---' `date`: Starting kernel
  144. fi
  145. # Generate -smp qemu argument.
  146. qemu_args="-enable-kvm -nographic $qemu_args"
  147. cpu_count=`configNR_CPUS.sh $resdir/ConfigFragment`
  148. cpu_count=`configfrag_boot_cpus "$boot_args" "$config_template" "$cpu_count"`
  149. vcpus=`identify_qemu_vcpus`
  150. if test $cpu_count -gt $vcpus
  151. then
  152. echo CPU count limited from $cpu_count to $vcpus | tee -a $resdir/Warnings
  153. cpu_count=$vcpus
  154. fi
  155. qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"
  156. # Generate architecture-specific and interaction-specific qemu arguments
  157. qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$resdir/console.log"`"
  158. # Generate qemu -append arguments
  159. qemu_append="`identify_qemu_append "$QEMU"`"
  160. # Pull in Kconfig-fragment boot parameters
  161. boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
  162. # Generate kernel-version-specific boot parameters
  163. boot_args="`per_version_boot_params "$boot_args" $resdir/.config $seconds`"
  164. if test -n "$TORTURE_BUILDONLY"
  165. then
  166. echo Build-only run specified, boot/test omitted.
  167. touch $resdir/buildonly
  168. exit 0
  169. fi
  170. echo "NOTE: $QEMU either did not run or was interactive" > $resdir/console.log
  171. echo $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd
  172. ( $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append "$qemu_append $boot_args"& echo $! > $resdir/qemu_pid; wait `cat $resdir/qemu_pid`; echo $? > $resdir/qemu-retval ) &
  173. commandcompleted=0
  174. sleep 10 # Give qemu's pid a chance to reach the file
  175. if test -s "$resdir/qemu_pid"
  176. then
  177. qemu_pid=`cat "$resdir/qemu_pid"`
  178. echo Monitoring qemu job at pid $qemu_pid
  179. else
  180. qemu_pid=""
  181. echo Monitoring qemu job at yet-as-unknown pid
  182. fi
  183. while :
  184. do
  185. if test -z "$qemu_pid" -a -s "$resdir/qemu_pid"
  186. then
  187. qemu_pid=`cat "$resdir/qemu_pid"`
  188. fi
  189. kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
  190. if test -z "$qemu_pid" || kill -0 "$qemu_pid" > /dev/null 2>&1
  191. then
  192. if test $kruntime -ge $seconds
  193. then
  194. break;
  195. fi
  196. sleep 1
  197. else
  198. commandcompleted=1
  199. if test $kruntime -lt $seconds
  200. then
  201. echo Completed in $kruntime vs. $seconds >> $resdir/Warnings 2>&1
  202. grep "^(qemu) qemu:" $resdir/kvm-test-1-run.sh.out >> $resdir/Warnings 2>&1
  203. killpid="`sed -n "s/^(qemu) qemu: terminating on signal [0-9]* from pid \([0-9]*\).*$/\1/p" $resdir/Warnings`"
  204. if test -n "$killpid"
  205. then
  206. echo "ps -fp $killpid" >> $resdir/Warnings 2>&1
  207. ps -fp $killpid >> $resdir/Warnings 2>&1
  208. fi
  209. else
  210. echo ' ---' `date`: "Kernel done"
  211. fi
  212. break
  213. fi
  214. done
  215. if test -z "$qemu_pid" -a -s "$resdir/qemu_pid"
  216. then
  217. qemu_pid=`cat "$resdir/qemu_pid"`
  218. fi
  219. if test $commandcompleted -eq 0 -a -n "$qemu_pid"
  220. then
  221. echo Grace period for qemu job at pid $qemu_pid
  222. oldline="`tail $resdir/console.log`"
  223. while :
  224. do
  225. kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
  226. if kill -0 $qemu_pid > /dev/null 2>&1
  227. then
  228. :
  229. else
  230. break
  231. fi
  232. must_continue=no
  233. newline="`tail $resdir/console.log`"
  234. if test "$newline" != "$oldline" && echo $newline | grep -q ' [0-9]\+us : '
  235. then
  236. must_continue=yes
  237. fi
  238. last_ts="`tail $resdir/console.log | grep '^\[ *[0-9]\+\.[0-9]\+]' | tail -1 | sed -e 's/^\[ *//' -e 's/\..*$//'`"
  239. if test -z "last_ts"
  240. then
  241. last_ts=0
  242. fi
  243. if test "$newline" != "$oldline" -a "$last_ts" -lt $((seconds + $TORTURE_SHUTDOWN_GRACE))
  244. then
  245. must_continue=yes
  246. fi
  247. if test $must_continue = no -a $kruntime -ge $((seconds + $TORTURE_SHUTDOWN_GRACE))
  248. then
  249. echo "!!! PID $qemu_pid hung at $kruntime vs. $seconds seconds" >> $resdir/Warnings 2>&1
  250. kill -KILL $qemu_pid
  251. break
  252. fi
  253. oldline=$newline
  254. sleep 10
  255. done
  256. elif test -z "$qemu_pid"
  257. then
  258. echo Unknown PID, cannot kill qemu command
  259. fi
  260. parse-console.sh $resdir/console.log $title