code wiki / _hdl_build / nx_mgmt_proc_read_gate.nx

nx_mgmt_proc_read_gate.nx source

↩ module page · 35 lines · 2160 B

1// Regression for the management API's real bounded proc reader. 2import "nx_mgmt_api.nx" 3import "nx_gate_verdict.nx" 4const PRG_BUF: i64 = 262144 5const PRG_FIXTURE_BYTES: i64 = 8 6func main(argc: i64, argv: *i64) -> i64 { 7 let ctr: *i64 = gv_ctr() 8 let b: *u8 = sys_mmap(PRG_BUF) 9 let path: *u8 = "_build/nx_mgmt_proc_read_gate.fixture" as *u8 10 let fd: i64 = sys_openat_wr(path, 384) 11 gv_need("fixture can be opened" as *u8, fd >= 0, ctr) 12 if fd < 0 { return gv_verdict("MGMT-PROC-READ" as *u8,ctr,"fixture unavailable" as *u8) } 13 let wn: i64 = sys_write(fd, "abcdefgh" as *u8, PRG_FIXTURE_BYTES) 14 sys_close(fd) 15 gv_need("fixture written completely" as *u8,wn == PRG_FIXTURE_BYTES,ctr) 16 if wn != PRG_FIXTURE_BYTES { return gv_verdict("MGMT-PROC-READ" as *u8,ctr,"fixture incomplete" as *u8) } 17 gv_check("truncated-input-refused" as *u8,mnp_readproc(path,b,PRG_FIXTURE_BYTES) == (0 - 2),ctr) 18 gv_check("truncated-prefix-not-exposed" as *u8,b[0] == (0 as u8),ctr) 19 gv_check("exact-capacity-accepted" as *u8,mnp_readproc(path,b,PRG_FIXTURE_BYTES + 1) == PRG_FIXTURE_BYTES,ctr) 20 gv_check("last-byte-preserved" as *u8,b[7] == (104 as u8),ctr) 21 gv_check("terminator-present" as *u8,b[8] == (0 as u8),ctr) 22 gv_check("terminator-only-capacity-refused" as *u8,mnp_readproc(path,b,1) == (0 - 2),ctr) 23 b[0] = 77 as u8 24 gv_check("zero-capacity-refused" as *u8,mnp_readproc(path,b,0) == (0 - 1),ctr) 25 gv_check("zero-capacity-does-not-write" as *u8,b[0] == (77 as u8),ctr) 26 gv_check("absent-path-refused" as *u8,mnp_readproc("/proc/nishi_missing_proc_fixture" as *u8,b,9) == (0 - 1),ctr) 27 let count: i64 = mnp_ncpu(b,PRG_BUF) 28 gv_need("live CPU count readable" as *u8,count > 0,ctr) 29 if argc > 1 { 30 let expected: i64 = mnp_pdec(argv[1] as *u8,sd_len(argv[1] as *u8),0,sys_mmap(8) as *i64) 31 gv_need("expected CPU count positive" as *u8,expected > 0,ctr) 32 gv_check("live-CPU-count-matches-external-expectation" as *u8,count == expected,ctr) 33 } 34 return gv_verdict("MGMT-PROC-READ" as *u8,ctr,"actual bounded reader: truncation, exact capacity, absent path and live procfs" as *u8) 35}