From 7a5d2a196f2d78eb55f8ef294b4c899e0378f71e Mon Sep 17 00:00:00 2001 From: mlugg Date: Sat, 13 Sep 2025 17:26:19 +0100 Subject: [PATCH] tweak tests to avoid timeouts --- lib/compiler_rt/memcpy.zig | 59 ++++++++++++++++---------------- lib/std/Thread/RwLock.zig | 4 +-- lib/std/crypto/25519/ed25519.zig | 3 +- lib/std/posix/test.zig | 12 +++---- test/behavior/call.zig | 8 ++--- 5 files changed, 40 insertions(+), 46 deletions(-) diff --git a/lib/compiler_rt/memcpy.zig b/lib/compiler_rt/memcpy.zig index a31bbe62a0..82a032d3e9 100644 --- a/lib/compiler_rt/memcpy.zig +++ b/lib/compiler_rt/memcpy.zig @@ -194,37 +194,36 @@ inline fn copyRange4( copyFixedLength(dest + last, src + last, copy_len); } -test "memcpy" { - if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; +fn testMemcpyImpl(comptime memcpyImpl: anytype) !void { + const max_len = 1024; + var buffer: [max_len + @alignOf(Element) - 1]u8 align(@alignOf(Element)) = undefined; + for (&buffer, 0..) |*b, i| { + b.* = @intCast(i % 97); + } + var dest: [max_len + @alignOf(Element) - 1]u8 align(@alignOf(Element)) = undefined; - const S = struct { - fn testFunc(comptime copy_func: anytype) !void { - const max_len = 1024; - var buffer: [max_len + @alignOf(Element) - 1]u8 align(@alignOf(Element)) = undefined; - for (&buffer, 0..) |*b, i| { - b.* = @intCast(i % 97); - } - var dest: [max_len + @alignOf(Element) - 1]u8 align(@alignOf(Element)) = undefined; - - for (0..max_len) |copy_len| { - for (0..@alignOf(Element)) |s_offset| { - for (0..@alignOf(Element)) |d_offset| { - @memset(&dest, 0xff); - const s = buffer[s_offset..][0..copy_len]; - const d = dest[d_offset..][0..copy_len]; - _ = copy_func(@ptrCast(d.ptr), @ptrCast(s.ptr), s.len); - std.testing.expectEqualSlices(u8, s, d) catch |e| { - std.debug.print("error encountered for length={d}, s_offset={d}, d_offset={d}\n", .{ - copy_len, s_offset, d_offset, - }); - return e; - }; - } - } + for (0..max_len) |copy_len| { + for (0..@alignOf(Element)) |s_offset| { + for (0..@alignOf(Element)) |d_offset| { + @memset(&dest, 0xff); + const s = buffer[s_offset..][0..copy_len]; + const d = dest[d_offset..][0..copy_len]; + _ = memcpyImpl(@ptrCast(d.ptr), @ptrCast(s.ptr), s.len); + std.testing.expectEqualSlices(u8, s, d) catch |e| { + std.debug.print("error encountered for length={d}, s_offset={d}, d_offset={d}\n", .{ + copy_len, s_offset, d_offset, + }); + return e; + }; } } - }; - - try S.testFunc(memcpySmall); - try S.testFunc(memcpyFast); + } +} +test memcpySmall { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + try testMemcpyImpl(memcpySmall); +} +test memcpyFast { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; + try testMemcpyImpl(memcpyFast); } diff --git a/lib/std/Thread/RwLock.zig b/lib/std/Thread/RwLock.zig index 0e8da6239f..6f39221e36 100644 --- a/lib/std/Thread/RwLock.zig +++ b/lib/std/Thread/RwLock.zig @@ -301,8 +301,8 @@ test "concurrent access" { const num_writers: usize = 2; const num_readers: usize = 4; - const num_writes: usize = 10000; - const num_reads: usize = num_writes * 2; + const num_writes: usize = 4096; + const num_reads: usize = 8192; const Runner = struct { const Self = @This(); diff --git a/lib/std/crypto/25519/ed25519.zig b/lib/std/crypto/25519/ed25519.zig index 0a8e0ee07d..a78e1aa3ab 100644 --- a/lib/std/crypto/25519/ed25519.zig +++ b/lib/std/crypto/25519/ed25519.zig @@ -587,8 +587,7 @@ test "signature" { } test "batch verification" { - var i: usize = 0; - while (i < 100) : (i += 1) { + for (0..16) |_| { const key_pair = Ed25519.KeyPair.generate(); var msg1: [32]u8 = undefined; var msg2: [32]u8 = undefined; diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig index 5f22d18f01..7294334ec1 100644 --- a/lib/std/posix/test.zig +++ b/lib/std/posix/test.zig @@ -562,15 +562,11 @@ test "sync" { if (native_os != .linux) return error.SkipZigTest; - var tmp = tmpDir(.{}); - defer tmp.cleanup(); + // Unfortunately, we cannot safely call `sync` or `syncfs`, because if file IO is happening + // than the system can commit the results to disk, such calls could block indefinitely. - const test_out_file = "os_tmp_test"; - const file = try tmp.dir.createFile(test_out_file, .{}); - defer file.close(); - - posix.sync(); - try posix.syncfs(file.handle); + _ = &posix.sync; + _ = &posix.syncfs; } test "fsync" { diff --git a/test/behavior/call.zig b/test/behavior/call.zig index e05db0827f..e4d09c7fa1 100644 --- a/test/behavior/call.zig +++ b/test/behavior/call.zig @@ -320,7 +320,7 @@ test "inline call preserves tail call" { if (builtin.zig_backend == .stage2_c and builtin.os.tag == .windows) return error.SkipZigTest; // MSVC doesn't support always tail calls - const max = std.math.maxInt(u16); + const max_depth = 1000; const S = struct { var a: u16 = 0; fn foo() void { @@ -328,16 +328,16 @@ test "inline call preserves tail call" { } inline fn bar() void { - if (a == max) return; + if (a == max_depth) return; // Stack overflow if not tail called - var buf: [max]u16 = undefined; + var buf: [100_000]u16 = undefined; buf[a] = a; a += 1; return @call(.always_tail, foo, .{}); } }; S.foo(); - try expect(S.a == std.math.maxInt(u16)); + try expect(S.a == max_depth); } test "inline call doesn't re-evaluate non generic struct" {