From a67f140d2f1247d3996f763dd36e55cbecb09eef Mon Sep 17 00:00:00 2001 From: Joran Dirk Greef Date: Sun, 1 Nov 2020 11:55:27 +0200 Subject: [PATCH] Add test --- lib/std/os/linux/test.zig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/std/os/linux/test.zig b/lib/std/os/linux/test.zig index 7599cfc395..24c96cdd70 100644 --- a/lib/std/os/linux/test.zig +++ b/lib/std/os/linux/test.zig @@ -11,6 +11,25 @@ const elf = std.elf; const expect = std.testing.expect; const fs = std.fs; +test "fallocate" { + const path = "test_fallocate"; + const file = try fs.cwd().createFile(path, .{ .truncate = true, .mode = 0o666 }); + defer file.close(); + defer fs.cwd().deleteFile(path) catch {}; + + expect((try file.stat()).size == 0); + + const len: u64 = 65536; + switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) { + 0 => {}, + linux.ENOSYS => return error.SkipZigTest, + linux.EOPNOTSUPP => return error.SkipZigTest, + else => unreachable, + } + + expect((try file.stat()).size == len); +} + test "getpid" { expect(linux.getpid() != 0); }