code wiki / (root) / nx_hash_bench_test.nx

nx_hash_bench_test.nx source

↩ module page · 28 lines · 1071 B

1// nx_hash_bench_test.nx -- correctness KAT for the hashing benchmark (deterministic only). 2// Native sovereign lane; exit 0 = pass, N = assertion N failed. Throughput is measured by 3// nx_hash_bench_run (timing, non-deterministic) and is NOT asserted here. 4 5import "nx_str.nx" 6import "nx_hash_bench.nx" 7 8func main() -> i64 { 9 // deterministic fill pattern 10 let buf: *u8 = sys_mmap(512) 11 nx_hb_fill(buf, 512) 12 if (buf[0] as i64) != 0 { return 1 } 13 if (buf[1] as i64) != 1 { return 2 } 14 if (buf[255] as i64) != 255 { return 3 } 15 if (buf[256] as i64) != 0 { return 4 } // wraps at 256 16 17 // hash correctness (the throughput numbers are only trustworthy if these pass) 18 if nx_hb_sha1_ok() != 1 { return 5 } 19 if nx_hb_sha256_ok() != 1 { return 6 } 20 21 // liveness: a real measurement over a non-trivial buffer returns a positive MB/s 22 let big: *u8 = sys_mmap(200000) 23 nx_hb_fill(big, 200000) 24 if nx_hb_sha1_mbps(big, 200000, 4) < 1 { return 7 } 25 if nx_hb_sha256_mbps(big, 200000, 4) < 1 { return 8 } 26 27 return 0 28}