From de10ce58e295c7f4419976384be92d2b7407056f Mon Sep 17 00:00:00 2001 From: Pascal Zittlau Date: Wed, 17 Dec 2025 10:14:05 +0100 Subject: [PATCH] fix flaky tests --- docs/TODO.md | 2 +- src/Patcher.zig | 2 +- src/main.zig | 57 ++++++++++++++++++++++--------------------------- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/docs/TODO.md b/docs/TODO.md index e2888d9..0468f93 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -22,7 +22,7 @@ IvyBridge(2012) and AMD Zen 2 Family 17H(2019) and Linux 5.9(2020). - [ ] JIT support: intercept `mmap`, `mprotect` and `mremap` that change pages to be executable - [ ] `SIGILL` patching fallback - [x] `vdso` handling -- [ ] check why the libc tests are flaky +- [x] check why the libc tests are flaky ## Minor things diff --git a/src/Patcher.zig b/src/Patcher.zig index 344f46f..f40f6e7 100644 --- a/src/Patcher.zig +++ b/src/Patcher.zig @@ -854,7 +854,7 @@ fn ensureRangeWritable( const gop = try allocated_pages.getOrPut(gpa, page_addr); if (gop.found_existing) { const ptr: [*]align(page_size) u8 = @ptrFromInt(page_addr); - try posix.mprotect(ptr[0..page_addr], protection); + try posix.mprotect(ptr[0..page_size], protection); } else { const addr = posix.mmap( @ptrFromInt(page_addr), diff --git a/src/main.zig b/src/main.zig index a0e8bd8..573e9e5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -332,10 +332,9 @@ test "nolibc_nopie_exit" { test "nolibc_pie_exit" { try testHelper(&.{ flicker_path, getTestExePath("nolibc_pie_exit") }, ""); } -// BUG: This one is flaky -// test "libc_pie_exit" { -// try testHelper(&.{ flicker_path, getTestExePath("libc_pie_exit") }, ""); -// } +test "libc_pie_exit" { + try testHelper(&.{ flicker_path, getTestExePath("libc_pie_exit") }, ""); +} test "nolibc_nopie_helloWorld" { try testHelper(&.{ flicker_path, getTestExePath("nolibc_nopie_helloWorld") }, "Hello World!\n"); @@ -343,10 +342,9 @@ test "nolibc_nopie_helloWorld" { test "nolibc_pie_helloWorld" { try testHelper(&.{ flicker_path, getTestExePath("nolibc_pie_helloWorld") }, "Hello World!\n"); } -// BUG: This one is flaky -// test "libc_pie_helloWorld" { -// try testHelper(&.{ flicker_path, getTestExePath("libc_pie_helloWorld") }, "Hello World!\n"); -// } +test "libc_pie_helloWorld" { + try testHelper(&.{ flicker_path, getTestExePath("libc_pie_helloWorld") }, "Hello World!\n"); +} test "nolibc_nopie_printArgs" { try testPrintArgs("nolibc_nopie_printArgs"); @@ -354,10 +352,9 @@ test "nolibc_nopie_printArgs" { test "nolibc_pie_printArgs" { try testPrintArgs("nolibc_pie_printArgs"); } -// BUG: This one is flaky -// test "libc_pie_printArgs" { -// try testPrintArgs("libc_pie_printArgs"); -// } +test "libc_pie_printArgs" { + try testPrintArgs("libc_pie_printArgs"); +} test "nolibc_nopie_readlink" { try testReadlink("nolibc_nopie_readlink"); @@ -365,7 +362,7 @@ test "nolibc_nopie_readlink" { test "nolibc_pie_readlink" { try testReadlink("nolibc_pie_readlink"); } -// BUG: This one just outputs the path to the flicker executable and is likely also flaky +// BUG: This one just outputs the path to the flicker executable // test "libc_pie_readlink" { // try testReadlink("libc_pie_readlink"); // } @@ -396,10 +393,6 @@ test "nolibc_pie_clone_no_new_stack" { ); } -test "echo" { - try testHelper(&.{ "echo", "Hello", "There" }, "Hello There\n"); -} - test "nolibc_nopie_fork" { try testHelper( &.{ flicker_path, getTestExePath("nolibc_nopie_fork") }, @@ -412,13 +405,12 @@ test "nolibc_pie_fork" { "Child: I'm alive!\nParent: Child died.\n", ); } -// BUG: This one is flaky -// test "libc_pie_fork" { -// try testHelper( -// &.{ flicker_path, getTestExePath("libc_pie_fork") }, -// "Child: I'm alive!\nParent: Child died.\n", -// ); -// } +test "libc_pie_fork" { + try testHelper( + &.{ flicker_path, getTestExePath("libc_pie_fork") }, + "Child: I'm alive!\nParent: Child died.\n", + ); +} test "nolibc_nopie_signal_handler" { try testHelper( @@ -445,13 +437,16 @@ test "nolibc_pie_vdso_clock" { "Time gotten\n", ); } -// BUG: This one is flaky -// test "libc_pie_vdso_clock" { -// try testHelper( -// &.{ flicker_path, getTestExePath("libc_pie_vdso_clock") }, -// "Time gotten\n", -// ); -// } +test "libc_pie_vdso_clock" { + try testHelper( + &.{ flicker_path, getTestExePath("libc_pie_vdso_clock") }, + "Time gotten\n", + ); +} + +test "echo" { + try testHelper(&.{ "echo", "Hello", "There" }, "Hello There\n"); +} fn testPrintArgs(comptime name: []const u8) !void { const exe_path = getTestExePath(name);