1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0+
3#
4# Given the results directories for previous KVM-based torture runs,
5# check the build and console output for errors.  Given a directory
6# containing results directories, this recursively checks them all.
7#
8# Usage: kvm-recheck.sh resdir ...
9#
10# Returns status reflecting the success or not of the last run specified.
11#
12# Copyright (C) IBM Corporation, 2011
13#
14# Authors: Paul E. McKenney <paulmck@linux.ibm.com>
15
16T=/tmp/kvm-recheck.sh.$$
17trap 'rm -f $T' 0 2
18
19PATH=`pwd`/tools/testing/selftests/rcutorture/bin:$PATH; export PATH
20. functions.sh
21for rd in "$@"
22do
23	firsttime=1
24	dirs=`find $rd -name Make.defconfig.out -print | sort | sed -e 's,/[^/]*$,,' | sort -u`
25	for i in $dirs
26	do
27		if test -n "$firsttime"
28		then
29			firsttime=""
30			resdir=`echo $i | sed -e 's,/$,,' -e 's,/[^/]*$,,'`
31			head -1 $resdir/log
32		fi
33		TORTURE_SUITE="`cat $i/../torture_suite`"
34		configfile=`echo $i | sed -e 's,^.*/,,'`
35		rm -f $i/console.log.*.diags
36		kvm-recheck-${TORTURE_SUITE}.sh $i
37		if test -f "$i/qemu-retval" && test "`cat $i/qemu-retval`" -ne 0 && test "`cat $i/qemu-retval`" -ne 137
38		then
39			echo QEMU error, output:
40			cat $i/qemu-output
41		elif test -f "$i/console.log"
42		then
43			if test -f "$i/qemu-retval" && test "`cat $i/qemu-retval`" -eq 137
44			then
45				echo QEMU killed
46			fi
47			configcheck.sh $i/.config $i/ConfigFragment > $T 2>&1
48			cat $T
49			if test -r $i/Make.oldconfig.err
50			then
51				cat $i/Make.oldconfig.err
52			fi
53			parse-build.sh $i/Make.out $configfile
54			parse-console.sh $i/console.log $configfile
55			if test -r $i/Warnings
56			then
57				cat $i/Warnings
58			fi
59		else
60			if test -f "$i/buildonly"
61			then
62				echo Build-only run, no boot/test
63				configcheck.sh $i/.config $i/ConfigFragment
64				parse-build.sh $i/Make.out $configfile
65			elif test -f "$i/qemu-cmd"
66			then
67				print_bug qemu failed
68				echo "   $i"
69			else
70				print_bug Build failed
71				echo "   $i"
72			fi
73		fi
74	done
75	if test -f "$rd/kcsan.sum"
76	then
77		if ! test -f $T
78		then
79			:
80		elif grep -q CONFIG_KCSAN=y $T
81		then
82			echo "Compiler or architecture does not support KCSAN!"
83			echo Did you forget to switch your compiler with '--kmake-arg CC=<cc-that-supports-kcsan>'?
84		elif test -s "$rd/kcsan.sum"
85		then
86			echo KCSAN summary in $rd/kcsan.sum
87		else
88			echo Clean KCSAN run in $rd
89		fi
90	fi
91done
92EDITOR=echo kvm-find-errors.sh "${@: -1}" > $T 2>&1
93builderrors="`tr ' ' '\012' < $T | grep -c '/Make.out.diags'`"
94if test "$builderrors" -gt 0
95then
96	echo $builderrors runs with build errors.
97	ret=1
98fi
99runerrors="`tr ' ' '\012' < $T | grep -c '/console.log.diags'`"
100if test "$runerrors" -gt 0
101then
102	echo $runerrors runs with runtime errors.
103	ret=2
104fi
105exit $ret
106