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 <fabian.kosmale@qt.io>
This commit is contained in:
Thiago Macieira 2024-12-03 10:19:23 -08:00
parent 3bed6f4e86
commit 898abae6ad

View File

@ -5,6 +5,29 @@
#include <QTest>
#include <private/qtestlog_p.h>
#if defined(Q_OS_WIN) && defined(Q_CC_MSVC)
# include <crtdbg.h>
#endif
#ifdef Q_OS_UNIX
# include <sys/resource.h>
# include <unistd.h>
#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