zig/std/os/linux/test.zig
Jimmi Holst Christensen 8139c5a516
New Zig formal grammar (#1685)
Reverted #1628 and changed the grammar+parser of the language to not allow certain expr where types are expected
2018-11-13 05:08:37 -08:00

45 lines
1.3 KiB
Zig

const std = @import("../../index.zig");
const builtin = @import("builtin");
const linux = std.os.linux;
const assert = std.debug.assert;
test "getpid" {
assert(linux.getpid() != 0);
}
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);
const time_interval = linux.timespec{
.tv_sec = 0,
.tv_nsec = 2000000,
};
const new_time = linux.itimerspec{
.it_interval = time_interval,
.it_value = time_interval,
};
err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
assert(err == 0);
var event = linux.epoll_event{
.events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
.data = linux.epoll_data{ .ptr = 0 },
};
err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);
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);
}