| ... | ... | @@ -475,9 +475,6 @@ test "close" { |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | test "accept/connect/send/recv" { |
| 478 | | const io = testing.io; |
| 479 | | _ = io; |
| 480 | | |
| 481 | 478 | var ring = IoUring.init(16, 0) catch |err| switch (err) { |
| 482 | 479 | error.SystemOutdated => return error.SkipZigTest, |
| 483 | 480 | error.PermissionDenied => return error.SkipZigTest, |
| ... | ... | @@ -620,7 +617,7 @@ test "timeout (after a relative time)" { |
| 620 | 617 | |
| 621 | 618 | const ms = 10; |
| 622 | 619 | const margin = 5; |
| 623 | | const ts: linux.kernel_timespec = .{ .sec = 0, .nsec = ms * 1000000 }; |
| 620 | const ts: linux.kernel_timespec = .{ .sec = 0, .nsec = ms * std.time.ns_per_ms }; |
| 624 | 621 | |
| 625 | 622 | const started = std.Io.Clock.awake.now(io); |
| 626 | 623 | const sqe = try ring.timeout(0x55555555, &ts, 0, 0); |
| ... | ... | @@ -730,9 +727,6 @@ test "timeout_remove" { |
| 730 | 727 | } |
| 731 | 728 | |
| 732 | 729 | test "accept/connect/recv/link_timeout" { |
| 733 | | const io = testing.io; |
| 734 | | _ = io; |
| 735 | | |
| 736 | 730 | var ring = IoUring.init(16, 0) catch |err| switch (err) { |
| 737 | 731 | error.SystemOutdated => return error.SkipZigTest, |
| 738 | 732 | error.PermissionDenied => return error.SkipZigTest, |
| ... | ... | @@ -748,7 +742,7 @@ test "accept/connect/recv/link_timeout" { |
| 748 | 742 | const sqe_recv = try ring.recv(0xffffffff, socket_test_harness.server, .{ .buffer = buffer_recv[0..] }, 0); |
| 749 | 743 | sqe_recv.flags |= linux.IOSQE_IO_LINK; |
| 750 | 744 | |
| 751 | | const ts = linux.kernel_timespec{ .sec = 0, .nsec = 1000000 }; |
| 745 | const ts: linux.kernel_timespec = .{ .sec = 0, .nsec = std.time.ns_per_ms }; |
| 752 | 746 | _ = try ring.link_timeout(0x22222222, &ts, 0); |
| 753 | 747 | |
| 754 | 748 | const nr_wait = try ring.submit(); |
| ... | ... | @@ -883,9 +877,6 @@ test "statx" { |
| 883 | 877 | } |
| 884 | 878 | |
| 885 | 879 | test "accept/connect/recv/cancel" { |
| 886 | | const io = testing.io; |
| 887 | | _ = io; |
| 888 | | |
| 889 | 880 | var ring = IoUring.init(16, 0) catch |err| switch (err) { |
| 890 | 881 | error.SystemOutdated => return error.SkipZigTest, |
| 891 | 882 | error.PermissionDenied => return error.SkipZigTest, |
| ... | ... | @@ -1568,9 +1559,6 @@ test "remove_buffers" { |
| 1568 | 1559 | } |
| 1569 | 1560 | |
| 1570 | 1561 | test "provide_buffers: accept/connect/send/recv" { |
| 1571 | | const io = testing.io; |
| 1572 | | _ = io; |
| 1573 | | |
| 1574 | 1562 | var ring = IoUring.init(16, 0) catch |err| switch (err) { |
| 1575 | 1563 | error.SystemOutdated => return error.SkipZigTest, |
| 1576 | 1564 | error.PermissionDenied => return error.SkipZigTest, |
| ... | ... | @@ -1777,11 +1765,6 @@ test "accept multishot" { |
| 1777 | 1765 | } |
| 1778 | 1766 | |
| 1779 | 1767 | test "accept/connect/send_zc/recv" { |
| 1780 | | try skipKernelLessThan(.{ .major = 6, .minor = 0, .patch = 0 }); |
| 1781 | | |
| 1782 | | const io = testing.io; |
| 1783 | | _ = io; |
| 1784 | | |
| 1785 | 1768 | var ring = IoUring.init(16, 0) catch |err| switch (err) { |
| 1786 | 1769 | error.SystemOutdated => return error.SkipZigTest, |
| 1787 | 1770 | error.PermissionDenied => return error.SkipZigTest, |
| ... | ... | @@ -1789,6 +1772,13 @@ test "accept/connect/send_zc/recv" { |
| 1789 | 1772 | }; |
| 1790 | 1773 | defer ring.deinit(); |
| 1791 | 1774 | |
| 1775 | const probe = ring.get_probe() catch return error.SkipZigTest; |
| 1776 | const ops_not_supported = !probe.is_supported(.ACCEPT) or |
| 1777 | !probe.is_supported(.CONNECT) or |
| 1778 | !probe.is_supported(.SEND_ZC) or |
| 1779 | !probe.is_supported(.RECV); |
| 1780 | if (ops_not_supported) return error.SkipZigTest; |
| 1781 | |
| 1792 | 1782 | const socket_test_harness = try createSocketTestHarness(&ring); |
| 1793 | 1783 | defer socket_test_harness.close(); |
| 1794 | 1784 | |
| ... | ... | @@ -1836,14 +1826,16 @@ test "accept/connect/send_zc/recv" { |
| 1836 | 1826 | } |
| 1837 | 1827 | |
| 1838 | 1828 | test "accept_direct" { |
| 1839 | | try skipKernelLessThan(.{ .major = 5, .minor = 19, .patch = 0 }); |
| 1840 | | |
| 1841 | 1829 | var ring = IoUring.init(1, 0) catch |err| switch (err) { |
| 1842 | 1830 | error.SystemOutdated => return error.SkipZigTest, |
| 1843 | 1831 | error.PermissionDenied => return error.SkipZigTest, |
| 1844 | 1832 | else => return err, |
| 1845 | 1833 | }; |
| 1846 | 1834 | defer ring.deinit(); |
| 1835 | |
| 1836 | const probe = ring.get_probe() catch return error.SkipZigTest; |
| 1837 | if (!probe.is_supported(.ACCEPT)) return error.SkipZigTest; |
| 1838 | |
| 1847 | 1839 | var address: linux.sockaddr.in = .{ |
| 1848 | 1840 | .port = 0, |
| 1849 | 1841 | .addr = @as(*align(1) const u32, @ptrCast( |
| ... | ... | @@ -1921,8 +1913,6 @@ test "accept_direct" { |
| 1921 | 1913 | } |
| 1922 | 1914 | |
| 1923 | 1915 | test "accept_multishot_direct" { |
| 1924 | | try skipKernelLessThan(.{ .major = 5, .minor = 19, .patch = 0 }); |
| 1925 | | |
| 1926 | 1916 | var ring = IoUring.init(1, 0) catch |err| switch (err) { |
| 1927 | 1917 | error.SystemOutdated => return error.SkipZigTest, |
| 1928 | 1918 | error.PermissionDenied => return error.SkipZigTest, |
| ... | ... | @@ -1930,6 +1920,9 @@ test "accept_multishot_direct" { |
| 1930 | 1920 | }; |
| 1931 | 1921 | defer ring.deinit(); |
| 1932 | 1922 | |
| 1923 | const probe = ring.get_probe() catch return error.SkipZigTest; |
| 1924 | if (!probe.is_supported(.ACCEPT)) return error.SkipZigTest; |
| 1925 | |
| 1933 | 1926 | var address: linux.sockaddr.in = .{ |
| 1934 | 1927 | .port = 0, |
| 1935 | 1928 | .addr = @as(*align(1) const u32, @ptrCast( |
| ... | ... | @@ -1984,8 +1977,6 @@ test "accept_multishot_direct" { |
| 1984 | 1977 | } |
| 1985 | 1978 | |
| 1986 | 1979 | test "socket" { |
| 1987 | | try skipKernelLessThan(.{ .major = 5, .minor = 19, .patch = 0 }); |
| 1988 | | |
| 1989 | 1980 | var ring = IoUring.init(1, 0) catch |err| switch (err) { |
| 1990 | 1981 | error.SystemOutdated => return error.SkipZigTest, |
| 1991 | 1982 | error.PermissionDenied => return error.SkipZigTest, |
| ... | ... | @@ -1993,6 +1984,9 @@ test "socket" { |
| 1993 | 1984 | }; |
| 1994 | 1985 | defer ring.deinit(); |
| 1995 | 1986 | |
| 1987 | const probe = ring.get_probe() catch return error.SkipZigTest; |
| 1988 | if (!probe.is_supported(.SOCKET)) return error.SkipZigTest; |
| 1989 | |
| 1996 | 1990 | // prepare, submit socket operation |
| 1997 | 1991 | _ = try ring.socket(0, linux.AF.INET, posix.SOCK.STREAM, 0, 0); |
| 1998 | 1992 | try testing.expectEqual(@as(u32, 1), try ring.submit()); |
| ... | ... | @@ -2007,8 +2001,6 @@ test "socket" { |
| 2007 | 2001 | } |
| 2008 | 2002 | |
| 2009 | 2003 | test "socket_direct/socket_direct_alloc/close_direct" { |
| 2010 | | try skipKernelLessThan(.{ .major = 5, .minor = 19, .patch = 0 }); |
| 2011 | | |
| 2012 | 2004 | var ring = IoUring.init(2, 0) catch |err| switch (err) { |
| 2013 | 2005 | error.SystemOutdated => return error.SkipZigTest, |
| 2014 | 2006 | error.PermissionDenied => return error.SkipZigTest, |
| ... | ... | @@ -2016,6 +2008,9 @@ test "socket_direct/socket_direct_alloc/close_direct" { |
| 2016 | 2008 | }; |
| 2017 | 2009 | defer ring.deinit(); |
| 2018 | 2010 | |
| 2011 | const probe = ring.get_probe() catch return error.SkipZigTest; |
| 2012 | if (!probe.is_supported(.SOCKET) or !probe.is_supported(.CLOSE)) return error.SkipZigTest; |
| 2013 | |
| 2019 | 2014 | var registered_fds: [3]linux.fd_t = @splat(-1); |
| 2020 | 2015 | try ring.register_files(registered_fds[0..]); |
| 2021 | 2016 | |
| ... | ... | @@ -2090,8 +2085,6 @@ test "socket_direct/socket_direct_alloc/close_direct" { |
| 2090 | 2085 | } |
| 2091 | 2086 | |
| 2092 | 2087 | test "openat_direct/close_direct" { |
| 2093 | | try skipKernelLessThan(.{ .major = 5, .minor = 19, .patch = 0 }); |
| 2094 | | |
| 2095 | 2088 | var ring = IoUring.init(2, 0) catch |err| switch (err) { |
| 2096 | 2089 | error.SystemOutdated => return error.SkipZigTest, |
| 2097 | 2090 | error.PermissionDenied => return error.SkipZigTest, |
| ... | ... | @@ -2099,6 +2092,9 @@ test "openat_direct/close_direct" { |
| 2099 | 2092 | }; |
| 2100 | 2093 | defer ring.deinit(); |
| 2101 | 2094 | |
| 2095 | const probe = ring.get_probe() catch return error.SkipZigTest; |
| 2096 | if (!probe.is_supported(.OPENAT) or !probe.is_supported(.CLOSE)) return error.SkipZigTest; |
| 2097 | |
| 2102 | 2098 | var registered_fds: [3]linux.fd_t = @splat(-1); |
| 2103 | 2099 | try ring.register_files(registered_fds[0..]); |
| 2104 | 2100 | |
| ... | ... | @@ -2141,9 +2137,6 @@ test "openat_direct/close_direct" { |
| 2141 | 2137 | } |
| 2142 | 2138 | |
| 2143 | 2139 | test "ring mapped buffers recv" { |
| 2144 | | const io = testing.io; |
| 2145 | | _ = io; |
| 2146 | | |
| 2147 | 2140 | var ring = IoUring.init(16, 0) catch |err| switch (err) { |
| 2148 | 2141 | error.SystemOutdated => return error.SkipZigTest, |
| 2149 | 2142 | error.PermissionDenied => return error.SkipZigTest, |
| ... | ... | @@ -2231,9 +2224,6 @@ test "ring mapped buffers recv" { |
| 2231 | 2224 | } |
| 2232 | 2225 | |
| 2233 | 2226 | test "ring mapped buffers multishot recv" { |
| 2234 | | const io = testing.io; |
| 2235 | | _ = io; |
| 2236 | | |
| 2237 | 2227 | var ring = IoUring.init(16, 0) catch |err| switch (err) { |
| 2238 | 2228 | error.SystemOutdated => return error.SkipZigTest, |
| 2239 | 2229 | error.PermissionDenied => return error.SkipZigTest, |
| ... | ... | @@ -2665,7 +2655,7 @@ pub fn createSocketTestHarness(ring: *IoUring) !SocketTestHarness { |
| 2665 | 2655 | |
| 2666 | 2656 | // All good |
| 2667 | 2657 | |
| 2668 | | return SocketTestHarness{ |
| 2658 | return .{ |
| 2669 | 2659 | .listener = listener_socket, |
| 2670 | 2660 | .server = cqe_accept.res, |
| 2671 | 2661 | .client = client, |
| ... | ... | @@ -2688,27 +2678,6 @@ fn createListenerSocket(address: *linux.sockaddr.in) !posix.socket_t { |
| 2688 | 2678 | return listener_socket; |
| 2689 | 2679 | } |
| 2690 | 2680 | |
| 2691 | | /// For use in tests. Returns SkipZigTest if kernel version is less than required. |
| 2692 | | inline fn skipKernelLessThan(required: std.SemanticVersion) !void { |
| 2693 | | var uts: linux.utsname = undefined; |
| 2694 | | const res = linux.uname(&uts); |
| 2695 | | switch (linux.errno(res)) { |
| 2696 | | .SUCCESS => {}, |
| 2697 | | else => |errno| return posix.unexpectedErrno(errno), |
| 2698 | | } |
| 2699 | | |
| 2700 | | const release = mem.sliceTo(&uts.release, 0); |
| 2701 | | // Strips potential extra, as kernel version might not be semver compliant, example "6.8.9-300.fc40.x86_64" |
| 2702 | | const extra_index = std.mem.findAny(u8, release, "-+"); |
| 2703 | | const stripped = release[0..(extra_index orelse release.len)]; |
| 2704 | | // Make sure the input don't rely on the extra we just stripped |
| 2705 | | try testing.expect(required.pre == null and required.build == null); |
| 2706 | | |
| 2707 | | var current = try std.SemanticVersion.parse(stripped); |
| 2708 | | current.pre = null; // don't check pre field |
| 2709 | | if (required.order(current) == .gt) return error.SkipZigTest; |
| 2710 | | } |
| 2711 | | |
| 2712 | 2681 | fn addrAny(addr: *linux.sockaddr.in) *linux.sockaddr { |
| 2713 | 2682 | return @ptrCast(addr); |
| 2714 | 2683 | } |