Skip to content
Snippets Groups Projects
Commit 30b89b83 authored by Simon McVittie's avatar Simon McVittie
Browse files

testutils: Add a backport of g_test_disable_crash_reporting()


When testing something that is expected to fail or crash, it's useful
to disable core dump reporting.

This is a slightly simplified version of GNOME/glib!3510: because
libglnx isn't portable to non-Linux, we can assume that <sys/prctl.h>,
prctl() and <sys/resource.h> are always available, so we don't need
to check for them in the build system.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 07e3e49d
No related branches found
No related tags found
1 merge request!584Update libglnx
......@@ -33,6 +33,9 @@
#include "glnx-backport-testutils.h"
#include "glnx-backports.h"
#include <sys/prctl.h>
#include <sys/resource.h>
#if !GLIB_CHECK_VERSION (2, 68, 0)
/* Backport of g_assertion_message_cmpstrv() */
void
......@@ -143,3 +146,17 @@ _glnx_test_incomplete_printf (const char *format,
#endif
}
#endif
#if !GLIB_CHECK_VERSION (2, 78, 0)
void
_glnx_test_disable_crash_reporting (void)
{
struct rlimit limit = { 0, 0 };
(void) setrlimit (RLIMIT_CORE, &limit);
/* On Linux, RLIMIT_CORE = 0 is ignored if core dumps are
* configured to be written to a pipe, but PR_SET_DUMPABLE is not. */
(void) prctl (PR_SET_DUMPABLE, 0, 0, 0, 0);
}
#endif
......@@ -201,4 +201,9 @@ void _glnx_test_skip_printf (const char *format, ...) G_GNUC_PRINTF (1, 2);
void _glnx_test_incomplete_printf (const char *format, ...) G_GNUC_PRINTF (1, 2);
#endif
#if !GLIB_CHECK_VERSION (2, 78, 0)
#define g_test_disable_crash_reporting _glnx_test_disable_crash_reporting
void _glnx_test_disable_crash_reporting (void);
#endif
G_END_DECLS
......@@ -243,6 +243,7 @@ main (int argc,
}
g_test_init (&argc, &argv, NULL);
g_test_disable_crash_reporting ();
#if GLIB_CHECK_VERSION(2, 38, 0)
g_test_set_nonfatal_assertions ();
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment