run_compile_tests.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/bash
  2. # Build and run the direct compiler harness (tests/CompileTest.mod).
  3. #
  4. # Same two-phase ISO link recipe as tpshell: a single monolithic invocation
  5. # trips gm2's pass-3 rollup on a compiler-size program, so generate the module
  6. # list first (-fgen-module-list -> /dev/null, rc=1 is expected) and then link
  7. # with -fuse-list.
  8. set -u
  9. D=/home/eric/Projets/Projets-Modula2/MyWork/TP3-comp/shell
  10. GM2=/home/eric/bin/Modula2/Gm2/bin/gm2
  11. cd "$D" || exit 9
  12. FLAGS="-fiso"
  13. if [ ! -f TextBuf.o ] || [ ! -f Compiler.o ] || [ ! -f Posix.o ] \
  14. || [ ! -f Runtime.o ] \
  15. || [ TextBuf.mod -nt TextBuf.o ] || [ Compiler.mod -nt Compiler.o ] \
  16. || [ Runtime.mod -nt Runtime.o ] || [ Runtime.def -nt Runtime.o ] \
  17. || [ Compiler.def -nt Compiler.o ] \
  18. || [ Posix.c -nt Posix.o ] || [ Posix.def -nt Posix.o ]; then
  19. echo "building support modules (source newer than object)..."
  20. # Runtime is listed because Compiler now links against it: the blob is
  21. # copied into the code buffer and the TU_* offsets come from it. A
  22. # `make clean` (or a fresh checkout) removes every .o, so the C module has
  23. # to be built here too - it used to be assumed present, which made the
  24. # script fail with "cannot find Posix.o" after any clean.
  25. if [ ! -f Posix.o ] || [ Posix.c -nt Posix.o ] || [ Posix.def -nt Posix.o ]; then
  26. cc -c Posix.c >/tmp/ct_c_Posix 2>&1 \
  27. || { echo "COMPILE_FAIL Posix"; grep -m5 "error:" /tmp/ct_c_Posix; exit 1; }
  28. fi
  29. for m in TextBuf Compiler Runtime; do
  30. $GM2 $FLAGS -c $m.mod >/tmp/ct_c_$m 2>&1
  31. if [ $? -ne 0 ]; then
  32. echo "COMPILE_FAIL $m"
  33. grep -m5 -E "error:|Please submit" /tmp/ct_c_$m
  34. exit 1
  35. fi
  36. done
  37. echo " support modules rebuilt"
  38. fi
  39. rm -f tests/ct.lst compiletest
  40. $GM2 $FLAGS -fgen-module-list=tests/ct.lst -o /dev/null \
  41. tests/CompileTest.mod TextBuf.o Posix.o Compiler.o Runtime.o >/tmp/ct_p1 2>&1
  42. p1=$?
  43. $GM2 $FLAGS -fuse-list=tests/ct.lst -o compiletest \
  44. tests/CompileTest.mod TextBuf.o Posix.o Compiler.o Runtime.o >/tmp/ct_p2 2>&1
  45. p2=$?
  46. if [ $p2 -ne 0 ]; then
  47. echo "LINK_FAIL p1_rc=$p1 p2_rc=$p2"
  48. grep -E "error:|undefined" /tmp/ct_p2 | head -10
  49. exit 1
  50. fi
  51. echo "compiletest built (p1_rc=$p1, phase 1 rc=1 is the expected rollup)"
  52. FX=${1:-tests/fixtures}
  53. # ---- assert against tests/fixtures/expected.tsv ---------------------------
  54. # Previously this script only printed a verdict, so "17 of 23" was a number a
  55. # human counted by hand and a wrong error POSITION was invisible. Both the
  56. # verdict and the numbers are compared now, and the exit status is meaningful.
  57. EXP="$FX/expected.tsv"
  58. if [ ! -f "$EXP" ]; then
  59. echo "no expectations file $EXP - printing only"
  60. ls "$FX"/*.pas 2>/dev/null | ./compiletest
  61. exit 0
  62. fi
  63. RAW=$(mktemp) || exit 9
  64. ls "$FX"/*.pas 2>/dev/null | ./compiletest > "$RAW"
  65. # expected row for a fixture basename, normalised to single spaces
  66. # (only rows that actually carry a verdict count, so the wrapped comment
  67. # lines in expected.tsv can never be mistaken for data)
  68. expect_for() {
  69. awk -F'\t' -v n="$1" '
  70. ($2 == "OK" || $2 == "ERR") && $1 == n {
  71. out = ""
  72. for (i = 2; i <= NF; i++)
  73. out = (out == "") ? $i : out " " $i
  74. print out
  75. exit
  76. }
  77. ' "$EXP"
  78. }
  79. pass=0; fail=0
  80. while IFS= read -r base; do
  81. actual=$(grep -F "$base" "$RAW" \
  82. | head -1 \
  83. | tr -d '\r' \
  84. | sed -E 's/^[^ ]+[[:space:]]+//' \
  85. | tr -s ' ' \
  86. | sed -E 's/^OK code=([0-9]+) data=([0-9]+)$/OK \1 \2/;
  87. s/^ERROR ([0-9]+) at pos ([0-9]+)$/ERR \1 \2/')
  88. want=$(expect_for "$base" | tr -s ' ')
  89. if [ -z "$want" ]; then
  90. printf ' %-24s NO_EXPECTATION got: %s\n' "$base" "$actual"
  91. fail=$((fail + 1))
  92. elif [ "$actual" = "$want" ]; then
  93. printf ' %-24s PASS %s\n' "$base" "$actual"
  94. pass=$((pass + 1))
  95. else
  96. printf ' %-24s FAIL\n expected: %s\n actual: %s\n' \
  97. "$base" "$want" "$actual"
  98. fail=$((fail + 1))
  99. fi
  100. done <<EOF
  101. $(ls "$FX"/*.pas 2>/dev/null | xargs -n1 basename | sed 's/\.pas$//')
  102. EOF
  103. echo "----------------------------------------------------------------"
  104. echo "compile matrix: $pass passed, $fail failed (of $((pass + fail)))"
  105. rm -f "$RAW"
  106. [ "$fail" -eq 0 ] || exit 1