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 / gpu / nvidia / driver / seqgate.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note gpu/nvidia/driver/seqgate.om: the sequence gate of the driver slice. It reads the cases the C oracle printed |
| 3 | note (gpu/nvidia/driver/seq-cases.tsv: the C bodies of CUDApp 84b524ca nvrm_open, alloc_with_cacheability, |
| 4 | note nvrm_free, chan_extra, nvrm_channel_n, nvrm_channel_destroy, nvrm_enqueue, nvrm_chan_submit, nvrm_close, |
| 5 | note m16_native_free_memory and the rest, run outside this tree with every device effect recorded) and runs the |
| 6 | note same program on client.om with fx.om's recorder and the same failure script. The command sequence, the |
| 7 | note answers, the messages and the final client state must be the same bytes. Exit 0 is PASS. |
| 8 | note |
| 9 | note Line: seq PROGRAM K F R TRACE, tab separated. PROGRAM is decimal tokens, the calls made on one client: |
| 10 | note 1 ADMITSM SELSM DISC NCLS nvrm_open / 2 SLOT SIZE MODE alloc (0 nvrm_alloc, 1 gpu_uncached, 2 vram) / |
| 11 | note 3 SLOT nvrm_free / 4 EXTRA nvrm_channel_n / 5 nvrm_channel_destroy / 6 SLOT OFF NW nvrm_enqueue / |
| 12 | note 7 CH SLOT OFF NW nvrm_chan_submit / 8 nvrm_close / 9 SIZE m16_native_alloc_memory / 10 SEL |
| 13 | note m16_native_free_memory (SEL < 64: legacy row SEL's cpu; else the address SEL) / 11 SLOT FIELD VALUE set a |
| 14 | note caller descriptor field (0 handle, 1 va, 2 size, 3 cpu) / 12 DST SRC copy a caller descriptor / |
| 15 | note 13 CH PUT RETIRED set a channel's counters (0 the main one) / 14 MS channel_no_memory_retry_ms / |
| 16 | note 15 ADMITSM SELSM DISC NCLS m16_native_open / 16 m16_native_create_channel / 17 m16_native_close / |
| 17 | note 18 SLOT OFF NW nvrm_submit / 19 m16_native_ring_doorbell (nvrm_ring). |
| 18 | note SLOT is a caller descriptor, 0 to 15. K F R: the failure script (fx.om). TRACE: events "NAME ARGS =R;" in |
| 19 | note order (fx.om), "OP CODE =RC;" after each call, then the state: "ST ...;" client fields, "LV ...;" each |
| 20 | note live row, "CH ...;" each extra channel, "MM ...;" each non-empty caller descriptor, "LG ...;" each |
| 21 | note non-empty m16 legacy row, "PB ...;" m16's pushbuffer when not empty. |
| 22 | note |
| 23 | note Controls, two for the first case of each program: the comparison against the expected trace with one |
| 24 | note byte changed, and the program rerun with another failure script (K 1), each of which must differ. |
| 25 | note A line is read into a 65536-byte array (fixed when compiled); a longer line is refused by name, never cut. |
| 26 | |
| 27 | text sq_use "usage: seqgate SEQ-CASES.tsv\n" |
| 28 | text sq_topen "seqgate: cannot open, size or map the cases file\n" |
| 29 | text sq_long "seqgate: a line of the cases file is longer than 65536 bytes; refused\n" |
| 30 | text sq_fl "FAIL line " |
| 31 | text sq_at " at byte " |
| 32 | text sq_tbad "FAIL malformed line " |
| 33 | text sq_ctl "FAIL control not caught, line " |
| 34 | text sq_want "\n want: " |
| 35 | text sq_got "\n got: " |
| 36 | text sq_ovf "FAIL trace longer than 65536 bytes or a script the recorder cannot follow, line " |
| 37 | text sq_sum "OMEGA-GPU-DRIVER-SEQ " |
| 38 | text sq_pass "PASS" |
| 39 | text sq_fail "FAIL" |
| 40 | text sq_cs " cases=" |
| 41 | text sq_ps " programs=" |
| 42 | text sq_co " controls=" |
| 43 | text sq_ca " caught=" |
| 44 | text sq_hw " hardware=NOT_RUN\n" |
| 45 | text sq_nl "\n" |
| 46 | text sq_seq "seq" |
| 47 | global sq_p uchar 4096 |
| 48 | global sq_st uchar 256 |
| 49 | global sq_nb uchar 24 |
| 50 | note program tokens and their count |
| 51 | global sp ulong 256 |
| 52 | note the five tab offsets of the current line |
| 53 | global sq_t ulong 6 |
| 54 | note sq_n: 0 tokens, 1 line number, 2 cases, 3 fails, 4 controls, 5 caught, 6 programs, 7 file fd, 8 size, |
| 55 | note 9 control mode (1 on) |
| 56 | global sq_n ulong 16 |
| 57 | note the previous program, for the first case of each |
| 58 | global sq_prev uchar 4096 |
| 59 | global sq_pl ulong 1 |
| 60 | |
| 61 | fn sq_num v ulong to void |
| 62 | k = ulong 0 |
| 63 | x = v |
| 64 | while true bound 20 |
| 65 | put sq_nb k uchar add 48 rem x 10 |
| 66 | k = add k 1 |
| 67 | x = div x 10 |
| 68 | if eq x 0 |
| 69 | break |
| 70 | end |
| 71 | end |
| 72 | for j ulong div k 2 bound 10 |
| 73 | a = get sq_nb j |
| 74 | put sq_nb j get sq_nb sub sub k j 1 |
| 75 | put sq_nb sub sub k j 1 a |
| 76 | end |
| 77 | r = write 1 sq_nb 0 k |
| 78 | end |
| 79 | |
| 80 | note --- the state dump, in the oracle's format --- |
| 81 | fn sq_hex2 b ulong to void |
| 82 | put sq_nb 0 uchar 32 |
| 83 | h = shr b 4 |
| 84 | lo = and b 15 |
| 85 | put sq_nb 1 uchar add h 48 |
| 86 | if gt h 9 |
| 87 | put sq_nb 1 uchar add h 87 |
| 88 | end |
| 89 | put sq_nb 2 uchar add lo 48 |
| 90 | if gt lo 9 |
| 91 | put sq_nb 2 uchar add lo 87 |
| 92 | end |
| 93 | for i ulong 3 |
| 94 | fx_c ulong get sq_nb i |
| 95 | end |
| 96 | end |
| 97 | |
| 98 | fn sq_row s ulong to void |
| 99 | fx_su mh s |
| 100 | fx_su mva s |
| 101 | fx_su msz s |
| 102 | fx_su mcpu s |
| 103 | end |
| 104 | |
| 105 | fn sq_dump to void |
| 106 | fx_c 83 |
| 107 | fx_c 84 |
| 108 | for i ulong 11 |
| 109 | fx_su cg i |
| 110 | end |
| 111 | for i ulong 4 |
| 112 | fx_sd bitcast long cg add CS_FDCTL i |
| 113 | end |
| 114 | fx_su cg CS_GREG |
| 115 | fx_su cg CS_VREG |
| 116 | fx_su cg CS_CREG |
| 117 | fx_su cg CS_NEXTRA |
| 118 | fx_su cg CS_LIVEN |
| 119 | fx_su cg CS_PUT |
| 120 | fx_su cg CS_RET |
| 121 | fx_su cg CS_ENT |
| 122 | fx_su cg CS_USERD |
| 123 | fx_su cg CS_TOKEN |
| 124 | fx_su cg CS_CHVA |
| 125 | fx_su cg CS_CHVASZ |
| 126 | fx_su cg CS_SLOT |
| 127 | fx_su cg CS_VANEXT |
| 128 | fx_su cg CS_TSM |
| 129 | fx_su cg CS_DISC |
| 130 | fx_su cg CS_CCLS |
| 131 | fx_su cg CS_GCLS |
| 132 | fx_su cg CS_UCLS |
| 133 | fx_su cg CS_SMV |
| 134 | fx_su cg CS_GPUID |
| 135 | fx_su cg CS_MINOR |
| 136 | fx_su cg CS_UCPU |
| 137 | fx_su cg CS_LRS |
| 138 | fx_su cg CS_RETRIES |
| 139 | for i ulong 16 |
| 140 | sq_hex2 cn_uuidb i |
| 141 | end |
| 142 | sq_row 0 |
| 143 | sq_row 1 |
| 144 | fx_semi |
| 145 | for r ulong cg CS_LIVEN bound 4096 |
| 146 | fx_c 76 |
| 147 | fx_c 86 |
| 148 | fx_su lg r 0 |
| 149 | fx_su lg r 1 |
| 150 | fx_su lg r 2 |
| 151 | fx_su lg r 3 |
| 152 | for f ulong 5 |
| 153 | fx_su lg r add 4 f |
| 154 | end |
| 155 | fx_semi |
| 156 | end |
| 157 | for i ulong 3 |
| 158 | fx_c 67 |
| 159 | fx_c 72 |
| 160 | for f ulong 10 |
| 161 | fx_su xg i f |
| 162 | end |
| 163 | fx_su xg i 10 |
| 164 | sq_row add 2 mul i 2 |
| 165 | sq_row add 3 mul i 2 |
| 166 | fx_semi |
| 167 | end |
| 168 | for i ulong 16 |
| 169 | s = add 10 i |
| 170 | if or or or ne mh s 0 ne mva s 0 ne msz s 0 ne mcpu s 0 |
| 171 | fx_c 77 |
| 172 | fx_c 77 |
| 173 | fx_su i |
| 174 | sq_row s |
| 175 | fx_semi |
| 176 | end |
| 177 | end |
| 178 | for i ulong 64 |
| 179 | s = add 26 i |
| 180 | if or or or ne mh s 0 ne mva s 0 ne msz s 0 ne mcpu s 0 |
| 181 | fx_c 76 |
| 182 | fx_c 71 |
| 183 | fx_su i |
| 184 | sq_row s |
| 185 | fx_semi |
| 186 | end |
| 187 | end |
| 188 | if or or or ne mh 9 0 ne mva 9 0 ne msz 9 0 ne mcpu 9 0 |
| 189 | fx_c 80 |
| 190 | fx_c 66 |
| 191 | sq_row 9 |
| 192 | fx_semi |
| 193 | end |
| 194 | end |
| 195 | |
| 196 | note --- run the program in sp with failure script k f r into fo; false when the program is malformed --- |
| 197 | note the argument count of call op; 99 for an unknown call |
| 198 | fn sq_nargs op ulong to ulong |
| 199 | if or or eq op 1 eq op 7 eq op 15 |
| 200 | ret 4 |
| 201 | end |
| 202 | if or or or or eq op 2 eq op 6 eq op 11 eq op 13 eq op 18 |
| 203 | ret 3 |
| 204 | end |
| 205 | if or or or or eq op 3 eq op 4 eq op 9 eq op 10 eq op 14 |
| 206 | ret 1 |
| 207 | end |
| 208 | if eq op 12 |
| 209 | ret 2 |
| 210 | end |
| 211 | if or or or or eq op 5 eq op 8 eq op 16 eq op 17 eq op 19 |
| 212 | ret 0 |
| 213 | end |
| 214 | ret 99 |
| 215 | end |
| 216 | |
| 217 | fn sq_a i ulong to ulong |
| 218 | ret get sp i |
| 219 | end |
| 220 | |
| 221 | fn sq_u i ulong to ulong |
| 222 | ret and get sp i CN_U32 |
| 223 | end |
| 224 | |
| 225 | note 11 SLOT FIELD VALUE |
| 226 | fn sq_poke i ulong to long |
| 227 | s = add 10 sq_a i |
| 228 | fd = sq_a add i 1 |
| 229 | v = sq_a add i 2 |
| 230 | if eq fd 0 |
| 231 | v = and v CN_U32 |
| 232 | end |
| 233 | put cm add mul s 4 fd v |
| 234 | ret 0 |
| 235 | end |
| 236 | |
| 237 | note 12 DST SRC |
| 238 | fn sq_copy i ulong to long |
| 239 | d = add 10 sq_a i |
| 240 | s = add 10 sq_a add i 1 |
| 241 | mset d mh s mva s msz s mcpu s |
| 242 | ret 0 |
| 243 | end |
| 244 | |
| 245 | note 13 CH PUT RETIRED |
| 246 | fn sq_ctr i ulong to long |
| 247 | c = sq_a i |
| 248 | if eq c 0 |
| 249 | cp CS_PUT sq_u add i 1 |
| 250 | cp CS_RET sq_u add i 2 |
| 251 | ret 0 |
| 252 | end |
| 253 | xp sub c 1 6 sq_u add i 1 |
| 254 | xp sub c 1 7 sq_u add i 2 |
| 255 | ret 0 |
| 256 | end |
| 257 | |
| 258 | note 10 SEL |
| 259 | fn sq_m16free i ulong to long |
| 260 | sel = sq_a i |
| 261 | if lt sel 64 |
| 262 | ret cn_m16free mcpu add 26 sel |
| 263 | end |
| 264 | ret cn_m16free sel |
| 265 | end |
| 266 | |
| 267 | note call op with its arguments at sp[i] (checked by sq_ok) |
| 268 | fn sq_op op ulong i ulong to long |
| 269 | if eq op 1 |
| 270 | fx_scen sq_a i sq_a add i 1 sq_a add i 2 sq_a add i 3 |
| 271 | ret cn_open |
| 272 | end |
| 273 | if eq op 2 |
| 274 | ret cn_alloc_mode sq_a add i 1 add 10 sq_a i sq_a add i 2 |
| 275 | end |
| 276 | if eq op 3 |
| 277 | ret cn_free add 10 sq_a i |
| 278 | end |
| 279 | if eq op 4 |
| 280 | ret cn_channel sq_u i |
| 281 | end |
| 282 | if eq op 5 |
| 283 | ret cn_chdestroy |
| 284 | end |
| 285 | if eq op 6 |
| 286 | ret cn_enqueue add 10 sq_a i sq_u add i 1 sq_u add i 2 |
| 287 | end |
| 288 | if eq op 7 |
| 289 | ret cn_submit sq_u i add 10 sq_a add i 1 sq_u add i 2 sq_u add i 3 |
| 290 | end |
| 291 | if eq op 8 |
| 292 | ret cn_close |
| 293 | end |
| 294 | if eq op 9 |
| 295 | ret cn_m16alloc sq_a i |
| 296 | end |
| 297 | if eq op 10 |
| 298 | ret sq_m16free i |
| 299 | end |
| 300 | if eq op 11 |
| 301 | ret sq_poke i |
| 302 | end |
| 303 | if eq op 12 |
| 304 | ret sq_copy i |
| 305 | end |
| 306 | if eq op 13 |
| 307 | ret sq_ctr i |
| 308 | end |
| 309 | if eq op 15 |
| 310 | fx_scen sq_a i sq_a add i 1 sq_a add i 2 sq_a add i 3 |
| 311 | ret cn_m16open |
| 312 | end |
| 313 | if eq op 16 |
| 314 | ret cn_m16chan |
| 315 | end |
| 316 | if eq op 17 |
| 317 | ret cn_m16close |
| 318 | end |
| 319 | if eq op 18 |
| 320 | ret cn_nsubmit add 10 sq_a i sq_u add i 1 sq_u add i 2 |
| 321 | end |
| 322 | if eq op 19 |
| 323 | cn_ring |
| 324 | ret 0 |
| 325 | end |
| 326 | cp CS_RETMS sq_u i |
| 327 | ret 0 |
| 328 | end |
| 329 | |
| 330 | note the arguments of call op at sp[i] name existing slots, fields and channels |
| 331 | fn sq_ok op ulong i ulong to bool |
| 332 | if or or or or or eq op 2 eq op 3 eq op 6 eq op 11 eq op 12 eq op 18 |
| 333 | if gt sq_a i 15 |
| 334 | ret false |
| 335 | end |
| 336 | end |
| 337 | if or eq op 7 eq op 12 |
| 338 | if gt sq_a add i 1 15 |
| 339 | ret false |
| 340 | end |
| 341 | end |
| 342 | if eq op 11 |
| 343 | if gt sq_a add i 1 3 |
| 344 | ret false |
| 345 | end |
| 346 | end |
| 347 | if eq op 13 |
| 348 | if gt sq_a i 3 |
| 349 | ret false |
| 350 | end |
| 351 | end |
| 352 | ret true |
| 353 | end |
| 354 | |
| 355 | fn sq_run k ulong f ulong r ulong to bool |
| 356 | fx_reset k f r |
| 357 | cn_zero |
| 358 | for j ulong 360 |
| 359 | put cm j 0 |
| 360 | end |
| 361 | np = get sq_n 0 |
| 362 | i = ulong 0 |
| 363 | while lt i np bound 256 |
| 364 | op = get sp i |
| 365 | i = add i 1 |
| 366 | n = sq_nargs op |
| 367 | if gt add i n np |
| 368 | ret false |
| 369 | end |
| 370 | if not sq_ok op i |
| 371 | ret false |
| 372 | end |
| 373 | rc = sq_op op i |
| 374 | i = add i n |
| 375 | fx_c 79 |
| 376 | fx_c 80 |
| 377 | fx_su op |
| 378 | fx_rd rc |
| 379 | end |
| 380 | sq_dump |
| 381 | ret true |
| 382 | end |
| 383 | |
| 384 | note --- line fields --- |
| 385 | note decimal l[a, b): 1 to 20 digits below 2^64, else false (and v unchanged) |
| 386 | fn sq_dec l view uchar 65536 a ulong b ulong o edit ulong 1 to bool |
| 387 | if or ge a b gt sub b a 20 |
| 388 | ret false |
| 389 | end |
| 390 | v = ulong 0 |
| 391 | for i ulong sub b a bound 20 |
| 392 | c = ulong get l add a i |
| 393 | if or lt c 48 gt c 57 |
| 394 | ret false |
| 395 | end |
| 396 | d = sub c 48 |
| 397 | if gt v 1844674407370955161 |
| 398 | ret false |
| 399 | end |
| 400 | if and eq v 1844674407370955161 gt d 5 |
| 401 | ret false |
| 402 | end |
| 403 | v = add mul v 10 d |
| 404 | end |
| 405 | put o 0 v |
| 406 | ret true |
| 407 | end |
| 408 | |
| 409 | note the program field l[a, b) into sp; false when it is not decimal tokens separated by single spaces |
| 410 | fn sq_prog l view uchar 65536 a ulong b ulong to bool |
| 411 | o = new ulong 1 0 |
| 412 | n = ulong 0 |
| 413 | s = a |
| 414 | for i ulong sub add b 1 a bound 65537 |
| 415 | p = add a i |
| 416 | if or eq p b eq get l p 32 |
| 417 | if ge n 256 |
| 418 | ret false |
| 419 | end |
| 420 | if not sq_dec l s p o |
| 421 | ret false |
| 422 | end |
| 423 | put sp n get o 0 |
| 424 | n = add n 1 |
| 425 | s = add p 1 |
| 426 | end |
| 427 | end |
| 428 | put sq_n 0 n |
| 429 | ret true |
| 430 | end |
| 431 | |
| 432 | note bytes l[a, b) against fo: the first difference, or 2^64 - 1 when they are the same |
| 433 | fn sq_cmp l view uchar 65536 a ulong b ulong to ulong |
| 434 | m = get fz 0 |
| 435 | w = sub b a |
| 436 | for i ulong m bound 65536 |
| 437 | if ge i w |
| 438 | ret i |
| 439 | end |
| 440 | if ne ulong get fo i ulong get l add a i |
| 441 | ret i |
| 442 | end |
| 443 | end |
| 444 | if ne m w |
| 445 | ret m |
| 446 | end |
| 447 | ret 18446744073709551615 |
| 448 | end |
| 449 | |
| 450 | fn sq_show l view uchar 65536 a ulong b ulong ab ulong to void |
| 451 | s = ulong 0 |
| 452 | if gt ab 60 |
| 453 | s = sub ab 60 |
| 454 | end |
| 455 | e = add s 160 |
| 456 | r = write 1 sq_want 0 len sq_want |
| 457 | we = sub b a |
| 458 | if gt e we |
| 459 | e = we |
| 460 | end |
| 461 | if lt s e |
| 462 | r = write 1 l add a s sub e s |
| 463 | end |
| 464 | r = write 1 sq_got 0 len sq_got |
| 465 | ge2 = add s 160 |
| 466 | if gt ge2 get fz 0 |
| 467 | ge2 = get fz 0 |
| 468 | end |
| 469 | if lt s ge2 |
| 470 | r = write 1 fo s sub ge2 s |
| 471 | end |
| 472 | r = write 1 sq_nl 0 len sq_nl |
| 473 | end |
| 474 | |
| 475 | fn sq_fail_line ab ulong to void |
| 476 | put sq_n 3 add get sq_n 3 1 |
| 477 | r = write 1 sq_fl 0 len sq_fl |
| 478 | sq_num get sq_n 1 |
| 479 | r = write 1 sq_at 0 len sq_at |
| 480 | sq_num ab |
| 481 | end |
| 482 | |
| 483 | fn sq_bad to void |
| 484 | put sq_n 3 add get sq_n 3 1 |
| 485 | r = write 1 sq_tbad 0 len sq_tbad |
| 486 | sq_num get sq_n 1 |
| 487 | r = write 1 sq_nl 0 len sq_nl |
| 488 | end |
| 489 | |
| 490 | fn sq_ctlmiss to void |
| 491 | put sq_n 3 add get sq_n 3 1 |
| 492 | r = write 1 sq_ctl 0 len sq_ctl |
| 493 | sq_num get sq_n 1 |
| 494 | r = write 1 sq_nl 0 len sq_nl |
| 495 | end |
| 496 | |
| 497 | note is the program l[a, b) the one of the previous case; remember it |
| 498 | fn sq_newprog l view uchar 65536 a ulong b ulong to bool |
| 499 | w = sub b a |
| 500 | same = eq w get sq_pl 0 |
| 501 | if gt w 4096 |
| 502 | ret true |
| 503 | end |
| 504 | for i ulong w bound 4096 |
| 505 | if ne get sq_prev i get l add a i |
| 506 | same = false |
| 507 | end |
| 508 | put sq_prev i get l add a i |
| 509 | end |
| 510 | put sq_pl 0 w |
| 511 | ret not same |
| 512 | end |
| 513 | |
| 514 | note the fields of line l[0, e) into sq_t (tab offsets) and sq_n 11 12 13 (K F R); false when malformed |
| 515 | fn sq_parse e ulong l view uchar 65536 to bool |
| 516 | nt = ulong 0 |
| 517 | for i ulong e bound 65536 |
| 518 | if eq get l i 9 |
| 519 | if lt nt 5 |
| 520 | put sq_t nt i |
| 521 | end |
| 522 | nt = add nt 1 |
| 523 | end |
| 524 | end |
| 525 | if ne nt 5 |
| 526 | ret false |
| 527 | end |
| 528 | if ne get sq_t 0 3 |
| 529 | ret false |
| 530 | end |
| 531 | for i ulong 3 |
| 532 | if ne get l i get sq_seq i |
| 533 | ret false |
| 534 | end |
| 535 | end |
| 536 | if not sq_prog l add get sq_t 0 1 get sq_t 1 |
| 537 | ret false |
| 538 | end |
| 539 | o = new ulong 1 0 |
| 540 | for j ulong 3 |
| 541 | if not sq_dec l add get sq_t add j 1 1 get sq_t add j 2 o |
| 542 | ret false |
| 543 | end |
| 544 | put sq_n add 11 j get o 0 |
| 545 | end |
| 546 | ret true |
| 547 | end |
| 548 | |
| 549 | note run the case and compare; true when the trace is the expected one |
| 550 | fn sq_case e ulong l view uchar 65536 to bool |
| 551 | if not sq_run get sq_n 11 get sq_n 12 get sq_n 13 |
| 552 | sq_bad |
| 553 | ret false |
| 554 | end |
| 555 | if or ne get fz 11 0 ne get fz 12 0 |
| 556 | put sq_n 3 add get sq_n 3 1 |
| 557 | w = write 1 sq_ovf 0 len sq_ovf |
| 558 | sq_num get sq_n 1 |
| 559 | w = write 1 sq_nl 0 len sq_nl |
| 560 | ret false |
| 561 | end |
| 562 | ta = add get sq_t 4 1 |
| 563 | ab = sq_cmp l ta e |
| 564 | if ne ab 18446744073709551615 |
| 565 | sq_fail_line ab |
| 566 | sq_show l ta e ab |
| 567 | ret false |
| 568 | end |
| 569 | ret true |
| 570 | end |
| 571 | |
| 572 | note the two controls of a program's first case |
| 573 | fn sq_ctls e ulong l edit uchar 65536 to void |
| 574 | ta = add get sq_t 4 1 |
| 575 | note control 1: the expected trace with one byte changed must not compare equal |
| 576 | mid = add ta div sub e ta 2 |
| 577 | keep = get l mid |
| 578 | put l mid uchar xor ulong keep 1 |
| 579 | put sq_n 4 add get sq_n 4 1 |
| 580 | if ne sq_cmp l ta e 18446744073709551615 |
| 581 | put sq_n 5 add get sq_n 5 1 |
| 582 | else |
| 583 | sq_ctlmiss |
| 584 | end |
| 585 | put l mid keep |
| 586 | note control 2: the same program with another failure script must give another trace |
| 587 | k2 = ulong 1 |
| 588 | if eq get sq_n 11 1 |
| 589 | k2 = ulong 2 |
| 590 | end |
| 591 | put sq_n 4 add get sq_n 4 1 |
| 592 | if sq_run k2 0 1 |
| 593 | if ne sq_cmp l ta e 18446744073709551615 |
| 594 | put sq_n 5 add get sq_n 5 1 |
| 595 | else |
| 596 | sq_ctlmiss |
| 597 | end |
| 598 | else |
| 599 | sq_ctlmiss |
| 600 | end |
| 601 | end |
| 602 | |
| 603 | fn sq_line e ulong l edit uchar 65536 to void |
| 604 | put sq_n 1 add get sq_n 1 1 |
| 605 | if eq e 0 |
| 606 | ret |
| 607 | end |
| 608 | if eq get l 0 35 |
| 609 | ret |
| 610 | end |
| 611 | if not sq_parse e l |
| 612 | sq_bad |
| 613 | ret |
| 614 | end |
| 615 | put sq_n 2 add get sq_n 2 1 |
| 616 | first = sq_newprog l add get sq_t 0 1 get sq_t 1 |
| 617 | if first |
| 618 | put sq_n 6 add get sq_n 6 1 |
| 619 | end |
| 620 | if not sq_case e l |
| 621 | ret |
| 622 | end |
| 623 | if first |
| 624 | sq_ctls e l |
| 625 | end |
| 626 | end |
| 627 | |
| 628 | fn sq_gsize fd int to ulong |
| 629 | if ne fstat fd sq_st 0 128 0 |
| 630 | ret 0 |
| 631 | end |
| 632 | size = ulong 0 |
| 633 | for j ulong 8 |
| 634 | size = or size shl ulong get sq_st add 48 j mul j 8 |
| 635 | end |
| 636 | ret size |
| 637 | end |
| 638 | |
| 639 | fn sq_open to long |
| 640 | if ne argcnt 2 |
| 641 | r = write 2 sq_use 0 len sq_use |
| 642 | ret 0 |
| 643 | end |
| 644 | pl = argread 1 sq_p 0 4095 |
| 645 | if lt pl 1 |
| 646 | r = write 2 sq_use 0 len sq_use |
| 647 | ret 0 |
| 648 | end |
| 649 | fd = int fopen sq_p 0 ulong pl 524288 0 |
| 650 | if lt fd 0 |
| 651 | r = write 2 sq_topen 0 len sq_topen |
| 652 | ret 0 |
| 653 | end |
| 654 | size = sq_gsize fd |
| 655 | put sq_n 7 ulong fd |
| 656 | put sq_n 8 size |
| 657 | h = long 0 |
| 658 | if gt size 0 |
| 659 | h = mapnew fd 0 size 1 2 |
| 660 | end |
| 661 | if le h 0 |
| 662 | r = write 2 sq_topen 0 len sq_topen |
| 663 | ret 0 |
| 664 | end |
| 665 | ret h |
| 666 | end |
| 667 | |
| 668 | fn sq_eol k ulong l view uchar 65536 to ulong |
| 669 | for i ulong k bound 65536 |
| 670 | if eq get l i 10 |
| 671 | ret i |
| 672 | end |
| 673 | end |
| 674 | ret k |
| 675 | end |
| 676 | |
| 677 | fn sq_summary to int |
| 678 | r = write 1 sq_sum 0 len sq_sum |
| 679 | pass = and eq get sq_n 3 0 gt get sq_n 2 0 |
| 680 | pass = and pass eq get sq_n 4 get sq_n 5 |
| 681 | pass = and pass eq get sq_n 4 mul 2 get sq_n 6 |
| 682 | if pass |
| 683 | r = write 1 sq_pass 0 len sq_pass |
| 684 | else |
| 685 | r = write 1 sq_fail 0 len sq_fail |
| 686 | end |
| 687 | r = write 1 sq_cs 0 len sq_cs |
| 688 | sq_num get sq_n 2 |
| 689 | r = write 1 sq_ps 0 len sq_ps |
| 690 | sq_num get sq_n 6 |
| 691 | r = write 1 sq_co 0 len sq_co |
| 692 | sq_num get sq_n 4 |
| 693 | r = write 1 sq_ca 0 len sq_ca |
| 694 | sq_num get sq_n 5 |
| 695 | r = write 1 sq_hw 0 len sq_hw |
| 696 | if pass |
| 697 | ret 0 |
| 698 | end |
| 699 | ret 1 |
| 700 | end |
| 701 | |
| 702 | fn main to int |
| 703 | l = new uchar 65536 0 |
| 704 | h = sq_open |
| 705 | if le h 0 |
| 706 | ret 2 |
| 707 | end |
| 708 | size = get sq_n 8 |
| 709 | pos = ulong 0 |
| 710 | while lt pos size bound 9223372036854775807 |
| 711 | k = sub size pos |
| 712 | if gt k 65536 |
| 713 | k = ulong 65536 |
| 714 | end |
| 715 | if ne mapread h pos l 0 k long k |
| 716 | r = write 2 sq_topen 0 len sq_topen |
| 717 | ret 2 |
| 718 | end |
| 719 | e = sq_eol k l |
| 720 | if and eq e k eq k 65536 |
| 721 | r = write 2 sq_long 0 len sq_long |
| 722 | ret 2 |
| 723 | end |
| 724 | sq_line e l |
| 725 | pos = add pos add e 1 |
| 726 | end |
| 727 | r = mapdrop h |
| 728 | q = fclose int get sq_n 7 |
| 729 | ret sq_summary |
| 730 | end |