diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-09-26 01:54:45 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-26 01:54:45 -0400 |
| commit | 68bb3945708c43109c48bda3664176307d45b62c (patch) | |
| tree | afb9731e10cef9d192560b52cd9ae2cf179775c4 /lib/std/os/linux/test.zig | |
| parent | 6128bc728d1e1024a178c16c2149f5b1a167a013 (diff) | |
| parent | 4637e8f9699af9c3c6cf4df50ef5bb67c7a318a4 (diff) | |
| download | zig-68bb3945708c43109c48bda3664176307d45b62c.tar.gz zig-68bb3945708c43109c48bda3664176307d45b62c.zip | |
Merge pull request #3315 from ziglang/mv-std-lib
Move std/ to lib/std/
Diffstat (limited to 'lib/std/os/linux/test.zig')
| -rw-r--r-- | lib/std/os/linux/test.zig | 46 |
1 files changed, 46 insertions, 0 deletions
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); +} |
