Skip to content

Commit

Permalink
test: make the reference test work standalone
Browse files Browse the repository at this point in the history
Let's make the reference and benchmark tests work standalone, i.e.
without a build dir, since they're useful on their own.

This renames the $DBUS_BROKER_TEST_DAEMON env variable to
$TEST_DBUS_DAEMON and introduces a matching $TEST_DBUS_BROKER variable,
which both can be used to override the path to both dbus-broker and
dbus-daemon binaries that are used by the respective tests.
  • Loading branch information
mrc0mmand committed Mar 22, 2024
1 parent 0cdc6e0 commit 45fd9a3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 51 deletions.
70 changes: 26 additions & 44 deletions test/dbus/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -41,62 +41,44 @@ dep_test = declare_dependency(
# target: tool-*
#

tool_flood = executable('tool-flood', ['tool-flood.c'], dependencies: [ dep_test ])
tool_flood = executable('tool-flood', ['tool-flood.c'], dependencies: [dep_test])

#
# target: bench-*
#

bench_connect = executable('bench-connect', ['bench-connect.c'], dependencies: [ dep_test ])
benchmark('Connection', bench_connect)

bench_message = executable('bench-message', ['bench-message.c'], dependencies: [ dep_test ])
benchmark('Message passing', bench_message)
bench_connect = executable('bench-connect', ['bench-connect.c'], dependencies: [dep_test])
bench_message = executable('bench-message', ['bench-message.c'], dependencies: [dep_test])

#
# target: test-*
#

test_broker = executable('test-broker', ['test-broker.c'], dependencies: [ dep_test ])
test('Broker API', test_broker)

test_driver = executable('test-driver', ['test-driver.c'], dependencies: [ dep_test ])
test('Driver API', test_driver)

test_fdstream = executable('test-fdstream', ['test-fdstream.c'], dependencies: [ dep_test ])
test('FD Stream Constraints', test_fdstream)
test_broker = executable('test-broker', ['test-broker.c'], dependencies: [dep_test])
test_driver = executable('test-driver', ['test-driver.c'], dependencies: [dep_test])
test_fdstream = executable('test-fdstream', ['test-fdstream.c'], dependencies: [dep_test])
test_lifetime = executable('test-lifetime', ['test-lifetime.c'], dependencies: [dep_test])
test_matches = executable('test-matches', ['test-matches.c'], dependencies: [dep_test])

test_lifetime = executable('test-lifetime', ['test-lifetime.c'], dependencies: [ dep_test ])
test('Client Lifetime', test_lifetime)

test_matches = executable('test-matches', ['test-matches.c'], dependencies: [ dep_test ])
test('Signals and Matches', test_matches)
suites = [
{ 'suite': 'dbus-broker(1)', 'env': ['TEST_DBUS_BROKER=' + exe_dbus_broker.full_path()]},
]

if use_reference_test
dbus_bin = dep_dbus.get_variable(pkgconfig: 'bindir') + '/dbus-daemon'

benchmark('Connection', bench_connect,
suite: 'dbus-daemon(1)',
env: [ 'DBUS_BROKER_TEST_DAEMON=' + dbus_bin ],
timeout: 60)
benchmark('Message passing', bench_message,
suite: 'dbus-daemon(1)',
env: [ 'DBUS_BROKER_TEST_DAEMON=' + dbus_bin ],
timeout: 120)

test('Broker API', test_broker,
suite: 'dbus-daemon(1)',
env: [ 'DBUS_BROKER_TEST_DAEMON=' + dbus_bin ])
test('Driver API', test_driver,
suite: 'dbus-daemon(1)',
env: [ 'DBUS_BROKER_TEST_DAEMON=' + dbus_bin ])
test('FD Stream Constraints', test_fdstream,
suite: 'dbus-daemon(1)',
env: [ 'DBUS_BROKER_TEST_DAEMON=' + dbus_bin ])
test('Client Lifetime', test_lifetime,
suite: 'dbus-daemon(1)',
env: [ 'DBUS_BROKER_TEST_DAEMON=' + dbus_bin ])
test('Signals and Matches', test_matches,
suite: 'dbus-daemon(1)',
env: [ 'DBUS_BROKER_TEST_DAEMON=' + dbus_bin ])
dbus_daemon_bin = dep_dbus.get_variable(pkgconfig: 'bindir') + '/dbus-daemon'
suites += [
{ 'suite': 'dbus-daemon(1)', 'env': ['TEST_DBUS_DAEMON=' + dbus_daemon_bin]},
]
endif

foreach suite : suites
benchmark('Connection', bench_connect, timeout: 60, kwargs: suite)
benchmark('Message passing', bench_message, timeout: 120, kwargs: suite)

test('Broker API', test_broker, kwargs: suite)
test('Driver API', test_driver, kwargs: suite)
test('FD Stream Constraints', test_fdstream, kwargs: suite)
test('Client Lifetime', test_lifetime, kwargs: suite)
test('Signals and Matches', test_matches, kwargs: suite)
endforeach
4 changes: 2 additions & 2 deletions test/dbus/test-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ static void test_remove_match(void) {
r = sd_bus_call_method(bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus",
"RemoveMatch", &error, NULL,
"s", "sender=org.freedesktop.DBus");
if (!getenv("DBUS_BROKER_TEST_DAEMON")) {
if (!getenv("TEST_DBUS_DAEMON")) {
/* XXX: dbus-daemon is buggy, ignore for now. See <https://bugs.freedesktop.org/show_bug.cgi?id=101161> */
c_assert(r < 0);
c_assert(!strcmp(error.name, "org.freedesktop.DBus.Error.MatchRuleNotFound"));
Expand All @@ -1189,7 +1189,7 @@ static void test_remove_match(void) {
r = sd_bus_call_method(bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus",
"RemoveMatch", &error, NULL,
"s", "sender=org.freedesktop.DBus");
if (!getenv("DBUS_BROKER_TEST_DAEMON")) {
if (!getenv("TEST_DBUS_DAEMON")) {
/* XXX: ignore bug in dbus-daemon, as above */
c_assert(r < 0);
c_assert(!strcmp(error.name, "org.freedesktop.DBus.Error.MatchRuleNotFound"));
Expand Down
2 changes: 1 addition & 1 deletion test/dbus/test-fdstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (getenv("TEST_DBUS_DAEMON"))
return 77;

for (unsigned int i = 0; i < _TEST_FD_STREAM_N; ++i) {
Expand Down
12 changes: 8 additions & 4 deletions test/dbus/util-broker.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void util_fork_broker(sd_bus **busp, sd_event *event, int listener_fd, pid_t *pi
_c_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
_c_cleanup_(sd_bus_message_unrefp) sd_bus_message *message = NULL;
_c_cleanup_(c_freep) char *fdstr = NULL;
const char *bin;
int r, pair[2];
pid_t pid;

Expand All @@ -203,8 +204,10 @@ void util_fork_broker(sd_bus **busp, sd_event *event, int listener_fd, pid_t *pi
r = asprintf(&fdstr, "%d", pair[1]);
c_assert(r >= 0);

r = execl("./src/dbus-broker",
"./src/dbus-broker",
bin = getenv("TEST_DBUS_BROKER") ?: "/usr/bin/dbus-broker";
fprintf(stderr, "Using dbus-broker binary %s\n", bin);
r = execl(bin,
bin,
"--controller", fdstr,
"--machine-id", "0123456789abcdef0123456789abcdef",
"--max-matches", "1000000",
Expand Down Expand Up @@ -318,7 +321,8 @@ void util_fork_daemon(sd_event *event, int pipe_fd, pid_t *pidp) {
c_assert(r >= 0);

/* exec dbus-daemon */
bin = getenv("DBUS_BROKER_TEST_DAEMON") ?: "/usr/bin/dbus-daemon";
bin = getenv("TEST_DBUS_DAEMON") ?: "/usr/bin/dbus-daemon";
fprintf(stderr, "Using dbus-daemon binary %s\n", bin);
r = execl(bin,
bin,
path,
Expand Down Expand Up @@ -450,7 +454,7 @@ void util_broker_spawn(Broker *broker) {
r = pipe2(broker->pipe_fds, O_CLOEXEC | O_DIRECT);
c_assert(r >= 0);

if (getenv("DBUS_BROKER_TEST_DAEMON")) {
if (getenv("TEST_DBUS_DAEMON")) {
/*
* Our pipe is passed to a forked dbus-daemon(1). It will
* write its picked address to the pipe, which we then remember
Expand Down

0 comments on commit 45fd9a3

Please sign in to comment.