From 898abae6adf0ab9ff75752df456aaedef71ae096 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 3 Dec 2024 10:19:23 -0800 Subject: [PATCH] selftests/silent_fatal: disable core dumps and MSVC debug dialogs Otherwise the test may hang forever waiting for the user to click a button or just too long waiting for the core dumper. Pick-to: 6.8 Change-Id: Id570aab34608aed86b86fffd8d196c84296e0389 Reviewed-by: Fabian Kosmale --- .../silent_fatal/tst_silent_fatal.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/auto/testlib/selftests/silent_fatal/tst_silent_fatal.cpp b/tests/auto/testlib/selftests/silent_fatal/tst_silent_fatal.cpp index 57aa1f702cc..a7b4324992d 100644 --- a/tests/auto/testlib/selftests/silent_fatal/tst_silent_fatal.cpp +++ b/tests/auto/testlib/selftests/silent_fatal/tst_silent_fatal.cpp @@ -5,6 +5,29 @@ #include #include +#if defined(Q_OS_WIN) && defined(Q_CC_MSVC) +# include +#endif +#ifdef Q_OS_UNIX +# include +# include +#endif + +void disableCoreDumps() +{ +#if defined(Q_OS_WIN) && defined(Q_CC_MSVC) + // Windows: Suppress crash notification dialog. + _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); +#elif defined(RLIMIT_CORE) + // Unix: set our core dump limit to zero to request no dialogs. + if (struct rlimit rlim; getrlimit(RLIMIT_CORE, &rlim) == 0) { + rlim.rlim_cur = 0; + setrlimit(RLIMIT_CORE, &rlim); + } +#endif +} +Q_CONSTRUCTOR_FUNCTION(disableCoreDumps) + class tst_SilentFatal : public QObject { Q_OBJECT