From 11e6c92e9521ef55ceb0b421c5d077d5793c71d5 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 15 Jul 2022 15:27:24 +0100 Subject: [PATCH 1/3] test/bus: Factor out common setup/teardown code Signed-off-by: Simon McVittie --- test/CMakeLists.txt | 6 ++-- test/Makefile.am | 6 ++-- test/bus/common.c | 61 ++++++++++++++++++++++++++++++++++++++++ test/bus/common.h | 21 ++++++++++++++ test/bus/dispatch-sha1.c | 33 ++-------------------- test/bus/dispatch.c | 33 ++-------------------- test/bus/main.c | 33 ++-------------------- test/meson.build | 6 ++-- 8 files changed, 97 insertions(+), 102 deletions(-) create mode 100644 test/bus/common.c create mode 100644 test/bus/common.h diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 864d078b..c08ad95b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -146,15 +146,15 @@ if(DBUS_ENABLE_EMBEDDED_TESTS) add_test_executable(test-platform-mutex test-platform-mutex.c ${DBUS_INTERNAL_LIBRARIES} dbus-testutils) - set(SOURCES bus/main.c) + set(SOURCES bus/main.c bus/common.c bus/common.h) add_test_executable(test-bus "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES}) set_target_properties(test-bus PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) - set(SOURCES bus/dispatch.c) + set(SOURCES bus/dispatch.c bus/common.c bus/common.h) add_test_executable(test-bus-dispatch "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES}) set_target_properties(test-bus-dispatch PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) - set(SOURCES bus/dispatch-sha1.c) + set(SOURCES bus/dispatch-sha1.c bus/common.c bus/common.h) add_test_executable(test-bus-dispatch-sha1 "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES}) set_target_properties(test-bus-dispatch-sha1 PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) diff --git a/test/Makefile.am b/test/Makefile.am index 1ee9dd21..18798278 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -199,19 +199,19 @@ test_bus_system_LDADD = \ libdbus-testutils.la \ $(NULL) -test_bus_SOURCES = bus/main.c +test_bus_SOURCES = bus/main.c bus/common.c bus/common.h test_bus_LDADD = \ $(top_builddir)/bus/libdbus-daemon-internal.la \ libdbus-testutils.la \ $(NULL) -test_bus_dispatch_SOURCES = bus/dispatch.c +test_bus_dispatch_SOURCES = bus/dispatch.c bus/common.c bus/common.h test_bus_dispatch_LDADD = \ $(top_builddir)/bus/libdbus-daemon-internal.la \ libdbus-testutils.la \ $(NULL) -test_bus_dispatch_sha1_SOURCES = bus/dispatch-sha1.c +test_bus_dispatch_sha1_SOURCES = bus/dispatch-sha1.c bus/common.c bus/common.h test_bus_dispatch_sha1_LDADD = \ $(top_builddir)/bus/libdbus-daemon-internal.la \ libdbus-testutils.la \ diff --git a/test/bus/common.c b/test/bus/common.c new file mode 100644 index 00000000..96573858 --- /dev/null +++ b/test/bus/common.c @@ -0,0 +1,61 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright 2003-2009 Red Hat, Inc. + * Copyright 2011-2022 Collabora Ltd. + * SPDX-License-Identifier: AFL-2.1 or GPL-2-or-later + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "bus/audit.h" +#include "bus/selinux.h" + +#include "test/bus/common.h" +#include "test/test-utils.h" + +#ifndef DBUS_ENABLE_EMBEDDED_TESTS +#error This file is only relevant for the embedded tests +#endif + +static void +test_pre_hook (void) +{ +} + +static void +test_post_hook (void) +{ + if (_dbus_getenv ("DBUS_TEST_SELINUX")) + bus_selinux_shutdown (); + + bus_audit_shutdown (); +} + +int +bus_test_main (int argc, + char **argv, + size_t n_tests, + const DBusTestCase *tests) +{ + return _dbus_test_main (argc, argv, n_tests, tests, + (DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS | + DBUS_TEST_FLAGS_CHECK_FD_LEAKS | + DBUS_TEST_FLAGS_REQUIRE_DATA), + test_pre_hook, test_post_hook); +} diff --git a/test/bus/common.h b/test/bus/common.h new file mode 100644 index 00000000..0f3c87d0 --- /dev/null +++ b/test/bus/common.h @@ -0,0 +1,21 @@ +/* + * Copyright 2022 Collabora Ltd. + * SPDX-License-Identifier: MIT + */ + +#ifndef TEST_BUS_COMMON_H +#define TEST_BUS_COMMON_H + +#ifndef DBUS_ENABLE_EMBEDDED_TESTS +#error This file is only relevant for the embedded tests +#endif + +#include "bus/test.h" +#include "test/test-utils.h" + +int bus_test_main (int argc, + char **argv, + size_t n_tests, + const DBusTestCase *tests); + +#endif diff --git a/test/bus/dispatch-sha1.c b/test/bus/dispatch-sha1.c index a32508bc..dc2dcb5d 100644 --- a/test/bus/dispatch-sha1.c +++ b/test/bus/dispatch-sha1.c @@ -22,41 +22,12 @@ */ #include - -#include "bus/test.h" - -#include - -#include "bus/audit.h" -#include "bus/selinux.h" -#include "test/test-utils.h" - -#ifndef DBUS_ENABLE_EMBEDDED_TESTS -#error This file is only relevant for the embedded tests -#endif - -static void -test_pre_hook (void) -{ -} - -static void -test_post_hook (void) -{ - if (_dbus_getenv ("DBUS_TEST_SELINUX")) - bus_selinux_shutdown (); - - bus_audit_shutdown (); -} +#include "test/bus/common.h" static DBusTestCase test = { "dispatch-sha1", bus_dispatch_sha1_test }; int main (int argc, char **argv) { - return _dbus_test_main (argc, argv, 1, &test, - (DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS | - DBUS_TEST_FLAGS_CHECK_FD_LEAKS | - DBUS_TEST_FLAGS_REQUIRE_DATA), - test_pre_hook, test_post_hook); + return bus_test_main (argc, argv, 1, &test); } diff --git a/test/bus/dispatch.c b/test/bus/dispatch.c index ad6718fe..bd86419f 100644 --- a/test/bus/dispatch.c +++ b/test/bus/dispatch.c @@ -22,41 +22,12 @@ */ #include - -#include "bus/test.h" - -#include - -#include "bus/audit.h" -#include "bus/selinux.h" -#include "test/test-utils.h" - -#ifndef DBUS_ENABLE_EMBEDDED_TESTS -#error This file is only relevant for the embedded tests -#endif - -static void -test_pre_hook (void) -{ -} - -static void -test_post_hook (void) -{ - if (_dbus_getenv ("DBUS_TEST_SELINUX")) - bus_selinux_shutdown (); - - bus_audit_shutdown (); -} +#include "test/bus/common.h" static DBusTestCase test = { "dispatch", bus_dispatch_test }; int main (int argc, char **argv) { - return _dbus_test_main (argc, argv, 1, &test, - (DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS | - DBUS_TEST_FLAGS_CHECK_FD_LEAKS | - DBUS_TEST_FLAGS_REQUIRE_DATA), - test_pre_hook, test_post_hook); + return bus_test_main (argc, argv, 1, &test); } diff --git a/test/bus/main.c b/test/bus/main.c index 445e9269..16c0ac20 100644 --- a/test/bus/main.c +++ b/test/bus/main.c @@ -23,32 +23,7 @@ */ #include - -#include "bus/test.h" - -#include - -#include "bus/audit.h" -#include "bus/selinux.h" -#include "test/test-utils.h" - -#ifndef DBUS_ENABLE_EMBEDDED_TESTS -#error This file is only relevant for the embedded tests -#endif - -static void -test_pre_hook (void) -{ -} - -static void -test_post_hook (void) -{ - if (_dbus_getenv ("DBUS_TEST_SELINUX")) - bus_selinux_shutdown (); - - bus_audit_shutdown (); -} +#include "test/bus/common.h" static DBusTestCase tests[] = { @@ -63,9 +38,5 @@ static DBusTestCase tests[] = int main (int argc, char **argv) { - return _dbus_test_main (argc, argv, _DBUS_N_ELEMENTS (tests), tests, - (DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS | - DBUS_TEST_FLAGS_CHECK_FD_LEAKS | - DBUS_TEST_FLAGS_REQUIRE_DATA), - test_pre_hook, test_post_hook); + return bus_test_main (argc, argv, _DBUS_N_ELEMENTS (tests), tests); } diff --git a/test/meson.build b/test/meson.build index e310e9db..28e4f0bb 100644 --- a/test/meson.build +++ b/test/meson.build @@ -230,20 +230,20 @@ if embedded_tests tests += [ { 'name': 'bus', - 'srcs': [ 'bus/main.c' ], + 'srcs': [ 'bus/main.c', 'bus/common.c' ], 'link': [ libdbus_testutils, libdbus_daemon_internal, ], 'install': false, }, { 'name': 'bus-dispatch-sha1', - 'srcs': [ 'bus/dispatch-sha1.c' ], + 'srcs': [ 'bus/dispatch-sha1.c', 'bus/common.c' ], 'link': [ libdbus_testutils, libdbus_daemon_internal, ], 'install': false, 'suite': ['slow'], }, { 'name': 'bus-dispatch', - 'srcs': [ 'bus/dispatch.c' ], + 'srcs': [ 'bus/dispatch.c', 'bus/common.c' ], 'link': [ libdbus_testutils, libdbus_daemon_internal, ], 'install': false, 'suite': ['slow'], From bef88fd5627f2d990915c9009982107a8e329ef5 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 15 Jul 2022 15:41:14 +0100 Subject: [PATCH 2/3] test/bus: Break up dispatch test into three separate tests This is really three separate test-cases: one for traditional activation as a direct child process of the dbus-daemon, and two for traditional activation (successful and failing) via the setuid dbus-daemon-launch-helper on Unix. The ones where activation succeeds extremely slow, as a result of the instrumentation for simulating malloc() failures combined with a large number of memory operations, particularly when using AddressSanitizer. Splitting up "OOM" tests like these has a disproportionately good impact on the time they take, because the simulated malloc() failure instrumentation repeats the entire test making the first malloc() fail, then making the second malloc() fail, and so on. For allocation failures in the second half of the test, this means we repeat the first half of the test with no malloc() failures a very large number of times, which is not a good use of time, because we already tested it successfully. Even when not using the "OOM" instrumentation, splitting up these tests lets them run in parallel, which is also a major time saving. Needless to say, this speeds up testing considerably. On my modern but unexceptional x86 laptop, in a typical debug build with Meson, the old dispatch test took just over 21 minutes, which drops to about 40 seconds each for the new normal-activation and helper-activation tests (and for most of that time, they're running in parallel, so the wall-clock time taken for the whole test suite is somewhere around a minute). In a debug build with Meson, gcc and AddressSanitizer, the old dispatch test takes longer than my patience will allow, and the new separate tests take about 5-6 minutes each. Reduce their timeout accordingly, but not as far as the default for slow tests (5 minutes) to allow some headroom for AddressSanitizer or slower systems. The failed-helper-activation test is almost instantaneous, and no longer needs to be marked as slow. Signed-off-by: Simon McVittie --- bus/dispatch.c | 54 +++++++++++++------- bus/test.h | 4 +- test/CMakeLists.txt | 17 ++++-- test/Makefile.am | 43 +++++++++++++--- test/bus/failed-helper-activation.c | 37 ++++++++++++++ test/bus/{dispatch.c => helper-activation.c} | 2 +- test/bus/normal-activation.c | 33 ++++++++++++ test/meson.build | 35 ++++++++++--- 8 files changed, 186 insertions(+), 39 deletions(-) create mode 100644 test/bus/failed-helper-activation.c rename test/bus/{dispatch.c => helper-activation.c} (93%) create mode 100644 test/bus/normal-activation.c diff --git a/bus/dispatch.c b/bus/dispatch.c index 3f985261..118258e4 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -5036,37 +5036,53 @@ bus_dispatch_test_conf_fail (const DBusString *test_data_dir, } #endif +#ifdef ENABLE_TRADITIONAL_ACTIVATION dbus_bool_t -bus_dispatch_test (const char *test_data_dir_cstr) +bus_test_normal_activation (const char *test_data_dir_cstr) { DBusString test_data_dir; _dbus_string_init_const (&test_data_dir, test_data_dir_cstr); -#ifdef ENABLE_TRADITIONAL_ACTIVATION - /* run normal activation tests */ - _dbus_verbose ("Normal activation tests\n"); if (!bus_dispatch_test_conf (&test_data_dir, - "valid-config-files/debug-allow-all.conf", FALSE)) + "valid-config-files/debug-allow-all.conf", FALSE)) return FALSE; -#ifndef DBUS_WIN - /* run launch-helper activation tests */ - _dbus_verbose ("Launch helper activation tests\n"); - if (!bus_dispatch_test_conf (&test_data_dir, - "valid-config-files-system/debug-allow-all-pass.conf", TRUE)) - return FALSE; - - /* run select launch-helper activation tests on broken service files */ - if (!bus_dispatch_test_conf_fail (&test_data_dir, - "valid-config-files-system/debug-allow-all-fail.conf")) - return FALSE; -#endif -#endif - return TRUE; } +#ifndef DBUS_WIN +dbus_bool_t +bus_test_helper_activation (const char *test_data_dir_cstr) +{ + DBusString test_data_dir; + + _dbus_string_init_const (&test_data_dir, test_data_dir_cstr); + + if (!bus_dispatch_test_conf (&test_data_dir, + "valid-config-files-system/debug-allow-all-pass.conf", TRUE)) + return FALSE; + + return TRUE; +} + +dbus_bool_t +bus_test_failed_helper_activation (const char *test_data_dir_cstr) +{ + DBusString test_data_dir; + + _dbus_string_init_const (&test_data_dir, test_data_dir_cstr); + + /* run select launch-helper activation tests on broken service files */ + if (!bus_dispatch_test_conf_fail (&test_data_dir, + "valid-config-files-system/debug-allow-all-fail.conf")) + return FALSE; + + return TRUE; +} +#endif /* !DBUS_WIN */ +#endif /* ENABLE_TRADITIONAL_ACTIVATION */ + dbus_bool_t bus_dispatch_sha1_test (const char *test_data_dir_cstr) { diff --git a/bus/test.h b/bus/test.h index 6f1f6b0d..a6658cab 100644 --- a/bus/test.h +++ b/bus/test.h @@ -36,7 +36,9 @@ typedef dbus_bool_t (* BusConnectionForeachFunction) (DBusConnection *connection, void *data); -dbus_bool_t bus_dispatch_test (const char *test_data_dir_cstr); +dbus_bool_t bus_test_normal_activation (const char *test_data_dir_cstr); +dbus_bool_t bus_test_helper_activation (const char *test_data_dir_cstr); +dbus_bool_t bus_test_failed_helper_activation (const char *test_data_dir_cstr); dbus_bool_t bus_dispatch_sha1_test (const char *test_data_dir_cstr); dbus_bool_t bus_config_parser_test (const char *test_data_dir_cstr); dbus_bool_t bus_config_parser_trivial_test (const char *test_data_dir_cstr); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c08ad95b..8ea3bb52 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -150,9 +150,12 @@ if(DBUS_ENABLE_EMBEDDED_TESTS) add_test_executable(test-bus "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES}) set_target_properties(test-bus PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) - set(SOURCES bus/dispatch.c bus/common.c bus/common.h) - add_test_executable(test-bus-dispatch "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES}) - set_target_properties(test-bus-dispatch PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) + if(ENABLE_TRADITIONAL_ACTIVATION) + set(SOURCES bus/normal-activation.c bus/common.c bus/common.h) + add_test_executable(test-bus-normal-activation "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES}) + set_target_properties(test-bus-normal-activation PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) + endif() + set(SOURCES bus/dispatch-sha1.c bus/common.c bus/common.h) add_test_executable(test-bus-dispatch-sha1 "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES}) @@ -163,6 +166,14 @@ if(DBUS_ENABLE_EMBEDDED_TESTS) if(ENABLE_TRADITIONAL_ACTIVATION) add_test_executable(test-bus-launch-helper-oom bus/launch-helper-oom.c launch-helper-internal dbus-testutils) add_helper_executable(dbus-daemon-launch-helper-for-tests bus/launch-helper-for-tests.c launch-helper-internal) + + set(SOURCES bus/failed-helper-activation.c bus/common.c bus/common.h) + add_test_executable(test-bus-failed-helper-activation "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES}) + set_target_properties(test-bus-failed-helper-activation PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) + + set(SOURCES bus/helper-activation.c bus/common.c bus/common.h) + add_test_executable(test-bus-helper-activation "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES}) + set_target_properties(test-bus-helper-activation PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS}) endif() endif() endif() diff --git a/test/Makefile.am b/test/Makefile.am index 18798278..f791a56e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -87,16 +87,21 @@ endif uninstallable_test_programs += \ test-platform-mutex \ test-bus \ - test-bus-dispatch \ test-bus-dispatch-sha1 \ test-marshal-recursive \ test-message-internals \ $(NULL) +if ENABLE_TRADITIONAL_ACTIVATION +uninstallable_test_programs += test-normal-activation +endif + if DBUS_UNIX if ENABLE_TRADITIONAL_ACTIVATION uninstallable_test_programs += test-bus-launch-helper-oom uninstallable_test_programs += test-bus-system +uninstallable_test_programs += test-failed-helper-activation +uninstallable_test_programs += test-helper-activation # this is used by the tests but is not, itself, a test TEST_BINARIES += dbus-daemon-launch-helper-for-tests endif ENABLE_TRADITIONAL_ACTIVATION @@ -205,12 +210,6 @@ test_bus_LDADD = \ libdbus-testutils.la \ $(NULL) -test_bus_dispatch_SOURCES = bus/dispatch.c bus/common.c bus/common.h -test_bus_dispatch_LDADD = \ - $(top_builddir)/bus/libdbus-daemon-internal.la \ - libdbus-testutils.la \ - $(NULL) - test_bus_dispatch_sha1_SOURCES = bus/dispatch-sha1.c bus/common.c bus/common.h test_bus_dispatch_sha1_LDADD = \ $(top_builddir)/bus/libdbus-daemon-internal.la \ @@ -220,6 +219,26 @@ test_bus_dispatch_sha1_LDADD = \ test_hash_SOURCES = internals/hash.c test_hash_LDADD = libdbus-testutils.la +test_failed_helper_activation_SOURCES = \ + bus/failed-helper-activation.c \ + bus/common.c \ + bus/common.h \ + $(NULL) +test_failed_helper_activation_LDADD = \ + $(top_builddir)/bus/libdbus-daemon-internal.la \ + libdbus-testutils.la \ + $(NULL) + +test_helper_activation_SOURCES = \ + bus/helper-activation.c \ + bus/common.c \ + bus/common.h \ + $(NULL) +test_helper_activation_LDADD = \ + $(top_builddir)/bus/libdbus-daemon-internal.la \ + libdbus-testutils.la \ + $(NULL) + test_marshal_recursive_SOURCES = \ internals/dbus-marshal-recursive-util.c \ internals/dbus-marshal-recursive-util.h \ @@ -257,6 +276,16 @@ test_misc_internals_SOURCES = \ $(NULL) test_misc_internals_LDADD = libdbus-testutils.la +test_normal_activation_SOURCES = \ + bus/normal-activation.c \ + bus/common.c \ + bus/common.h \ + $(NULL) +test_normal_activation_LDADD = \ + $(top_builddir)/bus/libdbus-daemon-internal.la \ + libdbus-testutils.la \ + $(NULL) + test_platform_mutex_SOURCES = test-platform-mutex.c test_platform_mutex_LDADD = \ $(top_builddir)/dbus/libdbus-internal.la \ diff --git a/test/bus/failed-helper-activation.c b/test/bus/failed-helper-activation.c new file mode 100644 index 00000000..044ab42d --- /dev/null +++ b/test/bus/failed-helper-activation.c @@ -0,0 +1,37 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright 2003-2009 Red Hat, Inc. + * Copyright 2011-2018 Collabora Ltd. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include "test/bus/common.h" + +static DBusTestCase test = +{ + "failed-helper-activation", + bus_test_failed_helper_activation +}; + +int +main (int argc, char **argv) +{ + return bus_test_main (argc, argv, 1, &test); +} diff --git a/test/bus/dispatch.c b/test/bus/helper-activation.c similarity index 93% rename from test/bus/dispatch.c rename to test/bus/helper-activation.c index bd86419f..f4c9a37d 100644 --- a/test/bus/dispatch.c +++ b/test/bus/helper-activation.c @@ -24,7 +24,7 @@ #include #include "test/bus/common.h" -static DBusTestCase test = { "dispatch", bus_dispatch_test }; +static DBusTestCase test = { "helper-activation", bus_test_helper_activation }; int main (int argc, char **argv) diff --git a/test/bus/normal-activation.c b/test/bus/normal-activation.c new file mode 100644 index 00000000..ce935a5f --- /dev/null +++ b/test/bus/normal-activation.c @@ -0,0 +1,33 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ +/* + * Copyright 2003-2009 Red Hat, Inc. + * Copyright 2011-2018 Collabora Ltd. + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include "test/bus/common.h" + +static DBusTestCase test = { "normal-activation", bus_test_normal_activation }; + +int +main (int argc, char **argv) +{ + return bus_test_main (argc, argv, 1, &test); +} diff --git a/test/meson.build b/test/meson.build index 28e4f0bb..c593a801 100644 --- a/test/meson.build +++ b/test/meson.build @@ -241,14 +241,6 @@ if embedded_tests 'install': false, 'suite': ['slow'], }, - { - 'name': 'bus-dispatch', - 'srcs': [ 'bus/dispatch.c', 'bus/common.c' ], - 'link': [ libdbus_testutils, libdbus_daemon_internal, ], - 'install': false, - 'suite': ['slow'], - 'timeout': 3000, - }, { 'name': 'marshal-recursive', 'srcs': [ @@ -273,8 +265,35 @@ if embedded_tests }, ] + if use_traditional_activation + tests += [ + { + 'name': 'bus-normal-activation', + 'srcs': [ 'bus/normal-activation.c', 'bus/common.c' ], + 'link': [ libdbus_testutils, libdbus_daemon_internal, ], + 'install': false, + 'suite': ['slow'], + 'timeout': 1000, + }, + ] + endif + if use_traditional_activation and platform_unix tests += [ + { + 'name': 'bus-failed-helper-activation', + 'srcs': [ 'bus/failed-helper-activation.c', 'bus/common.c' ], + 'link': [ libdbus_testutils, libdbus_daemon_internal, ], + 'install': false, + }, + { + 'name': 'bus-helper-activation', + 'srcs': [ 'bus/helper-activation.c', 'bus/common.c' ], + 'link': [ libdbus_testutils, libdbus_daemon_internal, ], + 'install': false, + 'suite': ['slow'], + 'timeout': 1000, + }, { 'name': 'bus-launch-helper-oom', 'srcs': [ 'bus/launch-helper-oom.c' ], From f49ff4f0eaf1a9176b6b9b1249af96612398e50a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 17 Jul 2022 16:20:14 +0100 Subject: [PATCH 3/3] dispatch test: Pass in test data directory as a C string This reduces duplication a little bit. Signed-off-by: Simon McVittie --- bus/dispatch.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/bus/dispatch.c b/bus/dispatch.c index 118258e4..c7803b42 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -4797,25 +4797,27 @@ setenv_TEST_LAUNCH_HELPER_CONFIG(const DBusString *test_data_dir, } static dbus_bool_t -bus_dispatch_test_conf (const DBusString *test_data_dir, - const char *filename, - dbus_bool_t use_launcher) +bus_dispatch_test_conf (const char *test_data_dir_cstr, + const char *filename, + dbus_bool_t use_launcher) { BusContext *context; DBusConnection *foo; DBusConnection *bar; DBusConnection *baz; DBusError error; + DBusString test_data_dir; + _dbus_string_init_const (&test_data_dir, test_data_dir_cstr); _dbus_test_diag ("%s:%s...", _DBUS_FUNCTION_NAME, filename); /* save the config name for the activation helper */ - if (!setenv_TEST_LAUNCH_HELPER_CONFIG (test_data_dir, filename)) + if (!setenv_TEST_LAUNCH_HELPER_CONFIG (&test_data_dir, filename)) _dbus_test_fatal ("no memory setting TEST_LAUNCH_HELPER_CONFIG"); dbus_error_init (&error); - context = bus_context_new_test (test_data_dir, filename); + context = bus_context_new_test (&test_data_dir, filename); if (context == NULL) { _dbus_test_not_ok ("%s:%s - bus_context_new_test() failed", @@ -4972,22 +4974,24 @@ bus_dispatch_test_conf (const DBusString *test_data_dir, #if defined(ENABLE_TRADITIONAL_ACTIVATION) && !defined(DBUS_WIN) static dbus_bool_t -bus_dispatch_test_conf_fail (const DBusString *test_data_dir, - const char *filename) +bus_dispatch_test_conf_fail (const char *test_data_dir_cstr, + const char *filename) { BusContext *context; DBusConnection *foo; DBusError error; + DBusString test_data_dir; + _dbus_string_init_const (&test_data_dir, test_data_dir_cstr); _dbus_test_diag ("%s:%s...", _DBUS_FUNCTION_NAME, filename); /* save the config name for the activation helper */ - if (!setenv_TEST_LAUNCH_HELPER_CONFIG (test_data_dir, filename)) + if (!setenv_TEST_LAUNCH_HELPER_CONFIG (&test_data_dir, filename)) _dbus_test_fatal ("no memory setting TEST_LAUNCH_HELPER_CONFIG"); dbus_error_init (&error); - context = bus_context_new_test (test_data_dir, filename); + context = bus_context_new_test (&test_data_dir, filename); if (context == NULL) { _dbus_test_not_ok ("%s:%s - bus_context_new_test() failed", @@ -5040,11 +5044,7 @@ bus_dispatch_test_conf_fail (const DBusString *test_data_dir, dbus_bool_t bus_test_normal_activation (const char *test_data_dir_cstr) { - DBusString test_data_dir; - - _dbus_string_init_const (&test_data_dir, test_data_dir_cstr); - - if (!bus_dispatch_test_conf (&test_data_dir, + if (!bus_dispatch_test_conf (test_data_dir_cstr, "valid-config-files/debug-allow-all.conf", FALSE)) return FALSE; @@ -5055,11 +5055,7 @@ bus_test_normal_activation (const char *test_data_dir_cstr) dbus_bool_t bus_test_helper_activation (const char *test_data_dir_cstr) { - DBusString test_data_dir; - - _dbus_string_init_const (&test_data_dir, test_data_dir_cstr); - - if (!bus_dispatch_test_conf (&test_data_dir, + if (!bus_dispatch_test_conf (test_data_dir_cstr, "valid-config-files-system/debug-allow-all-pass.conf", TRUE)) return FALSE; @@ -5069,12 +5065,8 @@ bus_test_helper_activation (const char *test_data_dir_cstr) dbus_bool_t bus_test_failed_helper_activation (const char *test_data_dir_cstr) { - DBusString test_data_dir; - - _dbus_string_init_const (&test_data_dir, test_data_dir_cstr); - /* run select launch-helper activation tests on broken service files */ - if (!bus_dispatch_test_conf_fail (&test_data_dir, + if (!bus_dispatch_test_conf_fail (test_data_dir_cstr, "valid-config-files-system/debug-allow-all-fail.conf")) return FALSE;