1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0+
3#
4# Invoke a text editor on all console.log files for all runs with diagnostics,
5# that is, on all such files having a console.log.diags counterpart.
6# Note that both console.log.diags and console.log are passed to the
7# editor (currently defaulting to "vi"), allowing the user to get an
8# idea of what to search for in the console.log file.
9#
10# Usage: kvm-find-errors.sh directory
11#
12# The "directory" above should end with the date/time directory, for example,
13# "tools/testing/selftests/rcutorture/res/2018.02.25-14:27:27".
14# Returns error status reflecting the success (or not) of the specified run.
15#
16# Copyright (C) IBM Corporation, 2018
17#
18# Author: Paul E. McKenney <paulmck@linux.ibm.com>
19
20rundir="${1}"
21if test -z "$rundir" -o ! -d "$rundir"
22then
23	echo Directory "$rundir" not found.
24	echo Usage: $0 directory
25	exit 1
26fi
27editor=${EDITOR-vi}
28
29# Find builds with errors
30files=
31for i in ${rundir}/*/Make.out
32do
33	if egrep -q "error:|warning:" < $i
34	then
35		egrep "error:|warning:" < $i > $i.diags
36		files="$files $i.diags $i"
37	fi
38done
39if test -n "$files"
40then
41	$editor $files
42	editorret=1
43else
44	echo No build errors.
45fi
46if grep -q -e "--buildonly" < ${rundir}/log
47then
48	echo Build-only run, no console logs to check.
49	exit $editorret
50fi
51
52# Find console logs with errors
53files=
54for i in ${rundir}/*/console.log
55do
56	if test -r $i.diags
57	then
58		files="$files $i.diags $i"
59	fi
60done
61if test -n "$files"
62then
63	$editor $files
64	exit 1
65else
66	echo No errors in console logs.
67	if test -n "$editorret"
68	then
69		exit $editorret
70	else
71		exit 0
72	fi
73fi
74