2019-12-07 22:25:19 +03:00
|
|
|
module forkedtest
|
|
|
|
|
2020-04-23 06:16:10 +03:00
|
|
|
pub fn run (op fn(), label string, code Wi_si_code, status int) int {
|
2019-12-07 22:25:19 +03:00
|
|
|
child := sys_fork()
|
|
|
|
if child == 0 {
|
|
|
|
op()
|
|
|
|
sys_exit(0)
|
|
|
|
}
|
2019-12-08 13:44:52 +03:00
|
|
|
|
2020-04-23 06:16:10 +03:00
|
|
|
siginfo := [0].repeat(int(Sig_index.si_size))
|
2019-12-08 13:44:52 +03:00
|
|
|
|
|
|
|
e := sys_waitid(.p_pid, child, intptr(&siginfo[0]), .wexited, 0)
|
2019-12-07 22:25:19 +03:00
|
|
|
|
|
|
|
assert e == .enoerror
|
2020-04-23 06:16:10 +03:00
|
|
|
assert siginfo[int(Sig_index.si_pid)] == child
|
|
|
|
assert siginfo[int(Sig_index.si_signo)] == int(Signo.sigchld)
|
|
|
|
assert siginfo[int(Sig_index.si_uid)] == sys_getuid()
|
2019-12-07 22:25:19 +03:00
|
|
|
|
2020-04-23 06:16:10 +03:00
|
|
|
r_code := siginfo[Sig_index.si_code]
|
|
|
|
r_status := siginfo[Sig_index.si_status]
|
2019-12-07 22:25:19 +03:00
|
|
|
|
2019-12-08 13:44:52 +03:00
|
|
|
print("+++ ")
|
2019-12-07 22:25:19 +03:00
|
|
|
print(label)
|
|
|
|
if (int(code) == r_code) && (status == r_status) {
|
|
|
|
println(" PASSED")
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
println(" FAILED")
|
|
|
|
|
|
|
|
if int(code) != r_code {
|
|
|
|
print(">> Expecting si_code 0x")
|
2019-12-08 13:44:52 +03:00
|
|
|
println(i64_str(int(code),16))
|
2019-12-07 22:25:19 +03:00
|
|
|
print(">> Got 0x")
|
2019-12-08 13:44:52 +03:00
|
|
|
println(i64_str(r_code,16))
|
2019-12-07 22:25:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if status != r_status {
|
|
|
|
print(">> Expecting status 0x")
|
2019-12-08 13:44:52 +03:00
|
|
|
println(i64_str(status,16))
|
2019-12-07 22:25:19 +03:00
|
|
|
print(">> Got 0x")
|
2019-12-08 13:44:52 +03:00
|
|
|
println(i64_str(r_status,16))
|
2019-12-07 22:25:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn normal_run (op fn(), label string) int {
|
|
|
|
return run (op, label, .cld_exited, 0)
|
|
|
|
}
|