run_tests.sh 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. # --- multiple extra C shims, --lib and --pkg-config (one-shot) ---
  85. rm -rf gen_ssa LinkExtra m2make.log
  86. OLD_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
  87. PKG_CONFIG_PATH="$PWD/tests${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
  88. export PKG_CONFIG_PATH
  89. if $V3M -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  90. --extra tests/extra_one.c --extra tests/extra_two.c \
  91. --pkg-config m2make-test --lib m -o LinkExtra tests/LinkExtra.mod \
  92. > /tmp/m2make_t.log 2>&1; then
  93. ./LinkExtra > /dev/null 2>&1; rc=$?
  94. if [ "$rc" = "42" ]; then ok "multiple --extra + --pkg-config + --lib"
  95. else no "multiple --extra + --pkg-config + --lib (rc=$rc)"; fi
  96. else
  97. no "multiple --extra + --pkg-config + --lib (build)"
  98. fi
  99. # --- same link integration in separate-object mode ---
  100. rm -rf gen_ssa LinkExtraSep m2make.log
  101. if $V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  102. --extra tests/extra_one.c --extra tests/extra_two.c \
  103. --pkg-config m2make-test --lib m -o LinkExtraSep tests/LinkExtra.mod \
  104. > /tmp/m2make_t.log 2>&1; then
  105. ./LinkExtraSep > /dev/null 2>&1; rc=$?
  106. if [ "$rc" = "42" ]; then ok "separate --extra + --pkg-config + --lib"
  107. else no "separate --extra + --pkg-config + --lib (rc=$rc)"; fi
  108. else
  109. no "separate --extra + --pkg-config + --lib (build)"
  110. fi
  111. PKG_CONFIG_PATH="$OLD_PKG_CONFIG_PATH"
  112. export PKG_CONFIG_PATH
  113. # --- separate-object build, up-to-date, incremental relink ---
  114. rm -rf gen_ssa SepMain m2make.log
  115. if $V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  116. -I ../../lib/common -o SepMain tests/Main.mod > /tmp/m2make_t.log 2>&1; then
  117. ok "separate-mode real build"
  118. else
  119. no "separate-mode real build"
  120. fi
  121. if ./SepMain 2>/dev/null | grep -q "42"; then
  122. ok "separate-built program runs (42)"
  123. else
  124. no "separate-built program runs"
  125. fi
  126. out=$($V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  127. -I ../../lib/common -o SepMain tests/Main.mod 2>&1)
  128. case "$out" in
  129. *"up to date"*) ok "separate-mode up-to-date skip" ;;
  130. *) no "separate-mode up-to-date skip: $out" ;;
  131. esac
  132. sleep 1
  133. touch tests/Calc.mod
  134. out=$($V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  135. -I ../../lib/common -o SepMain tests/Main.mod 2>&1)
  136. case "$out" in
  137. *"tests/Calc.mod"*) ok "separate-mode recompiles changed object" ;;
  138. *) no "separate-mode recompiles changed object: $out" ;;
  139. esac
  140. if ./SepMain 2>/dev/null | grep -q "42"; then
  141. ok "separate relink runs (42)"
  142. else
  143. no "separate relink runs"
  144. fi
  145. sleep 1
  146. touch tests/Calc.def
  147. out=$($V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  148. -I ../../lib/common -o SepMain tests/Main.mod 2>&1)
  149. case "$out" in
  150. *"tests/Main.mod"*) ok "separate-mode recompiles importer after .def change" ;;
  151. *) no "separate-mode .def rebuild: $out" ;;
  152. esac
  153. touch tests/Calc.def tests/Calc.mod tests/Main.mod
  154. # --- definition-only class object ---
  155. rm -rf gen_ssa CDefProg
  156. if $V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  157. -I . -o CDefProg tests/CProg.mod > /tmp/m2make_t.log 2>&1; then
  158. ./CDefProg > /dev/null 2>&1; rc=$?
  159. if [ "$rc" = "8" ]; then ok "separate-mode definition-only class object"
  160. else no "separate-mode definition-only class object (rc=$rc)"; fi
  161. else
  162. no "separate-mode definition-only class object (build)"
  163. fi
  164. # --- generic instance as its own object ---
  165. rm -rf gen_ssa GenProg
  166. if $V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  167. -I . -o GenProg tests/GenProg.mod > /tmp/m2make_t.log 2>&1; then
  168. ./GenProg > /dev/null 2>&1; rc=$?
  169. if [ "$rc" = "42" ]; then ok "separate-mode generic instance object"
  170. else no "separate-mode generic instance object (rc=$rc)"; fi
  171. else
  172. no "separate-mode generic instance object (build)"
  173. fi
  174. # --- generic class instance object ---
  175. rm -rf gen_ssa GCProg
  176. if $V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  177. -I . -o GCProg tests/GCProg.mod > /tmp/m2make_t.log 2>&1; then
  178. ./GCProg > /dev/null 2>&1; rc=$?
  179. if [ "$rc" = "42" ]; then ok "separate-mode generic class object"
  180. else no "separate-mode generic class object (rc=$rc)"; fi
  181. else
  182. no "separate-mode generic class object (build)"
  183. fi
  184. # --- content ABI stamp ---
  185. rm -f gen_ssa/.m2abi
  186. out=$($V3M --separate -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  187. -I . -o CDefProg tests/CProg.mod 2>&1)
  188. case "$out" in
  189. *"tests/CProg.mod"*) ok "separate-mode ABI stamp forces rebuild" ;;
  190. *) no "separate-mode ABI stamp: $out" ;;
  191. esac
  192. # --- cross-check: gm2-built M2make drives an m2 build too ---
  193. rm -rf gen_ssa MainX m2make.log
  194. if $GM2 -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  195. -I ../../lib/common -o MainX tests/Main.mod > /tmp/m2make_t.log 2>&1 \
  196. && ./MainX 2>/dev/null | grep -q "42"; then
  197. ok "gm2-built M2make drives m2 build"
  198. else
  199. no "gm2-built M2make drives m2 build"
  200. fi
  201. rm -f Main MainX Main2 SepMain LinkExtra LinkExtraSep CDefProg GenProg GCProg *.o
  202. rm -rf gen_ssa
  203. rm -f m2make.log
  204. echo "--- $pass passed, $fail failed ---"
  205. [ "$fail" -eq 0 ]