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
15perfect=0
16obsline=0
17noobsline=0
18obsresult=0
19badcompare=0
20comparetest () {
21	grep -v 'maxresident)k\|minor)pagefaults\|^Time' $1 > $T/oldout
22	grep -v 'maxresident)k\|minor)pagefaults\|^Time' $2 > $T/newout
23	if cmp -s $T/oldout $T/newout && grep -q '^Observation' $1
24	then
25		echo Exact output match: $2
26		perfect=`expr "$perfect" + 1`
27		return 0
28	fi
29
30	grep '^Observation' $1 > $T/oldout
31	grep '^Observation' $2 > $T/newout
32	if test -s $T/oldout -o -s $T/newout
33	then
34		if cmp -s $T/oldout $T/newout
35		then
36			echo Matching Observation result and counts: $2
37			obsline=`expr "$obsline" + 1`
38			return 0
39		fi
40	else
41		echo Missing Observation line "(e.g., herd7 timeout)": $2
42		noobsline=`expr "$noobsline" + 1`
43		return 0
44	fi
45
46	grep '^Observation' $1 | awk '{ print $3 }' > $T/oldout
47	grep '^Observation' $2 | awk '{ print $3 }' > $T/newout
48	if cmp -s $T/oldout $T/newout
49	then
50		echo Matching Observation Always/Sometimes/Never result: $2
51		obsresult=`expr "$obsresult" + 1`
52		return 0
53	fi
54	echo ' !!!' Result changed: $2
55	badcompare=`expr "$badcompare" + 1`
56	return 1
57}
58
59sed -e 's/^.*$/comparetest &.out &.out.new/' > $T/cmpscript
60. $T/cmpscript > $T/cmpscript.out
61cat $T/cmpscript.out
62
63echo ' ---' Summary: 1>&2
64grep '!!!' $T/cmpscript.out 1>&2
65if test "$perfect" -ne 0
66then
67	echo Exact output matches: $perfect 1>&2
68fi
69if test "$obsline" -ne 0
70then
71	echo Matching Observation result and counts: $obsline 1>&2
72fi
73if test "$noobsline" -ne 0
74then
75	echo Missing Observation line "(e.g., herd7 timeout)": $noobsline 1>&2
76fi
77if test "$obsresult" -ne 0
78then
79	echo Matching Observation Always/Sometimes/Never result: $obsresult 1>&2
80fi
81if test "$badcompare" -ne 0
82then
83	echo "!!!" Result changed: $badcompare 1>&2
84	exit 1
85fi
86
87exit 0
88