omega-office
Omega office documents: read and write office files in Omega
Brought by drakestapleton
omega-office / tests / gate.om
| 1 | om2 |
| 2 | note tests/gate.om: the omega-office gate. Run from the repository root: |
| 3 | note OMC < tests/gate.om > build/gate-bin && chmod +x build/gate-bin && build/gate-bin OMC |
| 4 | note 1. Refuses (NOT_RUN, exit 3) unless the compiler's SHA-256 is the pin PIN below (and in the file |
| 5 | note PIN); SHA-256 (FIPS 180-4) is computed here. |
| 6 | note 2. Builds officeread from UNITS with that compiler (build/gate/officeread). |
| 7 | note 3. Runs every case of tests/cases.txt: exit status, stdout against the oracle's bytes, and stderr |
| 8 | note (empty after success, exactly one line "officeread: ..." or "ozip: ..." after a refusal). |
| 9 | note 4. Builds every mutant of tests/mutants.txt (lines replaced) and requires some case to fail on it. |
| 10 | note 5. Robustness (rob lines): each input cut at 64 points and changed at 256 single bytes. Every run must |
| 11 | note end with exit 0 or a documented refusal code, never a trap (101..114), a signal or the time |
| 12 | note limit (10 s each). An exit 0 must print the unchanged input's output, except for a plain XML file |
| 13 | note (no checksum: a changed byte can be a changed character), counted as "changed-plain". |
| 14 | note 6. Before step 3, builds tests/docs.om with the same compiler and runs it: publication checks of the |
| 15 | note repository's own text (rules tests/docrules.txt, its own mutants tests/docmutants.txt). Its |
| 16 | note output is copied here, and any exit but 0 fails the gate. |
| 17 | note Exit 0 with the last line "OFFICEREADGATE PASS ...", 1 FAIL, 3 NOT_RUN. Scratch: build/gate (recreated). |
| 18 | |
| 19 | text PIN "6d1b1cf5a44803389a831b67f750ea4cd1c9f53edfde9d6d9241d7352887f1f8" |
| 20 | text UNITS "src/head.om vendor/omega-zip/vendor/omega-mv/seed/text/text.om vendor/omega-zip/src/io.om vendor/omega-zip/src/crc32.om vendor/omega-zip/src/inflate.om vendor/omega-zip/src/unzip.om src/xml.om src/sink.om src/opc.om src/docx.om src/xlsx.om src/main.om" |
| 21 | const TLIM long 10000000000 |
| 22 | const CLIM long 300000000000 |
| 23 | const GXH ulong 8388608 |
| 24 | |
| 25 | global cs uchar 262144 |
| 26 | global csn ulong 1 |
| 27 | global mu uchar 65536 |
| 28 | global mun ulong 1 |
| 29 | global sr uchar 1048576 |
| 30 | global srn ulong 1 |
| 31 | global ub uchar 262144 |
| 32 | global ca uchar 65536 |
| 33 | global cb uchar 65536 |
| 34 | global rb uchar 1048576 |
| 35 | global gx uchar 16777216 |
| 36 | global pk uchar 4096 |
| 37 | global pkn ulong 1 |
| 38 | global pkc ulong 1 |
| 39 | global pa uchar 4096 |
| 40 | global pan ulong 1 |
| 41 | global pb uchar 4096 |
| 42 | global pbn ulong 1 |
| 43 | global om uchar 4096 |
| 44 | global omn ulong 1 |
| 45 | global fs ulong 32 |
| 46 | global fe ulong 32 |
| 47 | global nf ulong 1 |
| 48 | note cnt: 0..3 passing runs by oracle (expat, LibreOffice text, LibreOffice CSV, exact expected file), |
| 49 | note 8..11 refusals by code range (XML 60..75, package 80..89, zip engine 2..53, usage 1); 20 mutants, 21 |
| 50 | note killed; 30 robustness runs, 31 refused, 32 exact, 33 changed-plain, 34 failures, 35 files, |
| 51 | note 36 accepted after a change (a refused plain XML file that a change made well-formed); 64 + code: runs |
| 52 | note refused with that code. |
| 53 | global cnt ulong 256 |
| 54 | global stb uchar 8 |
| 55 | global wp uchar 4096 |
| 56 | global hk uint 64 |
| 57 | global hh uint 8 |
| 58 | global hv uint 8 |
| 59 | global hw uint 64 |
| 60 | global hbk uchar 64 |
| 61 | note a mutant: up to 4 replacements r: unit mru[r], old line mu[mro[4r] .. mro[4r+1]), new line |
| 62 | note mu[mro[4r+2] .. mro[4r+3]), lines replaced mrh[r]; mrc replacements in all. |
| 63 | global mru ulong 4 |
| 64 | global mro ulong 16 |
| 65 | global mrh ulong 4 |
| 66 | global mrc ulong 1 |
| 67 | global failn ulong 1 |
| 68 | |
| 69 | text tnl "\n" |
| 70 | text tsp " " |
| 71 | text tdash "-" |
| 72 | text tbuild "build" |
| 73 | text tgdir "build/gate" |
| 74 | text tooff "build/gate/officeread" |
| 75 | text tmut "build/gate/mutant" |
| 76 | text tout "build/gate/out" |
| 77 | text terr "build/gate/err" |
| 78 | text trob "build/gate/rob.in" |
| 79 | text tref "build/gate/rob.ref" |
| 80 | text tnull "/dev/null" |
| 81 | text tcases "tests/cases.txt" |
| 82 | text tmutf "tests/mutants.txt" |
| 83 | text tdotom ".om" |
| 84 | text tpre1 "officeread: " |
| 85 | text tpre2 "ozip: " |
| 86 | text trobw "rob" |
| 87 | text txmlev "xmlev" |
| 88 | text tzip "zip" |
| 89 | text tfail "FAIL " |
| 90 | text tnotrun "OFFICEREADGATE NOT_RUN: " |
| 91 | text tbadpin "compiler sha256 is not the pin " |
| 92 | text tnoomc "usage: gate OMC (run from the repository root)" |
| 93 | text tcompile "build: compile failed: " |
| 94 | text tio "gate: I/O error on " |
| 95 | text twait "gate: fork or wait failed " |
| 96 | text tshort "malformed case line " |
| 97 | text tbig "gate: a file is above the comparison buffer " |
| 98 | |
| 99 | fn say t view uchar * to void |
| 100 | r = write 1 t 0 len t |
| 101 | end |
| 102 | |
| 103 | fn saypa to void |
| 104 | r = write 1 pa 0 get pan 0 |
| 105 | end |
| 106 | |
| 107 | fn saynum v ulong to void |
| 108 | b = new uchar 24 0 |
| 109 | x = v |
| 110 | for i ulong 20 |
| 111 | put b sub 19 i uchar add rem x 10 48 |
| 112 | x = div x 10 |
| 113 | end |
| 114 | k = ulong 0 |
| 115 | while lt k 19 bound 20 |
| 116 | if ne get b k 48 |
| 117 | break |
| 118 | end |
| 119 | k = add k 1 |
| 120 | end |
| 121 | r = write 1 b k sub 20 k |
| 122 | end |
| 123 | |
| 124 | fn die t view uchar * to void |
| 125 | say t |
| 126 | saypa |
| 127 | say tnl |
| 128 | exit 1 |
| 129 | end |
| 130 | |
| 131 | note ---- paths: pa and pb are built from texts and case fields ---- |
| 132 | fn pat t view uchar * to void |
| 133 | for i ulong len t bound 4096 |
| 134 | put pa i get t i |
| 135 | end |
| 136 | put pan 0 len t |
| 137 | end |
| 138 | |
| 139 | fn paadd t view uchar * to void |
| 140 | n = get pan 0 |
| 141 | for i ulong len t bound 4096 |
| 142 | put pa add n i get t i |
| 143 | end |
| 144 | put pan 0 add n len t |
| 145 | end |
| 146 | |
| 147 | fn pacs s ulong e ulong to void |
| 148 | n = get pan 0 |
| 149 | for i ulong sub e s bound 4096 |
| 150 | put pa add n i get cs add s i |
| 151 | end |
| 152 | put pan 0 add n sub e s |
| 153 | end |
| 154 | |
| 155 | fn pbt t view uchar * to void |
| 156 | for i ulong len t bound 4096 |
| 157 | put pb i get t i |
| 158 | end |
| 159 | put pbn 0 len t |
| 160 | end |
| 161 | |
| 162 | fn pbcs s ulong e ulong to void |
| 163 | for i ulong sub e s bound 4096 |
| 164 | put pb i get cs add s i |
| 165 | end |
| 166 | put pbn 0 sub e s |
| 167 | end |
| 168 | |
| 169 | note ---- argument packet for execprog: u16 count, then u16 length + bytes per argument ---- |
| 170 | fn pkreset to void |
| 171 | put pkn 0 2 |
| 172 | put pkc 0 0 |
| 173 | end |
| 174 | |
| 175 | fn pkhdr k ulong to ulong |
| 176 | n = get pkn 0 |
| 177 | put pk n uchar and k 255 |
| 178 | put pk add n 1 uchar shr k 8 |
| 179 | c = add get pkc 0 1 |
| 180 | put pkc 0 c |
| 181 | put pk 0 uchar and c 255 |
| 182 | put pk 1 uchar shr c 8 |
| 183 | ret add n 2 |
| 184 | end |
| 185 | |
| 186 | fn pkt t view uchar * to void |
| 187 | n = pkhdr len t |
| 188 | for i ulong len t bound 4096 |
| 189 | put pk add n i get t i |
| 190 | end |
| 191 | put pkn 0 add n len t |
| 192 | end |
| 193 | |
| 194 | fn pkpa to void |
| 195 | k = get pan 0 |
| 196 | n = pkhdr k |
| 197 | for i ulong k bound 4096 |
| 198 | put pk add n i get pa i |
| 199 | end |
| 200 | put pkn 0 add n k |
| 201 | end |
| 202 | |
| 203 | fn pkcs s ulong e ulong to void |
| 204 | n = pkhdr sub e s |
| 205 | for i ulong sub e s bound 4096 |
| 206 | put pk add n i get cs add s i |
| 207 | end |
| 208 | put pkn 0 add n sub e s |
| 209 | end |
| 210 | |
| 211 | fn pkom to void |
| 212 | k = get omn 0 |
| 213 | n = pkhdr k |
| 214 | for i ulong k bound 4096 |
| 215 | put pk add n i get om i |
| 216 | end |
| 217 | put pkn 0 add n k |
| 218 | end |
| 219 | |
| 220 | note ---- processes ---- |
| 221 | fn openout to int |
| 222 | fd = fopen pa 0 get pan 0 577 420 |
| 223 | if lt fd 0 |
| 224 | die tio |
| 225 | end |
| 226 | ret int fd |
| 227 | end |
| 228 | |
| 229 | note reap: wait for pid at most lim ns; the status as spawn describes it. |
| 230 | fn reap pid long lim long to ulong |
| 231 | t0 = monons |
| 232 | while true bound 100000000 |
| 233 | w = waitpid int pid stb 0 4 1 |
| 234 | if eq w pid |
| 235 | s = or ulong get stb 0 shl ulong get stb 1 8 |
| 236 | if eq and s 127 0 |
| 237 | ret and shr s 8 255 |
| 238 | end |
| 239 | ret add 1000 and s 127 |
| 240 | end |
| 241 | if lt w 0 |
| 242 | die twait |
| 243 | end |
| 244 | if gt sub monons t0 lim |
| 245 | r = killpid int pid 9 |
| 246 | w = waitpid int pid stb 0 4 0 |
| 247 | ret 2000 |
| 248 | end |
| 249 | r = sleepns 50000 |
| 250 | end |
| 251 | ret 2000 |
| 252 | end |
| 253 | |
| 254 | note spawn: run the packet with stdin pb (/dev/null when pbn is 0), stdout pa, stderr ep. The |
| 255 | note result: exit status 0..255, 1000 + signal, or 2000 when the time limit lim (ns) was reached |
| 256 | note (the child is then killed with SIGKILL and reaped). |
| 257 | fn spawn ep view uchar * lim long to ulong |
| 258 | fi = long -1 |
| 259 | if gt get pbn 0 0 |
| 260 | fi = fopen pb 0 get pbn 0 0 0 |
| 261 | else |
| 262 | fi = fopen tnull 0 len tnull 0 0 |
| 263 | end |
| 264 | if lt fi 0 |
| 265 | pat tnull |
| 266 | die tio |
| 267 | end |
| 268 | fo = openout |
| 269 | fx = fopen ep 0 len ep 577 420 |
| 270 | if lt fx 0 |
| 271 | die tio |
| 272 | end |
| 273 | pid = fork |
| 274 | if lt pid 0 |
| 275 | die twait |
| 276 | end |
| 277 | if eq pid 0 |
| 278 | r = dupfd int fi 0 0 |
| 279 | r = dupfd fo 1 0 |
| 280 | r = dupfd int fx 2 0 |
| 281 | r = execprog pk 0 get pkn 0 |
| 282 | exit 127 |
| 283 | end |
| 284 | r = fclose int fi |
| 285 | r = fclose fo |
| 286 | r = fclose int fx |
| 287 | ret reap pid lim |
| 288 | end |
| 289 | |
| 290 | note ---- files ---- |
| 291 | note rdinto: file pa into a big buffer (0 cs, 1 mu, 2 ub, 3 rb); the byte count. |
| 292 | fn rdinto which ulong to ulong |
| 293 | fd = fopen pa 0 get pan 0 0 0 |
| 294 | if lt fd 0 |
| 295 | die tio |
| 296 | end |
| 297 | n = ulong 0 |
| 298 | while true bound 1000 |
| 299 | r = long 0 |
| 300 | if eq which 0 |
| 301 | r = read int fd cs n sub len cs n |
| 302 | end |
| 303 | if eq which 1 |
| 304 | r = read int fd mu n sub len mu n |
| 305 | end |
| 306 | if eq which 2 |
| 307 | r = read int fd ub n sub len ub n |
| 308 | end |
| 309 | if eq which 3 |
| 310 | r = read int fd rb n sub len rb n |
| 311 | end |
| 312 | if lt r 0 |
| 313 | die tio |
| 314 | end |
| 315 | if eq r 0 |
| 316 | break |
| 317 | end |
| 318 | n = add n ulong r |
| 319 | end |
| 320 | r = fclose int fd |
| 321 | ret n |
| 322 | end |
| 323 | |
| 324 | note rdgx: file pa into gx[o .. o + GXH); the byte count (a larger file stops the gate). |
| 325 | fn rdgx o ulong to ulong |
| 326 | fd = fopen pa 0 get pan 0 0 0 |
| 327 | if lt fd 0 |
| 328 | die tio |
| 329 | end |
| 330 | n = ulong 0 |
| 331 | while true bound 100000 |
| 332 | if eq n GXH |
| 333 | die tbig |
| 334 | end |
| 335 | r = read int fd gx add o n sub GXH n |
| 336 | if lt r 0 |
| 337 | die tio |
| 338 | end |
| 339 | if eq r 0 |
| 340 | break |
| 341 | end |
| 342 | n = add n ulong r |
| 343 | end |
| 344 | r = fclose int fd |
| 345 | ret n |
| 346 | end |
| 347 | |
| 348 | note same: files pa and pb have equal bytes. |
| 349 | fn same to bool |
| 350 | fa = fopen pa 0 get pan 0 0 0 |
| 351 | if lt fa 0 |
| 352 | ret false |
| 353 | end |
| 354 | fb = fopen pb 0 get pbn 0 0 0 |
| 355 | if lt fb 0 |
| 356 | r = fclose int fa |
| 357 | ret false |
| 358 | end |
| 359 | ok = true |
| 360 | while true bound 1000000 |
| 361 | xa = read int fa ca 0 65536 |
| 362 | xb = read int fb cb 0 65536 |
| 363 | if ne xa xb |
| 364 | ok = false |
| 365 | break |
| 366 | end |
| 367 | if le xa 0 |
| 368 | if lt xa 0 |
| 369 | ok = false |
| 370 | end |
| 371 | break |
| 372 | end |
| 373 | for i ulong ulong xa |
| 374 | if ne get ca i get cb i |
| 375 | ok = false |
| 376 | end |
| 377 | end |
| 378 | if not ok |
| 379 | break |
| 380 | end |
| 381 | end |
| 382 | r = fclose int fa |
| 383 | r = fclose int fb |
| 384 | ret ok |
| 385 | end |
| 386 | |
| 387 | note ---- the stated normalisation for the LibreOffice oracles ---- |
| 388 | note gnorm: gx[o .. o+n) in place; the new length. Always: CR LF becomes LF. Text mode t also: a leading |
| 389 | note UTF-8 byte order mark is removed, and spaces and tabs at the end of each line and of the file. |
| 390 | fn gnorm o ulong n ulong t bool to ulong |
| 391 | e = add o n |
| 392 | i = o |
| 393 | if and t ge n 3 |
| 394 | b0 = eq get gx o 0xef |
| 395 | b1 = eq get gx add o 1 0xbb |
| 396 | if and b0 and b1 eq get gx add o 2 0xbf |
| 397 | i = add o 3 |
| 398 | end |
| 399 | end |
| 400 | w = o |
| 401 | ls = o |
| 402 | while lt i e bound 16777217 |
| 403 | c = get gx i |
| 404 | i = add i 1 |
| 405 | if eq c 13 |
| 406 | if lt i e |
| 407 | if eq get gx i 10 |
| 408 | continue |
| 409 | end |
| 410 | end |
| 411 | end |
| 412 | if and t eq c 10 |
| 413 | while gt w ls bound 16777217 |
| 414 | d = get gx sub w 1 |
| 415 | if and ne d 32 ne d 9 |
| 416 | break |
| 417 | end |
| 418 | w = sub w 1 |
| 419 | end |
| 420 | put gx w c |
| 421 | w = add w 1 |
| 422 | ls = w |
| 423 | continue |
| 424 | end |
| 425 | put gx w c |
| 426 | w = add w 1 |
| 427 | end |
| 428 | if t |
| 429 | while gt w ls bound 16777217 |
| 430 | d = get gx sub w 1 |
| 431 | if and ne d 32 ne d 9 |
| 432 | break |
| 433 | end |
| 434 | w = sub w 1 |
| 435 | end |
| 436 | end |
| 437 | ret sub w o |
| 438 | end |
| 439 | |
| 440 | note ncmp: stdout (build/gate/out) and the oracle file pb, both normalised (t: text mode), are equal. |
| 441 | fn ncmp t bool to bool |
| 442 | pat tout |
| 443 | na = rdgx 0 |
| 444 | for i ulong get pbn 0 bound 4096 |
| 445 | put pa i get pb i |
| 446 | end |
| 447 | put pan 0 get pbn 0 |
| 448 | nb = rdgx GXH |
| 449 | na = gnorm 0 na t |
| 450 | nb = gnorm GXH nb t |
| 451 | if ne na nb |
| 452 | ret false |
| 453 | end |
| 454 | for i ulong na bound 8388608 |
| 455 | if ne get gx i get gx add GXH i |
| 456 | ret false |
| 457 | end |
| 458 | end |
| 459 | ret true |
| 460 | end |
| 461 | |
| 462 | note errok: the stderr file: empty after exit 0, else exactly one line starting "officeread: " or "ozip: ". |
| 463 | fn errok code ulong to bool |
| 464 | fd = fopen terr 0 len terr 0 0 |
| 465 | if lt fd 0 |
| 466 | ret false |
| 467 | end |
| 468 | r = read int fd ca 0 65536 |
| 469 | c = fclose int fd |
| 470 | if lt r 0 |
| 471 | ret false |
| 472 | end |
| 473 | n = ulong r |
| 474 | if eq code 0 |
| 475 | ret eq n 0 |
| 476 | end |
| 477 | if lt n 8 |
| 478 | ret false |
| 479 | end |
| 480 | k1 = len tpre1 |
| 481 | p1 = ge n k1 |
| 482 | for i ulong k1 |
| 483 | if ne get ca i get tpre1 i |
| 484 | p1 = false |
| 485 | end |
| 486 | end |
| 487 | p2 = true |
| 488 | for i ulong 6 |
| 489 | if ne get ca i get tpre2 i |
| 490 | p2 = false |
| 491 | end |
| 492 | end |
| 493 | if not or p1 p2 |
| 494 | ret false |
| 495 | end |
| 496 | for i ulong sub n 1 |
| 497 | if eq get ca i 10 |
| 498 | ret false |
| 499 | end |
| 500 | end |
| 501 | ret eq get ca sub n 1 10 |
| 502 | end |
| 503 | |
| 504 | fn wrrob n ulong to void |
| 505 | fd = fopen trob 0 len trob 577 420 |
| 506 | if lt fd 0 |
| 507 | pat trob |
| 508 | die tio |
| 509 | end |
| 510 | if gt n 0 |
| 511 | r = write int fd rb 0 n |
| 512 | if ne r long n |
| 513 | pat trob |
| 514 | die tio |
| 515 | end |
| 516 | end |
| 517 | r = fclose int fd |
| 518 | end |
| 519 | |
| 520 | note ---- directories ---- |
| 521 | note wipe: remove the tree wp[0 .. n) (directories at most 8 deep) like rm -rf; O_DIRECTORY and |
| 522 | note O_NOFOLLOW (AArch64 values 16384 and 32768), so a symbolic link is removed, never followed. |
| 523 | fn wipe depth ulong n ulong to void |
| 524 | fd = fopen wp 0 n 49152 0 |
| 525 | if lt fd 0 |
| 526 | r = unlink wp 0 n |
| 527 | ret |
| 528 | end |
| 529 | d = new uchar 8192 0 |
| 530 | while true bound 100000 |
| 531 | k = getdnts int fd d 0 8192 |
| 532 | if le k 0 |
| 533 | break |
| 534 | end |
| 535 | o = ulong 0 |
| 536 | while lt o ulong k bound 8192 |
| 537 | dent d o n depth |
| 538 | rl = or ulong get d add o 16 shl ulong get d add o 17 8 |
| 539 | o = add o rl |
| 540 | end |
| 541 | end |
| 542 | r = fclose int fd |
| 543 | r = rmdir wp 0 n |
| 544 | end |
| 545 | |
| 546 | note dent: one getdents64 record at d[o ..] (name at 19, type at 18) below wp[0 .. n). |
| 547 | fn dent d view uchar * o ulong n ulong depth ulong to void |
| 548 | m = ulong 0 |
| 549 | while ne get d add add o 19 m 0 bound 256 |
| 550 | m = add m 1 |
| 551 | end |
| 552 | if eq m 1 |
| 553 | if eq get d add o 19 46 |
| 554 | ret |
| 555 | end |
| 556 | end |
| 557 | if eq m 2 |
| 558 | if eq get d add o 19 46 |
| 559 | if eq get d add o 20 46 |
| 560 | ret |
| 561 | end |
| 562 | end |
| 563 | end |
| 564 | put wp n 47 |
| 565 | b = add n 1 |
| 566 | c = add o 19 |
| 567 | for j ulong m bound 256 |
| 568 | put wp add b j get d add c j |
| 569 | end |
| 570 | q = add b m |
| 571 | if and eq get d add o 18 4 lt depth 8 |
| 572 | wipe add depth 1 q |
| 573 | ret |
| 574 | end |
| 575 | r = unlink wp 0 q |
| 576 | end |
| 577 | |
| 578 | fn mkd to void |
| 579 | r = makedir pa 0 get pan 0 493 |
| 580 | end |
| 581 | |
| 582 | fn wipepa to void |
| 583 | for i ulong get pan 0 bound 4096 |
| 584 | put wp i get pa i |
| 585 | end |
| 586 | wipe 0 get pan 0 |
| 587 | end |
| 588 | |
| 589 | note ---- SHA-256 (FIPS 180-4 section 6.2) of the compiler ---- |
| 590 | text KTAB "428a2f98 71374491 b5c0fbcf e9b5dba5 3956c25b 59f111f1 923f82a4 ab1c5ed5 d807aa98 12835b01 243185be 550c7dc3 72be5d74 80deb1fe 9bdc06a7 c19bf174 e49b69c1 efbe4786 0fc19dc6 240ca1cc 2de92c6f 4a7484aa 5cb0a9dc 76f988da 983e5152 a831c66d b00327c8 bf597fc7 c6e00bf3 d5a79147 06ca6351 14292967 27b70a85 2e1b2138 4d2c6dfc 53380d13 650a7354 766a0abb 81c2c92e 92722c85 a2bfe8a1 a81a664b c24b8b70 c76c51a3 d192e819 d6990624 f40e3585 106aa070 19a4c116 1e376c08 2748774c 34b0bcb5 391c0cb3 4ed8aa4a 5b9cca4f 682e6ff3 748f82ee 78a5636f 84c87814 8cc70208 90befffa a4506ceb bef9a3f7 c67178f2" |
| 591 | text IVTAB "6a09e667 bb67ae85 3c6ef372 a54ff53a 510e527f 9b05688c 1f83d9ab 5be0cd19" |
| 592 | |
| 593 | fn hexv c uchar to uint |
| 594 | if le c 57 |
| 595 | ret uint sub c 48 |
| 596 | end |
| 597 | ret uint sub c 87 |
| 598 | end |
| 599 | |
| 600 | fn shainit to void |
| 601 | for i ulong 64 |
| 602 | v = uint 0 |
| 603 | for j ulong 8 |
| 604 | v = or shl v 4 hexv get KTAB add mul i 9 j |
| 605 | end |
| 606 | put hk i v |
| 607 | end |
| 608 | for i ulong 8 |
| 609 | v = uint 0 |
| 610 | for j ulong 8 |
| 611 | v = or shl v 4 hexv get IVTAB add mul i 9 j |
| 612 | end |
| 613 | put hh i v |
| 614 | end |
| 615 | end |
| 616 | |
| 617 | fn shablk to void |
| 618 | for t ulong 16 |
| 619 | b = mul t 4 |
| 620 | x = or shl uint get hbk b 24 shl uint get hbk add b 1 16 |
| 621 | y = or shl uint get hbk add b 2 8 uint get hbk add b 3 |
| 622 | put hw t or x y |
| 623 | end |
| 624 | for t ulong 48 |
| 625 | u = add t 16 |
| 626 | x = get hw sub u 15 |
| 627 | y = get hw sub u 2 |
| 628 | s0 = xor xor rotr x 7 rotr x 18 shr x 3 |
| 629 | s1 = xor xor rotr y 17 rotr y 19 shr y 10 |
| 630 | z = add get hw sub u 16 s0 |
| 631 | z = add z add get hw sub u 7 s1 |
| 632 | put hw u z |
| 633 | end |
| 634 | for i ulong 8 |
| 635 | put hv i get hh i |
| 636 | end |
| 637 | for t ulong 64 |
| 638 | e = get hv 4 |
| 639 | s1 = xor xor rotr e 6 rotr e 11 rotr e 25 |
| 640 | ch = xor and e get hv 5 and not e get hv 6 |
| 641 | t1 = add get hv 7 s1 |
| 642 | t1 = add t1 ch |
| 643 | t1 = add t1 add get hk t get hw t |
| 644 | a = get hv 0 |
| 645 | s0 = xor xor rotr a 2 rotr a 13 rotr a 22 |
| 646 | b1 = get hv 1 |
| 647 | c1 = get hv 2 |
| 648 | mj = xor xor and a b1 and a c1 and b1 c1 |
| 649 | put hv 7 get hv 6 |
| 650 | put hv 6 get hv 5 |
| 651 | put hv 5 e |
| 652 | put hv 4 add get hv 3 t1 |
| 653 | put hv 3 get hv 2 |
| 654 | put hv 2 get hv 1 |
| 655 | put hv 1 a |
| 656 | put hv 0 add t1 add s0 mj |
| 657 | end |
| 658 | for i ulong 8 |
| 659 | put hh i add get hh i get hv i |
| 660 | end |
| 661 | end |
| 662 | |
| 663 | fn shafile to bool |
| 664 | shainit |
| 665 | fd = fopen om 0 get omn 0 0 0 |
| 666 | if lt fd 0 |
| 667 | ret false |
| 668 | end |
| 669 | tot = ulong 0 |
| 670 | k = ulong 0 |
| 671 | while true bound 10000000 |
| 672 | r = read int fd ca 0 65536 |
| 673 | if lt r 0 |
| 674 | c = fclose int fd |
| 675 | ret false |
| 676 | end |
| 677 | if eq r 0 |
| 678 | break |
| 679 | end |
| 680 | for i ulong ulong r |
| 681 | put hbk k get ca i |
| 682 | k = add k 1 |
| 683 | if eq k 64 |
| 684 | shablk |
| 685 | k = 0 |
| 686 | end |
| 687 | end |
| 688 | tot = add tot ulong r |
| 689 | end |
| 690 | c = fclose int fd |
| 691 | shapad k tot |
| 692 | ret true |
| 693 | end |
| 694 | |
| 695 | note shapad: the final padding (FIPS 180-4 5.1.1) after k bytes of the last block, tot bytes in all. |
| 696 | fn shapad k0 ulong tot ulong to void |
| 697 | k = k0 |
| 698 | put hbk k 128 |
| 699 | k = add k 1 |
| 700 | if gt k 56 |
| 701 | while lt k 64 bound 64 |
| 702 | put hbk k 0 |
| 703 | k = add k 1 |
| 704 | end |
| 705 | shablk |
| 706 | k = 0 |
| 707 | end |
| 708 | while lt k 56 bound 64 |
| 709 | put hbk k 0 |
| 710 | k = add k 1 |
| 711 | end |
| 712 | bl = mul tot 8 |
| 713 | for i ulong 8 |
| 714 | put hbk add 56 i uchar and shr bl mul sub 7 i 8 255 |
| 715 | end |
| 716 | shablk |
| 717 | end |
| 718 | |
| 719 | note pinok: the SHA-256 of the file om[0 .. omn) in lowercase hex equals PIN. |
| 720 | fn pinok to bool |
| 721 | if not shafile |
| 722 | ret false |
| 723 | end |
| 724 | for i ulong 8 |
| 725 | v = get hh i |
| 726 | for j ulong 8 |
| 727 | d = and shr v uint mul sub 7 j 4 15 |
| 728 | c = uchar add d 48 |
| 729 | if gt d 9 |
| 730 | c = uchar add d 87 |
| 731 | end |
| 732 | if ne c get PIN add mul i 8 j |
| 733 | ret false |
| 734 | end |
| 735 | end |
| 736 | end |
| 737 | ret true |
| 738 | end |
| 739 | |
| 740 | note ---- build: UNITS concatenated (lines replaced in a mutant) and compiled ---- |
| 741 | note lineeq: ub[s .. e) equals the old line of replacement r. |
| 742 | fn lineeq r ulong s ulong e ulong to bool |
| 743 | a = get mro mul r 4 |
| 744 | if ne sub e s sub get mro add mul r 4 1 a |
| 745 | ret false |
| 746 | end |
| 747 | for i ulong sub e s bound 4096 |
| 748 | if ne get ub add s i get mu add a i |
| 749 | ret false |
| 750 | end |
| 751 | end |
| 752 | ret true |
| 753 | end |
| 754 | |
| 755 | note emitub: ub[s .. e) and a newline appended to sr at o; emitmu: the new line of replacement r. |
| 756 | fn emitub o ulong s ulong e ulong to ulong |
| 757 | for i ulong sub e s bound 65536 |
| 758 | put sr add o i get ub add s i |
| 759 | end |
| 760 | put sr add o sub e s 10 |
| 761 | ret add add o sub e s 1 |
| 762 | end |
| 763 | |
| 764 | fn emitmu o ulong r ulong to ulong |
| 765 | c = get mro add mul r 4 2 |
| 766 | k = sub get mro add mul r 4 3 c |
| 767 | for i ulong k bound 4096 |
| 768 | put sr add o i get mu add c i |
| 769 | end |
| 770 | put sr add o k 10 |
| 771 | ret add add o k 1 |
| 772 | end |
| 773 | |
| 774 | note repl: the replacement of unit u whose old line is ub[s .. e), or 99. |
| 775 | fn repl u ulong s ulong e ulong to ulong |
| 776 | for r ulong get mrc 0 bound 4 |
| 777 | if eq get mru r u |
| 778 | if lineeq r s e |
| 779 | ret r |
| 780 | end |
| 781 | end |
| 782 | end |
| 783 | ret 99 |
| 784 | end |
| 785 | |
| 786 | note addunit: unit file pa (index u) appended to sr, replacing the lines a replacement names. |
| 787 | fn addunit u ulong to void |
| 788 | n = rdinto 2 |
| 789 | o = get srn 0 |
| 790 | s = ulong 0 |
| 791 | while lt s n bound 262144 |
| 792 | e = s |
| 793 | while lt e n bound 262144 |
| 794 | if eq get ub e 10 |
| 795 | break |
| 796 | end |
| 797 | e = add e 1 |
| 798 | end |
| 799 | r = repl u s e |
| 800 | if eq r 99 |
| 801 | o = emitub o s e |
| 802 | else |
| 803 | put mrh r add get mrh r 1 |
| 804 | o = emitmu o r |
| 805 | end |
| 806 | s = add e 1 |
| 807 | end |
| 808 | put srn 0 o |
| 809 | end |
| 810 | |
| 811 | fn unitpa s ulong e ulong to void |
| 812 | for j ulong sub e s bound 4096 |
| 813 | put pa j get UNITS add s j |
| 814 | end |
| 815 | put pan 0 sub e s |
| 816 | end |
| 817 | |
| 818 | note units: every unit of UNITS into sr; true when each replacement replaced exactly one line. |
| 819 | fn units to bool |
| 820 | put srn 0 0 |
| 821 | for r ulong 4 |
| 822 | put mrh r 0 |
| 823 | end |
| 824 | k = ulong 0 |
| 825 | s = ulong 0 |
| 826 | n = len UNITS |
| 827 | for i ulong add n 1 bound 4096 |
| 828 | c = uchar 32 |
| 829 | if lt i n |
| 830 | c = get UNITS i |
| 831 | end |
| 832 | if eq c 32 |
| 833 | if gt i s |
| 834 | unitpa s i |
| 835 | addunit k |
| 836 | k = add k 1 |
| 837 | end |
| 838 | s = add i 1 |
| 839 | end |
| 840 | end |
| 841 | for r ulong get mrc 0 bound 4 |
| 842 | if ne get mrh r 1 |
| 843 | ret false |
| 844 | end |
| 845 | end |
| 846 | ret true |
| 847 | end |
| 848 | |
| 849 | note build: UNITS (with the current replacements, none when mrc = 0) into build/gate/NAME.om, compiled to |
| 850 | note build/gate/NAME (the text bn). |
| 851 | fn build bn view uchar * to bool |
| 852 | if not units |
| 853 | ret false |
| 854 | end |
| 855 | pat bn |
| 856 | paadd tdotom |
| 857 | fd = openout |
| 858 | r = write fd sr 0 get srn 0 |
| 859 | c = fclose fd |
| 860 | if ne r long get srn 0 |
| 861 | die tio |
| 862 | end |
| 863 | for i ulong get pan 0 bound 4096 |
| 864 | put pb i get pa i |
| 865 | end |
| 866 | put pbn 0 get pan 0 |
| 867 | pkreset |
| 868 | pkom |
| 869 | pat bn |
| 870 | st = spawn terr CLIM |
| 871 | if ne st 0 |
| 872 | ret false |
| 873 | end |
| 874 | r = chmod pa 0 get pan 0 493 |
| 875 | ret true |
| 876 | end |
| 877 | |
| 878 | note ---- cases ---- |
| 879 | fn fields s ulong e ulong to void |
| 880 | k = ulong 0 |
| 881 | i = s |
| 882 | while lt i e bound 65536 |
| 883 | while lt i e bound 65536 |
| 884 | if ne get cs i 32 |
| 885 | break |
| 886 | end |
| 887 | i = add i 1 |
| 888 | end |
| 889 | if ge i e |
| 890 | break |
| 891 | end |
| 892 | if ge k 32 |
| 893 | break |
| 894 | end |
| 895 | put fs k i |
| 896 | while lt i e bound 65536 |
| 897 | if eq get cs i 32 |
| 898 | break |
| 899 | end |
| 900 | i = add i 1 |
| 901 | end |
| 902 | put fe k i |
| 903 | k = add k 1 |
| 904 | end |
| 905 | put nf 0 k |
| 906 | end |
| 907 | |
| 908 | fn fis k ulong t view uchar * to bool |
| 909 | s = get fs k |
| 910 | n = sub get fe k s |
| 911 | if ne n len t |
| 912 | ret false |
| 913 | end |
| 914 | for i ulong n bound 4096 |
| 915 | if ne get cs add s i get t i |
| 916 | ret false |
| 917 | end |
| 918 | end |
| 919 | ret true |
| 920 | end |
| 921 | |
| 922 | fn fnum k ulong to ulong |
| 923 | v = ulong 0 |
| 924 | s = get fs k |
| 925 | n = sub get fe k s |
| 926 | for i ulong n bound 20 |
| 927 | c = ulong get cs add s i |
| 928 | v = add mul v 10 sub c 48 |
| 929 | end |
| 930 | ret v |
| 931 | end |
| 932 | |
| 933 | note fmode: field k begins "t:" (1, LibreOffice text oracle), "c:" (2, LibreOffice CSV oracle), else 0. |
| 934 | fn fmode k ulong to ulong |
| 935 | s = get fs k |
| 936 | if lt sub get fe k s 3 |
| 937 | ret 0 |
| 938 | end |
| 939 | if ne get cs add s 1 58 |
| 940 | ret 0 |
| 941 | end |
| 942 | c = get cs s |
| 943 | if eq c 116 |
| 944 | ret 1 |
| 945 | end |
| 946 | if eq c 99 |
| 947 | ret 2 |
| 948 | end |
| 949 | ret 0 |
| 950 | end |
| 951 | |
| 952 | fn fail1 f ulong to void |
| 953 | put failn 0 add get failn 0 1 |
| 954 | say tfail |
| 955 | r = write 1 cs get fs f sub get fe f get fs f |
| 956 | say tsp |
| 957 | end |
| 958 | |
| 959 | text texit "exit " |
| 960 | text twant " want " |
| 961 | text tbytes "stdout differs from " |
| 962 | text tstderr "stderr is not one officeread: or ozip: line" |
| 963 | |
| 964 | note runcase: one run line ID EXIT STDIN EXPECT ARGS... ("-" for no stdin, or for no stdout check; EXPECT |
| 965 | note "t:FILE" or "c:FILE" compares after the stated normalisation). True when exit, stdout, stderr are right. |
| 966 | fn runcase bin view uchar * quiet bool to bool |
| 967 | want = fnum 1 |
| 968 | pkreset |
| 969 | pkt bin |
| 970 | for k ulong sub get nf 0 4 bound 28 |
| 971 | f = add k 4 |
| 972 | pkcs get fs f get fe f |
| 973 | end |
| 974 | put pbn 0 0 |
| 975 | if not fis 2 tdash |
| 976 | pbcs get fs 2 get fe 2 |
| 977 | end |
| 978 | pat tout |
| 979 | st = spawn terr TLIM |
| 980 | if ne st want |
| 981 | if not quiet |
| 982 | fail1 0 |
| 983 | say texit |
| 984 | saynum st |
| 985 | say twant |
| 986 | saynum want |
| 987 | say tnl |
| 988 | end |
| 989 | ret false |
| 990 | end |
| 991 | if not errok st |
| 992 | if not quiet |
| 993 | fail1 0 |
| 994 | say tstderr |
| 995 | say tnl |
| 996 | end |
| 997 | ret false |
| 998 | end |
| 999 | if fis 3 tdash |
| 1000 | ret true |
| 1001 | end |
| 1002 | m = fmode 3 |
| 1003 | ok = false |
| 1004 | if eq m 0 |
| 1005 | pbcs get fs 3 get fe 3 |
| 1006 | pat tout |
| 1007 | ok = same |
| 1008 | else |
| 1009 | pbcs add get fs 3 2 get fe 3 |
| 1010 | ok = ncmp eq m 1 |
| 1011 | end |
| 1012 | if not ok |
| 1013 | if not quiet |
| 1014 | fail1 0 |
| 1015 | say tbytes |
| 1016 | r = write 1 pb 0 get pbn 0 |
| 1017 | say tnl |
| 1018 | end |
| 1019 | ret false |
| 1020 | end |
| 1021 | ret true |
| 1022 | end |
| 1023 | |
| 1024 | note ckind: the counter of a passing case: by oracle when it exits 0, else by refusal code range. |
| 1025 | fn ckind to ulong |
| 1026 | w = fnum 1 |
| 1027 | if eq w 0 |
| 1028 | m = fmode 3 |
| 1029 | if ne m 0 |
| 1030 | ret m |
| 1031 | end |
| 1032 | if fis 4 txmlev |
| 1033 | ret 0 |
| 1034 | end |
| 1035 | ret 3 |
| 1036 | end |
| 1037 | if and ge w 60 le w 75 |
| 1038 | ret 8 |
| 1039 | end |
| 1040 | if and ge w 80 le w 89 |
| 1041 | ret 9 |
| 1042 | end |
| 1043 | if eq w 1 |
| 1044 | ret 11 |
| 1045 | end |
| 1046 | ret 10 |
| 1047 | end |
| 1048 | |
| 1049 | note doline: the case line already split into fields; true when it passes (comments and rob lines pass |
| 1050 | note here; rob lines run in robust). |
| 1051 | fn doline bin view uchar * quiet bool count bool to bool |
| 1052 | if eq get nf 0 0 |
| 1053 | ret true |
| 1054 | end |
| 1055 | if eq get cs get fs 0 35 |
| 1056 | ret true |
| 1057 | end |
| 1058 | if fis 0 trobw |
| 1059 | ret true |
| 1060 | end |
| 1061 | if lt get nf 0 5 |
| 1062 | fail1 0 |
| 1063 | say tshort |
| 1064 | say tnl |
| 1065 | ret false |
| 1066 | end |
| 1067 | ok = runcase bin quiet |
| 1068 | if and ok count |
| 1069 | k = ckind |
| 1070 | put cnt k add get cnt k 1 |
| 1071 | end |
| 1072 | ret ok |
| 1073 | end |
| 1074 | |
| 1075 | note runall: every case line against bin; the number of failures (stop: return at the first one, and |
| 1076 | note the failing line stays in fs/fe for the report). With count the passing runs are counted. |
| 1077 | fn runall bin view uchar * quiet bool stop bool count bool to ulong |
| 1078 | bad = ulong 0 |
| 1079 | s = ulong 0 |
| 1080 | n = get csn 0 |
| 1081 | while lt s n bound 262144 |
| 1082 | e = s |
| 1083 | while lt e n bound 262144 |
| 1084 | if eq get cs e 10 |
| 1085 | break |
| 1086 | end |
| 1087 | e = add e 1 |
| 1088 | end |
| 1089 | fields s e |
| 1090 | s = add e 1 |
| 1091 | if not doline bin quiet count |
| 1092 | bad = add bad 1 |
| 1093 | if stop |
| 1094 | ret bad |
| 1095 | end |
| 1096 | end |
| 1097 | end |
| 1098 | ret bad |
| 1099 | end |
| 1100 | |
| 1101 | note ---- mutants: tests/mutants.txt lines ID|UNIT|OLD|NEW, UNIT the 0-based index in UNITS; consecutive |
| 1102 | note lines with the same ID are one mutant (each of its lines must be found exactly once) ---- |
| 1103 | text tkilled "MUTANT killed " |
| 1104 | text tsurv "MUTANT SURVIVED " |
| 1105 | text tnobuild "MUTANT FAIL (a line not found exactly once, or no compile) " |
| 1106 | text tby " by case " |
| 1107 | text tnomut "OFFICEREADGATE mutants not run: the unmutated build failed cases\n" |
| 1108 | |
| 1109 | fn bar s ulong e ulong to ulong |
| 1110 | p = s |
| 1111 | while lt p e bound 65536 |
| 1112 | if eq get mu p 124 |
| 1113 | ret p |
| 1114 | end |
| 1115 | p = add p 1 |
| 1116 | end |
| 1117 | ret e |
| 1118 | end |
| 1119 | |
| 1120 | fn munum s ulong e ulong to ulong |
| 1121 | u = ulong 0 |
| 1122 | for i ulong sub e s bound 4 |
| 1123 | c = ulong get mu add s i |
| 1124 | u = add mul u 10 sub c 48 |
| 1125 | end |
| 1126 | ret u |
| 1127 | end |
| 1128 | |
| 1129 | note mreport: k 0 killed (with the case that failed), 1 survived, 2 not built; the id is mu[s .. e). |
| 1130 | fn mreport k ulong s ulong e ulong to void |
| 1131 | if eq k 0 |
| 1132 | put cnt 21 add get cnt 21 1 |
| 1133 | say tkilled |
| 1134 | r = write 1 mu s sub e s |
| 1135 | say tby |
| 1136 | r = write 1 cs get fs 0 sub get fe 0 get fs 0 |
| 1137 | say tsp |
| 1138 | r = write 1 cs get fs 1 sub get fe 1 get fs 1 |
| 1139 | say tnl |
| 1140 | ret |
| 1141 | end |
| 1142 | put failn 0 add get failn 0 1 |
| 1143 | if eq k 1 |
| 1144 | say tsurv |
| 1145 | else |
| 1146 | say tnobuild |
| 1147 | end |
| 1148 | r = write 1 mu s sub e s |
| 1149 | say tnl |
| 1150 | end |
| 1151 | |
| 1152 | note mrun: build and test the mutant whose replacements are set; its id is mu[s .. e). |
| 1153 | fn mrun s ulong e ulong to void |
| 1154 | put cnt 20 add get cnt 20 1 |
| 1155 | k = ulong 2 |
| 1156 | if build tmut |
| 1157 | k = 1 |
| 1158 | if gt runall tmut true true false 0 |
| 1159 | k = 0 |
| 1160 | end |
| 1161 | end |
| 1162 | mreport k s e |
| 1163 | put mrc 0 0 |
| 1164 | end |
| 1165 | |
| 1166 | note mideq: the ids mu[a .. b) and mu[c .. d) are equal. |
| 1167 | fn mideq a ulong b ulong c ulong d ulong to bool |
| 1168 | if ne sub b a sub d c |
| 1169 | ret false |
| 1170 | end |
| 1171 | for i ulong sub b a bound 4096 |
| 1172 | if ne get mu add a i get mu add c i |
| 1173 | ret false |
| 1174 | end |
| 1175 | end |
| 1176 | ret true |
| 1177 | end |
| 1178 | |
| 1179 | fn mutants to void |
| 1180 | pat tmutf |
| 1181 | n = rdinto 1 |
| 1182 | put mun 0 n |
| 1183 | put mrc 0 0 |
| 1184 | is = ulong 0 |
| 1185 | ie = ulong 0 |
| 1186 | s = ulong 0 |
| 1187 | while lt s n bound 65536 |
| 1188 | e = s |
| 1189 | while lt e n bound 65536 |
| 1190 | if eq get mu e 10 |
| 1191 | break |
| 1192 | end |
| 1193 | e = add e 1 |
| 1194 | end |
| 1195 | p1 = bar s e |
| 1196 | p2 = bar add p1 1 e |
| 1197 | p3 = bar add p2 1 e |
| 1198 | if lt p3 e |
| 1199 | if gt get mrc 0 0 |
| 1200 | if not mideq is ie s p1 |
| 1201 | mrun is ie |
| 1202 | end |
| 1203 | end |
| 1204 | r = get mrc 0 |
| 1205 | if lt r 4 |
| 1206 | put mru r munum add p1 1 p2 |
| 1207 | put mro mul r 4 add p2 1 |
| 1208 | put mro add mul r 4 1 p3 |
| 1209 | put mro add mul r 4 2 add p3 1 |
| 1210 | put mro add mul r 4 3 e |
| 1211 | put mrc 0 add r 1 |
| 1212 | end |
| 1213 | is = s |
| 1214 | ie = p1 |
| 1215 | end |
| 1216 | s = add e 1 |
| 1217 | end |
| 1218 | if gt get mrc 0 0 |
| 1219 | mrun is ie |
| 1220 | end |
| 1221 | end |
| 1222 | |
| 1223 | note ---- robustness: rob ID KIND FILE CMD [ARG], KIND zip or xml; runs officeread CMD build/gate/rob.in [ARG] ---- |
| 1224 | text tcut " cut at " |
| 1225 | text tflip " flip at " |
| 1226 | text tcode " exit " |
| 1227 | text tbase " the unchanged input exits " |
| 1228 | |
| 1229 | fn allowed c ulong to bool |
| 1230 | if eq c 0 |
| 1231 | ret true |
| 1232 | end |
| 1233 | if and ge c 10 le c 22 |
| 1234 | ret true |
| 1235 | end |
| 1236 | if and ge c 30 le c 32 |
| 1237 | ret true |
| 1238 | end |
| 1239 | if and ge c 40 le c 53 |
| 1240 | ret true |
| 1241 | end |
| 1242 | if and ge c 60 le c 75 |
| 1243 | ret true |
| 1244 | end |
| 1245 | ret and ge c 80 le c 89 |
| 1246 | end |
| 1247 | |
| 1248 | note robexec: run the case's command on build/gate/rob.in with stdout to pa; the status. |
| 1249 | fn robexec to ulong |
| 1250 | pkreset |
| 1251 | pkt tooff |
| 1252 | pkcs get fs 4 get fe 4 |
| 1253 | pkt trob |
| 1254 | if gt get nf 0 5 |
| 1255 | pkcs get fs 5 get fe 5 |
| 1256 | end |
| 1257 | put pbn 0 0 |
| 1258 | ret spawn terr TLIM |
| 1259 | end |
| 1260 | |
| 1261 | note robrun: one changed input; base is the unchanged input's status (its stdout is build/gate/rob.ref). |
| 1262 | fn robrun base ulong what view uchar * pos ulong to void |
| 1263 | pat tout |
| 1264 | st = robexec |
| 1265 | put cnt 30 add get cnt 30 1 |
| 1266 | plain = not fis 2 tzip |
| 1267 | bad = false |
| 1268 | if not allowed st |
| 1269 | bad = true |
| 1270 | else |
| 1271 | if eq st 0 |
| 1272 | same0 = false |
| 1273 | if eq base 0 |
| 1274 | pbt tref |
| 1275 | pat tout |
| 1276 | same0 = same |
| 1277 | end |
| 1278 | if same0 |
| 1279 | put cnt 32 add get cnt 32 1 |
| 1280 | else |
| 1281 | if not plain |
| 1282 | bad = true |
| 1283 | else |
| 1284 | if eq base 0 |
| 1285 | put cnt 33 add get cnt 33 1 |
| 1286 | else |
| 1287 | put cnt 36 add get cnt 36 1 |
| 1288 | end |
| 1289 | end |
| 1290 | end |
| 1291 | else |
| 1292 | put cnt 31 add get cnt 31 1 |
| 1293 | put cnt add 64 st add get cnt add 64 st 1 |
| 1294 | end |
| 1295 | end |
| 1296 | if bad |
| 1297 | put cnt 34 add get cnt 34 1 |
| 1298 | fail1 1 |
| 1299 | say what |
| 1300 | saynum pos |
| 1301 | say tcode |
| 1302 | saynum st |
| 1303 | say tnl |
| 1304 | end |
| 1305 | end |
| 1306 | |
| 1307 | fn robline to void |
| 1308 | put pan 0 0 |
| 1309 | pacs get fs 3 get fe 3 |
| 1310 | n = rdinto 3 |
| 1311 | wrrob n |
| 1312 | pat tref |
| 1313 | base = robexec |
| 1314 | if not allowed base |
| 1315 | fail1 1 |
| 1316 | say tbase |
| 1317 | saynum base |
| 1318 | say tnl |
| 1319 | ret |
| 1320 | end |
| 1321 | for k ulong 64 |
| 1322 | c = div mul n k 64 |
| 1323 | wrrob c |
| 1324 | robrun base tcut c |
| 1325 | end |
| 1326 | for k ulong 256 |
| 1327 | p = div mul n k 256 |
| 1328 | if lt p n |
| 1329 | v = get rb p |
| 1330 | m = uchar 255 |
| 1331 | if eq rem k 2 0 |
| 1332 | m = uchar shl ulong 1 rem div k 2 8 |
| 1333 | end |
| 1334 | put rb p xor v m |
| 1335 | wrrob n |
| 1336 | robrun base tflip p |
| 1337 | put rb p v |
| 1338 | end |
| 1339 | end |
| 1340 | end |
| 1341 | |
| 1342 | fn robust to void |
| 1343 | s = ulong 0 |
| 1344 | n = get csn 0 |
| 1345 | while lt s n bound 262144 |
| 1346 | e = s |
| 1347 | while lt e n bound 262144 |
| 1348 | if eq get cs e 10 |
| 1349 | break |
| 1350 | end |
| 1351 | e = add e 1 |
| 1352 | end |
| 1353 | fields s e |
| 1354 | s = add e 1 |
| 1355 | if ge get nf 0 5 |
| 1356 | if fis 0 trobw |
| 1357 | put cnt 35 add get cnt 35 1 |
| 1358 | robline |
| 1359 | end |
| 1360 | end |
| 1361 | end |
| 1362 | end |
| 1363 | |
| 1364 | note ---- report ---- |
| 1365 | text r1 "OFFICEREADGATE cases passed: expat=" |
| 1366 | text r2 " libreoffice-text=" |
| 1367 | text r3 " libreoffice-csv=" |
| 1368 | text r4 " exact=" |
| 1369 | text r5 "; refusals passed: xml=" |
| 1370 | text r6 " package=" |
| 1371 | text r7 " zip=" |
| 1372 | text r7b " usage=" |
| 1373 | text r8 "OFFICEREADGATE mutants=" |
| 1374 | text r9 " killed=" |
| 1375 | text r10 "OFFICEREADGATE robustness files=" |
| 1376 | text r11 " runs=" |
| 1377 | text r12 " refused=" |
| 1378 | text r13 " exact=" |
| 1379 | text r14 " changed-plain=" |
| 1380 | text r14b " accepted-after-change=" |
| 1381 | text r15 " failures=" |
| 1382 | text r16 "OFFICEREADGATE robustness exit codes:" |
| 1383 | text r17 "OFFICEREADGATE PASS cases=" |
| 1384 | text r18 " mutants-killed=" |
| 1385 | text r19 " robust-runs=" |
| 1386 | text r20 "OFFICEREADGATE FAIL failures=" |
| 1387 | text tslsh "/" |
| 1388 | text tcolon ":" |
| 1389 | |
| 1390 | fn report to int |
| 1391 | say r1 |
| 1392 | saynum get cnt 0 |
| 1393 | say r2 |
| 1394 | saynum get cnt 1 |
| 1395 | say r3 |
| 1396 | saynum get cnt 2 |
| 1397 | say r4 |
| 1398 | saynum get cnt 3 |
| 1399 | say r5 |
| 1400 | saynum get cnt 8 |
| 1401 | say r6 |
| 1402 | saynum get cnt 9 |
| 1403 | say r7 |
| 1404 | saynum get cnt 10 |
| 1405 | say r7b |
| 1406 | saynum get cnt 11 |
| 1407 | say tnl |
| 1408 | say r8 |
| 1409 | saynum get cnt 20 |
| 1410 | say r9 |
| 1411 | saynum get cnt 21 |
| 1412 | say tnl |
| 1413 | say r10 |
| 1414 | saynum get cnt 35 |
| 1415 | say r11 |
| 1416 | saynum get cnt 30 |
| 1417 | say r12 |
| 1418 | saynum get cnt 31 |
| 1419 | say r13 |
| 1420 | saynum get cnt 32 |
| 1421 | say r14 |
| 1422 | saynum get cnt 33 |
| 1423 | say r14b |
| 1424 | saynum get cnt 36 |
| 1425 | say r15 |
| 1426 | saynum get cnt 34 |
| 1427 | say tnl |
| 1428 | say r16 |
| 1429 | for c ulong 128 |
| 1430 | if gt get cnt add 64 c 0 |
| 1431 | say tsp |
| 1432 | saynum c |
| 1433 | say tcolon |
| 1434 | saynum get cnt add 64 c |
| 1435 | end |
| 1436 | end |
| 1437 | say tnl |
| 1438 | t = add add add get cnt 0 get cnt 1 get cnt 2 get cnt 3 |
| 1439 | t = add t add add add get cnt 8 get cnt 9 get cnt 10 get cnt 11 |
| 1440 | if eq get failn 0 0 |
| 1441 | say r17 |
| 1442 | saynum t |
| 1443 | say r18 |
| 1444 | saynum get cnt 21 |
| 1445 | say tslsh |
| 1446 | saynum get cnt 20 |
| 1447 | say r19 |
| 1448 | saynum get cnt 30 |
| 1449 | say tnl |
| 1450 | ret 0 |
| 1451 | end |
| 1452 | say r20 |
| 1453 | saynum get failn 0 |
| 1454 | say tnl |
| 1455 | ret 1 |
| 1456 | end |
| 1457 | |
| 1458 | text tdocsrc "tests/docs.om" |
| 1459 | text tdocbin "build/gate/docs" |
| 1460 | text tdocout "build/gate/docs.out" |
| 1461 | text tdocfail "OFFICEREADGATE FAIL tests/docs.om (publication checks) exit " |
| 1462 | |
| 1463 | note docs: step 6 of the head note; a failure counts in failn. |
| 1464 | fn docs to void |
| 1465 | pbt tdocsrc |
| 1466 | pkreset |
| 1467 | pkom |
| 1468 | pat tdocbin |
| 1469 | st = spawn terr CLIM |
| 1470 | if ne st 0 |
| 1471 | pat tdocbin |
| 1472 | die tcompile |
| 1473 | end |
| 1474 | pat tdocbin |
| 1475 | r = chmod pa 0 get pan 0 493 |
| 1476 | pkreset |
| 1477 | pkpa |
| 1478 | put pbn 0 0 |
| 1479 | pat tdocout |
| 1480 | st2 = spawn terr TLIM |
| 1481 | pat tdocout |
| 1482 | n = rdinto 3 |
| 1483 | w = write 1 rb 0 n |
| 1484 | if ne st2 0 |
| 1485 | put failn 0 add get failn 0 1 |
| 1486 | say tdocfail |
| 1487 | saynum st2 |
| 1488 | say tnl |
| 1489 | end |
| 1490 | end |
| 1491 | |
| 1492 | fn main to int |
| 1493 | if lt argcnt 2 |
| 1494 | say tnoomc |
| 1495 | say tnl |
| 1496 | ret 3 |
| 1497 | end |
| 1498 | k = argread 1 om 0 4096 |
| 1499 | if le k 0 |
| 1500 | say tnoomc |
| 1501 | say tnl |
| 1502 | ret 3 |
| 1503 | end |
| 1504 | put omn 0 ulong k |
| 1505 | if not pinok |
| 1506 | say tnotrun |
| 1507 | say tbadpin |
| 1508 | say PIN |
| 1509 | say tnl |
| 1510 | ret 3 |
| 1511 | end |
| 1512 | pat tbuild |
| 1513 | mkd |
| 1514 | pat tgdir |
| 1515 | wipepa |
| 1516 | pat tgdir |
| 1517 | mkd |
| 1518 | docs |
| 1519 | pat tcases |
| 1520 | put csn 0 rdinto 0 |
| 1521 | put mrc 0 0 |
| 1522 | if not build tooff |
| 1523 | pat tooff |
| 1524 | die tcompile |
| 1525 | end |
| 1526 | bad = runall tooff false false true |
| 1527 | if eq bad 0 |
| 1528 | mutants |
| 1529 | else |
| 1530 | say tnomut |
| 1531 | end |
| 1532 | robust |
| 1533 | ret report |
| 1534 | end |