kvm-test-1-run.sh 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0+
  3. #
  4. # Run a kvm-based test of the specified tree on the specified configs.
  5. # Fully automated run and error checking, no graphics console.
  6. #
  7. # Execute this in the source tree. Do not run it as a background task
  8. # because qemu does not seem to like that much.
  9. #
  10. # Usage: kvm-test-1-run.sh config resdir seconds qemu-args boot_args_in
  11. #
  12. # qemu-args defaults to "-enable-kvm -display none -no-reboot", along
  13. # with arguments specifying the number of CPUs
  14. # and other options generated from the underlying
  15. # CPU architecture.
  16. # boot_args_in defaults to value returned by the per_version_boot_params
  17. # shell function.
  18. #
  19. # Anything you specify for either qemu-args or boot_args_in is appended to
  20. # the default values. The "-smp" value is deduced from the contents of
  21. # the config fragment.
  22. #
  23. # More sophisticated argument parsing is clearly needed.
  24. #
  25. # Copyright (C) IBM Corporation, 2011
  26. #
  27. # Authors: Paul E. McKenney <paulmck@linux.ibm.com>
  28. T="`mktemp -d ${TMPDIR-/tmp}/kvm-test-1-run.sh.XXXXXX`"
  29. trap 'rm -rf $T' 0
  30. . functions.sh
  31. . $CONFIGFRAG/ver_functions.sh
  32. config_template=${1}
  33. config_dir=`echo $config_template | sed -e 's,/[^/]*$,,'`
  34. title=`echo $config_template | sed -e 's/^.*\///'`
  35. resdir=${2}
  36. if test -z "$resdir" -o ! -d "$resdir" -o ! -w "$resdir"
  37. then
  38. echo "kvm-test-1-run.sh :$resdir: Not a writable directory, cannot store results into it"
  39. exit 1
  40. fi
  41. echo ' ---' `date`: Starting build, PID $$
  42. echo ' ---' Kconfig fragment at: $config_template >> $resdir/log
  43. touch $resdir/ConfigFragment.input
  44. # Combine additional Kconfig options into an existing set such that
  45. # newer options win. The first argument is the Kconfig source ID, the
  46. # second the to-be-updated file within $T, and the third and final the
  47. # list of additional Kconfig options. Note that a $2.tmp file is
  48. # created when doing the update.
  49. config_override_param () {
  50. if test -n "$3"
  51. then
  52. echo $3 | sed -e 's/^ *//' -e 's/ *$//' | tr -s " " "\012" > $T/Kconfig_args
  53. echo " --- $1" >> $resdir/ConfigFragment.input
  54. cat $T/Kconfig_args >> $resdir/ConfigFragment.input
  55. config_override.sh $T/$2 $T/Kconfig_args > $T/$2.tmp
  56. mv $T/$2.tmp $T/$2
  57. fi
  58. }
  59. echo > $T/KcList
  60. config_override_param "$config_dir/CFcommon" KcList "`cat $config_dir/CFcommon 2> /dev/null`"
  61. config_override_param "$config_template" KcList "`cat $config_template 2> /dev/null`"
  62. config_override_param "--gdb options" KcList "$TORTURE_KCONFIG_GDB_ARG"
  63. config_override_param "--kasan options" KcList "$TORTURE_KCONFIG_KASAN_ARG"
  64. config_override_param "--kcsan options" KcList "$TORTURE_KCONFIG_KCSAN_ARG"
  65. config_override_param "--kconfig argument" KcList "$TORTURE_KCONFIG_ARG"
  66. config_override_param "$config_dir/CFcommon.$(uname -m)" KcList \
  67. "`cat $config_dir/CFcommon.$(uname -m) 2> /dev/null`"
  68. cp $T/KcList $resdir/ConfigFragment
  69. base_resdir=`echo $resdir | sed -e 's/\.[0-9]\+$//'`
  70. if test "$base_resdir" != "$resdir" && (test -f $base_resdir/bzImage || test -f $base_resdir/Image) && test -f $base_resdir/vmlinux
  71. then
  72. # Rerunning previous test, so use that test's kernel.
  73. QEMU="`identify_qemu $base_resdir/vmlinux`"
  74. BOOT_IMAGE="`identify_boot_image $QEMU`"
  75. KERNEL=$base_resdir/${BOOT_IMAGE##*/} # use the last component of ${BOOT_IMAGE}
  76. ln -s $base_resdir/Make*.out $resdir # for kvm-recheck.sh
  77. ln -s $base_resdir/.config $resdir # for kvm-recheck.sh
  78. # Arch-independent indicator
  79. touch $resdir/builtkernel
  80. elif test "$base_resdir" != "$resdir"
  81. then
  82. # Rerunning previous test for which build failed
  83. ln -s $base_resdir/Make*.out $resdir # for kvm-recheck.sh
  84. ln -s $base_resdir/.config $resdir # for kvm-recheck.sh
  85. echo Initial build failed, not running KVM, see $resdir.
  86. if test -f $resdir/build.wait
  87. then
  88. mv $resdir/build.wait $resdir/build.ready
  89. fi
  90. exit 1
  91. elif kvm-build.sh $T/KcList $resdir
  92. then
  93. # Had to build a kernel for this test.
  94. QEMU="`identify_qemu vmlinux`"
  95. BOOT_IMAGE="`identify_boot_image $QEMU`"
  96. cp vmlinux $resdir
  97. cp .config $resdir
  98. cp Module.symvers $resdir > /dev/null || :
  99. cp System.map $resdir > /dev/null || :
  100. if test -n "$BOOT_IMAGE"
  101. then
  102. cp $BOOT_IMAGE $resdir
  103. KERNEL=$resdir/${BOOT_IMAGE##*/}
  104. # Arch-independent indicator
  105. touch $resdir/builtkernel
  106. else
  107. echo No identifiable boot image, not running KVM, see $resdir.
  108. echo Do the torture scripts know about your architecture?
  109. fi
  110. parse-build.sh $resdir/Make.out $title
  111. else
  112. # Build failed.
  113. cp .config $resdir || :
  114. echo Build failed, not running KVM, see $resdir.
  115. if test -f $resdir/build.wait
  116. then
  117. mv $resdir/build.wait $resdir/build.ready
  118. fi
  119. exit 1
  120. fi
  121. if test -f $resdir/build.wait
  122. then
  123. mv $resdir/build.wait $resdir/build.ready
  124. fi
  125. while test -f $resdir/build.ready
  126. do
  127. sleep 1
  128. done
  129. seconds=$3
  130. qemu_args=$4
  131. boot_args_in=$5
  132. if test -z "$TORTURE_BUILDONLY"
  133. then
  134. echo ' ---' `date`: Starting kernel
  135. fi
  136. # Generate -smp qemu argument.
  137. qemu_args="-enable-kvm -display none -no-reboot $qemu_args"
  138. cpu_count=`configNR_CPUS.sh $resdir/ConfigFragment`
  139. cpu_count=`configfrag_boot_cpus "$boot_args_in" "$config_template" "$cpu_count"`
  140. if test "$cpu_count" -gt "$TORTURE_ALLOTED_CPUS"
  141. then
  142. echo CPU count limited from $cpu_count to $TORTURE_ALLOTED_CPUS | tee -a $resdir/Warnings
  143. cpu_count=$TORTURE_ALLOTED_CPUS
  144. fi
  145. qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"
  146. qemu_args="`specify_qemu_net "$qemu_args"`"
  147. # Generate architecture-specific and interaction-specific qemu arguments
  148. qemu_args="$qemu_args `identify_qemu_args "$QEMU" "$resdir/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_in" "$config_template"`"
  153. # Generate kernel-version-specific boot parameters
  154. boot_args="`per_version_boot_params "$boot_args" $resdir/.config $seconds`"
  155. if test -n "$TORTURE_BOOT_GDB_ARG"
  156. then
  157. boot_args="$TORTURE_BOOT_GDB_ARG $boot_args"
  158. fi
  159. # Give bare-metal advice
  160. modprobe_args="`echo $boot_args | tr -s ' ' '\012' | grep "^$TORTURE_MOD\." | sed -e "s/$TORTURE_MOD\.//g"`"
  161. kboot_args="`echo $boot_args | tr -s ' ' '\012' | grep -v "^$TORTURE_MOD\."`"
  162. testid_txt="`dirname $resdir`/testid.txt"
  163. touch $resdir/bare-metal
  164. echo To run this scenario on bare metal: >> $resdir/bare-metal
  165. echo >> $resdir/bare-metal
  166. echo " 1." Set your bare-metal build tree to the state shown in this file: >> $resdir/bare-metal
  167. echo " " $testid_txt >> $resdir/bare-metal
  168. echo " 2." Update your bare-metal build tree"'"s .config based on this file: >> $resdir/bare-metal
  169. echo " " $resdir/ConfigFragment >> $resdir/bare-metal
  170. echo " 3." Make the bare-metal kernel"'"s build system aware of your .config updates: >> $resdir/bare-metal
  171. echo " " $ 'yes "" | make oldconfig' >> $resdir/bare-metal
  172. echo " 4." Build your bare-metal kernel. >> $resdir/bare-metal
  173. echo " 5." Boot your bare-metal kernel with the following parameters: >> $resdir/bare-metal
  174. echo " " $kboot_args >> $resdir/bare-metal
  175. echo " 6." Start the test with the following command: >> $resdir/bare-metal
  176. echo " " $ modprobe $TORTURE_MOD $modprobe_args >> $resdir/bare-metal
  177. echo " 7." After some time, end the test with the following command: >> $resdir/bare-metal
  178. echo " " $ rmmod $TORTURE_MOD >> $resdir/bare-metal
  179. echo " 8." Copy your bare-metal kernel"'"s .config file, overwriting this file: >> $resdir/bare-metal
  180. echo " " $resdir/.config >> $resdir/bare-metal
  181. echo " 9." Copy the console output from just before the modprobe to just after >> $resdir/bare-metal
  182. echo " " the rmmod into this file: >> $resdir/bare-metal
  183. echo " " $resdir/console.log >> $resdir/bare-metal
  184. echo "10." Check for runtime errors using the following command: >> $resdir/bare-metal
  185. echo " " $ tools/testing/selftests/rcutorture/bin/kvm-recheck.sh `dirname $resdir` >> $resdir/bare-metal
  186. echo >> $resdir/bare-metal
  187. echo Some of the above steps may be skipped if you build your bare-metal >> $resdir/bare-metal
  188. echo kernel here: `head -n 1 $testid_txt | sed -e 's/^Build directory: //'` >> $resdir/bare-metal
  189. echo $QEMU $qemu_args -m $TORTURE_QEMU_MEM -kernel $KERNEL -append \"$qemu_append $boot_args\" $TORTURE_QEMU_GDB_ARG > $resdir/qemu-cmd
  190. echo "# TORTURE_SHUTDOWN_GRACE=$TORTURE_SHUTDOWN_GRACE" >> $resdir/qemu-cmd
  191. echo "# seconds=$seconds" >> $resdir/qemu-cmd
  192. echo "# TORTURE_KCONFIG_GDB_ARG=\"$TORTURE_KCONFIG_GDB_ARG\"" >> $resdir/qemu-cmd
  193. echo "# TORTURE_JITTER_START=\"$TORTURE_JITTER_START\"" >> $resdir/qemu-cmd
  194. echo "# TORTURE_JITTER_STOP=\"$TORTURE_JITTER_STOP\"" >> $resdir/qemu-cmd
  195. echo "# TORTURE_TRUST_MAKE=\"$TORTURE_TRUST_MAKE\"; export TORTURE_TRUST_MAKE" >> $resdir/qemu-cmd
  196. echo "# TORTURE_CPU_COUNT=$cpu_count" >> $resdir/qemu-cmd
  197. if test -n "$TORTURE_BUILDONLY"
  198. then
  199. echo Build-only run specified, boot/test omitted.
  200. touch $resdir/buildonly
  201. exit 0
  202. fi
  203. kvm-test-1-run-qemu.sh $resdir
  204. parse-console.sh $resdir/console.log $title