runlitmushist.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0+
  3. #
  4. # Runs the C-language litmus tests specified on standard input, using up
  5. # to the specified number of CPUs (defaulting to all of them) and placing
  6. # the results in the specified directory (defaulting to the same place
  7. # the litmus test came from).
  8. #
  9. # sh runlitmushist.sh
  10. #
  11. # Run from the Linux kernel tools/memory-model directory.
  12. # This script uses environment variables produced by parseargs.sh.
  13. #
  14. # Copyright IBM Corporation, 2018
  15. #
  16. # Author: Paul E. McKenney <[email protected]>
  17. T=/tmp/runlitmushist.sh.$$
  18. trap 'rm -rf $T' 0
  19. mkdir $T
  20. if test -d litmus
  21. then
  22. :
  23. else
  24. echo Directory \"litmus\" missing, aborting run.
  25. exit 1
  26. fi
  27. # Prefixes for per-CPU scripts
  28. for ((i=0;i<$LKMM_JOBS;i++))
  29. do
  30. echo dir="$LKMM_DESTDIR" > $T/$i.sh
  31. echo T=$T >> $T/$i.sh
  32. echo herdoptions=\"$LKMM_HERD_OPTIONS\" >> $T/$i.sh
  33. cat << '___EOF___' >> $T/$i.sh
  34. runtest () {
  35. echo ' ... ' /usr/bin/time $LKMM_TIMEOUT_CMD herd7 $herdoptions $1 '>' $dir/$1.out '2>&1'
  36. if /usr/bin/time $LKMM_TIMEOUT_CMD herd7 $herdoptions $1 > $dir/$1.out 2>&1
  37. then
  38. if ! grep -q '^Observation ' $dir/$1.out
  39. then
  40. echo ' !!! Herd failed, no Observation:' $1
  41. fi
  42. else
  43. exitcode=$?
  44. if test "$exitcode" -eq 124
  45. then
  46. exitmsg="timed out"
  47. else
  48. exitmsg="failed, exit code $exitcode"
  49. fi
  50. echo ' !!! Herd' ${exitmsg}: $1
  51. fi
  52. }
  53. ___EOF___
  54. done
  55. awk -v q="'" -v b='\\' '
  56. {
  57. print "echo `grep " q "^P[0-9]" b "+(" q " " $0 " | tail -1 | sed -e " q "s/^P" b "([0-9]" b "+" b ")(.*$/" b "1/" q "` " $0
  58. }' | bash |
  59. sort -k1n |
  60. awk -v ncpu=$LKMM_JOBS -v t=$T '
  61. {
  62. print "runtest " $2 >> t "/" NR % ncpu ".sh";
  63. }
  64. END {
  65. for (i = 0; i < ncpu; i++) {
  66. print "sh " t "/" i ".sh > " t "/" i ".sh.out 2>&1 &";
  67. close(t "/" i ".sh");
  68. }
  69. print "wait";
  70. }' | sh
  71. cat $T/*.sh.out
  72. if grep -q '!!!' $T/*.sh.out
  73. then
  74. echo ' ---' Summary: 1>&2
  75. grep '!!!' $T/*.sh.out 1>&2
  76. nfail="`grep '!!!' $T/*.sh.out | wc -l`"
  77. echo 'Number of failed herd7 runs (e.g., timeout): ' $nfail 1>&2
  78. exit 1
  79. else
  80. echo All runs completed successfully. 1>&2
  81. exit 0
  82. fi