checklitmus.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/sh
  2. #
  3. # Run a herd test and check the result against a "Result:" comment within
  4. # the litmus test. If the verification result does not match that specified
  5. # in the litmus test, this script prints an error message prefixed with
  6. # "^^^" and exits with a non-zero status. It also outputs verification
  7. # results to a file whose name is that of the specified litmus test, but
  8. # with ".out" appended.
  9. #
  10. # Usage:
  11. # checklitmus.sh file.litmus
  12. #
  13. # The LINUX_HERD_OPTIONS environment variable may be used to specify
  14. # arguments to herd, which default to "-conf linux-kernel.cfg". Thus,
  15. # one would normally run this in the directory containing the memory model,
  16. # specifying the pathname of the litmus test to check.
  17. #
  18. # This program is free software; you can redistribute it and/or modify
  19. # it under the terms of the GNU General Public License as published by
  20. # the Free Software Foundation; either version 2 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU General Public License
  29. # along with this program; if not, you can access it online at
  30. # http://www.gnu.org/licenses/gpl-2.0.html.
  31. #
  32. # Copyright IBM Corporation, 2018
  33. #
  34. # Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  35. litmus=$1
  36. herdoptions=${LINUX_HERD_OPTIONS--conf linux-kernel.cfg}
  37. if test -f "$litmus" -a -r "$litmus"
  38. then
  39. :
  40. else
  41. echo ' --- ' error: \"$litmus\" is not a readable file
  42. exit 255
  43. fi
  44. if grep -q '^ \* Result: ' $litmus
  45. then
  46. outcome=`grep -m 1 '^ \* Result: ' $litmus | awk '{ print $3 }'`
  47. else
  48. outcome=specified
  49. fi
  50. echo Herd options: $herdoptions > $litmus.out
  51. /usr/bin/time herd7 -o ~/tmp $herdoptions $litmus >> $litmus.out 2>&1
  52. grep "Herd options:" $litmus.out
  53. grep '^Observation' $litmus.out
  54. if grep -q '^Observation' $litmus.out
  55. then
  56. :
  57. else
  58. cat $litmus.out
  59. echo ' ^^^ Verification error'
  60. echo ' ^^^ Verification error' >> $litmus.out 2>&1
  61. exit 255
  62. fi
  63. if test "$outcome" = DEADLOCK
  64. then
  65. echo grep 3 and 4
  66. if grep '^Observation' $litmus.out | grep -q 'Never 0 0$'
  67. then
  68. ret=0
  69. else
  70. echo " ^^^ Unexpected non-$outcome verification"
  71. echo " ^^^ Unexpected non-$outcome verification" >> $litmus.out 2>&1
  72. ret=1
  73. fi
  74. elif grep '^Observation' $litmus.out | grep -q $outcome || test "$outcome" = Maybe
  75. then
  76. ret=0
  77. else
  78. echo " ^^^ Unexpected non-$outcome verification"
  79. echo " ^^^ Unexpected non-$outcome verification" >> $litmus.out 2>&1
  80. ret=1
  81. fi
  82. tail -2 $litmus.out | head -1
  83. exit $ret