gtestutils: Ensure test subprocesses don't dump core

Since we expect them to crash, let's not spam the system
core dump collection (systemd, abrt).  At the moment
systemd is not very robust against programs crashing
in loops.

Instead of aborting, we exit(1).

https://bugzilla.gnome.org/show_bug.cgi?id=700714
This commit is contained in:
Colin Walters 2013-05-20 14:31:48 +01:00
parent 9038e22638
commit 714cbbea52
4 changed files with 77 additions and 4 deletions

View File

@ -152,6 +152,7 @@ libglib_2_0_la_SOURCES = \
gmarkup.c \
gmem.c \
gmessages.c \
gmessages-private.h \
gmirroringtable.h \
gnode.c \
goption.c \

35
glib/gmessages-private.h Normal file
View File

@ -0,0 +1,35 @@
/* gmain.h - the GLib Main loop
* Copyright (C) 1998-2000 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __G_MESSAGES_PRIVATE_H__
#define __G_MESSAGES_PRIVATE_H__
#include <glib/gmessages.h>
G_BEGIN_DECLS
G_GNUC_INTERNAL void
_g_log_set_exit_on_fatal (void);
G_GNUC_INTERNAL void
_g_log_abort (void) G_GNUC_NORETURN;
G_END_DECLS
#endif /* __G_MESSAGES_PRIVATE_H__ */

View File

@ -59,7 +59,7 @@
#include <locale.h>
#include <errno.h>
#include "gmessages.h"
#include "gmessages-private.h"
#include "glib-init.h"
#include "gbacktrace.h"
@ -238,12 +238,23 @@ static GLogDomain *g_log_domains = NULL;
static GPrintFunc glib_print_func = NULL;
static GPrintFunc glib_printerr_func = NULL;
static GPrivate g_log_depth;
static gboolean exit_on_fatal;
static GLogFunc default_log_func = g_log_default_handler;
static gpointer default_log_data = NULL;
static GTestLogFatalFunc fatal_log_func = NULL;
static gpointer fatal_log_data;
/* --- functions --- */
void
_g_log_abort (void)
{
if (exit_on_fatal)
_exit (1);
else
abort ();
}
#ifdef G_OS_WIN32
# include <windows.h>
static gboolean win32_keep_fatal_message = FALSE;
@ -955,7 +966,11 @@ g_logv (const gchar *log_domain,
&& !fatal_log_func (log_domain, test_level, msg, fatal_log_data);
}
if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal)
if ((test_level & G_LOG_FLAG_FATAL) && exit_on_fatal)
{
_g_log_abort ();
}
else if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal)
{
#ifdef G_OS_WIN32
if (win32_keep_fatal_message)
@ -1060,7 +1075,7 @@ g_assert_warning (const char *log_domain,
line,
pretty_function,
expression);
abort ();
_g_log_abort ();
}
/**
@ -1552,3 +1567,9 @@ g_printf_string_upper_bound (const gchar *format,
gchar c;
return _g_vsnprintf (&c, 1, format, args) + 1;
}
void
_g_log_set_exit_on_fatal (void)
{
exit_on_fatal = TRUE;
}

View File

@ -21,6 +21,7 @@
#include "config.h"
#include "gtestutils.h"
#include "gmessages-private.h"
#include "gfileutils.h"
#include <sys/types.h>
@ -36,6 +37,9 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#ifdef G_OS_WIN32
#include <io.h>
#include <windows.h>
@ -54,6 +58,7 @@
#include "gslice.h"
#include "gspawn.h"
#include "glib-private.h"
#include "gmessages-private.h"
/**
@ -759,6 +764,17 @@ parse_args (gint *argc_p,
else if (strcmp ("--GTestSubprocess", argv[i]) == 0)
{
test_in_subprocess = TRUE;
/* We typically expect these child processes to crash, and some
* tests spawn a *lot* of them. Avoid spamming system crash
* collection programs such as systemd-coredump and abrt.
*/
#ifdef HAVE_SYS_RESOURCE_H
{
struct rlimit limit = { 0, 0 };
(void) setrlimit (RLIMIT_CORE, &limit);
}
#endif
_g_log_set_exit_on_fatal ();
argv[i] = NULL;
}
else if (strcmp ("-p", argv[i]) == 0 || strncmp ("-p=", argv[i], 3) == 0)
@ -2027,7 +2043,7 @@ g_assertion_message (const char *domain,
g_test_log (G_TEST_LOG_ERROR, s, NULL, 0, NULL);
g_free (s);
abort();
_g_log_abort ();
}
void