xref: /linux/tools/memory-model/scripts/cmplitmushist.sh (revision 8e07e0e3964ca4e23ce7b68e2096fe660a888942)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0+
3#
4# Compares .out and .out.new files for each name on standard input,
5# one full pathname per line.  Outputs comparison results followed by
6# a summary.
7#
8# sh cmplitmushist.sh
9
10T=/tmp/cmplitmushist.sh.$$
11trap 'rm -rf $T' 0
12mkdir $T
13
14# comparetest oldpath newpath
15badmacnam=0
16timedout=0
17perfect=0
18obsline=0
19noobsline=0
20obsresult=0
21badcompare=0
22comparetest () {
23	if grep -q ': Unknown macro ' $1 || grep -q ': Unknown macro ' $2
24	then
25		if grep -q ': Unknown macro ' $1
26		then
27			badname=`grep ': Unknown macro ' $1 |
28				sed -e 's/^.*: Unknown macro //' |
29				sed -e 's/ (User error).*$//'`
30			echo 'Current LKMM version does not know "'$badname'"' $1
31		fi
32		if grep -q ': Unknown macro ' $2
33		then
34			badname=`grep ': Unknown macro ' $2 |
35				sed -e 's/^.*: Unknown macro //' |
36				sed -e 's/ (User error).*$//'`
37			echo 'Current LKMM version does not know "'$badname'"' $2
38		fi
39		badmacnam=`expr "$badmacnam" + 1`
40		return 0
41	elif grep -q '^Command exited with non-zero status 124' $1 ||
42	     grep -q '^Command exited with non-zero status 124' $2
43	then
44		if grep -q '^Command exited with non-zero status 124' $1 &&
45		   grep -q '^Command exited with non-zero status 124' $2
46		then
47			echo Both runs timed out: $2
48		elif grep -q '^Command exited with non-zero status 124' $1
49		then
50			echo Old run timed out: $2
51		elif grep -q '^Command exited with non-zero status 124' $2
52		then
53			echo New run timed out: $2
54		fi
55		timedout=`expr "$timedout" + 1`
56		return 0
57	fi
58	grep -v 'maxresident)k\|minor)pagefaults\|^Time' $1 > $T/oldout
59	grep -v 'maxresident)k\|minor)pagefaults\|^Time' $2 > $T/newout
60	if cmp -s $T/oldout $T/newout && grep -q '^Observation' $1
61	then
62		echo Exact output match: $2
63		perfect=`expr "$perfect" + 1`
64		return 0
65	fi
66
67	grep '^Observation' $1 > $T/oldout
68	grep '^Observation' $2 > $T/newout
69	if test -s $T/oldout -o -s $T/newout
70	then
71		if cmp -s $T/oldout $T/newout
72		then
73			echo Matching Observation result and counts: $2
74			obsline=`expr "$obsline" + 1`
75			return 0
76		fi
77	else
78		echo Missing Observation line "(e.g., syntax error)": $2
79		noobsline=`expr "$noobsline" + 1`
80		return 0
81	fi
82
83	grep '^Observation' $1 | awk '{ print $3 }' > $T/oldout
84	grep '^Observation' $2 | awk '{ print $3 }' > $T/newout
85	if cmp -s $T/oldout $T/newout
86	then
87		echo Matching Observation Always/Sometimes/Never result: $2
88		obsresult=`expr "$obsresult" + 1`
89		return 0
90	fi
91	echo ' !!!' Result changed: $2
92	badcompare=`expr "$badcompare" + 1`
93	return 1
94}
95
96sed -e 's/^.*$/comparetest &.out &.out.new/' > $T/cmpscript
97. $T/cmpscript > $T/cmpscript.out
98cat $T/cmpscript.out
99
100echo ' ---' Summary: 1>&2
101grep '!!!' $T/cmpscript.out 1>&2
102if test "$perfect" -ne 0
103then
104	echo Exact output matches: $perfect 1>&2
105fi
106if test "$obsline" -ne 0
107then
108	echo Matching Observation result and counts: $obsline 1>&2
109fi
110if test "$noobsline" -ne 0
111then
112	echo Missing Observation line "(e.g., syntax error)": $noobsline 1>&2
113fi
114if test "$obsresult" -ne 0
115then
116	echo Matching Observation Always/Sometimes/Never result: $obsresult 1>&2
117fi
118if test "$timedout" -ne 0
119then
120	echo "!!!" Timed out: $timedout 1>&2
121fi
122if test "$badmacnam" -ne 0
123then
124	echo "!!!" Unknown primitive: $badmacnam 1>&2
125fi
126if test "$badcompare" -ne 0
127then
128	echo "!!!" Result changed: $badcompare 1>&2
129	exit 1
130fi
131
132exit 0
133