Skip to content

Commit

Permalink
aio: test shared outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloudef committed Jun 19, 2024
1 parent d514421 commit df2d84f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/aio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ pub const ChildExit = ops.ChildExit;
pub const Socket = ops.Socket;
pub const CloseSocket = ops.CloseSocket;

test "shared outputs" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
var f = try tmp.dir.createFile("test", .{});
defer f.close();
var id1: Id = @enumFromInt(69);
var id2: Id = undefined;
var id3: Id = undefined;
var counter1: u16 = 0;
var counter2: u16 = 2;
try multi(.{
Fsync{ .file = f, .out_id = &id1, .counter = .{ .inc = &counter1 } },
Fsync{ .file = f, .out_id = &id2, .counter = .{ .inc = &counter1 } },
Fsync{ .file = f, .out_id = &id3, .counter = .{ .dec = &counter2 } },
});
try std.testing.expect(id1 != @as(Id, @enumFromInt(69)));
try std.testing.expect(id1 != id2);
try std.testing.expect(id1 != id3);
try std.testing.expect(id2 != id3);
try std.testing.expect(counter1 == 2);
try std.testing.expect(counter2 == 1);
}

test "Fsync" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
Expand Down
2 changes: 1 addition & 1 deletion src/aio/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn complete(self: *@This(), mode: aio.Dynamic.CompletionMode) aio.Completion
}

pub fn immediate(comptime len: u16, work: anytype) aio.ImmediateError!aio.CompletionResult {
var io = try uring_init(len);
var io = try uring_init(try std.math.ceilPowerOfTwo(u16, len));
defer io.deinit();
inline for (&work.ops, 0..) |*op, idx| try uring_queue(&io, op, idx);
var num = try uring_submit(&io);
Expand Down

0 comments on commit df2d84f

Please sign in to comment.