code wiki / (root) / nx_vacuole_test.nx

nx_vacuole_test.nx source

↩ module page · 58 lines · 1957 B

1// nx_vacuole_test.nx -- smoke for nx_vacuole. 2 3import "nx_syscalls.nx" 4import "nx_methyl.nx" 5import "nx_vacuole.nx" 6 7func main() -> i64 { 8 let sig: *u8 = (sys_mmap(96)) as *u8 9 sig[0] = 1 as u8 10 let mark: *NxMethylMark = nx_methyl_new(7, 0xcafe, 1000, sig, 96) 11 let body: *u8 = (sys_mmap(64)) as *u8 12 body[0] = 65 as u8 13 14 let v: *NxVacuole = nx_vacuole_new(8) 15 if v.capacity != 8 { return 1 } 16 if v.count != 0 { return 2 } 17 18 if nx_vacuole_put(v, 0xaa, body, 64, mark, 1000) != NX_VAC_OK { return 3 } 19 if v.count != 1 { return 4 } 20 if nx_vacuole_contains(v, 0xaa) != 1 { return 5 } 21 if nx_vacuole_contains(v, 0xbb) != 0 { return 6 } 22 23 let e: *NxVacuoleEntry = nx_vacuole_get(v, 0xaa) 24 if (e as i64) == 0 { return 7 } 25 if e.content_hash != 0xaa { return 8 } 26 if e.payload_len != 64 { return 9 } 27 28 // Idempotent put (same hash) 29 nx_vacuole_put(v, 0xaa, body, 64, mark, 2000) 30 if v.count != 1 { return 10 } 31 32 // Different hashes 33 nx_vacuole_put(v, 0xbb, body, 64, mark, 3000) 34 nx_vacuole_put(v, 0xcc, body, 64, mark, 4000) 35 if v.count != 3 { return 11 } 36 37 // Delete middle 38 if nx_vacuole_delete(v, 0xbb) != NX_VAC_OK { return 12 } 39 if v.count != 2 { return 13 } 40 if nx_vacuole_contains(v, 0xbb) != 0 { return 14 } 41 if nx_vacuole_contains(v, 0xaa) != 1 { return 15 } 42 if nx_vacuole_contains(v, 0xcc) != 1 { return 16 } 43 44 // Delete nonexistent 45 if nx_vacuole_delete(v, 0x9999) != NX_VAC_ERR_NOT_FOUND { return 17 } 46 47 // NULL mark refused 48 let null_mark: *NxMethylMark = (0 as i64) as *NxMethylMark 49 if nx_vacuole_put(v, 0xdd, body, 64, null_mark, 5000) != NX_VAC_ERR_BAD_MARK { return 18 } 50 51 // Full 52 let small: *NxVacuole = nx_vacuole_new(2) 53 nx_vacuole_put(small, 0x1, body, 64, mark, 1000) 54 nx_vacuole_put(small, 0x2, body, 64, mark, 1000) 55 if nx_vacuole_put(small, 0x3, body, 64, mark, 1000) != NX_VAC_ERR_FULL { return 19 } 56 57 return 0 58}