From 262a4362647e028cd83f4d898374ff1f3af1e99c Mon Sep 17 00:00:00 2001 From: TapTap Date: Mon, 20 Jul 2026 20:48:22 +0200 Subject: [PATCH] fix: auto-detect valgrind to skip fork tests --- tests/test_file.c | 2 +- tests/test_utils.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_file.c b/tests/test_file.c index 1a65a05..ae50a30 100644 --- a/tests/test_file.c +++ b/tests/test_file.c @@ -271,7 +271,7 @@ void test_file() { test_to_disk_basic(); test_to_disk_creates_dirs(); test_file_content_to_buffer(); - if (!getenv("FASTSYNC_UNDER_VALGRIND")) { + if (!is_running_under_valgrind()) { // Fork tests are skipped under valgrind because the parent process runs // orders of magnitude slower than the child (parent is instrumented, child // is not), which causes pipe-based protocol handshake timeouts. The parent diff --git a/tests/test_utils.h b/tests/test_utils.h index c9e9f02..67b6bca 100644 --- a/tests/test_utils.h +++ b/tests/test_utils.h @@ -2,9 +2,24 @@ #define TEST_UTILS_H #include +#include #include #include +// Detect if running under valgrind by checking /proc/self/maps for vgpreload. +// This is used to skip fork-based tests that are incompatible with valgrind +// (the instrumented parent runs too slowly, causing pipe timeouts). +static inline bool is_running_under_valgrind(void) { + FILE* f = fopen("/proc/self/maps", "r"); + if (!f) + return false; + char buf[4096]; + size_t n = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[n] = '\0'; + return strstr(buf, "vgpreload") != NULL; +} + // Global test suite status extern int tests_run; extern int tests_failed;