Merge branch 'wip/pwithnall/cancellable-test-fixes' into 'main'

tests: Run expected-to-hang cancellable tests in subprocesses

See merge request GNOME/glib!4198
This commit is contained in:
Philip Withnall 2024-08-20 13:40:34 +00:00
commit 23a7b4bf17

View File

@ -25,7 +25,6 @@
#include <gio/gio.h>
#include "glib/glib-private.h"
#include "glib/gvalgrind.h"
/* How long to wait in ms for each iteration */
#define WAIT_ITERATION (10)
@ -276,11 +275,6 @@ test_cancellable_source_threaded_dispose (void)
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/issues/2309");
#endif
#ifdef ENABLE_VALGRIND
if (RUNNING_ON_VALGRIND)
g_test_incomplete ("FIXME: Leaks lots of GCancellableSource objects, see glib#2309");
#endif
/* Create a new thread and wait until its ready to execute. Each iteration of
* the test will pass it a new #GCancellableSource. */
g_cond_init (&data.cond);
@ -536,6 +530,17 @@ test_cancellable_disconnect_on_cancelled_callback_hangs (void)
return;
}
/* Run the test in a subprocess. While we can get away with deadlocking a
* specific thread on Linux, the glibc on FreeBSD manages to detect the
* deadlock and aborts the whole test process. */
if (!g_test_subprocess ())
{
g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
if (!g_test_trap_has_passed ())
g_test_trap_assert_stderr ("*Unexpected error from C library during 'pthread_mutex_lock': Resource deadlock avoided. Aborting.*");
return;
}
cancellable = g_cancellable_new ();
thread_data.cancellable = cancellable;
thread_data.callback = G_CALLBACK (on_cancellable_connect_disconnect);
@ -552,10 +557,9 @@ test_cancellable_disconnect_on_cancelled_callback_hangs (void)
thread_loop = thread_data.loop;
g_assert_cmpuint ((gulong) (guintptr) g_atomic_pointer_get (&thread_data.handler_id), !=, 0);
/* FIXME: This thread will hang (at least that's what this test wants to
* ensure), but we can't stop it from the caller, unless we'll expose
* pthread_cancel (and similar) to GLib.
* So it will keep hanging till the test process is alive.
/* This thread will hang (at least that's what this test wants to ensure), but
* we can't stop it from the caller, unless we'll expose pthread_cancel() (and
* similar) to GLib. So it will keep hanging until the test subprocess exits.
*/
cancelling_thread = g_thread_new ("/cancellable/disconnect-on-cancelled-callback-hangs",
(GThreadFunc) g_cancellable_cancel,
@ -621,6 +625,17 @@ test_cancellable_reset_on_cancelled_callback_hangs (void)
return;
}
/* Run the test in a subprocess. While we can get away with deadlocking a
* specific thread on Linux, the glibc on FreeBSD manages to detect the
* deadlock and aborts the whole test process. */
if (!g_test_subprocess ())
{
g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
if (!g_test_trap_has_passed ())
g_test_trap_assert_stderr ("*Unexpected error from C library during 'pthread_mutex_lock': Resource deadlock avoided. Aborting.*");
return;
}
cancellable = g_cancellable_new ();
thread_data.cancellable = cancellable;
thread_data.callback = G_CALLBACK (on_cancelled_reset);
@ -637,10 +652,9 @@ test_cancellable_reset_on_cancelled_callback_hangs (void)
thread_loop = thread_data.loop;
g_assert_cmpuint ((gulong) (guintptr) g_atomic_pointer_get (&thread_data.handler_id), !=, 0);
/* FIXME: This thread will hang (at least that's what this test wants to
* ensure), but we can't stop it from the caller, unless we'll expose
* pthread_cancel (and similar) to GLib.
* So it will keep hanging till the test process is alive.
/* This thread will hang (at least that's what this test wants to ensure), but
* we can't stop it from the caller, unless we'll expose pthread_cancel() (and
* similar) to GLib. So it will keep hanging until the test subprocess exits.
*/
cancelling_thread = g_thread_new ("/cancellable/reset-on-cancelled-callback-hangs",
(GThreadFunc) g_cancellable_cancel,