After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 711800 - fix g_test_set_nonfatal_assertions()
fix g_test_set_nonfatal_assertions()
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-11-10 20:59 UTC by Dan Winship
Modified: 2013-12-03 15:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtestutils: fix g_test_set_nonfatal_assertions() (4.12 KB, patch)
2013-11-10 20:59 UTC, Dan Winship
needs-work Details | Review
gtestutils: add g_assert_nonnull() to go with g_assert_null() (2.63 KB, patch)
2013-11-10 20:59 UTC, Dan Winship
accepted-commit_now Details | Review
gtestutils: fix g_test_set_nonfatal_assertions() (4.12 KB, patch)
2013-11-23 22:19 UTC, Dan Winship
accepted-commit_now Details | Review
gtestutils: add g_assert_nonnull() to go with g_assert_null() (2.63 KB, patch)
2013-11-23 22:19 UTC, Dan Winship
accepted-commit_now Details | Review
Reorganize the "don't dump core from test subprocesses" code. (6.06 KB, patch)
2013-11-23 22:19 UTC, Dan Winship
needs-work Details | Review
gmessages: make _g_log_abort() do only breakpoints again (1.33 KB, patch)
2013-12-03 14:40 UTC, Marc-Andre Lureau
committed Details | Review

Description Dan Winship 2013-11-10 20:59:17 UTC
g_test_set_nonfatal_assertions() didn't actually work.

Also, while trying to port some libsoup tests, I kept wanting
g_assert_nonnull() to go with g_assert_null(), so I added that. (Or
should it be "non_null"?)
Comment 1 Dan Winship 2013-11-10 20:59:19 UTC
Created attachment 259465 [details] [review]
gtestutils: fix g_test_set_nonfatal_assertions()

g_test_set_nonfatal_assertions() was a no-op, because
g_assertion_message() wasn't actually checking the
test_nonfatal_assertions flag. Fix that and add a test.

Also, g_test_set_nonfatal_assertions() has to set test_mode_fatal to
FALSE as well, or else a failed assertion will cause the test program
to abort at the end of the failed test.

Also, belatedly add this and the new g_assert_* methods to the docs.
Comment 2 Dan Winship 2013-11-10 20:59:22 UTC
Created attachment 259466 [details] [review]
gtestutils: add g_assert_nonnull() to go with g_assert_null()
Comment 3 Colin Walters 2013-11-18 18:22:30 UTC
Review of attachment 259465 [details] [review]:

::: glib/gtestutils.c
@@ +2292,1 @@
   __glib_assert_msg = (char*) malloc (strlen (s) + 1);

You've created a use-after-free here for the case where we still do have fatal assertions.
Comment 4 Colin Walters 2013-11-18 18:23:03 UTC
Review of attachment 259466 [details] [review]:

Okay.
Comment 5 Matthias Clasen 2013-11-20 01:13:22 UTC
Hmm, there's a bit of a mess now.

It seems Stef has introduced _g_log_set_exit_on_fatal and _g_log_abort in the meantime, which kinda overlaps this. And if you look around, we have

g_assertion_message call _g_log_abort and
g_assertion_message_expr call abort, right next to each other

