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
53for i in "$@"
54do
55	echo ---- System running test: `uname -a` > $i/kvm-test-1-run-qemu.sh.out
56	echo > $i/kvm-test-1-run-qemu.sh.out
57	kvm-test-1-run-qemu.sh $i >> $i/kvm-test-1-run-qemu.sh.out 2>&1 &
58done
59for i in $runfiles
60do
61	while ls $i > /dev/null 2>&1
62	do
63		:
64	done
65done
66echo ---- All kernel runs complete. `date` | tee -a log
67$TORTURE_JITTER_STOP
68