omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / protocol / synapse / board / tests / run.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note tests/run.om: build synapse-board with tools/build.om, then run its positive and negative cases in a |
| 3 | note fresh directory (replaces tests/run.sh). README.md (Test) holds the one command that compiles it, |
| 4 | note from the repository root, with the pinned omc. |
| 5 | note usage: run OMEGA_SRC TEST_ROOT [--update-golden] (from the repository root) |
| 6 | note It first compiles the build driver from OMEGA_SRC/om/tls/sha2.om and tools/build.om into TEST_ROOT/bin/build |
| 7 | note (unit TEST_ROOT/build.unit.om, omc's messages TEST_ROOT/build.err), so a stale build/build is never used. |
| 8 | note TEST_ROOT must not exist yet; its parent must. It is created and left for inspection. |
| 9 | note --update-golden rewrites tests/golden from the fixture render (review the diff before committing). |
| 10 | note The live serve case runs only when this host has a local address inside 100.64.0.0/10 (read from |
| 11 | note /proc/net/fib_trie); otherwise it is NOT_RUN. It binds that address on port 18731 for one GET. |
| 12 | note Prints PASS, FAIL and NOT_RUN lines and a SUMMARY line. Exit 0 only if every case that ran passed; |
| 13 | note 1 when a case failed or the build failed; 64 usage or TEST_ROOT already exists. |
| 14 | |
| 15 | text tuse "usage: run OMEGA_SRC TEST_ROOT [--update-golden] (from the synapse-board repository root)\n" |
| 16 | text texists "run: TEST_ROOT exists or cannot be created; give a new path\n" |
| 17 | text tupd "--update-golden" |
| 18 | text tunit "/build.unit.om" |
| 19 | text tbldb "/bin/build" |
| 20 | text tblde "/build.err" |
| 21 | text tsha2 "/om/tls/sha2.om" |
| 22 | text tbldom "tools/build.om" |
| 23 | text tomc "/seed/out/omc" |
| 24 | text tom2 "om2\n" |
| 25 | text tbin "/bin" |
| 26 | text tbinb "/bin/synapse-board" |
| 27 | text tfx "tests/fixtures/" |
| 28 | text tgd "tests/golden/" |
| 29 | text tout "/out.txt" |
| 30 | text terr "/err.txt" |
| 31 | text tsout "/serve.out" |
| 32 | text tserr "/serve.err" |
| 33 | text tr1 "/r1" |
| 34 | text tr2 "/r2" |
| 35 | text tr3 "/r3" |
| 36 | text tn1 "/n1" |
| 37 | text tn2 "/n2" |
| 38 | text tnope "/nope.jsonl" |
| 39 | text tbmd "/BOARD.md" |
| 40 | text tidx "/index.html" |
| 41 | text tfbmd "BOARD.md" |
| 42 | text tfidx "index.html" |
| 43 | text fcl "claims.jsonl" |
| 44 | text fmap "map.jsonl" |
| 45 | text ffind "findings.jsonl" |
| 46 | text fbcl "bad-claims.jsonl" |
| 47 | text fbmap "bad-map.jsonl" |
| 48 | text arender "render" |
| 49 | text aserve "serve" |
| 50 | text adelete "delete" |
| 51 | text aclaims "--claims" |
| 52 | text amap "--map" |
| 53 | text afind "--findings" |
| 54 | text aout "--out" |
| 55 | text anow "--now" |
| 56 | text ahead "--head" |
| 57 | text adir "--dir" |
| 58 | text abind "--bind" |
| 59 | text amax "--max" |
| 60 | text abogus "--bogus" |
| 61 | text a1 "1" |
| 62 | text vnow "2026-10-27T02:00:00Z" |
| 63 | text vhead "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" |
| 64 | text vbadnow "2026<x>" |
| 65 | text vbadhead "XYZ" |
| 66 | text b0 "0.0.0.0:18731" |
| 67 | text b127 "127.0.0.1:18731" |
| 68 | text b128 "100.128.0.1:18731" |
| 69 | text b63 "100.63.255.255:18731" |
| 70 | text bnoport "100.64.0.1" |
| 71 | text bok "100.64.0.1:18731" |
| 72 | text wjson1 "{\"ok\":true,\"files\":2,\"active\":6,\"conflicts\":1,\"findings\":3,\"repos\":9,\"head\":\"" |
| 73 | text wjson2 "\"}" |
| 74 | text tpass "PASS " |
| 75 | text tfail "FAIL " |
| 76 | text tnotrun "NOT_RUN live serve (no 100.64.0.0/10 address on this host)\n" |
| 77 | text trc " (rc=" |
| 78 | text twant ", want " |
| 79 | text tclose ")" |
| 80 | text tnl "\n" |
| 81 | text tstderr " stderr: " |
| 82 | text tsum "SUMMARY pass=" |
| 83 | text tsumf " fail=" |
| 84 | text tsumn " not_run=" |
| 85 | text tnote "NOTE golden rewritten: " |
| 86 | text tkeep ": render output unreadable, golden kept\n" |
| 87 | text tnowr ": cannot write the golden in full\n" |
| 88 | text tfd " first difference at byte " |
| 89 | text tlg " (golden " |
| 90 | text tlr " bytes, rendered " |
| 91 | text tnot " not in " |
| 92 | text tdots ".." |
| 93 | text ton " on " |
| 94 | text tcolon ":" |
| 95 | text tsp " (" |
| 96 | text tplus " (+" |
| 97 | text tgot " got " |
| 98 | note case names |
| 99 | text nbuild "build" |
| 100 | text nrender "render-fixture" |
| 101 | text nrjson "render stdout json" |
| 102 | text ngold "golden " |
| 103 | text ntmp "no leftover .tmp" |
| 104 | text nupd "update-golden " |
| 105 | text nhs "html has no <script" |
| 106 | text nms "md has no <script" |
| 107 | text nhe "html escapes script" |
| 108 | text nme "md escapes script" |
| 109 | text njs "javascript: never linked" |
| 110 | text nsafe "safe evidence linked" |
| 111 | text nquo "quoted URL not linked" |
| 112 | text nact "no active/external elements" |
| 113 | text npipe "md pipe escaped" |
| 114 | text nlap "lapsed marked" |
| 115 | text ninf "inferred parent marked" |
| 116 | text ncyc "cycle reported" |
| 117 | text nagain "render-again" |
| 118 | text nover "render-overwrite" |
| 119 | text ndet "deterministic" |
| 120 | text nclock "render-clock" |
| 121 | text nciso "clock iso" |
| 122 | text nhu "head unknown" |
| 123 | text nnone "no findings file = empty" |
| 124 | text nmc "missing-claims" |
| 125 | text nmm "missing-map" |
| 126 | text nmf "missing-findings-ok" |
| 127 | text nbc "bad-claims" |
| 128 | text nbc2 "bad-claims names line 2" |
| 129 | text nbm "bad-map" |
| 130 | text nnw "nothing written on refusal" |
| 131 | text nno "no-out" |
| 132 | text nbn "bad-now" |
| 133 | text nbh "bad-head" |
| 134 | text nuf "unknown-flag" |
| 135 | text ndf "dup-flag" |
| 136 | text nnc "no-command" |
| 137 | text nbcmd "bad-command" |
| 138 | text ns0 "serve-0.0.0.0" |
| 139 | text ns127 "serve-127.0.0.1" |
| 140 | text ns128 "serve-100.128.0.1" |
| 141 | text ns63 "serve-100.63.255.255" |
| 142 | text nsnp "serve-no-port" |
| 143 | text nsnd "serve-no-dir" |
| 144 | text nsrf "serve-render-flag" |
| 145 | text nsexit "serve exits after --max 1" |
| 146 | text nlive "live serve GET /" |
| 147 | note needles |
| 148 | text kscript "<script" |
| 149 | text kesc "<script>alert(1)</script>" |
| 150 | text kjs "href=\"javascript" |
| 151 | text ksafe "href=\"https://github.com/aien-dev/omega-mv/pull/880\"" |
| 152 | text kquo "href=\"https://aienos.com/community" |
| 153 | text kiframe "<iframe" |
| 154 | text kobject "<object" |
| 155 | text kembed "<embed" |
| 156 | text klink "<link" |
| 157 | text kimg "<img" |
| 158 | text ksrc "src=" |
| 159 | text krefresh "http-equiv=\"refresh\"" |
| 160 | text kpipe "Vulkan GLCompute \\| SPIR-V" |
| 161 | text klapsed "LAPSED" |
| 162 | text kinf "INFERRED: name-prefix synapse-" |
| 163 | text kcycle "[cycle]" |
| 164 | text khu "ledger head unknown" |
| 165 | text knone "none" |
| 166 | text kc2 "claims:2:" |
| 167 | text kserving "serving" |
| 168 | text ktmp ".tmp" |
| 169 | text kat " at " |
| 170 | text kdash "|-- " |
| 171 | text kloc "/32 host LOCAL" |
| 172 | text kfib "/proc/net/fib_trie" |
| 173 | text kget1 "GET / HTTP/1.0" |
| 174 | text khost "Host: " |
| 175 | text kget2 "Connection: close" |
| 176 | |
| 177 | global groot uchar 4096 |
| 178 | global gosrc uchar 4096 |
| 179 | global gn ulong 18 |
| 180 | note gn: 0 TEST_ROOT length, 1 OMEGA_SRC length, 2 gp length, 3 gpk length, 4 pass, 5 fail, 6 not_run, |
| 181 | note 7 redirect (0 none, 1 out.txt/err.txt, 2 serve.out/serve.err), 8 ga length, 9 gb length, 10 last rc, |
| 182 | note 11 tailnet address (host order), 12 time before, 13 time after, 14 parsed time, 15 HTTP status, |
| 183 | note 16 gp overflow (a byte past 8191 was dropped: openp refuses with -36, ENAMETOOLONG), |
| 184 | note 17 gpk holds an overflowed item (runk refuses with -1) |
| 185 | global gp uchar 8192 |
| 186 | global gpk uchar 65536 |
| 187 | global gst uchar 4 |
| 188 | global gob uchar 64 |
| 189 | global gts uchar 64 |
| 190 | global gtl ulong 1 |
| 191 | global ga uchar * |
| 192 | global gb uchar * |
| 193 | global gde uchar 65536 |
| 194 | |
| 195 | note ======== output |
| 196 | fn o t view uchar * to void |
| 197 | r = write 1 t 0 len t |
| 198 | end |
| 199 | fn onum v ulong to void |
| 200 | n = ulong 0 |
| 201 | x = v |
| 202 | if eq x 0 |
| 203 | put gob 63 48 |
| 204 | n = 1 |
| 205 | end |
| 206 | while gt x 0 bound 21 |
| 207 | put gob sub 63 n uchar add 48 rem x 10 |
| 208 | x = div x 10 |
| 209 | n = add n 1 |
| 210 | end |
| 211 | r = write 1 gob sub 64 n n |
| 212 | end |
| 213 | fn onl to void |
| 214 | o tnl |
| 215 | end |
| 216 | fn ok t view uchar * to void |
| 217 | put gn 4 add get gn 4 1 |
| 218 | o tpass |
| 219 | o t |
| 220 | end |
| 221 | fn bad t view uchar * to void |
| 222 | put gn 5 add get gn 5 1 |
| 223 | o tfail |
| 224 | o t |
| 225 | end |
| 226 | note judge: PASS name or FAIL name on a line |
| 227 | fn judge c bool t view uchar * to void |
| 228 | if c |
| 229 | ok t |
| 230 | else |
| 231 | bad t |
| 232 | end |
| 233 | onl |
| 234 | end |
| 235 | |
| 236 | note ======== path scratch gp |
| 237 | fn pclr to void |
| 238 | put gn 2 0 |
| 239 | put gn 16 0 |
| 240 | end |
| 241 | fn pc c uchar to void |
| 242 | n = get gn 2 |
| 243 | if lt n 8191 |
| 244 | put gp n c |
| 245 | put gn 2 add n 1 |
| 246 | else |
| 247 | put gn 16 1 |
| 248 | end |
| 249 | end |
| 250 | fn pt t view uchar * to void |
| 251 | for i ulong len t |
| 252 | pc get t i |
| 253 | end |
| 254 | end |
| 255 | fn proot to void |
| 256 | for i ulong get gn 0 |
| 257 | pc get groot i |
| 258 | end |
| 259 | end |
| 260 | fn pr t view uchar * to void |
| 261 | pclr |
| 262 | proot |
| 263 | pt t |
| 264 | end |
| 265 | fn pf t view uchar * to void |
| 266 | pclr |
| 267 | pt tfx |
| 268 | pt t |
| 269 | end |
| 270 | fn pr2 d view uchar * t view uchar * to void |
| 271 | pclr |
| 272 | proot |
| 273 | pt d |
| 274 | pt t |
| 275 | end |
| 276 | fn openp flags ulong mode ulong to long |
| 277 | if ne get gn 16 0 |
| 278 | ret -36 |
| 279 | end |
| 280 | ret fopen gp 0 get gn 2 int flags int mode |
| 281 | end |
| 282 | |
| 283 | note ======== packed argument list gpk (u16 count, then u16 length and bytes per item) |
| 284 | fn k0 to void |
| 285 | put gpk 0 0 |
| 286 | put gpk 1 0 |
| 287 | put gn 3 2 |
| 288 | put gn 17 0 |
| 289 | end |
| 290 | note kp: append gp as one item |
| 291 | fn kp to void |
| 292 | q = get gn 3 |
| 293 | n = get gn 2 |
| 294 | if or ne get gn 16 0 gt add add q 2 n 65536 |
| 295 | put gn 17 1 |
| 296 | ret |
| 297 | end |
| 298 | put gpk q uchar and n 255 |
| 299 | put gpk add q 1 uchar shr n 8 |
| 300 | for i ulong n |
| 301 | put gpk add add q 2 i get gp i |
| 302 | end |
| 303 | put gn 3 add add q 2 n |
| 304 | c = add add ulong get gpk 0 shl ulong get gpk 1 8 1 |
| 305 | put gpk 0 uchar and c 255 |
| 306 | put gpk 1 uchar shr c 8 |
| 307 | end |
| 308 | fn ka t view uchar * to void |
| 309 | pclr |
| 310 | pt t |
| 311 | kp |
| 312 | end |
| 313 | fn af t view uchar * to void |
| 314 | pf t |
| 315 | kp |
| 316 | end |
| 317 | fn ar t view uchar * to void |
| 318 | pr t |
| 319 | kp |
| 320 | end |
| 321 | fn ar2 d view uchar * t view uchar * to void |
| 322 | pr2 d t |
| 323 | kp |
| 324 | end |
| 325 | fn cmd to void |
| 326 | k0 |
| 327 | pr tbinb |
| 328 | kp |
| 329 | end |
| 330 | note rargs: render --claims F(claims) --map F(map) |
| 331 | fn rbase to void |
| 332 | cmd |
| 333 | ka arender |
| 334 | ka aclaims |
| 335 | af fcl |
| 336 | ka amap |
| 337 | af fmap |
| 338 | end |
| 339 | fn rfull d view uchar * to void |
| 340 | rbase |
| 341 | ka afind |
| 342 | af ffind |
| 343 | ka aout |
| 344 | ar d |
| 345 | ka anow |
| 346 | ka vnow |
| 347 | ka ahead |
| 348 | ka vhead |
| 349 | end |
| 350 | |
| 351 | note ======== running a child |
| 352 | fn redir t view uchar * fd int to void |
| 353 | redirm t fd 524865 420 |
| 354 | end |
| 355 | note redirm: open TEST_ROOT t with flags and mode as the child's fd |
| 356 | fn redirm t view uchar * fd int flags ulong mode ulong to void |
| 357 | pr t |
| 358 | f = openp flags mode |
| 359 | if lt f 0 |
| 360 | exit 126 |
| 361 | end |
| 362 | r = dupfd int f fd 0 |
| 363 | end |
| 364 | fn child to void |
| 365 | m = get gn 7 |
| 366 | if eq m 1 |
| 367 | redir tout 1 |
| 368 | redir terr 2 |
| 369 | end |
| 370 | if eq m 2 |
| 371 | redir tsout 1 |
| 372 | redir tserr 2 |
| 373 | end |
| 374 | if eq m 3 |
| 375 | redirm tunit 0 524288 0 |
| 376 | redirm tbldb 1 524865 493 |
| 377 | redir tblde 2 |
| 378 | end |
| 379 | r = execprog gpk 0 get gn 3 |
| 380 | exit 127 |
| 381 | end |
| 382 | note spawn: the child's pid, or negative |
| 383 | fn spawn to long |
| 384 | if ne get gn 17 0 |
| 385 | ret -36 |
| 386 | end |
| 387 | pid = fork |
| 388 | if eq pid 0 |
| 389 | child |
| 390 | end |
| 391 | ret pid |
| 392 | end |
| 393 | note reap: exit status of pid (128+signal when killed), or -1 |
| 394 | fn reap pid long options int to long |
| 395 | r = waitpid int pid gst 0 4 options |
| 396 | if ne r pid |
| 397 | ret -1 |
| 398 | end |
| 399 | if ne get gst 0 0 |
| 400 | ret add 128 long get gst 0 |
| 401 | end |
| 402 | ret long get gst 1 |
| 403 | end |
| 404 | fn runk to long |
| 405 | pid = spawn |
| 406 | if lt pid 0 |
| 407 | ret -1 |
| 408 | end |
| 409 | ret reap pid 0 |
| 410 | end |
| 411 | |
| 412 | note ======== whole files into the run-time pools ga (w 0) and gb (w 1) |
| 413 | fn growp w ulong n ulong to bool |
| 414 | if eq w 0 |
| 415 | if lt len ga n |
| 416 | r = enlarge ga n |
| 417 | ret eq r 0 |
| 418 | end |
| 419 | ret true |
| 420 | end |
| 421 | if lt len gb n |
| 422 | r = enlarge gb n |
| 423 | ret eq r 0 |
| 424 | end |
| 425 | ret true |
| 426 | end |
| 427 | fn rdp w ulong fd int p ulong to long |
| 428 | if eq w 0 |
| 429 | ret read fd ga p 65536 |
| 430 | end |
| 431 | ret read fd gb p 65536 |
| 432 | end |
| 433 | note load: the file named by gp into pool w; its length, or negative |
| 434 | fn load w ulong to long |
| 435 | put gn add 8 w 0 |
| 436 | fd = openp 524288 0 |
| 437 | if lt fd 0 |
| 438 | ret fd |
| 439 | end |
| 440 | p = ulong 0 |
| 441 | for it ulong 999999 |
| 442 | if not growp w add p 65536 |
| 443 | c = fclose int fd |
| 444 | ret -12 |
| 445 | end |
| 446 | r = rdp w int fd p |
| 447 | if lt r 0 |
| 448 | if ne r -4 |
| 449 | c = fclose int fd |
| 450 | ret r |
| 451 | end |
| 452 | else |
| 453 | if eq r 0 |
| 454 | c = fclose int fd |
| 455 | put gn add 8 w p |
| 456 | ret long p |
| 457 | end |
| 458 | p = add p ulong r |
| 459 | end |
| 460 | end |
| 461 | c = fclose int fd |
| 462 | ret -27 |
| 463 | end |
| 464 | fn lower c uchar to uchar |
| 465 | if and ge c 65 le c 90 |
| 466 | ret add c 32 |
| 467 | end |
| 468 | ret c |
| 469 | end |
| 470 | note has: does ga[0..gn 8) contain t (ASCII case-insensitive when ci) |
| 471 | fn has t view uchar * ci bool to bool |
| 472 | n = get gn 8 |
| 473 | m = len t |
| 474 | if lt n m |
| 475 | ret false |
| 476 | end |
| 477 | for i ulong add sub n m 1 |
| 478 | j = ulong 0 |
| 479 | while lt j m bound 65536 |
| 480 | x = get ga add i j |
| 481 | y = get t j |
| 482 | if ci |
| 483 | x = lower x |
| 484 | y = lower y |
| 485 | end |
| 486 | if ne x y |
| 487 | break |
| 488 | end |
| 489 | j = add j 1 |
| 490 | end |
| 491 | if eq j m |
| 492 | ret true |
| 493 | end |
| 494 | end |
| 495 | ret false |
| 496 | end |
| 497 | note sameab: ga and gb hold the same bytes |
| 498 | fn sameab to bool |
| 499 | n = get gn 8 |
| 500 | if ne n get gn 9 |
| 501 | ret false |
| 502 | end |
| 503 | for i ulong n |
| 504 | if ne get ga i get gb i |
| 505 | ret false |
| 506 | end |
| 507 | end |
| 508 | ret true |
| 509 | end |
| 510 | note pr3: gp = TEST_ROOT d / f |
| 511 | fn pr3 d view uchar * f view uchar * to void |
| 512 | pr d |
| 513 | pc 47 |
| 514 | pt f |
| 515 | end |
| 516 | note cmp2: TEST_ROOT/r1/f equals tests/golden/f (gold) or TEST_ROOT/r2/f |
| 517 | fn cmp2 f view uchar * gold bool to bool |
| 518 | note both sides are always loaded, so a missing side reads as 0 bytes in diffnote, never a stale length |
| 519 | pr3 tr1 f |
| 520 | ra = load 0 |
| 521 | if gold |
| 522 | pclr |
| 523 | pt tgd |
| 524 | pt f |
| 525 | else |
| 526 | pr3 tr2 f |
| 527 | end |
| 528 | rb = load 1 |
| 529 | if or lt ra 0 lt rb 0 |
| 530 | ret false |
| 531 | end |
| 532 | ret sameab |
| 533 | end |
| 534 | |
| 535 | note ======== cases |
| 536 | note expect: run gpk with stdout and stderr in TEST_ROOT/out.txt and err.txt and compare the exit status |
| 537 | fn expect t view uchar * want long to void |
| 538 | put gn 7 1 |
| 539 | rc = runk |
| 540 | put gn 10 ulong rc |
| 541 | if eq rc want |
| 542 | ok t |
| 543 | o trc |
| 544 | onum ulong rc |
| 545 | o tclose |
| 546 | onl |
| 547 | ret |
| 548 | end |
| 549 | bad t |
| 550 | o trc |
| 551 | if lt rc 0 |
| 552 | o tfail |
| 553 | else |
| 554 | onum ulong rc |
| 555 | end |
| 556 | o twant |
| 557 | onum ulong want |
| 558 | o tclose |
| 559 | onl |
| 560 | pr terr |
| 561 | r = load 1 |
| 562 | if le r 0 |
| 563 | ret |
| 564 | end |
| 565 | showerr |
| 566 | end |
| 567 | fn showerr to void |
| 568 | s = ulong 0 |
| 569 | n = get gn 9 |
| 570 | for i ulong n |
| 571 | if or eq get gb i 10 eq add i 1 n |
| 572 | o tstderr |
| 573 | e = add i 1 |
| 574 | w = write 1 gb s sub e s |
| 575 | if ne get gb i 10 |
| 576 | onl |
| 577 | end |
| 578 | s = e |
| 579 | end |
| 580 | end |
| 581 | end |
| 582 | note gp names a file holding exactly the bytes of the render summary (trailing newlines ignored) |
| 583 | fn jsonok to bool |
| 584 | r = load 0 |
| 585 | if lt r 0 |
| 586 | ret false |
| 587 | end |
| 588 | n = get gn 8 |
| 589 | note Omega's and is eager, so the index is checked inside the loop, never beside n > 0 |
| 590 | while gt n 0 bound 9223372036854775807 |
| 591 | if ne get ga sub n 1 10 |
| 592 | break |
| 593 | end |
| 594 | n = sub n 1 |
| 595 | end |
| 596 | a = len wjson1 |
| 597 | b = len vhead |
| 598 | if ne n add add a b len wjson2 |
| 599 | ret false |
| 600 | end |
| 601 | for i ulong a |
| 602 | if ne get ga i get wjson1 i |
| 603 | ret false |
| 604 | end |
| 605 | end |
| 606 | for i ulong b |
| 607 | if ne get ga add a i get vhead i |
| 608 | ret false |
| 609 | end |
| 610 | end |
| 611 | for i ulong len wjson2 |
| 612 | if ne get ga add add a b i get wjson2 i |
| 613 | ret false |
| 614 | end |
| 615 | end |
| 616 | ret true |
| 617 | end |
| 618 | note tmpleft: a directory entry of TEST_ROOT/r1 ends in .tmp (or the directory cannot be listed) |
| 619 | fn tmpleft to bool |
| 620 | pr tr1 |
| 621 | note getdents64 records land in gde (host directory words take a sized array, not a run-time pool) |
| 622 | fd = openp 540672 0 |
| 623 | if lt fd 0 |
| 624 | ret true |
| 625 | end |
| 626 | for it ulong 999999 |
| 627 | r = getdnts int fd gde 0 65536 |
| 628 | if le r 0 |
| 629 | c = fclose int fd |
| 630 | ret lt r 0 |
| 631 | end |
| 632 | p = ulong 0 |
| 633 | while lt p ulong r bound 65536 |
| 634 | if tmpent p |
| 635 | c = fclose int fd |
| 636 | ret true |
| 637 | end |
| 638 | p = add p add ulong get gde add p 16 shl ulong get gde add p 17 8 |
| 639 | end |
| 640 | end |
| 641 | c = fclose int fd |
| 642 | ret true |
| 643 | end |
| 644 | fn tmpent p ulong to bool |
| 645 | q = add p 19 |
| 646 | n = ulong 0 |
| 647 | while ne get gde add q n 0 bound 256 |
| 648 | n = add n 1 |
| 649 | end |
| 650 | k = len ktmp |
| 651 | if lt n k |
| 652 | ret false |
| 653 | end |
| 654 | for i ulong k |
| 655 | if ne get gde add q add sub n k i get ktmp i |
| 656 | ret false |
| 657 | end |
| 658 | end |
| 659 | ret true |
| 660 | end |
| 661 | note ogold: print the golden path of file w (0 BOARD.md, 1 index.html) |
| 662 | fn ogold w ulong to void |
| 663 | o tgd |
| 664 | if eq w 0 |
| 665 | o tfbmd |
| 666 | else |
| 667 | o tfidx |
| 668 | end |
| 669 | end |
| 670 | note updgold: rewrite each golden from the fixture render; a golden is kept when the render cannot be read, |
| 671 | note and a write that cannot complete is a FAIL |
| 672 | fn updgold to void |
| 673 | for w ulong 2 |
| 674 | pr tr1 |
| 675 | if eq w 0 |
| 676 | pt tbmd |
| 677 | else |
| 678 | pt tidx |
| 679 | end |
| 680 | r = load 0 |
| 681 | if lt r 0 |
| 682 | bad nupd |
| 683 | ogold w |
| 684 | o tkeep |
| 685 | continue |
| 686 | end |
| 687 | pclr |
| 688 | pt tgd |
| 689 | if eq w 0 |
| 690 | pt tfbmd |
| 691 | else |
| 692 | pt tfidx |
| 693 | end |
| 694 | fd = openp 524865 420 |
| 695 | if lt fd 0 |
| 696 | bad nupd |
| 697 | ogold w |
| 698 | o tnowr |
| 699 | continue |
| 700 | end |
| 701 | full = wga int fd get gn 8 |
| 702 | c = fclose int fd |
| 703 | if not full |
| 704 | bad nupd |
| 705 | ogold w |
| 706 | o tnowr |
| 707 | continue |
| 708 | end |
| 709 | o tnote |
| 710 | ogold w |
| 711 | onl |
| 712 | end |
| 713 | end |
| 714 | |
| 715 | fn render1 to void |
| 716 | rfull tr1 |
| 717 | expect nrender 0 |
| 718 | pr tout |
| 719 | judge jsonok nrjson |
| 720 | end |
| 721 | fn golden to void |
| 722 | c = cmp2 tfbmd true |
| 723 | if c |
| 724 | ok ngold |
| 725 | else |
| 726 | bad ngold |
| 727 | end |
| 728 | o tfbmd |
| 729 | if not c |
| 730 | diffnote |
| 731 | end |
| 732 | onl |
| 733 | c = cmp2 tfidx true |
| 734 | if c |
| 735 | ok ngold |
| 736 | else |
| 737 | bad ngold |
| 738 | end |
| 739 | o tfidx |
| 740 | if not c |
| 741 | diffnote |
| 742 | end |
| 743 | onl |
| 744 | judge not tmpleft ntmp |
| 745 | end |
| 746 | note escaping: the fixture intent carries <script>alert(1)</script> |
| 747 | fn escapes to void |
| 748 | pr3 tr1 tfidx |
| 749 | r = load 0 |
| 750 | k = gt r 0 |
| 751 | judge and k not has kscript true nhs |
| 752 | judge and k has kesc false nhe |
| 753 | judge and k not has kjs false njs |
| 754 | judge and k has ksafe false nsafe |
| 755 | judge and k not has kquo false nquo |
| 756 | judge and k not active nact |
| 757 | pr3 tr1 tfbmd |
| 758 | r = load 0 |
| 759 | k = gt r 0 |
| 760 | judge and k not has kscript true nms |
| 761 | judge and k has kesc false nme |
| 762 | judge and k has kpipe false npipe |
| 763 | judge and k has klapsed false nlap |
| 764 | judge and k has kinf false ninf |
| 765 | judge and k has kcycle false ncyc |
| 766 | end |
| 767 | note diffnote: after cmp2, where TEST_ROOT/r1/f (ga) and the golden (gb) first differ |
| 768 | fn diffnote to void |
| 769 | a = get gn 8 |
| 770 | b = get gn 9 |
| 771 | m = a |
| 772 | if lt b m |
| 773 | m = b |
| 774 | end |
| 775 | i = ulong 0 |
| 776 | while lt i m bound 9223372036854775807 |
| 777 | if ne get ga i get gb i |
| 778 | break |
| 779 | end |
| 780 | i = add i 1 |
| 781 | end |
| 782 | o tfd |
| 783 | onum i |
| 784 | o tlg |
| 785 | onum b |
| 786 | o tlr |
| 787 | onum a |
| 788 | o tclose |
| 789 | end |
| 790 | fn active to bool |
| 791 | if or has kscript true has kiframe true |
| 792 | ret true |
| 793 | end |
| 794 | if or has kobject true has kembed true |
| 795 | ret true |
| 796 | end |
| 797 | if or has klink true has kimg true |
| 798 | ret true |
| 799 | end |
| 800 | ret or has ksrc true has krefresh true |
| 801 | end |
| 802 | fn again to void |
| 803 | rfull tr2 |
| 804 | expect nagain 0 |
| 805 | rfull tr2 |
| 806 | expect nover 0 |
| 807 | c = and cmp2 tfbmd false cmp2 tfidx false |
| 808 | judge c ndet |
| 809 | end |
| 810 | |
| 811 | note ======== clock: without --now the generated-by time is the current UTC second |
| 812 | note days: days since 1970-01-01 of a proleptic Gregorian date (days-from-civil) |
| 813 | fn days y ulong m ulong d ulong to ulong |
| 814 | yy = y |
| 815 | if le m 2 |
| 816 | yy = sub yy 1 |
| 817 | end |
| 818 | era = div yy 400 |
| 819 | yoe = sub yy mul era 400 |
| 820 | mm = add m 9 |
| 821 | if gt m 2 |
| 822 | mm = sub m 3 |
| 823 | end |
| 824 | doy = add div add mul 153 mm 2 5 sub d 1 |
| 825 | doe = add mul yoe 365 div yoe 4 |
| 826 | doe = add sub doe div yoe 100 doy |
| 827 | era = mul era 146097 |
| 828 | ret sub add era doe 719468 |
| 829 | end |
| 830 | fn tsc c uchar to bool |
| 831 | ret or or and ge c 48 le c 57 or eq c 84 eq c 90 or eq c 58 eq c 45 |
| 832 | end |
| 833 | note tsfind: copy into gts the [0-9TZ:-]* run between " at " and a "_" that ends a line of ga |
| 834 | fn tsfind to bool |
| 835 | n = get gn 8 |
| 836 | for e ulong n |
| 837 | if eq get ga e 95 |
| 838 | nl = true |
| 839 | if lt add e 1 n |
| 840 | nl = eq get ga add e 1 10 |
| 841 | end |
| 842 | if nl |
| 843 | s = e |
| 844 | while gt s 0 bound 9223372036854775807 |
| 845 | if not tsc get ga sub s 1 |
| 846 | break |
| 847 | end |
| 848 | s = sub s 1 |
| 849 | end |
| 850 | if and ge s 4 lt sub e s 64 |
| 851 | if attxt sub s 4 |
| 852 | put gtl 0 sub e s |
| 853 | for i ulong sub e s |
| 854 | put gts i get ga add s i |
| 855 | end |
| 856 | ret true |
| 857 | end |
| 858 | end |
| 859 | end |
| 860 | end |
| 861 | end |
| 862 | ret false |
| 863 | end |
| 864 | fn attxt p ulong to bool |
| 865 | for i ulong 4 |
| 866 | if ne get ga add p i get kat i |
| 867 | ret false |
| 868 | end |
| 869 | end |
| 870 | ret true |
| 871 | end |
| 872 | fn dig p ulong k ulong to ulong |
| 873 | v = ulong 0 |
| 874 | for i ulong k |
| 875 | c = get gts add p i |
| 876 | if or lt c 48 gt c 57 |
| 877 | ret 4294967296 |
| 878 | end |
| 879 | v = add mul v 10 ulong sub c 48 |
| 880 | end |
| 881 | ret v |
| 882 | end |
| 883 | note tsval: gts as Unix seconds when it is YYYY-MM-DDTHH:MM:SSZ, else 0 |
| 884 | fn tsval to ulong |
| 885 | if ne get gtl 0 20 |
| 886 | ret 0 |
| 887 | end |
| 888 | if or ne get gts 10 84 ne get gts 19 90 |
| 889 | ret 0 |
| 890 | end |
| 891 | y = dig 0 4 |
| 892 | mo = dig 5 2 |
| 893 | d = dig 8 2 |
| 894 | h = dig 11 2 |
| 895 | mi = dig 14 2 |
| 896 | se = dig 17 2 |
| 897 | if or gt y 9999 or gt mo 12 lt mo 1 |
| 898 | ret 0 |
| 899 | end |
| 900 | if or gt d 31 lt d 1 |
| 901 | ret 0 |
| 902 | end |
| 903 | if or gt h 23 or gt mi 59 gt se 60 |
| 904 | ret 0 |
| 905 | end |
| 906 | t = days y mo d |
| 907 | t = add mul t 24 h |
| 908 | t = add mul t 60 mi |
| 909 | ret add mul t 60 se |
| 910 | end |
| 911 | fn clock to void |
| 912 | put gn 12 div ulong realns 1000000000 |
| 913 | rbase |
| 914 | ka aout |
| 915 | ar tr3 |
| 916 | expect nclock 0 |
| 917 | put gn 13 div ulong realns 1000000000 |
| 918 | pr3 tr3 tfbmd |
| 919 | r = load 0 |
| 920 | put gtl 0 0 |
| 921 | f = tsfind |
| 922 | tv = tsval |
| 923 | c = and ge tv get gn 12 le tv get gn 13 |
| 924 | if c |
| 925 | ok nciso |
| 926 | o tsp |
| 927 | else |
| 928 | bad nciso |
| 929 | o tsp |
| 930 | end |
| 931 | r = write 1 gts 0 get gtl 0 |
| 932 | if not c |
| 933 | o tnot |
| 934 | onum get gn 12 |
| 935 | o tdots |
| 936 | onum get gn 13 |
| 937 | end |
| 938 | o tclose |
| 939 | onl |
| 940 | judge has khu false nhu |
| 941 | judge has knone false nnone |
| 942 | end |
| 943 | |
| 944 | note ======== negative cases |
| 945 | fn neg1 to void |
| 946 | cmdmiss 0 |
| 947 | expect nmc 4 |
| 948 | cmdmiss 1 |
| 949 | expect nmm 4 |
| 950 | rbase |
| 951 | ka afind |
| 952 | ar tnope |
| 953 | ka aout |
| 954 | ar tn2 |
| 955 | expect nmf 0 |
| 956 | cmd |
| 957 | ka arender |
| 958 | ka aclaims |
| 959 | af fbcl |
| 960 | ka amap |
| 961 | af fmap |
| 962 | ka aout |
| 963 | ar tn1 |
| 964 | expect nbc 65 |
| 965 | pr terr |
| 966 | r = load 0 |
| 967 | judge has kc2 false nbc2 |
| 968 | cmd |
| 969 | ka arender |
| 970 | ka aclaims |
| 971 | af fcl |
| 972 | ka amap |
| 973 | af fbmap |
| 974 | ka aout |
| 975 | ar tn1 |
| 976 | expect nbm 65 |
| 977 | pr3 tn1 tfbmd |
| 978 | fd = openp 524288 0 |
| 979 | if ge fd 0 |
| 980 | c = fclose int fd |
| 981 | end |
| 982 | judge lt fd 0 nnw |
| 983 | end |
| 984 | note cmdmiss: render with a missing claims file (w 0) or map file (w 1), out TEST_ROOT/n1 |
| 985 | fn cmdmiss w ulong to void |
| 986 | cmd |
| 987 | ka arender |
| 988 | ka aclaims |
| 989 | if eq w 0 |
| 990 | ar tnope |
| 991 | else |
| 992 | af fcl |
| 993 | end |
| 994 | ka amap |
| 995 | if eq w 1 |
| 996 | ar tnope |
| 997 | else |
| 998 | af fmap |
| 999 | end |
| 1000 | ka aout |
| 1001 | ar tn1 |
| 1002 | end |
| 1003 | fn neg2 to void |
| 1004 | rbase |
| 1005 | expect nno 64 |
| 1006 | rn1 |
| 1007 | ka anow |
| 1008 | ka vbadnow |
| 1009 | expect nbn 64 |
| 1010 | rn1 |
| 1011 | ka ahead |
| 1012 | ka vbadhead |
| 1013 | expect nbh 64 |
| 1014 | rn1 |
| 1015 | ka abogus |
| 1016 | ka a1 |
| 1017 | expect nuf 64 |
| 1018 | cmd |
| 1019 | ka arender |
| 1020 | ka aclaims |
| 1021 | af fcl |
| 1022 | ka aclaims |
| 1023 | af fcl |
| 1024 | ka amap |
| 1025 | af fmap |
| 1026 | ka aout |
| 1027 | ar tn1 |
| 1028 | expect ndf 64 |
| 1029 | cmd |
| 1030 | expect nnc 64 |
| 1031 | cmd |
| 1032 | ka adelete |
| 1033 | ka aout |
| 1034 | ar tn1 |
| 1035 | expect nbcmd 64 |
| 1036 | end |
| 1037 | fn rn1 to void |
| 1038 | rbase |
| 1039 | ka aout |
| 1040 | ar tn1 |
| 1041 | end |
| 1042 | note sv: serve --dir TEST_ROOT/r1 --bind b --max 1 |
| 1043 | fn sv b view uchar * to void |
| 1044 | cmd |
| 1045 | ka aserve |
| 1046 | ka adir |
| 1047 | ar tr1 |
| 1048 | ka abind |
| 1049 | ka b |
| 1050 | ka amax |
| 1051 | ka a1 |
| 1052 | end |
| 1053 | fn neg3 to void |
| 1054 | sv b0 |
| 1055 | expect ns0 64 |
| 1056 | sv b127 |
| 1057 | expect ns127 64 |
| 1058 | sv b128 |
| 1059 | expect ns128 64 |
| 1060 | sv b63 |
| 1061 | expect ns63 64 |
| 1062 | sv bnoport |
| 1063 | expect nsnp 64 |
| 1064 | cmd |
| 1065 | ka aserve |
| 1066 | ka abind |
| 1067 | ka bok |
| 1068 | ka amax |
| 1069 | ka a1 |
| 1070 | expect nsnd 64 |
| 1071 | cmd |
| 1072 | ka aserve |
| 1073 | ka adir |
| 1074 | ar tr1 |
| 1075 | ka abind |
| 1076 | ka bok |
| 1077 | ka aout |
| 1078 | ar tr1 |
| 1079 | expect nsrf 64 |
| 1080 | end |
| 1081 | |
| 1082 | note ======== live serve on this host's tailnet address (GET only, read-only, one connection) |
| 1083 | note octet: the decimal at ga[p..), with its end in gn 14; 256 when absent or out of range |
| 1084 | fn octet p ulong to ulong |
| 1085 | v = ulong 0 |
| 1086 | n = ulong 0 |
| 1087 | while lt add p n get gn 8 bound 4 |
| 1088 | c = get ga add p n |
| 1089 | if or lt c 48 gt c 57 |
| 1090 | break |
| 1091 | end |
| 1092 | v = add mul v 10 ulong sub c 48 |
| 1093 | n = add n 1 |
| 1094 | end |
| 1095 | put gn 14 add p n |
| 1096 | if or eq n 0 gt v 255 |
| 1097 | ret 256 |
| 1098 | end |
| 1099 | ret v |
| 1100 | end |
| 1101 | note addrat: the dotted address at ga[p..) in host order, or 0 when it is not one |
| 1102 | fn addrat p ulong to ulong |
| 1103 | a = ulong 0 |
| 1104 | q = p |
| 1105 | for i ulong 4 |
| 1106 | v = octet q |
| 1107 | if eq v 256 |
| 1108 | ret 0 |
| 1109 | end |
| 1110 | a = add shl a 8 v |
| 1111 | q = get gn 14 |
| 1112 | if lt i 3 |
| 1113 | if or ge q get gn 8 ne get ga q 46 |
| 1114 | ret 0 |
| 1115 | end |
| 1116 | q = add q 1 |
| 1117 | end |
| 1118 | end |
| 1119 | ret a |
| 1120 | end |
| 1121 | fn at2 p ulong t view uchar * to bool |
| 1122 | if gt add p len t get gn 8 |
| 1123 | ret false |
| 1124 | end |
| 1125 | for i ulong len t |
| 1126 | if ne get ga add p i get t i |
| 1127 | ret false |
| 1128 | end |
| 1129 | end |
| 1130 | ret true |
| 1131 | end |
| 1132 | note tailnet: the first local /32 inside 100.64.0.0/10 in /proc/net/fib_trie, or 0 |
| 1133 | fn tailnet to ulong |
| 1134 | pclr |
| 1135 | pt kfib |
| 1136 | r = load 0 |
| 1137 | if lt r 0 |
| 1138 | ret 0 |
| 1139 | end |
| 1140 | last = ulong 0 |
| 1141 | for p ulong get gn 8 |
| 1142 | if at2 p kdash |
| 1143 | last = addrat add p len kdash |
| 1144 | end |
| 1145 | if at2 p kloc |
| 1146 | if eq and last 4290772992 1681915904 |
| 1147 | ret last |
| 1148 | end |
| 1149 | end |
| 1150 | end |
| 1151 | ret 0 |
| 1152 | end |
| 1153 | note paddr: append the dotted form of gn 11 and ":18731" to gp |
| 1154 | fn pnum v ulong to void |
| 1155 | if ge v 100 |
| 1156 | pc uchar add div v 100 48 |
| 1157 | end |
| 1158 | if ge v 10 |
| 1159 | pc uchar add rem div v 10 10 48 |
| 1160 | end |
| 1161 | pc uchar add rem v 10 48 |
| 1162 | end |
| 1163 | fn paddr to void |
| 1164 | a = get gn 11 |
| 1165 | pnum shr a 24 |
| 1166 | pc 46 |
| 1167 | pnum and shr a 16 255 |
| 1168 | pc 46 |
| 1169 | pnum and shr a 8 255 |
| 1170 | pc 46 |
| 1171 | pnum and a 255 |
| 1172 | end |
| 1173 | fn pport to void |
| 1174 | pc 58 |
| 1175 | pnum 187 |
| 1176 | pnum 31 |
| 1177 | end |
| 1178 | note serving: TEST_ROOT/serve.out shows the server is up |
| 1179 | fn serving to bool |
| 1180 | pr tsout |
| 1181 | r = load 0 |
| 1182 | if lt r 0 |
| 1183 | ret false |
| 1184 | end |
| 1185 | ret has kserving false |
| 1186 | end |
| 1187 | note get: one GET / to the tailnet address; status into gn 15 and the body into gb from offset 0 |
| 1188 | fn sendreq fd int to bool |
| 1189 | pclr |
| 1190 | pt kget1 |
| 1191 | crlf |
| 1192 | pt khost |
| 1193 | paddr |
| 1194 | pport |
| 1195 | crlf |
| 1196 | pt kget2 |
| 1197 | crlf |
| 1198 | crlf |
| 1199 | w = send fd gp 0 get gn 2 0 |
| 1200 | ret eq w long get gn 2 |
| 1201 | end |
| 1202 | fn crlf to void |
| 1203 | pc 13 |
| 1204 | pc 10 |
| 1205 | end |
| 1206 | fn httpget to void |
| 1207 | put gn 15 0 |
| 1208 | put gn 9 0 |
| 1209 | fd = socknew 2 1 0 |
| 1210 | if lt fd 0 |
| 1211 | ret |
| 1212 | end |
| 1213 | sa = new uchar 16 0 |
| 1214 | put sa 0 2 |
| 1215 | put sa 2 uchar 73 |
| 1216 | put sa 3 uchar 43 |
| 1217 | a = get gn 11 |
| 1218 | put sa 4 uchar shr a 24 |
| 1219 | put sa 5 uchar and shr a 16 255 |
| 1220 | put sa 6 uchar and shr a 8 255 |
| 1221 | put sa 7 uchar and a 255 |
| 1222 | r = connect int fd sa 0 16 |
| 1223 | if or lt r 0 not sendreq int fd |
| 1224 | c = fclose int fd |
| 1225 | ret |
| 1226 | end |
| 1227 | recvall int fd |
| 1228 | c = fclose int fd |
| 1229 | parse |
| 1230 | end |
| 1231 | fn recvall fd int to void |
| 1232 | p = ulong 0 |
| 1233 | for it ulong 999999 |
| 1234 | if not growp 1 add p 65536 |
| 1235 | ret |
| 1236 | end |
| 1237 | w = waitio fd 1 5000000000 |
| 1238 | if le w 0 |
| 1239 | ret |
| 1240 | end |
| 1241 | r = recv fd gde 0 65536 0 |
| 1242 | if le r 0 |
| 1243 | put gn 9 p |
| 1244 | ret |
| 1245 | end |
| 1246 | for i ulong ulong r |
| 1247 | put gb add p i get gde i |
| 1248 | end |
| 1249 | p = add p ulong r |
| 1250 | put gn 9 p |
| 1251 | end |
| 1252 | end |
| 1253 | note parse: status code of gb's response into gn 15; the body moved to the front of gb, its length gn 9 |
| 1254 | fn parse to void |
| 1255 | n = get gn 9 |
| 1256 | if lt n 12 |
| 1257 | ret |
| 1258 | end |
| 1259 | s = ulong 0 |
| 1260 | for i ulong 3 |
| 1261 | c = get gb add 9 i |
| 1262 | if or lt c 48 gt c 57 |
| 1263 | ret |
| 1264 | end |
| 1265 | s = add mul s 10 ulong sub c 48 |
| 1266 | end |
| 1267 | put gn 15 s |
| 1268 | for i ulong sub n 3 |
| 1269 | if hdrend i |
| 1270 | b = add i 4 |
| 1271 | for j ulong sub n b |
| 1272 | put gb j get gb add b j |
| 1273 | end |
| 1274 | put gn 9 sub n b |
| 1275 | ret |
| 1276 | end |
| 1277 | end |
| 1278 | put gn 15 0 |
| 1279 | end |
| 1280 | fn hdrend i ulong to bool |
| 1281 | if or ne get gb i 13 ne get gb add i 1 10 |
| 1282 | ret false |
| 1283 | end |
| 1284 | ret and eq get gb add i 2 13 eq get gb add i 3 10 |
| 1285 | end |
| 1286 | fn live to void |
| 1287 | a = tailnet |
| 1288 | if eq a 0 |
| 1289 | put gn 6 add get gn 6 1 |
| 1290 | o tnotrun |
| 1291 | ret |
| 1292 | end |
| 1293 | put gn 11 a |
| 1294 | k0 |
| 1295 | pr tbinb |
| 1296 | kp |
| 1297 | ka aserve |
| 1298 | ka adir |
| 1299 | ar tr1 |
| 1300 | ka abind |
| 1301 | pclr |
| 1302 | paddr |
| 1303 | pport |
| 1304 | kp |
| 1305 | ka amax |
| 1306 | ka a1 |
| 1307 | put gn 7 2 |
| 1308 | pid = spawn |
| 1309 | if lt pid 0 |
| 1310 | bad nsexit |
| 1311 | onl |
| 1312 | ret |
| 1313 | end |
| 1314 | for i ulong 50 |
| 1315 | if serving |
| 1316 | break |
| 1317 | end |
| 1318 | s = sleepns 100000000 |
| 1319 | end |
| 1320 | httpget |
| 1321 | livewait pid |
| 1322 | liveres |
| 1323 | end |
| 1324 | fn livewait pid long to void |
| 1325 | e = long -1 |
| 1326 | for i ulong 50 |
| 1327 | e = reap pid 1 |
| 1328 | if ge e 0 |
| 1329 | break |
| 1330 | end |
| 1331 | s = sleepns 100000000 |
| 1332 | end |
| 1333 | if ge e 0 |
| 1334 | ok nsexit |
| 1335 | onl |
| 1336 | ret |
| 1337 | end |
| 1338 | k = killpid int pid 9 |
| 1339 | e = reap pid 0 |
| 1340 | bad nsexit |
| 1341 | onl |
| 1342 | end |
| 1343 | fn liveres to void |
| 1344 | pr3 tr1 tfidx |
| 1345 | r = load 0 |
| 1346 | c = and eq get gn 15 200 sameab |
| 1347 | if c |
| 1348 | ok nlive |
| 1349 | o ton |
| 1350 | pclr |
| 1351 | paddr |
| 1352 | pport |
| 1353 | w = write 1 gp 0 get gn 2 |
| 1354 | else |
| 1355 | bad nlive |
| 1356 | o tsp |
| 1357 | onum get gn 15 |
| 1358 | o tclose |
| 1359 | end |
| 1360 | onl |
| 1361 | end |
| 1362 | |
| 1363 | note ======== main |
| 1364 | note posrc: append OMEGA_SRC to gp |
| 1365 | fn posrc to void |
| 1366 | for i ulong get gn 1 |
| 1367 | pc get gosrc i |
| 1368 | end |
| 1369 | end |
| 1370 | note wga: write ga[0..n) to fd in full |
| 1371 | fn wga fd int n ulong to bool |
| 1372 | p = ulong 0 |
| 1373 | while lt p n bound 9223372036854775807 |
| 1374 | w = write fd ga p sub n p |
| 1375 | if le w 0 |
| 1376 | ret false |
| 1377 | end |
| 1378 | p = add p ulong w |
| 1379 | end |
| 1380 | ret true |
| 1381 | end |
| 1382 | note catto: append the file named by gp to fd |
| 1383 | fn catto fd int to bool |
| 1384 | r = load 0 |
| 1385 | if lt r 0 |
| 1386 | ret false |
| 1387 | end |
| 1388 | ret wga fd get gn 8 |
| 1389 | end |
| 1390 | note mkdriver: compose om2 + OMEGA_SRC/om/tls/sha2.om + tools/build.om into TEST_ROOT/build.unit.om and |
| 1391 | note compile it with OMEGA_SRC's omc into TEST_ROOT/bin/build (omc's messages in TEST_ROOT/build.err), so |
| 1392 | note the build driver is always the one in this tree, never a stale build/build |
| 1393 | fn mkdriver to bool |
| 1394 | pr tunit |
| 1395 | fd = openp 524865 420 |
| 1396 | if lt fd 0 |
| 1397 | ret false |
| 1398 | end |
| 1399 | w = write int fd tom2 0 len tom2 |
| 1400 | okw = eq w 4 |
| 1401 | pclr |
| 1402 | posrc |
| 1403 | pt tsha2 |
| 1404 | ok1 = catto int fd |
| 1405 | pclr |
| 1406 | pt tbldom |
| 1407 | ok2 = catto int fd |
| 1408 | c = fclose int fd |
| 1409 | if not and okw and ok1 ok2 |
| 1410 | ret false |
| 1411 | end |
| 1412 | k0 |
| 1413 | pclr |
| 1414 | posrc |
| 1415 | pt tomc |
| 1416 | kp |
| 1417 | put gn 7 3 |
| 1418 | rc = runk |
| 1419 | ret eq rc 0 |
| 1420 | end |
| 1421 | fn build to bool |
| 1422 | if not mkdriver |
| 1423 | ret false |
| 1424 | end |
| 1425 | k0 |
| 1426 | pr tbldb |
| 1427 | kp |
| 1428 | pclr |
| 1429 | posrc |
| 1430 | kp |
| 1431 | pr tbinb |
| 1432 | kp |
| 1433 | put gn 7 0 |
| 1434 | rc = runk |
| 1435 | ret eq rc 0 |
| 1436 | end |
| 1437 | fn summary to int |
| 1438 | o tsum |
| 1439 | onum get gn 4 |
| 1440 | o tsumf |
| 1441 | onum get gn 5 |
| 1442 | o tsumn |
| 1443 | onum get gn 6 |
| 1444 | onl |
| 1445 | if eq get gn 5 0 |
| 1446 | ret 0 |
| 1447 | end |
| 1448 | ret 1 |
| 1449 | end |
| 1450 | fn setup to bool |
| 1451 | pr tbin |
| 1452 | n = get gn 0 |
| 1453 | r = makedir groot 0 n 493 |
| 1454 | if lt r 0 |
| 1455 | ret false |
| 1456 | end |
| 1457 | r = makedir gp 0 get gn 2 493 |
| 1458 | ret ge r 0 |
| 1459 | end |
| 1460 | fn main to int |
| 1461 | na = argcnt |
| 1462 | if or lt na 3 gt na 4 |
| 1463 | r = write 2 tuse 0 len tuse |
| 1464 | ret 64 |
| 1465 | end |
| 1466 | n = argread 1 gosrc 0 4096 |
| 1467 | m = argread 2 groot 0 4096 |
| 1468 | if or lt n 1 lt m 1 |
| 1469 | r = write 2 tuse 0 len tuse |
| 1470 | ret 64 |
| 1471 | end |
| 1472 | put gn 1 ulong n |
| 1473 | put gn 0 ulong m |
| 1474 | upd = false |
| 1475 | if eq na 4 |
| 1476 | k = argread 3 gp 0 64 |
| 1477 | upd = and eq k long len tupd at2gp |
| 1478 | if not upd |
| 1479 | r = write 2 tuse 0 len tuse |
| 1480 | ret 64 |
| 1481 | end |
| 1482 | end |
| 1483 | if not setup |
| 1484 | r = write 2 texists 0 len texists |
| 1485 | ret 64 |
| 1486 | end |
| 1487 | if not build |
| 1488 | bad nbuild |
| 1489 | onl |
| 1490 | ret 1 |
| 1491 | end |
| 1492 | ok nbuild |
| 1493 | onl |
| 1494 | render1 |
| 1495 | if upd |
| 1496 | updgold |
| 1497 | end |
| 1498 | golden |
| 1499 | escapes |
| 1500 | again |
| 1501 | clock |
| 1502 | neg1 |
| 1503 | neg2 |
| 1504 | neg3 |
| 1505 | live |
| 1506 | ret summary |
| 1507 | end |
| 1508 | fn at2gp to bool |
| 1509 | for i ulong len tupd |
| 1510 | if ne get gp i get tupd i |
| 1511 | ret false |
| 1512 | end |
| 1513 | end |
| 1514 | ret true |
| 1515 | end |