2019-03-02 13:46:04 -08:00
|
|
|
const std = @import("../../std.zig");
|
2018-04-22 10:24:25 -07:00
|
|
|
const builtin = @import("builtin");
|
2017-11-10 15:12:46 -08:00
|
|
|
const linux = std.os.linux;
|
2019-05-05 04:00:32 -07:00
|
|
|
const mem = std.mem;
|
|
|
|
const elf = std.elf;
|
2019-02-08 15:18:47 -08:00
|
|
|
const expect = std.testing.expect;
|
2017-11-10 15:12:46 -08:00
|
|
|
|
2018-08-03 08:45:23 -07:00
|
|
|
test "getpid" {
|
2019-02-08 15:18:47 -08:00
|
|
|
expect(linux.getpid() != 0);
|
2018-08-03 08:45:23 -07:00
|
|
|
}
|
|
|
|
|
2017-11-10 15:12:46 -08:00
|
|
|
test "timer" {
|
|
|
|
const epoll_fd = linux.epoll_create();
|
2019-05-26 20:35:26 -07:00
|
|
|
var err: usize = linux.getErrno(epoll_fd);
|
2019-02-08 15:18:47 -08:00
|
|
|
expect(err == 0);
|
2017-11-10 15:12:46 -08:00
|
|
|
|
|
|
|
const timer_fd = linux.timerfd_create(linux.CLOCK_MONOTONIC, 0);
|
2019-02-08 15:18:47 -08:00
|
|
|
expect(linux.getErrno(timer_fd) == 0);
|
2017-11-10 15:12:46 -08:00
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
const time_interval = linux.timespec{
|
2017-11-10 15:12:46 -08:00
|
|
|
.tv_sec = 0,
|
2018-05-28 17:23:55 -07:00
|
|
|
.tv_nsec = 2000000,
|
2017-11-10 15:12:46 -08:00
|
|
|
};
|
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
const new_time = linux.itimerspec{
|
2017-11-10 15:12:46 -08:00
|
|
|
.it_interval = time_interval,
|
2018-05-28 17:23:55 -07:00
|
|
|
.it_value = time_interval,
|
2017-11-10 15:12:46 -08:00
|
|
|
};
|
|
|
|
|
2018-06-16 23:57:07 -07:00
|
|
|
err = linux.timerfd_settime(@intCast(i32, timer_fd), 0, &new_time, null);
|
2019-02-08 15:18:47 -08:00
|
|
|
expect(err == 0);
|
2017-11-10 15:12:46 -08:00
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
var event = linux.epoll_event{
|
2017-11-10 15:12:46 -08:00
|
|
|
.events = linux.EPOLLIN | linux.EPOLLOUT | linux.EPOLLET,
|
2018-11-13 05:08:37 -08:00
|
|
|
.data = linux.epoll_data{ .ptr = 0 },
|
2017-11-10 15:12:46 -08:00
|
|
|
};
|
|
|
|
|
2018-06-16 23:57:07 -07:00
|
|
|
err = linux.epoll_ctl(@intCast(i32, epoll_fd), linux.EPOLL_CTL_ADD, @intCast(i32, timer_fd), &event);
|
2019-02-08 15:18:47 -08:00
|
|
|
expect(err == 0);
|
2017-11-10 15:12:46 -08:00
|
|
|
|
|
|
|
const events_one: linux.epoll_event = undefined;
|
2019-06-09 16:24:24 -07:00
|
|
|
var events = [_]linux.epoll_event{events_one} ** 8;
|
2017-11-10 15:12:46 -08:00
|
|
|
|
2018-06-03 22:09:15 -07:00
|
|
|
// TODO implicit cast from *[N]T to [*]T
|
2018-06-16 23:57:07 -07:00
|
|
|
err = linux.epoll_wait(@intCast(i32, epoll_fd), @ptrCast([*]linux.epoll_event, &events), 8, -1);
|
2017-11-10 15:12:46 -08:00
|
|
|
}
|
2019-10-12 05:55:02 -07:00
|
|
|
|
|
|
|
const File = std.fs.File;
|
|
|
|
|
|
|
|
test "statx" {
|
|
|
|
const tmp_file_name = "just_a_temporary_file.txt";
|
|
|
|
var file = try File.openWrite(tmp_file_name);
|
|
|
|
defer {
|
|
|
|
file.close();
|
|
|
|
std.fs.deleteFile(tmp_file_name) catch {};
|
|
|
|
}
|
|
|
|
|
|
|
|
var statx_buf: linux.Statx = undefined;
|
2019-11-19 17:29:08 -08:00
|
|
|
switch (linux.getErrno(linux.statx(file.handle, "", linux.AT_EMPTY_PATH, linux.STATX_BASIC_STATS, &statx_buf))) {
|
2019-10-12 05:55:02 -07:00
|
|
|
0 => {},
|
|
|
|
// The statx syscall was only introduced in linux 4.11
|
|
|
|
linux.ENOSYS => return error.SkipZigTest,
|
|
|
|
else => unreachable,
|
|
|
|
}
|
|
|
|
|
|
|
|
var stat_buf: linux.Stat = undefined;
|
2019-11-19 17:29:08 -08:00
|
|
|
switch (linux.getErrno(linux.fstatat(file.handle, "", &stat_buf, linux.AT_EMPTY_PATH))) {
|
2019-10-12 05:55:02 -07:00
|
|
|
0 => {},
|
|
|
|
else => unreachable,
|
|
|
|
}
|
|
|
|
|
2019-10-16 14:24:42 -07:00
|
|
|
expect(stat_buf.mode == statx_buf.mode);
|
|
|
|
expect(@bitCast(u32, stat_buf.uid) == statx_buf.uid);
|
|
|
|
expect(@bitCast(u32, stat_buf.gid) == statx_buf.gid);
|
2019-11-07 15:52:09 -08:00
|
|
|
expect(@bitCast(u64, @as(i64, stat_buf.size)) == statx_buf.size);
|
|
|
|
expect(@bitCast(u64, @as(i64, stat_buf.blksize)) == statx_buf.blksize);
|
|
|
|
expect(@bitCast(u64, @as(i64, stat_buf.blocks)) == statx_buf.blocks);
|
2019-10-12 05:55:02 -07:00
|
|
|
}
|