kvm-test-1-run.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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=/tmp/kvm-test-1-run.sh.$$
  41. trap 'rm -rf $T' 0
  42. touch $T
  43. . $KVM/bin/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. cp $config_template $resdir/ConfigFragment
  61. echo ' ---' `date`: Starting build
  62. echo ' ---' Kconfig fragment at: $config_template >> $resdir/log
  63. if test -r "$config_dir/CFcommon"
  64. then
  65. cat < $config_dir/CFcommon >> $T
  66. fi
  67. # Optimizations below this point
  68. # CONFIG_USB=n
  69. # CONFIG_SECURITY=n
  70. # CONFIG_NFS_FS=n
  71. # CONFIG_SOUND=n
  72. # CONFIG_INPUT_JOYSTICK=n
  73. # CONFIG_INPUT_TABLET=n
  74. # CONFIG_INPUT_TOUCHSCREEN=n
  75. # CONFIG_INPUT_MISC=n
  76. # CONFIG_INPUT_MOUSE=n
  77. # # CONFIG_NET=n # disables console access, so accept the slower build.
  78. # CONFIG_SCSI=n
  79. # CONFIG_ATA=n
  80. # CONFIG_FAT_FS=n
  81. # CONFIG_MSDOS_FS=n
  82. # CONFIG_VFAT_FS=n
  83. # CONFIG_ISO9660_FS=n
  84. # CONFIG_QUOTA=n
  85. # CONFIG_HID=n
  86. # CONFIG_CRYPTO=n
  87. # CONFIG_PCCARD=n
  88. # CONFIG_PCMCIA=n
  89. # CONFIG_CARDBUS=n
  90. # CONFIG_YENTA=n
  91. base_resdir=`echo $resdir | sed -e 's/\.[0-9]\+$//'`
  92. if test "$base_resdir" != "$resdir" -a -f $base_resdir/bzImage -a -f $base_resdir/vmlinux
  93. then
  94. # Rerunning previous test, so use that test's kernel.
  95. QEMU="`identify_qemu $base_resdir/vmlinux`"
  96. BOOT_IMAGE="`identify_boot_image $QEMU`"
  97. KERNEL=$base_resdir/${BOOT_IMAGE##*/} # use the last component of ${BOOT_IMAGE}
  98. ln -s $base_resdir/Make*.out $resdir # for kvm-recheck.sh
  99. ln -s $base_resdir/.config $resdir # for kvm-recheck.sh
  100. elif kvm-build.sh $config_template $builddir $T
  101. then
  102. # Had to build a kernel for this test.
  103. QEMU="`identify_qemu $builddir/vmlinux`"
  104. BOOT_IMAGE="`identify_boot_image $QEMU`"
  105. cp $builddir/Make*.out $resdir
  106. cp $builddir/vmlinux $resdir
  107. cp $builddir/.config $resdir
  108. if test -n "$BOOT_IMAGE"
  109. then
  110. cp $builddir/$BOOT_IMAGE $resdir
  111. KERNEL=$resdir/${BOOT_IMAGE##*/}
  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 $config_template`
  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
  153. touch $resdir/Warnings
  154. echo CPU count limited from $cpu_count to $vcpus >> $resdir/Warnings
  155. cpu_count=$vcpus
  156. fi
  157. qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"
  158. # Generate architecture-specific and interaction-specific qemu arguments
  159. qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$resdir/console.log"`"
  160. # Generate qemu -append arguments
  161. qemu_append="`identify_qemu_append "$QEMU"`"
  162. # Pull in Kconfig-fragment boot parameters
  163. boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
  164. # Generate kernel-version-specific boot parameters
  165. boot_args="`per_version_boot_params "$boot_args" $builddir/.config $seconds`"
  166. if test -n "$TORTURE_BUILDONLY"
  167. then
  168. echo Build-only run specified, boot/test omitted.
  169. touch $resdir/buildonly
  170. exit 0
  171. fi
  172. echo "NOTE: $QEMU either did not run or was interactive" > $resdir/console.log
  173. echo $QEMU $qemu_args -m 512 -kernel $KERNEL -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd
  174. ( $QEMU $qemu_args -m 512 -kernel $KERNEL -append "$qemu_append $boot_args"& echo $! > $resdir/qemu_pid; wait `cat $resdir/qemu_pid`; echo $? > $resdir/qemu-retval ) &
  175. commandcompleted=0
  176. sleep 10 # Give qemu's pid a chance to reach the file
  177. if test -s "$resdir/qemu_pid"
  178. then
  179. qemu_pid=`cat "$resdir/qemu_pid"`
  180. echo Monitoring qemu job at pid $qemu_pid
  181. else
  182. qemu_pid=""
  183. echo Monitoring qemu job at yet-as-unknown pid
  184. fi
  185. while :
  186. do
  187. if test -z "$qemu_pid" -a -s "$resdir/qemu_pid"
  188. then
  189. qemu_pid=`cat "$resdir/qemu_pid"`
  190. fi
  191. kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
  192. if test -z "$qemu_pid" || kill -0 "$qemu_pid" > /dev/null 2>&1
  193. then
  194. if test $kruntime -ge $seconds
  195. then
  196. break;
  197. fi
  198. sleep 1
  199. else
  200. commandcompleted=1
  201. if test $kruntime -lt $seconds
  202. then
  203. echo Completed in $kruntime vs. $seconds >> $resdir/Warnings 2>&1
  204. grep "^(qemu) qemu:" $resdir/kvm-test-1-run.sh.out >> $resdir/Warnings 2>&1
  205. killpid="`sed -n "s/^(qemu) qemu: terminating on signal [0-9]* from pid \([0-9]*\).*$/\1/p" $resdir/Warnings`"
  206. if test -n "$killpid"
  207. then
  208. echo "ps -fp $killpid" >> $resdir/Warnings 2>&1
  209. ps -fp $killpid >> $resdir/Warnings 2>&1
  210. fi
  211. else
  212. echo ' ---' `date`: "Kernel done"
  213. fi
  214. break
  215. fi
  216. done
  217. if test -z "$qemu_pid" -a -s "$resdir/qemu_pid"
  218. then
  219. qemu_pid=`cat "$resdir/qemu_pid"`
  220. fi
  221. if test $commandcompleted -eq 0 -a -n "$qemu_pid"
  222. then
  223. echo Grace period for qemu job at pid $qemu_pid
  224. oldline="`tail $resdir/console.log`"
  225. while :
  226. do
  227. kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
  228. if kill -0 $qemu_pid > /dev/null 2>&1
  229. then
  230. :
  231. else
  232. break
  233. fi
  234. must_continue=no
  235. newline="`tail $resdir/console.log`"
  236. if test "$newline" != "$oldline" && echo $newline | grep -q ' [0-9]\+us : '
  237. then
  238. must_continue=yes
  239. fi
  240. last_ts="`tail $resdir/console.log | grep '^\[ *[0-9]\+\.[0-9]\+]' | tail -1 | sed -e 's/^\[ *//' -e 's/\..*$//'`"
  241. if test -z "last_ts"
  242. then
  243. last_ts=0
  244. fi
  245. if test "$newline" != "$oldline" -a "$last_ts" -lt $((seconds + $TORTURE_SHUTDOWN_GRACE))
  246. then
  247. must_continue=yes
  248. fi
  249. if test $must_continue = no -a $kruntime -ge $((seconds + $TORTURE_SHUTDOWN_GRACE))
  250. then
  251. echo "!!! PID $qemu_pid hung at $kruntime vs. $seconds seconds" >> $resdir/Warnings 2>&1
  252. kill -KILL $qemu_pid
  253. break
  254. fi
  255. oldline=$newline
  256. sleep 10
  257. done
  258. elif test -z "$qemu_pid"
  259. then
  260. echo Unknown PID, cannot kill qemu command
  261. fi
  262. parse-torture.sh $resdir/console.log $title
  263. parse-console.sh $resdir/console.log $title