nonvacuity.sh 135 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063
  1. #!/bin/sh
  2. # The layout cases below rewrite tests/comimage.py and restore it within the
  3. # same second. A .pyc names the source by (mtime, size), and two versions of
  4. # this file can have both in common, so Python would keep executing the
  5. # MUTATED module after the restore. That made later cases report the mutation
  6. # as if it were the baseline. Do not write bytecode here.
  7. PYTHONDONTWRITEBYTECODE=1
  8. export PYTHONDONTWRITEBYTECODE
  9. # nonvacuity.sh -- prove the runtime checks can actually fail.
  10. #
  11. # A test that has never been seen red is not a test. This script breaks the
  12. # runtime on purpose, once per check, and asserts that the check goes red and
  13. # says something useful about the breakage. Then it restores the source and
  14. # asserts everything is green again.
  15. #
  16. # Each mutation below is a real bug that was in this file at some point, not an
  17. # invented one. That is the point: these are the mistakes we actually make
  18. # with 16-bit ModRM, so these are the ones the checks have to catch.
  19. #
  20. # audit_helpers.py name-versus-decode: catches a wrong ModRM that still
  21. # decodes cleanly, and both halves of a name that admits
  22. # an operand at all - `34 02' where the name promises
  23. # `34 01', and `35 01' where the row's opcode gate admits
  24. # only 34h. Both rows are new, and a row nobody has seen
  25. # reject anything accepts whatever it is shown.
  26. # audit_helpers.py coverage: catches a helper that has silently
  27. # dropped OUT of the audit, which is a green report about
  28. # a subject nobody looked at
  29. # run_com_tests.sh the .COM layout: catches a header that cannot be
  30. # located, a runtime size that disagrees with the image,
  31. # and an entry jump that starts in the wrong place
  32. # check_runtime.py golden: catches the same thing in the built
  33. # image
  34. # check_runtime.py decode sweep: catches a wrong instruction LENGTH
  35. # check_runtime.py branch targets: catches a wrong fixup
  36. # check_runtime.py entry goldens: catches a broken prologue
  37. # probe/modrm11.py the mod=11 table: catches the ModRM column itself
  38. # going wrong, which no amount of decoding will show
  39. # check_framedisp.py the BP disp rule: catches a displacement that reads
  40. # a different address than the symbol table named
  41. # tests/comimage.py the image layout: catches a sweep region built from a
  42. # literal instead of from two independent readings of the
  43. # file - the old RT_SZ went on reporting PASS while its
  44. # region began inside the runtime - and the layout itself
  45. # being written down a second time, now that one file
  46. # defines it and all three readers import it
  47. # rt_exec.py the BP contract: catches an entry that borrows BP to
  48. # reach its argument and does not hand it back. The bytes
  49. # are well formed, the golden is satisfied, the audit says
  50. # every helper emits what its name says, and the machine
  51. # triple-faults on the second call - so nothing short of
  52. # running it, or of stating the register contract
  53. # explicitly, can see it.
  54. # rt_exec.py the string entries: catches rdstr storing its first
  55. # character where the length byte belongs (a missing IncSi
  56. # puts `hello' back as 05 65 6c 6c 6f), and strstore
  57. # running LOOP with CX = 0 when the source is empty - 65536
  58. # iterations that wrap the segment and walk through the
  59. # driver's own case record. Both are same-size,
  60. # matrix-green slips that only a byte dump can see.
  61. # run_com_exec.py the frame rule: catches a local STRING packed with the
  62. # INTEGER rule, so its characters grow up over the saved BP
  63. # and the return address; readln into such a local then
  64. # runs the string's own bytes as an address. The fix moves
  65. # no well-formed instruction, so only execution - or the
  66. # size it pins in the compile matrix - can tell.
  67. # run_com_exec.py the string arms: catches the destination limit loaded
  68. # into AX instead of CX, the assignment pushes swapped so
  69. # the destination is read as its own source, and a string
  70. # read dispatched to the integer reader. Every one is the
  71. # right shape reading the wrong thing, and the MovCxi
  72. # helper is COMP in the audit, so no byte check can see it.
  73. # check_8086.py the 8086 opcodes: catches a conditional branch or a
  74. # SETcc emitted as `0F 8x'/`0F 9x', which are 386-only.
  75. # Nothing else here can: qemu-system-i386's lowest CPU
  76. # model is 486, where both are ordinary instructions, and
  77. # FCML's -m16 mode is a 386 too. Clause H additionally
  78. # catches the branch polarity being inverted, which is
  79. # still a legal opcode and therefore invisible to every
  80. # shape-based check.
  81. # run_com_exec.py behaviour: catches a*b that emits an ADD, `>'
  82. # and `>=' swapped, REPEAT..UNTIL that stops after one
  83. # pass, two procedures whose parameters collide, a left
  84. # operand overwritten by the right one's code (SaveLeft),
  85. # and a boolean `not' lowered as the integer one. Every
  86. # one of them sat in a fixture that COMPILED and was
  87. # never RUN, with every byte-level check green.
  88. # run_compile_tests.sh refusal: catches a boolean READ slipping
  89. # through to the runtime. TP3 refuses it with error 66
  90. # (TPSRC8 prderrtp; its runtime has no xrdbool), and
  91. # this compiler used to accept it and let rdbool store
  92. # a WORD into the one-byte variable. The mutation is
  93. # the one arm of IoCall's type dispatch that refuses it,
  94. # and only the COMPILE MATRIX can see a refusal: an ERR
  95. # fixture is never executed, so nothing that runs
  96. # programs on it can fail the check.
  97. # run_exec86.py behaviour (Exec86): catches the interpreter's OWN
  98. # reading of the machine: JE inverted in Exec86's Cond,
  99. # which swaps the two arms of every `=' in every program
  100. # while the emitted bytes, the sizes and every
  101. # byte-level check stay green. The image is fine; only
  102. # the thing reading it is wrong, so nothing that looks at
  103. # the image can fail this one.
  104. # runtest.py the R key: catches CmdRun poking nothing into
  105. # the interpreter at all, which faults on the first step
  106. # and prints "interpreter fault" instead of the guest's
  107. # answer. It is the only case here that needs a rebuilt
  108. # SHELL rather than a rebuilt compiler or runtime.
  109. #
  110. # The mod=11 cases do not need a rebuild -- they read the probe sources
  111. # directly -- so they are cheap, and they are the ones that matter most: the
  112. # table they guard is the one thing in this project that was wrong in the
  113. # documentation while the code was right, and a table that is wrong in the
  114. # code produces bytes that decode perfectly.
  115. #
  116. # Usage: tests/nonvacuity.sh (from shell/; leaves Runtime.mod restored)
  117. set -u
  118. cd "$(dirname "$0")/.." || exit 1
  119. GM2=/home/eric/bin/Modula2/Gm2/bin/gm2
  120. SAVED=../tmp/nonvacuity.Runtime.mod
  121. PROBE=../tmp/nonvacuity.rtprobe
  122. DUMP=../tmp/nonvacuity.dump
  123. # Exec86.mod is UNTRACKED, so unlike Runtime.mod git cannot put a botched
  124. # mutation back: the copy taken here is the only correct one in existence.
  125. # Shell.mod is tracked but is mutated by the R-key case below, and a trap that
  126. # restored only the sources would leave tpshell BUILT FROM the mutation - so
  127. # the trap rebuilds too. All three copies live in the project's own tmp/ and
  128. # are taken here, before the first mutation, rather than beside each case.
  129. #
  130. # comimage.py and comtest.py are the image layout and one of its three readers;
  131. # both are mutated by cases further down, and neither is recoverable from git
  132. # once the mutation is staged over - so they join the trap here for the same
  133. # reason, and an interrupted run cannot leave the layout half-written.
  134. #
  135. # Compiler.mod is the file mutated by the most cases, and it used to be saved
  136. # BESIDE the first case that needed it - the BP displacement section halfway
  137. # down this file, which is well AFTER this trap is set. An interrupted run
  138. # therefore left Compiler.mod half-mutated, with `git status` showing a source
  139. # that no case had finished with. It joins the copies above, taken before the
  140. # first mutation and covered by the same trap.
  141. #
  142. # tests/probe/modrm11.{py,s} are the last two: the mod=11 table section mutates
  143. # them and puts them back after each case, so a run that died between the two
  144. # left them edited. They move here for the same reason. restore_all copies
  145. # them directly instead of calling restore_probe, which is defined halfway down
  146. # this file: a trap firing before that definition would abort the rest of the
  147. # restore with "command not found".
  148. mkdir -p ../tmp
  149. SAVED_E=../tmp/nonvacuity.Exec86.mod
  150. SAVED_SH=../tmp/nonvacuity.Shell.mod
  151. SAVED_CI=../tmp/nonvacuity.comimage.py
  152. SAVED_T=../tmp/nonvacuity.comtest.py
  153. SAVED_C=../tmp/nonvacuity.Compiler.mod
  154. SAVED_PY=../tmp/nonvacuity.modrm11.py
  155. SAVED_S=../tmp/nonvacuity.modrm11.s
  156. cp Runtime.mod "$SAVED" || exit 1
  157. cp Exec86.mod "$SAVED_E" || exit 1
  158. cp Shell.mod "$SAVED_SH" || exit 1
  159. cp tests/comimage.py "$SAVED_CI" || exit 1
  160. cp tests/comtest.py "$SAVED_T" || exit 1
  161. cp Compiler.mod "$SAVED_C" || exit 1
  162. cp tests/probe/modrm11.py "$SAVED_PY" || exit 1
  163. cp tests/probe/modrm11.s "$SAVED_S" || exit 1
  164. restore_all () {
  165. cp "$SAVED" Runtime.mod
  166. cp "$SAVED_E" Exec86.mod
  167. cp "$SAVED_SH" Shell.mod
  168. cp "$SAVED_CI" tests/comimage.py
  169. cp "$SAVED_T" tests/comtest.py
  170. cp "$SAVED_C" Compiler.mod
  171. cp "$SAVED_PY" tests/probe/modrm11.py
  172. cp "$SAVED_S" tests/probe/modrm11.s
  173. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1
  174. "$GM2" -fiso -c Exec86.mod >/dev/null 2>&1
  175. # The shell is rebuilt as well: a test that runs against a binary built
  176. # from a half-restored tree is reporting on the mutation, not on the code.
  177. # make rebuilds Compiler.o out of the Compiler.mod restored just above.
  178. make >/dev/null 2>&1
  179. }
  180. trap restore_all EXIT
  181. #
  182. # An unhandled signal does NOT run an EXIT trap: bash dies on the spot. That is
  183. # what the comment above promises ("an interrupted run cannot leave the layout
  184. # half-written") and what this file did not actually do. A handler that only
  185. # `exit's is enough, because `exit' from a trap DOES fire the EXIT trap -- and
  186. # it has to exit, or the run would go on using a tree it has just put back.
  187. #
  188. # Measured on bash 5.2: TERM and HUP fire these and restore everything, so
  189. # `kill' and a session teardown are covered. INT is trapped too, but in the
  190. # usual case it never reaches this script: a foreground child that dies of
  191. # SIGINT makes bash treat the signal as the CHILD's and continue the script
  192. # instead. So Ctrl-C does not abort this run at all -- it kills the current
  193. # case's child and the next case starts -- and SIGTERM is what actually stops
  194. # it. 129/130/143 = 128+SIGHUP/INT/TERM.
  195. trap 'exit 129' HUP
  196. trap 'exit 130' INT
  197. trap 'exit 143' TERM
  198. pass=0
  199. fail=0
  200. # mutate <file> <sed-expr> -- apply a deliberate breakage and INSIST it landed.
  201. #
  202. # Four cases in this file were already dead when first run, all the same way:
  203. # the helper they name had been renamed or reformatted since the case was
  204. # written, the sed matched nothing, the source was unchanged, and the check
  205. # correctly passed - so the harness reported "NOT NON-VACUOUS" and, worse, a
  206. # reader skimming the output could take "the check still passed" for a passing
  207. # test. A case that cannot fire is worse than no case: it is a claim of
  208. # coverage that was never tested.
  209. #
  210. # So the mutation is verified, not assumed. If the file is byte-identical
  211. # afterwards, that is reported as a FAILURE of the harness, naming the sed, and
  212. # the case is not run - because running it would only produce a meaningless
  213. # green. The message says what to do (fix the sed) rather than what it found.
  214. mutate () {
  215. mf=$1
  216. msed=$2
  217. cp "$mf" ../tmp/nonvacuity.mut.bak
  218. sed -i "$msed" "$mf"
  219. if cmp -s "$mf" ../tmp/nonvacuity.mut.bak; then
  220. echo " BROKEN CASE: the mutation did not change $mf"
  221. echo " sed: $msed"
  222. echo " the named code has probably been renamed or reformatted -"
  223. echo " fix this case, it is asserting nothing"
  224. fail=$((fail + 1))
  225. return 1
  226. fi
  227. return 0
  228. }
  229. # rebuild <label> -- re-emit the runtime and dump it
  230. rebuild () {
  231. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1 || return 1
  232. "$GM2" -fiso -o "$PROBE" tests/RtProbe.mod Runtime.o Posix.o \
  233. >/dev/null 2>&1 || return 1
  234. "$PROBE" > "$DUMP" || return 1
  235. return 0
  236. }
  237. # expect_red <label> <pattern> <checker-cmd...>
  238. # <pattern> is a grep the failure output must match, so a check cannot
  239. # "pass" by failing for some unrelated reason.
  240. expect_red () {
  241. label=$1
  242. want=$2
  243. shift 2
  244. if out=$("$@" 2>&1); then
  245. echo "NOT NON-VACUOUS: $label -- the check still passed"
  246. fail=$((fail + 1))
  247. elif ! printf '%s\n' "$out" | grep -qi "$want"; then
  248. echo "WRONG FAILURE: $label -- went red, but not for the stated reason"
  249. printf '%s\n' "$out" | sed 's/^/ /'
  250. fail=$((fail + 1))
  251. else
  252. echo " ok: $label"
  253. printf '%s\n' "$out" | grep -im1 "$want" | sed 's/^/ /'
  254. pass=$((pass + 1))
  255. fi
  256. }
  257. echo "== each mutation must turn the named check red"
  258. echo
  259. # --- 1. name-versus-decode -------------------------------------------
  260. # MovSiBx was `89 DC`, which is MOV SP,BX. Two bytes either way, decodes
  261. # cleanly, and no structural check can see it.
  262. cp "$SAVED" Runtime.mod
  263. mutate Runtime.mod 's|B (0DEH) END MovSiBx|B (0DCH) END MovSiBx|'
  264. expect_red "audit_helpers catches MovSiBx emitting MOV SP,BX" \
  265. "MovSiBx" python3 tests/audit_helpers.py
  266. # CmpSiBx had the identical mistake, which is how you know a single fix is
  267. # not enough -- the same misreading was written twice.
  268. cp "$SAVED" Runtime.mod
  269. mutate Runtime.mod 's|B (39H) ; B (0DEH) END CmpSiBx|B (39H) ; B (0DCH) END CmpSiBx|'
  270. expect_red "audit_helpers catches CmpSiBx emitting CMP SP,BX" \
  271. "CmpSiBx" python3 tests/audit_helpers.py
  272. # --- 2. golden, and entry goldens ------------------------------------
  273. # MovDlAl was `88 C0` = MOV AL,AL instead of MOV DL,AL. This is the case that
  274. # motivated runtime.golden: the sweep stayed in sync, every branch target
  275. # stayed on a boundary, no entry's first bytes moved, and the size did not
  276. # change. The target helper was MovAlDh when this case was written, which is
  277. # the fourth way a case here can rot - see the note on `mutate` below.
  278. cp "$SAVED" Runtime.mod
  279. mutate Runtime.mod 's|PROCEDURE MovDlAl ; BEGIN B (88H) ; B (0C2H)|PROCEDURE MovDlAl ; BEGIN B (88H) ; B (0C0H)|'
  280. rebuild
  281. expect_red "runtime.golden catches MOV AL,AL" \
  282. "mov al,al" python3 tests/check_runtime.py "$DUMP"
  283. # initmem opened with the mis-emitted MovSiAx, so its entry golden was the
  284. # thing that noticed the prologue was a no-op.
  285. cp "$SAVED" Runtime.mod
  286. mutate Runtime.mod 's|B (0F0H) END MovSiAx|B (0C0H) END MovSiAx|'
  287. rebuild
  288. expect_red "check_runtime catches a broken initmem prologue" \
  289. "mov ax,ax" python3 tests/check_runtime.py "$DUMP"
  290. # --- 3. decode sweep / length ----------------------------------------
  291. # StDiDl was `88 97` = [BX+disp16],DL: mod=10, so the instruction needs a
  292. # disp16 it was not given, and the sweep loses sync two bytes later.
  293. cp "$SAVED" Runtime.mod
  294. mutate Runtime.mod 's|PROCEDURE StDiDl ; BEGIN B (88H) ; B (15H)|PROCEDURE StDiDl ; BEGIN B (88H) ; B (97H)|'
  295. rebuild
  296. expect_red "decode sweep catches a mod=10 byte move with no displacement" \
  297. "mov byte ptr \[bx+5b5fh\],dl" python3 tests/check_runtime.py "$DUMP"
  298. # --- 4. branch targets ------------------------------------------------
  299. # FixUp measures a rel8 from the end of the instruction, one byte past the
  300. # displacement field. Drop the +1 and every short branch lands one byte into
  301. # its target, which for a 3-byte instruction means the middle of it. The
  302. # bytes themselves are all perfectly well formed -- only the fixups are
  303. # wrong -- so this is the one failure mode the golden cannot be expected to
  304. # catch on its own.
  305. cp "$SAVED" Runtime.mod
  306. mutate Runtime.mod 's|rel := (t + 100H - (fix \[i\].place + 1)) MOD 100H|rel := (t + 100H - fix [i].place) MOD 100H|'
  307. rebuild
  308. expect_red "branch check catches rel8 fixups measured from the wrong byte" \
  309. "not an instruction boundary" \
  310. python3 tests/check_runtime.py "$DUMP"
  311. echo
  312. echo "== everything restored and green again"
  313. cp "$SAVED" Runtime.mod
  314. if rebuild; then
  315. if python3 tests/audit_helpers.py >/dev/null 2>&1 &&
  316. python3 tests/check_runtime.py "$DUMP" >/dev/null 2>&1; then
  317. echo " ok: both checks pass on the restored source"
  318. pass=$((pass + 1))
  319. else
  320. echo "NOT RESTORED: a check is red after restoring Runtime.mod"
  321. fail=$((fail + 1))
  322. fi
  323. else
  324. echo "NOT RESTORED: the runtime would not rebuild"
  325. fail=$((fail + 1))
  326. fi
  327. echo
  328. echo "== the mod=11 table (probe/modrm11.py)"
  329. # These mutate the probe's own sources, not the runtime, so there is no
  330. # rebuild in the loop. SAVED_PY / SAVED_S are taken at the top of this file,
  331. # beside the EXIT trap, so an interrupted run restores them too; each case
  332. # still puts them back here so the next one starts from the real table.
  333. M11="python3 tests/probe/modrm11.py"
  334. restore_probe () {
  335. cp "$SAVED_PY" tests/probe/modrm11.py
  336. cp "$SAVED_S" tests/probe/modrm11.s
  337. }
  338. # 1. one cell of the table moved
  339. mutate tests/probe/modrm11.py 's|"Si", "Di"\]$|"Bp", "Di"]|'
  340. expect_red "anchor pins a moved table cell" \
  341. "anchor ADD SI, 2" $M11
  342. restore_probe
  343. # 2. the table this project actually shipped: AX dropped off the front and a
  344. # duplicate BX invented at the end, which shifts every code down by one
  345. mutate tests/probe/modrm11.py 's|^REG = .*$|REG = ["Cx", "Dx", "Bx", "Sp", "Bp", "Si", "Di", "Bx"]|'
  346. expect_red "the table shifted by one (AX dropped, BX duplicated)" \
  347. "anchor MOV SP, BP" $M11
  348. restore_probe
  349. # 3. the .s edited to contradict the table. This is the case that shows why
  350. # the hard-coded EXPECT bytes exist: the assembler encodes the new claim
  351. # correctly, so comparing the .s against `as` alone can never fail here.
  352. mutate tests/probe/modrm11.s 's|movw %sp, %di # reg 100|movw %bp, %di # reg 100|'
  353. expect_red "probe source edited away from the recorded bytes" \
  354. "expected 89 E7" $M11
  355. restore_probe
  356. # 4. the 8-bit list edited, which is a different table from the word one
  357. mutate tests/probe/modrm11.s 's|movb %al, %dl # 88 C2 -> DL := AL|movb %al, %bl # was DL|'
  358. expect_red "the 8-bit register list edited" \
  359. "expected 88 C2" $M11
  360. restore_probe
  361. # 5. an anchor's recorded byte corrupted, so the anchor can no longer
  362. # corroborate itself
  363. mutate tests/probe/modrm11.py 's|"8B EC", "8B E5"|"8B ED", "8B E5"|'
  364. expect_red "anchor byte no longer matches the emitted code" \
  365. "expected 8B ED" $M11
  366. restore_probe
  367. if $M11 >/dev/null 2>&1; then
  368. echo " ok: modrm11.py passes on the restored probe sources"
  369. pass=$((pass + 1))
  370. else
  371. echo "NOT RESTORED: modrm11.py is red after restoring its sources"
  372. $M11 2>&1 | sed 's/^/ /'
  373. fail=$((fail + 1))
  374. fi
  375. echo
  376. echo "== the BP displacement rule (check_framedisp.py)"
  377. # This one is about Compiler.mod rather than the runtime, and it needs the
  378. # whole toolchain rebuilt (comtest, not rtprobe), so it gets its own rebuild.
  379. # SAVED_C itself is taken at the top of this file, beside the EXIT trap, so an
  380. # interrupted run restores Compiler.mod as well.
  381. rebuild_compiler () {
  382. $GM2 -fiso -c Compiler.mod >/dev/null 2>&1 || return 1
  383. $GM2 -fiso -fgen-module-list=tests/ct.lst -o /dev/null \
  384. tests/ComTest.mod TextBuf.o Posix.o Compiler.o Runtime.o Linker.o \
  385. >/dev/null 2>&1
  386. $GM2 -fiso -fuse-list=tests/ct.lst -o comtest \
  387. tests/ComTest.mod TextBuf.o Posix.o Compiler.o Runtime.o Linker.o \
  388. >/dev/null 2>&1 || return 1
  389. return 0
  390. }
  391. # 1. the original bug: `off MOD 100H`, always disp8. Restores the code that
  392. # was there before EmBpDisp existed. t28's [BP+128] read becomes [BP-128],
  393. # which is the failure this whole check is named after.
  394. #
  395. # regf is KEPT. It is the other half of EmBpDisp's job - the ModR/M reg
  396. # field, which the DI forms (regf 7) need - and it was added after this
  397. # case was written. Hard-coding 46H here again would break the DI forms at
  398. # the same time and turn one mutation into two faults; the check would
  399. # still go red, but for a reason the label does not name.
  400. python3 - "$SAVED_C" <<'PYEOF'
  401. import sys
  402. p = 'Compiler.mod'
  403. s = open(p).read()
  404. old = """ IF off <= 127 THEN
  405. Ebyte (VAL (BYTE, 40H + regf * 8 + 6H)) ; Ebyte (VAL (BYTE, off))
  406. ELSE
  407. Ebyte (VAL (BYTE, 80H + regf * 8 + 6H)) ; Eword (off)
  408. END
  409. END EmBpDisp ;"""
  410. new = """ Ebyte (VAL (BYTE, 40H + regf * 8 + 6H)) ; Ebyte (VAL (BYTE, off MOD 100H))
  411. END EmBpDisp ;"""
  412. assert old in s, "EmBpDisp body not found -- update this mutation"
  413. open(p, 'w').write(s.replace(old, new))
  414. PYEOF
  415. if rebuild_compiler; then
  416. expect_red "displacement truncation reads a different address" \
  417. "no 8B access at \[BP+128\]" python3 tests/check_framedisp.py
  418. else
  419. echo " FAIL: the compiler would not rebuild with the truncation"
  420. fail=$((fail + 1))
  421. fi
  422. cp "$SAVED_C" Compiler.mod
  423. # 2. the other half of the rule: always use the 4-byte form, ignoring the
  424. # <= 127 case. This is over-cautious rather than wrong, so the checker must
  425. # still be happy -- which is worth asserting, because a check that only
  426. # ever fails on a smaller encoding is a check that pins one answer instead
  427. # of the rule.
  428. python3 - <<'PYEOF'
  429. p = 'Compiler.mod'
  430. s = open(p).read()
  431. old = """ IF off <= 127 THEN
  432. Ebyte (VAL (BYTE, 40H + regf * 8 + 6H)) ; Ebyte (VAL (BYTE, off))
  433. ELSE
  434. Ebyte (VAL (BYTE, 80H + regf * 8 + 6H)) ; Eword (off)
  435. END"""
  436. new = """ Ebyte (VAL (BYTE, 80H + regf * 8 + 6H)) ; Eword (off)"""
  437. assert old in s, "EmBpDisp branch not found -- update this mutation"
  438. open(p, 'w').write(s.replace(old, new))
  439. PYEOF
  440. if rebuild_compiler; then
  441. if python3 tests/check_framedisp.py >/dev/null 2>&1; then
  442. echo " ok: always-disp16 is accepted, so the check pins the rule"
  443. echo " and not one particular encoding"
  444. pass=$((pass + 1))
  445. else
  446. echo " FAIL: check_framedisp rejects a safe, over-long encoding"
  447. python3 tests/check_framedisp.py 2>&1 | sed 's/^/ /'
  448. fail=$((fail + 1))
  449. fi
  450. else
  451. echo " FAIL: the compiler would not rebuild with always-disp16"
  452. fail=$((fail + 1))
  453. fi
  454. cp "$SAVED_C" Compiler.mod
  455. if rebuild_compiler; then
  456. if python3 tests/check_framedisp.py >/dev/null 2>&1; then
  457. echo " ok: check_framedisp passes on the restored source"
  458. pass=$((pass + 1))
  459. else
  460. echo "NOT RESTORED: check_framedisp is red after restoring Compiler.mod"
  461. python3 tests/check_framedisp.py 2>&1 | sed 's/^/ /'
  462. fail=$((fail + 1))
  463. fi
  464. else
  465. echo "NOT RESTORED: the compiler would not rebuild"
  466. fail=$((fail + 1))
  467. fi
  468. # --- the region check_framedisp sweeps, and the one file it comes from -----
  469. echo
  470. echo "== the image layout, measured once (tests/comimage.py)"
  471. # check_framedisp.py decodes instructions over a REGION of the image, and a
  472. # wrong region does not stop it: the byte patterns it searches for are in the
  473. # image wherever they happen to be, and a decode that starts mid-instruction
  474. # reached the same offsets anyway. That is how RT_SZ = 391 - a literal that had
  475. # drifted from the runtime it described - went on reporting PASS while its sweep
  476. # began inside the runtime, part way through an instruction. Nothing in the
  477. # check could see where its own region began.
  478. #
  479. # So the region is two independent readings of the file - where the entry jump
  480. # says execution starts, and where the program header says the runtime ends -
  481. # and the two must AGREE or the region is undetermined. Both readings, and the
  482. # layout itself, live in tests/comimage.py, which is also where comtest.py and
  483. # the independent checker in run_com_tests.sh now get the copy each of them
  484. # used to keep: a duplicated constant that has silently drifted is not an
  485. # independent check, it is a second source of truth that lies, and it lies in
  486. # the direction of looking like the code under test is broken.
  487. #
  488. # None of this needs a rebuild - comimage.py is Python the checkers import -
  489. # so these cases are cheap, and they turn the READERS red one at a time.
  490. # 1. entry_target answers with the literal the region used to be built from.
  491. # The two readings now disagree, and there is no measured region to sweep.
  492. python3 - <<'PYEOF'
  493. p = 'tests/comimage.py'
  494. s = open(p).read()
  495. old = ' return ENT_SZ + int.from_bytes(d[1:ENT_SZ], "little", signed=True)'
  496. new = ' return ENT_SZ + 391 # the literal RT_SZ was'
  497. assert s.count(old) == 1, "entry_target's return not found -- update this mutation"
  498. open(p, 'w').write(s.replace(old, new))
  499. PYEOF
  500. expect_red "a sweep region that is not where execution starts is rejected" \
  501. "neither region is swept" python3 tests/check_framedisp.py
  502. cp "$SAVED_CI" tests/comimage.py
  503. # 2 and 3. The header's own equation, one byte out, so the header cannot be
  504. # located at all - the case where a checker that fell back on a remembered
  505. # offset would report a confident number instead. Two readers, two
  506. # different sentences: each must say in its own words that it does not know
  507. # where the program's code begins.
  508. python3 - <<'PYEOF'
  509. p = 'tests/comimage.py'
  510. s = open(p).read()
  511. old = ' if w(HDR_DS_WORD) != DATA_IMAGE + LOAD_BIAS: # hdrDS'
  512. new = ' if w(HDR_DS_WORD) != DATA_IMAGE + LOAD_BIAS + 1: # hdrDS'
  513. assert s.count(old) == 1, "the hdrDS equation not found -- update this mutation"
  514. open(p, 'w').write(s.replace(old, new))
  515. PYEOF
  516. expect_red "check_framedisp reports a header it cannot locate" \
  517. "no program header found" python3 tests/check_framedisp.py
  518. expect_red "check_8086 reports the same unlocatable header" \
  519. "could not locate the code region" python3 tests/check_8086.py
  520. cp "$SAVED_CI" tests/comimage.py
  521. # 4-7. The single copy itself, now that there is one. A second find_header,
  522. # a second HDR_SZ, a caller that reaches the helper through another
  523. # consumer instead of through comimage, and - the case that exists
  524. # because of rt_exec.py's "matched nothing" lesson - the definition the
  525. # audit counts. A rule that matches nothing looks exactly like a rule
  526. # that passes, so a deleted definition must be a red report rather than a
  527. # silent green one.
  528. python3 - <<'PYEOF'
  529. p = 'tests/comtest.py'
  530. s = open(p).read()
  531. old = 'def check_com(path, expected_src_len):'
  532. new = ('def find_header(d):\n'
  533. ' return None # a second copy of the helper\n'
  534. '\n\n'
  535. 'def check_com(path, expected_src_len):')
  536. assert s.count(old) == 1, "check_com not found -- update this mutation"
  537. open(p, 'w').write(s.replace(old, new))
  538. PYEOF
  539. expect_red "the audit reports a find_header copied out of comimage" \
  540. "comtest.py defines its own find_header" python3 tests/check_comimage.py
  541. cp "$SAVED_T" tests/comtest.py
  542. python3 - <<'PYEOF'
  543. p = 'tests/comtest.py'
  544. s = open(p).read()
  545. old = 'from comimage import (ENT_SZ, HDR_SZ, LOAD_BIAS, DATA_IMAGE, HEAD,'
  546. new = ('HDR_SZ = 16 # a second copy of the layout\n'
  547. 'from comimage import (ENT_SZ, HDR_SZ, LOAD_BIAS, DATA_IMAGE, HEAD,')
  548. assert s.count(old) == 1, "the comimage import not found -- update this mutation"
  549. open(p, 'w').write(s.replace(old, new))
  550. PYEOF
  551. expect_red "the audit reports a layout constant defined elsewhere" \
  552. "comtest.py defines its own HDR_SZ" python3 tests/check_comimage.py
  553. cp "$SAVED_T" tests/comtest.py
  554. python3 - <<'PYEOF'
  555. p = 'tests/comimage.py'
  556. s = open(p).read()
  557. old = 'def find_header(d):'
  558. new = 'def _find_header(d): # the definition is gone'
  559. assert s.count(old) == 1, "def find_header not found -- update this mutation"
  560. open(p, 'w').write(s.replace(old, new))
  561. PYEOF
  562. expect_red "the audit counts its own subject rather than matching nothing" \
  563. "defines find_header 0 times" python3 tests/check_comimage.py
  564. cp "$SAVED_CI" tests/comimage.py
  565. # 7. The import dropped while the CALLS stay - the shape a refactor makes when
  566. # one reader starts taking the helper from another reader instead. It would
  567. # NameError the moment comtest ran, but the audit says so first, and in the
  568. # vocabulary of the layout rather than in the vocabulary of Python: the
  569. # failure this is guarding is "two sources of truth", not "undefined name".
  570. python3 - <<'PYEOF'
  571. p = 'tests/comtest.py'
  572. s = open(p).read()
  573. old = ('from comimage import (ENT_SZ, HDR_SZ, LOAD_BIAS, DATA_IMAGE, HEAD,\n'
  574. ' HDR_DS_WORD, HDR_HEAP_WORD, find_header)')
  575. new = '# MUTATION: the shared import is gone, but the calls remain\n'
  576. assert s.count(old) == 1, "the comimage import not found -- update this mutation"
  577. open(p, 'w').write(s.replace(old, new))
  578. PYEOF
  579. expect_red "the audit reports a caller that does not take it from comimage" \
  580. "comtest.py calls find_header without importing it from comimage" \
  581. python3 tests/check_comimage.py
  582. cp "$SAVED_T" tests/comtest.py
  583. # Green again, on all three readers at once: the case above mutated the one
  584. # file all of them import, so restoring it has to satisfy each of them, not
  585. # just the one that was last run.
  586. for c in tests/check_framedisp.py tests/check_comimage.py tests/check_8086.py; do
  587. if python3 "$c" >/dev/null 2>&1; then
  588. echo " ok: $c passes on the restored sources"
  589. pass=$((pass + 1))
  590. else
  591. echo "NOT RESTORED: $c is red after restoring comimage.py and comtest.py"
  592. python3 "$c" 2>&1 | tail -3 | sed 's/^/ /'
  593. fail=$((fail + 1))
  594. fi
  595. done
  596. # --- 3. the operator bugs the nine dead fixtures were hiding ------------
  597. echo
  598. echo "== the bugs the never-executed fixtures were hiding"
  599. echo
  600. # A different KIND of case from everything above. The others break the code
  601. # and assert a byte-level check notices; these break the code and assert a
  602. # BEHAVIOURAL check notices, which is the only kind that could have found them.
  603. # Each of the original four shipped with a green compile matrix, a passing .COM
  604. # layout check, a passing golden and a passing emitter audit:
  605. #
  606. # OpMul = 1 `a * b` emitted ADD AX,CX. `*' and `+' both numbered
  607. # their operator 1, and BinOpEmit cannot see which
  608. # precedence level called it, so every multiplication
  609. # dispatched to the addition. The constant-folding arm was
  610. # correct, which is why `n * n' with n a CONST was right and
  611. # `a * a' with a a variable was not -- and t08_const is the
  612. # only fixture that ever multiplied.
  613. # 9Dh / 9FH `>' got SETGE and `>=' got SETG: swapped, one letter
  614. # apart in the mnemonic. Only a==b could see it.
  615. # JNZ -> body REPEAT..UNTIL looped back while the condition was TRUE,
  616. # which is WHILE, so the body ran once and stopped.
  617. #
  618. # They are mutated back to the original defect and run_com_exec.py must go red
  619. # on the exact fixture that pins the behaviour. The fourth (HideLocals) is a
  620. # scoping bug rather than an operator bug; it was hiding in the same place.
  621. #
  622. # Two joined them when the operand-lifetime and `not' fixes landed, each run
  623. # red by hand before it was written down here, and each with the same property
  624. # as the four above -- green everywhere except execution:
  625. #
  626. # SaveLeft's park `(p > q) or (q > p)' evaluated `(q > p) or (q > p)'. A
  627. # kind-2 value exists only in AX, and the right operand's
  628. # code is emitted before the two are ever brought together,
  629. # so without the push the left one is simply gone.
  630. # neglevel's split `not' on a boolean emitted the INTEGER `not', which left
  631. # 0FFFEh where a boolean belongs, and wrbool reads anything
  632. # non-zero as TRUE -- so `not (a = a)' answered TRUE and so
  633. # did every other `not'.
  634. mutate_compiler () { # reuse mutate's verified-change discipline on Compiler.mod
  635. mf=Compiler.mod
  636. msed=$1
  637. cp "$SAVED_C" ../tmp/nonvacuity.mut2.bak
  638. sed -i "$msed" "$mf"
  639. if cmp -s "$mf" ../tmp/nonvacuity.mut2.bak; then
  640. echo " BROKEN CASE: the mutation did not change Compiler.mod"
  641. echo " sed: $msed"
  642. echo " the named code has probably been renamed or reformatted -"
  643. echo " fix this case, it is asserting nothing"
  644. fail=$((fail + 1))
  645. return 1
  646. fi
  647. return 0
  648. }
  649. # The SETcc swap and the HideLocals removal are done in python rather than
  650. # with sed: both need to match source text containing `*` and `(` in a way that
  651. # is tedious and fragile as a regex, and a case whose only failure mode is a
  652. # malformed sed is a case that silently asserts nothing.
  653. #
  654. # And a python helper fails in a way sed does not: a syntax error in the helper
  655. # is a non-zero exit, `if mutate_foo; then` is simply false, and the case is
  656. # SKIPPED -- with no failure counted and nothing on stdout but whatever python
  657. # printed. That is how the SETcc case spent its first run: an apostrophe in an
  658. # assert message ("the `>' arm") closed the string early, python died, the
  659. # compiler was never broken, and the suite still reported 0 failed. A skipped
  660. # case and a passing case look the same in the total. So each helper below
  661. # fails LOUDLY: a non-zero exit from python is reported as a BROKEN CASE and
  662. # counted, never swallowed.
  663. #
  664. # Each one also counts its targets before replacing. `assert s != before' only
  665. # says the file changed; with two edits it would pass if just one of them
  666. # landed, and with two identical HideLocals call sites it would happily delete
  667. # the wrong one -- still a changed file, still a working compiler, still green
  668. # for the wrong reason.
  669. mutate_cc_swap () {
  670. if python3 - <<'PYX'
  671. p = 'Compiler.mod'
  672. s = open(p).read()
  673. GT = 'EmSetcc (9FH) ; (* > SETG *)' # the greater-than arm
  674. GE = 'EmSetcc (9DH) ; (* >= SETGE *)' # the greater-equal arm
  675. assert s.count(GT) == 1, 'expected 1 greater-than arm, found %d' % s.count(GT)
  676. assert s.count(GE) == 1, 'expected 1 greater-equal arm, found %d' % s.count(GE)
  677. s = s.replace(GT, GT.replace('9FH', '9DH'))
  678. s = s.replace(GE, GE.replace('9DH', '9FH'))
  679. open(p, 'w').write(s)
  680. PYX
  681. then
  682. return 0
  683. fi
  684. echo " BROKEN CASE: the SETcc swap did not apply"
  685. echo " the two EmSetcc arms are probably renamed or reformatted -"
  686. echo " fix this case, it is asserting nothing"
  687. fail=$((fail + 1))
  688. return 1
  689. }
  690. mutate_no_hidelocals () {
  691. if python3 - <<'PYX'
  692. p = 'Compiler.mod'
  693. s = open(p).read()
  694. # Two HideLocals calls exist. Only the body-exit one may go: deleting the
  695. # FORWARD one instead would still change the file, still rebuild, and still
  696. # leave t13_proc compiling, so the case would go green for the wrong reason.
  697. HL = ' HideLocals (nestMark) ; (* parameters and locals stop here *)\n'
  698. assert s.count(HL) == 1, 'expected 1 body-exit HideLocals, found %d' % s.count(HL)
  699. open(p, 'w').write(s.replace(HL, ''))
  700. PYX
  701. then
  702. return 0
  703. fi
  704. echo " BROKEN CASE: HideLocals was not removed"
  705. echo " the call or its comment has probably been reformatted -"
  706. echo " fix this case, it is asserting nothing"
  707. fail=$((fail + 1))
  708. return 1
  709. }
  710. cp "$SAVED_C" Compiler.mod
  711. if mutate_compiler 's|^ op := OpMul ; DropCh| op := OpAdd ; DropCh|'; then
  712. if rebuild_compiler; then
  713. expect_red "execution catches '*' emitting an ADD (t08_const, n*n)" \
  714. "t08_const" python3 tests/run_com_exec.py t08_const
  715. # t08 only ever multiplied two CONSTANTS, which is the one path that was
  716. # never wrong, because BinOpEmit folds it. So the case above is close
  717. # to vacuous: it proves the mutation changed the binary, not that the
  718. # emitted multiply is covered. The check that matters needs a
  719. # VARIABLE operand, and no shipped fixture has one -- which is why the
  720. # bug survived at all. So this writes a throwaway fixture that
  721. # multiplies a variable, runs it, and asserts the multiply is right.
  722. # The fixture is deleted afterwards; it is here to close the coverage
  723. # hole, not to become a permanent test (that is what a real fixture
  724. # with a `*' in it would be for).
  725. cat > tests/fixtures/zzmul.pas <<'ZZEOF'
  726. program zzmul;
  727. var a : integer ;
  728. begin
  729. a := 7 ;
  730. writeln (a * 6)
  731. end.
  732. ZZEOF
  733. printf '42\r\n' > tests/fixtures/zzmul.out
  734. expect_red "execution catches '*' on a VARIABLE (the unfolded path)" \
  735. "zzmul" python3 tests/run_com_exec.py zzmul
  736. rm -f tests/fixtures/zzmul.pas tests/fixtures/zzmul.out
  737. else
  738. echo " FAIL: the compiler would not rebuild with OpAdd for '*'"
  739. fail=$((fail + 1))
  740. fi
  741. fi
  742. cp "$SAVED_C" Compiler.mod
  743. cp "$SAVED_C" Compiler.mod
  744. if mutate_cc_swap; then
  745. if rebuild_compiler; then
  746. expect_red "execution catches '>' and '>=' swapped (t09_if)" \
  747. "t09_if" python3 tests/run_com_exec.py t09_if
  748. else
  749. echo " FAIL: the compiler would not rebuild with the SETcc swap"
  750. fail=$((fail + 1))
  751. fi
  752. fi
  753. cp "$SAVED_C" Compiler.mod
  754. cp "$SAVED_C" Compiler.mod
  755. if mutate_compiler 's| DropC (EmJcc (84H, L1)) ; (\* JZ -> body again \*)| zj := EmJcc (85H, L1) ;|'; then
  756. if rebuild_compiler; then
  757. expect_red "execution catches REPEAT..UNTIL exiting after one pass (t12)" \
  758. "t12_repeat" python3 tests/run_com_exec.py t12_repeat
  759. else
  760. echo " FAIL: the compiler would not rebuild with the JNZ repeat"
  761. fail=$((fail + 1))
  762. fi
  763. fi
  764. cp "$SAVED_C" Compiler.mod
  765. # The fourth: sibling procedures shared one parameter namespace, because a
  766. # finished procedure's symbols were left at a level Search still accepts.
  767. # Removing HideLocals puts two procedures' `a : integer' back in collision.
  768. cp "$SAVED_C" Compiler.mod
  769. if mutate_no_hidelocals; then
  770. if rebuild_compiler; then
  771. expect_red "a duplicate parameter in two procedures is a compile error again" \
  772. "ERROR 41" python3 tests/run_com_exec.py t13_proc
  773. else
  774. echo " FAIL: the compiler would not rebuild without HideLocals"
  775. fail=$((fail + 1))
  776. fi
  777. else
  778. echo " FAIL: could not remove HideLocals to test the scoping fix"
  779. fail=$((fail + 1))
  780. fi
  781. # M6: the LEFT operand, parked for the right one. kind 2 means "this value
  782. # exists in AX and nowhere else", and the right-hand operand's code is emitted
  783. # between recognizing the operator and using both operands - so without
  784. # SaveLeft's push the left value is overwritten before it is ever read, and
  785. # LoadPair's kind-4 shape can never trigger. `(p > q) or (q > p)' then
  786. # evaluates `(q > p) or (q > p)'. Every byte, every size and the whole compile
  787. # matrix stay green: nothing is malformed, the value is simply the wrong one.
  788. cp "$SAVED_C" Compiler.mod
  789. if python3 - <<'PYX'
  790. p = 'Compiler.mod'
  791. s = open(p).read()
  792. # Both guards are matched, and each must be unique. `IF left.kind = 2 THEN'
  793. # reads like it can only be SaveLeft's, but LoadAtom and friends also branch
  794. # on kind, so an unasserted replace could disable one of THEM instead and the
  795. # case would still go red - for a reason the label does not name.
  796. #
  797. # The kind-5 ("a string element whose address is in DI") guard did not exist
  798. # when this case was written; it arrived with `s[i]`. Making only the kind-2
  799. # park unreachable would leave that one alive, so the mutation would no longer
  800. # be "SaveLeft parks nothing" - it would be a half-disabled SaveLeft, and the
  801. # case would be testing something narrower than it says.
  802. g2 = ' IF left.kind = 2 THEN\n'
  803. g5 = ' ELSIF left.kind = 5 THEN\n'
  804. assert s.count(g2) == 1, 'the kind-2 guard found %d times -- update this mutation' % s.count(g2)
  805. assert s.count(g5) == 1, 'the kind-5 guard found %d times -- update this mutation' % s.count(g5)
  806. s = s.replace(g2, ' IF left.kind = 99 THEN\n')
  807. s = s.replace(g5, ' ELSIF left.kind = 99 THEN\n')
  808. open(p, 'w').write(s)
  809. PYX
  810. then
  811. if rebuild_compiler; then
  812. expect_red "execution catches a left operand clobbered by the right one" \
  813. "t34_arith" python3 tests/run_com_exec.py t34_arith
  814. else
  815. echo " FAIL: the compiler would not rebuild without SaveLeft's push"
  816. fail=$((fail + 1))
  817. fi
  818. else
  819. echo " BROKEN CASE: the SaveLeft mutation did not apply"
  820. fail=$((fail + 1))
  821. fi
  822. cp "$SAVED_C" Compiler.mod
  823. # M7: the type split in TPSRC9's neglevel, wrong half. A boolean NOT lowered
  824. # as the INTEGER one leaves 0FFFEh/0FFFFh, and wrbool tests [BP+4] <> 0 - so
  825. # `not (a = a)' answers TRUE, and so does every other `not'. One instruction,
  826. # same length, same sizes, and the compile matrix cannot see it because both
  827. # halves emit well-formed code for a type the parser already accepted.
  828. cp "$SAVED_C" Compiler.mod
  829. if python3 - <<'PYX'
  830. p = 'Compiler.mod'
  831. s = open(p).read()
  832. old = """ IF r.cls = TBool THEN
  833. LoadAtom (r) ;
  834. EmXorAl01 () ;"""
  835. new = """ IF r.cls = TBool THEN
  836. LoadAtom (r) ;
  837. EmNotAx () ; (* MUTATION: integer NOT on a boolean *)"""
  838. assert s.count(old) == 1, 'the TBool arm of ParseNeg found %d times -- update this mutation' % s.count(old)
  839. open(p, 'w').write(s.replace(old, new))
  840. PYX
  841. then
  842. if rebuild_compiler; then
  843. expect_red "execution catches a boolean NOT lowered as an integer one" \
  844. "t35_not" python3 tests/run_com_exec.py t35_not
  845. else
  846. echo " FAIL: the compiler would not rebuild with EmNotAx for a boolean"
  847. fail=$((fail + 1))
  848. fi
  849. else
  850. echo " BROKEN CASE: the neglevel type-split mutation did not apply"
  851. fail=$((fail + 1))
  852. fi
  853. cp "$SAVED_C" Compiler.mod
  854. # Bug 36, argument order: the fix has FOUR independent halves - three parsers
  855. # that push each argument the moment it is parsed instead of after the whole
  856. # list, and the callee that reads its parameters backwards from BP+4 - and
  857. # t36_argclobber is the one fixture that tells them apart. Before these four
  858. # cases existed, its only proof was the pre-fix run quoted in the commit
  859. # message, which is a fact about the past rather than a check: it cannot be
  860. # re-derived, and nothing stops the four halves from drifting apart.
  861. #
  862. # Each revert below was run to a red BEFORE it was written here, and the four
  863. # fail on four DIFFERENT rows, which is what makes them four cases and not one
  864. # wearing four hats: the callee revert turns `5 3 7' into `7 3 5' (every
  865. # argument lands on its neighbour's parameter), the deferred ParseCallArgs
  866. # zeroes the rows built from computed arguments, ParseCall changes the
  867. # function call's result (19 -> 10) and IoCall changes the last write
  868. # (`FALSE 1' -> `TRUE 544', the first argument printed as the second
  869. # argument's value). A revert that left t36 green is reported by expect_red
  870. # as NOT NON-VACUOUS; a revert that did not land is a BROKEN CASE.
  871. # revert_procedure <name> -- put <name> back the way it was before bug 36 was
  872. # fixed, spliced out of the tree the fix landed on top of. The old code's
  873. # source of truth is the old code: quoting a copy of it in this file is a copy
  874. # that can drift from the tag it claims to reproduce, and a revert that
  875. # reproduces nothing is a case asserting nothing.
  876. revert_procedure () {
  877. python3 - "$1" <<'PYX'
  878. import subprocess, sys
  879. name = sys.argv[1]
  880. cur = open('Compiler.mod').read()
  881. r = subprocess.run(['git', 'show', 'v-TP3-IMAGELAYOUT:shell/Compiler.mod'],
  882. capture_output=True)
  883. assert r.returncode == 0, 'cannot read the pre-fix tree: %s' % r.stderr.decode()[:200]
  884. pre = r.stdout.decode()
  885. def span(text, where):
  886. # The DEFINITION, not the FORWARD declaration a few screens earlier: the
  887. # anchor runs to the end of the line, and a FORWARD line ends `FORWARD ;'
  888. # instead of nothing.
  889. a, b = 'PROCEDURE %s (idx : CARDINAL) ;\n' % name, 'END %s ;' % name
  890. na, nb = text.count(a), text.count(b)
  891. assert na == 1 and nb == 1, \
  892. '%s: %d definitions, %d ends in %s -- update this case' % (name, na, nb, where)
  893. i = text.index(a)
  894. j = text.index(b, i) + len(b)
  895. return text[i:j], i, j
  896. new, i, j = span(cur, 'Compiler.mod')
  897. old, _, _ = span(pre, 'the pre-fix tree')
  898. assert old != new, 'the pre-fix %s is identical to the current one' % name
  899. open('Compiler.mod', 'w').write(cur[:i] + old + cur[j:])
  900. PYX
  901. }
  902. # The callee half: no remap, so parameters are read in declaration order from
  903. # BP+4 while the arguments are pushed in parse order - the FIRST argument ends
  904. # up in the LAST parameter's slot, and one-argument calls (all of
  905. # Runtime.mod's own cases) cannot tell the two layouts apart.
  906. cp "$SAVED_C" Compiler.mod
  907. if python3 - <<'PYX'
  908. p = 'Compiler.mod'
  909. s = open(p).read()
  910. old = """ i := nestMark ;
  911. WHILE i < symTop DO
  912. symtab [i].off := 8 + (parmOff - 4) - symtab [i].off
  913. - ParamSlotBytes (symtab [i]) ;
  914. INC (i)
  915. END ;
  916. """
  917. assert s.count(old) == 1, 'the ProcFunc parameter remap found %d times -- update this mutation' % s.count(old)
  918. open(p, 'w').write(s.replace(old, ''))
  919. PYX
  920. then
  921. if rebuild_compiler; then
  922. expect_red "t36 catches the callee laid out in declaration order (no remap)" \
  923. "t36_argclobber" python3 tests/run_com_exec.py t36_argclobber
  924. else
  925. echo " FAIL: the compiler would not rebuild without the parameter remap"
  926. fail=$((fail + 1))
  927. fi
  928. else
  929. echo " BROKEN CASE: the ProcFunc remap mutation did not apply"
  930. fail=$((fail + 1))
  931. fi
  932. cp "$SAVED_C" Compiler.mod
  933. # The caller half, site 1 of 3: a call used as a statement. The old code
  934. # read the whole list into args[] and pushed it backwards afterwards, so a
  935. # computed argument (which exists only in AX) was gone before the push loop
  936. # reached it.
  937. cp "$SAVED_C" Compiler.mod
  938. if revert_procedure ParseCallArgs; then
  939. if rebuild_compiler; then
  940. expect_red "t36 catches ParseCallArgs pushing after the whole list" \
  941. "t36_argclobber" python3 tests/run_com_exec.py t36_argclobber
  942. else
  943. echo " FAIL: the compiler would not rebuild with ParseCallArgs deferred"
  944. fail=$((fail + 1))
  945. fi
  946. else
  947. echo " BROKEN CASE: the ParseCallArgs revert did not apply"
  948. fail=$((fail + 1))
  949. fi
  950. cp "$SAVED_C" Compiler.mod
  951. # Site 2 of 3: the same call reached from ParseAtom, when a FUNCTION is
  952. # called inside an expression. A separate site, because it is a separate
  953. # procedure - and t36's `19' row is the only thing that notices this one.
  954. cp "$SAVED_C" Compiler.mod
  955. if revert_procedure ParseCall; then
  956. if rebuild_compiler; then
  957. expect_red "t36 catches ParseCall pushing after the whole list" \
  958. "t36_argclobber" python3 tests/run_com_exec.py t36_argclobber
  959. else
  960. echo " FAIL: the compiler would not rebuild with ParseCall deferred"
  961. fail=$((fail + 1))
  962. fi
  963. else
  964. echo " BROKEN CASE: the ParseCall revert did not apply"
  965. fail=$((fail + 1))
  966. fi
  967. cp "$SAVED_C" Compiler.mod
  968. # Site 3 of 3: write/writeln/read/readln, where the argument list is also
  969. # where an inline string literal gets its call. Reverting this procedure
  970. # also reverts the per-argument dispatch inside it (the BYTE read landed
  971. # here), which is harmless for t36 and is why the splice is the whole
  972. # procedure rather than the push alone: half a revert is a state the tree
  973. # was never in.
  974. cp "$SAVED_C" Compiler.mod
  975. if revert_procedure IoCall; then
  976. if rebuild_compiler; then
  977. expect_red "t36 catches IoCall printing the last argument's value" \
  978. "t36_argclobber" python3 tests/run_com_exec.py t36_argclobber
  979. else
  980. echo " FAIL: the compiler would not rebuild with IoCall's loops split"
  981. fail=$((fail + 1))
  982. fi
  983. else
  984. echo " BROKEN CASE: the IoCall revert did not apply"
  985. fail=$((fail + 1))
  986. fi
  987. cp "$SAVED_C" Compiler.mod
  988. # The boolean read (t38): TP3 refuses `readln (b)' with error 66 - prderrtp
  989. # rejects the whole class and the runtime has no xrdbool - and this compiler
  990. # used to accept it and dispatch to rdbool, which stores a WORD into the
  991. # one-byte variable, its second byte landing on the variable AFTER b (t37's
  992. # overflow, unobserved only because no fixture read a boolean). The fix is
  993. # one arm of IoCall's type dispatch, so the mutation restores exactly that
  994. # arm. The check is the COMPILE MATRIX rather than any run: an ERR fixture
  995. # is never executed, so nothing that runs programs on it can see a refusal.
  996. cp "$SAVED_C" Compiler.mod
  997. if python3 - <<'PYX'
  998. p = 'Compiler.mod'
  999. s = open(p).read()
  1000. old = """ ELSIF acls = TBool THEN
  1001. (* TP3 refuses boolean I/O: TPSRC8 prderrtp is error 66,
  1002. "I/O not allowed here", and the runtime has no xrdbool
  1003. at all. rdbool stores a WORD, so one byte of an
  1004. accepted read would land on the variable AFTER b - the
  1005. exact overflow t37_readbyte pins for a byte. TP3's
  1006. answer to the whole class is the error; so is ours. *)
  1007. Err (EIoHere) ;
  1008. RETURN"""
  1009. assert s.count(old) == 1, 'the boolean-read error arm found %d times -- update this mutation' % s.count(old)
  1010. rep = """ ELSIF acls = TBool THEN
  1011. ent := TU_RdBool"""
  1012. open(p, 'w').write(s.replace(old, rep))
  1013. PYX
  1014. then
  1015. if rebuild_compiler; then
  1016. expect_red "t38 red when a boolean read dispatches to TU_RdBool" \
  1017. "t38_readbool" tests/run_compile_tests.sh
  1018. else
  1019. echo " FAIL: the compiler would not rebuild with the boolean read accepted"
  1020. fail=$((fail + 1))
  1021. fi
  1022. else
  1023. echo " BROKEN CASE: the boolean-read mutation did not apply"
  1024. fail=$((fail + 1))
  1025. fi
  1026. cp "$SAVED_C" Compiler.mod
  1027. # The string variable (t39). A STRING is the first declared type bigger than
  1028. # a word that this compiler accepts, and it is accepted in two places: DefVar
  1029. # exempts TString from its `size > 2' catch-all so `var s : string [10]' can
  1030. # exist at all, and the two arms below USE it once it does. The three
  1031. # mutations are the three places the feature lives, each restored to the
  1032. # exact pre-fix state (all three used to be ENoLib, or never existed):
  1033. #
  1034. # 1. the DEPARSE of assignment: before the fix, `s := 'hello'' fell out of
  1035. # Assignment's size check. Removing the string arm puts it back there.
  1036. # 2. the WRITE: before the fix, `writeln (s)' was refused by IoCall's
  1037. # type dispatch. Restoring the refusal arm is removing the feature.
  1038. # 3. the RUNTIME: wrstr's print loop is only as good as its length byte,
  1039. # and only rt_exec.py can see a wrstr that reads no length at all.
  1040. # 1. Assignment's string arm is gone, so `s := 'hello'' trips the old
  1041. # `size > 2' refusal again. The arm is spliced between its guard and the
  1042. # `size > 2' check that follows it, so a comment inside cannot break the
  1043. # match - but the GUARD is matched by text, and it has to be the whole
  1044. # guard. It grew an `AND (r.cls = TString)' when `s[i] := c' made a
  1045. # TString destination reach a second arm, and ParseSub grew a look-alike
  1046. # `IF symtab [r.idx].cls = TString THEN' for `s[i]'. The shorter anchor
  1047. # therefore now finds ParseSub's, some 800 lines earlier, and the splice
  1048. # below deletes everything between the two - which does not test the
  1049. # refusal, it tests whether the compiler still compiles. Hence the assert
  1050. # and the spelled-out guard.
  1051. cp "$SAVED_C" Compiler.mod
  1052. if python3 - <<'PYX'
  1053. p = 'Compiler.mod'
  1054. s = open(p).read()
  1055. g = ' IF (r.cls = TString) AND (VarSize (r) > 1) THEN\n'
  1056. assert s.count(g) == 1, 'the string-assignment guard found %d times' % s.count(g)
  1057. a = s.index(g)
  1058. m = ' RETURN\n END ;\n IF (r.kind = 5) OR (VarSize (r) > 2) THEN\n'
  1059. i = s.index(m, a)
  1060. new = g + ' Err (ENoLib) ; (* MUTATION: the arm is refused *)\n RETURN\n'
  1061. open(p, 'w').write(s[:a] + new + s[i + len(' RETURN\n'):])
  1062. PYX
  1063. then
  1064. if rebuild_compiler; then
  1065. expect_red "t39 red when the string-assignment arm is refused" \
  1066. "t39_strvar" tests/run_compile_tests.sh
  1067. else
  1068. echo " FAIL: the compiler would not rebuild with the string assignment refused"
  1069. fail=$((fail + 1))
  1070. fi
  1071. else
  1072. echo " BROKEN CASE: the string-assignment mutation did not apply"
  1073. fail=$((fail + 1))
  1074. fi
  1075. cp "$SAVED_C" Compiler.mod
  1076. # 2. The write arm of IoCall, restored to its pre-fix refusal.
  1077. cp "$SAVED_C" Compiler.mod
  1078. if python3 - <<'PYX'
  1079. p = 'Compiler.mod'
  1080. s = open(p).read()
  1081. old = """ IF arg.kind = 5 THEN
  1082. EmPushDi ()
  1083. ELSIF symtab [arg.idx].isVar THEN
  1084. (* VAR string: the slot holds the address of the
  1085. caller's characters; push that, not the slot. *)
  1086. EmLoadVar (TRUE, symtab [arg.idx].off, 2) ;
  1087. EmPushAx ()
  1088. ELSE
  1089. EmPushVarAddr (symtab [arg.idx].local,
  1090. (symtab [arg.idx].off + arg.boff) MOD 10000H)
  1091. END ;
  1092. ent := TU_WrStr"""
  1093. assert s.count(old) == 1, 'the string-write arm found %d times -- update this mutation' % s.count(old)
  1094. rep = """ Err (ENoLib) ;
  1095. RETURN"""
  1096. open(p, 'w').write(s.replace(old, rep))
  1097. PYX
  1098. then
  1099. if rebuild_compiler; then
  1100. expect_red "t39 red when a string write is refused again (ENoLib)" \
  1101. "t39_strvar" tests/run_compile_tests.sh
  1102. else
  1103. echo " FAIL: the compiler would not rebuild with the string write refused"
  1104. fail=$((fail + 1))
  1105. fi
  1106. else
  1107. echo " BROKEN CASE: the string-write mutation did not apply"
  1108. fail=$((fail + 1))
  1109. fi
  1110. cp "$SAVED_C" Compiler.mod
  1111. # 3. The runtime half: wrstr never reads the length byte, so every string -
  1112. # "hello" and the empty one alike - prints nothing. The compiler, the
  1113. # golden and the audit all stay green; only executing the entry finds it.
  1114. cp "$SAVED" Runtime.mod
  1115. if python3 - <<'PYX'
  1116. p = 'Runtime.mod'
  1117. s = open(p).read()
  1118. old = """ MovBxBp4 ; (* BX := the caller's string address *)
  1119. XorCxCx ;
  1120. MovClBx ; (* CX := the length byte at [BX] *)"""
  1121. assert s.count(old) == 1, 'the wrstr length load found %d times -- update this mutation' % s.count(old)
  1122. rep = """ MovBxBp4 ; (* BX := the caller's string address *)
  1123. XorCxCx ; (* CX is never loaded: prints nothing *)"""
  1124. open(p, 'w').write(s.replace(old, rep))
  1125. PYX
  1126. then
  1127. if rebuild; then
  1128. expect_red "the runtime cases catch a wrstr that reads no length" \
  1129. "wrstr" python3 tests/rt_exec.py
  1130. else
  1131. echo " FAIL: the runtime would not rebuild with the length load dropped"
  1132. fail=$((fail + 1))
  1133. fi
  1134. else
  1135. echo " BROKEN CASE: the wrstr length-load mutation did not apply"
  1136. fail=$((fail + 1))
  1137. fi
  1138. cp "$SAVED" Runtime.mod
  1139. # Re-emit the object: the `rebuild` above compiled Runtime.o from the MUTATED
  1140. # source, and the restored-compiler check next links that object - without
  1141. # this recompile it would report on the mutation, not on the restored code.
  1142. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1 || {
  1143. echo " FAIL: Runtime.mod would not recompile after the restore"
  1144. fail=$((fail + 1))
  1145. }
  1146. if rebuild_compiler; then
  1147. if python3 tests/run_com_exec.py >/dev/null 2>&1; then
  1148. # No count: the matrix grows every time a fixture is added, and a
  1149. # number here would be right only until the next one.
  1150. echo " ok: every executed fixture passes on the restored compiler"
  1151. pass=$((pass + 1))
  1152. else
  1153. echo "NOT RESTORED: run_com_exec.py is red after restoring Compiler.mod"
  1154. python3 tests/run_com_exec.py 2>&1 | grep -i fail | head -3 | sed 's/^/ /'
  1155. fail=$((fail + 1))
  1156. fi
  1157. else
  1158. echo "NOT RESTORED: the compiler would not rebuild"
  1159. fail=$((fail + 1))
  1160. fi
  1161. echo
  1162. echo "== the string READ and ASSIGNMENT entries (t40, t41)"
  1163. # t39 above gave a STRING variable a frame and printed it. This milestone puts
  1164. # one on the RECEIVING end of the two operations that move data into a string
  1165. # and between two strings - readln(s)/read(s), and s := t - and each one is
  1166. # three things at once: a compiler arm that chooses a runtime entry, the
  1167. # convention that carries the limit, and the entry itself. The cases below
  1168. # break each of the six in turn. Every mutation is a fault, or a plausible
  1169. # neighbour of one, that was run to a red BY HAND before it was written here.
  1170. #
  1171. # The frame rule is the odd one out: it is not a new entry at all, but a
  1172. # pre-existing compiler bug that only this milestone could reach. A local
  1173. # STRING was packed with the INTEGER rule - the symbol took the pre-decrement
  1174. # locFree, so a string[5] local sat at BP-2 and its characters grew UP into
  1175. # BP+3, over the saved BP at [BP] and the return address at [BP+2]. `readln(s)'
  1176. # into such a local stored 'hello' over its own return address, and t40 then ran
  1177. # the string's own bytes as an address: Exec86 said `fault at IP=0x6F6C', which
  1178. # is 'l','o'. The fix packs locals top-anchored, so the first INTEGER (size 2)
  1179. # is still at -2 - byte for byte what the old rule produced - while a string[5]
  1180. # (size 6) goes to -6..-1, inside the frame. t39's size (217) and t40's
  1181. # behaviour are the two independent things that pin it.
  1182. # --- the two runtime entries ---------------------------------------------
  1183. # rdstr stored the first character where the length byte belongs, because the
  1184. # IncSi that steps SI past dest[0] was missing. The length byte then
  1185. # overwrote it: `hello' read back as 05 65 6c 6c 6f. Same length, same sizes,
  1186. # and the whole compile matrix stays green - only rt_exec.py's byte dump can
  1187. # see it.
  1188. cp "$SAVED" Runtime.mod
  1189. if python3 - <<'PYX'
  1190. p = 'Runtime.mod'
  1191. lines = open(p).read().split('\n')
  1192. out, i, n = [], 0, 0
  1193. while i < len(lines):
  1194. if lines[i].startswith(' IncSi ;') and 'dest + 1' in lines[i]:
  1195. out.append(' (* MUTATION: the IncSi that puts chars at dest+1 is gone *)')
  1196. i += 1
  1197. while i < len(lines) and not lines[i].rstrip().endswith('*)'):
  1198. i += 1
  1199. i += 1
  1200. n += 1
  1201. continue
  1202. out.append(lines[i])
  1203. i += 1
  1204. assert n == 1, 'the rdstr IncSi found %d times -- update this mutation' % n
  1205. open(p, 'w').write('\n'.join(out))
  1206. PYX
  1207. then
  1208. if rebuild; then
  1209. expect_red "rt_exec catches rdstr storing its first character at dest[0]" \
  1210. "rdstr reads a line into a string" python3 tests/rt_exec.py
  1211. else
  1212. echo " FAIL: the runtime would not rebuild with rdstr's IncSi removed"
  1213. fail=$((fail + 1))
  1214. fi
  1215. else
  1216. echo " BROKEN CASE: the rdstr IncSi mutation did not apply"
  1217. fail=$((fail + 1))
  1218. fi
  1219. cp "$SAVED" Runtime.mod
  1220. # strstore's empty-source guard. A source of length 0 sets CX := 0, and LOOP
  1221. # with CX = 0 runs 65536 times rather than zero - so `s := ''' copied 64K,
  1222. # wrapped the segment, and walked through the driver's own case record. That is
  1223. # why the pattern below matches the CASE, not a byte count: rt_exec.py reports
  1224. # this one as a malformed record, which is the honest shape of "the entry wrote
  1225. # where it had no business writing".
  1226. if python3 - <<'PYX'
  1227. p = 'Runtime.mod'
  1228. lines = open(p).read().split('\n')
  1229. out, i, n = [], 0, 0
  1230. while i < len(lines):
  1231. if lines[i].startswith(' Jcxz8 ("ss_done")'):
  1232. out.append(' (* MUTATION: the empty-source guard is gone *)')
  1233. i += 1
  1234. while i < len(lines) and not lines[i].rstrip().endswith('*)'):
  1235. i += 1
  1236. i += 1
  1237. n += 1
  1238. continue
  1239. out.append(lines[i])
  1240. i += 1
  1241. assert n == 1, 'the strstore Jcxz8 found %d times -- update this mutation' % n
  1242. open(p, 'w').write('\n'.join(out))
  1243. PYX
  1244. then
  1245. if rebuild; then
  1246. expect_red "rt_exec catches a strstore that runs LOOP with CX=0" \
  1247. "strstore copies an empty string" python3 tests/rt_exec.py
  1248. else
  1249. echo " FAIL: the runtime would not rebuild with the empty-source guard removed"
  1250. fail=$((fail + 1))
  1251. fi
  1252. else
  1253. echo " BROKEN CASE: the strstore empty-source guard mutation did not apply"
  1254. fail=$((fail + 1))
  1255. fi
  1256. cp "$SAVED" Runtime.mod
  1257. # Re-emit the object: `rebuild` above compiled Runtime.o from the MUTATED
  1258. # source, and the compiler rebuild below links that object - without this
  1259. # recompile the restored-compiler check at the end would report on the mutation.
  1260. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1 || {
  1261. echo " FAIL: Runtime.mod would not recompile after the restore"
  1262. fail=$((fail + 1))
  1263. }
  1264. # --- the frame rule -------------------------------------------------------
  1265. # The pre-fix layout, exactly: the symbol took locFree itself instead of its
  1266. # top, and the frame began at 0FFFEh. For INTEGER locals that is byte-for-byte
  1267. # the same -2, -4, ... the new rule produces, which is why the old rule survived
  1268. # so long unnoticed; for a STRING it puts characters where the return address
  1269. # is. Two independent readers go red together, so both are asserted: the
  1270. # compile matrix pins the LAYOUT (t39's code size drops 217 -> 215), and t40
  1271. # pins that the program RUNS (with the overlap its readln never sees the line
  1272. # terminator and the machine hangs).
  1273. cp "$SAVED_C" Compiler.mod
  1274. if python3 - <<'PYX'
  1275. p = 'Compiler.mod'
  1276. s = open(p).read()
  1277. a = '(locFree - size + 1) MOD 10000H'
  1278. assert s.count(a) == 2, 'the top-anchored base found %d times -- update this mutation' % s.count(a)
  1279. s = s.replace(a, 'locFree') # the old pre-decrement base
  1280. b = 'locFree := 0FFFFH ;'
  1281. assert s.count(b) == 2, 'the frame top found %d times -- update this mutation' % s.count(b)
  1282. s = s.replace(b, 'locFree := 0FFFEH ;') # the old starting point
  1283. open(p, 'w').write(s)
  1284. PYX
  1285. then
  1286. if rebuild_compiler; then
  1287. expect_red "the compile matrix catches a local string packed over the frame" \
  1288. "expected: OK 222" tests/run_compile_tests.sh
  1289. expect_red "t40 red when readln into a local string overwrites its return address" \
  1290. "never halted" python3 tests/run_com_exec.py t40_readln
  1291. else
  1292. echo " FAIL: the compiler would not rebuild with the old frame layout"
  1293. fail=$((fail + 1))
  1294. fi
  1295. else
  1296. echo " BROKEN CASE: the frame-layout revert did not apply"
  1297. fail=$((fail + 1))
  1298. fi
  1299. cp "$SAVED_C" Compiler.mod
  1300. # --- the MBF integer conversion's exponent base ---------------------------
  1301. # intreal starts with exponent 90h for a value whose top byte is set; one less
  1302. # and every real_from_int result carries the wrong exponent. rt_exec compares
  1303. # the six emitted bytes against CALC-PORT.md's measured table, so this is a
  1304. # behavioural case, not a byte-golden one.
  1305. cp "$SAVED" Runtime.mod
  1306. if mutate Runtime.mod 's| MovAxImm (0090H)| MovAxImm (008FH)|'; then
  1307. if "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1; then
  1308. expect_red "real_from_int red when the exponent base is 8Fh" \
  1309. "real_from_int" python3 tests/rt_exec.py
  1310. else
  1311. echo " FAIL: the runtime would not rebuild with the wrong base"
  1312. fail=$((fail + 1))
  1313. fi
  1314. else
  1315. echo " BROKEN CASE: the MBF exponent-base mutation did not apply"
  1316. fail=$((fail + 1))
  1317. fi
  1318. cp "$SAVED" Runtime.mod
  1319. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1
  1320. # --- the MBF sign is stored, not XORed into DH --------------------------
  1321. # XorDataDh is `30 36' (memory destination). Encoding it as `32 36' makes it
  1322. # XOR DH with the saved sign instead, which leaves the result with the
  1323. # operand's fraction bits (the bug found while transcribing readd). The
  1324. # real_add/real_sub cases compare exact bytes.
  1325. cp "$SAVED" Runtime.mod
  1326. if mutate Runtime.mod 's|BEGIN B (30H) ; B (36H) ; Dd (delta) END XorDataDh|BEGIN B (32H) ; B (36H) ; Dd (delta) END XorDataDh|'; then
  1327. if "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1; then
  1328. expect_red "real_add red when the sign is XORed into DH, not memory" \
  1329. "real_add" python3 tests/rt_exec.py
  1330. else
  1331. echo " FAIL: the runtime would not rebuild with the XOR direction wrong"
  1332. fail=$((fail + 1))
  1333. fi
  1334. else
  1335. echo " BROKEN CASE: the MBF XOR-direction mutation did not apply"
  1336. fail=$((fail + 1))
  1337. fi
  1338. cp "$SAVED" Runtime.mod
  1339. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1
  1340. # --- JccNear jumps when the condition HOLDS ------------------------------
  1341. # The near form is an INVERSE Jcc over an E9. Putting the condition back
  1342. # unchanged makes remult's `b = 0 ?' test jump when b is NON-zero, so every
  1343. # product becomes zero. The rt_exec real_mul cases compare exact bytes.
  1344. cp "$SAVED" Runtime.mod
  1345. if python3 - <<'PYX'
  1346. p = 'Runtime.mod'
  1347. s = open(p).read()
  1348. old = """ IF (code MOD 2) = 0 THEN
  1349. B (code + 1)
  1350. ELSE
  1351. B (code - 1)
  1352. END ;"""
  1353. assert s.count(old) == 1, 'the JccNear inverse found %d times' % s.count(old)
  1354. open(p, 'w').write(s.replace(old, ' B (code) ;'))
  1355. PYX
  1356. then
  1357. if "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1; then
  1358. expect_red "real_mul red when JccNear uses the raw condition" \
  1359. "real_mul" python3 tests/rt_exec.py
  1360. else
  1361. echo " FAIL: the runtime would not rebuild with the raw JccNear"
  1362. fail=$((fail + 1))
  1363. fi
  1364. else
  1365. echo " BROKEN CASE: the JccNear-inverse mutation did not apply"
  1366. fail=$((fail + 1))
  1367. fi
  1368. cp "$SAVED" Runtime.mod
  1369. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1
  1370. # --- rediv's first subtraction is SUB, not SBB ---------------------------
  1371. # TPSRC's `SUB.B AH,remul21a' ignores the carry; `SBB' would subtract the
  1372. # carry-out of the shifted numerator as well. In the ordinary compare path
  1373. # CF is 0, so the two agree and a casual transcription passes most divisions;
  1374. # only 42/6 - the one quotient below 1, where the loop subtracts on equality -
  1375. # comes out two ulps low. Encoding the AH subtraction as SBB must turn the
  1376. # exact-byte real_div cases red.
  1377. if mutate Runtime.mod 's|BEGIN B (2AH) ; B (26H) ; Dd (delta) END SubAhData|BEGIN B (1AH) ; B (26H) ; Dd (delta) END SubAhData|'; then
  1378. if "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1; then
  1379. expect_red "real_div red when the mantissa subtraction uses SBB instead of SUB" \
  1380. "real_div" python3 tests/rt_exec.py
  1381. else
  1382. echo " FAIL: the runtime would not rebuild with SubAhData as SBB"
  1383. fail=$((fail + 1))
  1384. fi
  1385. fi
  1386. cp "$SAVED" Runtime.mod
  1387. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1
  1388. # --- recmp compares b's SIGN, not its middle word -----------------------
  1389. # The different-sign path is decided by RCL on a's high word, but WHICH pair is
  1390. # different is decided by XOR DX,DI. XORing with SI (b's middle mantissa word)
  1391. # still sees a's sign, so two negatives are taken as different signs: -3.7 and
  1392. # -3.9 then compare backwards. The fractional real_cmp cases catch it.
  1393. if mutate Runtime.mod 's|BEGIN B (31H) ; B (0FAH) END XorDxDi|BEGIN B (31H) ; B (0F2H) END XorDxDi|'; then
  1394. if "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1; then
  1395. expect_red "real_cmp red when the sign XOR uses SI instead of DI" \
  1396. "real_cmp" python3 tests/rt_exec.py
  1397. else
  1398. echo " FAIL: the runtime would not rebuild with the XorDxDi mutation"
  1399. fail=$((fail + 1))
  1400. fi
  1401. fi
  1402. cp "$SAVED" Runtime.mod
  1403. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1
  1404. # --- reint must not skip the mask for ordinary large reals ---------------
  1405. # 0A8h is 2^39, above which every representable value is already integral.
  1406. # Lowering it to 088h (256) makes 12345.75 come back unchanged instead of
  1407. # 12345: the fraction survives, and the exact-byte real_int case says so.
  1408. if mutate Runtime.mod 's|CmpAl (0A8H)|CmpAl (088H)|'; then
  1409. if "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1; then
  1410. expect_red "real_int red when the integral short-circuit starts too low" \
  1411. "real_int" python3 tests/rt_exec.py
  1412. else
  1413. echo " FAIL: the runtime would not rebuild with the CmpAl mutation"
  1414. fail=$((fail + 1))
  1415. fi
  1416. fi
  1417. cp "$SAVED" Runtime.mod
  1418. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1
  1419. # --- fmtreal reads the real through DI, not BX ---------------------------
  1420. # LdBxDiOff is `8B 5D off' = MOV BX,[DI+off]. 8B 5F is [BX+off], and the
  1421. # formatter would then read its own card scratch as the real's mantissa. The
  1422. # exact-output real_fmt cases catch it.
  1423. if mutate Runtime.mod 's|BEGIN B (8BH) ; B (5DH) ; B (off MOD 256) END LdBxDiOff|BEGIN B (8BH) ; B (5FH) ; B (off MOD 256) END LdBxDiOff|'; then
  1424. if "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1; then
  1425. expect_red "real_fmt red when the real is loaded through BX, not DI" \
  1426. "real_fmt" python3 tests/rt_exec.py
  1427. else
  1428. echo " FAIL: the runtime would not rebuild with the LdBxDiOff mutation"
  1429. fail=$((fail + 1))
  1430. fi
  1431. fi
  1432. cp "$SAVED" Runtime.mod
  1433. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1
  1434. # --- ascreal's digit add is an ADD, not a SUB ----------------------------
  1435. # rd_core is the post-testexp core; its caller must set resign. The parser
  1436. # adds each digit, so resign must be 0. 8000h makes it a subtraction with the
  1437. # sign XORed into the second operand: 12341 comes out 12339-ish, while the
  1438. # offset tests (which do not look at the value) still pass.
  1439. if python3 - <<'PYX'
  1440. p = 'Runtime.mod'
  1441. s = open(p).read()
  1442. old = """ PopAx ; PopBx ; PopDx ;
  1443. StDataImm (D_RSIGN, 0) ; (* readd, not resub: resign := 0 *)"""
  1444. assert s.count(old) == 1, 'the parser resign found %d times' % s.count(old)
  1445. open(p, 'w').write(s.replace(old, """ PopAx ; PopBx ; PopDx ;
  1446. StDataImm (D_RSIGN, 8000H) ;"""))
  1447. PYX
  1448. then
  1449. if "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1; then
  1450. expect_red "real_val value red when the digit add uses resign=8000h" \
  1451. "real_val" python3 tests/rt_exec.py
  1452. else
  1453. echo " FAIL: the runtime would not rebuild with the parser resign mutation"
  1454. fail=$((fail + 1))
  1455. fi
  1456. else
  1457. echo " BROKEN CASE: the parser resign mutation did not apply"
  1458. fail=$((fail + 1))
  1459. fi
  1460. cp "$SAVED" Runtime.mod
  1461. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1
  1462. # --- the compiler's arms --------------------------------------------------
  1463. # The limit both entries read is MOV CX,imm16. MOV AX,imm16 is one opcode away,
  1464. # the same length, and the audit's MovCxi row is COMP - "no single sequence to
  1465. # disassemble" - so nothing in the byte-level checks can tell them apart. Only
  1466. # execution can: t41's `s := t' truncates to 4 under CX and does not under AX.
  1467. # (t40 passes either way, because its CX happens to survive large enough for the
  1468. # five characters it reads - exactly the kind of luck a behavioural case is for.)
  1469. cp "$SAVED_C" Compiler.mod
  1470. if mutate_compiler 's| Ebyte (0B9H) ; Eword (imm)| Ebyte (0B8H) ; Eword (imm)|'; then
  1471. if rebuild_compiler; then
  1472. expect_red "t41 red when the destination limit is loaded into AX, not CX" \
  1473. "t41_strassign" python3 tests/run_com_exec.py t41_strassign
  1474. else
  1475. echo " FAIL: the compiler would not rebuild with MovCxi emitting MOV AX"
  1476. fail=$((fail + 1))
  1477. fi
  1478. fi
  1479. cp "$SAVED_C" Compiler.mod
  1480. # Assignment pushes the source first, then the destination, so the source sits
  1481. # at [BP+6] and the destination at [BP+4]. Swapped, strstore takes the
  1482. # destination as its own source - t41's `worl' rows become copies of what was
  1483. # already in the destination, which looks like it works and prints the wrong
  1484. # bytes.
  1485. cp "$SAVED_C" Compiler.mod
  1486. if python3 - <<'PYX'
  1487. p = 'Compiler.mod'
  1488. s = open(p).read()
  1489. src = (' EmPushVarAddr (symtab [src.idx].local,\n'
  1490. ' (symtab [src.idx].off + src.boff) MOD 10000H) ;\n'
  1491. ' EmPushVarAddr (symtab [r.idx].local,\n'
  1492. ' (symtab [r.idx].off + r.boff) MOD 10000H) ;')
  1493. dst = (' EmPushVarAddr (symtab [r.idx].local,\n'
  1494. ' (symtab [r.idx].off + r.boff) MOD 10000H) ;\n'
  1495. ' EmPushVarAddr (symtab [src.idx].local,\n'
  1496. ' (symtab [src.idx].off + src.boff) MOD 10000H) ;')
  1497. assert s.count(src) == 1, 'the assignment pushes found %d times -- update this mutation' % s.count(src)
  1498. open(p, 'w').write(s.replace(src, dst))
  1499. PYX
  1500. then
  1501. if rebuild_compiler; then
  1502. expect_red "t41 red when the assignment pushes are swapped" \
  1503. "t41_strassign" python3 tests/run_com_exec.py t41_strassign
  1504. else
  1505. echo " FAIL: the compiler would not rebuild with the pushes swapped"
  1506. fail=$((fail + 1))
  1507. fi
  1508. else
  1509. echo " BROKEN CASE: the assignment push-order mutation did not apply"
  1510. fail=$((fail + 1))
  1511. fi
  1512. cp "$SAVED_C" Compiler.mod
  1513. # The read dispatch's string arm. TU_RdStr and TU_RdInt sit next to each other
  1514. # in the same table and both take one address; TU_RdInt parses the line as a
  1515. # number, which stores nothing on `world', so readln(s) leaves s empty and the
  1516. # program prints a blank line. A refusal would at least say so; this arm looks
  1517. # like it worked and answers with the wrong bytes.
  1518. cp "$SAVED_C" Compiler.mod
  1519. if python3 - <<'PYX'
  1520. p = 'Compiler.mod'
  1521. s = open(p).read()
  1522. old = (' EmMovCxi ((VarSize (arg) - 1) MOD 10000H) ;\n'
  1523. ' ent := TU_RdStr')
  1524. assert s.count(old) == 1, 'the string-read arm found %d times -- update this mutation' % s.count(old)
  1525. open(p, 'w').write(s.replace(old, old.replace('TU_RdStr', 'TU_RdInt')))
  1526. PYX
  1527. then
  1528. if rebuild_compiler; then
  1529. expect_red "t40 red when a string read dispatches to TU_RdInt" \
  1530. "t40_readln" python3 tests/run_com_exec.py t40_readln
  1531. else
  1532. echo " FAIL: the compiler would not rebuild with the read dispatch on TU_RdInt"
  1533. fail=$((fail + 1))
  1534. fi
  1535. else
  1536. echo " BROKEN CASE: the string-read dispatch mutation did not apply"
  1537. fail=$((fail + 1))
  1538. fi
  1539. cp "$SAVED_C" Compiler.mod
  1540. # --- the include pre-pass -------------------------------------------------
  1541. # ExpandIncludes is the only thing that turns {$I name} into the named file;
  1542. # forced off, it is exactly the old bug - the directive is a comment and the
  1543. # include's own symbols do not exist. t56_include's `FromInclude' lives only in
  1544. # the .inc, so the compile matrix demands OK 56 4 and gets ERR 41 instead. That
  1545. # pins the fixture to the include ACTUALLY happening, not merely to the buffer
  1546. # being well formed; t57/t58 pin the two refusals (90 and 96) separately.
  1547. cp "$SAVED_C" Compiler.mod
  1548. if python3 - <<'PYX'
  1549. p = 'Compiler.mod'
  1550. s = open(p).read()
  1551. old = 'isInc := TRUE'
  1552. assert s.count(old) == 1, 'the include flag found %d times -- update this mutation' % s.count(old)
  1553. open(p, 'w').write(s.replace(old, 'isInc := FALSE'))
  1554. PYX
  1555. then
  1556. if rebuild_compiler; then
  1557. expect_red "t56 red when the include is swallowed, not expanded" \
  1558. "expected: OK 61 5" tests/run_compile_tests.sh
  1559. else
  1560. echo " FAIL: the compiler would not rebuild with the include forced off"
  1561. fail=$((fail + 1))
  1562. fi
  1563. else
  1564. echo " BROKEN CASE: the include-flag mutation did not apply"
  1565. fail=$((fail + 1))
  1566. fi
  1567. cp "$SAVED_C" Compiler.mod
  1568. # --- typed constants, and the caret/decimal character constants -----------
  1569. # A scalar typed constant's whole point is the CLASS its declaration gives the
  1570. # symbol: the value folds to an immediate either way, so the code size does not
  1571. # move when the class is dropped - `cls := typCls' -> `cls := cls' turns
  1572. # t59's `write (FXMax)' from the char writer to the integer one and the program
  1573. # prints 71 for 'G'. The compile matrix stays GREEN (same OK 65 4); only
  1574. # execution can see it, which is why this case runs the .COM and not the matrix.
  1575. cp "$SAVED_C" Compiler.mod
  1576. if python3 - <<'PYX'
  1577. p = 'Compiler.mod'
  1578. s = open(p).read()
  1579. old = ' cls := typCls'
  1580. assert s.count(old) == 1, 'the declared-type assignment found %d times -- update this mutation' % s.count(old)
  1581. open(p, 'w').write(s.replace(old, ' cls := cls'))
  1582. PYX
  1583. then
  1584. if rebuild_compiler; then
  1585. expect_red "t59 red when a typed constant's declared class is thrown away" \
  1586. "t59_typedconst" python3 tests/run_com_exec.py t59_typedconst
  1587. else
  1588. echo " FAIL: the compiler would not rebuild with the typed-const class dropped"
  1589. fail=$((fail + 1))
  1590. fi
  1591. else
  1592. echo " BROKEN CASE: the typed-const class mutation did not apply"
  1593. fail=$((fail + 1))
  1594. fi
  1595. cp "$SAVED_C" Compiler.mod
  1596. # ^M and #27 are CHARACTER constants, and ParseAtom must accept them as
  1597. # literals - RdConst alone only helps in a declaration. Drop them from the
  1598. # literal test and `write (^M)' is a syntax error, so the MATRIX goes red here
  1599. # (unlike the class case above, this one is visible at compile time).
  1600. cp "$SAVED_C" Compiler.mod
  1601. if python3 - <<'PYX'
  1602. p = 'Compiler.mod'
  1603. s = open(p).read()
  1604. old = " OR (CurCh () = '^') OR (CurCh () = '#') THEN"
  1605. assert s.count(old) == 1, 'the caret/decimal literal test found %d times -- update this mutation' % s.count(old)
  1606. open(p, 'w').write(s.replace(old, ' THEN'))
  1607. PYX
  1608. then
  1609. if rebuild_compiler; then
  1610. expect_red "t60 red when ^M / #nn are not character literals" \
  1611. "expected: OK 80 5" tests/run_compile_tests.sh
  1612. else
  1613. echo " FAIL: the compiler would not rebuild with the caret literal test removed"
  1614. fail=$((fail + 1))
  1615. fi
  1616. else
  1617. echo " BROKEN CASE: the caret-literal mutation did not apply"
  1618. fail=$((fail + 1))
  1619. fi
  1620. cp "$SAVED_C" Compiler.mod
  1621. # --- the set membership bit -----------------------------------------------
  1622. # Compile-time `in' reads a byte out of the emitted set and tests one bit. Flip
  1623. # the test and every answer is wrong while the sizes are untouched, so the
  1624. # compile matrix stays GREEN (same OK 183 4) and only execution sees it - the
  1625. # same shape as the typed-constant class case above, and the reason t61 has a
  1626. # .out rather than just a row.
  1627. cp "$SAVED_C" Compiler.mod
  1628. if python3 - <<'PYX'
  1629. p = 'Compiler.mod'
  1630. s = open(p).read()
  1631. old = 'isIn := (o DIV m) MOD 2 # 0'
  1632. assert s.count(old) == 1, 'the set membership bit test found %d times -- update this mutation' % s.count(old)
  1633. open(p, 'w').write(s.replace(old, 'isIn := (o DIV m) MOD 2 = 0'))
  1634. PYX
  1635. then
  1636. if rebuild_compiler; then
  1637. expect_red "t61 red when the set membership bit test is inverted" \
  1638. "t61_setconst" python3 tests/run_com_exec.py t61_setconst
  1639. else
  1640. echo " FAIL: the compiler would not rebuild with the set bit test inverted"
  1641. fail=$((fail + 1))
  1642. fi
  1643. else
  1644. echo " BROKEN CASE: the set-bit mutation did not apply"
  1645. fail=$((fail + 1))
  1646. fi
  1647. cp "$SAVED_C" Compiler.mod
  1648. # --- an enumerator's ordinal ----------------------------------------------
  1649. # Every enumerator must get its own ordinal (0,1,2,..). Give them all 0 and
  1650. # every `a = SomeEnumerator' is TRUE, while the sizes do not move: the compile
  1651. # matrix stays green (OK 187 5) and only execution sees it.
  1652. cp "$SAVED_C" Compiler.mod
  1653. if python3 - <<'PYX'
  1654. p = 'Compiler.mod'
  1655. s = open(p).read()
  1656. old = 'KConst, TScalar, 1, 1, 0, hi + 1, FALSE'
  1657. assert s.count(old) == 1, 'the enumerator ordinal found %d times -- update this mutation' % s.count(old)
  1658. open(p, 'w').write(s.replace(old, 'KConst, TScalar, 1, 1, 0, 0, FALSE'))
  1659. PYX
  1660. then
  1661. if rebuild_compiler; then
  1662. expect_red "t62 red when every enumerator gets ordinal 0" \
  1663. "t62_enum" python3 tests/run_com_exec.py t62_enum
  1664. else
  1665. echo " FAIL: the compiler would not rebuild with the enumerator ordinals flattened"
  1666. fail=$((fail + 1))
  1667. fi
  1668. else
  1669. echo " BROKEN CASE: the enumerator-ordinal mutation did not apply"
  1670. fail=$((fail + 1))
  1671. fi
  1672. cp "$SAVED_C" Compiler.mod
  1673. # --- subrange sizing ------------------------------------------------------
  1674. # TP3 sizes a subrange by its bounds: one byte when both are inside 0..255.
  1675. # Force two bytes and CellRec grows from 80 to 82, so the compile matrix's
  1676. # `data=84' becomes `data=86' - this one is visible at compile time, unlike the
  1677. # set/class cases above.
  1678. cp "$SAVED_C" Compiler.mod
  1679. if python3 - <<'PYX'
  1680. p = 'Compiler.mod'
  1681. s = open(p).read()
  1682. old = 'IF (lo >= 0) AND (hi <= 255) AND (lo <= hi) THEN\n size := 1'
  1683. assert s.count(old) == 1, 'the subrange size test found %d times -- update this mutation' % s.count(old)
  1684. open(p, 'w').write(s.replace(old, old.replace('size := 1', 'size := 2')))
  1685. PYX
  1686. then
  1687. if rebuild_compiler; then
  1688. expect_red "t63 red when a small subrange is sized two bytes" \
  1689. "expected: OK 62 85" tests/run_compile_tests.sh
  1690. else
  1691. echo " FAIL: the compiler would not rebuild with subranges forced to two bytes"
  1692. fail=$((fail + 1))
  1693. fi
  1694. else
  1695. echo " BROKEN CASE: the subrange-size mutation did not apply"
  1696. fail=$((fail + 1))
  1697. fi
  1698. cp "$SAVED_C" Compiler.mod
  1699. # --- an element's width ---------------------------------------------------
  1700. # A constant array subscript must hand the ELEMENT's size to the store, or the
  1701. # array's own size is used and `v[1] := 11' writes the whole array. Drop the
  1702. # width and the compile matrix stays green (same OK 101 16) while execution
  1703. # sees 0s and a corrupted neighbour - the shape the width exists to prevent.
  1704. cp "$SAVED_C" Compiler.mod
  1705. if python3 - <<'PYX'
  1706. p = 'Compiler.mod'
  1707. s = open(p).read()
  1708. # The element width is set once after the subscript list, for constant and
  1709. # run-time indices alike; dropping it makes the whole array's width win.
  1710. old = 'r.sz := arrs [ai].elem'
  1711. new = 'r.sz := 0'
  1712. assert s.count(old) == 1, 'the element width assignment found %d times -- update this mutation' % s.count(old)
  1713. open(p, 'w').write(s.replace(old, new))
  1714. PYX
  1715. then
  1716. if rebuild_compiler; then
  1717. expect_red "t65 red when a subscripted element keeps the array's width" \
  1718. "t65_array_access" python3 tests/run_com_exec.py t65_array_access
  1719. else
  1720. echo " FAIL: the compiler would not rebuild with the element width dropped"
  1721. fail=$((fail + 1))
  1722. fi
  1723. else
  1724. echo " BROKEN CASE: the element-width mutation did not apply"
  1725. fail=$((fail + 1))
  1726. fi
  1727. cp "$SAVED_C" Compiler.mod
  1728. # --- the file variable's size ---------------------------------------------
  1729. # Our file control block is FileVarSize bytes; shrink it and every file
  1730. # variable's slot moves, so t66's `data=269' becomes `data=265'. Visible at
  1731. # compile time, so the matrix carries it.
  1732. cp "$SAVED_C" Compiler.mod
  1733. if python3 - <<'PYX'
  1734. p = 'Compiler.mod'
  1735. s = open(p).read()
  1736. old = 'FileVarSize = 132 ;'
  1737. assert s.count(old) == 1, 'the file variable size found %d times -- update this mutation' % s.count(old)
  1738. open(p, 'w').write(s.replace(old, 'FileVarSize = 130 ;'))
  1739. PYX
  1740. then
  1741. if rebuild_compiler; then
  1742. expect_red "t66 red when the file variable is the wrong size" \
  1743. "expected: OK 55 269" tests/run_compile_tests.sh
  1744. else
  1745. echo " FAIL: the compiler would not rebuild with the file size changed"
  1746. fail=$((fail + 1))
  1747. fi
  1748. else
  1749. echo " BROKEN CASE: the file-size mutation did not apply"
  1750. fail=$((fail + 1))
  1751. fi
  1752. cp "$SAVED_C" Compiler.mod
  1753. # --- a string parameter's slot --------------------------------------------
  1754. # A string VALUE parameter's slot is its size (n+1 bytes). Collapse SlotSize
  1755. # to 2 for it and BOTH sides agree on 2 - so the compiler still compiles and
  1756. # the matrix stays green - but the callee's "string" is just a length byte and
  1757. # garbage; t67 prints something other than `hello'.
  1758. cp "$SAVED_C" Compiler.mod
  1759. if python3 - <<'PYX'
  1760. p = 'Compiler.mod'
  1761. s = open(p).read()
  1762. old = ' RETURN size\nEND SlotSize ;'
  1763. assert s.count(old) == 1, 'the SlotSize fallthrough found %d times -- update this mutation' % s.count(old)
  1764. open(p, 'w').write(s.replace(old, ' RETURN 2\nEND SlotSize ;'))
  1765. PYX
  1766. then
  1767. if rebuild_compiler; then
  1768. expect_red "t67 red when a string parameter's slot collapses to a word" \
  1769. "t67_strparam" python3 tests/run_com_exec.py t67_strparam
  1770. else
  1771. echo " FAIL: the compiler would not rebuild with SlotSize collapsed"
  1772. fail=$((fail + 1))
  1773. fi
  1774. else
  1775. echo " BROKEN CASE: the string-slot mutation did not apply"
  1776. fail=$((fail + 1))
  1777. fi
  1778. cp "$SAVED_C" Compiler.mod
  1779. # --- a string builtin is registered ---------------------------------------
  1780. # LENGTH has to be in the symbol table, or the name is simply unknown. Remove
  1781. # its registration and t68 stops compiling (ERR 41), so the compile matrix
  1782. # carries this one.
  1783. cp "$SAVED_C" Compiler.mod
  1784. if python3 - <<'PYX'
  1785. p = 'Compiler.mod'
  1786. s = open(p).read()
  1787. old = (' i := NewSym ("LENGTH" , KBuiltin, BI_Length , 0, 0, 0, 0, FALSE) ;\n'
  1788. ' symtab [i].defnd := TRUE ;\n'
  1789. ' symtab [i].goPos := 0 ; (* inline: the length byte, no entry *)\n')
  1790. assert s.count(old) == 1, 'the LENGTH registration found %d times -- update this mutation' % s.count(old)
  1791. open(p, 'w').write(s.replace(old, ''))
  1792. PYX
  1793. then
  1794. if rebuild_compiler; then
  1795. expect_red "t68 red when LENGTH is not registered" \
  1796. "expected: OK 127 26" tests/run_compile_tests.sh
  1797. else
  1798. echo " FAIL: the compiler would not rebuild without the LENGTH builtin"
  1799. fail=$((fail + 1))
  1800. fi
  1801. else
  1802. echo " BROKEN CASE: the LENGTH-registration mutation did not apply"
  1803. fail=$((fail + 1))
  1804. fi
  1805. cp "$SAVED_C" Compiler.mod
  1806. # --- a CRT builtin is registered ------------------------------------------
  1807. # ClrScr must be in the symbol table for t69 to compile. Remove it and the
  1808. # fixture stops at ERR 41 against its expected OK 102 4.
  1809. cp "$SAVED_C" Compiler.mod
  1810. if python3 - <<'PYX'
  1811. p = 'Compiler.mod'
  1812. s = open(p).read()
  1813. old = ' i := NewSym ("CLRSCR" , KBuiltin, BI_ClrScr , 0, 0, 0, 0, FALSE) ;\n symtab [i].defnd := TRUE ;\n'
  1814. assert s.count(old) == 1, 'the CLRSCR registration found %d times -- update this mutation' % s.count(old)
  1815. open(p, 'w').write(s.replace(old, ''))
  1816. PYX
  1817. then
  1818. if rebuild_compiler; then
  1819. expect_red "t69 red when CLRSCR is not registered" \
  1820. "expected: OK 158 5" tests/run_compile_tests.sh
  1821. else
  1822. echo " FAIL: the compiler would not rebuild without the CLRSCR builtin"
  1823. fail=$((fail + 1))
  1824. fi
  1825. else
  1826. echo " BROKEN CASE: the CLRSCR-registration mutation did not apply"
  1827. fail=$((fail + 1))
  1828. fi
  1829. cp "$SAVED_C" Compiler.mod
  1830. # --- KBD is registered ----------------------------------------------------
  1831. # Without the predefined KBD file, `Read(Kbd, Ch)' is an unknown identifier and
  1832. # t70 stops compiling against its expected OK 55 5.
  1833. cp "$SAVED_C" Compiler.mod
  1834. if python3 - <<'PYX'
  1835. p = 'Compiler.mod'
  1836. s = open(p).read()
  1837. old = (' i := NewSym ("KBD", KVar, TText, FileVarSize, 1, 0, 0, FALSE) ;\n'
  1838. ' symtab [i].isKbd := TRUE\n')
  1839. assert s.count(old) == 1, 'the KBD registration found %d times -- update this mutation' % s.count(old)
  1840. open(p, 'w').write(s.replace(old, ''))
  1841. PYX
  1842. then
  1843. if rebuild_compiler; then
  1844. expect_red "t70 red when KBD is not registered" \
  1845. "expected: OK 60 6" tests/run_compile_tests.sh
  1846. else
  1847. echo " FAIL: the compiler would not rebuild without the KBD file"
  1848. fail=$((fail + 1))
  1849. fi
  1850. else
  1851. echo " BROKEN CASE: the KBD-registration mutation did not apply"
  1852. fail=$((fail + 1))
  1853. fi
  1854. cp "$SAVED_C" Compiler.mod
  1855. # --- KEYPRESSED is registered ---------------------------------------------
  1856. # It is a FUNCTION, not a statement builtin, so it is registered like LENGTH
  1857. # and parsed in ParseAtom. Remove it and t72 stops at ERR 41.
  1858. cp "$SAVED_C" Compiler.mod
  1859. if python3 - <<'PYX'
  1860. p = 'Compiler.mod'
  1861. s = open(p).read()
  1862. old = (' i := NewSym ("KEYPRESSED", KBuiltin, BI_KeyPressed, 0, 0, 0, 0, FALSE) ;\n'
  1863. ' symtab [i].defnd := TRUE ;\n')
  1864. assert s.count(old) == 1, 'the KEYPRESSED registration found %d times -- update this mutation' % s.count(old)
  1865. open(p, 'w').write(s.replace(old, ''))
  1866. PYX
  1867. then
  1868. if rebuild_compiler; then
  1869. expect_red "t72 red when KEYPRESSED is not registered" "expected: OK 138 6" tests/run_compile_tests.sh
  1870. else
  1871. echo " FAIL: the compiler would not rebuild without the KEYPRESSED builtin"
  1872. fail=$((fail + 1))
  1873. fi
  1874. else
  1875. echo " BROKEN CASE: the KEYPRESSED-registration mutation did not apply"
  1876. fail=$((fail + 1))
  1877. fi
  1878. cp "$SAVED_C" Compiler.mod
  1879. # --- KeyPressed masks AL, not AX ------------------------------------------
  1880. # AH is still 0Bh after INT 21h, so `AND AL,1' leaves AX = 0B00h and the
  1881. # boolean test `CMP AX,0' calls the NO-KEY answer TRUE. bootcom's handler
  1882. # happens to IRET the whole AX and returns AH=0, so qemu cannot see this;
  1883. # only the Exec86 oracle can, which is why t72 runs under both.
  1884. cp "$SAVED_C" Compiler.mod
  1885. if mutate_compiler 's| Ebyte (25H) ; Ebyte (01H) ; Ebyte (00H)| Ebyte (24H) ; Ebyte (01H)|'; then
  1886. if rebuild_compiler; then
  1887. expect_red "t72 red when KeyPressed masks AL instead of AX" "more" python3 tests/run_exec86.py t72_keypress
  1888. else
  1889. echo " FAIL: the compiler would not rebuild with AND AL,1"
  1890. fail=$((fail + 1))
  1891. fi
  1892. else
  1893. echo " BROKEN CASE: the AND AX,1 mutation did not apply"
  1894. fail=$((fail + 1))
  1895. fi
  1896. cp "$SAVED_C" Compiler.mod
  1897. # --- a parameter may shadow a global --------------------------------------
  1898. # DupTest used to reject any name Search could see, so CALC's
  1899. # `IBMCh(var Ch: Char)' collided with the global `Ch'. Make the level test
  1900. # unconditional and t73 is ERR 41 at the parameter name again.
  1901. cp "$SAVED_C" Compiler.mod
  1902. if mutate_compiler 's| IF symtab \[i\].level = lexnest THEN| IF TRUE THEN|'; then
  1903. if rebuild_compiler; then
  1904. expect_red "t73 red when a parameter may not shadow a global" "expected: OK 334 8" tests/run_compile_tests.sh
  1905. else
  1906. echo " FAIL: the compiler would not rebuild with the old DupTest"
  1907. fail=$((fail + 1))
  1908. fi
  1909. else
  1910. echo " BROKEN CASE: the DupTest level-test mutation did not apply"
  1911. fail=$((fail + 1))
  1912. fi
  1913. cp "$SAVED_C" Compiler.mod
  1914. # --- a VAR parameter is not a value parameter -----------------------------
  1915. # Record the formal as a value parameter again (the exact old behaviour):
  1916. # the caller pushes a copy and IBMCh/Bump update that copy. This compiles and
  1917. # runs, and prints H,H,41,a - which is why it is the execution, not the
  1918. # compile, that must catch it.
  1919. cp "$SAVED_C" Compiler.mod
  1920. if mutate_compiler 's| symtab \[i\].isVar := groupVar ;| symtab \[i\].isVar := FALSE ;|'; then
  1921. if rebuild_compiler; then
  1922. expect_red "t73 red when a VAR parameter is recorded as value" "FAIL" python3 tests/run_com_exec.py t73_varparam
  1923. else
  1924. echo " FAIL: the compiler would not rebuild with VAR as value"
  1925. fail=$((fail + 1))
  1926. fi
  1927. else
  1928. echo " BROKEN CASE: the VAR-as-value mutation did not apply"
  1929. fail=$((fail + 1))
  1930. fi
  1931. cp "$SAVED_C" Compiler.mod
  1932. # --- a CASE range is a range ----------------------------------------------
  1933. # The old emitter compared the selector with lo and then with hi, both
  1934. # demanding equality, so `1..5' matched nothing. Invert only the high test:
  1935. # i=5 in t74's `1..5' arm then falls through to ELSE, and the .out says
  1936. # `range'. This is an execution failure, not a compile failure - the range
  1937. # compiled and ran, and answered wrongly.
  1938. cp "$SAVED_C" Compiler.mod
  1939. if mutate_compiler 's|EmJcc (8FH, 0)|EmJcc (84H, 0)|'; then
  1940. if rebuild_compiler; then
  1941. expect_red "t74 red when a CASE range requires equality" "FAIL" python3 tests/run_com_exec.py t74_caselist
  1942. else
  1943. echo " FAIL: the compiler would not rebuild with the broken range test"
  1944. fail=$((fail + 1))
  1945. fi
  1946. else
  1947. echo " BROKEN CASE: the CASE-range mutation did not apply"
  1948. fail=$((fail + 1))
  1949. fi
  1950. cp "$SAVED_C" Compiler.mod
  1951. # --- an array subscript scales by the element size ------------------------
  1952. # Skip the multiply: for an Integer array a[i] is then base + (i - lo) BYTES,
  1953. # so a[2] reads the second byte of a[1]. Compiles, runs, wrong - an execution
  1954. # failure, which is what t75 is executed for.
  1955. cp "$SAVED_C" Compiler.mod
  1956. if mutate_compiler 's| IF st # 1 THEN| IF FALSE THEN|'; then
  1957. if rebuild_compiler; then
  1958. expect_red "t75 red when an array subscript is not scaled" "FAIL" python3 tests/run_com_exec.py t75_arrvar
  1959. else
  1960. echo " FAIL: the compiler would not rebuild without the element scale"
  1961. fail=$((fail + 1))
  1962. fi
  1963. else
  1964. echo " BROKEN CASE: the element-scale mutation did not apply"
  1965. fail=$((fail + 1))
  1966. fi
  1967. cp "$SAVED_C" Compiler.mod
  1968. # --- a field width reaches the width-aware writer -------------------------
  1969. # Call wrint instead of wrintw. The caller still pushes the value and the
  1970. # width and still cleans up four bytes, so wrint reads the WIDTH as its value
  1971. # and the stack stays balanced: t76 prints the widths, not the numbers.
  1972. cp "$SAVED_C" Compiler.mod
  1973. if mutate_compiler 's|ent := TU_WrIntW ;|ent := TU_WrInt ;|'; then
  1974. if rebuild_compiler; then
  1975. expect_red "t76 red when a width calls the plain integer writer" "FAIL" python3 tests/run_com_exec.py t76_width
  1976. else
  1977. echo " FAIL: the compiler would not rebuild with the plain writer"
  1978. fail=$((fail + 1))
  1979. fi
  1980. else
  1981. echo " BROKEN CASE: the width-entry mutation did not apply"
  1982. fail=$((fail + 1))
  1983. fi
  1984. cp "$SAVED_C" Compiler.mod
  1985. # --- a 2-D subscript uses the row stride ----------------------------------
  1986. # Let every dimension use the ELEMENT size: `g[i,j]' then adds (i-lo0)*elem
  1987. # and (j-lo1)*elem instead of scaling the first by the second dimension's
  1988. # count. 1-D is unchanged, so t75 stays green; t77's 2-D element moves.
  1989. cp "$SAVED_C" Compiler.mod
  1990. if mutate_compiler 's| k := nd + 1 ;| k := arrs \[ai\].n ;|'; then
  1991. if rebuild_compiler; then
  1992. expect_red "t77 red when the 2-D row stride is dropped" "FAIL" python3 tests/run_com_exec.py t77_with
  1993. else
  1994. echo " FAIL: the compiler would not rebuild without the row stride"
  1995. fail=$((fail + 1))
  1996. fi
  1997. else
  1998. echo " BROKEN CASE: the row-stride mutation did not apply"
  1999. fail=$((fail + 1))
  2000. fi
  2001. cp "$SAVED_C" Compiler.mod
  2002. # --- a WITH over an element keeps the element's offset ---------------------
  2003. # `with g[1,2]' must remember boff (2,3's predecessor); dropping it makes the
  2004. # body address g[1,1]. t77 sets g[1,2].a := 7 and reads it back.
  2005. cp "$SAVED_C" Compiler.mod
  2006. if mutate_compiler 's| withBoff \[withN\] := t.boff| withBoff \[withN\] := 0|'; then
  2007. if rebuild_compiler; then
  2008. expect_red "t77 red when WITH forgets the element offset" "FAIL" python3 tests/run_com_exec.py t77_with
  2009. else
  2010. echo " FAIL: the compiler would not rebuild without the WITH offset"
  2011. fail=$((fail + 1))
  2012. fi
  2013. else
  2014. echo " BROKEN CASE: the WITH-offset mutation did not apply"
  2015. fail=$((fail + 1))
  2016. fi
  2017. cp "$SAVED_C" Compiler.mod
  2018. # --- a set field's constructor is sized by the TARGET ---------------------
  2019. # Write the default 32-byte set-of-Char length instead of the field's one
  2020. # byte: the store runs past Status into N and the neighbours. t78 reads N
  2021. # back, so the overrun is visible.
  2022. cp "$SAVED_C" Compiler.mod
  2023. if mutate_compiler 's| WHILE k < r.setsize DO| WHILE k < 32 DO|'; then
  2024. if rebuild_compiler; then
  2025. expect_red "t78 red when a set field stores 32 bytes, not its size" "FAIL" python3 tests/run_com_exec.py t78_setfield
  2026. else
  2027. echo " FAIL: the compiler would not rebuild with the 32-byte store"
  2028. fail=$((fail + 1))
  2029. fi
  2030. else
  2031. echo " BROKEN CASE: the set-size mutation did not apply"
  2032. fail=$((fail + 1))
  2033. fi
  2034. cp "$SAVED_C" Compiler.mod
  2035. # --- a field's set base offset is the ARRAY/RECORD's ----------------------
  2036. # `in' reads setoff + boff. Forgetting the symbol's base (setoff := 0) makes
  2037. # sh[2,3].Status read absolute address 15 instead of sh+15.
  2038. cp "$SAVED_C" Compiler.mod
  2039. if mutate_compiler 's| r.setoff := symtab \[r.idx\].off ;| r.setoff := 0 ;|'; then
  2040. if rebuild_compiler; then
  2041. expect_red "t78 red when a field's set base offset is dropped" "FAIL" python3 tests/run_com_exec.py t78_setfield
  2042. else
  2043. echo " FAIL: the compiler would not rebuild without the set base"
  2044. fail=$((fail + 1))
  2045. fi
  2046. else
  2047. echo " BROKEN CASE: the set-base mutation did not apply"
  2048. fail=$((fail + 1))
  2049. fi
  2050. cp "$SAVED_C" Compiler.mod
  2051. # --- a short literal sets the SOURCE length ---------------------------------
  2052. # Skip the min(source length, capacity): n stays at the field's capacity and
  2053. # the copy reads past the literal into the string pool, so 'abc' prints five
  2054. # characters. t79's first line is 'abc'.
  2055. cp "$SAVED_C" Compiler.mod
  2056. if mutate_compiler 's| IF strLen \[src.strx\] < n THEN| IF FALSE THEN|'; then
  2057. if rebuild_compiler; then
  2058. expect_red "t79 red when a short string literal keeps the capacity" "FAIL" python3 tests/run_com_exec.py t79_strfield
  2059. else
  2060. echo " FAIL: the compiler would not rebuild without the length min"
  2061. fail=$((fail + 1))
  2062. fi
  2063. else
  2064. echo " BROKEN CASE: the literal-length mutation did not apply"
  2065. fail=$((fail + 1))
  2066. fi
  2067. cp "$SAVED_C" Compiler.mod
  2068. # --- a DI-addressed string field stores its length --------------------------
  2069. # Store a zero length byte: the characters go to the field but every reader
  2070. # sees an empty string. t79 writes 'xy' through WITH and prints it back.
  2071. cp "$SAVED_C" Compiler.mod
  2072. if mutate_compiler 's| EmStDiImm (0, n) ;| EmStDiImm (0, 0) ;|'; then
  2073. if rebuild_compiler; then
  2074. expect_red "t79 red when a string field's length byte is zero" "FAIL" python3 tests/run_com_exec.py t79_strfield
  2075. else
  2076. echo " FAIL: the compiler would not rebuild with a zero length"
  2077. fail=$((fail + 1))
  2078. fi
  2079. else
  2080. echo " BROKEN CASE: the string length-byte mutation did not apply"
  2081. fail=$((fail + 1))
  2082. fi
  2083. cp "$SAVED_C" Compiler.mod
  2084. # --- the Real exponent bias is 129, not 128 -------------------------------
  2085. # byte 0 is E + 129 in CALC-PORT.md's measured table. One less and every
  2086. # constant's exponent is wrong; the byte check reads the emitted code.
  2087. cp "$SAVED_C" Compiler.mod
  2088. if mutate_compiler 's| e := 129 + k ;| e := 128 + k ;|'; then
  2089. if rebuild_compiler; then
  2090. if ./tests/run_compile_tests.sh --build-only >/dev/null 2>&1; then
  2091. expect_red "the Real bytes red when the exponent bias is 128" "FAIL" python3 tests/check_realconst.py
  2092. else
  2093. echo " FAIL: compiletest would not rebuild with the wrong bias"
  2094. fail=$((fail + 1))
  2095. fi
  2096. else
  2097. echo " FAIL: the compiler would not rebuild with the wrong bias"
  2098. fail=$((fail + 1))
  2099. fi
  2100. else
  2101. echo " BROKEN CASE: the Real-bias mutation did not apply"
  2102. fail=$((fail + 1))
  2103. fi
  2104. cp "$SAVED_C" Compiler.mod
  2105. # --- the fraction is (a - 2^k), not a ------------------------------------
  2106. # Dropping the implicit 1 from the mantissa: 1.0 becomes 2.0, 3.0's bytes are
  2107. # wrong, and the measured table no longer appears.
  2108. cp "$SAVED_C" Compiler.mod
  2109. if mutate_compiler 's| n := a - p ;| n := a ;|'; then
  2110. if rebuild_compiler; then
  2111. if ./tests/run_compile_tests.sh --build-only >/dev/null 2>&1; then
  2112. expect_red "the Real bytes red when the implicit 1 is missing" "FAIL" python3 tests/check_realconst.py
  2113. else
  2114. echo " FAIL: compiletest would not rebuild without the implicit 1"
  2115. fail=$((fail + 1))
  2116. fi
  2117. else
  2118. echo " FAIL: the compiler would not rebuild without the implicit 1"
  2119. fail=$((fail + 1))
  2120. fi
  2121. else
  2122. echo " BROKEN CASE: the implicit-1 mutation did not apply"
  2123. fail=$((fail + 1))
  2124. fi
  2125. cp "$SAVED_C" Compiler.mod
  2126. # --- UpCase subtracts 32, not 33 ------------------------------------------
  2127. # The run-time fold; 'a' becomes '@'. t81 prints A for 'a'.
  2128. cp "$SAVED_C" Compiler.mod
  2129. if mutate_compiler 's| EmSubAlImm (32) ;| EmSubAlImm (33) ;|'; then
  2130. if rebuild_compiler; then
  2131. expect_red "t81 red when UpCase subtracts 33" "FAIL" python3 tests/run_com_exec.py t81_upcase
  2132. else
  2133. echo " FAIL: the compiler would not rebuild with a 33 fold"
  2134. fail=$((fail + 1))
  2135. fi
  2136. else
  2137. echo " BROKEN CASE: the UpCase-fold mutation did not apply"
  2138. fail=$((fail + 1))
  2139. fi
  2140. cp "$SAVED_C" Compiler.mod
  2141. # --- a set membership indexes bytes with DIV 8 ----------------------------
  2142. # Two SHRs instead of three divide by 4: 'Y' (89) picks byte 22 of a 32-byte
  2143. # literal, whose bits are clear. t82 expects the first line to be 'yes'.
  2144. cp "$SAVED_C" Compiler.mod
  2145. if mutate_compiler 's| EmShrAx1 () ; EmShrAx1 () ; EmShrAx1 () ;| EmShrAx1 () ; EmShrAx1 () ;|'; then
  2146. if rebuild_compiler; then
  2147. expect_red "t82 red when set membership divides by 4, not 8" "FAIL" python3 tests/run_com_exec.py t82_setin
  2148. else
  2149. echo " FAIL: the compiler would not rebuild with two shifts"
  2150. fail=$((fail + 1))
  2151. fi
  2152. else
  2153. echo " BROKEN CASE: the set-index shift mutation did not apply"
  2154. fail=$((fail + 1))
  2155. fi
  2156. cp "$SAVED_C" Compiler.mod
  2157. # --- real output goes through real_write, not the placeholder ----------
  2158. # TU_WrReal is still the "?REAL?" marker; the compiler's new real arm must
  2159. # select TU_RealWrite. t84 prints a real field with variable width/decimals.
  2160. cp "$SAVED_C" Compiler.mod
  2161. if mutate_compiler 's| ent := TU_RealWrite ;| ent := TU_WrReal ;|'; then
  2162. if rebuild_compiler; then
  2163. expect_red "t84 red when real output falls back to the placeholder" \
  2164. "t84_realwrite" python3 tests/run_com_exec.py t84_realwrite
  2165. else
  2166. echo " FAIL: the compiler would not rebuild with the placeholder"
  2167. fail=$((fail + 1))
  2168. fi
  2169. fi
  2170. cp "$SAVED_C" Compiler.mod
  2171. # --- a DI-addressed string field is an address, not a scalar ------------
  2172. # `if A[I].Contents <> '' then' must push DI; the old EmPushStrAddr refused
  2173. # kind 5 (ENoLib) and SaveLeft would try to load the whole string.
  2174. cp "$SAVED_C" Compiler.mod
  2175. if python3 - <<'PYX'
  2176. p = 'Compiler.mod'
  2177. s = open(p).read()
  2178. old = """ IF r.kind = 5 THEN
  2179. (* a string element/field computed through DI - `Sheet[X,Y].Contents'"""
  2180. assert s.count(old) == 1, 'the kind-5 string branch found %d times' % s.count(old)
  2181. open(p, 'w').write(s.replace(old, """ IF r.kind = 4 THEN
  2182. (* a string element/field computed through DI - `Sheet[X,Y].Contents'"""))
  2183. PYX
  2184. then
  2185. if rebuild_compiler; then
  2186. expect_red "t83 red when a string field address is refused" \
  2187. "t83_strfield_cmp" python3 tests/run_com_exec.py t83_strfield_cmp
  2188. else
  2189. echo " FAIL: the compiler would not rebuild without the kind-5 push"
  2190. fail=$((fail + 1))
  2191. fi
  2192. else
  2193. echo " BROKEN CASE: the kind-5 string-field mutation did not apply"
  2194. fail=$((fail + 1))
  2195. fi
  2196. cp "$SAVED_C" Compiler.mod
  2197. # --- real_write pads from the WIDTH, not from the length ----------------
  2198. # The pad is width - length; using the length for both makes it zero, so every
  2199. # right-justified field loses its leading spaces. rt_exec checks exact output.
  2200. cp "$SAVED" Runtime.mod
  2201. if mutate Runtime.mod 's| MovAxData (D_FMTW) ;| MovAxData (D_FMTLEN) ;|'; then
  2202. if "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1; then
  2203. expect_red "real_write red when the pad uses the length" \
  2204. "real_write" python3 tests/rt_exec.py
  2205. else
  2206. echo " FAIL: the runtime would not rebuild with the pad mutation"
  2207. fail=$((fail + 1))
  2208. fi
  2209. fi
  2210. cp "$SAVED" Runtime.mod
  2211. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1
  2212. # --- set_op's intersection really ANDs the two bytes ---------------------
  2213. # 20 D0 is AND AL,DL; 20 C2 is AND DL,AL and leaves AL (the left byte), which
  2214. # is exactly the bug this rung fixed. The exact-byte set_op cases catch it.
  2215. cp "$SAVED" Runtime.mod
  2216. if mutate Runtime.mod 's|PROCEDURE AndAlDl ; BEGIN B (20H) ; B (0D0H)|PROCEDURE AndAlDl ; BEGIN B (20H) ; B (0C2H)|'; then
  2217. if "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1; then
  2218. expect_red "set_op red when intersection uses the wrong AND operand" \
  2219. "set_op" python3 tests/rt_exec.py
  2220. else
  2221. echo " FAIL: the runtime would not rebuild with the AND mutation"
  2222. fail=$((fail + 1))
  2223. fi
  2224. fi
  2225. cp "$SAVED" Runtime.mod
  2226. "$GM2" -fiso -c Runtime.mod >/dev/null 2>&1
  2227. # --- set union is OR, not intersection -----------------------------------
  2228. # t85's `union' line is `Status := Status + [C]'; choosing intersection there
  2229. # loses C (and the later difference line too). This pins the compiler's
  2230. # operator-to-runtime mapping, not just the runtime core.
  2231. cp "$SAVED_C" Compiler.mod
  2232. if mutate_compiler 's| SetBinEmit (1, left, right, r)| SetBinEmit (0, left, right, r)|'; then
  2233. if rebuild_compiler; then
  2234. expect_red "t85 red when set addition becomes intersection" \
  2235. "t85_setops" python3 tests/run_com_exec.py t85_setops
  2236. else
  2237. echo " FAIL: the compiler would not rebuild with set + as *"
  2238. fail=$((fail + 1))
  2239. fi
  2240. fi
  2241. cp "$SAVED_C" Compiler.mod
  2242. # --- Succ increments, Pred decrements ------------------------------------
  2243. cp "$SAVED_C" Compiler.mod
  2244. if python3 - <<'PYX'
  2245. p = 'Compiler.mod'
  2246. s = open(p).read()
  2247. old = """ IF symtab [idx].cls = BI_Succ THEN
  2248. EmIncAx ()
  2249. ELSE
  2250. EmDecAx ()"""
  2251. assert s.count(old) == 1, 'the Succ branch found %d times' % s.count(old)
  2252. open(p, 'w').write(s.replace(old, """ IF symtab [idx].cls = BI_Succ THEN
  2253. EmDecAx ()
  2254. ELSE
  2255. EmDecAx ()"""))
  2256. PYX
  2257. then
  2258. if rebuild_compiler; then
  2259. expect_red "t86 red when Succ decrements" \
  2260. "t86_succ" python3 tests/run_com_exec.py t86_succ
  2261. else
  2262. echo " FAIL: the compiler would not rebuild with Succ as Pred"
  2263. fail=$((fail + 1))
  2264. fi
  2265. else
  2266. echo " BROKEN CASE: the Succ mutation did not apply"
  2267. fail=$((fail + 1))
  2268. fi
  2269. cp "$SAVED_C" Compiler.mod
  2270. if rebuild_compiler; then
  2271. if python3 tests/run_com_exec.py >/dev/null 2>&1; then
  2272. echo " ok: every executed fixture passes on the restored sources"
  2273. pass=$((pass + 1))
  2274. else
  2275. echo "NOT RESTORED: run_com_exec.py is red after restoring the sources"
  2276. python3 tests/run_com_exec.py 2>&1 | grep -i fail | head -3 | sed 's/^/ /'
  2277. fail=$((fail + 1))
  2278. fi
  2279. else
  2280. echo "NOT RESTORED: the compiler would not rebuild"
  2281. fail=$((fail + 1))
  2282. fi
  2283. echo
  2284. echo "== the second execution oracle (run_exec86.py)"
  2285. # Everything above runs the image under qemu-system-i386. This one runs the
  2286. # SAME image inside shell/Exec86.mod, this project's own in-process 8086
  2287. # interpreter, and requires its output to agree with BOTH the hand-derived .out
  2288. # and qemu, byte for byte. Two execution checks that could only ever agree
  2289. # with each other would be one check: the point of this one is that it was
  2290. # written against the 8086's own reference rather than against qemu, whose
  2291. # lowest CPU model is a 486 and whose `0F 84' is an ordinary JZ.
  2292. #
  2293. # So the only mutation worth writing here is one qemu cannot make at all - the
  2294. # interpreter's own reading of the machine. Cond is that reading: nibble 4 is
  2295. # JE, and inverting it swaps the two arms of every `=' in every program. The
  2296. # emitted bytes, the sizes and the compile matrix are untouched, because
  2297. # nothing is emitted here - the fault is in who interprets it.
  2298. #
  2299. # Exec86.mod is recompiled explicitly rather than left to the harness:
  2300. # ensure_exec86run() notices the source changed and RELINKS, but does not
  2301. # recompile it, so a mutated source with a stale object would link the good
  2302. # interpreter straight back in and stay green - which is the trap its own
  2303. # docstring records, and the reason this case compiles first.
  2304. #
  2305. # SAVED_E itself was taken at the top of this file, next to the EXIT trap that
  2306. # puts it back.
  2307. if python3 - <<'PYX'
  2308. p = 'Exec86.mod'
  2309. s = open(p).read()
  2310. old = "| 4H : r := ZF"
  2311. new = "| 4H : r := NOT ZF (* MUTATION: JE inverted *)"
  2312. assert s.count(old) == 1, 'the JE arm of Cond found %d times -- update this mutation' % s.count(old)
  2313. open(p, 'w').write(s.replace(old, new))
  2314. PYX
  2315. then
  2316. if $GM2 -fiso -c Exec86.mod >/dev/null 2>&1; then
  2317. expect_red "the interpreter's own oracle catches JE inverted" \
  2318. "t33_cmpops" python3 tests/run_exec86.py t33_cmpops
  2319. else
  2320. echo " FAIL: Exec86.mod would not compile with JE inverted"
  2321. fail=$((fail + 1))
  2322. fi
  2323. else
  2324. echo " BROKEN CASE: the Cond JE mutation did not apply"
  2325. fail=$((fail + 1))
  2326. fi
  2327. cp "$SAVED_E" Exec86.mod
  2328. # And the check on the RESTORED interpreter, because a green above could also
  2329. # come from a mutation that never took and an object left mutated by a run
  2330. # that died in between.
  2331. if $GM2 -fiso -c Exec86.mod >/dev/null 2>&1; then
  2332. if python3 tests/run_exec86.py >/dev/null 2>&1; then
  2333. echo " ok: run_exec86 green on the restored interpreter"
  2334. pass=$((pass + 1))
  2335. else
  2336. echo "NOT RESTORED: run_exec86.py is red after restoring Exec86.mod"
  2337. python3 tests/run_exec86.py 2>&1 | grep -i "fail" | head -3 | sed 's/^/ /'
  2338. fail=$((fail + 1))
  2339. fi
  2340. else
  2341. echo "NOT RESTORED: Exec86.mod would not recompile"
  2342. fail=$((fail + 1))
  2343. fi
  2344. echo
  2345. echo "== the R key: compile, poke, run, report (runtest.py)"
  2346. # The only check in the project that exercises CmdRun. Everything above looks
  2347. # at bytes, or at what qemu says the image does; this one drives the shell
  2348. # through a pty the way a person would, presses R, and compares the GUEST's
  2349. # output against the fixture's hand-derived .out - so it fails on things no
  2350. # byte check can see and no file records either, because R writes no file at
  2351. # all (which is itself asserted).
  2352. #
  2353. # The mutation is the poke loop's count. With n = 0 nothing is copied into
  2354. # the interpreter, loadHi stays where Clear86 left it - 0100h - and Run86
  2355. # faults on its very first step, "execution left the loaded image", before the
  2356. # guest has executed a single instruction. That is fast and deterministic, which
  2357. # matters: the obvious alternative (poking the image somewhere else) leaves the
  2358. # machine executing zeros and buys a step-limit timeout instead of a finding.
  2359. cp "$SAVED_SH" Shell.mod
  2360. if python3 - <<'PYX'
  2361. p = 'Shell.mod'
  2362. s = open(p).read()
  2363. old = " n := LinkSize () ;"
  2364. new = " n := 0 ; (* MUTATION: nothing is poked *)"
  2365. assert s.count(old) == 1, 'the poke count in CmdRun found %d times -- update this mutation' % s.count(old)
  2366. open(p, 'w').write(s.replace(old, new))
  2367. PYX
  2368. then
  2369. if make > ../tmp/nonvacuity.make.log 2>&1; then
  2370. expect_red "the R check catches an image that was never poked" \
  2371. "AH=4Ch exit" python3 tests/runtest.py
  2372. else
  2373. echo " FAIL: the shell would not rebuild with the poke loop neutered"
  2374. tail -5 ../tmp/nonvacuity.make.log | sed 's/^/ /'
  2375. fail=$((fail + 1))
  2376. fi
  2377. else
  2378. echo " BROKEN CASE: the CmdRun poke mutation did not apply"
  2379. fail=$((fail + 1))
  2380. fi
  2381. cp "$SAVED_SH" Shell.mod
  2382. if make > ../tmp/nonvacuity.make.log 2>&1; then
  2383. if python3 tests/runtest.py >/dev/null 2>&1; then
  2384. echo " ok: runtest green on the restored shell"
  2385. pass=$((pass + 1))
  2386. else
  2387. echo "NOT RESTORED: runtest.py is red after restoring Shell.mod"
  2388. python3 tests/runtest.py 2>&1 | grep -i "fail" | head -3 | sed 's/^/ /'
  2389. fail=$((fail + 1))
  2390. fi
  2391. else
  2392. echo "NOT RESTORED: the shell would not rebuild"
  2393. tail -5 ../tmp/nonvacuity.make.log | sed 's/^/ /'
  2394. fail=$((fail + 1))
  2395. fi
  2396. echo
  2397. echo "== 8086 legality of the conditional lowering (check_8086.py)"
  2398. # This whole section exists because of a fault that every other check in the
  2399. # project was blind to, and being blunt about WHY is the point of listing it.
  2400. #
  2401. # EmJcc and EmSetcc emitted `0F 8x rel16' and `0F 9x rel8'. `0F' is a
  2402. # 386-and-later opcode prefix; the 8086 has none. So EVERY conditional branch
  2403. # and EVERY comparison in EVERY compiled program was an illegal instruction on
  2404. # the machine this compiler targets. And all of the following were green while
  2405. # it was: the compile matrix, the .COM layout checker, the runtime golden, the
  2406. # emitter audit, and the whole execution suite answering correctly under qemu.
  2407. #
  2408. # Two reasons, and the second is the one worth keeping:
  2409. # 1. qemu-system-i386 has no 8086 model. Its lowest is 486, where `0F 84' is
  2410. # a perfectly ordinary JZ. So the execution oracle CANNOT see this class
  2411. # of fault, ever.
  2412. # 2. FCML is this project's INDEPENDENT disassembler, and FCML's -m16 mode is
  2413. # a 386. The one tool whose job is to say "this is not a real instruction"
  2414. # was architecturally guaranteed to agree with the bug.
  2415. #
  2416. # So a check was needed that asks the question nothing else was asking. The
  2417. # five mutations below are the mutations that check has to catch, and each was
  2418. # run by hand and confirmed red BEFORE this section existed.
  2419. #
  2420. # M4 and M5 are the interesting pair. M4 is a fault this project actually
  2421. # introduced while fixing the above: EmJcc jumps TO its target, but the 8086
  2422. # shape steps OVER a 3-byte EJMP, so the naive port inverts every conditional
  2423. # in every program. It was caught by execution, not by any byte check. M5 is
  2424. # the partial version -- the inversion dropped for the IF and CASE sites only,
  2425. # kept for FOR -- and MEASURING that is what produced clause H, because the
  2426. # check was blind to M5 as first written: IF declares nibble 4, CASE declares
  2427. # 5, they negate into each other, and both are declared, so nothing complained
  2428. # while every conditional in every program took the wrong path. FOR declares
  2429. # C and F, whose negations D and E are declared for nothing at all, so the
  2430. # whole-suite version was caught by luck.
  2431. #
  2432. # Note these need `rebuild_compiler' only to refresh comtest; check_8086.py
  2433. # relinks the fixtures itself. Getting that wrong is how this section's first
  2434. # draft reported a mutation as VACUOUS: the build was skipped, a stale comtest
  2435. # ran the GOOD compiler, and the check passed. A helper that exits non-zero
  2436. # makes `if mutate_x; then' false and the case is silently skipped, which looks
  2437. # exactly like a pass -- so rebuild_compiler is checked, not assumed.
  2438. # M1: the original defect, restored verbatim.
  2439. cp "$SAVED_C" Compiler.mod
  2440. if python3 - <<'PYX'
  2441. p = 'Compiler.mod'
  2442. s = open(p).read()
  2443. old = """ Ebyte (JccShortInv (cc)) ; (* Jcc_s, taken when cc does NOT hold *)
  2444. Ebyte (03H) ; (* rel8: step over the 3-byte EJMP *)
  2445. RETURN EmJmpNear (target) (* target = 0 => forward, see above *)"""
  2446. new = """ Ebyte (0FH) ; Ebyte (cc) ; Eword (0) ;
  2447. IF target = 0 THEN
  2448. RETURN nPatch
  2449. END ;
  2450. RETURN 0"""
  2451. assert s.count(old) == 1, 'EmJcc body found %d times -- update this mutation' % s.count(old)
  2452. open(p, 'w').write(s.replace(old, new))
  2453. PYX
  2454. then
  2455. if rebuild_compiler; then
  2456. expect_red "check_8086 catches a 0F 8x branch (the original bug)" \
  2457. "0F 84" python3 tests/check_8086.py
  2458. else
  2459. echo " FAIL: the compiler would not rebuild with the 0F branch"
  2460. fail=$((fail + 1))
  2461. fi
  2462. else
  2463. echo " BROKEN CASE: the 0F branch mutation did not apply"
  2464. fail=$((fail + 1))
  2465. fi
  2466. cp "$SAVED_C" Compiler.mod
  2467. # M2: the other original defect, SETcc plus the MOV AH,0 it needed.
  2468. cp "$SAVED_C" Compiler.mod
  2469. if python3 - <<'PYX'
  2470. p = 'Compiler.mod'
  2471. s = open(p).read()
  2472. old = """ Ebyte (0B8H) ; Eword (1) ; (* MOV AX,#0001 *)
  2473. Ebyte (JccShort (cc)) ; (* taken when the comparison HOLDS *)
  2474. Ebyte (01H) ; (* rel8: step over the DEC AX *)
  2475. Ebyte (48H) (* DEC AX *)"""
  2476. new = """ Ebyte (0FH) ; Ebyte (cc) ; Ebyte (0C0H) ;
  2477. EmMovAh0 ()"""
  2478. assert s.count(old) == 1, 'EmSetcc body found %d times -- update this mutation' % s.count(old)
  2479. open(p, 'w').write(s.replace(old, new))
  2480. PYX
  2481. then
  2482. if rebuild_compiler; then
  2483. expect_red "check_8086 catches a 0F 9x SETcc (the original bug)" \
  2484. "0F 9F C0" python3 tests/check_8086.py
  2485. else
  2486. echo " FAIL: the compiler would not rebuild with the 0F SETcc"
  2487. fail=$((fail + 1))
  2488. fi
  2489. else
  2490. echo " BROKEN CASE: the 0F SETcc mutation did not apply"
  2491. fail=$((fail + 1))
  2492. fi
  2493. cp "$SAVED_C" Compiler.mod
  2494. # M4: the polarity inversion, everywhere. Note the expected text is clause H's,
  2495. # not a shape complaint: every byte here is a legal 8086 shape, which is the
  2496. # entire reason a separate clause had to be written.
  2497. cp "$SAVED_C" Compiler.mod
  2498. if python3 - <<'PYX'
  2499. p = 'Compiler.mod'
  2500. s = open(p).read()
  2501. old = ' Ebyte (JccShortInv (cc)) ; (* Jcc_s, taken when cc does NOT hold *)'
  2502. new = ' Ebyte (JccShort (cc)) ; (* MUTATION: inversion dropped *)'
  2503. assert s.count(old) == 1, 'EmJcc Ebyte found %d times -- update this mutation' % s.count(old)
  2504. open(p, 'w').write(s.replace(old, new))
  2505. PYX
  2506. then
  2507. if rebuild_compiler; then
  2508. expect_red "clause H catches the branch polarity inverted everywhere" \
  2509. "but reading the source says" python3 tests/check_8086.py
  2510. else
  2511. echo " FAIL: the compiler would not rebuild with the inversion dropped"
  2512. fail=$((fail + 1))
  2513. fi
  2514. else
  2515. echo " BROKEN CASE: the polarity mutation did not apply"
  2516. fail=$((fail + 1))
  2517. fi
  2518. cp "$SAVED_C" Compiler.mod
  2519. # M5: the same inversion dropped for the IF and CASE sites ONLY. This one is
  2520. # the reason clause H exists: it was run by hand and the check stayed GREEN,
  2521. # and FOR's C/F nibbles were the only reason the whole-suite version (M4)
  2522. # happened to be caught.
  2523. cp "$SAVED_C" Compiler.mod
  2524. if python3 - <<'PYX'
  2525. p = 'Compiler.mod'
  2526. s = open(p).read()
  2527. old = ' Ebyte (JccShortInv (cc)) ; (* Jcc_s, taken when cc does NOT hold *)'
  2528. new = """ IF (cc = 84H) OR (cc = 85H) THEN
  2529. Ebyte (JccShort (cc)) (* MUTATION: no inversion here *)
  2530. ELSE
  2531. Ebyte (JccShortInv (cc))
  2532. END ;"""
  2533. assert s.count(old) == 1, 'EmJcc Ebyte found %d times -- update this mutation' % s.count(old)
  2534. open(p, 'w').write(s.replace(old, new))
  2535. PYX
  2536. then
  2537. if rebuild_compiler; then
  2538. expect_red "clause H catches the inversion dropped for IF and CASE only" \
  2539. "t22_case" python3 tests/check_8086.py
  2540. else
  2541. echo " FAIL: the compiler would not rebuild with the partial inversion"
  2542. fail=$((fail + 1))
  2543. fi
  2544. else
  2545. echo " BROKEN CASE: the partial-inversion mutation did not apply"
  2546. fail=$((fail + 1))
  2547. fi
  2548. cp "$SAVED_C" Compiler.mod
  2549. # And the check on the RESTORED compiler, so a green above cannot come from a
  2550. # mutation that failed to take and left the real defect in place.
  2551. if rebuild_compiler; then
  2552. if python3 tests/check_8086.py >/dev/null 2>&1; then
  2553. echo " ok: check_8086 green on the restored compiler"
  2554. pass=$((pass + 1))
  2555. else
  2556. echo "NOT RESTORED: check_8086.py is red after restoring Compiler.mod"
  2557. python3 tests/check_8086.py 2>&1 | grep -m3 -- ' - ' | sed 's/^/ /'
  2558. fail=$((fail + 1))
  2559. fi
  2560. else
  2561. echo "NOT RESTORED: the compiler would not rebuild"
  2562. fail=$((fail + 1))
  2563. fi
  2564. echo
  2565. echo "== the emitter-name audit of Compiler.mod (audit_helpers.py)"
  2566. # These need no rebuild: the audit reads the SOURCE, not the built object, so
  2567. # they are the cheapest cases here and they cover the module the audit used
  2568. # not to look at at all. That is the point of the section: the audit reported
  2569. # "every helper agrees with its name" for a module it had never examined, and
  2570. # EmXchgAxCx was `93` (XCHG BX,AX) under a name that says XCHG AX,CX for the
  2571. # whole life of the project. Two of these five are for faults that were real.
  2572. SAVED_C2=../tmp/nonvacuity.Compiler.mod.2
  2573. SAVED_R2=../tmp/nonvacuity.Runtime.mod.2
  2574. cp Compiler.mod "$SAVED_C2" || exit 1
  2575. cp Runtime.mod "$SAVED_R2" || exit 1
  2576. restore_audit_sources () {
  2577. cp "$SAVED_C2" Compiler.mod
  2578. cp "$SAVED_R2" Runtime.mod
  2579. }
  2580. AUD="python3 tests/audit_helpers.py"
  2581. # 1. THE fault. 91h is XCHG AX,CX; 93h is XCHG BX,AX. Both are one byte, so
  2582. # the compile matrix never moved and the byte counts never moved.
  2583. cp "$SAVED_C2" Compiler.mod
  2584. mutate Compiler.mod 's|^ Ebyte (91H)$| Ebyte (93H)|'
  2585. expect_red "audit catches XchgAxCx emitting XCHG BX,AX" \
  2586. "exchanges Ax and Bx" $AUD
  2587. restore_audit_sources
  2588. # 2. the coverage check itself. A parameter list that find_helpers does not
  2589. # accept is exactly how the real emitter was missed, and the inventory is
  2590. # scanned separately on purpose so this can be caught. Without the
  2591. # independent scan this case is silent, because both lists would come from
  2592. # the same parser and agree that the helper does not exist.
  2593. cp "$SAVED_C2" Compiler.mod
  2594. mutate Compiler.mod 's|^PROCEDURE EmXchgAxCx () ;$|PROCEDURE EmXchgAxCx (why : CARDINAL) ;|'
  2595. expect_red "audit reports an emitter it cannot reach, rather than skipping it" \
  2596. "never examined it" $AUD
  2597. restore_audit_sources
  2598. # 3. EmXchgAxDx was named EmMoveAxDx, which said MOV where the bytes say XCHG.
  2599. # 93h here is XCHG AX,BX - one letter away, the exact class of mistake the
  2600. # name is supposed to make impossible.
  2601. cp "$SAVED_C2" Compiler.mod
  2602. mutate Compiler.mod 's|^ Ebyte (92H)$| Ebyte (93H)|'
  2603. expect_red "audit catches XchgAxDx emitting XCHG BX,AX" \
  2604. "XchgAxDx" $AUD
  2605. restore_audit_sources
  2606. # 4. CmpArgW0's [BP+2] written as the 386 SIB form, which decodes on a 8086 as
  2607. # [SI+24h]. A real bug: the runtime was clearing the wrong memory.
  2608. cp "$SAVED_R2" Runtime.mod
  2609. mutate Runtime.mod 's| B (83H) ; B (7EH) ; B (2) ; B (0) ;| B (83H) ; B (7CH) ; B (24) ; B (0) ; B (0) ;|'
  2610. expect_red "audit catches the [SI+24h] encoding of [BP+2]" \
  2611. "memory base is 'si" $AUD
  2612. restore_audit_sources
  2613. # 5. MovAxSp is POP then PUSH, because MOV AX,[SP] does not exist on an 8086.
  2614. # Dropping the POP leaves the stack one word short - a fault in the shape,
  2615. # not in a byte value.
  2616. cp "$SAVED_C2" Compiler.mod
  2617. python3 - <<'PYEOF'
  2618. p='Compiler.mod'; s=open(p).read()
  2619. a=" Ebyte (58H) ; (* POP AX *)\n"
  2620. assert s.count(a)==1, "EmMovAxSp POP line not found -- update this mutation"
  2621. open(p,'w').write(s.replace(a, ""))
  2622. PYEOF
  2623. expect_red "audit catches MovAxSp with its POP missing" \
  2624. "MovAxSp" $AUD
  2625. restore_audit_sources
  2626. # 6. The two-instruction shape: IDIV is CWD then IDIV, and dropping the CWD
  2627. # leaves an un-sign-extended dividend in DX:AX. Both are still present as
  2628. # a two-step spec, so a missing step has to be visible.
  2629. cp "$SAVED_C2" Compiler.mod
  2630. mutate Compiler.mod 's| Ebyte (99H) ; Ebyte (0F7H) ; Ebyte (0F9H)| Ebyte (0F7H) ; Ebyte (0F9H)|'
  2631. expect_red "audit catches IDiv without the CWD that extends the dividend" \
  2632. "IDivAxCx" $AUD
  2633. restore_audit_sources
  2634. # 7. The byte under EmXorAl01's name, and the row in PATTERNS that was added
  2635. # to admit it. `34 01' is XOR AL,#01 - the boolean NOT, and the one emitter
  2636. # in Compiler.mod with no ModRM byte at all. A grammar row nobody has ever
  2637. # seen reject anything cannot be trusted to accept only the truth, so here
  2638. # is the rejection: `34 02' is the same length, decodes just as cleanly, and
  2639. # `not x' would flip bit 1 instead of bit 0.
  2640. cp "$SAVED_C2" Compiler.mod
  2641. mutate Compiler.mod 's|^ Ebyte (34H) ; Ebyte (01H)| Ebyte (34H) ; Ebyte (02H)|'
  2642. expect_red "audit catches EmXorAl01 emitting xor al,#2 under a name saying #1" \
  2643. "XorAl01" $AUD
  2644. restore_audit_sources
  2645. # 7b. The other half of that row: the opcode gate. 34h is XOR AL,#imm and
  2646. # 35h is XOR AX,#imm - a word, not a byte, under a name that says AL. The
  2647. # row is pinned to {034h} on purpose, and a pin that has never been asked
  2648. # to hold is a pin. The report is the one thing the row above cannot
  2649. # produce: with no reading at all, the helper falls out of the grammar.
  2650. cp "$SAVED_C2" Compiler.mod
  2651. mutate Compiler.mod 's|^ Ebyte (34H) ; Ebyte (01H)| Ebyte (35H) ; Ebyte (01H)|'
  2652. expect_red "the opcode gate rejects XOR AX under an XOR AL name" \
  2653. "no name pattern accepts it" $AUD
  2654. restore_audit_sources
  2655. if $AUD >/dev/null 2>&1; then
  2656. echo " ok: the audit passes on both restored sources"
  2657. pass=$((pass + 1))
  2658. else
  2659. echo "NOT RESTORED: the audit is red after restoring the sources"
  2660. $AUD 2>&1 | sed 's/^/ /'
  2661. fail=$((fail + 1))
  2662. fi
  2663. echo
  2664. echo "== the BP contract rt_exec.py checks before it starts a machine"
  2665. # wrchar and wrbool both borrowed BP to reach their argument -- [SP] is not
  2666. # encodable in 16-bit mode -- and neither saved it. The driver's cursor into
  2667. # the case record lives in BP precisely because BP is the one register an entry
  2668. # may keep, so "wrchar borrowed it and did not give it back" sent the second
  2669. # call to a garbage address, the machine triple-faulted, and the run printed the
  2670. # record header twice and hung. Both the golden and the audit call that shape
  2671. # CORRECT: the bytes are well formed, every branch is on a boundary, the size
  2672. # is unchanged, and the decode says exactly what it says. So the rule is now
  2673. # checked directly, and these two cases are what make that check more than a
  2674. # claim.
  2675. #
  2676. # rt_exec.py needs the whole runtime rebuilt and then boots 36 machines, so this
  2677. # section is the slow one. The baseline comes first and is asserted: a case
  2678. # that mutates a red tree proves nothing.
  2679. SAVED_R3=../tmp/nonvacuity.Runtime.mod.3
  2680. cp Runtime.mod "$SAVED_R3" || exit 1
  2681. if rebuild; then
  2682. if python3 tests/rt_exec.py >/dev/null 2>&1; then
  2683. echo " ok: baseline - rt_exec.py passes on the unmutated runtime"
  2684. pass=$((pass + 1))
  2685. else
  2686. echo " FAIL: the baseline is already red, so the cases below prove"
  2687. echo " nothing - fix the baseline before reading them"
  2688. python3 tests/rt_exec.py 2>&1 | tail -3 | sed 's/^/ /'
  2689. fail=$((fail + 1))
  2690. fi
  2691. else
  2692. echo " FAIL: could not rebuild the runtime for the baseline"
  2693. fail=$((fail + 1))
  2694. fi
  2695. # 1. THE fault: drop the PUSH, exactly as EmitWrChar was written. This is the
  2696. # shape the behavioural case found, so the byte-level check must find it too
  2697. # -- a check that only the expensive test can trip is a check that has not
  2698. # been made to earn its place.
  2699. cp "$SAVED_R3" Runtime.mod
  2700. python3 - <<'PYEOF'
  2701. p = 'Runtime.mod'
  2702. s = open(p).read()
  2703. a = ' M ("wrchar") ;\n PushBp ; MovBpSp ;\n'
  2704. assert s.count(a) == 1, "EmitWrChar prologue not found exactly once"
  2705. open(p, 'w').write(s.replace(a, ' M ("wrchar") ;\n MovBpSp ;\n'))
  2706. PYEOF
  2707. if rebuild; then
  2708. expect_red "the BP contract catches wrchar borrowing BP unsaved" \
  2709. "borrows BP but does not open with" python3 tests/rt_exec.py
  2710. else
  2711. echo " FAIL: the runtime would not rebuild with the PUSH removed"
  2712. fail=$((fail + 1))
  2713. fi
  2714. cp "$SAVED_R3" Runtime.mod
  2715. # 2. The mirror image: push it and never pop it. A different one-instruction
  2716. # omission with the same consequence for a caller, and the reason the rule
  2717. # asks for the 5D and not just the 55.
  2718. cp "$SAVED_R3" Runtime.mod
  2719. mutate Runtime.mod 's|^ MovSpBp ; PopBp ;$| MovSpBp ;|'
  2720. if rebuild; then
  2721. expect_red "the BP contract catches a BP that is pushed and never popped" \
  2722. "pushes BP but never pops it" python3 tests/rt_exec.py
  2723. else
  2724. echo " FAIL: the runtime would not rebuild with the POP removed"
  2725. fail=$((fail + 1))
  2726. fi
  2727. cp "$SAVED_R3" Runtime.mod
  2728. # 3. The scan's other silent failure: a rule that matches nothing looks exactly
  2729. # like a rule that passes. The pattern the check looks for is changed to one
  2730. # the blob does not contain -- MOV BP,DI, which the runtime has no reason to
  2731. # emit -- so the check has examined thirteen entries and matched nothing and
  2732. # MUST say so rather than report a clean sweep. This is the general shape of
  2733. # the fault this project keeps making: a check whose SUBJECT has drifted
  2734. # reports a confident answer about the wrong thing.
  2735. cp "$SAVED_R3" Runtime.mod
  2736. SAVED_X=../tmp/nonvacuity.rt_exec.py
  2737. cp tests/rt_exec.py "$SAVED_X" || exit 1
  2738. mutate tests/rt_exec.py 's|^MOV_BP_SP = b"\\x8b\\xec" .*$|MOV_BP_SP = b"\\x8b\\xed" # MOV BP,DI: never emitted|' \
  2739. expect_red "a check that matched nothing is a failure, not a pass" \
  2740. "matched nothing" python3 tests/rt_exec.py
  2741. cp "$SAVED_X" tests/rt_exec.py
  2742. if rebuild; then
  2743. if python3 tests/rt_exec.py >/dev/null 2>&1; then
  2744. echo " ok: rt_exec.py passes on the restored source"
  2745. pass=$((pass + 1))
  2746. else
  2747. echo "NOT RESTORED: rt_exec.py is red after restoring Runtime.mod"
  2748. python3 tests/rt_exec.py 2>&1 | tail -3 | sed 's/^/ /'
  2749. fail=$((fail + 1))
  2750. fi
  2751. else
  2752. echo "NOT RESTORED: the runtime would not rebuild"
  2753. fail=$((fail + 1))
  2754. fi
  2755. # 4. The GOLDEN and the entry goldens, which are the other half of the same
  2756. # rule. rt_exec.py states the contract; check_runtime.py pins the bytes.
  2757. # They are separate mechanisms and the case below is what shows the golden
  2758. # one works on its own -- a re-baseline of runtime.golden would otherwise
  2759. # have absorbed the new prologues silently, and the next person to bless it
  2760. # would have no way to know the PUSH and POP were ever missing.
  2761. cp "$SAVED_R3" Runtime.mod
  2762. python3 - <<'PYEOF'
  2763. p = 'Runtime.mod'
  2764. s = open(p).read()
  2765. a = ' M ("wrchar") ;\n PushBp ; MovBpSp ;\n MovAlArg4 ;\n MovSpBp ; PopBp ;\n'
  2766. assert s.count(a) == 1, "EmitWrChar frame not found exactly once"
  2767. open(p, 'w').write(s.replace(a, ' M ("wrchar") ;\n MovBpSp ;\n MovAlArg2 ;\n MovSpBp ;\n'))
  2768. PYEOF
  2769. if rebuild; then
  2770. expect_red "the entry golden catches wrchar without its PUSH BP" \
  2771. "entry wrchar starts 8B EC" python3 tests/check_runtime.py "$DUMP"
  2772. else
  2773. echo " FAIL: the runtime would not rebuild with wrchar's frame removed"
  2774. fail=$((fail + 1))
  2775. fi
  2776. cp "$SAVED_R3" Runtime.mod
  2777. echo
  2778. echo "== the .COM layout check, and the runtime size it now measures"
  2779. # The checker used to RESTATE the runtime's size as a literal. It had drifted
  2780. # from the runtime it described, so the header was read out of the code stream
  2781. # and EVERY linked fixture "failed" on it - a whole file of "failures" that were
  2782. # not findings at all. A duplicated constant that has drifted does not fail
  2783. # loudly; it re-reports the same falsehood, in which the real failures hide.
  2784. # The size is now MEASURED from the image.
  2785. #
  2786. # These cases corrupt a real emitted .COM and require the checker to notice.
  2787. # They need the images, so they are built once and copied; the checker has a
  2788. # --check-only mode for exactly this, because its scratch directory is normally
  2789. # deleted on exit and a check that has only ever seen the truth is not a check.
  2790. KEEPDIR=../tmp/nonvacuity.com
  2791. rm -rf "$KEEPDIR"
  2792. TP_COM_KEEP=1 tests/run_com_tests.sh >../tmp/nonvacuity.com.log 2>&1
  2793. KEEP=$(sed -n 's/^TP_COM_KEEP=1: images left in //p' \
  2794. ../tmp/nonvacuity.com.log | tail -1)
  2795. if [ -z "$KEEP" ] || [ ! -d "$KEEP" ]; then
  2796. echo " FAIL: could not obtain emitted .COM images for the layout cases"
  2797. fail=$((fail + 1))
  2798. else
  2799. COMCHK="tests/run_com_tests.sh --check-only"
  2800. # 0. The baseline. Every case below is a claim that a specific assertion
  2801. # turns red, and none of them means anything if the copies of untouched
  2802. # images already fail. (The stale RT_SZ produced exactly that: a whole
  2803. # file of "failures" that were not findings.) So this is asserted first,
  2804. # and a failure here is reported as a broken baseline rather than a red
  2805. # test.
  2806. #
  2807. # The baseline is also WHERE THE HEADER OFFSET COMES FROM. Cases 1 and 2
  2808. # used to carry it as the literal 435 and 439, which were ENT_SZ + the
  2809. # runtime size at the time -- 432. Two 4-byte changes to the runtime
  2810. # later, both cases were editing the wrong bytes: 435 had become four
  2811. # bytes inside the runtime itself, so case 1 had stopped testing "the
  2812. # header cannot be found" and had started testing "the checker also
  2813. # notices you scribbled on the code", and case 2 had become a no-op
  2814. # that wrote the header where it already was. Both still went red, for
  2815. # reasons the messages did not name, which is the whole problem: a
  2816. # hard-coded offset is a claim about the world that expires silently.
  2817. #
  2818. # So the offset is read back out of the checker's own report on the
  2819. # untouched images, and the expected numbers below are ARITHMETIC ON IT.
  2820. # If the runtime grows again, these cases still test what they say.
  2821. rm -rf "$KEEPDIR"; mkdir -p "$KEEPDIR"
  2822. cp "$KEEP"/*.COM "$KEEP"/raw.txt "$KEEPDIR"/
  2823. BASE_OUT=$($COMCHK "$KEEPDIR" 2>&1)
  2824. if [ $? -eq 0 ]; then
  2825. echo " ok: baseline - untouched copies of the real images all pass"
  2826. pass=$((pass + 1))
  2827. else
  2828. echo " FAIL: the baseline is already red, so the cases below prove"
  2829. echo " nothing - fix the baseline before reading them"
  2830. printf '%s\n' "$BASE_OUT" | grep FAIL | head -3 | sed 's/^/ /'
  2831. fail=$((fail + 1))
  2832. fi
  2833. BASE_RT=$(printf '%s\n' "$BASE_OUT" \
  2834. | sed -n 's/.*measured runtime size: \([0-9][0-9]*\) bytes.*/\1/p' \
  2835. | head -1)
  2836. if [ -z "$BASE_RT" ]; then
  2837. echo " FAIL: the checker did not report the runtime size it measured,"
  2838. echo " so the cases below cannot find the header to edit"
  2839. fail=$((fail + 1))
  2840. BASE_RT=0
  2841. fi
  2842. # The layout constants are ENT_SZ 3 and HDR_SZ 16 (tests/comimage.py), so the
  2843. # header sits at hdrOff = 3 + rtSz and the entry jump's displacement must be
  2844. # (hdrOff + 16) - 3. The wanted number is therefore computed from the header
  2845. # OFFSET, not from rtSz: the two differ by 3, and getting that backwards
  2846. # produces a plausible-looking expectation three bytes out, which is how
  2847. # this case came to expect "want 452" and then be reported as not proving
  2848. # what it said.
  2849. BASE_OFF=$((3 + BASE_RT))
  2850. # Case 2 claims a runtime four bytes LONGER, so the header - and with it the
  2851. # demanded jump target - moves four bytes further on.
  2852. SHIFTED_WANT=$((BASE_OFF + 4 + 16 - 3))
  2853. echo " (measured runtime size $BASE_RT, header at image offset $BASE_OFF)"
  2854. # 1. Break hdrDS so it no longer ties the header to its own offset. The
  2855. # header must become UNFINDABLE and be reported as such - a checker that
  2856. # fell back to a remembered offset would report a confident number here,
  2857. # which is the failure mode the measurement was introduced to remove.
  2858. rm -rf "$KEEPDIR"; mkdir -p "$KEEPDIR"
  2859. cp "$KEEP"/*.COM "$KEEP"/raw.txt "$KEEPDIR"/
  2860. python3 - "$KEEPDIR/t01_minimal.COM" "$BASE_OFF" <<'PYEOF'
  2861. import sys
  2862. p, off = sys.argv[1], int(sys.argv[2])
  2863. d = bytearray(open(p, 'rb').read())
  2864. d[off + 4:off + 6] = (0x1234).to_bytes(2, 'little') # hdrDS, no longer self-consistent
  2865. open(p, 'wb').write(bytes(d))
  2866. PYEOF
  2867. expect_red "a header that cannot be located is reported, not assumed" \
  2868. "no program header found" $COMCHK "$KEEPDIR"
  2869. # 2. The entry jump is now the locator: it names the first instruction,
  2870. # and the header sits HDR_SZ bytes before it. Moving the jump four
  2871. # bytes off means no header is named, and the check must say so rather
  2872. # than fall back on a remembered runtime size.
  2873. rm -rf "$KEEPDIR"; mkdir -p "$KEEPDIR"
  2874. cp "$KEEP"/*.COM "$KEEP"/raw.txt "$KEEPDIR"/
  2875. python3 - "$KEEPDIR/t01_minimal.COM" <<'PYEOF'
  2876. import sys
  2877. p = sys.argv[1]
  2878. d = bytearray(open(p, 'rb').read())
  2879. rel = int.from_bytes(d[1:3], 'little')
  2880. d[1:3] = ((rel + 4) & 0xFFFF).to_bytes(2, 'little')
  2881. open(p, 'wb').write(bytes(d))
  2882. PYEOF
  2883. expect_red "the entry jump must name the header it follows" \
  2884. "no program header found" $COMCHK "$KEEPDIR"
  2885. # 3. The entry jump's opcode. One byte, and the only assertion in the
  2886. # project that can see where execution STARTS.
  2887. rm -rf "$KEEPDIR"; mkdir -p "$KEEPDIR"
  2888. cp "$KEEP"/*.COM "$KEEP"/raw.txt "$KEEPDIR"/
  2889. python3 - "$KEEPDIR/t01_minimal.COM" <<'PYEOF'
  2890. import sys
  2891. p = sys.argv[1]
  2892. d = bytearray(open(p, 'rb').read())
  2893. d[0] = 0xEA
  2894. open(p, 'wb').write(bytes(d))
  2895. PYEOF
  2896. expect_red "the entry jump must be E9, not a near JMP" \
  2897. "no program header found" $COMCHK "$KEEPDIR"
  2898. # 4. The entry jump's target, moved one instruction earlier. A .COM that
  2899. # lands in the middle of the prologue runs, prints something and exits
  2900. # cleanly, so no size or structure check can see this.
  2901. rm -rf "$KEEPDIR"; mkdir -p "$KEEPDIR"
  2902. cp "$KEEP"/*.COM "$KEEP"/raw.txt "$KEEPDIR"/
  2903. python3 - "$KEEPDIR/t01_minimal.COM" <<'PYEOF'
  2904. import sys
  2905. p = sys.argv[1]
  2906. d = bytearray(open(p, 'rb').read())
  2907. d[1:3] = (100).to_bytes(2, 'little')
  2908. open(p, 'wb').write(bytes(d))
  2909. PYEOF
  2910. expect_red "the entry jump must land on the first instruction" \
  2911. "no program header found" $COMCHK "$KEEPDIR"
  2912. rm -rf "$KEEPDIR"
  2913. fi
  2914. echo
  2915. echo "non-vacuity: $pass ok, $fail failed"
  2916. [ "$fail" -eq 0 ]