aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / om / hive-task / drive.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note om/hive-task/drive.om: the checks of the hive forge task rules (issue #925, DRA-288, DRA-162). |
| 3 | note Build with the pinned omc: omc < om/hive-task/drive.om > drive |
| 4 | note Run: drive MODE RULES COCKPIT SCRATCH DIR OMC MAIN |
| 5 | note MODE cases, http, table or migrate |
| 6 | note RULES om/hive-task/task.om compiled by the pinned omc |
| 7 | note COCKPIT the spark-cockpit-rs binary under test (the branch build, or main's as the control) |
| 8 | note SCRATCH an existing empty directory; every database, log and file of the run is made there |
| 9 | note DIR om/hive-task (cases.tsv and task.om are read from it) |
| 10 | note OMC the pinned omc; mode table rebuilds mutants of task.om with it |
| 11 | note MAIN spark-cockpit-rs built from main; mode migrate opens main's database with COCKPIT |
| 12 | note Modes: |
| 13 | note cases runs RULES once per line of cases.tsv and compares stdout and exit status. |
| 14 | note http starts COCKPIT on an ephemeral loopback port with a scratch database and drives |
| 15 | note /api/hive/forge/* over HTTP: T1 to T3, stale attempts, expired leases, generation |
| 16 | note exhaustion, ttl range (400 invalid), bad JSON bodies (400 invalid), artifact |
| 17 | note binding, a held write lock, 400 claim races between two cockpit processes sharing |
| 18 | note one database file, command-id replay (same body, no second change, 409 |
| 19 | note command_conflict on a different payload, across both processes and under a race), |
| 20 | note a write lock held for 2 s, past a 1 s ttl, while a claim, heartbeat or submit waits |
| 21 | note (the lease must be judged by the clock after the lock is granted), and a commit |
| 22 | note that cannot complete (the cockpit must not answer 200 for it). |
| 23 | note table seeds every combination of state, generation, fence, artifact, verdict, lease and |
| 24 | note ttl for each operation, applies it through the API, and checks that RULES predicts |
| 25 | note each outcome and next state; op 7 does the same for command ids (prior record, |
| 26 | note same or different payload, id length and characters, task state); then shows |
| 27 | note that mutants of task.om fail the checks. |
| 28 | note migrate makes a database with MAIN, opens it with COCKPIT and checks the migration. |
| 29 | note Output: one line per check, "PASS name ..." or "FAIL name ...", then a SUMMARY line. Exit 0 |
| 30 | note only when nothing failed. |
| 31 | note Host programs on this test path only, never shipped: /usr/bin/sqlite3 (3.45.1) seeds rows the |
| 32 | note API cannot create (any status, a generation near 2^53, an expired lease), holds a write lock |
| 33 | note for the busy case and a read lock on a rollback-journal database for the commit case. |
| 34 | note /usr/bin/env is a temporary bridge in cockexec, because execprog starts a program with an |
| 35 | note empty environment. |
| 36 | om2 |
| 37 | const NONE ulong 18446744073709551615 |
| 38 | const GMAX ulong 9007199254740991 |
| 39 | const ROUT ulong 0 |
| 40 | const RREQ ulong 1 |
| 41 | const RREQ2 ulong 2 |
| 42 | const RBODY ulong 3 |
| 43 | const RPATH ulong 4 |
| 44 | const REXEC ulong 5 |
| 45 | const RSQL ulong 6 |
| 46 | const RRESP ulong 7 |
| 47 | const RFILE ulong 8 |
| 48 | const RARG ulong 9 |
| 49 | const RTIN ulong 10 |
| 50 | const RTOBS ulong 11 |
| 51 | const RATT ulong 12 |
| 52 | const RSRC ulong 13 |
| 53 | const RCASE ulong 14 |
| 54 | const RDB ulong 15 |
| 55 | const RMISC ulong 16 |
| 56 | const RTOK ulong 17 |
| 57 | const RTID ulong 18 |
| 58 | const RAID ulong 19 |
| 59 | const RART ulong 20 |
| 60 | const RMUT ulong 21 |
| 61 | const RCMD ulong 22 |
| 62 | const RSAVE ulong 23 |
| 63 | const RROW ulong 24 |
| 64 | note g slots |
| 65 | const GTOP ulong 0 |
| 66 | const GNREC ulong 1 |
| 67 | const GPASS ulong 2 |
| 68 | const GFAIL ulong 3 |
| 69 | const GNRUN ulong 4 |
| 70 | const GPORTA ulong 5 |
| 71 | const GPIDA ulong 7 |
| 72 | const GBODY ulong 9 |
| 73 | const GLAST ulong 10 |
| 74 | const GT0 ulong 11 |
| 75 | const GROW ulong 12 |
| 76 | const GINC ulong 13 |
| 77 | const GTCH ulong 14 |
| 78 | const GP1 ulong 15 |
| 79 | const GP2 ulong 17 |
| 80 | const GP3 ulong 19 |
| 81 | const GAL0 ulong 22 |
| 82 | const GRZ ulong 30 |
| 83 | const GLREF ulong 33 |
| 84 | const GLBUSY ulong 34 |
| 85 | const GLOTH ulong 35 |
| 86 | const GRECL ulong 36 |
| 87 | const GRALW ulong 37 |
| 88 | const GCMD ulong 38 |
| 89 | const GP4 ulong 40 |
| 90 | const GQ ulong 42 |
| 91 | const GH ulong 45 |
| 92 | const GK0 ulong 48 |
| 93 | global m uchar 12582912 |
| 94 | global g ulong 64 |
| 95 | global al ulong 8 |
| 96 | global cu ulong 32 |
| 97 | global bs ulong 32 |
| 98 | global lm ulong 32 |
| 99 | global tc ulong 8 |
| 100 | global tv ulong 8 |
| 101 | global tr ulong 512 |
| 102 | global tk ulong 256 |
| 103 | text dq "\"" |
| 104 | text tusage "usage: drive MODE RULES COCKPIT SCRATCH DIR OMC MAIN\n" |
| 105 | text tderr "DRIVER ERROR " |
| 106 | text tpass "PASS " |
| 107 | text tfail "FAIL " |
| 108 | text thttp_ " http=" |
| 109 | text mcases "cases" |
| 110 | text mhttp "http" |
| 111 | text mtable "table" |
| 112 | text mmig "migrate" |
| 113 | text tsumm "SUMMARY mode=" |
| 114 | text tsp " pass=" |
| 115 | text tsf " fail=" |
| 116 | text tsn " not_run=" |
| 117 | text tsi " inconclusive=" |
| 118 | text fcases "/cases.tsv" |
| 119 | text fsrc "/task.om" |
| 120 | text frin "/rules.in" |
| 121 | text frout "/rules.out" |
| 122 | text fmuts "/mutant.om" |
| 123 | text fmutb "/mutant.bin" |
| 124 | text fsql "/q.sql" |
| 125 | text fsqo "/q.out" |
| 126 | text flog "/cockpit.log" |
| 127 | text dhome "/home" |
| 128 | text ftin "/table.in" |
| 129 | text ftobs "/table.obs" |
| 130 | text fhttpdb "/http.db" |
| 131 | text fmigdb "/migrate.db" |
| 132 | text fcomdb "/commit.db" |
| 133 | text ftbl "/table-" |
| 134 | text fdbs ".db" |
| 135 | text envbin "/usr/bin/env" |
| 136 | text ehome "HOME=" |
| 137 | text edb "HIVE_DB_PATH=" |
| 138 | text etok "AIEN_COCKPIT_TOKEN=" |
| 139 | text eaddr "AIEN_COCKPIT_ADDR=127.0.0.1:" |
| 140 | text sqlbin "/usr/bin/sqlite3" |
| 141 | text sqbatch "-batch" |
| 142 | text sqbail "-bail" |
| 143 | text sqhd ".timeout 10000\n" |
| 144 | text sqbeg "BEGIN;\n" |
| 145 | text sqcom "COMMIT;\n" |
| 146 | text sqi1 "INSERT INTO forge_tasks (id, comb_id, project, module, ring, q, r, title, status, created_at) VALUES ('" |
| 147 | text sqi2 "', 'c', 'scn', 'm', 0, 0, 0, 't', 'open', '2026-11-07T00:00:00Z');\n" |
| 148 | text tins1 "INSERT INTO forge_tasks (id, comb_id, project, module, ring, q, r, title, status, claimed_by, created_at, attempt_id, generation, lease_expires_ms, artifact) VALUES ('x" |
| 149 | text tins2 "', 'c', 'tbl', 'm', 0, 0, 0, 't', '" |
| 150 | text tins3 "', 'agent-t', '2026-11-07T00:00:00Z', 'att-" |
| 151 | text tins4 "', " |
| 152 | text tins5 ", 'art-" |
| 153 | text tins6 "');\n" |
| 154 | text tnull "NULL" |
| 155 | text tcomma ", " |
| 156 | text tdump_ "SELECT id, status, generation FROM forge_tasks WHERE id GLOB 'x*' ORDER BY CAST(substr(id, 2) AS INTEGER);\n" |
| 157 | text sopen "open" |
| 158 | text sclaim "claimed" |
| 159 | text ssub "submitted" |
| 160 | text sver "verified" |
| 161 | text sfail "failed" |
| 162 | text sunk "unknown" |
| 163 | text tpost "POST " |
| 164 | text tget "GET " |
| 165 | text thttp " HTTP/1.1" |
| 166 | text hhost "Host: 127.0.0.1" |
| 167 | text hauth "Authorization: Bearer " |
| 168 | text hclose "Connection: close" |
| 169 | text hctype "Content-Type: application/json" |
| 170 | text hclen "Content-Length: " |
| 171 | text pclaim "/api/hive/forge/claim" |
| 172 | text phb "/api/hive/forge/heartbeat" |
| 173 | text psub "/api/hive/forge/submit" |
| 174 | text pver "/api/hive/forge/verify" |
| 175 | text prec "/api/hive/forge/reclaim" |
| 176 | text ptasks "/api/hive/forge/tasks" |
| 177 | text jtid "{\"task_id\":\"" |
| 178 | text jagent ",\"agent_id\":\"" |
| 179 | text jaid ",\"attempt_id\":\"" |
| 180 | text jgenk ",\"generation\":" |
| 181 | text jttl ",\"ttl_secs\":" |
| 182 | text jbr ",\"branch\":\"b-core925\",\"artifact\":\"" |
| 183 | text jart ",\"artifact\":\"" |
| 184 | text jvby ",\"verifier\":\"" |
| 185 | text tver "v-core925" |
| 186 | text jvd ",\"verdict\":" |
| 187 | text jtrue "true" |
| 188 | text jfalse "false" |
| 189 | text jnotes ",\"notes\":\"n-core925\"}" |
| 190 | text cbr "}" |
| 191 | text jcmd ",\"command_id\":\"" |
| 192 | text jrcmd "{\"command_id\":\"" |
| 193 | text jrend "\"}" |
| 194 | text jbadm "{\"task_id\":\"s9\",\"ttl_secs\":300}" |
| 195 | text jbadj "{\"task_id\":" |
| 196 | text jcreate "{\"project\":\"scn\",\"module\":\"m\",\"ring\":0,\"title\":\"t\",\"description\":\"d\",\"parent_comb_id\":null}" |
| 197 | text kaid "\"attempt_id\":\"" |
| 198 | text kgen "\"generation\":" |
| 199 | text kstat "\"status\":" |
| 200 | text kcode "\"code\":" |
| 201 | text kretry "\"retryable\":" |
| 202 | text kartk "\"artifact\":" |
| 203 | text kbr "\"branch\":" |
| 204 | text kvby "\"verified_by\":" |
| 205 | text kvn "\"verify_notes\":" |
| 206 | text krecl "\"reclaimed_count\":" |
| 207 | text vopen "\"open\"" |
| 208 | text vclaim "\"claimed\"" |
| 209 | text vsub "\"submitted\"" |
| 210 | text vver "\"verified\"" |
| 211 | text vbusy "\"busy\"" |
| 212 | text vrefus "\"refused\"" |
| 213 | text vcmdc "\"command_conflict\"" |
| 214 | text vinval "\"invalid\"" |
| 215 | text vsha2 "\"sha256:s2\"" |
| 216 | text vsha3 "\"sha256:s3\"" |
| 217 | text vbr "\"b-core925\"" |
| 218 | text vver2 "\"v-core925\"" |
| 219 | text vnotes "\"n-core925\"" |
| 220 | text agw2 "w2" |
| 221 | text agw3 "w3" |
| 222 | text agwk "worker" |
| 223 | text agw5 "w5" |
| 224 | text agw6 "w6" |
| 225 | text agw9 "w9" |
| 226 | text agra "ra" |
| 227 | text agrb "rb" |
| 228 | text agold "old" |
| 229 | text agnew "new" |
| 230 | text agentc "agent-c" |
| 231 | text agentt "agent-t" |
| 232 | text ts1 "s1" |
| 233 | text ts2 "s2" |
| 234 | text ts3 "s3" |
| 235 | text ts4 "s4" |
| 236 | text ts5 "s5" |
| 237 | text ts6 "s6" |
| 238 | text ts7 "s7" |
| 239 | text ts8 "s8" |
| 240 | text ts9 "s9" |
| 241 | text ts10 "s10" |
| 242 | text ts11 "s11" |
| 243 | text ts12 "s12" |
| 244 | text ts13 "s13" |
| 245 | text ts14 "s14" |
| 246 | text ts15 "s15" |
| 247 | text ts16 "s16" |
| 248 | text ts17 "s17" |
| 249 | text ts18 "s18" |
| 250 | text ts19 "s19" |
| 251 | text tc1 "c1" |
| 252 | text cidc1 "core925-c1" |
| 253 | text cidh1 "core925-h1" |
| 254 | text cidu1 "core925-u1" |
| 255 | text cidv1 "core925-v1" |
| 256 | text cidr1 "core925-r1" |
| 257 | text cidx1 "core925-x1" |
| 258 | text cidb1 "core925-b1" |
| 259 | text cidk1 "core925-k1" |
| 260 | text cidbad "core925/1" |
| 261 | text cidq "core925-q" |
| 262 | text cidp "core925-p" |
| 263 | text cidl1 "core925-l1" |
| 264 | text cidl2 "core925-l2" |
| 265 | text tslx "/x" |
| 266 | text tm1 "m1" |
| 267 | text tm2 "m2" |
| 268 | text tm3 "m3" |
| 269 | text asha0 "sha256:none" |
| 270 | text asha2 "sha256:s2" |
| 271 | text asha3 "sha256:s3" |
| 272 | text ashax "sha256:other" |
| 273 | text tattp "att-" |
| 274 | text tattx "att-x" |
| 275 | text tartp "art-" |
| 276 | text tartx "art-x" |
| 277 | text tartn "art-new" |
| 278 | text ttokp "core925-" |
| 279 | text n_create "create_task_201" |
| 280 | text n_t1 "T1_verify_open_refused" |
| 281 | text n_t2a "T2_setup_claim" |
| 282 | text n_t2b "T2_setup_submit" |
| 283 | text n_t2c "T2_setup_verify" |
| 284 | text n_t2 "T2_claim_verified_refused" |
| 285 | text n_t3 "T3_submit_verified_refused" |
| 286 | text n_va "verify_setup_claim" |
| 287 | text n_vb "submit_persists_branch_and_artifact" |
| 288 | text n_vc "verify_wrong_artifact_refused" |
| 289 | text n_vd "verify_wrong_generation_refused" |
| 290 | text n_ve "verify_without_verifier_rejected_400" |
| 291 | text n_vf "verify_persists_verifier_and_notes" |
| 292 | text n_sa "stale_setup_first_claim" |
| 293 | text n_sb "stale_setup_same_name_reclaim_generation_plus_one" |
| 294 | text n_sc "stale_attempt_heartbeat_refused" |
| 295 | text n_sd "stale_attempt_submit_refused" |
| 296 | text n_se "current_attempt_heartbeat_accepted" |
| 297 | text n_ea "expired_setup_claim" |
| 298 | text n_eb "expired_heartbeat_refused_unchanged" |
| 299 | text n_ec "expired_submit_refused_unchanged" |
| 300 | text n_xa "exhaust_setup_seed_generations" |
| 301 | text n_xb "claim_at_max_generation_refused" |
| 302 | text n_xc "claim_reaches_max_generation_exactly" |
| 303 | text n_xd "heartbeat_at_max_generation_accepted" |
| 304 | text n_ta "claim_ttl_zero_invalid_400" |
| 305 | text n_tb "claim_ttl_over_one_day_invalid_400" |
| 306 | text n_tc "claim_ttl_one_day_accepted" |
| 307 | text n_td "heartbeat_ttl_zero_invalid_400" |
| 308 | text n_ja "json_missing_field_400_invalid" |
| 309 | text n_jb "json_malformed_400_invalid" |
| 310 | text n_ba "busy_setup_sqlite3_holds_write_lock" |
| 311 | text n_bb "busy_claim_refused_503_retryable" |
| 312 | text n_bc "busy_retry_same_command_id_granted" |
| 313 | text n_ra "replay_setup_claim_with_command_id" |
| 314 | text n_rb "replay_identical_claim_same_body" |
| 315 | text n_rc "replay_identical_claim_row_unchanged" |
| 316 | text n_rd "replay_different_payload_409_command_conflict" |
| 317 | text n_re "replay_heartbeat_identical_no_lease_extension" |
| 318 | text n_rf "replay_submit_identical_same_body" |
| 319 | text n_rg "replay_verify_identical_same_body" |
| 320 | text n_rh "replay_reclaim_identical_no_second_sweep" |
| 321 | text n_ri "command_id_too_long_400" |
| 322 | text n_rj "command_id_128_bytes_valid" |
| 323 | text n_rk "command_id_bad_char_400" |
| 324 | text n_rl "replay_after_refusal_decided_again" |
| 325 | text n_rm "command_record_written_once" |
| 326 | text n_rx "replay_across_two_cockpits_same_body" |
| 327 | text n_ry "replay_across_two_cockpits_conflict_409" |
| 328 | text n_rr "replay_race_two_cockpits_one_record" |
| 329 | text n_cf "commit_unsafe_db_refused_at_start_row_unchanged" |
| 330 | text n_cfa "commit_setup_rollback_journal_and_reader" |
| 331 | text n_race "race_two_cockpits_single_grant" |
| 332 | text n_lk1 "lock_setup_hold_and_send" |
| 333 | text n_lk2 "lock_claim_ttl_crossed_lease_live_at_grant" |
| 334 | text n_lk3 "lock_claim_cmd_ttl_crossed_lease_live_at_grant" |
| 335 | text n_lk4 "lock_heartbeat_expired_while_waiting_refused_row_unchanged" |
| 336 | text n_lk5 "lock_heartbeat_cmd_expired_while_waiting_refused_not_recorded" |
| 337 | text n_lk6 "lock_submit_expired_while_waiting_refused_row_unchanged" |
| 338 | text n_ma "migrate_setup_main_claim" |
| 339 | text n_mb "migrate_setup_main_submit" |
| 340 | text n_mc "migrate_old_schema_13_columns" |
| 341 | text n_md "migrate_new_schema_21_columns" |
| 342 | text n_me "migrate_rows_backfilled" |
| 343 | text n_mf "migrate_backfilled_lease_held" |
| 344 | text n_mg "migrate_open_claim_generation_1" |
| 345 | text n_mh "migrate_legacy_submitted_reworkable" |
| 346 | text n_mi "migrate_command_table_present" |
| 347 | text n_mj "migrate_reopen_idempotent" |
| 348 | text n_tab "table_crosscheck" |
| 349 | text n_trec "table_reap_count_matches" |
| 350 | text tbusyw " waited_ms=" |
| 351 | text tbsql ".timeout 0\nBEGIN IMMEDIATE;\nSELECT 'held';\n" |
| 352 | text tbheld "held" |
| 353 | text tbrb "ROLLBACK;\n" |
| 354 | text tbsql2 ".timeout 0\nBEGIN;\nSELECT 'held' FROM sqlite_master LIMIT 1;\n" |
| 355 | text tdelj "PRAGMA journal_mode = DELETE;\n" |
| 356 | text tdelw "delete\n" |
| 357 | text tcomq "SELECT status || ' ' || generation FROM forge_tasks WHERE id = 'c1';\n" |
| 358 | text tcopen "open 0\n" |
| 359 | text tcom1 " served=" |
| 360 | text tcom2 " claim=" |
| 361 | text trow10 "SELECT generation || '|' || attempt_id || '|' || COALESCE(lease_expires_ms, 0) || '|' || status FROM forge_tasks WHERE id = 's10';\n" |
| 362 | text texp1 "UPDATE forge_tasks SET status = 'claimed', claimed_by = 'w', attempt_id = 'a', generation = 1, lease_expires_ms = 1 WHERE id = '" |
| 363 | text tqend "';\n" |
| 364 | text tss13 "SELECT status FROM forge_tasks WHERE id = 's13';\n" |
| 365 | text tclnl "claimed\n" |
| 366 | text tcnt "SELECT (SELECT count(*) FROM forge_commands WHERE command_id IN ('core925-c1', 'core925-x1', 'core925-b1')) || ' ' || (SELECT count(*) FROM forge_commands WHERE command_id = 'core925/1' OR length(command_id) > 128);\n" |
| 367 | text tcntw "3 0\n" |
| 368 | text trq2 "SELECT (SELECT count(*) FROM forge_tasks WHERE id GLOB 'q[0-9]*' AND status = 'claimed' AND generation = 1) || ' ' || (SELECT count(*) FROM forge_commands WHERE command_id GLOB 'core925-q[0-9]*');\n" |
| 369 | text tlive "SELECT CASE WHEN status = 'claimed' AND lease_expires_ms > CAST((julianday('now') - 2440587.5) * 86400000 AS INTEGER) THEN 'live' ELSE 'dead' END FROM forge_tasks WHERE id = '" |
| 370 | text tlivew "live\n" |
| 371 | text trowa "SELECT generation || '|' || attempt_id || '|' || COALESCE(lease_expires_ms, 0) || '|' || status FROM forge_tasks WHERE id = '" |
| 372 | text tlkcnt "SELECT count(*) FROM forge_commands WHERE command_id = 'core925-l2';\n" |
| 373 | text tlkcntw "0\n" |
| 374 | text t4040 "40 40\n" |
| 375 | text trr1 " trials=40 same_body=" |
| 376 | text trr2 " one_busy=" |
| 377 | text trr3 " other=" |
| 378 | text tcmdt "SELECT count(*) FROM sqlite_master WHERE type = 'table' AND name = 'forge_commands';\n" |
| 379 | text t1nl "1\n" |
| 380 | text tcmdg "CREATE TABLE IF NOT EXISTS forge_commands (command_id TEXT PRIMARY KEY);\n" |
| 381 | text tkupd1 "UPDATE forge_tasks SET status = 'verified', generation = 1 WHERE id = 'k" |
| 382 | text td1 "SELECT COALESCE((SELECT status FROM forge_tasks WHERE id = 'k" |
| 383 | text td2 "'), 'none') || '|' || COALESCE((SELECT generation FROM forge_tasks WHERE id = 'k" |
| 384 | text td3 "'), 0) || '|' || (SELECT count(*) FROM forge_commands WHERE command_id = '" |
| 385 | text td4 "');\n" |
| 386 | text tz3 " 0 0 0 " |
| 387 | text tsx6 "UPDATE forge_tasks SET generation = 9007199254740991 WHERE id = 's6';\nUPDATE forge_tasks SET generation = 9007199254740990 WHERE id = 's7';\n" |
| 388 | text tss5 "SELECT status FROM forge_tasks WHERE id = 's5';\n" |
| 389 | text tsubnl "submitted\n" |
| 390 | text trq "SELECT count(*) FROM forge_tasks WHERE id GLOB 'r[0-9]*' AND status = 'claimed';\n" |
| 391 | text tcols "SELECT count(*) FROM pragma_table_info('forge_tasks');\n" |
| 392 | text t13 "13\n" |
| 393 | text t21 "21\n" |
| 394 | text tmrows "SELECT id || ' ' || status || ' ' || generation || ' ' || COALESCE(lease_expires_ms > 0, 0) || ' ' || COALESCE(verified_by, '-') FROM forge_tasks WHERE id GLOB 'm*' ORDER BY id;\n" |
| 395 | text tmwant "m1 open 0 0 -\nm2 claimed 0 1 -\nm3 failed 0 0 migration\n" |
| 396 | text trace1 " trials=400 one_grant=" |
| 397 | text trace2 " zero_grant=" |
| 398 | text trace3 " double_grant=" |
| 399 | text trace4 " loser_refused_409=" |
| 400 | text trace5 " loser_busy_503=" |
| 401 | text trace6 " loser_other=" |
| 402 | text trace7 " db_claimed=" |
| 403 | text ttab1 " rows=" |
| 404 | text ttab2 " mismatches=" |
| 405 | text ttab3 " chunks=" |
| 406 | text ttab4 " reclaimed_count=" |
| 407 | text ttab5 " rules_reaps=" |
| 408 | text tinc "INCONCLUSIVE table chunk " |
| 409 | text tinc2 ": over 25 s after the cockpit started, so its 30 s reaper may have run\n" |
| 410 | text tfrow "FAIL table row " |
| 411 | text tfin " in=" |
| 412 | text tfrul " rules=" |
| 413 | text tfobs " observed=" |
| 414 | text tmut "mutant " |
| 415 | text tmutk " killed: cases_failed=" |
| 416 | text tmuts " SURVIVED: cases_failed=" |
| 417 | text tmutt " table_mismatches=" |
| 418 | text tmuta "FAIL mutant anchor missing: " |
| 419 | text tmutc "FAIL mutant refused by omc: " |
| 420 | text tcase "case " |
| 421 | text tcex " exit=" |
| 422 | text tcout " out=" |
| 423 | text tcsum "cases total=" |
| 424 | note mutants of task.om: the exact line, its replacement, and which occurrence |
| 425 | text mf01 "el = or eq st OPEN eq st FAILED" |
| 426 | text mt01 "el = true" |
| 427 | text mf02 "ret HELD" |
| 428 | text mt02 "ret ALLOW" |
| 429 | text mf04 "if not live now exp" |
| 430 | text mt04 "if lt now 0" |
| 431 | text mf05 "ret and eq rgen gen eq am 1" |
| 432 | text mt05 "ret eq rgen gen" |
| 433 | text mt06 "ret eq am 1" |
| 434 | text mf07 "if ge gen GMAX" |
| 435 | text mt07 "if gt gen GMAX" |
| 436 | text mf08 "if or ne rgen gen ne art 1" |
| 437 | text mt08 "if ne rgen gen" |
| 438 | text mt09 "if ne art 1" |
| 439 | text mf10 "ret lt now exp" |
| 440 | text mt10 "ret le now exp" |
| 441 | text mf11 "ret and ge ttl 1 le ttl MAXTTL" |
| 442 | text mt11 "ret ge ttl 1" |
| 443 | text mf12 "ret add gen 1" |
| 444 | text mt12 "ret gen" |
| 445 | text mf13 "if eq vd 1" |
| 446 | text mt13 "if le vd 1" |
| 447 | text mf14 "if ne st SUBMTD" |
| 448 | text mtfal "if false" |
| 449 | text mf15 "if or eq code SQBUSY eq code SQLOCK" |
| 450 | text mt15 "if eq code SQBUSY" |
| 451 | text mf16 "if ne st CLAIMED" |
| 452 | text mf17 "if eq dig 1" |
| 453 | text mf18 "if eq prior 0" |
| 454 | text mf19 "if eq sdec BADTTL" |
| 455 | text mf20 "if ge sdec RETRY" |
| 456 | text mf21 "if or eq idl 0 gt idl CMDMAX" |
| 457 | text mt21 "if eq idl 0" |
| 458 | text mf22 "if ne bad 0" |
| 459 | text mf23 "if ne sdec ALLOW" |
| 460 | text mf24 "ret prior" |
| 461 | text mt24 "ret 0" |
| 462 | text mf25 "if and eq dc ALLOW eq sdec ALLOW" |
| 463 | text mt25 "if eq dc ALLOW" |
| 464 | text mf26 "if ne has 1" |
| 465 | text mf27 "if or eq dc REPLAY eq dc CONFLICT" |
| 466 | |
| 467 | note ---- arena regions: m holds every buffer; region r spans bs[r] up to lm[r], cursor cu[r]. |
| 468 | fn setreg r ulong sz ulong to void |
| 469 | b = get g GTOP |
| 470 | e = add b sz |
| 471 | if gt e len m |
| 472 | exit 70 |
| 473 | end |
| 474 | put bs r b |
| 475 | put cu r b |
| 476 | put lm r e |
| 477 | put g GTOP e |
| 478 | end |
| 479 | |
| 480 | fn setup to void |
| 481 | setreg ROUT 1048576 |
| 482 | setreg RREQ 131072 |
| 483 | setreg RREQ2 131072 |
| 484 | setreg RBODY 65536 |
| 485 | setreg RPATH 4096 |
| 486 | setreg REXEC 16384 |
| 487 | setreg RSQL 2097152 |
| 488 | setreg RRESP 1048576 |
| 489 | setreg RFILE 2097152 |
| 490 | setreg RARG 8192 |
| 491 | setreg RTIN 1048576 |
| 492 | setreg RTOBS 524288 |
| 493 | setreg RATT 4096 |
| 494 | setreg RSRC 262144 |
| 495 | setreg RCASE 65536 |
| 496 | setreg RDB 4096 |
| 497 | setreg RMISC 4096 |
| 498 | setreg RTOK 256 |
| 499 | setreg RTID 256 |
| 500 | setreg RAID 256 |
| 501 | setreg RART 256 |
| 502 | setreg RMUT 262144 |
| 503 | setreg RCMD 512 |
| 504 | setreg RSAVE 131072 |
| 505 | setreg RROW 4096 |
| 506 | end |
| 507 | |
| 508 | fn rsz r ulong to void |
| 509 | put cu r get bs r |
| 510 | end |
| 511 | |
| 512 | fn rln r ulong to ulong |
| 513 | ret sub get cu r get bs r |
| 514 | end |
| 515 | |
| 516 | fn pb r ulong c uchar to void |
| 517 | p = get cu r |
| 518 | if ge p get lm r |
| 519 | exit 71 |
| 520 | end |
| 521 | put m p c |
| 522 | put cu r add p 1 |
| 523 | end |
| 524 | |
| 525 | fn ap r ulong t view uchar * to void |
| 526 | for i ulong len t |
| 527 | pb r get t i |
| 528 | end |
| 529 | end |
| 530 | |
| 531 | fn apm r ulong o ulong n ulong to void |
| 532 | i = ulong 0 |
| 533 | while lt i n bound 999999 |
| 534 | pb r get m add o i |
| 535 | i = add i 1 |
| 536 | end |
| 537 | end |
| 538 | |
| 539 | fn apr r ulong s ulong to void |
| 540 | apm r get bs s rln s |
| 541 | end |
| 542 | |
| 543 | fn apa r ulong i ulong to void |
| 544 | apm r add get bs RARG mul i 1024 get al i |
| 545 | end |
| 546 | |
| 547 | fn apd r ulong v ulong to void |
| 548 | p = ulong 1 |
| 549 | while le p div v 10 bound 20 |
| 550 | p = mul p 10 |
| 551 | end |
| 552 | while ne p 0 bound 21 |
| 553 | pb r uchar add div v p 48 |
| 554 | v = rem v p |
| 555 | p = div p 10 |
| 556 | end |
| 557 | end |
| 558 | |
| 559 | fn apl r ulong v long to void |
| 560 | if lt v 0 |
| 561 | pb r 45 |
| 562 | apd r ulong neg v |
| 563 | else |
| 564 | apd r ulong v |
| 565 | end |
| 566 | end |
| 567 | |
| 568 | fn hexd v uchar to uchar |
| 569 | if lt v 10 |
| 570 | ret add v 48 |
| 571 | end |
| 572 | ret add v 87 |
| 573 | end |
| 574 | |
| 575 | fn sp r ulong to void |
| 576 | pb r 32 |
| 577 | end |
| 578 | |
| 579 | fn nlr r ulong to void |
| 580 | pb r 10 |
| 581 | end |
| 582 | |
| 583 | note ---- output |
| 584 | fn flush to void |
| 585 | b = get bs ROUT |
| 586 | n = sub get cu ROUT b |
| 587 | o = ulong 0 |
| 588 | while lt o n bound 999999 |
| 589 | k = write 1 m add b o sub n o |
| 590 | if le k 0 |
| 591 | exit 73 |
| 592 | end |
| 593 | o = add o ulong k |
| 594 | end |
| 595 | put cu ROUT b |
| 596 | end |
| 597 | |
| 598 | fn say t view uchar * to void |
| 599 | ap ROUT t |
| 600 | end |
| 601 | |
| 602 | fn nl to void |
| 603 | pb ROUT 10 |
| 604 | flush |
| 605 | end |
| 606 | |
| 607 | fn ck yes bool t view uchar * to void |
| 608 | if not yes |
| 609 | say tderr |
| 610 | say t |
| 611 | nl |
| 612 | exit 80 |
| 613 | end |
| 614 | end |
| 615 | |
| 616 | fn inc s ulong to void |
| 617 | put g s add get g s 1 |
| 618 | end |
| 619 | |
| 620 | fn mark ok bool to void |
| 621 | if ok |
| 622 | say tpass |
| 623 | inc GPASS |
| 624 | else |
| 625 | say tfail |
| 626 | inc GFAIL |
| 627 | end |
| 628 | end |
| 629 | |
| 630 | fn rep ok bool name view uchar * to void |
| 631 | mark ok |
| 632 | say name |
| 633 | say thttp_ |
| 634 | apd ROUT get g GLAST |
| 635 | nl |
| 636 | end |
| 637 | |
| 638 | note ---- arena scanning |
| 639 | fn findc o ulong e ulong c uchar to ulong |
| 640 | p = o |
| 641 | while lt p e bound 999999 |
| 642 | if eq get m p c |
| 643 | ret p |
| 644 | end |
| 645 | p = add p 1 |
| 646 | end |
| 647 | ret e |
| 648 | end |
| 649 | |
| 650 | fn pnum o ulong e ulong to ulong |
| 651 | v = ulong 0 |
| 652 | d = ulong 0 |
| 653 | p = o |
| 654 | while lt p e bound 64 |
| 655 | c = get m p |
| 656 | if or lt c 48 gt c 57 |
| 657 | break |
| 658 | end |
| 659 | if eq d 20 |
| 660 | ret NONE |
| 661 | end |
| 662 | v = add mul v 10 ulong sub c 48 |
| 663 | p = add p 1 |
| 664 | d = add d 1 |
| 665 | end |
| 666 | if eq d 0 |
| 667 | ret NONE |
| 668 | end |
| 669 | ret v |
| 670 | end |
| 671 | |
| 672 | fn same a ulong b ulong n ulong to bool |
| 673 | i = ulong 0 |
| 674 | while lt i n bound 999999 |
| 675 | if ne get m add a i get m add b i |
| 676 | ret false |
| 677 | end |
| 678 | i = add i 1 |
| 679 | end |
| 680 | ret true |
| 681 | end |
| 682 | |
| 683 | fn mtext a ulong t view uchar * to bool |
| 684 | for i ulong len t |
| 685 | if ne get m add a i get t i |
| 686 | ret false |
| 687 | end |
| 688 | end |
| 689 | ret true |
| 690 | end |
| 691 | |
| 692 | note rtext: region r holds exactly the bytes of t. |
| 693 | fn rtext r ulong t view uchar * to bool |
| 694 | if ne rln r len t |
| 695 | ret false |
| 696 | end |
| 697 | ret mtext get bs r t |
| 698 | end |
| 699 | |
| 700 | note nxt: the next decimal number at g[s] (positions up to g[s+1]), skipping other bytes. |
| 701 | fn nxt s ulong to ulong |
| 702 | p = get g s |
| 703 | e = get g add s 1 |
| 704 | while lt p e bound 999999 |
| 705 | c = get m p |
| 706 | if and ge c 48 le c 57 |
| 707 | break |
| 708 | end |
| 709 | p = add p 1 |
| 710 | end |
| 711 | v = pnum p e |
| 712 | q = p |
| 713 | while lt q e bound 64 |
| 714 | c2 = get m q |
| 715 | if or lt c2 48 gt c2 57 |
| 716 | break |
| 717 | end |
| 718 | q = add q 1 |
| 719 | end |
| 720 | put g s q |
| 721 | ret v |
| 722 | end |
| 723 | |
| 724 | note ---- arguments |
| 725 | fn args to void |
| 726 | n = argcnt |
| 727 | if ne n 8 |
| 728 | say tusage |
| 729 | flush |
| 730 | exit 2 |
| 731 | end |
| 732 | for i ulong 8 |
| 733 | k = argread i m add get bs RARG mul i 1024 1023 |
| 734 | if le k 0 |
| 735 | say tusage |
| 736 | flush |
| 737 | exit 2 |
| 738 | end |
| 739 | put al i ulong k |
| 740 | end |
| 741 | end |
| 742 | |
| 743 | fn argis i ulong t view uchar * to bool |
| 744 | if ne get al i len t |
| 745 | ret false |
| 746 | end |
| 747 | ret mtext add get bs RARG mul i 1024 t |
| 748 | end |
| 749 | |
| 750 | note ---- files |
| 751 | fn psc t view uchar * to void |
| 752 | rsz RPATH |
| 753 | apa RPATH 4 |
| 754 | ap RPATH t |
| 755 | end |
| 756 | |
| 757 | fn pdir t view uchar * to void |
| 758 | rsz RPATH |
| 759 | apa RPATH 5 |
| 760 | ap RPATH t |
| 761 | end |
| 762 | |
| 763 | note O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC = 524865; O_RDONLY|O_CLOEXEC = 524288; |
| 764 | note O_WRONLY|O_CREAT|O_APPEND|O_CLOEXEC = 525377. |
| 765 | fn fopw mode int to int |
| 766 | fd = fopen m get bs RPATH rln RPATH 524865 mode |
| 767 | ret int fd |
| 768 | end |
| 769 | |
| 770 | fn fopr to int |
| 771 | fd = fopen m get bs RPATH rln RPATH 524288 0 |
| 772 | ret int fd |
| 773 | end |
| 774 | |
| 775 | fn fopa to int |
| 776 | fd = fopen m get bs RPATH rln RPATH 525377 420 |
| 777 | ret int fd |
| 778 | end |
| 779 | |
| 780 | fn wall fd int r ulong to bool |
| 781 | b = get bs r |
| 782 | n = rln r |
| 783 | o = ulong 0 |
| 784 | while lt o n bound 999999 |
| 785 | k = write fd m add b o sub n o |
| 786 | if le k 0 |
| 787 | ret false |
| 788 | end |
| 789 | o = add o ulong k |
| 790 | end |
| 791 | ret true |
| 792 | end |
| 793 | |
| 794 | fn wfile r ulong to bool |
| 795 | fd = fopw 420 |
| 796 | if lt fd 0 |
| 797 | ret false |
| 798 | end |
| 799 | ok = wall fd r |
| 800 | c = fclose fd |
| 801 | ret and ok eq c 0 |
| 802 | end |
| 803 | |
| 804 | fn rfile r ulong to long |
| 805 | rsz r |
| 806 | fd = fopr |
| 807 | if lt fd 0 |
| 808 | ret long fd |
| 809 | end |
| 810 | p = get cu r |
| 811 | e = get lm r |
| 812 | while true bound 999999 |
| 813 | k = read fd m p sub e p |
| 814 | if lt k 0 |
| 815 | c = fclose fd |
| 816 | ret k |
| 817 | end |
| 818 | if eq k 0 |
| 819 | break |
| 820 | end |
| 821 | p = add p ulong k |
| 822 | end |
| 823 | c2 = fclose fd |
| 824 | ck lt p e fcases |
| 825 | put cu r p |
| 826 | ret long sub p get bs r |
| 827 | end |
| 828 | |
| 829 | note ---- processes: REXEC holds the packed argument list (u16 count, u16-length records). |
| 830 | fn xbeg to void |
| 831 | rsz REXEC |
| 832 | pb REXEC 0 |
| 833 | pb REXEC 0 |
| 834 | put g GNREC 0 |
| 835 | end |
| 836 | |
| 837 | fn xhdr n ulong to void |
| 838 | pb REXEC uchar and n 255 |
| 839 | pb REXEC uchar shr n 8 |
| 840 | inc GNREC |
| 841 | end |
| 842 | |
| 843 | fn xa t view uchar * to void |
| 844 | xhdr len t |
| 845 | ap REXEC t |
| 846 | end |
| 847 | |
| 848 | fn xreg r ulong to void |
| 849 | xhdr rln r |
| 850 | apr REXEC r |
| 851 | end |
| 852 | |
| 853 | fn xarg i ulong to void |
| 854 | xhdr get al i |
| 855 | apa REXEC i |
| 856 | end |
| 857 | |
| 858 | fn spawn fi int fo int fe int to int |
| 859 | b = get bs REXEC |
| 860 | n = get g GNREC |
| 861 | put m b uchar and n 255 |
| 862 | put m add b 1 uchar shr n 8 |
| 863 | pid = fork |
| 864 | if eq pid 0 |
| 865 | if ge fi 0 |
| 866 | r1 = dupfd fi 0 0 |
| 867 | end |
| 868 | if ge fo 0 |
| 869 | r2 = dupfd fo 1 0 |
| 870 | end |
| 871 | if ge fe 0 |
| 872 | r3 = dupfd fe 2 0 |
| 873 | end |
| 874 | r4 = execprog m b rln REXEC |
| 875 | exit 81 |
| 876 | end |
| 877 | ret int pid |
| 878 | end |
| 879 | |
| 880 | fn reap pid int to long |
| 881 | sb = new uchar 4 0 |
| 882 | r = waitpid pid sb 0 4 0 |
| 883 | if ne r long pid |
| 884 | ret -1 |
| 885 | end |
| 886 | sg = and get sb 0 127 |
| 887 | if eq sg 0 |
| 888 | ret long get sb 1 |
| 889 | end |
| 890 | ret add 256 long sg |
| 891 | end |
| 892 | |
| 893 | fn alive pid int to bool |
| 894 | sb = new uchar 4 0 |
| 895 | r = waitpid pid sb 0 4 1 |
| 896 | ret eq r 0 |
| 897 | end |
| 898 | |
| 899 | fn runw fi int fo int fe int to long |
| 900 | pid = spawn fi fo fe |
| 901 | if le pid 0 |
| 902 | ret -2 |
| 903 | end |
| 904 | ret reap pid |
| 905 | end |
| 906 | |
| 907 | note rules: run task.om (which 0) or the current mutant (which 1) on region ri; stdout to RFILE. |
| 908 | fn rules which ulong ri ulong to long |
| 909 | psc frin |
| 910 | ck wfile ri frin |
| 911 | fi = fopr |
| 912 | psc frout |
| 913 | fo = fopw 420 |
| 914 | ck and ge fi 0 ge fo 0 frout |
| 915 | xbeg |
| 916 | if eq which 0 |
| 917 | xarg 2 |
| 918 | else |
| 919 | psc fmutb |
| 920 | xreg RPATH |
| 921 | end |
| 922 | r = runw fi fo -1 |
| 923 | c1 = fclose fi |
| 924 | c2 = fclose fo |
| 925 | psc frout |
| 926 | n = rfile RFILE |
| 927 | ck ge n 0 frout |
| 928 | ret r |
| 929 | end |
| 930 | |
| 931 | note sqlrun: /usr/bin/sqlite3 on the database named by RDB, script RSQL, stdout to RFILE. |
| 932 | fn sqlrun to long |
| 933 | psc fsql |
| 934 | ck wfile RSQL fsql |
| 935 | fi = fopr |
| 936 | psc fsqo |
| 937 | fo = fopw 420 |
| 938 | ck and ge fi 0 ge fo 0 fsqo |
| 939 | xbeg |
| 940 | xa sqlbin |
| 941 | xa sqbatch |
| 942 | xa sqbail |
| 943 | xreg RDB |
| 944 | r = runw fi fo -1 |
| 945 | c1 = fclose fi |
| 946 | c2 = fclose fo |
| 947 | psc fsqo |
| 948 | n = rfile RFILE |
| 949 | ck ge n 0 fsqo |
| 950 | ret r |
| 951 | end |
| 952 | |
| 953 | note ---- cases mode |
| 954 | fn case1 which ulong s ulong e ulong quiet bool to bool |
| 955 | t1 = findc s e 9 |
| 956 | t2 = findc add t1 1 e 9 |
| 957 | ck lt t2 e fcases |
| 958 | rsz RMISC |
| 959 | apm RMISC add t1 1 sub sub t2 t1 1 |
| 960 | pb RMISC 10 |
| 961 | code = rules which RMISC |
| 962 | w = add t2 1 |
| 963 | wn = sub e w |
| 964 | ok = false |
| 965 | if eq get m w 101 |
| 966 | want = pnum add w 4 e |
| 967 | ok = and eq code long want eq rln RFILE 0 |
| 968 | else |
| 969 | fb = get bs RFILE |
| 970 | ok = and eq code 0 eq rln RFILE add wn 1 |
| 971 | if ok |
| 972 | ok = same w fb wn |
| 973 | end |
| 974 | if ok |
| 975 | ok = eq get m add fb wn 10 |
| 976 | end |
| 977 | end |
| 978 | if not quiet |
| 979 | mark ok |
| 980 | say tcase |
| 981 | apm ROUT s sub t1 s |
| 982 | if not ok |
| 983 | say tcex |
| 984 | apl ROUT code |
| 985 | say tcout |
| 986 | apm ROUT get bs RFILE rln RFILE |
| 987 | end |
| 988 | nl |
| 989 | end |
| 990 | ret ok |
| 991 | end |
| 992 | |
| 993 | |
| 994 | fn cases which ulong quiet bool to ulong |
| 995 | pdir fcases |
| 996 | n = rfile RCASE |
| 997 | ck gt n 0 fcases |
| 998 | p = get bs RCASE |
| 999 | e = get cu RCASE |
| 1000 | fails = ulong 0 |
| 1001 | cnt = ulong 0 |
| 1002 | while lt p e bound 65536 |
| 1003 | q = findc p e 10 |
| 1004 | if lt p q |
| 1005 | if ne get m p 35 |
| 1006 | cnt = add cnt 1 |
| 1007 | if not case1 which p q quiet |
| 1008 | fails = add fails 1 |
| 1009 | end |
| 1010 | end |
| 1011 | end |
| 1012 | p = add q 1 |
| 1013 | end |
| 1014 | if not quiet |
| 1015 | say tcsum |
| 1016 | apd ROUT cnt |
| 1017 | say tsf |
| 1018 | apd ROUT fails |
| 1019 | nl |
| 1020 | end |
| 1021 | ret fails |
| 1022 | end |
| 1023 | |
| 1024 | note ---- HTTP over Omega sockets |
| 1025 | fn crlf r ulong to void |
| 1026 | pb r 13 |
| 1027 | pb r 10 |
| 1028 | end |
| 1029 | |
| 1030 | fn hbuild rq ulong post bool path view uchar * to void |
| 1031 | rsz rq |
| 1032 | if post |
| 1033 | ap rq tpost |
| 1034 | else |
| 1035 | ap rq tget |
| 1036 | end |
| 1037 | ap rq path |
| 1038 | ap rq thttp |
| 1039 | crlf rq |
| 1040 | ap rq hhost |
| 1041 | crlf rq |
| 1042 | ap rq hauth |
| 1043 | apr rq RTOK |
| 1044 | crlf rq |
| 1045 | ap rq hclose |
| 1046 | crlf rq |
| 1047 | if post |
| 1048 | ap rq hctype |
| 1049 | crlf rq |
| 1050 | ap rq hclen |
| 1051 | apd rq rln RBODY |
| 1052 | crlf rq |
| 1053 | end |
| 1054 | crlf rq |
| 1055 | if post |
| 1056 | apr rq RBODY |
| 1057 | end |
| 1058 | end |
| 1059 | |
| 1060 | fn hconn port ulong to int |
| 1061 | a = new uchar 16 0 |
| 1062 | put a 0 2 |
| 1063 | put a 2 uchar shr port 8 |
| 1064 | put a 3 uchar and port 255 |
| 1065 | put a 4 127 |
| 1066 | put a 7 1 |
| 1067 | fd = socknew 2 524289 0 |
| 1068 | if lt fd 0 |
| 1069 | ret -1 |
| 1070 | end |
| 1071 | r = connect int fd a 0 16 |
| 1072 | if lt r 0 |
| 1073 | c = fclose int fd |
| 1074 | ret -1 |
| 1075 | end |
| 1076 | ret int fd |
| 1077 | end |
| 1078 | |
| 1079 | fn hput fd int rq ulong to bool |
| 1080 | b = get bs rq |
| 1081 | n = rln rq |
| 1082 | o = ulong 0 |
| 1083 | while lt o n bound 999999 |
| 1084 | k = send fd m add b o sub n o 0 |
| 1085 | if le k 0 |
| 1086 | ret false |
| 1087 | end |
| 1088 | o = add o ulong k |
| 1089 | end |
| 1090 | ret true |
| 1091 | end |
| 1092 | |
| 1093 | fn crlf2 i ulong to bool |
| 1094 | a = and eq get m i 13 eq get m add i 1 10 |
| 1095 | b = and eq get m add i 2 13 eq get m add i 3 10 |
| 1096 | ret and a b |
| 1097 | end |
| 1098 | |
| 1099 | fn hstat to ulong |
| 1100 | b = get bs RRESP |
| 1101 | e = get cu RRESP |
| 1102 | put g GBODY e |
| 1103 | if lt sub e b 12 |
| 1104 | ret 0 |
| 1105 | end |
| 1106 | code = pnum add b 9 add b 12 |
| 1107 | i = b |
| 1108 | while lt add i 3 e bound 999999 |
| 1109 | if crlf2 i |
| 1110 | put g GBODY add i 4 |
| 1111 | break |
| 1112 | end |
| 1113 | i = add i 1 |
| 1114 | end |
| 1115 | if eq code NONE |
| 1116 | ret 0 |
| 1117 | end |
| 1118 | ret code |
| 1119 | end |
| 1120 | |
| 1121 | note hrecv: read the whole response (the request said Connection: close); 30 s at most. |
| 1122 | fn hrecv fd int to ulong |
| 1123 | rsz RRESP |
| 1124 | t0 = monons |
| 1125 | p = get cu RRESP |
| 1126 | lim = get lm RRESP |
| 1127 | done = false |
| 1128 | while not done bound 999999 |
| 1129 | w = waitio fd 1 100000000 |
| 1130 | if gt w 0 |
| 1131 | k = recv fd m p sub lim p 0 |
| 1132 | if le k 0 |
| 1133 | done = true |
| 1134 | else |
| 1135 | p = add p ulong k |
| 1136 | end |
| 1137 | end |
| 1138 | if lt w 0 |
| 1139 | done = true |
| 1140 | end |
| 1141 | if gt sub monons t0 30000000000 |
| 1142 | done = true |
| 1143 | end |
| 1144 | if ge p lim |
| 1145 | done = true |
| 1146 | end |
| 1147 | end |
| 1148 | c = fclose fd |
| 1149 | put cu RRESP p |
| 1150 | code = hstat |
| 1151 | put g GLAST code |
| 1152 | ret code |
| 1153 | end |
| 1154 | |
| 1155 | fn hreq slot ulong post bool path view uchar * to ulong |
| 1156 | hbuild RREQ post path |
| 1157 | fd = hconn get g add GPORTA slot |
| 1158 | if lt fd 0 |
| 1159 | put g GLAST 0 |
| 1160 | put g GBODY get cu RRESP |
| 1161 | ret 0 |
| 1162 | end |
| 1163 | if not hput fd RREQ |
| 1164 | c = fclose fd |
| 1165 | put g GLAST 0 |
| 1166 | ret 0 |
| 1167 | end |
| 1168 | ret hrecv fd |
| 1169 | end |
| 1170 | |
| 1171 | fn hpost slot ulong path view uchar * to ulong |
| 1172 | ret hreq slot true path |
| 1173 | end |
| 1174 | |
| 1175 | fn hgetp slot ulong path view uchar * to ulong |
| 1176 | ret hreq slot false path |
| 1177 | end |
| 1178 | |
| 1179 | note ---- JSON: serde_json writes object keys in sorted order, so a top-level key such as |
| 1180 | note "attempt_id" or "generation" comes before "task" and the first match is the top-level one. |
| 1181 | fn jfind k view uchar * to ulong |
| 1182 | e = get cu RRESP |
| 1183 | n = len k |
| 1184 | i = get g GBODY |
| 1185 | while le add i n e bound 999999 |
| 1186 | if mtext i k |
| 1187 | ret add i n |
| 1188 | end |
| 1189 | i = add i 1 |
| 1190 | end |
| 1191 | ret NONE |
| 1192 | end |
| 1193 | |
| 1194 | fn jnum k view uchar * to ulong |
| 1195 | p = jfind k |
| 1196 | if eq p NONE |
| 1197 | ret NONE |
| 1198 | end |
| 1199 | ret pnum p get cu RRESP |
| 1200 | end |
| 1201 | |
| 1202 | fn jis k view uchar * t view uchar * to bool |
| 1203 | p = jfind k |
| 1204 | if eq p NONE |
| 1205 | ret false |
| 1206 | end |
| 1207 | if gt add p len t get cu RRESP |
| 1208 | ret false |
| 1209 | end |
| 1210 | ret mtext p t |
| 1211 | end |
| 1212 | |
| 1213 | note jatt: copy the response's attempt_id into slot s of RATT. |
| 1214 | fn jatt s ulong to bool |
| 1215 | o = add get bs RATT mul s 256 |
| 1216 | put g add GAL0 s 0 |
| 1217 | p = jfind kaid |
| 1218 | if eq p NONE |
| 1219 | ret false |
| 1220 | end |
| 1221 | q = findc p get cu RRESP 34 |
| 1222 | n = sub q p |
| 1223 | if gt n 255 |
| 1224 | ret false |
| 1225 | end |
| 1226 | for i ulong n |
| 1227 | put m add o i get m add p i |
| 1228 | end |
| 1229 | put g add GAL0 s n |
| 1230 | ret true |
| 1231 | end |
| 1232 | |
| 1233 | fn aidset s ulong to void |
| 1234 | rsz RAID |
| 1235 | apm RAID add get bs RATT mul s 256 get g add GAL0 s |
| 1236 | end |
| 1237 | |
| 1238 | fn gen0 v ulong to ulong |
| 1239 | if eq v NONE |
| 1240 | ret 0 |
| 1241 | end |
| 1242 | ret v |
| 1243 | end |
| 1244 | |
| 1245 | note ---- request bodies |
| 1246 | fn settid t view uchar * to void |
| 1247 | rsz RTID |
| 1248 | ap RTID t |
| 1249 | end |
| 1250 | |
| 1251 | fn setart t view uchar * to void |
| 1252 | rsz RART |
| 1253 | ap RART t |
| 1254 | end |
| 1255 | |
| 1256 | fn bopen to void |
| 1257 | rsz RBODY |
| 1258 | ap RBODY jtid |
| 1259 | apr RBODY RTID |
| 1260 | ap RBODY dq |
| 1261 | if eq get g GCMD 1 |
| 1262 | ap RBODY jcmd |
| 1263 | apr RBODY RCMD |
| 1264 | ap RBODY dq |
| 1265 | end |
| 1266 | end |
| 1267 | |
| 1268 | fn bagent a view uchar * to void |
| 1269 | ap RBODY jagent |
| 1270 | ap RBODY a |
| 1271 | ap RBODY dq |
| 1272 | end |
| 1273 | |
| 1274 | fn bfence gn ulong to void |
| 1275 | ap RBODY jaid |
| 1276 | apr RBODY RAID |
| 1277 | ap RBODY dq |
| 1278 | ap RBODY jgenk |
| 1279 | apd RBODY gn |
| 1280 | end |
| 1281 | |
| 1282 | fn bttl t ulong to void |
| 1283 | ap RBODY jttl |
| 1284 | apd RBODY t |
| 1285 | ap RBODY cbr |
| 1286 | end |
| 1287 | |
| 1288 | fn bsub to void |
| 1289 | ap RBODY jbr |
| 1290 | apr RBODY RART |
| 1291 | ap RBODY dq |
| 1292 | ap RBODY cbr |
| 1293 | end |
| 1294 | |
| 1295 | fn bver gn ulong vd ulong vf bool to void |
| 1296 | ap RBODY jgenk |
| 1297 | apd RBODY gn |
| 1298 | ap RBODY jart |
| 1299 | apr RBODY RART |
| 1300 | ap RBODY dq |
| 1301 | ap RBODY jvby |
| 1302 | if vf |
| 1303 | ap RBODY tver |
| 1304 | end |
| 1305 | ap RBODY dq |
| 1306 | ap RBODY jvd |
| 1307 | if eq vd 1 |
| 1308 | ap RBODY jtrue |
| 1309 | else |
| 1310 | ap RBODY jfalse |
| 1311 | end |
| 1312 | ap RBODY jnotes |
| 1313 | end |
| 1314 | |
| 1315 | note claim: POST claim for RTID by agent a with ttl t; the attempt goes to slot s; returns |
| 1316 | note the HTTP status, and the granted generation in g[GBODY]'s place is read by the caller. |
| 1317 | fn claim slot ulong a view uchar * t ulong s ulong to ulong |
| 1318 | bopen |
| 1319 | bagent a |
| 1320 | bttl t |
| 1321 | code = hpost slot pclaim |
| 1322 | ok = jatt s |
| 1323 | ret code |
| 1324 | end |
| 1325 | |
| 1326 | fn hbeat a view uchar * gn ulong t ulong to ulong |
| 1327 | bopen |
| 1328 | bagent a |
| 1329 | bfence gn |
| 1330 | bttl t |
| 1331 | ret hpost 0 phb |
| 1332 | end |
| 1333 | |
| 1334 | fn submit a view uchar * gn ulong to ulong |
| 1335 | bopen |
| 1336 | bagent a |
| 1337 | bfence gn |
| 1338 | bsub |
| 1339 | ret hpost 0 psub |
| 1340 | end |
| 1341 | |
| 1342 | fn verify gn ulong vd ulong vf bool to ulong |
| 1343 | bopen |
| 1344 | bver gn vd vf |
| 1345 | ret hpost 0 pver |
| 1346 | end |
| 1347 | |
| 1348 | note ---- command ids: while g[GCMD] is 1 every body carries "command_id": RCMD. |
| 1349 | fn setcmd t view uchar * to void |
| 1350 | rsz RCMD |
| 1351 | ap RCMD t |
| 1352 | put g GCMD 1 |
| 1353 | end |
| 1354 | |
| 1355 | fn nocmd to void |
| 1356 | put g GCMD 0 |
| 1357 | end |
| 1358 | |
| 1359 | fn tpad n ulong to void |
| 1360 | while lt rln RCMD n bound 256 |
| 1361 | pb RCMD 97 |
| 1362 | end |
| 1363 | end |
| 1364 | |
| 1365 | fn reclaimc to ulong |
| 1366 | rsz RBODY |
| 1367 | ap RBODY jrcmd |
| 1368 | apr RBODY RCMD |
| 1369 | ap RBODY jrend |
| 1370 | ret hpost 0 prec |
| 1371 | end |
| 1372 | |
| 1373 | note bsave keeps the body of the last response; bsame compares the last response's body with it. |
| 1374 | fn bsave to void |
| 1375 | b = get g GBODY |
| 1376 | rsz RSAVE |
| 1377 | apm RSAVE b sub get cu RRESP b |
| 1378 | end |
| 1379 | |
| 1380 | fn bsame to bool |
| 1381 | b = get g GBODY |
| 1382 | n = sub get cu RRESP b |
| 1383 | if ne n rln RSAVE |
| 1384 | ret false |
| 1385 | end |
| 1386 | ret same b get bs RSAVE n |
| 1387 | end |
| 1388 | |
| 1389 | note rowsave keeps generation, attempt, lease and status of s10; rowsame compares them again. |
| 1390 | note A schema without those columns (main) fails rowsame rather than stopping the driver. |
| 1391 | fn rowq to bool |
| 1392 | rsz RSQL |
| 1393 | ap RSQL sqhd |
| 1394 | ap RSQL trow10 |
| 1395 | ret eq sqlrun 0 |
| 1396 | end |
| 1397 | |
| 1398 | fn rowsave to void |
| 1399 | ok = rowq |
| 1400 | rsz RROW |
| 1401 | if ok |
| 1402 | apr RROW RFILE |
| 1403 | end |
| 1404 | end |
| 1405 | |
| 1406 | fn rowsame to bool |
| 1407 | if not rowq |
| 1408 | ret false |
| 1409 | end |
| 1410 | if ne rln RFILE rln RROW |
| 1411 | ret false |
| 1412 | end |
| 1413 | ret same get bs RFILE get bs RROW rln RROW |
| 1414 | end |
| 1415 | |
| 1416 | note ---- cockpit processes |
| 1417 | fn freeport to ulong |
| 1418 | a = new uchar 16 0 |
| 1419 | put a 0 2 |
| 1420 | put a 4 127 |
| 1421 | put a 7 1 |
| 1422 | fd = socknew 2 524289 0 |
| 1423 | ck ge fd 0 envbin |
| 1424 | r = bind int fd a 0 16 |
| 1425 | ck eq r 0 envbin |
| 1426 | k = sockname int fd a 0 16 |
| 1427 | ck ge k 0 envbin |
| 1428 | prt = or shl ulong get a 2 8 ulong get a 3 |
| 1429 | c = fclose int fd |
| 1430 | note never a port of the 18000s, where the live services listen |
| 1431 | ck or lt prt 18000 gt prt 18999 envbin |
| 1432 | ret prt |
| 1433 | end |
| 1434 | |
| 1435 | fn cockenv prt ulong to void |
| 1436 | rsz RMISC |
| 1437 | ap RMISC ehome |
| 1438 | apa RMISC 4 |
| 1439 | ap RMISC dhome |
| 1440 | xreg RMISC |
| 1441 | rsz RMISC |
| 1442 | ap RMISC edb |
| 1443 | apr RMISC RDB |
| 1444 | xreg RMISC |
| 1445 | rsz RMISC |
| 1446 | ap RMISC etok |
| 1447 | apr RMISC RTOK |
| 1448 | xreg RMISC |
| 1449 | rsz RMISC |
| 1450 | ap RMISC eaddr |
| 1451 | apd RMISC prt |
| 1452 | xreg RMISC |
| 1453 | end |
| 1454 | |
| 1455 | note cockexec: the argument list that starts cockpit binary argv[bin] on port prt. |
| 1456 | note BRIDGE: execprog gives the program an empty environment, so /usr/bin/env sets the four |
| 1457 | note variables of cockenv. When omega-mv adds the execprog variant that takes a packed environment |
| 1458 | note list, this function is the only change: drop "xa envbin" and pass the cockenv records as |
| 1459 | note that list. |
| 1460 | fn cockexec bin ulong prt ulong to void |
| 1461 | xbeg |
| 1462 | xa envbin |
| 1463 | cockenv prt |
| 1464 | xarg bin |
| 1465 | end |
| 1466 | |
| 1467 | note cockst starts cockpit binary argv[bin] as process slot and waits until it serves; false when |
| 1468 | note the process exits first or does not serve within 60 s. |
| 1469 | fn cockst slot ulong bin ulong to bool |
| 1470 | prt = freeport |
| 1471 | put g add GPORTA slot prt |
| 1472 | cockexec bin prt |
| 1473 | psc flog |
| 1474 | lf = fopa |
| 1475 | ck ge lf 0 flog |
| 1476 | if eq slot 0 |
| 1477 | put g GT0 ulong monons |
| 1478 | end |
| 1479 | pid = spawn -1 lf lf |
| 1480 | c = fclose lf |
| 1481 | ck gt pid 0 flog |
| 1482 | put g add GPIDA slot ulong pid |
| 1483 | i = ulong 0 |
| 1484 | while lt i 600 bound 600 |
| 1485 | if not alive pid |
| 1486 | put g add GPIDA slot 0 |
| 1487 | ret false |
| 1488 | end |
| 1489 | code = hgetp slot ptasks |
| 1490 | if eq code 200 |
| 1491 | ret true |
| 1492 | end |
| 1493 | z = sleepns 100000000 |
| 1494 | i = add i 1 |
| 1495 | end |
| 1496 | ret false |
| 1497 | end |
| 1498 | |
| 1499 | fn cockup slot ulong bin ulong to void |
| 1500 | ok = cockst slot bin |
| 1501 | ck ok flog |
| 1502 | end |
| 1503 | |
| 1504 | fn cockdn slot ulong to void |
| 1505 | pid = int get g add GPIDA slot |
| 1506 | if gt pid 0 |
| 1507 | r = killpid pid 15 |
| 1508 | s = reap pid |
| 1509 | end |
| 1510 | put g add GPIDA slot 0 |
| 1511 | end |
| 1512 | |
| 1513 | fn mktok to void |
| 1514 | rb = new uchar 16 0 |
| 1515 | r = random rb 0 16 0 |
| 1516 | ck eq r 16 ttokp |
| 1517 | rsz RTOK |
| 1518 | ap RTOK ttokp |
| 1519 | for i ulong 16 |
| 1520 | v = get rb i |
| 1521 | pb RTOK hexd shr v 4 |
| 1522 | pb RTOK hexd and v 15 |
| 1523 | end |
| 1524 | end |
| 1525 | |
| 1526 | fn sqtask t view uchar * to void |
| 1527 | ap RSQL sqi1 |
| 1528 | ap RSQL t |
| 1529 | ap RSQL sqi2 |
| 1530 | end |
| 1531 | |
| 1532 | note ---- http mode scenarios |
| 1533 | fn screate to void |
| 1534 | rsz RBODY |
| 1535 | ap RBODY jcreate |
| 1536 | code = hpost 0 ptasks |
| 1537 | rep eq code 201 n_create |
| 1538 | end |
| 1539 | |
| 1540 | fn st1 to void |
| 1541 | settid ts1 |
| 1542 | setart asha0 |
| 1543 | code = verify 0 1 true |
| 1544 | rep and eq code 409 jis kstat vopen n_t1 |
| 1545 | end |
| 1546 | |
| 1547 | fn st2t3 to void |
| 1548 | settid ts2 |
| 1549 | c1 = claim 0 agw2 300 0 |
| 1550 | gn = gen0 jnum kgen |
| 1551 | rep eq c1 200 n_t2a |
| 1552 | aidset 0 |
| 1553 | setart asha2 |
| 1554 | c2 = submit agw2 gn |
| 1555 | rep eq c2 200 n_t2b |
| 1556 | c3 = verify gn 1 true |
| 1557 | rep and eq c3 200 jis kstat vver n_t2c |
| 1558 | c4 = claim 0 agw3 300 1 |
| 1559 | rep and eq c4 409 jis kstat vver n_t2 |
| 1560 | c5 = submit agw2 gn |
| 1561 | rep and eq c5 409 jis kstat vver n_t3 |
| 1562 | end |
| 1563 | |
| 1564 | fn sverif to void |
| 1565 | settid ts3 |
| 1566 | c1 = claim 0 agw3 300 0 |
| 1567 | gn = gen0 jnum kgen |
| 1568 | rep eq c1 200 n_va |
| 1569 | aidset 0 |
| 1570 | setart asha3 |
| 1571 | c2 = submit agw3 gn |
| 1572 | rep and eq c2 200 and jis kartk vsha3 jis kbr vbr n_vb |
| 1573 | setart ashax |
| 1574 | c3 = verify gn 1 true |
| 1575 | rep and eq c3 409 jis kstat vsub n_vc |
| 1576 | setart asha3 |
| 1577 | c4 = verify add gn 1 1 true |
| 1578 | rep and eq c4 409 jis kstat vsub n_vd |
| 1579 | c5 = verify gn 1 false |
| 1580 | rep eq c5 400 n_ve |
| 1581 | c6 = verify gn 1 true |
| 1582 | rep and eq c6 200 and jis kvby vver2 jis kvn vnotes n_vf |
| 1583 | end |
| 1584 | |
| 1585 | fn sstale to void |
| 1586 | settid ts4 |
| 1587 | c1 = claim 0 agwk 1 0 |
| 1588 | g1 = gen0 jnum kgen |
| 1589 | rep eq c1 200 n_sa |
| 1590 | z = sleepns 1500000000 |
| 1591 | c2 = claim 0 agwk 300 1 |
| 1592 | g2 = gen0 jnum kgen |
| 1593 | rep and eq c2 200 eq g2 add g1 1 n_sb |
| 1594 | aidset 0 |
| 1595 | c3 = hbeat agwk g1 300 |
| 1596 | rep eq c3 409 n_sc |
| 1597 | setart asha0 |
| 1598 | c4 = submit agwk g1 |
| 1599 | rep eq c4 409 n_sd |
| 1600 | aidset 1 |
| 1601 | c5 = hbeat agwk g2 300 |
| 1602 | rep eq c5 200 n_se |
| 1603 | end |
| 1604 | |
| 1605 | fn sexpire to void |
| 1606 | settid ts5 |
| 1607 | c1 = claim 0 agw5 1 0 |
| 1608 | gn = gen0 jnum kgen |
| 1609 | rep eq c1 200 n_ea |
| 1610 | aidset 0 |
| 1611 | z = sleepns 1500000000 |
| 1612 | c2 = hbeat agw5 gn 300 |
| 1613 | rep and eq c2 409 eq jnum kgen gn n_eb |
| 1614 | setart asha0 |
| 1615 | c3 = submit agw5 gn |
| 1616 | ok = and eq c3 409 eq jnum kgen gn |
| 1617 | rsz RSQL |
| 1618 | ap RSQL sqhd |
| 1619 | ap RSQL tss5 |
| 1620 | r = sqlrun |
| 1621 | rep and ok and eq r 0 not rtext RFILE tsubnl n_ec |
| 1622 | end |
| 1623 | |
| 1624 | fn sexhaust to void |
| 1625 | rsz RSQL |
| 1626 | ap RSQL sqhd |
| 1627 | ap RSQL tsx6 |
| 1628 | r = sqlrun |
| 1629 | put g GLAST 0 |
| 1630 | rep eq r 0 n_xa |
| 1631 | settid ts6 |
| 1632 | c1 = claim 0 agw6 300 0 |
| 1633 | rep eq c1 409 n_xb |
| 1634 | settid ts7 |
| 1635 | c2 = claim 0 agw6 300 0 |
| 1636 | gn = jnum kgen |
| 1637 | rep and eq c2 200 eq gn GMAX n_xc |
| 1638 | aidset 0 |
| 1639 | c3 = hbeat agw6 gen0 gn 300 |
| 1640 | rep and eq c3 200 eq jnum kgen GMAX n_xd |
| 1641 | end |
| 1642 | |
| 1643 | fn sttl to void |
| 1644 | settid ts9 |
| 1645 | c1 = claim 0 agw9 0 0 |
| 1646 | rep and eq c1 400 jis kcode vinval n_ta |
| 1647 | c2 = claim 0 agw9 86401 0 |
| 1648 | rep and eq c2 400 jis kcode vinval n_tb |
| 1649 | c3 = claim 0 agw9 86400 0 |
| 1650 | gn = gen0 jnum kgen |
| 1651 | rep eq c3 200 n_tc |
| 1652 | aidset 0 |
| 1653 | c4 = hbeat agw9 gn 0 |
| 1654 | rep and eq c4 400 jis kcode vinval n_td |
| 1655 | end |
| 1656 | |
| 1657 | note sjson: a claim body without agent_id, and a body that is not JSON, answer 400 invalid. |
| 1658 | fn sjson to void |
| 1659 | rsz RBODY |
| 1660 | ap RBODY jbadm |
| 1661 | c1 = hpost 0 pclaim |
| 1662 | rep and eq c1 400 jis kcode vinval n_ja |
| 1663 | rsz RBODY |
| 1664 | ap RBODY jbadj |
| 1665 | c2 = hpost 0 pclaim |
| 1666 | rep and eq c2 400 jis kcode vinval n_jb |
| 1667 | end |
| 1668 | |
| 1669 | fn le32 a view uchar * o ulong to int |
| 1670 | v = or ulong get a o shl ulong get a add o 1 8 |
| 1671 | v = or v or shl ulong get a add o 2 16 shl ulong get a add o 3 24 |
| 1672 | ret int v |
| 1673 | end |
| 1674 | |
| 1675 | note bheld: read sqlite3's stdout until "held" (4 bytes or more) arrives; 10 s at most. |
| 1676 | fn bheld ro int to bool |
| 1677 | lb = new uchar 4096 0 |
| 1678 | n = ulong 0 |
| 1679 | i = ulong 0 |
| 1680 | while lt i 100 bound 100 |
| 1681 | w = waitio ro 1 100000000 |
| 1682 | if gt w 0 |
| 1683 | k = read ro lb n sub 4096 n |
| 1684 | if gt k 0 |
| 1685 | n = add n ulong k |
| 1686 | end |
| 1687 | end |
| 1688 | if ge n 4 |
| 1689 | ret true |
| 1690 | end |
| 1691 | i = add i 1 |
| 1692 | end |
| 1693 | ret false |
| 1694 | end |
| 1695 | |
| 1696 | fn bclaim to void |
| 1697 | settid ts8 |
| 1698 | t0 = monons |
| 1699 | c = claim 0 agw9 300 0 |
| 1700 | dt = sub monons t0 |
| 1701 | ok = and eq c 503 and jis kcode vbusy jis kretry jtrue |
| 1702 | say tbusyw |
| 1703 | apd ROUT ulong div dt 1000000 |
| 1704 | sp ROUT |
| 1705 | rep ok n_bb |
| 1706 | end |
| 1707 | |
| 1708 | note holdon: sqlite3 on RDB runs script t and keeps its transaction open; true once it printed |
| 1709 | note "held". holdoff rolls it back and reaps the process. |
| 1710 | fn holdon t view uchar * to bool |
| 1711 | pi = new uchar 8 0 |
| 1712 | po = new uchar 8 0 |
| 1713 | ck eq pipefds pi 0 8 524288 0 tbheld |
| 1714 | ck eq pipefds po 0 8 524288 0 tbheld |
| 1715 | xbeg |
| 1716 | xa sqlbin |
| 1717 | xa sqbatch |
| 1718 | xreg RDB |
| 1719 | pid = spawn le32 pi 0 le32 po 4 -1 |
| 1720 | z = fclose le32 pi 0 |
| 1721 | z = fclose le32 po 4 |
| 1722 | wi = le32 pi 4 |
| 1723 | ro = le32 po 0 |
| 1724 | put g GH ulong pid |
| 1725 | put g add GH 1 ulong wi |
| 1726 | put g add GH 2 ulong ro |
| 1727 | z = write wi t 0 len t |
| 1728 | ret bheld ro |
| 1729 | end |
| 1730 | |
| 1731 | fn holdoff to void |
| 1732 | wi = int get g add GH 1 |
| 1733 | z = write wi tbrb 0 len tbrb |
| 1734 | z = fclose wi |
| 1735 | z = reap int get g GH |
| 1736 | z = fclose int get g add GH 2 |
| 1737 | end |
| 1738 | |
| 1739 | note sbusy: sqlite3 holds BEGIN IMMEDIATE on the database while the cockpit claims with a |
| 1740 | note command id; the busy answer is not recorded, so the same id is granted after the release. |
| 1741 | fn sbusy to void |
| 1742 | ok = holdon tbsql |
| 1743 | put g GLAST 0 |
| 1744 | rep ok n_ba |
| 1745 | setcmd cidb1 |
| 1746 | bclaim |
| 1747 | holdoff |
| 1748 | c = claim 0 agw9 300 0 |
| 1749 | nocmd |
| 1750 | rep eq c 200 n_bc |
| 1751 | end |
| 1752 | |
| 1753 | note sreplay: claim, heartbeat, submit and verify of s10, each sent twice with one command id. |
| 1754 | fn sreplay to void |
| 1755 | settid ts10 |
| 1756 | setcmd cidc1 |
| 1757 | c1 = claim 0 agw2 300 0 |
| 1758 | gn = gen0 jnum kgen |
| 1759 | rep eq c1 200 n_ra |
| 1760 | bsave |
| 1761 | rowsave |
| 1762 | c2 = claim 0 agw2 300 1 |
| 1763 | rep and eq c2 200 bsame n_rb |
| 1764 | rep rowsame n_rc |
| 1765 | c3 = claim 0 agw2 301 1 |
| 1766 | rep and eq c3 409 jis kcode vcmdc n_rd |
| 1767 | aidset 0 |
| 1768 | sreplay2 gn |
| 1769 | end |
| 1770 | |
| 1771 | fn sreplay2 gn ulong to void |
| 1772 | setcmd cidh1 |
| 1773 | c1 = hbeat agw2 gn 300 |
| 1774 | bsave |
| 1775 | rowsave |
| 1776 | z = sleepns 20000000 |
| 1777 | c2 = hbeat agw2 gn 300 |
| 1778 | rep and and eq c1 200 eq c2 200 and bsame rowsame n_re |
| 1779 | setart asha2 |
| 1780 | setcmd cidu1 |
| 1781 | c3 = submit agw2 gn |
| 1782 | bsave |
| 1783 | c4 = submit agw2 gn |
| 1784 | rep and and eq c3 200 eq c4 200 bsame n_rf |
| 1785 | setcmd cidv1 |
| 1786 | c5 = verify gn 1 true |
| 1787 | bsave |
| 1788 | c6 = verify gn 1 true |
| 1789 | rep and and eq c5 200 eq c6 200 bsame n_rg |
| 1790 | nocmd |
| 1791 | end |
| 1792 | |
| 1793 | note scmdid: id length 128 is accepted (verified s10 refuses the claim), 129 and a bad byte are |
| 1794 | note 400 invalid; then a refused claim is not recorded, so its id is decided again later. |
| 1795 | fn scmdid to void |
| 1796 | settid ts10 |
| 1797 | rsz RCMD |
| 1798 | ap RCMD cidp |
| 1799 | tpad 128 |
| 1800 | put g GCMD 1 |
| 1801 | c1 = claim 0 agw2 300 0 |
| 1802 | rep and eq c1 409 jis kcode vrefus n_rj |
| 1803 | settid ts11 |
| 1804 | tpad 129 |
| 1805 | c2 = claim 0 agw2 300 0 |
| 1806 | rep and eq c2 400 jis kcode vinval n_ri |
| 1807 | setcmd cidbad |
| 1808 | c3 = claim 0 agw2 300 0 |
| 1809 | rep and eq c3 400 jis kcode vinval n_rk |
| 1810 | nocmd |
| 1811 | c4 = claim 0 agw3 1 0 |
| 1812 | setcmd cidx1 |
| 1813 | c5 = claim 0 agw2 300 1 |
| 1814 | z = sleepns 1500000000 |
| 1815 | c6 = claim 0 agw2 300 1 |
| 1816 | nocmd |
| 1817 | rep and and eq c4 200 eq c5 409 eq c6 200 n_rl |
| 1818 | end |
| 1819 | |
| 1820 | fn sexp t view uchar * to bool |
| 1821 | rsz RSQL |
| 1822 | ap RSQL sqhd |
| 1823 | ap RSQL texp1 |
| 1824 | ap RSQL t |
| 1825 | ap RSQL tqend |
| 1826 | ret eq sqlrun 0 |
| 1827 | end |
| 1828 | |
| 1829 | note srecl: a reclaim sweep with a command id, replayed after another lease expired, must not |
| 1830 | note sweep again; then every recorded id is in forge_commands exactly once. |
| 1831 | fn srecl to void |
| 1832 | ok1 = sexp ts12 |
| 1833 | setcmd cidr1 |
| 1834 | c1 = reclaimc |
| 1835 | bsave |
| 1836 | ok2 = sexp ts13 |
| 1837 | c2 = reclaimc |
| 1838 | nocmd |
| 1839 | ok3 = sqlis tss13 tclnl |
| 1840 | rep and and ok1 ok2 and and eq c1 200 eq c2 200 and bsame ok3 n_rh |
| 1841 | put g GLAST 0 |
| 1842 | rep sqlis tcnt tcntw n_rm |
| 1843 | end |
| 1844 | |
| 1845 | fn rtally ca ulong cb ulong to void |
| 1846 | n = ulong 0 |
| 1847 | if eq ca 200 |
| 1848 | n = add n 1 |
| 1849 | end |
| 1850 | if eq cb 200 |
| 1851 | n = add n 1 |
| 1852 | end |
| 1853 | inc add GRZ n |
| 1854 | if ne ca 200 |
| 1855 | loser ca |
| 1856 | end |
| 1857 | if ne cb 200 |
| 1858 | loser cb |
| 1859 | end |
| 1860 | end |
| 1861 | |
| 1862 | fn loser c ulong to void |
| 1863 | if eq c 409 |
| 1864 | inc GLREF |
| 1865 | ret |
| 1866 | end |
| 1867 | if eq c 503 |
| 1868 | inc GLBUSY |
| 1869 | ret |
| 1870 | end |
| 1871 | inc GLOTH |
| 1872 | end |
| 1873 | |
| 1874 | note srace: 400 trials; in each, two connections to two cockpit processes on one database file |
| 1875 | note claim the same open task; both requests are sent before either response is read. |
| 1876 | fn srace to void |
| 1877 | cockup 1 3 |
| 1878 | rsz RSQL |
| 1879 | ap RSQL sqhd |
| 1880 | ap RSQL sqbeg |
| 1881 | for i ulong 400 |
| 1882 | ap RSQL sqi1 |
| 1883 | pb RSQL 114 |
| 1884 | apd RSQL i |
| 1885 | ap RSQL sqi2 |
| 1886 | end |
| 1887 | ap RSQL sqcom |
| 1888 | ck eq sqlrun 0 n_race |
| 1889 | for i ulong 400 |
| 1890 | rsz RTID |
| 1891 | pb RTID 114 |
| 1892 | apd RTID i |
| 1893 | bopen |
| 1894 | bagent agra |
| 1895 | bttl 300 |
| 1896 | hbuild RREQ true pclaim |
| 1897 | bopen |
| 1898 | bagent agrb |
| 1899 | bttl 300 |
| 1900 | hbuild RREQ2 true pclaim |
| 1901 | fa = hconn get g GPORTA |
| 1902 | fb = hconn add get g GPORTA 0 |
| 1903 | fb2 = hconn get g add GPORTA 1 |
| 1904 | if ge fb 0 |
| 1905 | c0 = fclose fb |
| 1906 | end |
| 1907 | if eq and i 1 0 |
| 1908 | oa = hput fa RREQ |
| 1909 | ob = hput fb2 RREQ2 |
| 1910 | else |
| 1911 | ob = hput fb2 RREQ2 |
| 1912 | oa = hput fa RREQ |
| 1913 | end |
| 1914 | ca = hrecv fa |
| 1915 | cb = hrecv fb2 |
| 1916 | rtally ca cb |
| 1917 | end |
| 1918 | rsz RSQL |
| 1919 | ap RSQL sqhd |
| 1920 | ap RSQL trq |
| 1921 | r = sqlrun |
| 1922 | dbc = pnum get bs RFILE get cu RFILE |
| 1923 | grants = add get g add GRZ 1 mul 2 get g add GRZ 2 |
| 1924 | put g GLAST 0 |
| 1925 | say trace1 |
| 1926 | apd ROUT get g add GRZ 1 |
| 1927 | say trace2 |
| 1928 | apd ROUT get g GRZ |
| 1929 | say trace3 |
| 1930 | apd ROUT get g add GRZ 2 |
| 1931 | say trace4 |
| 1932 | apd ROUT get g GLREF |
| 1933 | say trace5 |
| 1934 | apd ROUT get g GLBUSY |
| 1935 | say trace6 |
| 1936 | apd ROUT get g GLOTH |
| 1937 | say trace7 |
| 1938 | apd ROUT dbc |
| 1939 | sp ROUT |
| 1940 | ok = and and eq get g add GRZ 1 400 eq get g GLOTH 0 and eq r 0 eq dbc grants |
| 1941 | rep ok n_race |
| 1942 | end |
| 1943 | |
| 1944 | note scross: one command id sent to both cockpit processes replays the first answer. |
| 1945 | fn scross to void |
| 1946 | settid ts14 |
| 1947 | setcmd cidk1 |
| 1948 | c1 = claim 0 agw3 300 0 |
| 1949 | bsave |
| 1950 | c2 = claim 1 agw3 300 1 |
| 1951 | rep and and eq c1 200 eq c2 200 bsame n_rx |
| 1952 | c3 = claim 1 agw3 301 1 |
| 1953 | rep and eq c3 409 jis kcode vcmdc n_ry |
| 1954 | nocmd |
| 1955 | end |
| 1956 | |
| 1957 | fn rqtally ca ulong cb ulong to void |
| 1958 | if and eq ca 200 eq cb 200 |
| 1959 | if bsame |
| 1960 | inc GQ |
| 1961 | ret |
| 1962 | end |
| 1963 | inc add GQ 2 |
| 1964 | ret |
| 1965 | end |
| 1966 | if or and eq ca 200 eq cb 503 and eq ca 503 eq cb 200 |
| 1967 | inc add GQ 1 |
| 1968 | ret |
| 1969 | end |
| 1970 | inc add GQ 2 |
| 1971 | end |
| 1972 | |
| 1973 | note sreprace: 40 trials; both cockpit processes get the identical claim with one command id at |
| 1974 | note once. Each trial must answer the same body twice (or 200 and 503), with one record per id. |
| 1975 | fn sreprace to void |
| 1976 | rsz RSQL |
| 1977 | ap RSQL sqhd |
| 1978 | ap RSQL sqbeg |
| 1979 | for i ulong 40 |
| 1980 | ap RSQL sqi1 |
| 1981 | pb RSQL 113 |
| 1982 | apd RSQL i |
| 1983 | ap RSQL sqi2 |
| 1984 | end |
| 1985 | ap RSQL sqcom |
| 1986 | ck eq sqlrun 0 n_rr |
| 1987 | for j ulong 40 |
| 1988 | rqtrial j |
| 1989 | end |
| 1990 | nocmd |
| 1991 | put g GLAST 0 |
| 1992 | say trr1 |
| 1993 | apd ROUT get g GQ |
| 1994 | say trr2 |
| 1995 | apd ROUT get g add GQ 1 |
| 1996 | say trr3 |
| 1997 | apd ROUT get g add GQ 2 |
| 1998 | sp ROUT |
| 1999 | rep and eq get g add GQ 2 0 sqlis trq2 t4040 n_rr |
| 2000 | end |
| 2001 | |
| 2002 | fn rqtrial i ulong to void |
| 2003 | rsz RTID |
| 2004 | pb RTID 113 |
| 2005 | apd RTID i |
| 2006 | rsz RCMD |
| 2007 | ap RCMD cidq |
| 2008 | apd RCMD i |
| 2009 | put g GCMD 1 |
| 2010 | bopen |
| 2011 | bagent agra |
| 2012 | bttl 300 |
| 2013 | hbuild RREQ true pclaim |
| 2014 | hbuild RREQ2 true pclaim |
| 2015 | fa = hconn get g GPORTA |
| 2016 | fb = hconn get g add GPORTA 1 |
| 2017 | if eq and i 1 0 |
| 2018 | oa = hput fa RREQ |
| 2019 | ob = hput fb RREQ2 |
| 2020 | else |
| 2021 | ob = hput fb RREQ2 |
| 2022 | oa = hput fa RREQ |
| 2023 | end |
| 2024 | ca = hrecv fa |
| 2025 | bsave |
| 2026 | cb = hrecv fb |
| 2027 | rqtally ca cb |
| 2028 | end |
| 2029 | |
| 2030 | note slock: sqlite3 holds BEGIN IMMEDIATE while one request waits in the cockpit's busy handler |
| 2031 | note for 2 s, longer than the 1 s ttl, then releases it. A claim must get a lease that is still |
| 2032 | note live after it is granted; a heartbeat or submit whose lease ran out during the wait must be |
| 2033 | note refused with the row unchanged, and its command id is not recorded, so a retry is refused too. |
| 2034 | fn slock to void |
| 2035 | slkc ts15 n_lk2 |
| 2036 | setcmd cidl1 |
| 2037 | slkc ts16 n_lk3 |
| 2038 | nocmd |
| 2039 | slkh |
| 2040 | slkhc |
| 2041 | slks |
| 2042 | end |
| 2043 | |
| 2044 | note lockreq: POST RBODY to path on cockpit 0 while sqlite3 holds the write lock for 2 s. |
| 2045 | fn lockreq path view uchar * to ulong |
| 2046 | ok = holdon tbsql |
| 2047 | ck ok n_lk1 |
| 2048 | hbuild RREQ true path |
| 2049 | fd = hconn get g GPORTA |
| 2050 | ck ge fd 0 n_lk1 |
| 2051 | ok2 = hput fd RREQ |
| 2052 | ck ok2 n_lk1 |
| 2053 | z = sleepns 2000000000 |
| 2054 | holdoff |
| 2055 | ret hrecv fd |
| 2056 | end |
| 2057 | |
| 2058 | fn sqtid pre view uchar * want view uchar * to bool |
| 2059 | rsz RSQL |
| 2060 | ap RSQL sqhd |
| 2061 | ap RSQL pre |
| 2062 | apr RSQL RTID |
| 2063 | ap RSQL tqend |
| 2064 | r = sqlrun |
| 2065 | ret and eq r 0 rtext RFILE want |
| 2066 | end |
| 2067 | |
| 2068 | fn rowqt to bool |
| 2069 | rsz RSQL |
| 2070 | ap RSQL sqhd |
| 2071 | ap RSQL trowa |
| 2072 | apr RSQL RTID |
| 2073 | ap RSQL tqend |
| 2074 | ret eq sqlrun 0 |
| 2075 | end |
| 2076 | |
| 2077 | fn rowsavt to void |
| 2078 | ok = rowqt |
| 2079 | rsz RROW |
| 2080 | if ok |
| 2081 | apr RROW RFILE |
| 2082 | end |
| 2083 | end |
| 2084 | |
| 2085 | fn rowsamet to bool |
| 2086 | if not rowqt |
| 2087 | ret false |
| 2088 | end |
| 2089 | if ne rln RFILE rln RROW |
| 2090 | ret false |
| 2091 | end |
| 2092 | ret same get bs RFILE get bs RROW rln RROW |
| 2093 | end |
| 2094 | |
| 2095 | fn slkc t view uchar * name view uchar * to void |
| 2096 | settid t |
| 2097 | bopen |
| 2098 | bagent agw2 |
| 2099 | bttl 1 |
| 2100 | c = lockreq pclaim |
| 2101 | rep and eq c 200 sqtid tlive tlivew name |
| 2102 | end |
| 2103 | |
| 2104 | note lkclaim: a fresh 1 s lease on task t for w2, its fence kept in RAID and the row saved; |
| 2105 | note NONE when the claim is not granted. |
| 2106 | fn lkclaim t view uchar * to ulong |
| 2107 | settid t |
| 2108 | c = claim 0 agw2 1 0 |
| 2109 | if ne c 200 |
| 2110 | ret NONE |
| 2111 | end |
| 2112 | gn = gen0 jnum kgen |
| 2113 | aidset 0 |
| 2114 | rowsavt |
| 2115 | ret gn |
| 2116 | end |
| 2117 | |
| 2118 | fn slkh to void |
| 2119 | gn = lkclaim ts17 |
| 2120 | bopen |
| 2121 | bagent agw2 |
| 2122 | bfence gn |
| 2123 | bttl 300 |
| 2124 | c = lockreq phb |
| 2125 | rep and and ne gn NONE eq c 409 rowsamet n_lk4 |
| 2126 | end |
| 2127 | |
| 2128 | fn slkhc to void |
| 2129 | gn = lkclaim ts18 |
| 2130 | setcmd cidl2 |
| 2131 | bopen |
| 2132 | bagent agw2 |
| 2133 | bfence gn |
| 2134 | bttl 300 |
| 2135 | c1 = lockreq phb |
| 2136 | c2 = hpost 0 phb |
| 2137 | nocmd |
| 2138 | ok = sqlis tlkcnt tlkcntw |
| 2139 | rep and and and ne gn NONE eq c1 409 and eq c2 409 rowsamet ok n_lk5 |
| 2140 | end |
| 2141 | |
| 2142 | fn slks to void |
| 2143 | gn = lkclaim ts19 |
| 2144 | setart asha2 |
| 2145 | bopen |
| 2146 | bagent agw2 |
| 2147 | bfence gn |
| 2148 | bsub |
| 2149 | c = lockreq psub |
| 2150 | rep and and ne gn NONE eq c 409 rowsamet n_lk6 |
| 2151 | end |
| 2152 | |
| 2153 | note scommit: a rollback-journal database with a reader holding its lock, so no commit can |
| 2154 | note finish. The cockpit must refuse to serve it (the branch requires WAL mode and exits), and |
| 2155 | note the task row must be unchanged. A cockpit that serves fails, whatever its claim answers. |
| 2156 | fn scommit to void |
| 2157 | rsz RDB |
| 2158 | apa RDB 4 |
| 2159 | ap RDB fcomdb |
| 2160 | cockup 0 3 |
| 2161 | rsz RSQL |
| 2162 | ap RSQL sqhd |
| 2163 | sqtask tc1 |
| 2164 | ck eq sqlrun 0 sqi1 |
| 2165 | cockdn 0 |
| 2166 | ok1 = sqlis tdelj tdelw |
| 2167 | ok2 = holdon tbsql2 |
| 2168 | put g GLAST 0 |
| 2169 | rep and ok1 ok2 n_cfa |
| 2170 | srv = cockst 0 3 |
| 2171 | code = ulong 0 |
| 2172 | if srv |
| 2173 | settid tc1 |
| 2174 | code = claim 0 agw2 300 0 |
| 2175 | end |
| 2176 | holdoff |
| 2177 | cockdn 0 |
| 2178 | ok3 = sqlis tcomq tcopen |
| 2179 | say tcom1 |
| 2180 | if srv |
| 2181 | pb ROUT 49 |
| 2182 | else |
| 2183 | pb ROUT 48 |
| 2184 | end |
| 2185 | say tcom2 |
| 2186 | apd ROUT code |
| 2187 | sp ROUT |
| 2188 | put g GLAST code |
| 2189 | rep and and ok1 ok2 and not srv ok3 n_cf |
| 2190 | end |
| 2191 | |
| 2192 | fn shttp to void |
| 2193 | rsz RDB |
| 2194 | apa RDB 4 |
| 2195 | ap RDB fhttpdb |
| 2196 | cockup 0 3 |
| 2197 | rsz RSQL |
| 2198 | ap RSQL sqhd |
| 2199 | sqtask ts1 |
| 2200 | sqtask ts2 |
| 2201 | sqtask ts3 |
| 2202 | sqtask ts4 |
| 2203 | sqtask ts5 |
| 2204 | sqtask ts6 |
| 2205 | sqtask ts7 |
| 2206 | sqtask ts8 |
| 2207 | sqtask ts9 |
| 2208 | sqtask ts10 |
| 2209 | sqtask ts11 |
| 2210 | sqtask ts12 |
| 2211 | sqtask ts13 |
| 2212 | sqtask ts14 |
| 2213 | sqtask ts15 |
| 2214 | sqtask ts16 |
| 2215 | sqtask ts17 |
| 2216 | sqtask ts18 |
| 2217 | sqtask ts19 |
| 2218 | ck eq sqlrun 0 sqi1 |
| 2219 | screate |
| 2220 | st1 |
| 2221 | st2t3 |
| 2222 | sverif |
| 2223 | sstale |
| 2224 | sexpire |
| 2225 | sexhaust |
| 2226 | sttl |
| 2227 | sjson |
| 2228 | sbusy |
| 2229 | sreplay |
| 2230 | scmdid |
| 2231 | srecl |
| 2232 | srace |
| 2233 | scross |
| 2234 | sreprace |
| 2235 | slock |
| 2236 | cockdn 1 |
| 2237 | cockdn 0 |
| 2238 | scommit |
| 2239 | end |
| 2240 | |
| 2241 | note ---- migrate mode |
| 2242 | fn sqlis q view uchar * want view uchar * to bool |
| 2243 | rsz RSQL |
| 2244 | ap RSQL sqhd |
| 2245 | ap RSQL q |
| 2246 | r = sqlrun |
| 2247 | ret and eq r 0 rtext RFILE want |
| 2248 | end |
| 2249 | |
| 2250 | fn smig to void |
| 2251 | rsz RDB |
| 2252 | apa RDB 4 |
| 2253 | ap RDB fmigdb |
| 2254 | cockup 0 7 |
| 2255 | rsz RSQL |
| 2256 | ap RSQL sqhd |
| 2257 | sqtask tm1 |
| 2258 | sqtask tm2 |
| 2259 | sqtask tm3 |
| 2260 | ck eq sqlrun 0 sqi1 |
| 2261 | settid tm2 |
| 2262 | c1 = claim 0 agold 600 0 |
| 2263 | rep eq c1 200 n_ma |
| 2264 | settid tm3 |
| 2265 | c2 = claim 0 agold 600 0 |
| 2266 | setart asha0 |
| 2267 | rsz RAID |
| 2268 | c3 = submit agold 0 |
| 2269 | rep and eq c2 200 eq c3 200 n_mb |
| 2270 | cockdn 0 |
| 2271 | put g GLAST 0 |
| 2272 | rep sqlis tcols t13 n_mc |
| 2273 | cockup 0 3 |
| 2274 | put g GLAST 0 |
| 2275 | rep sqlis tcols t21 n_md |
| 2276 | rep sqlis tmrows tmwant n_me |
| 2277 | settid tm2 |
| 2278 | c4 = claim 0 agnew 300 0 |
| 2279 | rep and eq c4 409 jis kstat vclaim n_mf |
| 2280 | settid tm1 |
| 2281 | c5 = claim 0 agnew 300 0 |
| 2282 | rep and eq c5 200 eq jnum kgen 1 n_mg |
| 2283 | settid tm3 |
| 2284 | c6 = claim 0 agnew 300 0 |
| 2285 | rep eq c6 200 n_mh |
| 2286 | cockdn 0 |
| 2287 | put g GLAST 0 |
| 2288 | rep sqlis tcmdt t1nl n_mi |
| 2289 | cockup 0 3 |
| 2290 | put g GLAST 0 |
| 2291 | rep and sqlis tcols t21 sqlis tcmdt t1nl n_mj |
| 2292 | cockdn 0 |
| 2293 | end |
| 2294 | |
| 2295 | note ---- table mode |
| 2296 | note dims: 0 state, 1 generation, 2 request generation (gen xor 0/1), 3 attempt matches, |
| 2297 | note 4 artifact matches, 5 verdict, 6 lease (live, expired, none), 7 ttl. |
| 2298 | fn fsz d ulong to ulong |
| 2299 | if eq d 0 |
| 2300 | ret 6 |
| 2301 | end |
| 2302 | if eq d 1 |
| 2303 | ret 4 |
| 2304 | end |
| 2305 | if eq d 6 |
| 2306 | ret 3 |
| 2307 | end |
| 2308 | if eq d 7 |
| 2309 | ret 4 |
| 2310 | end |
| 2311 | ret 2 |
| 2312 | end |
| 2313 | |
| 2314 | note rmask: the dims an operation reads. claim: state gen lease ttl; renew: state gen rgen |
| 2315 | note attempt lease ttl; submit: state gen rgen attempt lease; verify: state gen rgen artifact |
| 2316 | note verdict; reap: state gen lease. |
| 2317 | fn rmask op ulong to ulong |
| 2318 | if eq op 1 |
| 2319 | ret 195 |
| 2320 | end |
| 2321 | if eq op 2 |
| 2322 | ret 207 |
| 2323 | end |
| 2324 | if eq op 3 |
| 2325 | ret 79 |
| 2326 | end |
| 2327 | if eq op 4 |
| 2328 | ret 55 |
| 2329 | end |
| 2330 | ret 67 |
| 2331 | end |
| 2332 | |
| 2333 | fn dsz op ulong d ulong to ulong |
| 2334 | if eq and shr rmask op d 1 1 |
| 2335 | ret fsz d |
| 2336 | end |
| 2337 | ret 1 |
| 2338 | end |
| 2339 | |
| 2340 | fn opn op ulong to ulong |
| 2341 | n = ulong 1 |
| 2342 | for d ulong 8 |
| 2343 | n = mul n dsz op d |
| 2344 | end |
| 2345 | ret n |
| 2346 | end |
| 2347 | |
| 2348 | fn decode op ulong j ulong to void |
| 2349 | for d ulong 8 |
| 2350 | s = dsz op d |
| 2351 | put tc d rem j s |
| 2352 | j = div j s |
| 2353 | end |
| 2354 | end |
| 2355 | |
| 2356 | fn stv i ulong to ulong |
| 2357 | if lt i 5 |
| 2358 | ret i |
| 2359 | end |
| 2360 | ret 9 |
| 2361 | end |
| 2362 | |
| 2363 | fn genv i ulong to ulong |
| 2364 | if eq i 0 |
| 2365 | ret 0 |
| 2366 | end |
| 2367 | if eq i 1 |
| 2368 | ret 7 |
| 2369 | end |
| 2370 | if eq i 2 |
| 2371 | ret sub GMAX 1 |
| 2372 | end |
| 2373 | ret GMAX |
| 2374 | end |
| 2375 | |
| 2376 | fn ttlv i ulong to ulong |
| 2377 | if eq i 0 |
| 2378 | ret 0 |
| 2379 | end |
| 2380 | if eq i 1 |
| 2381 | ret 1 |
| 2382 | end |
| 2383 | if eq i 2 |
| 2384 | ret 86400 |
| 2385 | end |
| 2386 | ret 86401 |
| 2387 | end |
| 2388 | |
| 2389 | fn expv i ulong now ulong to ulong |
| 2390 | if eq i 0 |
| 2391 | ret add now 3600000 |
| 2392 | end |
| 2393 | if eq i 1 |
| 2394 | ret sub now 3600000 |
| 2395 | end |
| 2396 | ret 0 |
| 2397 | end |
| 2398 | |
| 2399 | fn apst r ulong s ulong to void |
| 2400 | if eq s 0 |
| 2401 | ap r sopen |
| 2402 | ret |
| 2403 | end |
| 2404 | if eq s 1 |
| 2405 | ap r sclaim |
| 2406 | ret |
| 2407 | end |
| 2408 | if eq s 2 |
| 2409 | ap r ssub |
| 2410 | ret |
| 2411 | end |
| 2412 | if eq s 3 |
| 2413 | ap r sver |
| 2414 | ret |
| 2415 | end |
| 2416 | if eq s 4 |
| 2417 | ap r sfail |
| 2418 | ret |
| 2419 | end |
| 2420 | ap r sunk |
| 2421 | end |
| 2422 | |
| 2423 | fn stcode a ulong b ulong to ulong |
| 2424 | n = sub b a |
| 2425 | if eq n 4 |
| 2426 | if mtext a sopen |
| 2427 | ret 0 |
| 2428 | end |
| 2429 | end |
| 2430 | if eq n 7 |
| 2431 | if mtext a sclaim |
| 2432 | ret 1 |
| 2433 | end |
| 2434 | if mtext a sunk |
| 2435 | ret 9 |
| 2436 | end |
| 2437 | end |
| 2438 | if eq n 9 |
| 2439 | if mtext a ssub |
| 2440 | ret 2 |
| 2441 | end |
| 2442 | end |
| 2443 | if eq n 8 |
| 2444 | if mtext a sver |
| 2445 | ret 3 |
| 2446 | end |
| 2447 | end |
| 2448 | if eq n 6 |
| 2449 | if mtext a sfail |
| 2450 | ret 4 |
| 2451 | end |
| 2452 | end |
| 2453 | ret 99 |
| 2454 | end |
| 2455 | |
| 2456 | note trow: the seed row x<k> and its rules input line, for the case decoded into tc. |
| 2457 | fn trow op ulong k ulong now ulong to void |
| 2458 | st = stv get tc 0 |
| 2459 | gn = genv get tc 1 |
| 2460 | ex = expv get tc 6 now |
| 2461 | ap RSQL tins1 |
| 2462 | apd RSQL k |
| 2463 | ap RSQL tins2 |
| 2464 | apst RSQL st |
| 2465 | ap RSQL tins3 |
| 2466 | apd RSQL k |
| 2467 | ap RSQL tins4 |
| 2468 | apd RSQL gn |
| 2469 | ap RSQL tcomma |
| 2470 | if eq get tc 6 2 |
| 2471 | ap RSQL tnull |
| 2472 | else |
| 2473 | apd RSQL ex |
| 2474 | end |
| 2475 | ap RSQL tins5 |
| 2476 | apd RSQL k |
| 2477 | ap RSQL tins6 |
| 2478 | apd RTIN op |
| 2479 | sp RTIN |
| 2480 | apd RTIN st |
| 2481 | sp RTIN |
| 2482 | apd RTIN gn |
| 2483 | sp RTIN |
| 2484 | apd RTIN xor gn get tc 2 |
| 2485 | tin2 now ex |
| 2486 | end |
| 2487 | |
| 2488 | fn tin2 now ulong ex ulong to void |
| 2489 | sp RTIN |
| 2490 | apd RTIN get tc 3 |
| 2491 | sp RTIN |
| 2492 | apd RTIN get tc 4 |
| 2493 | sp RTIN |
| 2494 | apd RTIN get tc 5 |
| 2495 | sp RTIN |
| 2496 | apd RTIN now |
| 2497 | sp RTIN |
| 2498 | apd RTIN ex |
| 2499 | sp RTIN |
| 2500 | apd RTIN ttlv get tc 7 |
| 2501 | nlr RTIN |
| 2502 | end |
| 2503 | |
| 2504 | fn tseed op ulong j0 ulong j1 ulong k0 ulong now ulong to void |
| 2505 | rsz RSQL |
| 2506 | ap RSQL sqhd |
| 2507 | ap RSQL sqbeg |
| 2508 | j = j0 |
| 2509 | while lt j j1 bound 4096 |
| 2510 | decode op j |
| 2511 | trow op add k0 sub j j0 now |
| 2512 | j = add j 1 |
| 2513 | end |
| 2514 | ap RSQL sqcom |
| 2515 | end |
| 2516 | |
| 2517 | note trreq: the request of operation op for row x<k> (case in tc); returns the HTTP status. |
| 2518 | fn trreq op ulong k ulong to ulong |
| 2519 | gn = genv get tc 1 |
| 2520 | rg = xor gn get tc 2 |
| 2521 | rsz RTID |
| 2522 | pb RTID 120 |
| 2523 | apd RTID k |
| 2524 | rsz RAID |
| 2525 | if eq get tc 3 1 |
| 2526 | ap RAID tattp |
| 2527 | apd RAID k |
| 2528 | else |
| 2529 | ap RAID tattx |
| 2530 | end |
| 2531 | rsz RART |
| 2532 | if eq op 4 |
| 2533 | if eq get tc 4 1 |
| 2534 | ap RART tartp |
| 2535 | apd RART k |
| 2536 | else |
| 2537 | ap RART tartx |
| 2538 | end |
| 2539 | else |
| 2540 | ap RART tartn |
| 2541 | end |
| 2542 | bopen |
| 2543 | if eq op 1 |
| 2544 | bagent agentc |
| 2545 | bttl ttlv get tc 7 |
| 2546 | ret hpost 0 pclaim |
| 2547 | end |
| 2548 | if eq op 4 |
| 2549 | bver rg get tc 5 true |
| 2550 | ret hpost 0 pver |
| 2551 | end |
| 2552 | bagent agentt |
| 2553 | bfence rg |
| 2554 | if eq op 2 |
| 2555 | bttl ttlv get tc 7 |
| 2556 | ret hpost 0 phb |
| 2557 | end |
| 2558 | bsub |
| 2559 | ret hpost 0 psub |
| 2560 | end |
| 2561 | |
| 2562 | fn tops op ulong j0 ulong j1 ulong k0 ulong to void |
| 2563 | if eq op 5 |
| 2564 | rsz RBODY |
| 2565 | code = hpost 0 prec |
| 2566 | put tr 0 code |
| 2567 | put g GRECL jnum krecl |
| 2568 | ret |
| 2569 | end |
| 2570 | j = j0 |
| 2571 | while lt j j1 bound 4096 |
| 2572 | decode op j |
| 2573 | put tr sub j j0 trreq op add k0 sub j j0 |
| 2574 | j = add j 1 |
| 2575 | end |
| 2576 | end |
| 2577 | |
| 2578 | note tdump: one observation line per row, "refused next_state next_generation"; refused is 0 |
| 2579 | note for HTTP 200, 1 for 409, 3 for 400, 2 for anything else. A reap is observed by its row alone. |
| 2580 | fn tdump op ulong j0 ulong j1 ulong to void |
| 2581 | rsz RSQL |
| 2582 | ap RSQL sqhd |
| 2583 | ap RSQL tdump_ |
| 2584 | ck eq sqlrun 0 tdump_ |
| 2585 | p = get bs RFILE |
| 2586 | e = get cu RFILE |
| 2587 | j = j0 |
| 2588 | while lt j j1 bound 4096 |
| 2589 | ck lt p e tdump_ |
| 2590 | q = findc p e 10 |
| 2591 | a = findc p q 124 |
| 2592 | b = findc add a 1 q 124 |
| 2593 | sc = stcode add a 1 b |
| 2594 | gn = pnum add b 1 q |
| 2595 | obs = tobs op j sc |
| 2596 | apd RTOBS obs |
| 2597 | sp RTOBS |
| 2598 | apd RTOBS sc |
| 2599 | sp RTOBS |
| 2600 | apd RTOBS gn |
| 2601 | nlr RTOBS |
| 2602 | p = add q 1 |
| 2603 | j = add j 1 |
| 2604 | end |
| 2605 | end |
| 2606 | |
| 2607 | fn tobs op ulong j ulong sc ulong to ulong |
| 2608 | if eq op 5 |
| 2609 | decode op j |
| 2610 | if and eq stv get tc 0 1 eq sc 0 |
| 2611 | inc GRALW |
| 2612 | ret 0 |
| 2613 | end |
| 2614 | ret 1 |
| 2615 | end |
| 2616 | c = get tr sub j get g GP1 |
| 2617 | if eq c 200 |
| 2618 | ret 0 |
| 2619 | end |
| 2620 | if eq c 409 |
| 2621 | ret 1 |
| 2622 | end |
| 2623 | if eq c 400 |
| 2624 | ret 3 |
| 2625 | end |
| 2626 | ret 2 |
| 2627 | end |
| 2628 | |
| 2629 | fn tchunk op ulong j0 ulong j1 ulong to void |
| 2630 | ch = get g GTCH |
| 2631 | inc GTCH |
| 2632 | rsz RDB |
| 2633 | apa RDB 4 |
| 2634 | ap RDB ftbl |
| 2635 | apd RDB ch |
| 2636 | ap RDB fdbs |
| 2637 | cockup 0 3 |
| 2638 | now = div ulong realns 1000000 |
| 2639 | k0 = get g GROW |
| 2640 | tseed op j0 j1 k0 now |
| 2641 | ck eq sqlrun 0 tins1 |
| 2642 | tops op j0 j1 k0 |
| 2643 | el = sub ulong monons get g GT0 |
| 2644 | if ge el 25000000000 |
| 2645 | say tinc |
| 2646 | apd ROUT ch |
| 2647 | say tinc2 |
| 2648 | flush |
| 2649 | inc GINC |
| 2650 | end |
| 2651 | put g GP1 j0 |
| 2652 | tdump op j0 j1 |
| 2653 | put g GROW add k0 sub j1 j0 |
| 2654 | cockdn 0 |
| 2655 | end |
| 2656 | |
| 2657 | note ---- table op 7: command ids. Row j has dims P = j%2 (a prior request with the id), |
| 2658 | note I = (j/2)%5 (no id, short id, 128 bytes, 129 bytes, a '/'), M = (j/10)%2 (the prior request |
| 2659 | note was the identical claim of k<k>, or a claim of the decoy y<k>), T = j/20 (k<k> open, |
| 2660 | note verified, absent). The rules line is "7 prior idlen bad M has 0 0 0 sdec" and the observed |
| 2661 | note line is "http records changed". |
| 2662 | fn cdim j ulong d ulong to ulong |
| 2663 | if eq d 0 |
| 2664 | ret rem j 2 |
| 2665 | end |
| 2666 | if eq d 1 |
| 2667 | ret rem div j 2 5 |
| 2668 | end |
| 2669 | if eq d 2 |
| 2670 | ret rem div j 10 2 |
| 2671 | end |
| 2672 | ret div j 20 |
| 2673 | end |
| 2674 | |
| 2675 | fn tcid j ulong k ulong to void |
| 2676 | iv = cdim j 1 |
| 2677 | rsz RCMD |
| 2678 | put g GCMD 0 |
| 2679 | if eq iv 0 |
| 2680 | ret |
| 2681 | end |
| 2682 | put g GCMD 1 |
| 2683 | pb RCMD 99 |
| 2684 | apd RCMD k |
| 2685 | if eq iv 4 |
| 2686 | ap RCMD tslx |
| 2687 | end |
| 2688 | if eq iv 2 |
| 2689 | tpad 128 |
| 2690 | end |
| 2691 | if eq iv 3 |
| 2692 | tpad 129 |
| 2693 | end |
| 2694 | end |
| 2695 | |
| 2696 | fn tcrow j ulong k ulong to void |
| 2697 | tt = cdim j 3 |
| 2698 | ap RSQL sqi1 |
| 2699 | pb RSQL 121 |
| 2700 | apd RSQL k |
| 2701 | ap RSQL sqi2 |
| 2702 | if eq tt 2 |
| 2703 | ret |
| 2704 | end |
| 2705 | ap RSQL sqi1 |
| 2706 | pb RSQL 107 |
| 2707 | apd RSQL k |
| 2708 | ap RSQL sqi2 |
| 2709 | if eq tt 1 |
| 2710 | ap RSQL tkupd1 |
| 2711 | apd RSQL k |
| 2712 | ap RSQL tqend |
| 2713 | end |
| 2714 | end |
| 2715 | |
| 2716 | fn tcseed k0 ulong to void |
| 2717 | rsz RSQL |
| 2718 | ap RSQL sqhd |
| 2719 | ap RSQL tcmdg |
| 2720 | ap RSQL sqbeg |
| 2721 | for j ulong 60 |
| 2722 | tcrow j add k0 j |
| 2723 | end |
| 2724 | ap RSQL sqcom |
| 2725 | end |
| 2726 | |
| 2727 | fn tcclaim to ulong |
| 2728 | bopen |
| 2729 | bagent agentc |
| 2730 | bttl 300 |
| 2731 | ret hpost 0 pclaim |
| 2732 | end |
| 2733 | |
| 2734 | fn tcph1 j ulong k ulong to void |
| 2735 | if or eq cdim j 0 0 eq cdim j 1 0 |
| 2736 | ret |
| 2737 | end |
| 2738 | tcid j k |
| 2739 | rsz RTID |
| 2740 | if eq cdim j 2 1 |
| 2741 | pb RTID 107 |
| 2742 | else |
| 2743 | pb RTID 121 |
| 2744 | end |
| 2745 | apd RTID k |
| 2746 | c = tcclaim |
| 2747 | end |
| 2748 | |
| 2749 | fn tcreq j ulong k ulong to void |
| 2750 | tcid j k |
| 2751 | rsz RTID |
| 2752 | pb RTID 107 |
| 2753 | apd RTID k |
| 2754 | put tk add mul j 4 3 tcclaim |
| 2755 | end |
| 2756 | |
| 2757 | fn tcq k ulong to void |
| 2758 | ap RSQL td1 |
| 2759 | apd RSQL k |
| 2760 | ap RSQL td2 |
| 2761 | apd RSQL k |
| 2762 | ap RSQL td3 |
| 2763 | if eq get g GCMD 1 |
| 2764 | apr RSQL RCMD |
| 2765 | end |
| 2766 | ap RSQL td4 |
| 2767 | end |
| 2768 | |
| 2769 | note tsd: the status code of stcode as the state decision of op 7 (open 0, claimed by a live |
| 2770 | note lease 3 HELD, verified 2 BADSTATE, absent 1 NOTFOUND). |
| 2771 | fn tsd s ulong to ulong |
| 2772 | if eq s 0 |
| 2773 | ret 0 |
| 2774 | end |
| 2775 | if eq s 1 |
| 2776 | ret 3 |
| 2777 | end |
| 2778 | if eq s 3 |
| 2779 | ret 2 |
| 2780 | end |
| 2781 | ret 1 |
| 2782 | end |
| 2783 | |
| 2784 | fn tcin j ulong s1 ulong c1 ulong to void |
| 2785 | tcid j add get g GK0 j |
| 2786 | iv = cdim j 1 |
| 2787 | has = ulong 1 |
| 2788 | if eq iv 0 |
| 2789 | has = 0 |
| 2790 | end |
| 2791 | bad = ulong 0 |
| 2792 | if eq iv 4 |
| 2793 | bad = 1 |
| 2794 | end |
| 2795 | apd RTIN 7 |
| 2796 | sp RTIN |
| 2797 | apd RTIN c1 |
| 2798 | sp RTIN |
| 2799 | apd RTIN rln RCMD |
| 2800 | sp RTIN |
| 2801 | apd RTIN bad |
| 2802 | sp RTIN |
| 2803 | apd RTIN cdim j 2 |
| 2804 | sp RTIN |
| 2805 | apd RTIN has |
| 2806 | ap RTIN tz3 |
| 2807 | apd RTIN tsd s1 |
| 2808 | nlr RTIN |
| 2809 | end |
| 2810 | |
| 2811 | fn tcobs j ulong sc ulong gn ulong cn ulong to void |
| 2812 | o = mul j 4 |
| 2813 | s1 = get tk o |
| 2814 | chg = ulong 0 |
| 2815 | if or ne sc s1 ne gn get tk add o 1 |
| 2816 | chg = 1 |
| 2817 | end |
| 2818 | apd RTOBS get tk add o 3 |
| 2819 | sp RTOBS |
| 2820 | apd RTOBS cn |
| 2821 | sp RTOBS |
| 2822 | apd RTOBS chg |
| 2823 | nlr RTOBS |
| 2824 | tcin j s1 get tk add o 2 |
| 2825 | end |
| 2826 | |
| 2827 | fn tcline j ulong p ulong q ulong ph ulong to void |
| 2828 | a = findc p q 124 |
| 2829 | b = findc add a 1 q 124 |
| 2830 | sc = stcode p a |
| 2831 | gn = pnum add a 1 b |
| 2832 | cn = pnum add b 1 q |
| 2833 | if eq ph 0 |
| 2834 | o = mul j 4 |
| 2835 | put tk o sc |
| 2836 | put tk add o 1 gn |
| 2837 | put tk add o 2 cn |
| 2838 | ret |
| 2839 | end |
| 2840 | tcobs j sc gn cn |
| 2841 | end |
| 2842 | |
| 2843 | fn tcdump ph ulong to void |
| 2844 | k0 = get g GK0 |
| 2845 | rsz RSQL |
| 2846 | ap RSQL sqhd |
| 2847 | for j ulong 60 |
| 2848 | tcid j add k0 j |
| 2849 | tcq add k0 j |
| 2850 | end |
| 2851 | ck eq sqlrun 0 td1 |
| 2852 | p = get bs RFILE |
| 2853 | e = get cu RFILE |
| 2854 | for j2 ulong 60 |
| 2855 | ck lt p e td1 |
| 2856 | q = findc p e 10 |
| 2857 | tcline j2 p q ph |
| 2858 | p = add q 1 |
| 2859 | end |
| 2860 | end |
| 2861 | |
| 2862 | fn tcmd to void |
| 2863 | ch = get g GTCH |
| 2864 | inc GTCH |
| 2865 | rsz RDB |
| 2866 | apa RDB 4 |
| 2867 | ap RDB ftbl |
| 2868 | apd RDB ch |
| 2869 | ap RDB fdbs |
| 2870 | cockup 0 3 |
| 2871 | k0 = get g GROW |
| 2872 | put g GK0 k0 |
| 2873 | tcseed k0 |
| 2874 | ck eq sqlrun 0 tcmdg |
| 2875 | for j ulong 60 |
| 2876 | tcph1 j add k0 j |
| 2877 | end |
| 2878 | tcdump 0 |
| 2879 | for j2 ulong 60 |
| 2880 | tcreq j2 add k0 j2 |
| 2881 | end |
| 2882 | tcdump 1 |
| 2883 | put g GROW add k0 60 |
| 2884 | nocmd |
| 2885 | cockdn 0 |
| 2886 | end |
| 2887 | |
| 2888 | fn httpof dec ulong sdec ulong to ulong |
| 2889 | if eq dec 11 |
| 2890 | ret 200 |
| 2891 | end |
| 2892 | if eq dec 12 |
| 2893 | ret 409 |
| 2894 | end |
| 2895 | if eq dec 13 |
| 2896 | ret 400 |
| 2897 | end |
| 2898 | if eq sdec 0 |
| 2899 | ret 200 |
| 2900 | end |
| 2901 | if eq sdec 1 |
| 2902 | ret 404 |
| 2903 | end |
| 2904 | if eq sdec 8 |
| 2905 | ret 400 |
| 2906 | end |
| 2907 | if eq sdec 9 |
| 2908 | ret 503 |
| 2909 | end |
| 2910 | if eq sdec 10 |
| 2911 | ret 500 |
| 2912 | end |
| 2913 | ret 409 |
| 2914 | end |
| 2915 | |
| 2916 | note tfield: number idx (from 0) of the rules input line at tp..tq. |
| 2917 | fn tfield tp ulong tq ulong idx ulong to ulong |
| 2918 | put g GP4 tp |
| 2919 | put g add GP4 1 tq |
| 2920 | v = ulong 0 |
| 2921 | r = ulong 0 |
| 2922 | while le r idx bound 16 |
| 2923 | v = nxt GP4 |
| 2924 | r = add r 1 |
| 2925 | end |
| 2926 | ret v |
| 2927 | end |
| 2928 | |
| 2929 | note trowok: op 7 compares HTTP status, record count and change; the other ops compare the |
| 2930 | note refusal class (0 granted, 3 invalid 400, 1 refused), next state and next generation. |
| 2931 | fn trowok tp ulong tq ulong to bool |
| 2932 | if eq tfield tp tq 0 7 |
| 2933 | ex = httpof get tv 0 tfield tp tq 9 |
| 2934 | if ne ex get tv 3 |
| 2935 | ret false |
| 2936 | end |
| 2937 | if ne get tv 1 get tv 4 |
| 2938 | ret false |
| 2939 | end |
| 2940 | ret eq get tv 2 get tv 5 |
| 2941 | end |
| 2942 | ra = ulong 1 |
| 2943 | if eq get tv 0 0 |
| 2944 | ra = 0 |
| 2945 | end |
| 2946 | if eq get tv 0 8 |
| 2947 | ra = 3 |
| 2948 | end |
| 2949 | ok = eq ra get tv 3 |
| 2950 | if ne get tv 1 get tv 4 |
| 2951 | ok = false |
| 2952 | end |
| 2953 | if ne get tv 2 get tv 5 |
| 2954 | ok = false |
| 2955 | end |
| 2956 | ret ok |
| 2957 | end |
| 2958 | |
| 2959 | note trowck: tv holds the 3 rules outputs, then the 3 observed values of the row. |
| 2960 | fn trowck i ulong verbose bool bad ulong to bool |
| 2961 | for j ulong 3 |
| 2962 | put tv j nxt GP1 |
| 2963 | end |
| 2964 | for j2 ulong 3 |
| 2965 | put tv add j2 3 nxt GP2 |
| 2966 | end |
| 2967 | tp = get g GP3 |
| 2968 | tq = findc tp get g add GP3 1 10 |
| 2969 | put g GP3 add tq 1 |
| 2970 | ok = trowok tp tq |
| 2971 | if and not ok and verbose lt bad 40 |
| 2972 | trowpr i tp tq |
| 2973 | end |
| 2974 | ret ok |
| 2975 | end |
| 2976 | |
| 2977 | fn trowpr i ulong tp ulong tq ulong to void |
| 2978 | say tfrow |
| 2979 | apd ROUT i |
| 2980 | say tfin |
| 2981 | apm ROUT tp sub tq tp |
| 2982 | say tfrul |
| 2983 | for j ulong 6 |
| 2984 | if eq j 3 |
| 2985 | say tfobs |
| 2986 | else |
| 2987 | sp ROUT |
| 2988 | end |
| 2989 | apd ROUT get tv j |
| 2990 | end |
| 2991 | nl |
| 2992 | end |
| 2993 | |
| 2994 | note tcheck: run the rules (which 0) or the mutant (which 1) on every table row and count the |
| 2995 | note rows whose decision, next state or next generation differ from what the cockpit did. |
| 2996 | fn tcheck which ulong verbose bool to ulong |
| 2997 | rows = get g GROW |
| 2998 | code = rules which RTIN |
| 2999 | if ne code 0 |
| 3000 | ret add rows 1 |
| 3001 | end |
| 3002 | put g GP1 get bs RFILE |
| 3003 | put g add GP1 1 get cu RFILE |
| 3004 | put g GP2 get bs RTOBS |
| 3005 | put g add GP2 1 get cu RTOBS |
| 3006 | put g GP3 get bs RTIN |
| 3007 | put g add GP3 1 get cu RTIN |
| 3008 | bad = ulong 0 |
| 3009 | i = ulong 0 |
| 3010 | while lt i rows bound 65536 |
| 3011 | if not trowck i verbose bad |
| 3012 | bad = add bad 1 |
| 3013 | end |
| 3014 | i = add i 1 |
| 3015 | end |
| 3016 | ret bad |
| 3017 | end |
| 3018 | |
| 3019 | fn mfind fr view uchar * occ ulong to ulong |
| 3020 | p = get bs RSRC |
| 3021 | e = get cu RSRC |
| 3022 | seen = ulong 0 |
| 3023 | while lt p e bound 999999 |
| 3024 | q = findc p e 10 |
| 3025 | if eq sub q p len fr |
| 3026 | if mtext p fr |
| 3027 | seen = add seen 1 |
| 3028 | if eq seen occ |
| 3029 | ret p |
| 3030 | end |
| 3031 | end |
| 3032 | end |
| 3033 | p = add q 1 |
| 3034 | end |
| 3035 | ret NONE |
| 3036 | end |
| 3037 | |
| 3038 | fn mutant fr view uchar * tx view uchar * occ ulong to void |
| 3039 | pos = mfind fr occ |
| 3040 | if eq pos NONE |
| 3041 | say tmuta |
| 3042 | say fr |
| 3043 | nl |
| 3044 | inc GFAIL |
| 3045 | ret |
| 3046 | end |
| 3047 | rsz RMUT |
| 3048 | b = get bs RSRC |
| 3049 | apm RMUT b sub pos b |
| 3050 | ap RMUT tx |
| 3051 | q = add pos len fr |
| 3052 | apm RMUT q sub get cu RSRC q |
| 3053 | psc fmuts |
| 3054 | ck wfile RMUT fmuts |
| 3055 | fi = fopr |
| 3056 | psc fmutb |
| 3057 | fo = fopw 493 |
| 3058 | ck and ge fi 0 ge fo 0 fmutb |
| 3059 | xbeg |
| 3060 | xarg 6 |
| 3061 | code = runw fi fo -1 |
| 3062 | c1 = fclose fi |
| 3063 | c2 = fclose fo |
| 3064 | if ne code 0 |
| 3065 | say tmutc |
| 3066 | say tx |
| 3067 | nl |
| 3068 | inc GFAIL |
| 3069 | ret |
| 3070 | end |
| 3071 | cf = cases 1 true |
| 3072 | tf = tcheck 1 false |
| 3073 | mutrep tx occ cf tf |
| 3074 | end |
| 3075 | |
| 3076 | fn mutrep tx view uchar * occ ulong cf ulong tf ulong to void |
| 3077 | killed = or gt cf 0 gt tf 0 |
| 3078 | if killed |
| 3079 | say tpass |
| 3080 | inc GPASS |
| 3081 | else |
| 3082 | say tfail |
| 3083 | inc GFAIL |
| 3084 | end |
| 3085 | say tmut |
| 3086 | say tx |
| 3087 | sp ROUT |
| 3088 | apd ROUT occ |
| 3089 | if killed |
| 3090 | say tmutk |
| 3091 | else |
| 3092 | say tmuts |
| 3093 | end |
| 3094 | apd ROUT cf |
| 3095 | say tmutt |
| 3096 | apd ROUT tf |
| 3097 | nl |
| 3098 | end |
| 3099 | |
| 3100 | fn smuts to void |
| 3101 | pdir fsrc |
| 3102 | n = rfile RSRC |
| 3103 | ck gt n 0 fsrc |
| 3104 | mutant mf01 mt01 1 |
| 3105 | mutant mf02 mt02 1 |
| 3106 | mutant mf02 mt02 2 |
| 3107 | mutant mf04 mt04 1 |
| 3108 | mutant mf05 mt05 1 |
| 3109 | mutant mf05 mt06 1 |
| 3110 | mutant mf07 mt07 1 |
| 3111 | mutant mf08 mt08 1 |
| 3112 | mutant mf08 mt09 1 |
| 3113 | mutant mf10 mt10 1 |
| 3114 | mutant mf11 mt11 1 |
| 3115 | mutant mf12 mt12 1 |
| 3116 | mutant mf13 mt13 1 |
| 3117 | mutant mf14 mtfal 1 |
| 3118 | mutant mf15 mt15 1 |
| 3119 | mutant mf16 mtfal 1 |
| 3120 | mutant mf16 mtfal 2 |
| 3121 | mutant mf17 mtfal 1 |
| 3122 | mutant mf18 mtfal 1 |
| 3123 | mutant mf19 mtfal 1 |
| 3124 | mutant mf20 mtfal 1 |
| 3125 | mutant mf21 mt21 1 |
| 3126 | mutant mf22 mtfal 1 |
| 3127 | mutant mf23 mtfal 1 |
| 3128 | mutant mf24 mt24 1 |
| 3129 | mutant mf25 mt25 1 |
| 3130 | mutant mf26 mtfal 1 |
| 3131 | mutant mf26 mtfal 2 |
| 3132 | mutant mf27 mtfal 1 |
| 3133 | end |
| 3134 | |
| 3135 | fn stable to void |
| 3136 | put g GROW 0 |
| 3137 | for o ulong 5 |
| 3138 | op = add o 1 |
| 3139 | n = opn op |
| 3140 | j0 = ulong 0 |
| 3141 | while lt j0 n bound 64 |
| 3142 | j1 = add j0 400 |
| 3143 | if gt j1 n |
| 3144 | j1 = n |
| 3145 | end |
| 3146 | tchunk op j0 j1 |
| 3147 | j0 = j1 |
| 3148 | end |
| 3149 | end |
| 3150 | tcmd |
| 3151 | psc ftin |
| 3152 | ck wfile RTIN ftin |
| 3153 | psc ftobs |
| 3154 | ck wfile RTOBS ftobs |
| 3155 | bad = tcheck 0 true |
| 3156 | put g GLAST 0 |
| 3157 | say ttab1 |
| 3158 | apd ROUT get g GROW |
| 3159 | say ttab2 |
| 3160 | apd ROUT bad |
| 3161 | say ttab3 |
| 3162 | apd ROUT get g GTCH |
| 3163 | sp ROUT |
| 3164 | rep eq bad 0 n_tab |
| 3165 | say ttab4 |
| 3166 | apd ROUT get g GRECL |
| 3167 | say ttab5 |
| 3168 | apd ROUT get g GRALW |
| 3169 | sp ROUT |
| 3170 | rep eq get g GRECL get g GRALW n_trec |
| 3171 | smuts |
| 3172 | end |
| 3173 | |
| 3174 | fn main to int |
| 3175 | setup |
| 3176 | args |
| 3177 | mktok |
| 3178 | psc dhome |
| 3179 | r = makedir m get bs RPATH rln RPATH 493 |
| 3180 | if argis 1 mcases |
| 3181 | f = cases 0 false |
| 3182 | end |
| 3183 | if argis 1 mhttp |
| 3184 | shttp |
| 3185 | end |
| 3186 | if argis 1 mtable |
| 3187 | stable |
| 3188 | end |
| 3189 | if argis 1 mmig |
| 3190 | smig |
| 3191 | end |
| 3192 | say tsumm |
| 3193 | apa ROUT 1 |
| 3194 | say tsp |
| 3195 | apd ROUT get g GPASS |
| 3196 | say tsf |
| 3197 | apd ROUT get g GFAIL |
| 3198 | say tsn |
| 3199 | apd ROUT get g GNRUN |
| 3200 | say tsi |
| 3201 | apd ROUT get g GINC |
| 3202 | nl |
| 3203 | if gt add get g GPASS get g GFAIL 0 |
| 3204 | if eq get g GFAIL 0 |
| 3205 | ret 0 |
| 3206 | end |
| 3207 | end |
| 3208 | ret 1 |
| 3209 | end |