code wiki / (root) / nx_attention_class_test.nx

nx_attention_class_test.nx source

↩ module page · 57 lines · 2425 B

1// nx_attention_class_test.nx -- smoke for nx_attention_class. 2 3import "nx_syscalls.nx" 4import "nx_attention_class.nx" 5 6func main() -> i64 { 7 // 1: enum sealed, seven classes 8 if NX_AC_N_CLASSES != 7 { return 1 } 9 10 // 2: all canonical class values are valid 11 if nx_ac_is_valid(NX_AC_INTERACTIVE_FOREGROUND_GAME) != 1 { return 2 } 12 if nx_ac_is_valid(NX_AC_IDLE_OPPORTUNISTIC) != 1 { return 3 } 13 14 // 3: out-of-range rejected 15 if nx_ac_is_valid(-1) != 0 { return 4 } 16 if nx_ac_is_valid(7) != 0 { return 5 } 17 if nx_ac_is_valid(99) != 0 { return 6 } 18 19 // 4: foreground predicates 20 if nx_ac_is_foreground(NX_AC_INTERACTIVE_FOREGROUND_GAME) != 1 { return 7 } 21 if nx_ac_is_foreground(NX_AC_VIDEO_CALL) != 1 { return 8 } 22 if nx_ac_is_foreground(NX_AC_DEV) != 0 { return 9 } 23 if nx_ac_is_foreground(NX_AC_BACKGROUND_INFERENCE) != 0 { return 10 } 24 25 // 5: background predicates 26 if nx_ac_is_background(NX_AC_BACKGROUND_INFERENCE) != 1 { return 11 } 27 if nx_ac_is_background(NX_AC_BACKGROUND_BUILD) != 1 { return 12 } 28 if nx_ac_is_background(NX_AC_BACKGROUND_HEALTH) != 1 { return 13 } 29 if nx_ac_is_background(NX_AC_IDLE_OPPORTUNISTIC) != 1 { return 14 } 30 if nx_ac_is_background(NX_AC_VIDEO_CALL) != 0 { return 15 } 31 32 // 6: priority strict total order 33 if nx_ac_priority(NX_AC_INTERACTIVE_FOREGROUND_GAME) != 0 { return 16 } 34 if nx_ac_priority(NX_AC_VIDEO_CALL) != 1 { return 17 } 35 if nx_ac_priority(NX_AC_IDLE_OPPORTUNISTIC) != 6 { return 18 } 36 37 // 7: invalid class gets last-rank priority 38 if nx_ac_priority(99) != NX_AC_N_CLASSES { return 19 } 39 40 // 8: higher_priority predicate 41 if nx_ac_higher_priority(NX_AC_INTERACTIVE_FOREGROUND_GAME, 42 NX_AC_BACKGROUND_INFERENCE) != 1 { return 20 } 43 if nx_ac_higher_priority(NX_AC_IDLE_OPPORTUNISTIC, 44 NX_AC_VIDEO_CALL) != 0 { return 21 } 45 if nx_ac_higher_priority(NX_AC_DEV, NX_AC_DEV) != 1 { return 22 } 46 47 // 9: yield quantum decreases with priority rank 48 let q_game: nx_size = nx_ac_yield_quantum_us(NX_AC_INTERACTIVE_FOREGROUND_GAME) 49 let q_call: nx_size = nx_ac_yield_quantum_us(NX_AC_VIDEO_CALL) 50 let q_idle: nx_size = nx_ac_yield_quantum_us(NX_AC_IDLE_OPPORTUNISTIC) 51 if q_game <= q_call { return 23 } 52 if q_call <= q_idle { return 24 } 53 if q_game != 16000 { return 25 } 54 if q_idle != 500 { return 26 } 55 56 return 0 57}