b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 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 | |
| 10 | T=/tmp/cmplitmushist.sh.$$ |
| 11 | trap 'rm -rf $T' 0 |
| 12 | mkdir $T |
| 13 | |
| 14 | # comparetest oldpath newpath |
| 15 | perfect=0 |
| 16 | obsline=0 |
| 17 | noobsline=0 |
| 18 | obsresult=0 |
| 19 | badcompare=0 |
| 20 | comparetest () { |
| 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 | |
| 59 | sed -e 's/^.*$/comparetest &.out &.out.new/' > $T/cmpscript |
| 60 | . $T/cmpscript > $T/cmpscript.out |
| 61 | cat $T/cmpscript.out |
| 62 | |
| 63 | echo ' ---' Summary: 1>&2 |
| 64 | grep '!!!' $T/cmpscript.out 1>&2 |
| 65 | if test "$perfect" -ne 0 |
| 66 | then |
| 67 | echo Exact output matches: $perfect 1>&2 |
| 68 | fi |
| 69 | if test "$obsline" -ne 0 |
| 70 | then |
| 71 | echo Matching Observation result and counts: $obsline 1>&2 |
| 72 | fi |
| 73 | if test "$noobsline" -ne 0 |
| 74 | then |
| 75 | echo Missing Observation line "(e.g., herd7 timeout)": $noobsline 1>&2 |
| 76 | fi |
| 77 | if test "$obsresult" -ne 0 |
| 78 | then |
| 79 | echo Matching Observation Always/Sometimes/Never result: $obsresult 1>&2 |
| 80 | fi |
| 81 | if test "$badcompare" -ne 0 |
| 82 | then |
| 83 | echo "!!!" Result changed: $badcompare 1>&2 |
| 84 | exit 1 |
| 85 | fi |
| 86 | |
| 87 | exit 0 |