tests: add helper to unify skipping a test and exiting
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "format-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
static int match_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
|
||||
@@ -510,10 +511,8 @@ int main(int argc, char *argv[]) {
|
||||
int q, r;
|
||||
|
||||
r = server_init(&bus);
|
||||
if (r < 0) {
|
||||
log_info("Failed to connect to bus, skipping tests.");
|
||||
return EXIT_TEST_SKIP;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_tests_skipped("Failed to connect to bus");
|
||||
|
||||
log_info("Initialized...");
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "bus-message.h"
|
||||
#include "bus-util.h"
|
||||
#include "refcnt.h"
|
||||
#include "tests.h"
|
||||
|
||||
static void test_bus_new(void) {
|
||||
_cleanup_(sd_bus_unrefp) sd_bus *bus = NULL;
|
||||
@@ -59,17 +60,13 @@ static void test_bus_new_signal(void) {
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int r;
|
||||
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
test_bus_new();
|
||||
r = test_bus_open();
|
||||
if (r < 0) {
|
||||
log_info("Failed to connect to bus, skipping tests.");
|
||||
return EXIT_TEST_SKIP;
|
||||
}
|
||||
|
||||
if (test_bus_open() < 0)
|
||||
return log_tests_skipped("Failed to connect to bus");
|
||||
|
||||
test_bus_new_method_call();
|
||||
test_bus_new_signal();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "bus-dump.h"
|
||||
#include "bus-util.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
|
||||
@@ -14,10 +15,8 @@ int main(int argc, char *argv[]) {
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
|
||||
if (cg_unified_flush() == -ENOMEDIUM) {
|
||||
log_info("Skipping test: /sys/fs/cgroup/ not available");
|
||||
return EXIT_TEST_SKIP;
|
||||
}
|
||||
if (cg_unified_flush() == -ENOMEDIUM)
|
||||
return log_tests_skipped("/sys/fs/cgroup/ not available");
|
||||
|
||||
r = sd_bus_creds_new_from_pid(&creds, 0, _SD_BUS_CREDS_ALL);
|
||||
log_full_errno(r < 0 ? LOG_ERR : LOG_DEBUG, r, "sd_bus_creds_new_from_pid: %m");
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "log.h"
|
||||
#include "tests.h"
|
||||
#include "util.h"
|
||||
|
||||
static void test_bus_path_encode_unique(void) {
|
||||
@@ -121,10 +122,8 @@ int main(int argc, char *argv[]) {
|
||||
uint64_t u64;
|
||||
|
||||
r = sd_bus_default_user(&bus);
|
||||
if (r < 0) {
|
||||
log_info("Failed to connect to bus, skipping tests.");
|
||||
return EXIT_TEST_SKIP;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_tests_skipped("Failed to connect to bus");
|
||||
|
||||
r = sd_bus_message_new_method_call(bus, &m, "foobar.waldo", "/", "foobar.waldo", "Piep");
|
||||
assert_se(r >= 0);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "bus-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "tests.h"
|
||||
|
||||
static bool mask[32];
|
||||
|
||||
@@ -78,10 +79,8 @@ int main(int argc, char *argv[]) {
|
||||
int r;
|
||||
|
||||
r = sd_bus_open_user(&bus);
|
||||
if (r < 0) {
|
||||
log_info("Failed to connect to bus, skipping tests.");
|
||||
return EXIT_TEST_SKIP;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_tests_skipped("Failed to connect to bus");
|
||||
|
||||
assert_se(match_add(slots, &root, "arg2='wal\\'do',sender='foo',type='signal',interface='bar.x',", 1) >= 0);
|
||||
assert_se(match_add(slots, &root, "arg2='wal\\'do2',sender='foo',type='signal',interface='bar.x',", 2) >= 0);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "sd-bus.h"
|
||||
|
||||
#include "macro.h"
|
||||
#include "tests.h"
|
||||
|
||||
static bool track_cb_called_x = false;
|
||||
static bool track_cb_called_y = false;
|
||||
@@ -51,10 +52,8 @@ int main(int argc, char *argv[]) {
|
||||
assert_se(r >= 0);
|
||||
|
||||
r = sd_bus_open_user(&a);
|
||||
if (IN_SET(r, -ECONNREFUSED, -ENOENT)) {
|
||||
log_info("Failed to connect to bus, skipping tests.");
|
||||
return EXIT_TEST_SKIP;
|
||||
}
|
||||
if (IN_SET(r, -ECONNREFUSED, -ENOENT))
|
||||
return log_tests_skipped("Failed to connect to bus");
|
||||
assert_se(r >= 0);
|
||||
|
||||
r = sd_bus_attach_event(a, event, SD_EVENT_PRIORITY_NORMAL);
|
||||
|
||||
Reference in New Issue
Block a user