3 # Shell functions for the rest of the scripts.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, you can access it online at
17 # http://www.gnu.org/licenses/gpl-2.0.html.
19 # Copyright (C) IBM Corporation, 2013
21 # Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
23 # bootparam_hotplug_cpu bootparam-string
25 # Returns 1 if the specified boot-parameter string tells rcutorture to
26 # test CPU-hotplug operations.
27 bootparam_hotplug_cpu () {
28 echo "$1" | grep -q "rcutorture\.onoff_"
31 # checkarg --argname argtype $# arg mustmatch cannotmatch
33 # Checks the specified argument "arg" against the mustmatch and cannotmatch
38 echo $1 needs argument $2 matching \"$5\"
41 if echo "$4" | grep -q -e "$5"
45 echo $1 $2 \"$4\" must match \"$5\"
48 if echo "$4" | grep -q -e "$6"
50 echo $1 $2 \"$4\" must not match \"$6\"
55 # configfrag_boot_params bootparam-string config-fragment-file
57 # Adds boot parameters from the .boot file, if any.
58 configfrag_boot_params () {
61 echo $1 `grep -v '^#' "$2.boot" | tr '\012' ' '`
67 # configfrag_hotplug_cpu config-fragment-file
69 # Returns 1 if the config fragment specifies hotplug CPU.
70 configfrag_hotplug_cpu () {
73 echo Unreadable config fragment "$1" 1>&2
76 grep -q '^CONFIG_HOTPLUG_CPU=y$' "$1"
79 # identify_boot_image qemu-cmd
81 # Returns the relative path to the kernel build image. This will be
82 # arch/<arch>/boot/bzImage unless overridden with the TORTURE_BOOT_IMAGE
83 # environment variable.
84 identify_boot_image () {
85 if test -n "$TORTURE_BOOT_IMAGE"
87 echo $TORTURE_BOOT_IMAGE
90 qemu-system-x86_64|qemu-system-i386)
91 echo arch/x86/boot/bzImage
94 echo arch/powerpc/boot/bzImage
103 # identify_qemu builddir
105 # Returns our best guess as to which qemu command is appropriate for
106 # the kernel at hand. Override with the TORTURE_QEMU_CMD environment variable.
108 local u="`file "$1"`"
109 if test -n "$TORTURE_QEMU_CMD"
111 echo $TORTURE_QEMU_CMD
112 elif echo $u | grep -q x86-64
114 echo qemu-system-x86_64
115 elif echo $u | grep -q "Intel 80386"
117 echo qemu-system-i386
118 elif uname -a | grep -q ppc64
120 echo qemu-system-ppc64
122 echo Cannot figure out what qemu command to use! 1>&2
123 echo file $1 output: $u
124 # Usually this will be one of /usr/bin/qemu-system-*
125 # Use TORTURE_QEMU_CMD environment variable or appropriate
126 # argument to top-level script.
131 # identify_qemu_append qemu-cmd
133 # Output arguments for the qemu "-append" string based on CPU type
134 # and the TORTURE_QEMU_INTERACTIVE environment variable.
135 identify_qemu_append () {
137 qemu-system-x86_64|qemu-system-i386)
138 echo noapic selinux=0 initcall_debug debug
141 if test -n "$TORTURE_QEMU_INTERACTIVE"
149 # identify_qemu_args qemu-cmd serial-file
151 # Output arguments for qemu arguments based on the TORTURE_QEMU_MAC
152 # and TORTURE_QEMU_INTERACTIVE environment variables.
153 identify_qemu_args () {
155 qemu-system-x86_64|qemu-system-i386)
158 echo -enable-kvm -M pseries -cpu POWER7 -nodefaults
159 echo -device spapr-vscsi
160 if test -n "$TORTURE_QEMU_INTERACTIVE" -a -n "$TORTURE_QEMU_MAC"
162 echo -device spapr-vlan,netdev=net0,mac=$TORTURE_QEMU_MAC
163 echo -netdev bridge,br=br0,id=net0
164 elif test -n "$TORTURE_QEMU_INTERACTIVE"
166 echo -net nic -net user
170 if test -n "$TORTURE_QEMU_INTERACTIVE"
172 echo -monitor stdio -serial pty -S
178 # identify_qemu_vcpus
180 # Returns the number of virtual CPUs available to the aggregate of the
182 identify_qemu_vcpus () {
183 lscpu | grep '^CPU(s):' | sed -e 's/CPU(s)://'
188 # Prints "BUG: " in red followed by remaining arguments
190 printf '\033[031mBUG: \033[m'
196 # Prints "WARNING: " in yellow followed by remaining arguments
198 printf '\033[033mWARNING: \033[m'
202 # specify_qemu_cpus qemu-cmd qemu-args #cpus
204 # Appends a string containing "-smp XXX" to qemu-args, unless the incoming
205 # qemu-args already contains "-smp".
206 specify_qemu_cpus () {
209 if echo $2 | grep -q -e -smp
214 qemu-system-x86_64|qemu-system-i386)
218 nt="`lscpu | grep '^NUMA node0' | sed -e 's/^[^,]*,\([0-9]*\),.*$/\1/'`"
219 echo $2 -smp cores=`expr \( $3 + $nt - 1 \) / $nt`,threads=$nt