cmplitmushist.sh 2.0 KB

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