:-(
Comment 6 Dan Winship 2013-11-23 22:19:01 UTC
Created attachment 261317 [details] [review]
gtestutils: fix g_test_set_nonfatal_assertions()

g_test_set_nonfatal_assertions() was a no-op, because
g_assertion_message() wasn't actually checking the
test_nonfatal_assertions flag. Fix that and add a test.

Also, g_test_set_nonfatal_assertions() has to set test_mode_fatal to
FALSE as well, or else a failed assertion will cause the test program
to abort at the end of the failed test.

Also, belatedly add this and the new g_assert_* methods to the docs.
Comment 7 Dan Winship 2013-11-23 22:19:04 UTC
Created attachment 261318 [details] [review]
gtestutils: add g_assert_nonnull() to go with g_assert_null()
Comment 8 Dan Winship 2013-11-23 22:19:07 UTC
Created attachment 261319 [details] [review]
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.)
Comment 9 Dan Winship 2013-11-23 22:20:46 UTC
(In reply to comment #0)
> Also, while trying to port some libsoup tests, I kept wanting
> g_assert_nonnull() to go with g_assert_null(), so I added that. (Or
> should it be "non_null"?)

Since we're talking about "nonfatal" assertions, it should be "nonnull" I guess.

(In reply to comment #3)
> You've created a use-after-free here for the case where we still do have fatal
> assertions.

fixed

(In reply to comment #5)
> Hmm, there's a bit of a mess now.

It's not as bad as it looked at first glance, and the third commit should clean up what mess there is.
Comment 10 Matthias Clasen 2013-11-24 14:46:10 UTC
Review of attachment 261318 [details] [review]:

sure, ok
Comment 11 Matthias Clasen 2013-11-24 14:49:08 UTC
Review of attachment 261317 [details] [review]:

::: docs/reference/glib/glib-sections.txt
@@ +2981,1 @@
 

oops, thanks for catching this oversight

::: glib/gtestutils.c
@@ +2291,2 @@
   __glib_assert_msg = (char*) malloc (strlen (s) + 1);
   strcpy (__glib_assert_msg, s);

I wonder if it wouldn't be better to use a small amount of static memory for this
Comment 12 Matthias Clasen 2013-11-24 14:49:29 UTC
Review of attachment 261317 [details] [review]:

.
Comment 13 Matthias Clasen 2013-11-24 14:53:37 UTC
Review of attachment 261319 [details] [review]:

::: glib/gmessages-private.h
@@ -26,3 @@
-
-G_GNUC_INTERNAL void
-_g_log_set_exit_on_fatal (void);

G_GNUC_INTERNAL is no longer needed - we switched to a model where exporting is explicit.

::: glib/gtestutils.c
@@ +2306,3 @@
   g_free (s);
+
+  if (test_in_subprocess)

Would be good to have a comment here explaining that this is about avoiding coredumps
Comment 14 Dan Winship 2013-11-24 20:15:08 UTC
(In reply to comment #13)
> -G_GNUC_INTERNAL void
> -_g_log_set_exit_on_fatal (void);
> 
> G_GNUC_INTERNAL is no longer needed

That code is being removed, not added.

> Would be good to have a comment here explaining that this is about avoiding
> coredumps

Added a comment there and in gmessages and pushed.
Comment 15 Marc-Andre Lureau 2013-12-03 14:31:44 UTC
commit e53caad4f139e2df0b34dae5864576796dda514e
Author: Dan Winship <danw@gnome.org>
Date:   Wed Nov 27 10:57:43 2013 -0500

    Fix a warning about _g_log_abort()
    
    G_BREAKPOINT is not noreturn, so make it so that we abort() if it
    returns, to make _g_log_abort() be properly noreturn again.


This completely breaks the breakpoint log_abort() usage (which I am using extensively, to skip some warnings/criticals (especially those deprecated created by third party libraries, such as gtk/gio ;).

reopening
Comment 16 Dan Winship 2013-12-03 14:33:57 UTC
um? can you clarify exactly what you're doing? It sounds vastly unsupported.
Comment 17 Marc-Andre Lureau 2013-12-03 14:40:45 UTC
Created attachment 263394 [details] [review]
gmessages: make _g_log_abort() do only breakpoints again

Commit e53caad4 makes _g_log_abort() noreturn by calling abort()
unconditionally.

However, it is useful to be able to skip some log_abort() with a
debugger, to reach a point of interest. Revert back to previous
behaviour. Make g_assert_warning() noreturn by calling abort().
Comment 18 Marc-Andre Lureau 2013-12-03 14:59:10 UTC
(In reply to comment #16)
> um? can you clarify exactly what you're doing? It sounds vastly unsupported.

run a glib program under gdb with SPICE_ABORT_LEVEL=2 for ex, and skip a few warnings until I reach the one I want to fix.

If _g_log_abort() always abort() I don't see the point of using breakpoint in the first place.
Comment 19 Marc-Andre Lureau 2013-12-03 15:01:09 UTC
Sorry, I meant G_DEBUG=fatal_warnings (I have the 2 in the same alias)
Comment 20 Dan Winship 2013-12-03 15:05:01 UTC
oh, I thought you meant you were *programmatically* skipping fatal warnings or something. Yes, assuming that glib compiles without warnings after your patch, it looks good.
Comment 21 Marc-Andre Lureau 2013-12-03 15:10:45 UTC
Attachment 263394 [details] pushed as bff76bc - gmessages: make _g_log_abort() do only breakpoints again