torture: Choose bzImage location based on architecture
[deliverable/linux.git] / tools / testing / selftests / rcutorture / bin / functions.sh
CommitLineData
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.
27bootparam_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.
35checkarg () {
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.
58configfrag_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
c87b9c60
PM
67# configfrag_hotplug_cpu config-fragment-file
68#
69# Returns 1 if the config fragment specifies hotplug CPU.
70configfrag_hotplug_cpu () {
4275be83 71 if test ! -r "$1"
c87b9c60 72 then
4275be83 73 echo Unreadable config fragment "$1" 1>&2
c87b9c60
PM
74 exit -1
75 fi
4275be83 76 grep -q '^CONFIG_HOTPLUG_CPU=y$' "$1"
c87b9c60 77}
4f8a0312 78
f189cc8c
PM
79# identify_boot_image qemu-cmd
80#
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.
84identify_boot_image () {
85 if test -n "$TORTURE_BOOT_IMAGE"
86 then
87 echo $TORTURE_BOOT_IMAGE
88 else
89 case "$1" in
90 qemu-system-x86_64|qemu-system-i386)
91 echo arch/x86/boot/bzImage
92 ;;
93 qemu-system-ppc64)
94 echo arch/powerpc/boot/bzImage
95 ;;
96 *)
97 echo ""
98 ;;
99 esac
100 fi
101}
102
4f8a0312
PM
103# identify_qemu builddir
104#
105# Returns our best guess as to which qemu command is appropriate for
250da31e 106# the kernel at hand. Override with the TORTURE_QEMU_CMD environment variable.
4f8a0312
PM
107identify_qemu () {
108 local u="`file "$1"`"
250da31e 109 if test -n "$TORTURE_QEMU_CMD"
4f8a0312 110 then
250da31e 111 echo $TORTURE_QEMU_CMD
4f8a0312
PM
112 elif echo $u | grep -q x86-64
113 then
114 echo qemu-system-x86_64
115 elif echo $u | grep -q "Intel 80386"
116 then
117 echo qemu-system-i386
118 elif uname -a | grep -q ppc64
119 then
120 echo qemu-system-ppc64
121 else
122 echo Cannot figure out what qemu command to use! 1>&2
43e38ab3 123 echo file $1 output: $u
4f8a0312 124 # Usually this will be one of /usr/bin/qemu-system-*
250da31e 125 # Use TORTURE_QEMU_CMD environment variable or appropriate
4f8a0312
PM
126 # argument to top-level script.
127 exit 1
128 fi
129}
315c540d
PM
130
131# identify_qemu_append qemu-cmd
132#
133# Output arguments for the qemu "-append" string based on CPU type
a0edd47c 134# and the TORTURE_QEMU_INTERACTIVE environment variable.
315c540d
PM
135identify_qemu_append () {
136 case "$1" in
137 qemu-system-x86_64|qemu-system-i386)
138 echo noapic selinux=0 initcall_debug debug
139 ;;
140 esac
a0edd47c 141 if test -n "$TORTURE_QEMU_INTERACTIVE"
315c540d
PM
142 then
143 echo root=/dev/sda
144 else
145 echo console=ttyS0
146 fi
147}
148
149# identify_qemu_args qemu-cmd serial-file
150#
58f724f7 151# Output arguments for qemu arguments based on the TORTURE_QEMU_MAC
a0edd47c 152# and TORTURE_QEMU_INTERACTIVE environment variables.
315c540d
PM
153identify_qemu_args () {
154 case "$1" in
155 qemu-system-x86_64|qemu-system-i386)
156 ;;
157 qemu-system-ppc64)
158 echo -enable-kvm -M pseries -cpu POWER7 -nodefaults
159 echo -device spapr-vscsi
58f724f7 160 if test -n "$TORTURE_QEMU_INTERACTIVE" -a -n "$TORTURE_QEMU_MAC"
315c540d 161 then
58f724f7 162 echo -device spapr-vlan,netdev=net0,mac=$TORTURE_QEMU_MAC
315c540d 163 echo -netdev bridge,br=br0,id=net0
a0edd47c 164 elif test -n "$TORTURE_QEMU_INTERACTIVE"
315c540d
PM
165 then
166 echo -net nic -net user
167 fi
168 ;;
169 esac
a0edd47c 170 if test -n "$TORTURE_QEMU_INTERACTIVE"
315c540d
PM
171 then
172 echo -monitor stdio -serial pty -S
173 else
174 echo -serial file:$2
175 fi
176}
177
178# identify_qemu_vcpus
179#
180# Returns the number of virtual CPUs available to the aggregate of the
181# guest OSes.
182identify_qemu_vcpus () {
183 lscpu | grep '^CPU(s):' | sed -e 's/CPU(s)://'
184}
185
6d40cc0c
PM
186# print_bug
187#
188# Prints "BUG: " in red followed by remaining arguments
189print_bug () {
190 printf '\033[031mBUG: \033[m'
191 echo $*
192}
193
194# print_warning
195#
196# Prints "WARNING: " in yellow followed by remaining arguments
197print_warning () {
198 printf '\033[033mWARNING: \033[m'
199 echo $*
200}
201
315c540d
PM
202# specify_qemu_cpus qemu-cmd qemu-args #cpus
203#
204# Appends a string containing "-smp XXX" to qemu-args, unless the incoming
205# qemu-args already contains "-smp".
206specify_qemu_cpus () {
207 local nt;
208
209 if echo $2 | grep -q -e -smp
210 then
211 echo $2
212 else
213 case "$1" in
214 qemu-system-x86_64|qemu-system-i386)
215 echo $2 -smp $3
216 ;;
217 qemu-system-ppc64)
218 nt="`lscpu | grep '^NUMA node0' | sed -e 's/^[^,]*,\([0-9]*\),.*$/\1/'`"
219 echo $2 -smp cores=`expr \( $3 + $nt - 1 \) / $nt`,threads=$nt
220 ;;
221 esac
222 fi
223}
This page took 0.053565 seconds and 5 git commands to generate.