mailhand
mailhand: agents look after a person's email in seeded Omega. Maildir + MIME parsing, JSONL CLI and MCP, rule triage, policy-gated sending, hash-chained audit. Free (Apache-2.0).
Brought by drakestapleton
| 1 | note ======== tests/bench.om: mailhand speed benchmark (GateBuilder) ======== |
| 2 | note Usage: bench MAILHAND DIR [N [SEED]] N default 10000, SEED default 1 (decimal, 0..2^64-1). |
| 3 | note Build: ./build.sh tests/BENCH_UNITS build/bench. Example from the repository root: |
| 4 | note build/bench build/mailhand build/benchrun (build/benchrun must not exist yet) |
| 5 | note MAILHAND is passed to execprog as given (no PATH search; relative to the current directory). |
| 6 | note DIR (made absolute with the current directory) must not exist; its parent must. The bench: |
| 7 | note 1. creates DIR and generates the Maildir DIR/Mail with N messages from SEED (tests/bench-lib.om, |
| 8 | note the same bytes as `mkmaildir DIR/Mail N SEED`), timed with monons: line "MHBENCH gen"; |
| 9 | note 2. runs MAILHAND setup --home DIR/h --maildir DIR/Mail --me bench@example.org --name Bench |
| 10 | note (not a measurement; it must exit 0): line "MHBENCH setup"; |
| 11 | note 3. runs MAILHAND list --home DIR/h --folder INBOX: line "MHBENCH list"; |
| 12 | note 4. runs MAILHAND stats --home DIR/h --folder INBOX (stats parses every message and prints only |
| 13 | note counts: the parse-only mode of src/ops.om op_stats): line "MHBENCH stats"; |
| 14 | note 5. prints "MHBENCH PASS ..." (exit 0) or "MHBENCH FAIL ..." (exit 2). |
| 15 | note Each run: stdin /dev/null, stdout DIR/OP.out, stderr DIR/OP.err (kept for inspection), the empty |
| 16 | note environment of execprog. wall_ns = monons just after the child is reaped minus monons just before |
| 17 | note fork: process start, config load, the op over all N messages, writing OP.out, the audit record |
| 18 | note (src/audit.om, fsync) and exit. The wait has no time limit (no-hard-caps rule: a hang shows as a |
| 19 | note bench that does not end). One run per op, no warm-up: the page cache holds the files just written. |
| 20 | note Fields: N messages generated, bytes = sum of their file sizes, messages_per_s = N * 10^9 / wall_ns, |
| 21 | note MB_per_s = bytes * 10^3 / wall_ns (decimal MB, 10^6 bytes), both truncated to 3 decimals by exact |
| 22 | note integer long division (bn_ratio; "n/a" when wall_ns is 0 or above 1844674407370955161), |
| 23 | note exit = the child's exit status, 1000 + signal number, or 2000 when the bench could not open the |
| 24 | note files, fork or wait (stderr says which); cmd = the exact argument vector, joined with spaces. |
| 25 | note list adds records (LF-ended lines of list.out: one JSONL record per message) and refused (records |
| 26 | note with a "refused":" key). stats adds the op's own record: messages, parsed, refused, path_refused, |
| 27 | note op_bytes, op_wall_ns (monons around the scan inside mailhand, without process start and output) |
| 28 | note and op_messages_per_s = messages * 10^9 / op_wall_ns, op_MB_per_s = op_bytes * 10^3 / op_wall_ns. |
| 29 | note Checks (each failure prints "MHBENCH CHECK_FAIL NAME got=X want=Y" and counts): setup exit 0; |
| 30 | note list exit 0, records N, refused 0; stats exit 0, messages N, parsed N, refused 0, path_refused 0, |
| 31 | note op_bytes = bytes. A measurement is printed only together with its checks; no comparison is made |
| 32 | note with anything not run here. |
| 33 | note Exit 0 PASS; 1 usage (arguments, DIR exists, a path too long); 2 FAIL (a check failed); |
| 34 | note 6 I/O (DIR or the Maildir could not be created or written). |
| 35 | |
| 36 | const BN_OW int 557633 |
| 37 | note bn_pk: the execprog argument packet (u16 count, then u16 length + bytes per argument); 65536 bytes |
| 38 | note is the execprog packet limit of the language (OMEGESE section 10), a boundary, not our cap. |
| 39 | global bn_pk uchar 65536 |
| 40 | note bn_g cells: 0 packet bytes, 1 packet count, 2 packet too big, 3 wall ns of the last run, |
| 41 | note 4 failed checks, 5 last key found, 6 generated bytes, 7 N |
| 42 | global bn_g ulong 16 |
| 43 | const BNG_PKN ulong 0 |
| 44 | const BNG_PKC ulong 1 |
| 45 | const BNG_PKBAD ulong 2 |
| 46 | const BNG_NS ulong 3 |
| 47 | const BNG_FAILS ulong 4 |
| 48 | const BNG_KOK ulong 5 |
| 49 | const BNG_BYTES ulong 6 |
| 50 | const BNG_N ulong 7 |
| 51 | const BNG_REC ulong 8 |
| 52 | const BNG_REF ulong 9 |
| 53 | |
| 54 | text bnt_us "usage: bench MAILHAND DIR [N [SEED]] (N default 10000, SEED default 1; DIR must not exist)" |
| 55 | text bnt_null "/dev/null" |
| 56 | text bnt_out ".out" |
| 57 | text bnt_err ".err" |
| 58 | text bnt_mail "/Mail" |
| 59 | text bnt_h "/h" |
| 60 | text bnt_setup "setup" |
| 61 | text bnt_list "list" |
| 62 | text bnt_stats "stats" |
| 63 | text bnt_home "--home" |
| 64 | text bnt_maildir "--maildir" |
| 65 | text bnt_me "--me" |
| 66 | text bnt_mev "bench@example.org" |
| 67 | text bnt_name "--name" |
| 68 | text bnt_namev "Bench" |
| 69 | text bnt_folder "--folder" |
| 70 | text bnt_inbox "INBOX" |
| 71 | text bnt_gen "MHBENCH gen " |
| 72 | text bnt_ksetup "MHBENCH setup" |
| 73 | text bnt_klist "MHBENCH list" |
| 74 | text bnt_kstats "MHBENCH stats" |
| 75 | text bnt_kwall " wall_ns=" |
| 76 | text bnt_kmps " messages_per_s=" |
| 77 | text bnt_kmbps " MB_per_s=" |
| 78 | text bnt_kexit " exit=" |
| 79 | text bnt_kcmd " cmd=" |
| 80 | text bnt_kn " N=" |
| 81 | text bnt_kbytes " bytes=" |
| 82 | text bnt_krec " records=" |
| 83 | text bnt_kref " refused=" |
| 84 | text bnt_kmd " maildir=" |
| 85 | text bnt_kmsgs " messages=" |
| 86 | text bnt_kpar " parsed=" |
| 87 | text bnt_kpath " path_refused=" |
| 88 | text bnt_ksb " op_bytes=" |
| 89 | text bnt_kons " op_wall_ns=" |
| 90 | text bnt_komps " op_messages_per_s=" |
| 91 | text bnt_kombps " op_MB_per_s=" |
| 92 | text bnt_missing "missing" |
| 93 | text bnt_jmsg "\"messages\":" |
| 94 | text bnt_jpar "\"parsed\":" |
| 95 | text bnt_jref "\"refused\":" |
| 96 | text bnt_jpath "\"path_refused\":" |
| 97 | text bnt_jbytes "\"bytes\":" |
| 98 | text bnt_jns "\"wall_ns\":" |
| 99 | text bnt_refq "\"refused\":\"" |
| 100 | text bnt_cf "MHBENCH CHECK_FAIL " |
| 101 | text bnt_kgot " got=" |
| 102 | text bnt_kwant " want=" |
| 103 | text bnt_pass "MHBENCH PASS" |
| 104 | text bnt_fail "MHBENCH FAIL" |
| 105 | text bnt_kfails " checks_failed=" |
| 106 | text bnt_csetup "setup_exit" |
| 107 | text bnt_clexit "list_exit" |
| 108 | text bnt_clout "list_output_readable" |
| 109 | text bnt_clrec "list_records" |
| 110 | text bnt_clref "list_refused" |
| 111 | text bnt_csexit "stats_exit" |
| 112 | text bnt_csout "stats_output_readable" |
| 113 | text bnt_csmsg "stats_messages" |
| 114 | text bnt_cspar "stats_parsed" |
| 115 | text bnt_csref "stats_refused" |
| 116 | text bnt_cspath "stats_path_refused" |
| 117 | text bnt_csbytes "stats_op_bytes" |
| 118 | text bnt_eexist "bench: DIR exists; give a directory that does not exist yet (its parent must exist)" |
| 119 | text bnt_emkdir "bench: cannot create DIR, errno " |
| 120 | text bnt_epath "bench: DIR is empty, longer than 4095 bytes or holds a NUL byte" |
| 121 | text bnt_eopen "bench: cannot open /dev/null or an output file under DIR" |
| 122 | text bnt_efork "bench: fork failed" |
| 123 | text bnt_ewait "bench: waitpid failed" |
| 124 | text bnt_epk "bench: the argument packet would pass 65536 bytes (the execprog packet limit)" |
| 125 | text bnt_eread "bench: cannot read an output file, errno " |
| 126 | text bnt_ecwd "bench: cannot read the current directory" |
| 127 | |
| 128 | note ---- arguments and directories ---- |
| 129 | note bn_args: store S_Y = MAILHAND (argument 1), store S_X = DIR (argument 2) made absolute |
| 130 | fn bn_args to bool |
| 131 | b = new uchar 131072 0 |
| 132 | w = new uchar 4096 0 |
| 133 | k = argread 1 b 0 131072 |
| 134 | if le k 0 |
| 135 | ret false |
| 136 | end |
| 137 | z = s_mem S_Y |
| 138 | s_addt S_Y part b 0 ulong k |
| 139 | k2 = argread 2 b 0 131072 |
| 140 | if le k2 0 |
| 141 | ret false |
| 142 | end |
| 143 | z = s_mem S_X |
| 144 | if ne get b 0 47 |
| 145 | cw = cwd w 0 4096 |
| 146 | if le cw 1 |
| 147 | mk_err bnt_ecwd |
| 148 | ret false |
| 149 | end |
| 150 | s_addt S_X part w 0 sub ulong cw 1 |
| 151 | zc = s_add S_X 47 |
| 152 | end |
| 153 | s_addt S_X part b 0 ulong k2 |
| 154 | ret true |
| 155 | end |
| 156 | |
| 157 | note bn_mkdir: create DIR; 0, 1 (unusable path or DIR exists), 6 (other error) |
| 158 | fn bn_mkdir to int |
| 159 | p_reset |
| 160 | p_s S_X 0 s_len S_X |
| 161 | if not p_ok |
| 162 | mk_err bnt_epath |
| 163 | ret 1 |
| 164 | end |
| 165 | r = p_mkdir |
| 166 | if eq r -17 |
| 167 | mk_err bnt_eexist |
| 168 | ret 1 |
| 169 | end |
| 170 | if lt r 0 |
| 171 | mk_errno bnt_emkdir r |
| 172 | ret 6 |
| 173 | end |
| 174 | ret 0 |
| 175 | end |
| 176 | |
| 177 | note bn_pfile: gp = DIR/NAME + sfx |
| 178 | fn bn_pfile nm view uchar * sfx view uchar * to void |
| 179 | p_reset |
| 180 | p_s S_X 0 s_len S_X |
| 181 | p_c 47 |
| 182 | p_t nm |
| 183 | p_t sfx |
| 184 | end |
| 185 | |
| 186 | fn bn_ostore s ulong to void |
| 187 | for i ulong s_len s bound 9223372036854775807 |
| 188 | o_b s_get s i |
| 189 | end |
| 190 | end |
| 191 | |
| 192 | note bn_orates: " wall_ns=.. messages_per_s=.. MB_per_s=.." |
| 193 | fn bn_orates n ulong b ulong ns ulong to void |
| 194 | o_raw bnt_kwall |
| 195 | o_digits ns |
| 196 | o_raw bnt_kmps |
| 197 | bn_ratio n 9 ns 3 |
| 198 | o_raw bnt_kmbps |
| 199 | bn_ratio b 3 ns 3 |
| 200 | end |
| 201 | |
| 202 | note ---- 1. generate ---- |
| 203 | fn bn_gen n ulong seed ulong to int |
| 204 | z = s_mem S_AUX |
| 205 | s_adds S_AUX S_X 0 s_len S_X |
| 206 | s_addt S_AUX bnt_mail |
| 207 | t0 = monons |
| 208 | r = mk_gen n seed |
| 209 | t1 = monons |
| 210 | if ne r 0 |
| 211 | ret r |
| 212 | end |
| 213 | ns = ulong sub t1 t0 |
| 214 | tb = mk_bytes |
| 215 | put bn_g BNG_BYTES tb |
| 216 | put bn_g BNG_N n |
| 217 | o_raw bnt_gen |
| 218 | mk_osum |
| 219 | bn_orates n tb ns |
| 220 | o_raw bnt_kmd |
| 221 | bn_ostore S_AUX |
| 222 | o_b 10 |
| 223 | o_flush |
| 224 | ret 0 |
| 225 | end |
| 226 | |
| 227 | note ---- argument packet ---- |
| 228 | fn bn_pkreset to void |
| 229 | put bn_g BNG_PKN 2 |
| 230 | put bn_g BNG_PKC 0 |
| 231 | put bn_g BNG_PKBAD 0 |
| 232 | put bn_pk 0 0 |
| 233 | put bn_pk 1 0 |
| 234 | end |
| 235 | |
| 236 | note bn_pkhdr: start a record of k bytes; false (and BNG_PKBAD 1) when it would pass 65536 bytes |
| 237 | fn bn_pkhdr k ulong to bool |
| 238 | n = get bn_g BNG_PKN |
| 239 | if gt add add n 2 k 65536 |
| 240 | put bn_g BNG_PKBAD 1 |
| 241 | ret false |
| 242 | end |
| 243 | put bn_pk n uchar and k 255 |
| 244 | put bn_pk add n 1 uchar shr k 8 |
| 245 | c = add get bn_g BNG_PKC 1 |
| 246 | put bn_g BNG_PKC c |
| 247 | put bn_pk 0 uchar and c 255 |
| 248 | put bn_pk 1 uchar shr c 8 |
| 249 | put bn_g BNG_PKN add n 2 |
| 250 | ret true |
| 251 | end |
| 252 | |
| 253 | fn bn_pkt t view uchar * to void |
| 254 | if not bn_pkhdr len t |
| 255 | ret |
| 256 | end |
| 257 | n = get bn_g BNG_PKN |
| 258 | for i ulong len t bound 65536 |
| 259 | put bn_pk add n i get t i |
| 260 | end |
| 261 | put bn_g BNG_PKN add n len t |
| 262 | end |
| 263 | |
| 264 | fn bn_pks s ulong off ulong k ulong to void |
| 265 | if not bn_pkhdr k |
| 266 | ret |
| 267 | end |
| 268 | n = get bn_g BNG_PKN |
| 269 | for i ulong k bound 65536 |
| 270 | put bn_pk add n i s_get s add off i |
| 271 | end |
| 272 | put bn_g BNG_PKN add n k |
| 273 | end |
| 274 | |
| 275 | note bn_pkdir: one argument: DIR + sfx |
| 276 | fn bn_pkdir sfx view uchar * to void |
| 277 | s_reset S_TMP |
| 278 | s_adds S_TMP S_X 0 s_len S_X |
| 279 | s_addt S_TMP sfx |
| 280 | bn_pks S_TMP 0 s_len S_TMP |
| 281 | end |
| 282 | |
| 283 | note bn_pkop: MAILHAND op --home DIR/h --folder INBOX |
| 284 | fn bn_pkop op view uchar * to void |
| 285 | bn_pkreset |
| 286 | bn_pks S_Y 0 s_len S_Y |
| 287 | bn_pkt op |
| 288 | bn_pkt bnt_home |
| 289 | bn_pkdir bnt_h |
| 290 | bn_pkt bnt_folder |
| 291 | bn_pkt bnt_inbox |
| 292 | end |
| 293 | |
| 294 | note bn_ocmd: the packet's arguments joined with spaces |
| 295 | fn bn_ocmd to void |
| 296 | c = or ulong get bn_pk 0 shl ulong get bn_pk 1 8 |
| 297 | p = ulong 2 |
| 298 | for a ulong c bound 1024 |
| 299 | k = or ulong get bn_pk p shl ulong get bn_pk add p 1 8 |
| 300 | p = add p 2 |
| 301 | if gt a 0 |
| 302 | o_b 32 |
| 303 | end |
| 304 | for i ulong k bound 65536 |
| 305 | o_b get bn_pk add p i |
| 306 | end |
| 307 | p = add p k |
| 308 | end |
| 309 | end |
| 310 | |
| 311 | note ---- running ---- |
| 312 | note bn_spawn: run the packet with stdin /dev/null, stdout DIR/NAME.out, stderr DIR/NAME.err and wait |
| 313 | note (no time limit); BNG_NS = wall ns from just before fork to just after the reap. Result: exit |
| 314 | note status 0..255, 1000 + signal, 2000 when files, fork or wait failed (stderr says which). |
| 315 | fn bn_spawn nm view uchar * to ulong |
| 316 | put bn_g BNG_NS 0 |
| 317 | if ne get bn_g BNG_PKBAD 0 |
| 318 | mk_err bnt_epk |
| 319 | ret 2000 |
| 320 | end |
| 321 | fi = fopen bnt_null 0 len bnt_null ORD 0 |
| 322 | bn_pfile nm bnt_out |
| 323 | fo = long -1 |
| 324 | if p_ok |
| 325 | fo = fopen gp 0 get gv VPL BN_OW 420 |
| 326 | end |
| 327 | bn_pfile nm bnt_err |
| 328 | fx = long -1 |
| 329 | if p_ok |
| 330 | fx = fopen gp 0 get gv VPL BN_OW 420 |
| 331 | end |
| 332 | if or or lt fi 0 lt fo 0 lt fx 0 |
| 333 | mk_err bnt_eopen |
| 334 | ret 2000 |
| 335 | end |
| 336 | ret bn_run fi fo fx |
| 337 | end |
| 338 | |
| 339 | note bn_run: fork; the child binds fi/fo/fx to 0/1/2 and execs the packet (exit 127 if exec fails) |
| 340 | fn bn_run fi long fo long fx long to ulong |
| 341 | t0 = monons |
| 342 | pid = fork |
| 343 | if lt pid 0 |
| 344 | mk_err bnt_efork |
| 345 | ret 2000 |
| 346 | end |
| 347 | if eq pid 0 |
| 348 | r = dupfd int fi 0 0 |
| 349 | r = dupfd int fo 1 0 |
| 350 | r = dupfd int fx 2 0 |
| 351 | r = execprog bn_pk 0 get bn_g BNG_PKN |
| 352 | exit 127 |
| 353 | end |
| 354 | z = fclose int fi |
| 355 | z = fclose int fo |
| 356 | z = fclose int fx |
| 357 | ret bn_reap pid t0 |
| 358 | end |
| 359 | |
| 360 | note bn_reap: blocking wait for pid (EINTR retried), BNG_NS = monons now - t0, the decoded status |
| 361 | fn bn_reap pid long t0 long to ulong |
| 362 | st = new uchar 4 0 |
| 363 | w = waitpid int pid st 0 4 0 |
| 364 | while eq w -4 bound 9223372036854775807 |
| 365 | w = waitpid int pid st 0 4 0 |
| 366 | end |
| 367 | t1 = monons |
| 368 | put bn_g BNG_NS ulong sub t1 t0 |
| 369 | if ne w pid |
| 370 | mk_err bnt_ewait |
| 371 | ret 2000 |
| 372 | end |
| 373 | s = or ulong get st 0 shl ulong get st 1 8 |
| 374 | if eq and s 127 0 |
| 375 | ret and shr s 8 255 |
| 376 | end |
| 377 | ret add 1000 and s 127 |
| 378 | end |
| 379 | |
| 380 | note bn_load: store S_MSG reads DIR/NAME.out; false (stderr names errno) when it cannot |
| 381 | fn bn_load nm view uchar * to bool |
| 382 | bn_pfile nm bnt_out |
| 383 | r = s_file S_MSG |
| 384 | if lt r 0 |
| 385 | mk_errno bnt_eread r |
| 386 | ret false |
| 387 | end |
| 388 | ret true |
| 389 | end |
| 390 | |
| 391 | note ---- checks ---- |
| 392 | fn bn_chk t view uchar * got ulong want ulong to void |
| 393 | if eq got want |
| 394 | ret |
| 395 | end |
| 396 | put bn_g BNG_FAILS add get bn_g BNG_FAILS 1 |
| 397 | o_raw bnt_cf |
| 398 | o_raw t |
| 399 | o_raw bnt_kgot |
| 400 | o_digits got |
| 401 | o_raw bnt_kwant |
| 402 | o_digits want |
| 403 | o_b 10 |
| 404 | end |
| 405 | |
| 406 | note bn_dec: the decimal number at S_MSG[p, n); BNG_KOK 0 when it does not fit a ulong |
| 407 | fn bn_dec p ulong n ulong to ulong |
| 408 | v = ulong 0 |
| 409 | q = p |
| 410 | while lt q n bound 9223372036854775807 |
| 411 | c = s_get S_MSG q |
| 412 | if or lt c 48 gt c 57 |
| 413 | ret v |
| 414 | end |
| 415 | dg = ulong sub c 48 |
| 416 | if gt v 1844674407370955161 |
| 417 | put bn_g BNG_KOK 0 |
| 418 | ret 0 |
| 419 | end |
| 420 | if eq v 1844674407370955161 |
| 421 | if gt dg 5 |
| 422 | put bn_g BNG_KOK 0 |
| 423 | ret 0 |
| 424 | end |
| 425 | end |
| 426 | v = add mul v 10 dg |
| 427 | q = add q 1 |
| 428 | end |
| 429 | ret v |
| 430 | end |
| 431 | |
| 432 | note bn_key: the number after the first occurrence of key t (e.g. "parsed": with quotes) in S_MSG; |
| 433 | note BNG_KOK 1 when found and in range |
| 434 | fn bn_key t view uchar * to ulong |
| 435 | n = s_len S_MSG |
| 436 | put bn_g BNG_KOK 0 |
| 437 | for i ulong n bound 9223372036854775807 |
| 438 | if eq s_get S_MSG i 34 |
| 439 | if s_eqt S_MSG i len t t |
| 440 | put bn_g BNG_KOK 1 |
| 441 | ret bn_dec add i len t n |
| 442 | end |
| 443 | end |
| 444 | end |
| 445 | ret 0 |
| 446 | end |
| 447 | |
| 448 | note bn_okey: " label=VALUE" (or "missing") for key t of the stats record |
| 449 | fn bn_okey lb view uchar * t view uchar * to void |
| 450 | v = bn_key t |
| 451 | o_raw lb |
| 452 | if eq get bn_g BNG_KOK 1 |
| 453 | o_digits v |
| 454 | else |
| 455 | o_raw bnt_missing |
| 456 | end |
| 457 | end |
| 458 | |
| 459 | note bn_chkkey: key t of the stats record equals want (missing counts as a failure) |
| 460 | fn bn_chkkey lb view uchar * t view uchar * want ulong to void |
| 461 | v = bn_key t |
| 462 | if eq get bn_g BNG_KOK 1 |
| 463 | bn_chk lb v want |
| 464 | ret |
| 465 | end |
| 466 | put bn_g BNG_FAILS add get bn_g BNG_FAILS 1 |
| 467 | o_raw bnt_cf |
| 468 | o_raw lb |
| 469 | o_raw bnt_kgot |
| 470 | o_raw bnt_missing |
| 471 | o_raw bnt_kwant |
| 472 | o_digits want |
| 473 | o_b 10 |
| 474 | end |
| 475 | |
| 476 | note bn_lscan: LF-ended records and records with a "refused":" key in S_MSG |
| 477 | fn bn_lscan to void |
| 478 | n = s_len S_MSG |
| 479 | rec = ulong 0 |
| 480 | nref = ulong 0 |
| 481 | for i ulong n bound 9223372036854775807 |
| 482 | c = s_get S_MSG i |
| 483 | if eq c 10 |
| 484 | rec = add rec 1 |
| 485 | end |
| 486 | if eq c 34 |
| 487 | if s_eqt S_MSG i len bnt_refq bnt_refq |
| 488 | nref = add nref 1 |
| 489 | end |
| 490 | end |
| 491 | end |
| 492 | put bn_g BNG_REC rec |
| 493 | put bn_g BNG_REF nref |
| 494 | end |
| 495 | |
| 496 | note ---- 2. setup ---- |
| 497 | fn bn_setup to int |
| 498 | bn_pkreset |
| 499 | bn_pks S_Y 0 s_len S_Y |
| 500 | bn_pkt bnt_setup |
| 501 | bn_pkt bnt_home |
| 502 | bn_pkdir bnt_h |
| 503 | bn_pkt bnt_maildir |
| 504 | bn_pkdir bnt_mail |
| 505 | bn_pkt bnt_me |
| 506 | bn_pkt bnt_mev |
| 507 | bn_pkt bnt_name |
| 508 | bn_pkt bnt_namev |
| 509 | o_flush |
| 510 | x = bn_spawn bnt_setup |
| 511 | o_raw bnt_ksetup |
| 512 | o_raw bnt_kexit |
| 513 | o_digits x |
| 514 | o_raw bnt_kwall |
| 515 | o_digits get bn_g BNG_NS |
| 516 | o_raw bnt_kcmd |
| 517 | bn_ocmd |
| 518 | o_b 10 |
| 519 | bn_chk bnt_csetup x 0 |
| 520 | o_flush |
| 521 | if ne x 0 |
| 522 | ret 2 |
| 523 | end |
| 524 | ret 0 |
| 525 | end |
| 526 | |
| 527 | note ---- 3. list ---- |
| 528 | fn bn_list to void |
| 529 | bn_pkop bnt_list |
| 530 | o_flush |
| 531 | x = bn_spawn bnt_list |
| 532 | ns = get bn_g BNG_NS |
| 533 | n = get bn_g BNG_N |
| 534 | b = get bn_g BNG_BYTES |
| 535 | put bn_g BNG_REC 0 |
| 536 | put bn_g BNG_REF 0 |
| 537 | ok = bn_load bnt_list |
| 538 | if ok |
| 539 | bn_lscan |
| 540 | end |
| 541 | o_raw bnt_klist |
| 542 | o_raw bnt_kn |
| 543 | o_digits n |
| 544 | o_raw bnt_kbytes |
| 545 | o_digits b |
| 546 | bn_orates n b ns |
| 547 | o_raw bnt_kexit |
| 548 | o_digits x |
| 549 | o_raw bnt_krec |
| 550 | o_digits get bn_g BNG_REC |
| 551 | o_raw bnt_kref |
| 552 | o_digits get bn_g BNG_REF |
| 553 | o_raw bnt_kcmd |
| 554 | bn_ocmd |
| 555 | o_b 10 |
| 556 | bn_chk bnt_clexit x 0 |
| 557 | if not ok |
| 558 | bn_chk bnt_clout 0 1 |
| 559 | end |
| 560 | bn_chk bnt_clrec get bn_g BNG_REC n |
| 561 | bn_chk bnt_clref get bn_g BNG_REF 0 |
| 562 | o_flush |
| 563 | end |
| 564 | |
| 565 | note ---- 4. stats (parse only) ---- |
| 566 | fn bn_stats to void |
| 567 | bn_pkop bnt_stats |
| 568 | o_flush |
| 569 | x = bn_spawn bnt_stats |
| 570 | ns = get bn_g BNG_NS |
| 571 | n = get bn_g BNG_N |
| 572 | b = get bn_g BNG_BYTES |
| 573 | ok = bn_load bnt_stats |
| 574 | o_raw bnt_kstats |
| 575 | o_raw bnt_kn |
| 576 | o_digits n |
| 577 | o_raw bnt_kbytes |
| 578 | o_digits b |
| 579 | bn_orates n b ns |
| 580 | o_raw bnt_kexit |
| 581 | o_digits x |
| 582 | bn_okey bnt_kmsgs bnt_jmsg |
| 583 | bn_okey bnt_kpar bnt_jpar |
| 584 | bn_okey bnt_kref bnt_jref |
| 585 | bn_okey bnt_kpath bnt_jpath |
| 586 | bn_okey bnt_ksb bnt_jbytes |
| 587 | bn_okey bnt_kons bnt_jns |
| 588 | bn_oprates |
| 589 | o_raw bnt_kcmd |
| 590 | bn_ocmd |
| 591 | o_b 10 |
| 592 | bn_chk bnt_csexit x 0 |
| 593 | if not ok |
| 594 | bn_chk bnt_csout 0 1 |
| 595 | end |
| 596 | bn_chkkey bnt_csmsg bnt_jmsg n |
| 597 | bn_chkkey bnt_cspar bnt_jpar n |
| 598 | bn_chkkey bnt_csref bnt_jref 0 |
| 599 | bn_chkkey bnt_cspath bnt_jpath 0 |
| 600 | bn_chkkey bnt_csbytes bnt_jbytes b |
| 601 | o_flush |
| 602 | end |
| 603 | |
| 604 | note bn_oprates: the op's own rates from its record (n/a when a key is missing) |
| 605 | fn bn_oprates to void |
| 606 | m = bn_key bnt_jmsg |
| 607 | okm = get bn_g BNG_KOK |
| 608 | ob = bn_key bnt_jbytes |
| 609 | okb = get bn_g BNG_KOK |
| 610 | ons = bn_key bnt_jns |
| 611 | okn = get bn_g BNG_KOK |
| 612 | if eq and and okm okb okn 1 |
| 613 | o_raw bnt_komps |
| 614 | bn_ratio m 9 ons 3 |
| 615 | o_raw bnt_kombps |
| 616 | bn_ratio ob 3 ons 3 |
| 617 | ret |
| 618 | end |
| 619 | o_raw bnt_komps |
| 620 | o_raw mkt_na |
| 621 | o_raw bnt_kombps |
| 622 | o_raw mkt_na |
| 623 | end |
| 624 | |
| 625 | note ---- 5. verdict ---- |
| 626 | fn bn_end to int |
| 627 | f = get bn_g BNG_FAILS |
| 628 | if eq f 0 |
| 629 | o_raw bnt_pass |
| 630 | else |
| 631 | o_raw bnt_fail |
| 632 | end |
| 633 | o_raw bnt_kn |
| 634 | o_digits get bn_g BNG_N |
| 635 | o_raw bnt_kbytes |
| 636 | o_digits get bn_g BNG_BYTES |
| 637 | o_raw bnt_kfails |
| 638 | o_digits f |
| 639 | o_b 10 |
| 640 | o_flush |
| 641 | if eq f 0 |
| 642 | ret 0 |
| 643 | end |
| 644 | ret 2 |
| 645 | end |
| 646 | |
| 647 | fn main to int |
| 648 | c = ulong argcnt |
| 649 | if or lt c 3 gt c 5 |
| 650 | mk_err bnt_us |
| 651 | ret 1 |
| 652 | end |
| 653 | n = ulong 10000 |
| 654 | seed = ulong 1 |
| 655 | if ge c 4 |
| 656 | n = mk_argnum 3 |
| 657 | end |
| 658 | if ge c 5 |
| 659 | seed = mk_argnum 4 |
| 660 | end |
| 661 | if ne get mk_g MKG_BAD 0 |
| 662 | mk_err bnt_us |
| 663 | ret 1 |
| 664 | end |
| 665 | if not bn_args |
| 666 | mk_err bnt_us |
| 667 | ret 1 |
| 668 | end |
| 669 | r = bn_mkdir |
| 670 | if ne r 0 |
| 671 | ret r |
| 672 | end |
| 673 | r = bn_gen n seed |
| 674 | if ne r 0 |
| 675 | ret r |
| 676 | end |
| 677 | if eq bn_setup 0 |
| 678 | bn_list |
| 679 | bn_stats |
| 680 | end |
| 681 | ret bn_end |
| 682 | end |