tests: Run GModule tests in subprocesses

While we try to unload the test modules that we load, at the end of each
test, it’s not always possible: musl, for example, explicitly doesn’t
support unloading modules (see
https://wiki.musl-libc.org/functional-differences-from-glibc.html#Unloading_libraries).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Fixes: #3415
This commit is contained in:
Philip Withnall 2024-07-24 17:07:23 +02:00
parent 435aeddbc7
commit 84fe784b51
No known key found for this signature in database
GPG Key ID: DCDF5885B1F3ED73

View File

@ -77,15 +77,22 @@ static SimpleFunc plugin_clash_func = NULL;
static void
test_module_basics (void)
{
if (!g_module_supported ())
{
g_test_skip ("dynamic modules not supported");
return;
}
/* Run the actual test in a subprocess to avoid symbol table changes from
* previous tests potentially affecting it. */
if (g_test_subprocess ())
{
GModule *module_self, *module_a, *module_b;
gchar *plugin_a, *plugin_b;
SimpleFunc f_a, f_b, f_self;
GModuleFunc gmod_f;
GError *error = NULL;
if (!g_module_supported ())
g_error ("dynamic modules not supported");
plugin_a = g_test_build_filename (G_TEST_BUILT, MODULE_FILENAME_PREFIX "moduletestplugin_a_" MODULE_TYPE, NULL);
plugin_b = g_test_build_filename (G_TEST_BUILT, MODULE_FILENAME_PREFIX "moduletestplugin_b_" MODULE_TYPE, NULL);
@ -204,6 +211,12 @@ test_module_basics (void)
g_free (plugin_a);
g_free (plugin_b);
g_module_close (module_self);
}
else
{
g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
g_test_trap_assert_passed ();
}
}
static void
@ -236,13 +249,6 @@ test_module_invalid_libtool_archive (void)
static void
test_local_binding (void)
{
gchar *plugin = NULL;
GModule *module_plugin = NULL, *module_self = NULL;
GError *error = NULL;
gboolean found_symbol = FALSE;
gpointer symbol = NULL;
g_test_summary ("Test that binding a library's symbols locally does not add them globally");
#if defined(G_PLATFORM_WIN32)
@ -250,6 +256,17 @@ test_local_binding (void)
return;
#endif
/* Run the actual test in a subprocess to avoid symbol table changes from
* previous tests potentially affecting it. */
if (g_test_subprocess ())
{
gchar *plugin = NULL;
GModule *module_plugin = NULL, *module_self = NULL;
GError *error = NULL;
gboolean found_symbol = FALSE;
gpointer symbol = NULL;
plugin = g_test_build_filename (G_TEST_BUILT, MODULE_FILENAME_PREFIX "moduletestplugin_a_" MODULE_TYPE, NULL);
module_plugin = g_module_open_full (plugin, G_MODULE_BIND_LOCAL, &error);
@ -267,6 +284,12 @@ test_local_binding (void)
g_module_close (module_self);
g_module_close (module_plugin);
g_free (plugin);
}
else
{
g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
g_test_trap_assert_passed ();
}
}
int