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 / tests / model / model_check.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: Apache-2.0 |
| 3 | note Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | note |
| 5 | note tests/model/model_check.om -- exhaustive check of the World lifecycle model (lane LG). |
| 6 | note Pure seeded OM-2 port of tests/model/{world_model,world_explore,model_check}.c. |
| 7 | |
| 8 | const MC_CAP ulong 65536 |
| 9 | const MC_TSZ ulong 131072 |
| 10 | const MC_TMASK ulong 131071 |
| 11 | |
| 12 | note Compact WmState layout (64 bytes per state): |
| 13 | note 0..3 st[0..3] |
| 14 | note 4..7 rearm[0..3] |
| 15 | note 8..11 stale[0..3] |
| 16 | note 12..15 parked[0..3] |
| 17 | note 16..19 yield[0..3] |
| 18 | note 20..23 surfaced[0..3] |
| 19 | note 24..27 act_committed[0..3] |
| 20 | note 28 ext |
| 21 | note 29 tick |
| 22 | note 30 used_slots |
| 23 | note 31 in_flight |
| 24 | note 32..35 used_mem (u32 LE) |
| 25 | note 36..51 wait_seq[0..3] (4 x u32 LE) |
| 26 | note 52..55 seq (u32 LE) |
| 27 | |
| 28 | global g_states uchar 4194304 |
| 29 | global g_keys uchar 2621440 |
| 30 | global g_parent uint 65536 |
| 31 | global g_op_kind uchar 65536 |
| 32 | global g_op_r uchar 65536 |
| 33 | global g_table uint 131072 |
| 34 | |
| 35 | global g_cur uchar 64 |
| 36 | global g_keybuf uchar 40 |
| 37 | global g_ops_k uchar 16 |
| 38 | global g_ops_r uchar 16 |
| 39 | |
| 40 | global g_res_u64 ulong 2 |
| 41 | global g_res_u32 uint 2 |
| 42 | global g_tlen int 5 |
| 43 | global g_tk uchar 320 |
| 44 | global g_tr uchar 320 |
| 45 | global g_rev_k uchar 64 |
| 46 | global g_rev_r uchar 64 |
| 47 | global g_prof int 4 |
| 48 | |
| 49 | global g_obuf uchar 65536 |
| 50 | global g_olen ulong 1 |
| 51 | global g_bad int 1 |
| 52 | global g_tmpd uchar 24 |
| 53 | global g_kids uchar 4 |
| 54 | |
| 55 | text t_star "[*] " |
| 56 | text t_lp " (" |
| 57 | text t_rp_c "): " |
| 58 | text t_st " states, " |
| 59 | text t_tr " transitions" |
| 60 | text t_trunc " TRUNCATED (not exhaustive)" |
| 61 | text t_res "RESULT model." |
| 62 | text t_dot_st ".states=" |
| 63 | text t_dot_tr ".transitions=" |
| 64 | text t_dot_ex ".exhaustive=" |
| 65 | text t_yes "YES\n" |
| 66 | text t_no "NO\n" |
| 67 | text t_eq_fail "=FAIL\n" |
| 68 | text t_eq_pass "=PASS\n" |
| 69 | text t_eq_killed "=KILLED\n" |
| 70 | text t_eq_kf "=KNOWN_FAIL\n" |
| 71 | text t_eq_surv "=SURVIVED\n" |
| 72 | text t_eq_upass "=UNEXPECTED_PASS\n" |
| 73 | text t_eq_viol "=violated\n" |
| 74 | text t_eq_held "=held\n" |
| 75 | text t_b0 "I1_no_budget_leak" |
| 76 | text t_b1 "I2_cancel_reaches_children" |
| 77 | text t_b2 "I3_no_double_commit" |
| 78 | text t_b3 "I4_deadline_overrun_surfaced" |
| 79 | text t_b4 "I2b_cancel_reaches_target" |
| 80 | text t_sp2 " " |
| 81 | text t_ce1 " counterexample (" |
| 82 | text t_ce2 " steps): " |
| 83 | text t_arr " -> " |
| 84 | text t_unexp "UNEXPECTED" |
| 85 | text t_kby "killed by" |
| 86 | text t_find "FINDING" |
| 87 | text t_ext "EXT" |
| 88 | text t_tick "TICK" |
| 89 | text t_fin "FIN(" |
| 90 | text t_fail "FAIL(" |
| 91 | text t_can "CANCEL(" |
| 92 | text t_p "P" |
| 93 | text t_c1 "C1" |
| 94 | text t_c2 "C2" |
| 95 | text t_g "G" |
| 96 | text t_p_spec "SPEC" |
| 97 | text t_p_ab "AS_BUILT" |
| 98 | text t_p_leak "MUT_LEAK_ON_FAIL" |
| 99 | text t_p_noprop "MUT_CANCEL_NO_PROPAGATE" |
| 100 | text t_p_dbl "MUT_COMMIT_KEEPS_ACTIVATION" |
| 101 | text t_p_dl "MUT_DEADLINE_ADMIT_ONLY" |
| 102 | text t_r_spec "spec" |
| 103 | text t_r_ab "as-built" |
| 104 | text t_r_mut "mutant" |
| 105 | text t_verd "RESULT model.verdict=" |
| 106 | text t_pass_nl "PASS\n" |
| 107 | text t_fail_nl "FAIL\n" |
| 108 | text t_mc_p "MODEL CHECK: PASS (" |
| 109 | text t_mc_f "MODEL CHECK: FAIL (" |
| 110 | text t_mc_e " unexpected)\n" |
| 111 | |
| 112 | fn out_flush to void |
| 113 | n = get g_olen 0 |
| 114 | if gt n 0 |
| 115 | ign = write 1 g_obuf 0 n |
| 116 | put g_olen 0 0 |
| 117 | end |
| 118 | end |
| 119 | |
| 120 | fn out_c c uchar to void |
| 121 | n = get g_olen 0 |
| 122 | if ge n 65535 |
| 123 | out_flush |
| 124 | n = ulong 0 |
| 125 | end |
| 126 | put g_obuf n c |
| 127 | put g_olen 0 add n 1 |
| 128 | end |
| 129 | |
| 130 | fn out_t s view uchar * n ulong to void |
| 131 | for i ulong n |
| 132 | out_c get s i |
| 133 | end |
| 134 | end |
| 135 | |
| 136 | fn out_u64 v ulong to void |
| 137 | if eq v 0 |
| 138 | out_c uchar 48 |
| 139 | ret |
| 140 | end |
| 141 | n = ulong 0 |
| 142 | x = v |
| 143 | while gt x 0 |
| 144 | d = rem x 10 |
| 145 | put g_tmpd n uchar add 48 d |
| 146 | n = add n 1 |
| 147 | x = div x 10 |
| 148 | end |
| 149 | while gt n 0 |
| 150 | n = sub n 1 |
| 151 | out_c get g_tmpd n |
| 152 | end |
| 153 | end |
| 154 | |
| 155 | fn out_int v int to void |
| 156 | if lt v 0 |
| 157 | out_c uchar 45 |
| 158 | out_u64 ulong sub 0 v |
| 159 | else |
| 160 | out_u64 ulong v |
| 161 | end |
| 162 | end |
| 163 | |
| 164 | fn ld_u32_cur off ulong to uint |
| 165 | b0 = uint get g_cur off |
| 166 | b1 = uint get g_cur add off 1 |
| 167 | b2 = uint get g_cur add off 2 |
| 168 | b3 = uint get g_cur add off 3 |
| 169 | r0 = or b0 shl b1 8 |
| 170 | r1 = or shl b2 16 shl b3 24 |
| 171 | ret or r0 r1 |
| 172 | end |
| 173 | |
| 174 | fn st_u32_cur off ulong v uint to void |
| 175 | put g_cur off uchar and v 255 |
| 176 | put g_cur add off 1 uchar and shr v 8 255 |
| 177 | put g_cur add off 2 uchar and shr v 16 255 |
| 178 | put g_cur add off 3 uchar and shr v 24 255 |
| 179 | end |
| 180 | |
| 181 | fn wm_parent r uint to int |
| 182 | if eq r 0 |
| 183 | ret -1 |
| 184 | end |
| 185 | if eq r 1 |
| 186 | ret 0 |
| 187 | end |
| 188 | if eq r 2 |
| 189 | ret 0 |
| 190 | end |
| 191 | ret 1 |
| 192 | end |
| 193 | |
| 194 | fn wm_mem r uint to uint |
| 195 | if eq r 0 |
| 196 | ret 4 |
| 197 | end |
| 198 | if eq r 1 |
| 199 | ret 4 |
| 200 | end |
| 201 | ret 2 |
| 202 | end |
| 203 | |
| 204 | fn wm_deadline r uint to uint |
| 205 | if eq r 0 |
| 206 | ret 1 |
| 207 | end |
| 208 | if eq r 1 |
| 209 | ret 2 |
| 210 | end |
| 211 | if eq r 2 |
| 212 | ret 0 |
| 213 | end |
| 214 | ret 1 |
| 215 | end |
| 216 | |
| 217 | fn wm_is_desc d uint r uint to int |
| 218 | a = wm_parent d |
| 219 | while ge a 0 |
| 220 | if eq uint a r |
| 221 | ret 1 |
| 222 | end |
| 223 | a = wm_parent uint a |
| 224 | end |
| 225 | ret 0 |
| 226 | end |
| 227 | |
| 228 | fn cur_zero to void |
| 229 | for i ulong 64 |
| 230 | put g_cur i uchar 0 |
| 231 | end |
| 232 | end |
| 233 | |
| 234 | fn copy_node_to_cur idx ulong to void |
| 235 | base = shl idx 6 |
| 236 | for i ulong 64 |
| 237 | put g_cur i get g_states add base i |
| 238 | end |
| 239 | end |
| 240 | |
| 241 | fn copy_cur_to_node idx ulong to void |
| 242 | base = shl idx 6 |
| 243 | for i ulong 64 |
| 244 | put g_states add base i get g_cur i |
| 245 | end |
| 246 | end |
| 247 | |
| 248 | fn cur_fits r uint to int |
| 249 | us = uint get g_cur 30 |
| 250 | if ge us 2 |
| 251 | ret 0 |
| 252 | end |
| 253 | um = ld_u32_cur 32 |
| 254 | if gt um 8 |
| 255 | ret 0 |
| 256 | end |
| 257 | need = wm_mem r |
| 258 | if gt need sub 8 um |
| 259 | ret 0 |
| 260 | end |
| 261 | ret 1 |
| 262 | end |
| 263 | |
| 264 | fn cur_admit r uint to void |
| 265 | ru = ulong r |
| 266 | put g_cur ru uchar 2 |
| 267 | put g_cur 30 uchar add uint get g_cur 30 1 |
| 268 | um = ld_u32_cur 32 |
| 269 | st_u32_cur 32 add um wm_mem r |
| 270 | put g_cur 31 uchar add uint get g_cur 31 1 |
| 271 | put g_cur add 8 ru uchar 0 |
| 272 | put g_cur add 24 ru uchar 0 |
| 273 | put g_cur add 20 ru uchar 0 |
| 274 | dl = wm_deadline r |
| 275 | tk = uint get g_cur 29 |
| 276 | if ne dl 0 |
| 277 | if gt tk dl |
| 278 | put g_cur add 20 ru uchar 1 |
| 279 | end |
| 280 | end |
| 281 | end |
| 282 | |
| 283 | fn cur_try_admit to void |
| 284 | cont = int 1 |
| 285 | while ne cont 0 |
| 286 | best = sub int 0 1 |
| 287 | best_seq = uint 0 |
| 288 | r = uint 0 |
| 289 | while lt r 4 |
| 290 | st = uint get g_cur ulong r |
| 291 | if eq st 1 |
| 292 | f = cur_fits r |
| 293 | if ne f 0 |
| 294 | ws = ld_u32_cur add 36 shl ulong r 2 |
| 295 | if lt best 0 |
| 296 | best = int r |
| 297 | best_seq = ws |
| 298 | else |
| 299 | if lt ws best_seq |
| 300 | best = int r |
| 301 | best_seq = ws |
| 302 | end |
| 303 | end |
| 304 | end |
| 305 | end |
| 306 | r = add r 1 |
| 307 | end |
| 308 | if lt best 0 |
| 309 | cont = int 0 |
| 310 | else |
| 311 | cur_admit uint best |
| 312 | end |
| 313 | end |
| 314 | end |
| 315 | |
| 316 | fn cur_demand r uint external int to void |
| 317 | ru = ulong r |
| 318 | if ne external 0 |
| 319 | put g_cur add 16 ru uchar 0 |
| 320 | end |
| 321 | put g_cur add 12 ru uchar 0 |
| 322 | st = uint get g_cur ru |
| 323 | if eq st 0 |
| 324 | put g_cur ru uchar 1 |
| 325 | sq = add ld_u32_cur 52 1 |
| 326 | st_u32_cur 52 sq |
| 327 | st_u32_cur add 36 shl ru 2 sq |
| 328 | cur_try_admit |
| 329 | else |
| 330 | if ne st 1 |
| 331 | put g_cur add 4 ru uchar 1 |
| 332 | end |
| 333 | end |
| 334 | end |
| 335 | |
| 336 | fn cur_others_busy self_r uint to int |
| 337 | i = uint 0 |
| 338 | while lt i 4 |
| 339 | if ne i self_r |
| 340 | st = uint get g_cur ulong i |
| 341 | if eq st 1 |
| 342 | ret 1 |
| 343 | end |
| 344 | if eq st 2 |
| 345 | ret 1 |
| 346 | end |
| 347 | end |
| 348 | i = add i 1 |
| 349 | end |
| 350 | ret 0 |
| 351 | end |
| 352 | |
| 353 | fn cur_release_parked to void |
| 354 | i = uint 0 |
| 355 | while lt i 4 |
| 356 | iu = ulong i |
| 357 | if ne uint get g_cur add 12 iu 0 |
| 358 | yd = uint get g_cur add 16 iu |
| 359 | skip = int 0 |
| 360 | if ne yd 0 |
| 361 | if ne cur_others_busy i 0 |
| 362 | skip = int 1 |
| 363 | end |
| 364 | end |
| 365 | if eq skip 0 |
| 366 | put g_cur add 12 iu uchar 0 |
| 367 | put g_cur add 16 iu uchar 0 |
| 368 | ext = int 0 |
| 369 | if eq i 0 |
| 370 | ext = int 1 |
| 371 | end |
| 372 | cur_demand i ext |
| 373 | end |
| 374 | end |
| 375 | i = add i 1 |
| 376 | end |
| 377 | end |
| 378 | |
| 379 | fn wm_backoff y uint to uint |
| 380 | n = uint 1 |
| 381 | if ne y 0 |
| 382 | n = shl y 1 |
| 383 | end |
| 384 | if gt n 8 |
| 385 | n = uint 8 |
| 386 | end |
| 387 | ret n |
| 388 | end |
| 389 | |
| 390 | fn cur_uncharge r uint to void |
| 391 | us = uint get g_cur 30 |
| 392 | if ne us 0 |
| 393 | put g_cur 30 uchar sub us 1 |
| 394 | end |
| 395 | um = ld_u32_cur 32 |
| 396 | need = wm_mem r |
| 397 | if ge um need |
| 398 | st_u32_cur 32 sub um need |
| 399 | else |
| 400 | st_u32_cur 32 0 |
| 401 | end |
| 402 | end |
| 403 | |
| 404 | fn cur_end_act r uint failed int to void |
| 405 | i = uint 0 |
| 406 | while lt i 4 |
| 407 | iu = ulong i |
| 408 | if ne uint get g_cur add 12 iu 0 |
| 409 | yd = uint get g_cur add 16 iu |
| 410 | if ne yd 0 |
| 411 | put g_cur add 16 iu uchar sub yd 1 |
| 412 | end |
| 413 | end |
| 414 | i = add i 1 |
| 415 | end |
| 416 | cur_release_parked |
| 417 | do_u = int 1 |
| 418 | if ne failed 0 |
| 419 | if ne get g_prof 2 0 |
| 420 | do_u = int 0 |
| 421 | end |
| 422 | end |
| 423 | if ne do_u 0 |
| 424 | cur_uncharge r |
| 425 | end |
| 426 | ru = ulong r |
| 427 | put g_cur ru uchar 0 |
| 428 | inf = uint get g_cur 31 |
| 429 | if ne inf 0 |
| 430 | put g_cur 31 uchar sub inf 1 |
| 431 | end |
| 432 | ra = uint get g_cur add 4 ru |
| 433 | yd2 = uint get g_cur add 16 ru |
| 434 | if ne ra 0 |
| 435 | ob = int 0 |
| 436 | if ne yd2 0 |
| 437 | ob = cur_others_busy r |
| 438 | end |
| 439 | if ne ob 0 |
| 440 | put g_cur add 16 ru uchar sub yd2 1 |
| 441 | put g_cur add 12 ru uchar 1 |
| 442 | put g_cur add 4 ru uchar 0 |
| 443 | cur_try_admit |
| 444 | else |
| 445 | put g_cur add 4 ru uchar 0 |
| 446 | ext = int 0 |
| 447 | if eq r 0 |
| 448 | ext = int 1 |
| 449 | end |
| 450 | cur_demand r ext |
| 451 | end |
| 452 | else |
| 453 | cur_try_admit |
| 454 | end |
| 455 | if eq uint get g_cur 31 0 |
| 456 | cur_release_parked |
| 457 | end |
| 458 | end |
| 459 | |
| 460 | fn cur_write_wake writer int to void |
| 461 | nk = ulong 0 |
| 462 | c = uint 0 |
| 463 | while lt c 4 |
| 464 | if eq wm_parent c writer |
| 465 | put g_kids nk uchar c |
| 466 | nk = add nk 1 |
| 467 | end |
| 468 | c = add c 1 |
| 469 | end |
| 470 | i = ulong 0 |
| 471 | while lt i nk |
| 472 | k = ulong get g_kids i |
| 473 | if eq uint get g_cur k 2 |
| 474 | put g_cur add 8 k uchar 1 |
| 475 | end |
| 476 | i = add i 1 |
| 477 | end |
| 478 | ext = int 0 |
| 479 | if lt writer 0 |
| 480 | ext = int 1 |
| 481 | end |
| 482 | i = ulong 0 |
| 483 | while lt i nk |
| 484 | k2 = uint get g_kids i |
| 485 | cur_demand k2 ext |
| 486 | i = add i 1 |
| 487 | end |
| 488 | end |
| 489 | |
| 490 | fn cur_cancel r uint to void |
| 491 | cm = get g_prof 0 |
| 492 | if eq cm 0 |
| 493 | ret |
| 494 | end |
| 495 | x = uint 0 |
| 496 | while lt x 4 |
| 497 | hit = int 0 |
| 498 | if eq x r |
| 499 | hit = int 1 |
| 500 | else |
| 501 | if eq cm 1 |
| 502 | if ne wm_is_desc x r 0 |
| 503 | hit = int 1 |
| 504 | end |
| 505 | end |
| 506 | end |
| 507 | if ne hit 0 |
| 508 | xu = ulong x |
| 509 | if eq uint get g_cur xu 2 |
| 510 | cur_uncharge x |
| 511 | inf = uint get g_cur 31 |
| 512 | if ne inf 0 |
| 513 | put g_cur 31 uchar sub inf 1 |
| 514 | end |
| 515 | end |
| 516 | put g_cur xu uchar 0 |
| 517 | put g_cur add 4 xu uchar 0 |
| 518 | put g_cur add 12 xu uchar 0 |
| 519 | put g_cur add 16 xu uchar 0 |
| 520 | put g_cur add 8 xu uchar 0 |
| 521 | end |
| 522 | x = add x 1 |
| 523 | end |
| 524 | cur_try_admit |
| 525 | if eq uint get g_cur 31 0 |
| 526 | cur_release_parked |
| 527 | end |
| 528 | end |
| 529 | |
| 530 | fn node_enabled idx ulong kind uint r uint to int |
| 531 | base = shl idx 6 |
| 532 | if eq kind 0 |
| 533 | if lt uint get g_states add base 28 3 |
| 534 | ret 1 |
| 535 | end |
| 536 | ret 0 |
| 537 | end |
| 538 | if eq kind 1 |
| 539 | if lt r 4 |
| 540 | if eq uint get g_states add base ulong r 2 |
| 541 | ret 1 |
| 542 | end |
| 543 | end |
| 544 | ret 0 |
| 545 | end |
| 546 | if eq kind 2 |
| 547 | if lt r 4 |
| 548 | if eq uint get g_states add base ulong r 2 |
| 549 | ret 1 |
| 550 | end |
| 551 | end |
| 552 | ret 0 |
| 553 | end |
| 554 | if eq kind 3 |
| 555 | if lt uint get g_states add base 29 3 |
| 556 | ret 1 |
| 557 | end |
| 558 | ret 0 |
| 559 | end |
| 560 | if eq kind 4 |
| 561 | if eq r 0 |
| 562 | ret 1 |
| 563 | end |
| 564 | if eq r 1 |
| 565 | ret 1 |
| 566 | end |
| 567 | ret 0 |
| 568 | end |
| 569 | ret 0 |
| 570 | end |
| 571 | |
| 572 | fn cur_check to uint |
| 573 | v = uint 0 |
| 574 | n_run = uint 0 |
| 575 | mem = uint 0 |
| 576 | r = uint 0 |
| 577 | while lt r 4 |
| 578 | if eq uint get g_cur ulong r 2 |
| 579 | n_run = add n_run 1 |
| 580 | mem = add mem wm_mem r |
| 581 | end |
| 582 | r = add r 1 |
| 583 | end |
| 584 | us = uint get g_cur 30 |
| 585 | um = ld_u32_cur 32 |
| 586 | leak = int 0 |
| 587 | if ne us n_run |
| 588 | leak = int 1 |
| 589 | end |
| 590 | if ne um mem |
| 591 | leak = int 1 |
| 592 | end |
| 593 | if gt us 2 |
| 594 | leak = int 1 |
| 595 | end |
| 596 | if gt um 8 |
| 597 | leak = int 1 |
| 598 | end |
| 599 | if ne leak 0 |
| 600 | v = or v 1 |
| 601 | end |
| 602 | tk = uint get g_cur 29 |
| 603 | r = uint 0 |
| 604 | while lt r 4 |
| 605 | ru = ulong r |
| 606 | if eq uint get g_cur ru 2 |
| 607 | dl = wm_deadline r |
| 608 | if ne dl 0 |
| 609 | if gt tk dl |
| 610 | if eq uint get g_cur add 20 ru 0 |
| 611 | v = or v 8 |
| 612 | end |
| 613 | end |
| 614 | end |
| 615 | end |
| 616 | r = add r 1 |
| 617 | end |
| 618 | ret v |
| 619 | end |
| 620 | |
| 621 | fn cur_step_fin r uint to uint |
| 622 | v = uint 0 |
| 623 | ru = ulong r |
| 624 | dl = wm_deadline r |
| 625 | tk = uint get g_cur 29 |
| 626 | if ne dl 0 |
| 627 | if gt tk dl |
| 628 | put g_cur ru uchar 3 |
| 629 | cur_end_act r 0 |
| 630 | ret v |
| 631 | end |
| 632 | end |
| 633 | if ne uint get g_cur add 8 ru 0 |
| 634 | yd = uint get g_cur add 16 ru |
| 635 | put g_cur add 16 ru uchar wm_backoff yd |
| 636 | put g_cur add 4 ru uchar 1 |
| 637 | put g_cur ru uchar 3 |
| 638 | cur_end_act r 0 |
| 639 | ret v |
| 640 | end |
| 641 | if ne uint get g_cur add 24 ru 0 |
| 642 | v = or v 4 |
| 643 | end |
| 644 | put g_cur add 24 ru uchar 1 |
| 645 | put g_cur add 16 ru uchar 0 |
| 646 | put g_cur ru uchar 3 |
| 647 | cur_write_wake int r |
| 648 | if ne get g_prof 3 0 |
| 649 | if eq uint get g_cur add 4 ru 0 |
| 650 | put g_cur ru uchar 2 |
| 651 | ret v |
| 652 | end |
| 653 | end |
| 654 | cur_end_act r 0 |
| 655 | ret v |
| 656 | end |
| 657 | |
| 658 | fn cur_step_cancel r uint to uint |
| 659 | v = uint 0 |
| 660 | cur_cancel r |
| 661 | ru = ulong r |
| 662 | if ne uint get g_cur ru 0 |
| 663 | v = or v 16 |
| 664 | end |
| 665 | if ne uint get g_cur add 4 ru 0 |
| 666 | v = or v 16 |
| 667 | end |
| 668 | if ne uint get g_cur add 12 ru 0 |
| 669 | v = or v 16 |
| 670 | end |
| 671 | x = uint 0 |
| 672 | while lt x 4 |
| 673 | if ne wm_is_desc x r 0 |
| 674 | xu = ulong x |
| 675 | badc = int 0 |
| 676 | if ne uint get g_cur xu 0 |
| 677 | badc = int 1 |
| 678 | end |
| 679 | if ne uint get g_cur add 4 xu 0 |
| 680 | badc = int 1 |
| 681 | end |
| 682 | if ne uint get g_cur add 12 xu 0 |
| 683 | badc = int 1 |
| 684 | end |
| 685 | if ne badc 0 |
| 686 | v = or v 2 |
| 687 | end |
| 688 | end |
| 689 | x = add x 1 |
| 690 | end |
| 691 | ret v |
| 692 | end |
| 693 | |
| 694 | fn cur_step_tick to void |
| 695 | tk = add uint get g_cur 29 1 |
| 696 | put g_cur 29 uchar tk |
| 697 | if ne get g_prof 1 0 |
| 698 | i = uint 0 |
| 699 | while lt i 4 |
| 700 | iu = ulong i |
| 701 | if eq uint get g_cur iu 2 |
| 702 | dl = wm_deadline i |
| 703 | if ne dl 0 |
| 704 | if gt tk dl |
| 705 | if eq uint get g_cur add 20 iu 0 |
| 706 | put g_cur add 20 iu uchar 1 |
| 707 | end |
| 708 | end |
| 709 | end |
| 710 | end |
| 711 | i = add i 1 |
| 712 | end |
| 713 | end |
| 714 | cur_try_admit |
| 715 | end |
| 716 | |
| 717 | fn cur_step kind uint r uint to uint |
| 718 | v = uint 0 |
| 719 | if eq kind 0 |
| 720 | put g_cur 28 uchar add uint get g_cur 28 1 |
| 721 | cur_write_wake -1 |
| 722 | else |
| 723 | if eq kind 3 |
| 724 | cur_step_tick |
| 725 | else |
| 726 | if eq kind 2 |
| 727 | put g_cur ulong r uchar 3 |
| 728 | cur_end_act r 1 |
| 729 | else |
| 730 | if eq kind 1 |
| 731 | v = cur_step_fin r |
| 732 | else |
| 733 | if eq kind 4 |
| 734 | v = cur_step_cancel r |
| 735 | end |
| 736 | end |
| 737 | end |
| 738 | end |
| 739 | end |
| 740 | cv = cur_check |
| 741 | ret or v cv |
| 742 | end |
| 743 | |
| 744 | fn cur_make_key to void |
| 745 | n = ulong 0 |
| 746 | r = uint 0 |
| 747 | while lt r 4 |
| 748 | ru = ulong r |
| 749 | rank = uint 0 |
| 750 | st = uint get g_cur ru |
| 751 | if eq st 1 |
| 752 | wr = ld_u32_cur add 36 shl ru 2 |
| 753 | q = uint 0 |
| 754 | while lt q 4 |
| 755 | qu = ulong q |
| 756 | if eq uint get g_cur qu 1 |
| 757 | wq = ld_u32_cur add 36 shl qu 2 |
| 758 | if le wq wr |
| 759 | rank = add rank 1 |
| 760 | end |
| 761 | end |
| 762 | q = add q 1 |
| 763 | end |
| 764 | end |
| 765 | put g_keybuf n uchar st |
| 766 | put g_keybuf add n 1 get g_cur add 4 ru |
| 767 | put g_keybuf add n 2 get g_cur add 8 ru |
| 768 | put g_keybuf add n 3 get g_cur add 12 ru |
| 769 | put g_keybuf add n 4 get g_cur add 16 ru |
| 770 | put g_keybuf add n 5 get g_cur add 20 ru |
| 771 | put g_keybuf add n 6 get g_cur add 24 ru |
| 772 | put g_keybuf add n 7 uchar rank |
| 773 | n = add n 8 |
| 774 | r = add r 1 |
| 775 | end |
| 776 | put g_keybuf 32 get g_cur 28 |
| 777 | put g_keybuf 33 get g_cur 29 |
| 778 | put g_keybuf 34 get g_cur 30 |
| 779 | um = ld_u32_cur 32 |
| 780 | put g_keybuf 35 uchar and um 255 |
| 781 | put g_keybuf 36 get g_cur 31 |
| 782 | end |
| 783 | |
| 784 | fn fnv_keybuf to ulong |
| 785 | h = ulong 1469598103934665603 |
| 786 | for i ulong 37 |
| 787 | b = ulong get g_keybuf i |
| 788 | h = xor h b |
| 789 | h = mul h 1099511628211 |
| 790 | end |
| 791 | ret h |
| 792 | end |
| 793 | |
| 794 | fn key_eq_node idx ulong to int |
| 795 | base = mul idx 40 |
| 796 | for i ulong 37 |
| 797 | if ne get g_keys add base i get g_keybuf i |
| 798 | ret 0 |
| 799 | end |
| 800 | end |
| 801 | ret 1 |
| 802 | end |
| 803 | |
| 804 | fn copy_keybuf_to_node idx ulong to void |
| 805 | base = mul idx 40 |
| 806 | for i ulong 37 |
| 807 | put g_keys add base i get g_keybuf i |
| 808 | end |
| 809 | end |
| 810 | |
| 811 | fn init_ops to int |
| 812 | put g_ops_k 0 uchar 0 |
| 813 | put g_ops_r 0 uchar 0 |
| 814 | put g_ops_k 1 uchar 3 |
| 815 | put g_ops_r 1 uchar 0 |
| 816 | n = int 2 |
| 817 | r = uint 0 |
| 818 | while lt r 4 |
| 819 | put g_ops_k ulong n uchar 1 |
| 820 | put g_ops_r ulong n uchar r |
| 821 | n = add n 1 |
| 822 | r = add r 1 |
| 823 | end |
| 824 | r = uint 0 |
| 825 | while lt r 4 |
| 826 | put g_ops_k ulong n uchar 2 |
| 827 | put g_ops_r ulong n uchar r |
| 828 | n = add n 1 |
| 829 | r = add r 1 |
| 830 | end |
| 831 | put g_ops_k ulong n uchar 4 |
| 832 | put g_ops_r ulong n uchar 0 |
| 833 | n = add n 1 |
| 834 | put g_ops_k ulong n uchar 4 |
| 835 | put g_ops_r ulong n uchar 1 |
| 836 | n = add n 1 |
| 837 | ret n |
| 838 | end |
| 839 | |
| 840 | fn record_trace bit int head ulong opk uchar opr uchar to void |
| 841 | rn = int 0 |
| 842 | idx = head |
| 843 | while ne idx 0 |
| 844 | if lt rn 64 |
| 845 | put g_rev_k ulong rn get g_op_kind idx |
| 846 | put g_rev_r ulong rn get g_op_r idx |
| 847 | rn = add rn 1 |
| 848 | idx = ulong get g_parent idx |
| 849 | else |
| 850 | idx = ulong 0 |
| 851 | end |
| 852 | end |
| 853 | tbase = mul ulong bit 64 |
| 854 | i = int 0 |
| 855 | while lt i rn |
| 856 | src = ulong sub sub rn 1 i |
| 857 | put g_tk add tbase ulong i get g_rev_k src |
| 858 | put g_tr add tbase ulong i get g_rev_r src |
| 859 | i = add i 1 |
| 860 | end |
| 861 | if lt rn 64 |
| 862 | put g_tk add tbase ulong rn opk |
| 863 | put g_tr add tbase ulong rn opr |
| 864 | rn = add rn 1 |
| 865 | end |
| 866 | put g_tlen ulong bit rn |
| 867 | end |
| 868 | |
| 869 | fn record_viols v uint head ulong opk uchar opr uchar to void |
| 870 | vs = get g_res_u32 0 |
| 871 | put g_res_u32 0 or vs v |
| 872 | b = int 0 |
| 873 | while lt b 5 |
| 874 | mask = shl uint 1 uint b |
| 875 | if ne and v mask 0 |
| 876 | tl = get g_tlen ulong b |
| 877 | if lt tl 0 |
| 878 | record_trace b head opk opr |
| 879 | end |
| 880 | end |
| 881 | b = add b 1 |
| 882 | end |
| 883 | end |
| 884 | |
| 885 | fn table_clear to void |
| 886 | for i ulong MC_TSZ |
| 887 | put g_table i uint 0xffffffff |
| 888 | end |
| 889 | end |
| 890 | |
| 891 | fn table_probe to ulong |
| 892 | h = fnv_keybuf |
| 893 | slot = and h MC_TMASK |
| 894 | cont = int 1 |
| 895 | while ne cont 0 |
| 896 | ent = get g_table slot |
| 897 | if eq ent 0xffffffff |
| 898 | ret slot |
| 899 | end |
| 900 | if ne key_eq_node ulong ent 0 |
| 901 | ret 0xffffffff |
| 902 | end |
| 903 | slot = and add slot 1 MC_TMASK |
| 904 | end |
| 905 | ret 0xffffffff |
| 906 | end |
| 907 | |
| 908 | fn wx_explore to void |
| 909 | put g_res_u64 0 0 |
| 910 | put g_res_u64 1 0 |
| 911 | put g_res_u32 0 0 |
| 912 | put g_res_u32 1 0 |
| 913 | for i ulong 5 |
| 914 | put g_tlen i -1 |
| 915 | end |
| 916 | table_clear |
| 917 | cur_zero |
| 918 | copy_cur_to_node 0 |
| 919 | cur_make_key |
| 920 | copy_keybuf_to_node 0 |
| 921 | h0 = fnv_keybuf |
| 922 | put g_table and h0 MC_TMASK uint 0 |
| 923 | n = ulong 1 |
| 924 | nops = init_ops |
| 925 | head = ulong 0 |
| 926 | while lt head n |
| 927 | o = int 0 |
| 928 | while lt o nops |
| 929 | opk = get g_ops_k ulong o |
| 930 | opr = get g_ops_r ulong o |
| 931 | if ne node_enabled head uint opk uint opr 0 |
| 932 | copy_node_to_cur head |
| 933 | v = cur_step uint opk uint opr |
| 934 | put g_res_u64 1 add get g_res_u64 1 1 |
| 935 | cur_make_key |
| 936 | slot = table_probe |
| 937 | do_rec = int 1 |
| 938 | if ne slot 0xffffffff |
| 939 | if ge n MC_CAP |
| 940 | put g_res_u32 1 1 |
| 941 | do_rec = int 0 |
| 942 | else |
| 943 | ni = n |
| 944 | n = add n 1 |
| 945 | copy_cur_to_node ni |
| 946 | put g_parent ni uint head |
| 947 | put g_op_kind ni opk |
| 948 | put g_op_r ni opr |
| 949 | copy_keybuf_to_node ni |
| 950 | put g_table slot uint ni |
| 951 | end |
| 952 | end |
| 953 | if ne v 0 |
| 954 | if ne do_rec 0 |
| 955 | record_viols v head opk opr |
| 956 | end |
| 957 | end |
| 958 | end |
| 959 | o = add o 1 |
| 960 | end |
| 961 | head = add head 1 |
| 962 | end |
| 963 | put g_res_u64 0 n |
| 964 | end |
| 965 | |
| 966 | fn print_rname r uint to void |
| 967 | if eq r 0 |
| 968 | out_t t_p 1 |
| 969 | ret |
| 970 | end |
| 971 | if eq r 1 |
| 972 | out_t t_c1 2 |
| 973 | ret |
| 974 | end |
| 975 | if eq r 2 |
| 976 | out_t t_c2 2 |
| 977 | ret |
| 978 | end |
| 979 | out_t t_g 1 |
| 980 | end |
| 981 | |
| 982 | fn print_op opk uint opr uint to void |
| 983 | if eq opk 0 |
| 984 | out_t t_ext 3 |
| 985 | ret |
| 986 | end |
| 987 | if eq opk 3 |
| 988 | out_t t_tick 4 |
| 989 | ret |
| 990 | end |
| 991 | if eq opk 1 |
| 992 | out_t t_fin 4 |
| 993 | else |
| 994 | if eq opk 2 |
| 995 | out_t t_fail 5 |
| 996 | else |
| 997 | out_t t_can 7 |
| 998 | end |
| 999 | end |
| 1000 | print_rname opr |
| 1001 | out_c uchar 41 |
| 1002 | end |
| 1003 | |
| 1004 | fn print_bit_name b int to void |
| 1005 | if eq b 0 |
| 1006 | out_t t_b0 17 |
| 1007 | ret |
| 1008 | end |
| 1009 | if eq b 1 |
| 1010 | out_t t_b1 26 |
| 1011 | ret |
| 1012 | end |
| 1013 | if eq b 2 |
| 1014 | out_t t_b2 19 |
| 1015 | ret |
| 1016 | end |
| 1017 | if eq b 3 |
| 1018 | out_t t_b3 28 |
| 1019 | ret |
| 1020 | end |
| 1021 | out_t t_b4 25 |
| 1022 | end |
| 1023 | |
| 1024 | fn show_ce tag_kind int b int to void |
| 1025 | tl = get g_tlen ulong b |
| 1026 | out_t t_sp2 2 |
| 1027 | if eq tag_kind 0 |
| 1028 | out_t t_unexp 10 |
| 1029 | else |
| 1030 | if eq tag_kind 1 |
| 1031 | out_t t_kby 9 |
| 1032 | else |
| 1033 | out_t t_find 7 |
| 1034 | end |
| 1035 | end |
| 1036 | out_c uchar 32 |
| 1037 | print_bit_name b |
| 1038 | out_t t_ce1 17 |
| 1039 | out_int tl |
| 1040 | out_t t_ce2 9 |
| 1041 | tbase = mul ulong b 64 |
| 1042 | i = int 0 |
| 1043 | while lt i tl |
| 1044 | if ne i 0 |
| 1045 | out_t t_arr 4 |
| 1046 | end |
| 1047 | k = uint get g_tk add tbase ulong i |
| 1048 | r = uint get g_tr add tbase ulong i |
| 1049 | print_op k r |
| 1050 | i = add i 1 |
| 1051 | end |
| 1052 | out_c uchar 10 |
| 1053 | end |
| 1054 | |
| 1055 | fn print_pname pid int to void |
| 1056 | if eq pid 0 |
| 1057 | out_t t_p_spec 4 |
| 1058 | ret |
| 1059 | end |
| 1060 | if eq pid 1 |
| 1061 | out_t t_p_ab 8 |
| 1062 | ret |
| 1063 | end |
| 1064 | if eq pid 2 |
| 1065 | out_t t_p_leak 16 |
| 1066 | ret |
| 1067 | end |
| 1068 | if eq pid 3 |
| 1069 | out_t t_p_noprop 23 |
| 1070 | ret |
| 1071 | end |
| 1072 | if eq pid 4 |
| 1073 | out_t t_p_dbl 27 |
| 1074 | ret |
| 1075 | end |
| 1076 | out_t t_p_dl 23 |
| 1077 | end |
| 1078 | |
| 1079 | fn print_role rkind int to void |
| 1080 | if eq rkind 0 |
| 1081 | out_t t_r_spec 4 |
| 1082 | ret |
| 1083 | end |
| 1084 | if eq rkind 1 |
| 1085 | out_t t_r_ab 8 |
| 1086 | ret |
| 1087 | end |
| 1088 | out_t t_r_mut 6 |
| 1089 | end |
| 1090 | |
| 1091 | fn report_bit pid int rkind int b int must_hold uint must_fail uint to void |
| 1092 | bit = shl uint 1 uint b |
| 1093 | vs = get g_res_u32 0 |
| 1094 | seen = int 0 |
| 1095 | if ne and vs bit 0 |
| 1096 | seen = int 1 |
| 1097 | end |
| 1098 | if ne and must_hold bit 0 |
| 1099 | if ne seen 0 |
| 1100 | put g_bad 0 add get g_bad 0 1 |
| 1101 | show_ce 0 b |
| 1102 | end |
| 1103 | out_t t_res 13 |
| 1104 | print_pname pid |
| 1105 | out_c uchar 46 |
| 1106 | print_bit_name b |
| 1107 | if ne seen 0 |
| 1108 | out_t t_eq_fail 6 |
| 1109 | else |
| 1110 | out_t t_eq_pass 6 |
| 1111 | end |
| 1112 | ret |
| 1113 | end |
| 1114 | if ne and must_fail bit 0 |
| 1115 | if eq seen 0 |
| 1116 | put g_bad 0 add get g_bad 0 1 |
| 1117 | else |
| 1118 | if eq rkind 2 |
| 1119 | show_ce 1 b |
| 1120 | else |
| 1121 | show_ce 2 b |
| 1122 | end |
| 1123 | end |
| 1124 | out_t t_res 13 |
| 1125 | print_pname pid |
| 1126 | out_c uchar 46 |
| 1127 | print_bit_name b |
| 1128 | if ne seen 0 |
| 1129 | if eq rkind 2 |
| 1130 | out_t t_eq_killed 8 |
| 1131 | else |
| 1132 | out_t t_eq_kf 12 |
| 1133 | end |
| 1134 | else |
| 1135 | if eq rkind 2 |
| 1136 | out_t t_eq_surv 10 |
| 1137 | else |
| 1138 | out_t t_eq_upass 17 |
| 1139 | end |
| 1140 | end |
| 1141 | ret |
| 1142 | end |
| 1143 | out_t t_res 13 |
| 1144 | print_pname pid |
| 1145 | out_c uchar 46 |
| 1146 | print_bit_name b |
| 1147 | if ne seen 0 |
| 1148 | out_t t_eq_viol 10 |
| 1149 | else |
| 1150 | out_t t_eq_held 6 |
| 1151 | end |
| 1152 | end |
| 1153 | |
| 1154 | fn set_prof cm int dl int ml int mk int to void |
| 1155 | put g_prof 0 cm |
| 1156 | put g_prof 1 dl |
| 1157 | put g_prof 2 ml |
| 1158 | put g_prof 3 mk |
| 1159 | end |
| 1160 | |
| 1161 | fn run_prof pid int rkind int mh uint mf uint to void |
| 1162 | wx_explore |
| 1163 | st = get g_res_u64 0 |
| 1164 | tr = get g_res_u64 1 |
| 1165 | trunc = get g_res_u32 1 |
| 1166 | out_t t_star 4 |
| 1167 | print_pname pid |
| 1168 | out_t t_lp 2 |
| 1169 | print_role rkind |
| 1170 | out_t t_rp_c 3 |
| 1171 | out_u64 st |
| 1172 | out_t t_st 9 |
| 1173 | out_u64 tr |
| 1174 | out_t t_tr 12 |
| 1175 | if ne trunc 0 |
| 1176 | out_t t_trunc 27 |
| 1177 | end |
| 1178 | out_c uchar 10 |
| 1179 | out_t t_res 13 |
| 1180 | print_pname pid |
| 1181 | out_t t_dot_st 8 |
| 1182 | out_u64 st |
| 1183 | out_c uchar 10 |
| 1184 | out_t t_res 13 |
| 1185 | print_pname pid |
| 1186 | out_t t_dot_tr 13 |
| 1187 | out_u64 tr |
| 1188 | out_c uchar 10 |
| 1189 | out_t t_res 13 |
| 1190 | print_pname pid |
| 1191 | out_t t_dot_ex 12 |
| 1192 | if ne trunc 0 |
| 1193 | out_t t_no 3 |
| 1194 | put g_bad 0 add get g_bad 0 1 |
| 1195 | else |
| 1196 | out_t t_yes 4 |
| 1197 | end |
| 1198 | b = int 0 |
| 1199 | while lt b 5 |
| 1200 | report_bit pid rkind b mh mf |
| 1201 | b = add b 1 |
| 1202 | end |
| 1203 | end |
| 1204 | |
| 1205 | fn main to int |
| 1206 | put g_olen 0 0 |
| 1207 | put g_bad 0 0 |
| 1208 | set_prof 1 1 0 0 |
| 1209 | run_prof 0 0 31 0 |
| 1210 | set_prof 0 0 0 0 |
| 1211 | run_prof 1 1 5 26 |
| 1212 | set_prof 1 1 1 0 |
| 1213 | run_prof 2 2 0 1 |
| 1214 | set_prof 2 1 0 0 |
| 1215 | run_prof 3 2 16 2 |
| 1216 | set_prof 1 1 0 1 |
| 1217 | run_prof 4 2 0 4 |
| 1218 | set_prof 1 0 0 0 |
| 1219 | run_prof 5 2 0 8 |
| 1220 | bad = get g_bad 0 |
| 1221 | out_t t_verd 21 |
| 1222 | if ne bad 0 |
| 1223 | out_t t_fail_nl 5 |
| 1224 | out_t t_mc_f 19 |
| 1225 | else |
| 1226 | out_t t_pass_nl 5 |
| 1227 | out_t t_mc_p 19 |
| 1228 | end |
| 1229 | out_int bad |
| 1230 | out_t t_mc_e 13 |
| 1231 | out_flush |
| 1232 | if ne bad 0 |
| 1233 | ret 1 |
| 1234 | end |
| 1235 | ret 0 |
| 1236 | end |