From ed36dbbd9c9dc21b2eebae1b31586fea1c6b51c3 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 25 Sep 2019 23:35:41 -0400 Subject: mv std/ lib/ that's all this commit does. further commits will fix cli flags and such. see #2221 --- lib/std/os/linux/test.zig | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/std/os/linux/test.zig (limited to 'lib/std/os/linux/test.zig') diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig new file mode 100644 index 0000000000..97bbcc402d --- /dev/null +++ b/lib/std/os/linux/test.zig @@ -0,0 +1,46 @@ +const std = @import("../../std.zig"); +const builtin = @import("builtin"); +const linux = std.os.linux; +const mem = std.mem; +const elf = std.elf; +const expect = std.testing.expect; + +test "getpid" { + expect(linux.getpid() != 0); +} + +test "timer" { + const epoll_fd = linux.epoll_create(); + var err: usize = linux.getErrno(epoll_fd); + expect(err == 0); + + const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0); + expect(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); + expect(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); + expect(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); +} -- cgit v1.2.3