authorgravatar for igor.anic@gmail.comIgor Anić <igor.anic@gmail.com> 2024-06-07 15:39:56+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-08 15:35:41-04:00
log45b62c4529ee76f0bb6e948626a7fa6a8024e243
tree714e5518e98ec06ab2da7eb7890ba7831007922c
parent0ba64e9ce3afcc400b55f7349c838e2d00e3c00d

io_uring: don't assume completions order

We are posting two submission (zero copy send and receive) and then reading two completions. There is no guarantee that those completions will be in the order of submissions. This test was expecting fist send completion then receive. Fix is allowing them to come other way too.

1 files changed, 6 insertions(+), 7 deletions(-)

lib/std/os/linux/IoUring.zig+6-7
......@@ -3503,10 +3503,6 @@ test "accept multishot" {
35033503}
35043504
35053505test "accept/connect/send_zc/recv" {
3506 if (true) {
3507 // https://github.com/ziglang/zig/issues/20212
3508 return error.SkipZigTest;
3509 }
35103506 try skipKernelLessThan(.{ .major = 6, .minor = 0, .patch = 0 });
35113507
35123508 var ring = IoUring.init(16, 0) catch |err| switch (err) {
......@@ -3528,25 +3524,28 @@ test "accept/connect/send_zc/recv" {
35283524 _ = try ring.recv(0xffffffff, socket_test_harness.server, .{ .buffer = buffer_recv[0..] }, 0);
35293525 try testing.expectEqual(@as(u32, 2), try ring.submit());
35303526
3527 var cqe_send, const cqe_recv = brk: {
3528 const cqe1 = try ring.copy_cqe();
3529 const cqe2 = try ring.copy_cqe();
3530 break :brk if (cqe1.user_data == 0xeeeeeeee) .{ cqe1, cqe2 } else .{ cqe2, cqe1 };
3531 };
3532
35313533 // First completion of zero-copy send.
35323534 // IORING_CQE_F_MORE, means that there
35333535 // will be a second completion event / notification for the
35343536 // request, with the user_data field set to the same value.
35353537 // buffer_send must be keep alive until second cqe.
3536 var cqe_send = try ring.copy_cqe();
35373538 try testing.expectEqual(linux.io_uring_cqe{
35383539 .user_data = 0xeeeeeeee,
35393540 .res = buffer_send.len,
35403541 .flags = linux.IORING_CQE_F_MORE,
35413542 }, cqe_send);
35423543
3543 const cqe_recv = try ring.copy_cqe();
35443544 try testing.expectEqual(linux.io_uring_cqe{
35453545 .user_data = 0xffffffff,
35463546 .res = buffer_recv.len,
35473547 .flags = cqe_recv.flags & linux.IORING_CQE_F_SOCK_NONEMPTY,
35483548 }, cqe_recv);
3549
35503549 try testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]);
35513550
35523551 // Second completion of zero-copy send.