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" {...@@ -3503,10 +3503,6 @@ test "accept multishot" {
3503}3503}
35043504
3505test "accept/connect/send_zc/recv" {3505test "accept/connect/send_zc/recv" {
3506 if (true) {
3507 // https://github.com/ziglang/zig/issues/20212
3508 return error.SkipZigTest;
3509 }
3510 try skipKernelLessThan(.{ .major = 6, .minor = 0, .patch = 0 });3506 try skipKernelLessThan(.{ .major = 6, .minor = 0, .patch = 0 });
35113507
3512 var ring = IoUring.init(16, 0) catch |err| switch (err) {3508 var ring = IoUring.init(16, 0) catch |err| switch (err) {
...@@ -3528,25 +3524,28 @@ test "accept/connect/send_zc/recv" {...@@ -3528,25 +3524,28 @@ test "accept/connect/send_zc/recv" {
3528 _ = try ring.recv(0xffffffff, socket_test_harness.server, .{ .buffer = buffer_recv[0..] }, 0);3524 _ = try ring.recv(0xffffffff, socket_test_harness.server, .{ .buffer = buffer_recv[0..] }, 0);
3529 try testing.expectEqual(@as(u32, 2), try ring.submit());3525 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
3531 // First completion of zero-copy send.3533 // First completion of zero-copy send.
3532 // IORING_CQE_F_MORE, means that there3534 // IORING_CQE_F_MORE, means that there
3533 // will be a second completion event / notification for the3535 // will be a second completion event / notification for the
3534 // request, with the user_data field set to the same value.3536 // request, with the user_data field set to the same value.
3535 // buffer_send must be keep alive until second cqe.3537 // buffer_send must be keep alive until second cqe.
3536 var cqe_send = try ring.copy_cqe();
3537 try testing.expectEqual(linux.io_uring_cqe{3538 try testing.expectEqual(linux.io_uring_cqe{
3538 .user_data = 0xeeeeeeee,3539 .user_data = 0xeeeeeeee,
3539 .res = buffer_send.len,3540 .res = buffer_send.len,
3540 .flags = linux.IORING_CQE_F_MORE,3541 .flags = linux.IORING_CQE_F_MORE,
3541 }, cqe_send);3542 }, cqe_send);
35423543
3543 const cqe_recv = try ring.copy_cqe();
3544 try testing.expectEqual(linux.io_uring_cqe{3544 try testing.expectEqual(linux.io_uring_cqe{
3545 .user_data = 0xffffffff,3545 .user_data = 0xffffffff,
3546 .res = buffer_recv.len,3546 .res = buffer_recv.len,
3547 .flags = cqe_recv.flags & linux.IORING_CQE_F_SOCK_NONEMPTY,3547 .flags = cqe_recv.flags & linux.IORING_CQE_F_SOCK_NONEMPTY,
3548 }, cqe_recv);3548 }, cqe_recv);
3549
3550 try testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]);3549 try testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]);
35513550
3552 // Second completion of zero-copy send.3551 // Second completion of zero-copy send.