nx_search_linear_test.nx source
↩ module page · 86 lines · 4226 B
1// nx_search_linear_test.nx -- smoke for nx_search_linear over the
2// bulk-ingested GBIF catalog at fixtures/gbif_bulk/ingested_bulk.jsonl.
3
4import "syscalls.nx"
5import "nx_search_linear.nx"
6
7func make_jsonl_path(out: *u8) -> i64 {
8 // "../../nishi-library/fixtures/gbif_bulk/ingested_bulk.jsonl"
9 out[0] = 0x2E; out[1] = 0x2E; out[2] = 0x2F
10 out[3] = 0x2E; out[4] = 0x2E; out[5] = 0x2F
11 out[6] = 0x6E; out[7] = 0x69; out[8] = 0x73; out[9] = 0x68
12 out[10] = 0x69; out[11] = 0x2D; out[12] = 0x6C; out[13] = 0x69
13 out[14] = 0x62; out[15] = 0x72; out[16] = 0x61; out[17] = 0x72
14 out[18] = 0x79; out[19] = 0x2F
15 out[20] = 0x66; out[21] = 0x69; out[22] = 0x78; out[23] = 0x74
16 out[24] = 0x75; out[25] = 0x72; out[26] = 0x65; out[27] = 0x73
17 out[28] = 0x2F
18 out[29] = 0x67; out[30] = 0x62; out[31] = 0x69; out[32] = 0x66
19 out[33] = 0x5F; out[34] = 0x62; out[35] = 0x75; out[36] = 0x6C
20 out[37] = 0x6B
21 out[38] = 0x2F
22 out[39] = 0x69; out[40] = 0x6E; out[41] = 0x67; out[42] = 0x65
23 out[43] = 0x73; out[44] = 0x74; out[45] = 0x65; out[46] = 0x64
24 out[47] = 0x5F; out[48] = 0x62; out[49] = 0x75; out[50] = 0x6C; out[51] = 0x6B
25 out[52] = 0x2E; out[53] = 0x6A; out[54] = 0x73; out[55] = 0x6F
26 out[56] = 0x6E; out[57] = 0x6C // "nl"
27 out[58] = 0
28 return 58
29}
30
31const NX_TEST_MATCH_CAP: i64 = 4096
32
33func main() -> i64 {
34 let path: *u8 = sys_mmap(64)
35 make_jsonl_path(path)
36
37 // Query 1: "Plantae" -- well-represented kingdom in the catalog.
38 let q1: *u8 = sys_mmap(16)
39 q1[0] = 0x50; q1[1] = 0x6C; q1[2] = 0x61; q1[3] = 0x6E // Plan
40 q1[4] = 0x74; q1[5] = 0x61; q1[6] = 0x65 // tae
41
42 let matches_raw: *u8 = sys_mmap(NX_TEST_MATCH_CAP * NX_SEARCH_MATCH_BYTES)
43 let matches: *NxSearchMatch = matches_raw as *NxSearchMatch
44 let rep_raw: *u8 = sys_mmap(NX_SEARCH_REPORT_BYTES)
45 let rep: *NxSearchReport = rep_raw as *NxSearchReport
46
47 let v: i64 = nx_search_linear_search(path, q1, 7, matches, NX_TEST_MATCH_CAP, rep)
48 if v != NX_SEARCH_OK { return __syscall(93, 1, 0, 0, 0, 0, 0) }
49 if rep.rows_scanned < 100 { return __syscall(93, 2, 0, 0, 0, 0, 0) }
50 if rep.rows_matched < 1 { return __syscall(93, 3, 0, 0, 0, 0, 0) }
51
52 // Verify first match looks like a row (starts with `{`)
53 let first: *NxSearchMatch = nx_search_match_at(matches, 0)
54 if first.row_ptr[0] != 0x7B { return __syscall(93, 4, 0, 0, 0, 0, 0) }
55 if first.row_len < 50 { return __syscall(93, 5, 0, 0, 0, 0, 0) }
56 if first.score < 1 { return __syscall(93, 6, 0, 0, 0, 0, 0) }
57
58 // Query 2: "Solanaceae" (nightshade family - potato/tomato/pepper).
59 // GBIF backbone bulk should include several Solanaceae species.
60 let q2: *u8 = sys_mmap(16)
61 q2[0] = 0x53; q2[1] = 0x6F; q2[2] = 0x6C; q2[3] = 0x61 // Sola
62 q2[4] = 0x6E; q2[5] = 0x61; q2[6] = 0x63; q2[7] = 0x65 // nace
63 q2[8] = 0x61; q2[9] = 0x65 // ae
64 let v2: i64 = nx_search_linear_search(path, q2, 10, matches, NX_TEST_MATCH_CAP, rep)
65 // Solanaceae may or may not appear in this specific paginated
66 // slice; accept OK with >=1 OR NO_MATCHES (which still proves the
67 // scan worked, just didn't find).
68 if v2 != NX_SEARCH_OK {
69 if v2 != NX_SEARCH_NO_MATCHES { return __syscall(93, 10, 0, 0, 0, 0, 0) }
70 }
71
72 // Query 3: "zzzzzzz_no_match_xyzpdq" -- must report NO_MATCHES.
73 let q3: *u8 = sys_mmap(32)
74 q3[0] = 0x7A; q3[1] = 0x7A; q3[2] = 0x7A; q3[3] = 0x7A
75 q3[4] = 0x7A; q3[5] = 0x7A; q3[6] = 0x7A; q3[7] = 0x5F
76 q3[8] = 0x6E; q3[9] = 0x6F; q3[10] = 0x5F; q3[11] = 0x6D
77 q3[12] = 0x61; q3[13] = 0x74; q3[14] = 0x63; q3[15] = 0x68
78 q3[16] = 0x5F; q3[17] = 0x78; q3[18] = 0x79; q3[19] = 0x7A
79 q3[20] = 0x70; q3[21] = 0x64; q3[22] = 0x71 // 23 bytes
80 let v3: i64 = nx_search_linear_search(path, q3, 23, matches, NX_TEST_MATCH_CAP, rep)
81 if v3 != NX_SEARCH_NO_MATCHES { return __syscall(93, 20, 0, 0, 0, 0, 0) }
82 if rep.rows_matched != 0 { return __syscall(93, 21, 0, 0, 0, 0, 0) }
83 if rep.rows_scanned < 100 { return __syscall(93, 22, 0, 0, 0, 0, 0) } // still scanned
84
85 return 0
86}