kvm-test-1-run.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 minutes qemu-args boot_args
  10. #
  11. # qemu-args defaults to "-nographic", along with arguments specifying the
  12. # number of CPUs and other options generated from
  13. # 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. grace=120
  41. T=/tmp/kvm-test-1-run.sh.$$
  42. trap 'rm -rf $T' 0
  43. touch $T
  44. . $KVM/bin/functions.sh
  45. . $KVPATH/ver_functions.sh
  46. config_template=${1}
  47. config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'`
  48. title=`echo $config_template | sed -e 's/^.*\///'`
  49. builddir=${2}
  50. if test -z "$builddir" -o ! -d "$builddir" -o ! -w "$builddir"
  51. then
  52. echo "kvm-test-1-run.sh :$builddir: Not a writable directory, cannot build into it"
  53. exit 1
  54. fi
  55. resdir=${3}
  56. if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"
  57. then
  58. echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it"
  59. exit 1
  60. fi
  61. cp $config_template $resdir/ConfigFragment
  62. echo ' ---' `date`: Starting build
  63. echo ' ---' Kconfig fragment at: $config_template >> $resdir/log
  64. if test -r "$config_dir/CFcommon"
  65. then
  66. cat < $config_dir/CFcommon >> $T
  67. fi
  68. # Optimizations below this point
  69. # CONFIG_USB=n
  70. # CONFIG_SECURITY=n
  71. # CONFIG_NFS_FS=n
  72. # CONFIG_SOUND=n
  73. # CONFIG_INPUT_JOYSTICK=n
  74. # CONFIG_INPUT_TABLET=n
  75. # CONFIG_INPUT_TOUCHSCREEN=n
  76. # CONFIG_INPUT_MISC=n
  77. # CONFIG_INPUT_MOUSE=n
  78. # # CONFIG_NET=n # disables console access, so accept the slower build.
  79. # CONFIG_SCSI=n
  80. # CONFIG_ATA=n
  81. # CONFIG_FAT_FS=n
  82. # CONFIG_MSDOS_FS=n
  83. # CONFIG_VFAT_FS=n
  84. # CONFIG_ISO9660_FS=n
  85. # CONFIG_QUOTA=n
  86. # CONFIG_HID=n
  87. # CONFIG_CRYPTO=n
  88. # CONFIG_PCCARD=n
  89. # CONFIG_PCMCIA=n
  90. # CONFIG_CARDBUS=n
  91. # CONFIG_YENTA=n
  92. if kvm-build.sh $config_template $builddir $T
  93. then
  94. QEMU="`identify_qemu $builddir/vmlinux`"
  95. BOOT_IMAGE="`identify_boot_image $QEMU`"
  96. cp $builddir/Make*.out $resdir
  97. cp $builddir/.config $resdir
  98. if test -n "$BOOT_IMAGE"
  99. then
  100. cp $builddir/$BOOT_IMAGE $resdir
  101. else
  102. echo No identifiable boot image, not running KVM, see $resdir.
  103. echo Do the torture scripts know about your architecture?
  104. fi
  105. parse-build.sh $resdir/Make.out $title
  106. if test -f $builddir.wait
  107. then
  108. mv $builddir.wait $builddir.ready
  109. fi
  110. else
  111. cp $builddir/Make*.out $resdir
  112. cp $builddir/.config $resdir || :
  113. echo Build failed, not running KVM, see $resdir.
  114. if test -f $builddir.wait
  115. then
  116. mv $builddir.wait $builddir.ready
  117. fi
  118. exit 1
  119. fi
  120. while test -f $builddir.ready
  121. do
  122. sleep 1
  123. done
  124. minutes=$4
  125. seconds=$(($minutes * 60))
  126. qemu_args=$5
  127. boot_args=$6
  128. cd $KVM
  129. kstarttime=`awk 'BEGIN { print systime() }' < /dev/null`
  130. if test -z "$TORTURE_BUILDONLY"
  131. then
  132. echo ' ---' `date`: Starting kernel
  133. fi
  134. # Generate -smp qemu argument.
  135. qemu_args="-nographic $qemu_args"
  136. cpu_count=`configNR_CPUS.sh $config_template`
  137. cpu_count=`configfrag_boot_cpus "$boot_args" "$config_template" "$cpu_count"`
  138. vcpus=`identify_qemu_vcpus`
  139. if test $cpu_count -gt $vcpus
  140. then
  141. echo CPU count limited from $cpu_count to $vcpus
  142. touch $resdir/Warnings
  143. echo CPU count limited from $cpu_count to $vcpus >> $resdir/Warnings
  144. cpu_count=$vcpus
  145. fi
  146. qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"
  147. # Generate architecture-specific and interaction-specific qemu arguments
  148. qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$builddir/console.log"`"
  149. # Generate qemu -append arguments
  150. qemu_append="`identify_qemu_append "$QEMU"`"
  151. # Pull in Kconfig-fragment boot parameters
  152. boot_args="`configfrag_boot_params "$boot_args" "$config_template"`"
  153. # Generate kernel-version-specific boot parameters
  154. boot_args="`per_version_boot_params "$boot_args" $builddir/.config $seconds`"
  155. if test -n "$TORTURE_BUILDONLY"
  156. then
  157. echo Build-only run specified, boot/test omitted.
  158. touch $resdir/buildonly
  159. exit 0
  160. fi
  161. echo $QEMU $qemu_args -m 512 -kernel $builddir/$BOOT_IMAGE -append \"$qemu_append $boot_args\" > $resdir/qemu-cmd
  162. ( $QEMU $qemu_args -m 512 -kernel $builddir/$BOOT_IMAGE -append "$qemu_append $boot_args"; echo $? > $resdir/qemu-retval ) &
  163. qemu_pid=$!
  164. commandcompleted=0
  165. echo Monitoring qemu job at pid $qemu_pid
  166. while :
  167. do
  168. kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
  169. if kill -0 $qemu_pid > /dev/null 2>&1
  170. then
  171. if test $kruntime -ge $seconds
  172. then
  173. break;
  174. fi
  175. sleep 1
  176. else
  177. commandcompleted=1
  178. if test $kruntime -lt $seconds
  179. then
  180. echo Completed in $kruntime vs. $seconds >> $resdir/Warnings 2>&1
  181. grep "^(qemu) qemu:" $resdir/kvm-test-1-run.sh.out >> $resdir/Warnings 2>&1
  182. killpid="`sed -n "s/^(qemu) qemu: terminating on signal [0-9]* from pid \([0-9]*\).*$/\1/p" $resdir/Warnings`"
  183. if test -n "$killpid"
  184. then
  185. echo "ps -fp $killpid" >> $resdir/Warnings 2>&1
  186. ps -fp $killpid >> $resdir/Warnings 2>&1
  187. fi
  188. else
  189. echo ' ---' `date`: Kernel done
  190. fi
  191. break
  192. fi
  193. done
  194. if test $commandcompleted -eq 0
  195. then
  196. echo Grace period for qemu job at pid $qemu_pid
  197. while :
  198. do
  199. kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
  200. if kill -0 $qemu_pid > /dev/null 2>&1
  201. then
  202. :
  203. else
  204. break
  205. fi
  206. if test $kruntime -ge $((seconds + grace))
  207. then
  208. echo "!!! PID $qemu_pid hung at $kruntime vs. $seconds seconds" >> $resdir/Warnings 2>&1
  209. kill -KILL $qemu_pid
  210. break
  211. fi
  212. sleep 1
  213. done
  214. fi
  215. cp $builddir/console.log $resdir
  216. parse-torture.sh $resdir/console.log $title
  217. parse-console.sh $resdir/console.log $title