Commit | Line | Data |
---|---|---|
c87b9c60 PM |
1 | #!/bin/bash |
2 | # | |
3 | # Shell functions for the rest of the scripts. | |
4 | # | |
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. | |
9 | # | |
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. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License | |
0e342a87 PM |
16 | # along with this program; if not, you can access it online at |
17 | # http://www.gnu.org/licenses/gpl-2.0.html. | |
c87b9c60 PM |
18 | # |
19 | # Copyright (C) IBM Corporation, 2013 | |
20 | # | |
21 | # Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com> | |
22 | ||
23 | # bootparam_hotplug_cpu bootparam-string | |
24 | # | |
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_" | |
29 | } | |
30 | ||
32caccb8 PM |
31 | # checkarg --argname argtype $# arg mustmatch cannotmatch |
32 | # | |
33 | # Checks the specified argument "arg" against the mustmatch and cannotmatch | |
34 | # patterns. | |
35 | checkarg () { | |
36 | if test $3 -le 1 | |
37 | then | |
38 | echo $1 needs argument $2 matching \"$5\" | |
39 | usage | |
40 | fi | |
41 | if echo "$4" | grep -q -e "$5" | |
42 | then | |
43 | : | |
44 | else | |
45 | echo $1 $2 \"$4\" must match \"$5\" | |
46 | usage | |
47 | fi | |
48 | if echo "$4" | grep -q -e "$6" | |
49 | then | |
50 | echo $1 $2 \"$4\" must not match \"$6\" | |
51 | usage | |
52 | fi | |
53 | } | |
54 | ||
0cc24414 PM |
55 | # configfrag_boot_params bootparam-string config-fragment-file |
56 | # | |
57 | # Adds boot parameters from the .boot file, if any. | |
58 | configfrag_boot_params () { | |
59 | if test -r "$2.boot" | |
60 | then | |
61 | echo $1 `grep -v '^#' "$2.boot" | tr '\012' ' '` | |
62 | else | |
63 | echo $1 | |
64 | fi | |
65 | } | |
66 | ||
ae867ff0 PM |
67 | # configfrag_boot_cpus bootparam-string config-fragment-file config-cpus |
68 | # | |
69 | # Decreases number of CPUs based on any maxcpus= boot parameters specified. | |
70 | configfrag_boot_cpus () { | |
71 | local bootargs="`configfrag_boot_params "$1" "$2"`" | |
72 | local maxcpus | |
73 | if echo "${bootargs}" | grep -q 'maxcpus=[0-9]' | |
74 | then | |
75 | maxcpus="`echo "${bootargs}" | sed -e 's/^.*maxcpus=\([0-9]*\).*$/\1/'`" | |
76 | if test "$3" -gt "$maxcpus" | |
77 | then | |
78 | echo $maxcpus | |
79 | else | |
80 | echo $3 | |
81 | fi | |
82 | else | |
83 | echo $3 | |
84 | fi | |
85 | } | |
86 | ||
c87b9c60 PM |
87 | # configfrag_hotplug_cpu config-fragment-file |
88 | # | |
89 | # Returns 1 if the config fragment specifies hotplug CPU. | |
90 | configfrag_hotplug_cpu () { | |
4275be83 | 91 | if test ! -r "$1" |
c87b9c60 | 92 | then |
4275be83 | 93 | echo Unreadable config fragment "$1" 1>&2 |
c87b9c60 PM |
94 | exit -1 |
95 | fi | |
4275be83 | 96 | grep -q '^CONFIG_HOTPLUG_CPU=y$' "$1" |
c87b9c60 | 97 | } |
4f8a0312 | 98 | |
f189cc8c PM |
99 | # identify_boot_image qemu-cmd |
100 | # | |
101 | # Returns the relative path to the kernel build image. This will be | |
1b900c6a BF |
102 | # arch/<arch>/boot/bzImage or vmlinux if bzImage is not a target for the |
103 | # architecture, unless overridden with the TORTURE_BOOT_IMAGE environment | |
104 | # variable. | |
f189cc8c PM |
105 | identify_boot_image () { |
106 | if test -n "$TORTURE_BOOT_IMAGE" | |
107 | then | |
108 | echo $TORTURE_BOOT_IMAGE | |
109 | else | |
110 | case "$1" in | |
111 | qemu-system-x86_64|qemu-system-i386) | |
112 | echo arch/x86/boot/bzImage | |
113 | ;; | |
f189cc8c | 114 | *) |
1b900c6a | 115 | echo vmlinux |
f189cc8c PM |
116 | ;; |
117 | esac | |
118 | fi | |
119 | } | |
120 | ||
4f8a0312 PM |
121 | # identify_qemu builddir |
122 | # | |
123 | # Returns our best guess as to which qemu command is appropriate for | |
250da31e | 124 | # the kernel at hand. Override with the TORTURE_QEMU_CMD environment variable. |
4f8a0312 PM |
125 | identify_qemu () { |
126 | local u="`file "$1"`" | |
250da31e | 127 | if test -n "$TORTURE_QEMU_CMD" |
4f8a0312 | 128 | then |
250da31e | 129 | echo $TORTURE_QEMU_CMD |
4f8a0312 PM |
130 | elif echo $u | grep -q x86-64 |
131 | then | |
132 | echo qemu-system-x86_64 | |
133 | elif echo $u | grep -q "Intel 80386" | |
134 | then | |
135 | echo qemu-system-i386 | |
136 | elif uname -a | grep -q ppc64 | |
137 | then | |
138 | echo qemu-system-ppc64 | |
139 | else | |
140 | echo Cannot figure out what qemu command to use! 1>&2 | |
43e38ab3 | 141 | echo file $1 output: $u |
4f8a0312 | 142 | # Usually this will be one of /usr/bin/qemu-system-* |
250da31e | 143 | # Use TORTURE_QEMU_CMD environment variable or appropriate |
4f8a0312 PM |
144 | # argument to top-level script. |
145 | exit 1 | |
146 | fi | |
147 | } | |
315c540d PM |
148 | |
149 | # identify_qemu_append qemu-cmd | |
150 | # | |
151 | # Output arguments for the qemu "-append" string based on CPU type | |
a0edd47c | 152 | # and the TORTURE_QEMU_INTERACTIVE environment variable. |
315c540d PM |
153 | identify_qemu_append () { |
154 | case "$1" in | |
155 | qemu-system-x86_64|qemu-system-i386) | |
156 | echo noapic selinux=0 initcall_debug debug | |
157 | ;; | |
158 | esac | |
a0edd47c | 159 | if test -n "$TORTURE_QEMU_INTERACTIVE" |
315c540d PM |
160 | then |
161 | echo root=/dev/sda | |
162 | else | |
163 | echo console=ttyS0 | |
164 | fi | |
165 | } | |
166 | ||
167 | # identify_qemu_args qemu-cmd serial-file | |
168 | # | |
58f724f7 | 169 | # Output arguments for qemu arguments based on the TORTURE_QEMU_MAC |
a0edd47c | 170 | # and TORTURE_QEMU_INTERACTIVE environment variables. |
315c540d PM |
171 | identify_qemu_args () { |
172 | case "$1" in | |
173 | qemu-system-x86_64|qemu-system-i386) | |
1b2f48f2 | 174 | echo -soundhw pcspk |
315c540d PM |
175 | ;; |
176 | qemu-system-ppc64) | |
d5e95373 | 177 | echo -enable-kvm -M pseries -nodefaults |
315c540d | 178 | echo -device spapr-vscsi |
58f724f7 | 179 | if test -n "$TORTURE_QEMU_INTERACTIVE" -a -n "$TORTURE_QEMU_MAC" |
315c540d | 180 | then |
58f724f7 | 181 | echo -device spapr-vlan,netdev=net0,mac=$TORTURE_QEMU_MAC |
315c540d | 182 | echo -netdev bridge,br=br0,id=net0 |
a0edd47c | 183 | elif test -n "$TORTURE_QEMU_INTERACTIVE" |
315c540d PM |
184 | then |
185 | echo -net nic -net user | |
186 | fi | |
187 | ;; | |
188 | esac | |
a0edd47c | 189 | if test -n "$TORTURE_QEMU_INTERACTIVE" |
315c540d PM |
190 | then |
191 | echo -monitor stdio -serial pty -S | |
192 | else | |
193 | echo -serial file:$2 | |
194 | fi | |
195 | } | |
196 | ||
197 | # identify_qemu_vcpus | |
198 | # | |
199 | # Returns the number of virtual CPUs available to the aggregate of the | |
200 | # guest OSes. | |
201 | identify_qemu_vcpus () { | |
202 | lscpu | grep '^CPU(s):' | sed -e 's/CPU(s)://' | |
203 | } | |
204 | ||
6d40cc0c PM |
205 | # print_bug |
206 | # | |
207 | # Prints "BUG: " in red followed by remaining arguments | |
208 | print_bug () { | |
209 | printf '\033[031mBUG: \033[m' | |
210 | echo $* | |
211 | } | |
212 | ||
213 | # print_warning | |
214 | # | |
215 | # Prints "WARNING: " in yellow followed by remaining arguments | |
216 | print_warning () { | |
217 | printf '\033[033mWARNING: \033[m' | |
218 | echo $* | |
219 | } | |
220 | ||
315c540d PM |
221 | # specify_qemu_cpus qemu-cmd qemu-args #cpus |
222 | # | |
223 | # Appends a string containing "-smp XXX" to qemu-args, unless the incoming | |
224 | # qemu-args already contains "-smp". | |
225 | specify_qemu_cpus () { | |
226 | local nt; | |
227 | ||
228 | if echo $2 | grep -q -e -smp | |
229 | then | |
230 | echo $2 | |
231 | else | |
232 | case "$1" in | |
233 | qemu-system-x86_64|qemu-system-i386) | |
234 | echo $2 -smp $3 | |
235 | ;; | |
236 | qemu-system-ppc64) | |
237 | nt="`lscpu | grep '^NUMA node0' | sed -e 's/^[^,]*,\([0-9]*\),.*$/\1/'`" | |
238 | echo $2 -smp cores=`expr \( $3 + $nt - 1 \) / $nt`,threads=$nt | |
239 | ;; | |
240 | esac | |
241 | fi | |
242 | } |