1#!/bin/bash
2#
3# Run a series of 14 tests under KVM.  These are not particularly
4# well-selected or well-tuned, but are the current set.  Run from the
5# top level of the source tree.
6#
7# Edit the definitions below to set the locations of the various directories,
8# as well as the test duration.
9#
10# Usage: sh kvm.sh [ options ]
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25#
26# Copyright (C) IBM Corporation, 2011
27#
28# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
29
30scriptname=$0
31args="$*"
32
33dur=30
34KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
35builddir="${KVM}/b1"
36RCU_INITRD="$KVM/initrd"; export RCU_INITRD
37RCU_KMAKE_ARG=""; export RCU_KMAKE_ARG
38resdir=""
39configs=""
40ds=`date +%Y.%m.%d-%H:%M:%S`
41kversion=""
42
43usage () {
44	echo "Usage: $scriptname optional arguments:"
45	echo "       --bootargs kernel-boot-arguments"
46	echo "       --builddir absolute-pathname"
47	echo "       --buildonly"
48	echo "       --configs \"config-file list\""
49	echo "       --datestamp string"
50	echo "       --duration minutes"
51	echo "       --interactive"
52	echo "       --kmake-arg kernel-make-arguments"
53	echo "       --kversion vN.NN"
54	echo "       --mac nn:nn:nn:nn:nn:nn"
55	echo "       --no-initrd"
56	echo "       --qemu-args qemu-system-..."
57	echo "       --qemu-cmd qemu-system-..."
58	echo "       --results absolute-pathname"
59	echo "       --relbuilddir relative-pathname"
60	exit 1
61}
62
63# checkarg --argname argtype $# arg mustmatch cannotmatch
64checkarg () {
65	if test $3 -le 1
66	then
67		echo $1 needs argument $2 matching \"$5\"
68		usage
69	fi
70	if echo "$4" | grep -q -e "$5"
71	then
72		:
73	else
74		echo $1 $2 \"$4\" must match \"$5\"
75		usage
76	fi
77	if echo "$4" | grep -q -e "$6"
78	then
79		echo $1 $2 \"$4\" must not match \"$6\"
80		usage
81	fi
82}
83
84while test $# -gt 0
85do
86	case "$1" in
87	--bootargs)
88		checkarg --bootargs "(list of kernel boot arguments)" "$#" "$2" '.*' '^--'
89		RCU_BOOTARGS="$2"
90		shift
91		;;
92	--builddir)
93		checkarg --builddir "(absolute pathname)" "$#" "$2" '^/' '^error'
94		builddir=$2
95		gotbuilddir=1
96		shift
97		;;
98	--buildonly)
99		RCU_BUILDONLY=1; export RCU_BUILDONLY
100		;;
101	--configs)
102		checkarg --configs "(list of config files)" "$#" "$2" '^[^/]*$' '^--'
103		configs="$2"
104		shift
105		;;
106	--datestamp)
107		checkarg --datestamp "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
108		ds=$2
109		shift
110		;;
111	--duration)
112		checkarg --duration "(minutes)" $# "$2" '^[0-9]*$' '^error'
113		dur=$2
114		shift
115		;;
116	--interactive)
117		RCU_QEMU_INTERACTIVE=1; export RCU_QEMU_INTERACTIVE
118		;;
119	--kmake-arg)
120		checkarg --kmake-arg "(kernel make arguments)" $# "$2" '.*' '^error$'
121		RCU_KMAKE_ARG="$2"; export RCU_KMAKE_ARG
122		shift
123		;;
124	--kversion)
125		checkarg --kversion "(kernel version)" $# "$2" '^v[0-9.]*$' '^error'
126		kversion=$2
127		shift
128		;;
129	--mac)
130		checkarg --mac "(MAC address)" $# "$2" '^\([0-9a-fA-F]\{2\}:\)\{5\}[0-9a-fA-F]\{2\}$' error
131		RCU_QEMU_MAC=$2; export RCU_QEMU_MAC
132		shift
133		;;
134	--no-initrd)
135		RCU_INITRD=""; export RCU_INITRD
136		;;
137	--qemu-args)
138		checkarg --qemu-args "-qemu args" $# "$2" '^-' '^error'
139		RCU_QEMU_ARG="$2"
140		shift
141		;;
142	--qemu-cmd)
143		checkarg --qemu-cmd "(qemu-system-...)" $# "$2" 'qemu-system-' '^--'
144		RCU_QEMU_CMD="$2"; export RCU_QEMU_CMD
145		shift
146		;;
147	--relbuilddir)
148		checkarg --relbuilddir "(relative pathname)" "$#" "$2" '^[^/]*$' '^--'
149		relbuilddir=$2
150		gotrelbuilddir=1
151		builddir=${KVM}/${relbuilddir}
152		shift
153		;;
154	--results)
155		checkarg --results "(absolute pathname)" "$#" "$2" '^/' '^error'
156		resdir=$2
157		shift
158		;;
159	*)
160		echo Unknown argument $1
161		usage
162		;;
163	esac
164	shift
165done
166
167PATH=${KVM}/bin:$PATH; export PATH
168CONFIGFRAG=${KVM}/configs; export CONFIGFRAG
169KVPATH=${CONFIGFRAG}/$kversion; export KVPATH
170
171if test -z "$configs"
172then
173	configs="`cat $CONFIGFRAG/$kversion/CFLIST`"
174fi
175
176if test -z "$resdir"
177then
178	resdir=$KVM/res
179	if ! test -e $resdir
180	then
181		mkdir $resdir || :
182	fi
183else
184	if ! test -e $resdir
185	then
186		mkdir -p "$resdir" || :
187	fi
188fi
189mkdir $resdir/$ds
190touch $resdir/$ds/log
191echo $scriptname $args >> $resdir/$ds/log
192
193pwd > $resdir/$ds/testid.txt
194if test -d .git
195then
196	git status >> $resdir/$ds/testid.txt
197	git rev-parse HEAD >> $resdir/$ds/testid.txt
198fi
199builddir=$KVM/b1
200if ! test -e $builddir
201then
202	mkdir $builddir || :
203fi
204
205for CF in $configs
206do
207	rd=$resdir/$ds/$CF
208	mkdir $rd || :
209	echo Results directory: $rd
210	kvm-test-1-rcu.sh $CONFIGFRAG/$kversion/$CF $builddir $rd $dur "-nographic $RCU_QEMU_ARG" "rcutorture.test_no_idle_hz=1 rcutorture.verbose=1 $RCU_BOOTARGS"
211done
212# Tracing: trace_event=rcu:rcu_nocb_grace_period,rcu:rcu_grace_period,rcu:rcu_grace_period_init,rcu:rcu_quiescent_state_report,rcu:rcu_fqs,rcu:rcu_callback,rcu:rcu_torture_read,rcu:rcu_invoke_callback,rcu:rcu_fqs,rcu:rcu_dyntick,rcu:rcu_unlock_preempted_task
213