zig/std/os/linux/test.zig

45 lines
1.3 KiB
Zig
Raw Normal View History

const std = @import("../../index.zig");
const builtin = @import("builtin");
2017-11-11 07:12:46 +08:00
const linux = std.os.linux;
const assert = std.debug.assert;
test "getpid" {
assert(linux.getpid() != 0);
}
2017-11-11 07:12:46 +08:00
test "timer" {
const epoll_fd = linux.epoll_create();
var err = linux.getErrno(epoll_fd);
assert(err == 0);
const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
assert(linux.getErrno(timer_fd) == 0);
2018-05-29 08:23:55 +08:00
const time_interval = linux.timespec{
2017-11-11 07:12:46 +08:00
.tv_sec = 0,
2018-05-29 08:23:55 +08:00
.tv_nsec = 2000000,
2017-11-11 07:12:46 +08:00
};
2018-05-29 08:23:55 +08:00
const new_time = linux.itimerspec{
2017-11-11 07:12:46 +08:00
.it_interval = time_interval,
2018-05-29 08:23:55 +08:00
.it_value = time_interval,
2017-11-11 07:12:46 +08:00
};
err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
2017-11-11 07:12:46 +08:00
assert(err == 0);
2018-05-29 08:23:55 +08:00
var event = linux.epoll_event{
2017-11-11 07:12:46 +08:00
.events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
2018-05-29 08:23:55 +08:00
.data = linux.epoll_data{ .ptr = 0 },
2017-11-11 07:12:46 +08:00
};
err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);
2017-11-11 07:12:46 +08:00
assert(err == 0);
const events_one: linux.epoll_event = undefined;
var events = []linux.epoll_event{events_one} ** 8;
// TODO implicit cast from *[N]T to [*]T
err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1);
2017-11-11 07:12:46 +08:00
}