xref: /linux/tools/testing/selftests/rcutorture/bin/kvm-test-1-run-batch.sh (revision a4eb44a6435d6d8f9e642407a4a06f65eb90ca04)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0+
3#
4# Carry out a kvm-based run for the specified batch of scenarios, which
5# might have been built by --build-only kvm.sh run.
6#
7# Usage: kvm-test-1-run-batch.sh SCENARIO [ SCENARIO ... ]
8#
9# Each SCENARIO is the name of a directory in the current directory
10#	containing a ready-to-run qemu-cmd file.
11#
12# Copyright (C) 2021 Facebook, Inc.
13#
14# Authors: Paul E. McKenney <paulmck@kernel.org>
15
16T=${TMPDIR-/tmp}/kvm-test-1-run-batch.sh.$$
17trap 'rm -rf $T' 0
18mkdir $T
19
20echo ---- Running batch $*
21# Check arguments
22runfiles=
23for i in "$@"
24do
25	if ! echo $i | grep -q '^[^/.a-z]\+\(\.[0-9]\+\)\?$'
26	then
27		echo Bad scenario name: \"$i\" 1>&2
28		exit 1
29	fi
30	if ! test -d "$i"
31	then
32		echo Scenario name not a directory: \"$i\" 1>&2
33		exit 2
34	fi
35	if ! test -f "$i/qemu-cmd"
36	then
37		echo Scenario lacks a command file: \"$i/qemu-cmd\" 1>&2
38		exit 3
39	fi
40	rm -f $i/build.*
41	touch $i/build.run
42	runfiles="$runfiles $i/build.run"
43done
44
45# Extract settings from the qemu-cmd file.
46grep '^#' $1/qemu-cmd | sed -e 's/^# //' > $T/qemu-cmd-settings
47. $T/qemu-cmd-settings
48
49# Start up jitter, start each scenario, wait, end jitter.
50echo ---- System running test: `uname -a`
51echo ---- Starting kernels. `date` | tee -a log
52$TORTURE_JITTER_START
53kvm-assign-cpus.sh /sys/devices/system/node > $T/cpuarray.awk
54for i in "$@"
55do
56	echo ---- System running test: `uname -a` > $i/kvm-test-1-run-qemu.sh.out
57	echo > $i/kvm-test-1-run-qemu.sh.out
58	export TORTURE_AFFINITY=
59	kvm-get-cpus-script.sh $T/cpuarray.awk $T/cpubatches.awk $T/cpustate
60	cat << '	___EOF___' >> $T/cpubatches.awk
61	END {
62		affinitylist = "";
63		if (!gotcpus()) {
64			print "echo No CPU-affinity information, so no taskset command.";
65		} else if (cpu_count !~ /^[0-9][0-9]*$/) {
66			print "echo " scenario ": Bogus number of CPUs (old qemu-cmd?), so no taskset command.";
67		} else {
68			affinitylist = nextcpus(cpu_count);
69			if (!(affinitylist ~ /^[0-9,-][0-9,-]*$/))
70				print "echo " scenario ": Bogus CPU-affinity information, so no taskset command.";
71			else if (!dumpcpustate())
72				print "echo " scenario ": Could not dump state, so no taskset command.";
73			else
74				print "export TORTURE_AFFINITY=" affinitylist;
75		}
76	}
77	___EOF___
78	cpu_count="`grep '# TORTURE_CPU_COUNT=' $i/qemu-cmd | sed -e 's/^.*=//'`"
79	affinity_export="`awk -f $T/cpubatches.awk -v cpu_count="$cpu_count" -v scenario=$i < /dev/null`"
80	$affinity_export
81	kvm-test-1-run-qemu.sh $i >> $i/kvm-test-1-run-qemu.sh.out 2>&1 &
82done
83for i in $runfiles
84do
85	while ls $i > /dev/null 2>&1
86	do
87		:
88	done
89done
90echo ---- All kernel runs complete. `date` | tee -a log
91$TORTURE_JITTER_STOP
92