1#!/bin/bash
2# simple test harness for mcelog daemon trigger test cases
3# ./test subdir [debugger]
4# run mcelog test in specific sub directory
5# requires root rights and a built mce-inject in ../../mce-inject or $PATH
6# warning: this kills any other running mcelogs
7
8D=${2:-}
9
10if [ "$1" = "" ] ; then
11	echo "usage $0 testdir"
12	exit 1
13fi
14
15if [ "$(whoami)" != "root" ] ; then
16	echo "Must run as root"
17	exit 1
18fi
19
20[ ! -f /dev/mce-inject ] && modprobe mce-inject
21
22echo "++++++++++++ running $1 test +++++++++++++++++++"
23
24# disable trigger
25echo -n "" > /sys/devices/system/machinecheck/machinecheck0/trigger
26killall mcelog || true
27
28#killwatchdog() {
29#	kill %1 || true
30#}
31#
32#watchdog() {
33#	sleep 10
34#	echo timeout waiting for mcelog
35#	killall mcelog
36#}
37
38cd $1
39
40#trap killwatchdog 0
41#watchdog &
42rm -f *.log
43rm -f results
44for conf in `ls *.conf`
45do
46	log=`echo $conf | sed "s/conf/log/g"`
47	# Inject mce records and run mcelog in parallel.
48	# So that the mce records can be consumed by mcelog in time (avoid mce record overflow).
49	./inject $conf &
50	if [ "$1" = "pfa" ] ; then
51		which page-types > /dev/null 2>&1 || continue
52	fi
53	$D ../../mcelog --foreground --daemon --debug-numerrors --config $conf --logfile $log >> result
54
55	# let triggers finish
56	sleep 1
57
58	NUMT="$(awk '/# trigger: / { print $3 }' $conf)"
59	NUMC="$(grep -c 'Running trigger' $log || true)"
60
61	if [ "$NUMT" != 0 ] ; then
62		if [ "$NUMC" = 0 ] ; then
63			echo "$conf: no triggers at all" >> results
64		fi
65	fi
66
67	if [ "$NUMT" != "" ] ; then
68		if [ "$NUMC" != "$NUMT" ] ; then
69			echo "$conf: triggers did not trigger as expected: expected $NUMT, got $NUMC" >> results
70		else
71			echo "$conf: triggers trigger as expected" >> results
72		fi
73	else
74		echo "$conf: did not declare number of triggers" >> results
75	fi
76done
77#trap "" 0
78#killwatchdog
79
80