nx_hunt_partition_test.nx source
↩ module page · 49 lines · 2039 B
1// nx_hunt_partition_test.nx -- smoke for nx_hunt_partition.
2
3import "nx_syscalls.nx"
4import "nx_hunt_partition.nx"
5
6func main() -> i64 {
7 if NX_HR_N_ROLES != 5 { return 1 }
8 if nx_hr_is_valid(NX_HR_KILLER) != 1 { return 2 }
9 if nx_hr_is_valid(5) != 0 { return 3 }
10
11 let p: *NxHuntPartition = nx_hunt_partition_new(16)
12
13 // Cell 10 claims SCOUT for target 100
14 if nx_hunt_partition_claim(p, 10, 100, NX_HR_SCOUT, 1000) != NX_HP_OK { return 4 }
15 if nx_hunt_partition_holder(p, 100, NX_HR_SCOUT) != 10 { return 5 }
16
17 // Same role for same target by different cell -- REFUSED
18 if nx_hunt_partition_claim(p, 20, 100, NX_HR_SCOUT, 1100) != NX_HP_ERR_ROLE_TAKEN { return 6 }
19
20 // Different role for same target -- OK
21 if nx_hunt_partition_claim(p, 20, 100, NX_HR_ENGAGER, 1200) != NX_HP_OK { return 7 }
22 if nx_hunt_partition_holder(p, 100, NX_HR_ENGAGER) != 20 { return 8 }
23
24 // Same role for different target -- OK
25 if nx_hunt_partition_claim(p, 10, 200, NX_HR_SCOUT, 1300) != NX_HP_OK { return 9 }
26 if nx_hunt_partition_holder(p, 200, NX_HR_SCOUT) != 10 { return 10 }
27
28 // Bad role
29 if nx_hunt_partition_claim(p, 30, 300, 99, 1400) != NX_HP_ERR_BAD_ROLE { return 11 }
30
31 // Count by role
32 if nx_hunt_partition_count_by_role(p, NX_HR_SCOUT) != 2 { return 12 }
33 if nx_hunt_partition_count_by_role(p, NX_HR_ENGAGER) != 1 { return 13 }
34 if nx_hunt_partition_count_by_role(p, NX_HR_KILLER) != 0 { return 14 }
35 if nx_hunt_partition_count(p) != 3 { return 15 }
36
37 // Release frees the role
38 if nx_hunt_partition_release(p, 10, 100, NX_HR_SCOUT) != NX_HP_OK { return 16 }
39 if nx_hunt_partition_count(p) != 2 { return 17 }
40 if nx_hunt_partition_holder(p, 100, NX_HR_SCOUT) != -1 { return 18 }
41
42 // Now another cell can claim SCOUT for target 100
43 if nx_hunt_partition_claim(p, 30, 100, NX_HR_SCOUT, 2000) != NX_HP_OK { return 19 }
44
45 // Release nonexistent
46 if nx_hunt_partition_release(p, 99, 99, NX_HR_KILLER) != NX_HP_ERR_NOT_FOUND { return 20 }
47
48 return 0
49}