aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/rcutorture/bin/kvm-transform.sh
blob: c45a953ef39319b3bff9162f37b16d07118d3863 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0+
#
# Transform a qemu-cmd file to allow reuse.
#
# Usage: kvm-transform.sh bzImage console.log < qemu-cmd-in > qemu-cmd-out
#
#	bzImage: Kernel and initrd from the same prior kvm.sh run.
#	console.log: File into which to place console output.
#
# The original qemu-cmd file is provided on standard input.
# The transformed qemu-cmd file is on standard output.
# The transformation assumes that the qemu command is confined to a
# single line.  It also assumes no whitespace in filenames.
#
# Copyright (C) 2020 Facebook, Inc.
#
# Authors: Paul E. McKenney <paulmck@kernel.org>

image="$1"
if test -z "$image"
then
	echo Need kernel image file.
	exit 1
fi
consolelog="$2"
if test -z "$consolelog"
then
	echo "Need console log file name."
	exit 1
fi

awk -v image="$image" -v consolelog="$consolelog" '
{
	line = "";
	for (i = 1; i <= NF; i++) {
		if (line == "")
			line = $i;
		else
			line = line " " $i;
		if ($i == "-serial") {
			i++;
			line = line " file:" consolelog;
		}
		if ($i == "-kernel") {
			i++;
			line = line " " image;
		}
	}
	print line;
}'