1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/builtin/bare/.checks/forkedtest/forkedtest.v
bogen85 8178e1f7da freestanding: malloc/free with mm_alloc an mm_free
Added more array support that depends on malloc. Added string clone (that uses malloc). Added test for it. Eliminated stack allocated buffers from most of the unit checks.
2019-12-08 13:44:52 +03:00

51 lines
1.0 KiB
V

module forkedtest
pub fn run (op fn(), label string, code wi_si_code, status int) int {
child := sys_fork()
if child == 0 {
op()
sys_exit(0)
}
siginfo := [0].repeat(int(sig_index.si_size))
e := sys_waitid(.p_pid, child, intptr(&siginfo[0]), .wexited, 0)
assert e == .enoerror
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()
r_code := siginfo[sig_index.si_code]
r_status := siginfo[sig_index.si_status]
print("+++ ")
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")
println(i64_str(int(code),16))
print(">> Got 0x")
println(i64_str(r_code,16))
}
if status != r_status {
print(">> Expecting status 0x")
println(i64_str(status,16))
print(">> Got 0x")
println(i64_str(r_status,16))
}
return 1
}
pub fn normal_run (op fn(), label string) int {
return run (op, label, .cld_exited, 0)
}