Merge branch 'wip/pwithnall/3415-module-tests' into 'main'

tests: Run GModule tests in subprocesses

Closes #3415

See merge request GNOME/glib!4169
This commit is contained in:
Emmanuele Bassi
2024-07-24 19:52:57 +00:00

View File

@@ -76,6 +76,16 @@ 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;
@@ -83,9 +93,6 @@ test_module_basics (void)
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);
@@ -205,6 +212,12 @@ test_module_basics (void)
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
test_module_invalid_libtool_archive (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);
@@ -268,6 +285,12 @@ test_local_binding (void)
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
main (int argc, char *argv[])