run_tests.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #!/bin/sh
  2. # M2make regression tests. Builds M2make with both compilers (via the
  3. # sibling build scripts) and exercises ordering, up-to-date checks,
  4. # rebuilds, cycles, and real builds.
  5. # Usage: ./run_tests.sh (from the tools/m2make directory)
  6. pass=0; fail=0
  7. ok() { pass=$((pass+1)); echo "PASS: $1"; }
  8. no() { fail=$((fail+1)); echo "FAIL: $1"; }
  9. # --- bootstrapping: both compilers must build M2make ---
  10. ./build_gm2.sh > /tmp/m2make_t.log 2>&1
  11. if [ -x b_gm2/M2make ]; then ok "gm2 builds M2make"; else no "gm2 builds M2make"; fi
  12. ./build_m2.sh > /tmp/m2make_t.log 2>&1
  13. if [ -x b_v3/M2make ]; then ok "M2 builds M2make"; else no "M2 builds M2make"; fi
  14. GM2=b_gm2/M2make
  15. V3M=b_v3/M2make
  16. # --- dry-run ordering (both binaries must agree) ---
  17. for bin in "$GM2" "$V3M"; do
  18. out=$($bin -n -c gm2 tests/Main2.mod 2>&1)
  19. calc_line=$(printf '%s\n' "$out" | grep -n "Calc :" | cut -d: -f1)
  20. main_line=$(printf '%s\n' "$out" | grep -n "M2makeMain" | cut -d: -f1)
  21. if [ -n "$calc_line" ] && [ -n "$main_line" ] && [ "$calc_line" -lt "$main_line" ]; then
  22. ok "$bin order (Calc before Main2)"
  23. else
  24. no "$bin order (Calc before Main2): $out"
  25. fi
  26. case "$out" in
  27. *"Add"*) no "$bin leaks FROM-items as modules: $out" ;;
  28. *) ok "$bin ignores FROM-items" ;;
  29. esac
  30. done
  31. # --- cycle detection ---
  32. for bin in "$GM2" "$V3M"; do
  33. out=$($bin -n -c gm2 tests/CycA.mod 2>&1); rc=$?
  34. case "$out" in
  35. *"cyclic import"*) ok "$bin reports cycle" ;;
  36. *) no "$bin reports cycle: $out" ;;
  37. esac
  38. if [ "$rc" = "1" ]; then ok "$bin cycle exit code 1"; else no "$bin cycle exit code ($rc)"; fi
  39. done
  40. # --- real gm2 build, run, up-to-date, rebuild ---
  41. rm -f Main2 *.o
  42. if $GM2 -c gm2 -o Main2 tests/Main2.mod > /tmp/m2make_t.log 2>&1; then
  43. ok "gm2-mode real build"
  44. else
  45. no "gm2-mode real build"
  46. fi
  47. if [ "$(./Main2 2>/dev/null)" = "ok42" ]; then
  48. ok "gm2-built program runs (ok42)"
  49. else
  50. no "gm2-built program runs"
  51. fi
  52. out=$($GM2 -c gm2 -o Main2 tests/Main2.mod 2>&1)
  53. case "$out" in
  54. *"up to date"*) ok "gm2-mode up-to-date skip" ;;
  55. *) no "gm2-mode up-to-date skip: $out" ;;
  56. esac
  57. sleep 1
  58. touch tests/Calc.mod
  59. out=$($GM2 -c gm2 -o Main2 tests/Main2.mod 2>&1)
  60. case "$out" in
  61. *"-c tests/Calc.mod"*) ok "gm2-mode recompiles touched dep" ;;
  62. *) no "gm2-mode recompiles touched dep: $out" ;;
  63. esac
  64. touch tests/Calc.def tests/Calc.mod tests/Main2.mod
  65. # --- real m2 build via the V3-built M2make ---
  66. rm -rf gen_ssa Main m2make.log
  67. if $V3M -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  68. -I ../../lib/common -o Main tests/Main.mod > /tmp/m2make_t.log 2>&1; then
  69. ok "m2-mode real build (V3 M2make)"
  70. else
  71. no "m2-mode real build (V3 M2make)"
  72. fi
  73. if ./Main 2>/dev/null | grep -q "42"; then
  74. ok "m2-built program runs (42)"
  75. else
  76. no "m2-built program runs"
  77. fi
  78. out=$($V3M -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  79. -I ../../lib/common -o Main tests/Main.mod 2>&1)
  80. case "$out" in
  81. *"up to date"*) ok "m2-mode up-to-date skip" ;;
  82. *) no "m2-mode up-to-date skip: $out" ;;
  83. esac
  84. # --- separate-object build, up-to-date, incremental relink ---
  85. rm -rf gen_ssa SepMain m2make.log
  86. if $V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  87. -I ../../lib/common -o SepMain tests/Main.mod > /tmp/m2make_t.log 2>&1; then
  88. ok "separate-mode real build"
  89. else
  90. no "separate-mode real build"
  91. fi
  92. if ./SepMain 2>/dev/null | grep -q "42"; then
  93. ok "separate-built program runs (42)"
  94. else
  95. no "separate-built program runs"
  96. fi
  97. out=$($V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  98. -I ../../lib/common -o SepMain tests/Main.mod 2>&1)
  99. case "$out" in
  100. *"up to date"*) ok "separate-mode up-to-date skip" ;;
  101. *) no "separate-mode up-to-date skip: $out" ;;
  102. esac
  103. sleep 1
  104. touch tests/Calc.mod
  105. out=$($V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  106. -I ../../lib/common -o SepMain tests/Main.mod 2>&1)
  107. case "$out" in
  108. *"tests/Calc.mod"*) ok "separate-mode recompiles changed object" ;;
  109. *) no "separate-mode recompiles changed object: $out" ;;
  110. esac
  111. if ./SepMain 2>/dev/null | grep -q "42"; then
  112. ok "separate relink runs (42)"
  113. else
  114. no "separate relink runs"
  115. fi
  116. sleep 1
  117. touch tests/Calc.def
  118. out=$($V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  119. -I ../../lib/common -o SepMain tests/Main.mod 2>&1)
  120. case "$out" in
  121. *"tests/Main.mod"*) ok "separate-mode recompiles importer after .def change" ;;
  122. *) no "separate-mode .def rebuild: $out" ;;
  123. esac
  124. touch tests/Calc.def tests/Calc.mod tests/Main.mod
  125. # --- definition-only class object ---
  126. rm -rf gen_ssa CDefProg
  127. if $V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  128. -I . -o CDefProg tests/CProg.mod > /tmp/m2make_t.log 2>&1; then
  129. ./CDefProg > /dev/null 2>&1; rc=$?
  130. if [ "$rc" = "8" ]; then ok "separate-mode definition-only class object"
  131. else no "separate-mode definition-only class object (rc=$rc)"; fi
  132. else
  133. no "separate-mode definition-only class object (build)"
  134. fi
  135. # --- generic instance as its own object ---
  136. rm -rf gen_ssa GenProg
  137. if $V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  138. -I . -o GenProg tests/GenProg.mod > /tmp/m2make_t.log 2>&1; then
  139. ./GenProg > /dev/null 2>&1; rc=$?
  140. if [ "$rc" = "42" ]; then ok "separate-mode generic instance object"
  141. else no "separate-mode generic instance object (rc=$rc)"; fi
  142. else
  143. no "separate-mode generic instance object (build)"
  144. fi
  145. # --- content ABI stamp ---
  146. rm -f gen_ssa/.m2abi
  147. out=$($V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  148. -I . -o CDefProg tests/CProg.mod 2>&1)
  149. case "$out" in
  150. *"tests/CProg.mod"*) ok "separate-mode ABI stamp forces rebuild" ;;
  151. *) no "separate-mode ABI stamp: $out" ;;
  152. esac
  153. # --- cross-check: gm2-built M2make drives an m2 build too ---
  154. rm -rf gen_ssa MainX m2make.log
  155. if $GM2 -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  156. -I ../../lib/common -o MainX tests/Main.mod > /tmp/m2make_t.log 2>&1 \
  157. && ./MainX 2>/dev/null | grep -q "42"; then
  158. ok "gm2-built M2make drives m2 build"
  159. else
  160. no "gm2-built M2make drives m2 build"
  161. fi
  162. rm -f Main MainX Main2 SepMain CDefProg GenProg *.o
  163. rm -rf gen_ssa
  164. rm -f m2make.log
  165. echo "--- $pass passed, $fail failed ---"
  166. [ "$fail" -eq 0 ]