nx_litpath_quirk_test.nx source
↩ module page · 88 lines · 4121 B
1// nx_litpath_quirk_test.nx -- minimal repro for literal-path syscall quirk.
2//
3// Hypothesis: passing a string-literal *u8 directly to sys_openat (via
4// sys_read_file or sys_openat_rd) silently fails to find the file,
5// while passing a mmap'd null-terminated buffer with the same bytes
6// succeeds.
7//
8// Test: create a file via known-good write path, then read back via
9// BOTH literal and mmap'd buffer. Compare results.
10//
11// expect_exit: 0
12// license_tier: ORIGINAL
13
14import "nx_chem.nx"
15import "nx_syscalls.nx"
16
17// Build "/tmp/nx_litpath_quirk_test_2026.txt" into out_buf, return length.
18// Hand-byte-coded so we don't rely on emit_str (which already works fine).
19func build_test_path(out_buf: *u8) -> nx_int {
20 out_buf[0] = 0x2F; out_buf[1] = 0x74; out_buf[2] = 0x6D; out_buf[3] = 0x70
21 out_buf[4] = 0x2F; out_buf[5] = 0x6E; out_buf[6] = 0x78; out_buf[7] = 0x5F
22 out_buf[8] = 0x6C; out_buf[9] = 0x69; out_buf[10] = 0x74; out_buf[11] = 0x70
23 out_buf[12] = 0x61; out_buf[13] = 0x74; out_buf[14] = 0x68; out_buf[15] = 0x5F
24 out_buf[16] = 0x71; out_buf[17] = 0x75; out_buf[18] = 0x69; out_buf[19] = 0x72
25 out_buf[20] = 0x6B; out_buf[21] = 0x5F; out_buf[22] = 0x32; out_buf[23] = 0x30
26 out_buf[24] = 0x32; out_buf[25] = 0x36; out_buf[26] = 0x2E; out_buf[27] = 0x74
27 out_buf[28] = 0x78; out_buf[29] = 0x74
28 out_buf[30] = 0
29 return 30
30}
31
32func main() -> nx_exit {
33 println("=== nx_litpath_quirk_test -- NishiLang literal-path syscall behavior ===" as *u8)
34
35 // STEP 1: write a known fixture file
36 let path_buf: *u8 = sys_mmap(64)
37 let _pl: nx_int = build_test_path(path_buf)
38 let content: *u8 = sys_mmap(32)
39 content[0] = 0x68; content[1] = 0x65; content[2] = 0x6C; content[3] = 0x6C; content[4] = 0x6F
40 content[5] = 0
41 let fd: i64 = sys_openat_wr(path_buf, 420)
42 if fd < 0 {
43 println(" FAIL: could not create test fixture file" as *u8)
44 return 1
45 }
46 let _wb: i64 = sys_write(fd, content, 5)
47 let _cc: i64 = sys_close(fd)
48 println(" Created /tmp/nx_litpath_quirk_test_2026.txt (5 bytes)" as *u8)
49
50 // STEP 2: read back via LITERAL path
51 let _lp1: i64 = print(" Test A: sys_read_file(LITERAL path) -> len = " as *u8)
52 var len_lit: i64 = 0
53 let buf_lit: *u8 = sys_read_file("/tmp/nx_litpath_quirk_test_2026.txt" as *u8, &len_lit)
54 let _lp2: i64 = print_i64(len_lit)
55 let _lp3: i64 = println("" as *u8)
56
57 // STEP 3: read back via MMAP'D path
58 let _mp1: i64 = print(" Test B: sys_read_file(mmap path) -> len = " as *u8)
59 var len_mmap: i64 = 0
60 let buf_mmap: *u8 = sys_read_file(path_buf, &len_mmap)
61 let _mp2: i64 = print_i64(len_mmap)
62 let _mp3: i64 = println("" as *u8)
63
64 // STEP 4: report verdict
65 println("" as *u8)
66 if len_lit == len_mmap {
67 if len_lit == 5 {
68 println(" VERDICT: literal-path and mmap-path BOTH work (5 bytes)." as *u8)
69 println(" NishiLang literal-path quirk DOES NOT REPRODUCE." as *u8)
70 println(" (If this regresses to FAIL, the quirk has returned.)" as *u8)
71 return 0
72 }
73 }
74 if len_lit == 0 {
75 if len_mmap == 5 {
76 println(" VERDICT: LITERAL fails (0 bytes), MMAP succeeds (5 bytes)." as *u8)
77 println(" CONFIRMED: NishiLang string-literal-as-syscall-path quirk" as *u8)
78 println(" is real. Workaround: copy literal to mmap'd buffer via" as *u8)
79 println(" nx_chem_emit_str() before passing to syscall. Pattern" as *u8)
80 println(" applied in nx_supplement.nx cmd_selftest (commit f3cac8be)." as *u8)
81 return 0 // exit 0 because we CHARACTERIZED the quirk; test purpose is monitoring
82 }
83 }
84 println(" VERDICT: unexpected result -- third behavior not previously seen." as *u8)
85 let _x1: i64 = print(" len_lit = " as *u8); let _x2: i64 = print_i64(len_lit); let _x3: i64 = println("" as *u8)
86 let _y1: i64 = print(" len_mmap = " as *u8); let _y2: i64 = print_i64(len_mmap); let _y3: i64 = println("" as *u8)
87 return 2
88}