code wiki / _hdl_build / nx_gzip_lib_probe.nx

nx_gzip_lib_probe.nx source

↩ module page · 25 lines · 1807 B

1// nx_gzip_lib_probe.nx -- proves nx_gzip_lib.nx is IMPORTABLE and that gz_compress links and works. 2// WHY THIS EXISTS: /api/build compiles its target as a PROGRAM, so a no-main lib cannot be built 3// standalone -- "no artifact" from `build target=nx_gzip_lib` is therefore NOT evidence the lib is 4// broken. The only honest test of an importable lib is to build a consumer of it. This is that 5// consumer, and it is also the CONTROL that separates "my lib is bad" from "the build lane is stuck". 6// ANTI-VACUITY: a probe that only checked rc=0 would pass if gz_compress returned garbage, so it 7// asserts the RFC-1952 magic bytes AND that the output is genuinely smaller than the input. A stub 8// returning 0, or copying the input through, cannot pass this. 9import "nx_gzip_lib.nx" 10 11func main(argc: i64, argv: *i64) -> i64 { 12 let msg: *u8 = "the quick brown fox jumps over the lazy dog. the quick brown fox jumps over the lazy dog. the quick brown fox jumps over the lazy dog.\x00" as *u8 13 var n: i64 = 0 14 while msg[n] != (0 as u8) { n = n + 1 } 15 let ob: *u8 = sys_mmap(n * 2 + GZ_MAGIC_4096) 16 let olen: i64 = gz_compress(msg, n, 2, ob) 17 gz_w("GZLIB-PROBE in=" as *u8); gz_wn(n); gz_w(" out=" as *u8); gz_wn(olen); gz_w("\n" as *u8) 18 if olen <= 0 { gz_w("FAIL: gz_compress returned nothing\n" as *u8); sys_exit(1); return 1 } 19 if ob[0] != (0x1f as u8) { gz_w("FAIL: no gzip magic byte 0\n" as *u8); sys_exit(1); return 1 } 20 if ob[1] != (0x8b as u8) { gz_w("FAIL: no gzip magic byte 1\n" as *u8); sys_exit(1); return 1 } 21 if olen >= n { gz_w("FAIL: output not smaller than input -- compression did nothing\n" as *u8); sys_exit(1); return 1 } 22 gz_w("GZLIB-PROBE verdict=GREEN -- lib imports, gz_compress emits a real gzip container\n" as *u8) 23 sys_exit(0) 24 return 0 25}