nx_stl_write_test.nx source
↩ module page · 52 lines · 2291 B
1// nx_stl_write_test.nx -- KAT gate: the sovereign STL writer's output ROUND-TRIPS
2// through the existing nx_stl reader -> proves DCC export feeds the real pipeline.
3// expect_exit: 0.
4
5import "nx_syscalls.nx"
6import "nx_le.nx"
7import "nx_f32_encode.nx"
8import "nx_stl_write.nx"
9import "nx_stl.nx"
10
11func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
12func wn(v: i64) -> i64 {
13 let b: *u8 = sys_mmap(28); var m: i64 = v
14 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) }
15 let t: *u8 = sys_mmap(28); var k: i64 = 0
16 if m == 0 { t[0] = 48 as u8; k = 1 }
17 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
18 var i: i64 = 0; while i < k { b[i] = t[k - 1 - i]; i = i + 1 }
19 sys_write(1, b, k); return 0
20}
21func chk(cond: i64, pass: *i64, fail: *i64, label: *u8) -> i64 {
22 if cond == 1 { pass[0] = pass[0] + 1; w(" ok " as *u8); w(label); w("\n" as *u8) }
23 else { fail[0] = fail[0] + 1; w(" XX " as *u8); w(label); w("\n" as *u8) }
24 return 0
25}
26
27func main() -> i64 {
28 let pass: *i64 = (sys_mmap(8)) as *i64
29 let fail: *i64 = (sys_mmap(8)) as *i64
30 pass[0] = 0
31 fail[0] = 0
32 w("=== nx_stl_write KAT (DCC export -> round-trip via existing reader) ===\n" as *u8)
33
34 let buf: *u8 = sys_mmap(2048)
35 let n: i64 = nx_stl_write_cube(buf, 20)
36 w(" wrote bytes=" as *u8); wn(n); w("\n" as *u8)
37 chk(n == 684, pass, fail, "size = 84 + 50*12 = 684" as *u8)
38 chk(nx_le_read_u32(buf, 80) == 12, pass, fail, "header n_tris field = 12" as *u8)
39
40 // ROUND-TRIP: feed our STL to the EXISTING reader the pipeline uses
41 let res: *NxStlResult = nx_stl_load_binary(buf, n)
42 w(" reader verdict=" as *u8); wn(res.verdict)
43 w(" n_tris=" as *u8); wn(res.n_tris_header)
44 w(" uniq_verts=" as *u8); wn(res.n_verts_unique); w("\n" as *u8)
45 chk(res.verdict == NX_STL_OK, pass, fail, "existing reader ACCEPTS our STL (verdict OK)" as *u8)
46 chk(res.n_tris_header == 12, pass, fail, "reader sees 12 triangles" as *u8)
47 chk(res.n_verts_unique == 8, pass, fail, "reader dedups to 8 cube corners (valid topology)" as *u8)
48
49 w("=== VERDICT pass=" as *u8); wn(pass[0]); w(" fail=" as *u8); wn(fail[0]); w(" ===\n" as *u8)
50 if fail[0] == 0 { return 0 }
51 return 1
52}