mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-28 17:57:25 +03:00
sd-bus: add new test for NameAcquired via proxy/dbus-daemon
This adds test-bus-proxy which should be used to test correct behavior of systemd-bus-proxyd. The first test that was added is to verify we actually receive NameAcquired signals for ourselves on bus-connect.
This commit is contained in:
parent
2ec7c4279e
commit
9afd2b46f2
1
.gitignore
vendored
1
.gitignore
vendored
@ -159,6 +159,7 @@
|
||||
/test-bus-match
|
||||
/test-bus-objects
|
||||
/test-bus-policy
|
||||
/test-bus-proxy
|
||||
/test-bus-server
|
||||
/test-bus-signature
|
||||
/test-bus-zero-copy
|
||||
|
@ -2996,6 +2996,7 @@ tests += \
|
||||
test-bus-cleanup \
|
||||
test-bus-server \
|
||||
test-bus-match \
|
||||
test-bus-proxy \
|
||||
test-bus-kernel \
|
||||
test-bus-kernel-bloom \
|
||||
test-bus-zero-copy \
|
||||
@ -3088,6 +3089,12 @@ test_bus_match_SOURCES = \
|
||||
test_bus_match_LDADD = \
|
||||
libshared.la
|
||||
|
||||
test_bus_proxy_SOURCES = \
|
||||
src/libsystemd/sd-bus/test-bus-proxy.c
|
||||
|
||||
test_bus_proxy_LDADD = \
|
||||
libshared.la
|
||||
|
||||
test_bus_kernel_SOURCES = \
|
||||
src/libsystemd/sd-bus/test-bus-kernel.c
|
||||
|
||||
|
109
src/libsystemd/sd-bus/test-bus-proxy.c
Normal file
109
src/libsystemd/sd-bus/test-bus-proxy.c
Normal file
@ -0,0 +1,109 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2015 David Herrmann <dh.herrmann@gmail.com>
|
||||
|
||||
systemd is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
systemd 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "bus-kernel.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-dump.h"
|
||||
|
||||
typedef struct {
|
||||
const char *sender;
|
||||
int matched_acquired;
|
||||
} TestProxyMatch;
|
||||
|
||||
static int test_proxy_acquired(sd_bus_message *m, void *userdata, sd_bus_error *error) {
|
||||
TestProxyMatch *match = userdata;
|
||||
const char *name;
|
||||
int r;
|
||||
|
||||
r = sd_bus_message_read(m, "s", &name);
|
||||
assert_se(r >= 0);
|
||||
|
||||
if (!streq_ptr(match->sender, name))
|
||||
return 0;
|
||||
|
||||
++match->matched_acquired;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void test_proxy_matched(void) {
|
||||
_cleanup_bus_flush_close_unref_ sd_bus *a = NULL;
|
||||
TestProxyMatch match = {};
|
||||
int r;
|
||||
|
||||
/* open bus 'a' */
|
||||
|
||||
r = sd_bus_new(&a);
|
||||
assert_se(r >= 0);
|
||||
|
||||
r = sd_bus_set_address(a, "unix:path=/var/run/dbus/system_bus_socket");
|
||||
assert_se(r >= 0);
|
||||
|
||||
r = sd_bus_set_bus_client(a, true);
|
||||
assert_se(r >= 0);
|
||||
|
||||
r = sd_bus_start(a);
|
||||
assert_se(r >= 0);
|
||||
|
||||
r = sd_bus_add_match(a, NULL,
|
||||
"type='signal',"
|
||||
"member='NameAcquired'",
|
||||
test_proxy_acquired, &match);
|
||||
assert_se(r >= 0);
|
||||
|
||||
r = sd_bus_get_unique_name(a, &match.sender);
|
||||
assert_se(r >= 0);
|
||||
|
||||
/* barrier to guarantee proxy/dbus-daemon handled the previous data */
|
||||
r = sd_bus_call_method(a,
|
||||
"org.freedesktop.DBus",
|
||||
"/org/freedesktop/DBus",
|
||||
"org.freedesktop.DBus",
|
||||
"GetId",
|
||||
NULL, NULL, NULL);
|
||||
assert_se(r >= 0);
|
||||
|
||||
/* now we can be sure the Name* signals were sent */
|
||||
do {
|
||||
r = sd_bus_process(a, NULL);
|
||||
} while (r > 0);
|
||||
assert_se(r == 0);
|
||||
|
||||
assert_se(match.matched_acquired == 1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (access("/var/run/dbus/system_bus_socket", F_OK) < 0)
|
||||
return EXIT_TEST_SKIP;
|
||||
|
||||
log_parse_environment();
|
||||
|
||||
test_proxy_matched();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user