xref: /linux/tools/testing/selftests/rcutorture/bin/kvm-build.sh (revision 9f2c9170934eace462499ba0bfe042cc72900173)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0+
3#
4# Build a kvm-ready Linux kernel from the tree in the current directory.
5#
6# Usage: kvm-build.sh config-template resdir
7#
8# Copyright (C) IBM Corporation, 2011
9#
10# Authors: Paul E. McKenney <paulmck@linux.ibm.com>
11
12if test -f "$TORTURE_STOPFILE"
13then
14	echo "kvm-build.sh early exit due to run STOP request"
15	exit 1
16fi
17
18config_template=${1}
19if test -z "$config_template" -o ! -f "$config_template" -o ! -r "$config_template"
20then
21	echo "kvm-build.sh :$config_template: Not a readable file"
22	exit 1
23fi
24resdir=${2}
25
26T="`mktemp -d ${TMPDIR-/tmp}/kvm-build.sh.XXXXXX`"
27trap 'rm -rf $T' 0
28
29cp ${config_template} $T/config
30cat << ___EOF___ >> $T/config
31CONFIG_INITRAMFS_SOURCE="$TORTURE_INITRD"
32CONFIG_VIRTIO_PCI=y
33CONFIG_VIRTIO_CONSOLE=y
34___EOF___
35
36configinit.sh $T/config $resdir
37retval=$?
38if test $retval -gt 1
39then
40	exit 2
41fi
42
43# Tell "make" to use double the number of real CPUs on the build system.
44ncpus="`getconf _NPROCESSORS_ONLN`"
45make -j$((2 * ncpus)) $TORTURE_KMAKE_ARG > $resdir/Make.out 2>&1
46retval=$?
47if test $retval -ne 0 || grep "rcu[^/]*": < $resdir/Make.out | egrep -q "Stop|Error|error:|warning:" || egrep -q "Stop|Error|error:" < $resdir/Make.out
48then
49	echo Kernel build error
50	egrep "Stop|Error|error:|warning:" < $resdir/Make.out
51	echo Run aborted.
52	exit 3
53fi
54