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.
This commit is contained in:
Igor Anić 2024-06-07 15:39:56 +02:00 committed by Andrew Kelley
parent 0ba64e9ce3
commit 45b62c4529

View File

@ -3503,10 +3503,6 @@ test "accept multishot" {
} }
test "accept/connect/send_zc/recv" { test "accept/connect/send_zc/recv" {
if (true) {
// https://github.com/ziglang/zig/issues/20212
return error.SkipZigTest;
}
try skipKernelLessThan(.{ .major = 6, .minor = 0, .patch = 0 }); try skipKernelLessThan(.{ .major = 6, .minor = 0, .patch = 0 });
var ring = IoUring.init(16, 0) catch |err| switch (err) { var ring = IoUring.init(16, 0) catch |err| switch (err) {
@ -3528,25 +3524,28 @@ test "accept/connect/send_zc/recv" {
_ = try ring.recv(0xffffffff, socket_test_harness.server, .{ .buffer = buffer_recv[0..] }, 0); _ = try ring.recv(0xffffffff, socket_test_harness.server, .{ .buffer = buffer_recv[0..] }, 0);
try testing.expectEqual(@as(u32, 2), try ring.submit()); try testing.expectEqual(@as(u32, 2), try ring.submit());
var cqe_send, const cqe_recv = brk: {
const cqe1 = try ring.copy_cqe();
const cqe2 = try ring.copy_cqe();
break :brk if (cqe1.user_data == 0xeeeeeeee) .{ cqe1, cqe2 } else .{ cqe2, cqe1 };
};
// First completion of zero-copy send. // First completion of zero-copy send.
// IORING_CQE_F_MORE, means that there // IORING_CQE_F_MORE, means that there
// will be a second completion event / notification for the // will be a second completion event / notification for the
// request, with the user_data field set to the same value. // request, with the user_data field set to the same value.
// buffer_send must be keep alive until second cqe. // buffer_send must be keep alive until second cqe.
var cqe_send = try ring.copy_cqe();
try testing.expectEqual(linux.io_uring_cqe{ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xeeeeeeee, .user_data = 0xeeeeeeee,
.res = buffer_send.len, .res = buffer_send.len,
.flags = linux.IORING_CQE_F_MORE, .flags = linux.IORING_CQE_F_MORE,
}, cqe_send); }, cqe_send);
const cqe_recv = try ring.copy_cqe();
try testing.expectEqual(linux.io_uring_cqe{ try testing.expectEqual(linux.io_uring_cqe{
.user_data = 0xffffffff, .user_data = 0xffffffff,
.res = buffer_recv.len, .res = buffer_recv.len,
.flags = cqe_recv.flags & linux.IORING_CQE_F_SOCK_NONEMPTY, .flags = cqe_recv.flags & linux.IORING_CQE_F_SOCK_NONEMPTY,
}, cqe_recv); }, cqe_recv);
try testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]); try testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]);
// Second completion of zero-copy send. // Second completion of zero-copy send.