run_all.sh 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/bash
  2. # Run every check. Non-zero exit if anything fails.
  3. #
  4. # Four suites, in increasing order of "how much could be lying to me":
  5. #
  6. # 1. compile matrix 33 fixtures, verdict + code size + data size ASSERTED
  7. # from expected.tsv. Fast, no pty.
  8. # 2. .COM linker links every fixture, then re-verifies the bytes with an
  9. # independent checker that restates the layout constants
  10. # instead of asking the compiler.
  11. # 3. UI error path pty: W, C on a bad file, editor opens on the error,
  12. # Ctrl-K D, Q. Covers the shell behaviour that only
  13. # exists interactively.
  14. # 4. UI success path pty: Options -> Destination=COM, C, then the .COM is
  15. # checked ON DISK. This is the end-to-end path from
  16. # keystroke to artifact.
  17. #
  18. # 5. frame displ links the two fixtures that touch a stack frame and
  19. # asserts the [BP+off] displacement encoding, which no
  20. # other check can see: disp8 and disp16 are both
  21. # well-formed and both decode cleanly, and only one of
  22. # them reads the variable the symbol table named.
  23. #
  24. # RtProbe dumps the runtime size and its 14 entry offsets, so a
  25. # runtime change that moves an entry is visible here.
  26. #
  27. # Three runtime suites run before all of those, because everything else
  28. # trusts the runtime's bytes:
  29. #
  30. # audit_helpers disassembles every one-line emitter in BOTH Runtime.mod
  31. # and Compiler.mod and compares the DECODE against the
  32. # procedure's NAME. This is the only check that can see
  33. # a wrong ModRM that still decodes cleanly, which is the
  34. # mistake this project actually makes: MovSiBx and
  35. # CmpSiBx were both `DC` (= MOV SP,BX / CMP SP,BX) for a
  36. # long time, and EmXchgAxCx was `93` (XCHG BX,AX) under a
  37. # name that says XCHG AX,CX.
  38. #
  39. # It sweeps Compiler.mod because that is where the
  40. # emitter was. Auditing one module said "every helper
  41. # agrees with its name" about a module it had not
  42. # examined, which is why the XCHG fault survived a green
  43. # run. It also cross-checks its own coverage: a
  44. # procedure that emits bytes but that the audit never
  45. # matched is itself a failure, because a helper that
  46. # drops out of the audit when you add a comment is worse
  47. # than a helper that is checked and found wanting.
  48. # check_runtime sweeps the built runtime's code region with FCML: no
  49. # desync, every entry and every branch target on an
  50. # instruction boundary, and the whole disassembly equal
  51. # to tests/runtime.golden.
  52. # nonvacuity breaks the runtime and the compiler in the ways each
  53. # named check is meant to catch, and asserts it goes red
  54. # for the STATED reason, not merely red. Slower, so it
  55. # is not in the default run: run it when a check's
  56. # sensitivity is in question, or after editing a check.
  57. #
  58. # nonvacuity.sh is NOT run by default: it rebuilds the runtime and the compiler
  59. # a dozen times over and it is a meta-check, so it belongs to "is the harness
  60. # honest" reviews rather than to every change. Run tests/nonvacuity.sh
  61. # directly after touching any of the checks above. (The count of rebuilds is
  62. # not stated here on purpose: it drifts every time a case is added, and a
  63. # number in a comment that is only right until the next edit is the kind of
  64. # restated constant that hides a fault here.)
  65. #
  66. # Two more checks guard the ModR/M table itself, which is the input every hand
  67. # written emitter in Runtime.mod depends on:
  68. #
  69. # probe/modrm11.py asks GNU `as` (.code16) to encode the register moves
  70. # and FCML to decode them, and requires the result to
  71. # agree with the hard-coded bytes, the four
  72. # hand-checking anchors, and the table in Runtime.mod.
  73. # This is the only check that can catch the TABLE being
  74. # wrong rather than one emitter: the table shipped once
  75. # with AX dropped off the front of the mod=11 column
  76. # and a duplicate BX invented at the end, which shifts
  77. # every code down by one and makes `89 DC` (MOV SP,BX)
  78. # look like the SI move the name asks for.
  79. # probe/modrm19.s the execution probe for mod=00/01/10, kept as the
  80. # record of how the memory forms were measured. It is
  81. # not run by default: it needs qemu and a hand-built
  82. # floppy image, and its result is already written into
  83. # the table in Runtime.mod, which modrm11.py checks.
  84. # See probe/README.md to re-run it.
  85. #
  86. # rt_exec.py DOES run. It used to run on Unicorn and fail 33 of 33, because
  87. # Unicorn 2.1.4 mis-decodes 16-bit ModRM memory operands - so every failure was
  88. # the emulator's, and a wrong oracle is worse than none: it cannot tell "my
  89. # codegen is broken" from "the machine is broken". It now boots the same
  90. # bootcom.s the .COM fixtures use, one fresh machine per case, so every case
  91. # gets a machine that has provably never run anything. See its own docstring
  92. # and the EXPECTATION FIXES section in tests/rt_exec.py.
  93. set -u
  94. D=/home/eric/Projets/Projets-Modula2/MyWork/TP3-comp/shell
  95. GM2=/home/eric/bin/Modula2/Gm2/bin/gm2
  96. cd "$D" || exit 9
  97. fail=0
  98. run () {
  99. name=$1
  100. shift
  101. echo
  102. echo "=============================================================="
  103. echo "== $name"
  104. echo "=============================================================="
  105. if "$@" ; then
  106. echo "-- $name: PASS"
  107. else
  108. echo "-- $name: FAIL (rc=$?)"
  109. fail=1
  110. fi
  111. }
  112. echo "== build =="
  113. make clean >/dev/null 2>&1
  114. if ! make >/tmp/tp_all_mk 2>&1 ; then
  115. echo "BUILD FAIL"
  116. grep -m10 "error:" /tmp/tp_all_mk
  117. exit 1
  118. fi
  119. echo "make rc=0, tpshell $(stat -c%s tpshell) bytes"
  120. # gm2 reports a pass-3 rollup on the compiler during phase 1 of the two-phase
  121. # link; that is expected and is not a build failure (make rc=0 is the check).
  122. # The probe step asks rt_exec.py for its dump rather than building RtProbe a
  123. # second time by hand. Two recipes for one artifact is how a stale binary gets
  124. # believed: ensure_rtprobe() is the only one that knows Runtime.mod's mtime, and
  125. # a probe older than the runtime it reports on is worse than no probe, because
  126. # its failure -- a blob with the wrong addresses baked in -- is invisible at the
  127. # byte level and catastrophic at the behaviour level.
  128. run "runtime probe" python3 tests/rt_exec.py --probe
  129. run "helper audit" python3 tests/audit_helpers.py
  130. run "mod=11 table" python3 tests/probe/modrm11.py
  131. run "runtime image" python3 tests/check_runtime.py
  132. run "compile matrix" tests/run_compile_tests.sh
  133. run "COM linker" tests/run_com_tests.sh
  134. # The byte checks above can only ask "are these bytes well formed". This one
  135. # asks "does the program do the right thing": every fixture with a .out is
  136. # compiled, booted in qemu, and its output compared byte for byte, together
  137. # with the DOS exit code. It is the step that found eleven runtime bugs, the
  138. # FOR off-by-one, the missing procedure-skip jump and a parser bug - none of
  139. # which produced a malformed byte.
  140. run "EXECUTE under qemu" python3 tests/run_com_exec.py
  141. # And this one asks whether the runtime ENTRIES do what they claim, one qemu
  142. # boot per call, 35 cases plus a pre-flight. It is the only check that can catch
  143. # an entry that is well-formed, decodes cleanly, preserves every register the
  144. # driver happens to need - and computes the wrong answer: wrchar and wrbool
  145. # borrowed BP to reach their argument and never gave it back, which a byte check
  146. # and a register-convention check both call correct. One case (four calls back
  147. # to back) noticed; the BP-contract pre-flight is what stops the next entry from
  148. # depending on there being such a case.
  149. run "runtime entries" python3 tests/rt_exec.py
  150. run "frame displ" python3 tests/check_framedisp.py
  151. # The machine this compiler targets is an 8086, and the byte checks above all
  152. # ask "is this well formed" -- which `0F 84 lo hi' is. qemu-system-i386's
  153. # lowest CPU model is 486, so the execution suite could not object either.
  154. # This one asks "does the target have this opcode at all", and asserts the
  155. # lowering that replaced the two illegal ones is the original compiler's shape.
  156. run "8086 opcodes" python3 tests/check_8086.py
  157. run "UI error path" python3 tests/uitest.py
  158. run "UI success path" python3 tests/comtest.py
  159. echo
  160. echo "=============================================================="
  161. if [ "$fail" -eq 0 ]; then
  162. echo "OVERALL: ALL PASS"
  163. else
  164. echo "OVERALL: FAILURES PRESENT"
  165. fi
  166. echo "=============================================================="
  167. exit $fail