code wiki / (root) / nx_svcreg_gate.nx

nx_svcreg_gate.nx source

↩ module page · 41 lines · 2461 B

1// nx_svcreg_gate.nx -- proves services can be declared as DATA and read back byte-exact + enumerated. Uses a test 2// prefix so it is repeatable. license_tier: ORIGINAL 3import "nx_svcreg.nx" 4import "nx_gate.nx" 5 6func main() -> i64 { 7 gw("=== nx_svcreg_gate: declarative service registry (services as data on seg_store) ===\n" as *u8) 8 var pass: i64=0; var tot: i64=0 9 let P: *u8 = "knowledge/svcreg-test-" as *u8 10 11 let id1: i64 = svc_register_pfx(P, "archive-server" as *u8, "_offc/nx_archive_server.elf" as *u8, "8080" as *u8, "/blocklist" as *u8) 12 tot=tot+1; if id1 >= 0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 13 gw("T1 register archive-server (segid=" as *u8); gn(id1); gw(")\n" as *u8) 14 15 let id2: i64 = svc_register_pfx(P, "torrent" as *u8, "_offc/nx_torrent.elf" as *u8, "8097" as *u8, "/healthz" as *u8) 16 tot=tot+1; if id2 >= 0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 17 gw("T2 register torrent\n" as *u8) 18 19 let box: *i64 = sys_mmap(16) as *i64; let lenbox: *i64 = sys_mmap(16) as *i64 20 let found: i64 = svc_get_pfx(P, "archive-server" as *u8, box, lenbox) 21 tot=tot+1; if found==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 22 gw("T3 get archive-server -> found\n" as *u8) 23 24 let rec: *u8 = box[0] as *u8; let rl: i64 = lenbox[0] 25 let out2: *i64 = sys_mmap(16) as *i64 26 var t4: i64=0 27 if tr_field_eq(rec, rl, 1, "_offc/nx_archive_server.elf" as *u8, out2)==1 { if tr_field_eq(rec, rl, 2, "8080" as *u8, out2)==1 { t4=1 } } 28 tot=tot+1; if t4==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 29 gw("T4 fields parse byte-exact (elf=_offc/nx_archive_server.elf, port=8080)\n" as *u8) 30 31 let idxbuf: *u8 = sys_mmap(65536) 32 let n: i64 = svc_list_pfx(P, idxbuf, 65536) 33 var t5: i64=0 34 if reg_id_present(idxbuf, n, "archive-server" as *u8, 14)==1 { if reg_id_present(idxbuf, n, "torrent" as *u8, 7)==1 { t5=1 } } 35 tot=tot+1; if t5==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 36 gw("T5 list -> both services enumerable\n" as *u8) 37 38 gw("\n=== nx_svcreg_gate " as *u8); gn(pass); gw("/" as *u8); gn(tot); gw(" ===\n" as *u8) 39 if pass==tot { gw("SVCREG GREEN -- services declared as data (name/elf/port/health) on seg_store; nx_runsv can supervise by name\n" as *u8); sys_exit(0); return 0 } 40 gw("SVCREG RED\n" as *u8); sys_exit(1); return 1 41}