From 5c05dfad9773c6e56540832a3599639647c82823 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 18 Jan 2024 15:22:30 +0000 Subject: [PATCH 1/2] tests: Run more appinfo tests under a GTestDBus environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I ran Bustle/dbus-monitor on the session bus while running the full GLib test suite, and noticed that these tests were causing `Launched` signal emissions on the main session bus. That suggested they weren’t isolated properly, which at best causes noise on the bus and at worst could cause spurious test failures. Fix that by running those tests in a `GTestDBus` environment, as some of the other appinfo tests already are. Signed-off-by: Philip Withnall --- gio/tests/appinfo.c | 25 +++++++++++++++++++++++++ gio/tests/desktop-app-info.c | 8 ++++++++ 2 files changed, 33 insertions(+) diff --git a/gio/tests/appinfo.c b/gio/tests/appinfo.c index 6a2ae697b..d9c53c853 100644 --- a/gio/tests/appinfo.c +++ b/gio/tests/appinfo.c @@ -6,6 +6,7 @@ #include #include +/* Should be called inside a #GTestDBus environment. */ static void test_launch_for_app_info (GAppInfo *appinfo) { @@ -51,15 +52,23 @@ test_launch_for_app_info (GAppInfo *appinfo) static void test_launch (void) { + GTestDBus *bus = NULL; GAppInfo *appinfo; const gchar *path; + /* Set up a test session bus to keep D-Bus traffic off the real session bus. */ + bus = g_test_dbus_new (G_TEST_DBUS_NONE); + g_test_dbus_up (bus); + path = g_test_get_filename (G_TEST_BUILT, "appinfo-test.desktop", NULL); appinfo = (GAppInfo*)g_desktop_app_info_new_from_filename (path); g_assert_true (G_IS_APP_INFO (appinfo)); test_launch_for_app_info (appinfo); g_object_unref (appinfo); + + g_test_dbus_down (bus); + g_clear_object (&bus); } static void @@ -83,6 +92,7 @@ test_launch_no_app_id (void) "Keywords=keyword1;test keyword;\n" "Categories=GNOME;GTK;\n"; + GTestDBus *bus = NULL; gchar *exec_line_variants[2]; gsize i; @@ -95,6 +105,10 @@ test_launch_no_app_id (void) g_test_bug ("https://bugzilla.gnome.org/show_bug.cgi?id=791337"); + /* Set up a test session bus to keep D-Bus traffic off the real session bus. */ + bus = g_test_dbus_new (G_TEST_DBUS_NONE); + g_test_dbus_up (bus); + for (i = 0; i < G_N_ELEMENTS (exec_line_variants); i++) { gchar *desktop_file_contents; @@ -125,6 +139,9 @@ test_launch_no_app_id (void) g_key_file_unref (fake_desktop_file); } + g_test_dbus_down (bus); + g_clear_object (&bus); + g_free (exec_line_variants[1]); g_free (exec_line_variants[0]); } @@ -332,12 +349,17 @@ launch_failed (GAppLaunchContext *context, static void test_launch_context_signals (void) { + GTestDBus *bus = NULL; GAppLaunchContext *context; GAppInfo *appinfo; GError *error = NULL; gboolean success; gchar *cmdline; + /* Set up a test session bus to keep D-Bus traffic off the real session bus. */ + bus = g_test_dbus_new (G_TEST_DBUS_NONE); + g_test_dbus_up (bus); + cmdline = g_strconcat (g_test_get_dir (G_TEST_BUILT), "/appinfo-test --option", NULL); context = g_app_launch_context_new (); @@ -358,6 +380,9 @@ test_launch_context_signals (void) g_object_unref (context); g_free (cmdline); + + g_test_dbus_down (bus); + g_clear_object (&bus); } static void diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c index bd28f940e..e82e2dd31 100644 --- a/gio/tests/desktop-app-info.c +++ b/gio/tests/desktop-app-info.c @@ -596,6 +596,7 @@ wait_for_file (const gchar *want_this, static void test_actions (void) { + GTestDBus *bus = NULL; const char *expected[] = { "frob", "tweak", "twiddle", "broken", NULL }; const gchar * const *actions; GDesktopAppInfo *appinfo; @@ -605,6 +606,10 @@ test_actions (void) gchar *tweak_path; gchar *twiddle_path; + /* Set up a test session bus to keep D-Bus traffic off the real session bus. */ + bus = g_test_dbus_new (G_TEST_DBUS_NONE); + g_test_dbus_up (bus); + appinfo = g_desktop_app_info_new_from_filename (g_test_get_filename (G_TEST_DIST, "appinfo-test-actions.desktop", NULL)); g_assert_nonnull (appinfo); @@ -651,6 +656,9 @@ test_actions (void) g_free (tweak_path); g_free (twiddle_path); g_object_unref (appinfo); + + g_test_dbus_down (bus); + g_clear_object (&bus); } static gchar * From 64e630e13251e38b712b837252e086f0392b26bd Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 18 Jan 2024 15:23:53 +0000 Subject: [PATCH 2/2] tests: Disable crash reporting in g_error() path in testing-helper This avoids four coredumps being processed for every run of the `testing` unit tests (which test `GTest`). Signed-off-by: Philip Withnall --- glib/tests/testing-helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/glib/tests/testing-helper.c b/glib/tests/testing-helper.c index da60f3e44..3f5629a48 100644 --- a/glib/tests/testing-helper.c +++ b/glib/tests/testing-helper.c @@ -55,6 +55,9 @@ test_fail (void) static void test_error (void) { + /* We expect this test to abort, so try to avoid that creating a coredump */ + g_test_disable_crash_reporting (); + g_error ("This should error out\nBecause it's just\nwrong!"); }