run_compile_tests.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. || [ TextBuf.mod -nt TextBuf.o ] || [ Compiler.mod -nt Compiler.o ] \
  15. || [ Posix.c -nt Posix.o ] || [ Posix.def -nt Posix.o ]; then
  16. echo "building support modules (source newer than object)..."
  17. # NB: Posix is a FOR "C" module (Posix.c + Posix.def, no Posix.mod), so it
  18. # is not rebuilt here - only TextBuf and Compiler have a .mod to compile.
  19. for m in TextBuf Compiler; do
  20. $GM2 $FLAGS -c $m.mod >/tmp/ct_c_$m 2>&1
  21. if [ $? -ne 0 ]; then
  22. echo "COMPILE_FAIL $m"
  23. grep -m5 -E "error:|Please submit" /tmp/ct_c_$m
  24. exit 1
  25. fi
  26. done
  27. echo " support modules rebuilt"
  28. fi
  29. rm -f tests/ct.lst compiletest
  30. $GM2 $FLAGS -fgen-module-list=tests/ct.lst -o /dev/null \
  31. tests/CompileTest.mod TextBuf.o Posix.o Compiler.o >/tmp/ct_p1 2>&1
  32. p1=$?
  33. $GM2 $FLAGS -fuse-list=tests/ct.lst -o compiletest \
  34. tests/CompileTest.mod TextBuf.o Posix.o Compiler.o >/tmp/ct_p2 2>&1
  35. p2=$?
  36. if [ $p2 -ne 0 ]; then
  37. echo "LINK_FAIL p1_rc=$p1 p2_rc=$p2"
  38. grep -E "error:|undefined" /tmp/ct_p2 | head -10
  39. exit 1
  40. fi
  41. echo "compiletest built (p1_rc=$p1, phase 1 rc=1 is the expected rollup)"
  42. FX=${1:-tests/fixtures}
  43. # ---- assert against tests/fixtures/expected.tsv ---------------------------
  44. # Previously this script only printed a verdict, so "17 of 23" was a number a
  45. # human counted by hand and a wrong error POSITION was invisible. Both the
  46. # verdict and the numbers are compared now, and the exit status is meaningful.
  47. EXP="$FX/expected.tsv"
  48. if [ ! -f "$EXP" ]; then
  49. echo "no expectations file $EXP - printing only"
  50. ls "$FX"/*.pas 2>/dev/null | ./compiletest
  51. exit 0
  52. fi
  53. RAW=$(mktemp) || exit 9
  54. ls "$FX"/*.pas 2>/dev/null | ./compiletest > "$RAW"
  55. # expected row for a fixture basename, normalised to single spaces
  56. # (only rows that actually carry a verdict count, so the wrapped comment
  57. # lines in expected.tsv can never be mistaken for data)
  58. expect_for() {
  59. awk -F'\t' -v n="$1" '
  60. ($2 == "OK" || $2 == "ERR") && $1 == n {
  61. out = ""
  62. for (i = 2; i <= NF; i++)
  63. out = (out == "") ? $i : out " " $i
  64. print out
  65. exit
  66. }
  67. ' "$EXP"
  68. }
  69. pass=0; fail=0
  70. while IFS= read -r base; do
  71. actual=$(grep -F "$base" "$RAW" \
  72. | head -1 \
  73. | tr -d '\r' \
  74. | sed -E 's/^[^ ]+[[:space:]]+//' \
  75. | tr -s ' ' \
  76. | sed -E 's/^OK code=([0-9]+) data=([0-9]+)$/OK \1 \2/;
  77. s/^ERROR ([0-9]+) at pos ([0-9]+)$/ERR \1 \2/')
  78. want=$(expect_for "$base" | tr -s ' ')
  79. if [ -z "$want" ]; then
  80. printf ' %-24s NO_EXPECTATION got: %s\n' "$base" "$actual"
  81. fail=$((fail + 1))
  82. elif [ "$actual" = "$want" ]; then
  83. printf ' %-24s PASS %s\n' "$base" "$actual"
  84. pass=$((pass + 1))
  85. else
  86. printf ' %-24s FAIL\n expected: %s\n actual: %s\n' \
  87. "$base" "$want" "$actual"
  88. fail=$((fail + 1))
  89. fi
  90. done <<EOF
  91. $(ls "$FX"/*.pas 2>/dev/null | xargs -n1 basename | sed 's/\.pas$//')
  92. EOF
  93. echo "----------------------------------------------------------------"
  94. echo "compile matrix: $pass passed, $fail failed (of $((pass + fail)))"
  95. rm -f "$RAW"
  96. [ "$fail" -eq 0 ] || exit 1