mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
test: try system bus if user bus cannot be opened
This commit is contained in:
parent
3bdce0eac0
commit
f9c8c01fcc
@ -10,6 +10,8 @@
|
||||
#include "refcnt.h"
|
||||
#include "tests.h"
|
||||
|
||||
static bool use_system_bus = false;
|
||||
|
||||
static void test_bus_new(void) {
|
||||
_cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
|
||||
|
||||
@ -22,8 +24,12 @@ static int test_bus_open(void) {
|
||||
int r;
|
||||
|
||||
r = sd_bus_open_user(&bus);
|
||||
if (IN_SET(r, -ECONNREFUSED, -ENOENT))
|
||||
return r;
|
||||
if (IN_SET(r, -ECONNREFUSED, -ENOENT)) {
|
||||
r = sd_bus_open_system(&bus);
|
||||
if (IN_SET(r, -ECONNREFUSED, -ENOENT))
|
||||
return r;
|
||||
use_system_bus = true;
|
||||
}
|
||||
|
||||
assert_se(r >= 0);
|
||||
printf("after open: refcount %u\n", REFCNT_GET(bus->n_ref));
|
||||
@ -35,7 +41,7 @@ static void test_bus_new_method_call(void) {
|
||||
sd_bus *bus = NULL;
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
||||
|
||||
assert_se(sd_bus_open_user(&bus) >= 0);
|
||||
assert_se(use_system_bus ? sd_bus_open_system(&bus) >= 0 : sd_bus_open_user(&bus) >= 0);
|
||||
|
||||
assert_se(sd_bus_message_new_method_call(bus, &m, "a.service.name", "/an/object/path", "an.interface.name", "AMethodName") >= 0);
|
||||
|
||||
@ -49,7 +55,7 @@ static void test_bus_new_signal(void) {
|
||||
sd_bus *bus = NULL;
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
||||
|
||||
assert_se(sd_bus_open_user(&bus) >= 0);
|
||||
assert_se(use_system_bus ? sd_bus_open_system(&bus) >= 0 : sd_bus_open_user(&bus) >= 0);
|
||||
|
||||
assert_se(sd_bus_message_new_signal(bus, &m, "/an/object/path", "an.interface.name", "Name") >= 0);
|
||||
|
||||
|
@ -122,6 +122,8 @@ static int test_marshal(void) {
|
||||
int r;
|
||||
|
||||
r = sd_bus_open_user(&bus);
|
||||
if (r < 0)
|
||||
r = sd_bus_open_system(&bus);
|
||||
if (r < 0)
|
||||
return log_tests_skipped_errno(r, "Failed to connect to bus");
|
||||
|
||||
|
@ -124,6 +124,8 @@ int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
r = sd_bus_default_user(&bus);
|
||||
if (r < 0)
|
||||
r = sd_bus_default_system(&bus);
|
||||
if (r < 0)
|
||||
return log_tests_skipped("Failed to connect to bus");
|
||||
|
||||
|
@ -81,6 +81,8 @@ int main(int argc, char *argv[]) {
|
||||
test_setup_logging(LOG_INFO);
|
||||
|
||||
r = sd_bus_open_user(&bus);
|
||||
if (r < 0)
|
||||
r = sd_bus_open_system(&bus);
|
||||
if (r < 0)
|
||||
return log_tests_skipped("Failed to connect to bus");
|
||||
|
||||
|
@ -45,6 +45,7 @@ int main(int argc, char *argv[]) {
|
||||
_cleanup_(sd_event_unrefp) sd_event *event = NULL;
|
||||
_cleanup_(sd_bus_track_unrefp) sd_bus_track *x = NULL, *y = NULL;
|
||||
_cleanup_(sd_bus_unrefp) sd_bus *a = NULL, *b = NULL;
|
||||
bool use_system_bus = false;
|
||||
const char *unique;
|
||||
int r;
|
||||
|
||||
@ -54,14 +55,21 @@ int main(int argc, char *argv[]) {
|
||||
assert_se(r >= 0);
|
||||
|
||||
r = sd_bus_open_user(&a);
|
||||
if (IN_SET(r, -ECONNREFUSED, -ENOENT))
|
||||
return log_tests_skipped("Failed to connect to bus");
|
||||
if (IN_SET(r, -ECONNREFUSED, -ENOENT)) {
|
||||
r = sd_bus_open_system(&a);
|
||||
if (IN_SET(r, -ECONNREFUSED, -ENOENT))
|
||||
return log_tests_skipped("Failed to connect to bus");
|
||||
use_system_bus = true;
|
||||
}
|
||||
assert_se(r >= 0);
|
||||
|
||||
r = sd_bus_attach_event(a, event, SD_EVENT_PRIORITY_NORMAL);
|
||||
assert_se(r >= 0);
|
||||
|
||||
r = sd_bus_open_user(&b);
|
||||
if (use_system_bus)
|
||||
r = sd_bus_open_system(&b);
|
||||
else
|
||||
r = sd_bus_open_user(&b);
|
||||
assert_se(r >= 0);
|
||||
|
||||
r = sd_bus_attach_event(b, event, SD_EVENT_PRIORITY_NORMAL);
|
||||
|
Loading…
Reference in New Issue
Block a user