[glib] Reorganize the "don't dump core from test subprocesses" code.
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Reorganize the "don't dump core from test subprocesses" code.
- Date: Sun, 24 Nov 2013 20:14:47 +0000 (UTC)
commit 3d70db075005a94d7fd18ac8a8dbd0abb82bff9e
Author: Dan Winship <danw gnome org>
Date: Sat Nov 23 12:06:05 2013 -0500
Reorganize the "don't dump core from test subprocesses" code.
g_test_init() was calling _g_messages_set_exit_on_fatal() from
subprocesses, to make fatal log messages call _exit() rather than
abort(), but the function name is sort of confusing, and we don't
really need it anyway, since g_log() can just call g_test_subprocess()
instead and decide for itself.
Likewise, update g_assertion_message() to do the check itself, rather
than calling into gmessages to do it, and fix
g_assertion_message_expr() to also check whether it should exit or
abort. (Previously it always called abort(), although this didn't
actually matter since that was dead code until
test_nonfatal_assertions was added.)
https://bugzilla.gnome.org/show_bug.cgi?id=711800
glib/Makefile.am | 1 -
glib/gmessages-private.h | 35 -----------------------------------
glib/gmessages.c | 34 +++++++++++++++-------------------
glib/gtestutils.c | 25 ++++++++++++++++++++-----
4 files changed, 35 insertions(+), 60 deletions(-)
---
diff --git a/glib/Makefile.am b/glib/Makefile.am
index 1330755..a03d719 100644
--- a/glib/Makefile.am
+++ b/glib/Makefile.am
@@ -145,7 +145,6 @@ libglib_2_0_la_SOURCES = \
gmarkup.c \
gmem.c \
gmessages.c \
- gmessages-private.h \
gmirroringtable.h \
gnode.c \
goption.c \
diff --git a/glib/gmessages.c b/glib/gmessages.c
index f21fc7e..c8f3c42 100644
--- a/glib/gmessages.c
+++ b/glib/gmessages.c
@@ -56,8 +56,6 @@
#include <locale.h>
#include <errno.h>
-#include "gmessages-private.h"
-
#include "glib-init.h"
#include "gbacktrace.h"
#include "gcharset.h"
@@ -285,7 +283,6 @@ 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;
@@ -293,11 +290,20 @@ static gpointer fatal_log_data;
/* --- functions --- */
-void
+static void _g_log_abort (void) G_GNUC_NORETURN;
+
+static void
_g_log_abort (void)
{
- if (exit_on_fatal)
- _exit (1);
+ if (g_test_subprocess ())
+ {
+ /* If this is a test case subprocess then it probably caused
+ * this error message on purpose, so just exit() rather than
+ * abort()ing, to avoid triggering any system crash-reporting
+ * daemon.
+ */
+ _exit (1);
+ }
else
abort ();
}
@@ -1017,11 +1023,7 @@ g_logv (const gchar *log_domain,
&& !fatal_log_func (log_domain, test_level, msg, fatal_log_data);
}
- if ((test_level & G_LOG_FLAG_FATAL) && exit_on_fatal && !masquerade_fatal)
- {
- _g_log_abort ();
- }
- else if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal)
+ if ((test_level & G_LOG_FLAG_FATAL) && !masquerade_fatal)
{
#ifdef G_OS_WIN32
if (win32_keep_fatal_message)
@@ -1034,12 +1036,12 @@ g_logv (const gchar *log_domain,
if (IsDebuggerPresent () && !(test_level & G_LOG_FLAG_RECURSION))
G_BREAKPOINT ();
else
- abort ();
+ _g_log_abort ();
#else
if (!(test_level & G_LOG_FLAG_RECURSION))
G_BREAKPOINT ();
else
- abort ();
+ _g_log_abort ();
#endif /* !G_OS_WIN32 */
}
@@ -1634,9 +1636,3 @@ 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;
-}
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index 0a9ba0a..c2d0c6a 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -21,7 +21,6 @@
#include "config.h"
#include "gtestutils.h"
-#include "gmessages-private.h"
#include "gfileutils.h"
#include <sys/types.h>
@@ -56,7 +55,6 @@
#include "gslice.h"
#include "gspawn.h"
#include "glib-private.h"
-#include "gmessages-private.h"
/**
@@ -892,7 +890,6 @@ parse_args (gint *argc_p,
(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)
@@ -2307,7 +2304,17 @@ g_assertion_message (const char *domain,
strcpy (__glib_assert_msg, s);
g_free (s);
- _g_log_abort ();
+
+ if (test_in_subprocess)
+ {
+ /* If this is a test case subprocess then it probably hit this
+ * assertion on purpose, so just exit() rather than abort()ing,
+ * to avoid triggering any system crash-reporting daemon.
+ */
+ _exit (1);
+ }
+ else
+ abort ();
}
void
@@ -2324,7 +2331,15 @@ g_assertion_message_expr (const char *domain,
s = g_strconcat ("assertion failed: (", expr, ")", NULL);
g_assertion_message (domain, file, line, func, s);
g_free (s);
- abort ();
+
+ /* Normally g_assertion_message() won't return, but we need this for
+ * when test_nonfatal_assertions is set, since
+ * g_assertion_message_expr() is used for always-fatal assertions.
+ */
+ if (test_in_subprocess)
+ _exit (1);
+ else
+ abort ();
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]