^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/bin/sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # Compares .out and .out.new files for each name on standard input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) # one full pathname per line. Outputs comparison results followed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) # a summary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) # sh cmplitmushist.sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) T=/tmp/cmplitmushist.sh.$$
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) trap 'rm -rf $T' 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) mkdir $T
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) # comparetest oldpath newpath
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) perfect=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) obsline=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) noobsline=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) obsresult=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) badcompare=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) comparetest () {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) grep -v 'maxresident)k\|minor)pagefaults\|^Time' $1 > $T/oldout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) grep -v 'maxresident)k\|minor)pagefaults\|^Time' $2 > $T/newout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) if cmp -s $T/oldout $T/newout && grep -q '^Observation' $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) echo Exact output match: $2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) perfect=`expr "$perfect" + 1`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) grep '^Observation' $1 > $T/oldout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) grep '^Observation' $2 > $T/newout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if test -s $T/oldout -o -s $T/newout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if cmp -s $T/oldout $T/newout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) echo Matching Observation result and counts: $2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) obsline=`expr "$obsline" + 1`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) echo Missing Observation line "(e.g., herd7 timeout)": $2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) noobsline=`expr "$noobsline" + 1`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) grep '^Observation' $1 | awk '{ print $3 }' > $T/oldout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) grep '^Observation' $2 | awk '{ print $3 }' > $T/newout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if cmp -s $T/oldout $T/newout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) echo Matching Observation Always/Sometimes/Never result: $2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) obsresult=`expr "$obsresult" + 1`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) echo ' !!!' Result changed: $2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) badcompare=`expr "$badcompare" + 1`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) sed -e 's/^.*$/comparetest &.out &.out.new/' > $T/cmpscript
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) . $T/cmpscript > $T/cmpscript.out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) cat $T/cmpscript.out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) echo ' ---' Summary: 1>&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) grep '!!!' $T/cmpscript.out 1>&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if test "$perfect" -ne 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) echo Exact output matches: $perfect 1>&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if test "$obsline" -ne 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) echo Matching Observation result and counts: $obsline 1>&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if test "$noobsline" -ne 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) echo Missing Observation line "(e.g., herd7 timeout)": $noobsline 1>&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if test "$obsresult" -ne 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) echo Matching Observation Always/Sometimes/Never result: $obsresult 1>&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if test "$badcompare" -ne 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) echo "!!!" Result changed: $badcompare 1>&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) exit 0