zig/std/os/linux/test.zig

47 lines
1.3 KiB
Zig
Raw Normal View History

2019-03-03 05:46:04 +08:00
const std = @import("../../std.zig");
const builtin = @import("builtin");
2017-11-11 07:12:46 +08:00
const linux = std.os.linux;
2019-05-05 19:00:32 +08:00
const mem = std.mem;
const elf = std.elf;
const expect = std.testing.expect;
2017-11-11 07:12:46 +08:00
test "getpid" {
expect(linux.getpid() != 0);
}
2017-11-11 07:12:46 +08:00
test "timer" {
const epoll_fd = linux.epoll_create();
2019-05-27 11:35:26 +08:00
var err: usize = linux.getErrno(epoll_fd);
expect(err == 0);
2017-11-11 07:12:46 +08:00
const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
expect(linux.getErrno(timer_fd) == 0);
2017-11-11 07:12:46 +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
};
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);
expect(err == 0);
2017-11-11 07:12:46 +08:00
var event = linux.epoll_event{
2017-11-11 07:12:46 +08:00
.events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
.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);
expect(err == 0);
2017-11-11 07:12:46 +08:00
const events_one: linux.epoll_event = undefined;
var events = [_]linux.epoll_event{events_one} ** 8;
2017-11-11 07:12:46 +08:00
// 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
}