diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-11-10 18:25:32 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-11-10 18:25:32 -0500 |
| commit | ca87f55a7b8416e0f0922af7178a8774e81eba97 (patch) | |
| tree | cbebd1f95c5873199d648ea4ba6c214e781fcf2c /std/os/linux_test.zig | |
| parent | 1403748fd8f923ac4b23bb19d02aa44fd739933d (diff) | |
| parent | 5ae53dacfb3e66fd626aa72a900b6b067b9ac19e (diff) | |
| download | zig-ca87f55a7b8416e0f0922af7178a8774e81eba97.tar.gz zig-ca87f55a7b8416e0f0922af7178a8774e81eba97.zip | |
Merge branch 'bscheinman-linux_timer'
Diffstat (limited to 'std/os/linux_test.zig')
| -rw-r--r-- | std/os/linux_test.zig | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/std/os/linux_test.zig b/std/os/linux_test.zig new file mode 100644 index 0000000000..265d0a17f9 --- /dev/null +++ b/std/os/linux_test.zig @@ -0,0 +1,38 @@ +const std = @import("std"); +const linux = std.os.linux; +const assert = std.debug.assert; + +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(i32(timer_fd), 0, &new_time, null); + assert(err == 0); + + var event = linux.epoll_event { + .events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET, + .data = 0 + }; + + err = linux.epoll_ctl(i32(epoll_fd), linux.EPOLL_CTL_ADD, i32(timer_fd), &event); + assert(err == 0); + + const events_one: linux.epoll_event = undefined; + var events = []linux.epoll_event{events_one} ** 8; + + err = linux.epoll_wait(i32(epoll_fd), &events[0], 8, -1); +} |
