code wiki / (root) / nx_tools_timing_fixture.nx

nx_tools_timing_fixture.nx source

↩ module page · 22 lines · 801 B

1// Dedicated fixture: stdout and exit only. All timings supplied by the gate. 2import "nx_syscalls.nx" 3const TF_FAILURE: i64 = 7 4const TF_I64_MAX: i64 = 9223372036854775807 5func main(argc: i64, argv: *i64) -> i64 { 6 if argc != 3 { return 3 } 7 let mode: *u8 = argv[1] as *u8 8 let number: *u8 = argv[2] as *u8 9 var delay: i64 = 0 10 var i: i64 = 0 11 while number[i] != (0 as u8) { 12 let c: i64 = number[i] as i64 13 if c < 48 { return 3 }; if c > 57 { return 3 } 14 if delay > (TF_I64_MAX-(c-48))/10 { return 3 } 15 delay = delay*10+c-48; i = i+1 16 } 17 if i == 0 { return 3 } 18 if sys_sleep_ms(delay) < 0 { return 4 } 19 if sys_write(1, "timing-fixture-output\n" as *u8, 22) != 22 { return 5 } 20 if mode[0] == (102 as u8) { return TF_FAILURE } 21 return 0 22}