diff --git a/meson.build b/meson.build index 4d7b4b80..ab7440f7 100644 --- a/meson.build +++ b/meson.build @@ -66,12 +66,6 @@ if use_docs prog_rst2man = find_program('rst2man', 'rst2man.py') endif -# -# Config: install-tests -# -install_tests = get_option('install-tests') -test_install_dir = get_option('prefix') / 'lib/dbus-broker/tests' - # # Config: launcher # @@ -119,6 +113,13 @@ endforeach add_project_arguments('-DSYSTEM_CONSOLE_USERS=' + acc_sysusers, language: 'c') +# +# Config: tests +# + +use_tests = get_option('tests') +conf.set('testdir', get_option('prefix') / 'lib/dbus-broker/tests') + # # Global Parameters # diff --git a/meson_options.txt b/meson_options.txt index d3399132..5227a938 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,9 +1,9 @@ option('apparmor', type: 'boolean', value: false, description: 'AppArmor support') option('audit', type: 'boolean', value: false, description: 'Audit support') option('docs', type: 'boolean', value: false, description: 'Build documentation') -option('install-tests', type: 'boolean', value: false, description: 'Install test executables') option('launcher', type: 'boolean', value: true, description: 'Build compatibility launcher') option('linux-4-17', type: 'boolean', value: false, description: 'Require linux-4.17 at runtime and make use of its features') option('reference-test', type: 'boolean', value: false, description: 'Run test suite against reference implementation') option('selinux', type: 'boolean', value: false, description: 'SELinux support') option('system-console-users', type: 'array', value: [], description: 'Additional set of names of system-users to be considered at-console') +option('tests', type: 'boolean', value: false, description: 'Include tests in the distribution') diff --git a/src/meson.build b/src/meson.build index 3f92a9c6..4b9bc71c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -173,195 +173,81 @@ endif # target: test-* # -test_unit_install_kwargs = { - 'install': install_tests, - 'install_dir': test_install_dir / 'unit', +test_kwargs = { + 'dependencies': dep_bus, + 'install': use_tests, + 'install_dir': conf.get('testdir') / 'unit', } -test_address = executable( - 'test-address', - sources: ['dbus/test-address.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('Address Handling', test_address) +test_address = executable('test-address', sources: ['dbus/test-address.c'], kwargs: test_kwargs) +test('Address Handling', test_address, suite: 'unit') -test_apparmor = executable( - 'test-apparmor', - sources: ['util/test-apparmor.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('AppArmor Handling', test_apparmor) +test_apparmor = executable('test-apparmor', sources: ['util/test-apparmor.c'], kwargs: test_kwargs) +test('AppArmor Handling', test_apparmor, suite: 'unit') if use_launcher - test_config = executable( - 'test-config', - sources: ['launch/test-config.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs - ) - test('Configuration Parser', test_config) + test_config = executable('test-config', sources: ['launch/test-config.c'], kwargs: test_kwargs) + test('Configuration Parser', test_config, suite: 'unit') endif -test_dirwatch = executable( - 'test-dirwatch', - sources: ['util/test-dirwatch.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('Directory Watch', test_dirwatch) +test_dirwatch = executable('test-dirwatch', sources: ['util/test-dirwatch.c'], kwargs: test_kwargs) +test('Directory Watch', test_dirwatch, suite: 'unit') -test_dispatch = executable( - 'test-dispatch', - sources: ['util/test-dispatch.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('Event Dispatcher', test_dispatch) +test_dispatch = executable('test-dispatch', sources: ['util/test-dispatch.c'], kwargs: test_kwargs) +test('Event Dispatcher', test_dispatch, suite: 'unit') -test_error = executable( - 'test-error', - sources: ['util/test-error.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('Error Handling', test_error) +test_error = executable('test-error', sources: ['util/test-error.c'], kwargs: test_kwargs) +test('Error Handling', test_error, suite: 'unit') -test_fdlist = executable( - 'test-fdlist', - sources: ['util/test-fdlist.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('Utility File-Desciptor Lists', test_fdlist) +test_fdlist = executable('test-fdlist', sources: ['util/test-fdlist.c'], kwargs: test_kwargs) +test('Utility File-Desciptor Lists', test_fdlist, suite: 'unit') -test_fs = executable( - 'test-fs', - sources: ['util/test-fs.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('File System Helpers', test_fs) +test_fs = executable('test-fs', sources: ['util/test-fs.c'], kwargs: test_kwargs) +test('File System Helpers', test_fs, suite: 'unit') -test_match = executable( - 'test-match', - sources: ['bus/test-match.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('D-Bus Match Handling', test_match) +test_match = executable('test-match', sources: ['bus/test-match.c'], kwargs: test_kwargs) +test('D-Bus Match Handling', test_match, suite: 'unit') -test_message = executable( - 'test-message', - sources: ['dbus/test-message.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('D-Bus Message Abstraction', test_message) +test_message = executable('test-message', sources: ['dbus/test-message.c'], kwargs: test_kwargs) +test('D-Bus Message Abstraction', test_message, suite: 'unit') -test_misc = executable( - 'test-misc', - sources: ['util/test-misc.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('Miscellaneous Helpers', test_misc) +test_misc = executable('test-misc', sources: ['util/test-misc.c'], kwargs: test_kwargs) +test('Miscellaneous Helpers', test_misc, suite: 'unit') -test_name = executable( - 'test-name', - sources: ['bus/test-name.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('Name Registry', test_name) +test_name = executable('test-name', sources: ['bus/test-name.c'], kwargs: test_kwargs) +test('Name Registry', test_name, suite: 'unit') if use_launcher - test_nss_cache = executable( - 'test-nss-cache', - sources: ['launch/test-nss-cache.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs - ) - test('NSS Cache', test_nss_cache) + test_nss_cache = executable('test-nss-cache', sources: ['launch/test-nss-cache.c'], kwargs: test_kwargs) + test('NSS Cache', test_nss_cache, suite: 'unit') endif -test_peersec = executable( - 'test-peersec', - sources: ['util/test-peersec.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('SO_PEERSEC Queries', test_peersec) +test_peersec = executable('test-peersec', sources: ['util/test-peersec.c'], kwargs: test_kwargs) +test('SO_PEERSEC Queries', test_peersec, suite: 'unit') -test_proc = executable( - 'test-proc', - sources: ['util/test-proc.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('Proc Utilities', test_proc) +test_proc = executable('test-proc', sources: ['util/test-proc.c'], kwargs: test_kwargs) +test('Proc Utilities', test_proc, suite: 'unit') -test_queue = executable( - 'test-queue', - sources: ['dbus/test-queue.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('D-Bus I/O Queues', test_queue) +test_queue = executable('test-queue', sources: ['dbus/test-queue.c'], kwargs: test_kwargs) +test('D-Bus I/O Queues', test_queue, suite: 'unit') -test_reply = executable( - 'test-reply', - sources: ['bus/test-reply.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('Reply Tracking', test_reply) +test_reply = executable('test-reply', sources: ['bus/test-reply.c'], kwargs: test_kwargs) +test('Reply Tracking', test_reply, suite: 'unit') -test_sasl = executable( - 'test-sasl', - sources: ['dbus/test-sasl.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('D-Bus SASL Parser', test_sasl) +test_sasl = executable('test-sasl', sources: ['dbus/test-sasl.c'], kwargs: test_kwargs) +test('D-Bus SASL Parser', test_sasl, suite: 'unit') -test_socket = executable( - 'test-socket', - sources: ['dbus/test-socket.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('D-Bus Socket Abstraction', test_socket) +test_socket = executable('test-socket', sources: ['dbus/test-socket.c'], kwargs: test_kwargs) +test('D-Bus Socket Abstraction', test_socket, suite: 'unit') -test_sockopt = executable( - 'test-sockopt', - sources: ['util/test-sockopt.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('D-Bus Socket Options', test_sockopt) +test_sockopt = executable('test-sockopt', sources: ['util/test-sockopt.c'], kwargs: test_kwargs) +test('D-Bus Socket Options', test_sockopt, suite: 'unit') -test_stitching = executable( - 'test-stitching', - sources: ['dbus/test-stitching.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('Message Sender Stitching', test_stitching) +test_stitching = executable('test-stitching', sources: ['dbus/test-stitching.c'], kwargs: test_kwargs) +test('Message Sender Stitching', test_stitching, suite: 'unit') -test_systemd = executable( - 'test-systemd', - sources: ['util/test-systemd.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('Systemd Utilities', test_systemd) +test_systemd = executable('test-systemd', sources: ['util/test-systemd.c'], kwargs: test_kwargs) +test('Systemd Utilities', test_systemd, suite: 'unit') -test_user = executable( - 'test-user', - sources: ['util/test-user.c'], - dependencies: dep_bus, - kwargs: test_unit_install_kwargs -) -test('User Accounting', test_user) +test_user = executable('test-user', sources: ['util/test-user.c'], kwargs: test_kwargs) +test('User Accounting', test_user, suite: 'unit') diff --git a/test/dbus/meson.build b/test/dbus/meson.build index d7c4cee6..b25e64a5 100644 --- a/test/dbus/meson.build +++ b/test/dbus/meson.build @@ -37,11 +37,6 @@ dep_test = declare_dependency( version: meson.project_version(), ) -test_dbus_install_kwargs = { - 'install': install_tests, - 'install_dir': test_install_dir / 'dbus', -} - # # target: tool-* # @@ -49,65 +44,32 @@ test_dbus_install_kwargs = { tool_flood = executable('tool-flood', ['tool-flood.c'], dependencies: [dep_test]) # -# target: bench-* +# target: bench-* / test-* # -bench_connect = executable( - 'bench-connect', - sources: ['bench-connect.c'], - dependencies: [dep_test], - kwargs: test_dbus_install_kwargs -) -bench_message = executable( - 'bench-message', - sources: ['bench-message.c'], - dependencies: [dep_test], - kwargs: test_dbus_install_kwargs -) +test_kwargs = { + 'dependencies': [dep_test], + 'install': use_tests, + 'install_dir': conf.get('testdir') / 'dbus', +} -# -# target: test-* -# +bench_connect = executable('bench-connect', sources: ['bench-connect.c'], kwargs: test_kwargs) +bench_message = executable('bench-message', sources: ['bench-message.c'], kwargs: test_kwargs) -test_broker = executable( - 'test-broker', - sources: ['test-broker.c'], - dependencies: [dep_test], - kwargs: test_dbus_install_kwargs -) -test_driver = executable( - 'test-driver', - sources: ['test-driver.c'], - dependencies: [dep_test], - kwargs: test_dbus_install_kwargs -) -test_fdstream = executable( - 'test-fdstream', - sources: ['test-fdstream.c'], - dependencies: [dep_test], - kwargs: test_dbus_install_kwargs -) -test_lifetime = executable( - 'test-lifetime', - sources: ['test-lifetime.c'], - dependencies: [dep_test], - kwargs: test_dbus_install_kwargs -) -test_matches = executable( - 'test-matches', - sources: ['test-matches.c'], - dependencies: [dep_test], - kwargs: test_dbus_install_kwargs -) +test_broker = executable('test-broker', sources: ['test-broker.c'], kwargs: test_kwargs) +test_driver = executable('test-driver', sources: ['test-driver.c'], kwargs: test_kwargs) +test_fdstream = executable('test-fdstream', sources: ['test-fdstream.c'], kwargs: test_kwargs) +test_lifetime = executable('test-lifetime', sources: ['test-lifetime.c'], kwargs: test_kwargs) +test_matches = executable('test-matches', sources: ['test-matches.c'], kwargs: test_kwargs) suites = [ - { 'suite': 'dbus-broker(1)', 'env': ['DBUS_BROKER_TEST_BROKER=' + exe_dbus_broker.full_path()]}, + { 'suite': 'dbus-broker', 'env': ['DBUS_BROKER_TEST_BROKER=' + exe_dbus_broker.full_path()]}, ] if use_reference_test - dbus_daemon_bin = dep_dbus.get_variable(pkgconfig: 'bindir') + '/dbus-daemon' + dbus_daemon_bin = dep_dbus.get_variable(pkgconfig: 'bindir') / 'dbus-daemon' suites += [ - { 'suite': 'dbus-daemon(1)', 'env': ['DBUS_BROKER_TEST_DAEMON=' + dbus_daemon_bin]}, + { 'suite': 'dbus-daemon', 'env': ['DBUS_BROKER_TEST_DAEMON=' + dbus_daemon_bin]}, ] endif diff --git a/test/dbus/test-driver.c b/test/dbus/test-driver.c index 23fb7c6f..90e80764 100644 --- a/test/dbus/test-driver.c +++ b/test/dbus/test-driver.c @@ -1685,7 +1685,12 @@ static void test_verify_credentials(sd_bus_message *message) { c_assert(got_uid); c_assert(got_pid); - c_assert(got_gids); + + if (!util_is_reference()) { + // Group-IDs are a relatively new feature, which might not be + // reported by the reference implementation used for this run. + c_assert(got_gids); + } /* * XXX: verify that we get the security label at least when SELinux is enabled diff --git a/test/dbus/test-fdstream.c b/test/dbus/test-fdstream.c index f301b1e4..4b91e63e 100644 --- a/test/dbus/test-fdstream.c +++ b/test/dbus/test-fdstream.c @@ -274,7 +274,7 @@ int main(int argc, char **argv) { * dbus-daemon(1), so we disable the test. Both issues are reported and * are hopefully fixed soon. See BZ #101754, #101755 */ - if (getenv("DBUS_BROKER_TEST_DAEMON")) + if (util_is_reference()) return 77; for (unsigned int i = 0; i < _TEST_FD_STREAM_N; ++i) { diff --git a/test/dbus/util-broker.c b/test/dbus/util-broker.c index d5939875..13e48dc6 100644 --- a/test/dbus/util-broker.c +++ b/test/dbus/util-broker.c @@ -18,6 +18,10 @@ #include "util/syscall.h" #include "util-broker.h" +bool util_is_reference(void) { + return !!getenv("DBUS_BROKER_TEST_DAEMON"); +} + void util_event_new(sd_event **eventp) { _c_cleanup_(sd_event_unrefp) sd_event *event = NULL; sigset_t sigold; @@ -205,7 +209,6 @@ void util_fork_broker(sd_bus **busp, sd_event *event, int listener_fd, pid_t *pi c_assert(r >= 0); bin = getenv("DBUS_BROKER_TEST_BROKER") ?: "/usr/bin/dbus-broker"; - fprintf(stderr, "Using dbus-broker binary %s\n", bin); r = execl(bin, bin, "--controller", fdstr, @@ -322,7 +325,6 @@ void util_fork_daemon(sd_event *event, int pipe_fd, pid_t *pidp) { /* exec dbus-daemon */ bin = getenv("DBUS_BROKER_TEST_DAEMON") ?: "/usr/bin/dbus-daemon"; - fprintf(stderr, "Using dbus-daemon binary %s\n", bin); r = execl(bin, bin, path, @@ -484,9 +486,10 @@ void util_broker_spawn(Broker *broker) { buffer + strlen("unix:path="), ',', sizeof(broker->address.sun_path) - 1); - } else + } else { /* Anything else is unexpected */ - assert(false); + c_assert(false); + } c_assert(e); --e; diff --git a/test/dbus/util-broker.h b/test/dbus/util-broker.h index a3f5f492..36afc17f 100644 --- a/test/dbus/util-broker.h +++ b/test/dbus/util-broker.h @@ -36,6 +36,7 @@ struct Broker { /* misc */ +bool util_is_reference(void); void util_event_new(sd_event **eventp); void util_fork_broker(sd_bus **busp, sd_event *event, int listener_fd, pid_t *pidp); void util_fork_daemon(sd_event *event, int pipe_fd, pid_t *pidp);