summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/journal/test-compress-benchmark.c3
-rw-r--r--src/journal/test-journal-interleaving.c10
-rw-r--r--src/journal/test-journal-stream.c7
-rw-r--r--src/journal/test-journal-verify.c7
-rw-r--r--src/journal/test-journal.c7
-rw-r--r--src/libsystemd-network/test-dhcp-server.c7
-rw-r--r--src/libsystemd/sd-bus/test-bus-chat.c7
-rw-r--r--src/libsystemd/sd-bus/test-bus-cleanup.c11
-rw-r--r--src/libsystemd/sd-bus/test-bus-creds.c7
-rw-r--r--src/libsystemd/sd-bus/test-bus-marshal.c7
-rw-r--r--src/libsystemd/sd-bus/test-bus-match.c7
-rw-r--r--src/libsystemd/sd-bus/test-bus-track.c7
-rw-r--r--src/network/test-network.c8
-rw-r--r--src/shared/tests.c7
-rw-r--r--src/shared/tests.h1
-rw-r--r--src/test/test-architecture.c7
-rw-r--r--src/test/test-barrier.c7
-rw-r--r--src/test/test-boot-timestamps.c9
-rw-r--r--src/test/test-bpf.c24
-rw-r--r--src/test/test-capability.c15
-rw-r--r--src/test/test-cgroup-mask.c15
-rw-r--r--src/test/test-engine.c6
-rw-r--r--src/test/test-execute.c12
-rw-r--r--src/test/test-hash.c7
-rw-r--r--src/test/test-ipcrm.c9
-rw-r--r--src/test/test-namespace.c14
-rw-r--r--src/test/test-netlink-manual.c7
-rw-r--r--src/test/test-path.c12
-rw-r--r--src/test/test-sched-prio.c6
-rw-r--r--src/test/test-sigbus.c21
-rw-r--r--src/test/test-sleep.c7
-rw-r--r--src/test/test-unit-file.c6
-rw-r--r--src/test/test-unit-name.c6
-rw-r--r--src/test/test-watch-pid.c13
34 files changed, 128 insertions, 178 deletions
diff --git a/src/journal/test-compress-benchmark.c b/src/journal/test-compress-benchmark.c
index 8701fe7954..0633fe6ea4 100644
--- a/src/journal/test-compress-benchmark.c
+++ b/src/journal/test-compress-benchmark.c
@@ -173,7 +173,6 @@ int main(int argc, char *argv[]) {
}
return 0;
#else
- log_info("No compression feature is enabled, skipping tests.");
- return EXIT_TEST_SKIP;
+ return log_tests_skipped("No compression feature is enabled");
#endif
}
diff --git a/src/journal/test-journal-interleaving.c b/src/journal/test-journal-interleaving.c
index a227dec646..82da68e0ea 100644
--- a/src/journal/test-journal-interleaving.c
+++ b/src/journal/test-journal-interleaving.c
@@ -15,9 +15,9 @@
#include "parse-util.h"
#include "rm-rf.h"
#include "util.h"
+#include "tests.h"
-/* This program tests skipping around in a multi-file journal.
- */
+/* This program tests skipping around in a multi-file journal. */
static bool arg_keep = false;
@@ -277,10 +277,8 @@ int main(int argc, char *argv[]) {
log_set_max_level(LOG_DEBUG);
/* journal_file_open requires a valid machine id */
- if (access("/etc/machine-id", F_OK) != 0) {
- log_info("/etc/machine-id not found, skipping tests.");
- return EXIT_TEST_SKIP;
- }
+ if (access("/etc/machine-id", F_OK) != 0)
+ return log_tests_skipped("/etc/machine-id not found");
arg_keep = argc > 1;
diff --git a/src/journal/test-journal-stream.c b/src/journal/test-journal-stream.c
index 9fe3208100..d7fdf907c8 100644
--- a/src/journal/test-journal-stream.c
+++ b/src/journal/test-journal-stream.c
@@ -12,6 +12,7 @@
#include "macro.h"
#include "parse-util.h"
#include "rm-rf.h"
+#include "tests.h"
#include "util.h"
#define N_ENTRIES 200
@@ -67,10 +68,8 @@ int main(int argc, char *argv[]) {
dual_timestamp previous_ts = DUAL_TIMESTAMP_NULL;
/* journal_file_open requires a valid machine id */
- if (access("/etc/machine-id", F_OK) != 0) {
- log_info("/etc/machine-id not found, skipping tests.");
- return EXIT_TEST_SKIP;
- }
+ if (access("/etc/machine-id", F_OK) != 0)
+ return log_tests_skipped("/etc/machine-id not found");
log_set_max_level(LOG_DEBUG);
diff --git a/src/journal/test-journal-verify.c b/src/journal/test-journal-verify.c
index ba962cd42e..c2a21cef9c 100644
--- a/src/journal/test-journal-verify.c
+++ b/src/journal/test-journal-verify.c
@@ -10,6 +10,7 @@
#include "log.h"
#include "rm-rf.h"
#include "terminal-util.h"
+#include "tests.h"
#include "util.h"
#define N_ENTRIES 6000
@@ -61,10 +62,8 @@ int main(int argc, char *argv[]) {
uint64_t p;
/* journal_file_open requires a valid machine id */
- if (access("/etc/machine-id", F_OK) != 0) {
- log_info("/etc/machine-id not found, skipping tests.");
- return EXIT_TEST_SKIP;
- }
+ if (access("/etc/machine-id", F_OK) != 0)
+ return log_tests_skipped("/etc/machine-id not found");
log_set_max_level(LOG_DEBUG);
diff --git a/src/journal/test-journal.c b/src/journal/test-journal.c
index 3cdaad4b40..7e188420db 100644
--- a/src/journal/test-journal.c
+++ b/src/journal/test-journal.c
@@ -8,6 +8,7 @@
#include "journal-vacuum.h"
#include "log.h"
#include "rm-rf.h"
+#include "tests.h"
static bool arg_keep = false;
@@ -239,10 +240,8 @@ int main(int argc, char *argv[]) {
arg_keep = argc > 1;
/* journal_file_open requires a valid machine id */
- if (access("/etc/machine-id", F_OK) != 0) {
- log_info("/etc/machine-id not found, skipping tests.");
- return EXIT_TEST_SKIP;
- }
+ if (access("/etc/machine-id", F_OK) != 0)
+ return log_tests_skipped("/etc/machine-id not found");
test_non_empty();
test_empty();
diff --git a/src/libsystemd-network/test-dhcp-server.c b/src/libsystemd-network/test-dhcp-server.c
index 3de25b02c2..2854e04abc 100644
--- a/src/libsystemd-network/test-dhcp-server.c
+++ b/src/libsystemd-network/test-dhcp-server.c
@@ -9,6 +9,7 @@
#include "sd-event.h"
#include "dhcp-server-internal.h"
+#include "tests.h"
static void test_pool(struct in_addr *address, unsigned size, int ret) {
_cleanup_(sd_dhcp_server_unrefp) sd_dhcp_server *server = NULL;
@@ -235,10 +236,8 @@ int main(int argc, char *argv[]) {
assert_se(sd_event_new(&e) >= 0);
r = test_basic(e);
- if (r != 0) {
- log_notice("%s: skipping tests.", program_invocation_short_name);
- return EXIT_TEST_SKIP;
- }
+ if (r != 0)
+ return log_tests_skipped("cannot start dhcp server");
test_message_handler();
test_client_id_hash();
diff --git a/src/libsystemd/sd-bus/test-bus-chat.c b/src/libsystemd/sd-bus/test-bus-chat.c
index f3ff856e42..28922e6a69 100644
--- a/src/libsystemd/sd-bus/test-bus-chat.c
+++ b/src/libsystemd/sd-bus/test-bus-chat.c
@@ -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...");
diff --git a/src/libsystemd/sd-bus/test-bus-cleanup.c b/src/libsystemd/sd-bus/test-bus-cleanup.c
index d1d962ebb2..a70f4823db 100644
--- a/src/libsystemd/sd-bus/test-bus-cleanup.c
+++ b/src/libsystemd/sd-bus/test-bus-cleanup.c
@@ -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();
diff --git a/src/libsystemd/sd-bus/test-bus-creds.c b/src/libsystemd/sd-bus/test-bus-creds.c
index 69f1f3e345..a99fbc3bc5 100644
--- a/src/libsystemd/sd-bus/test-bus-creds.c
+++ b/src/libsystemd/sd-bus/test-bus-creds.c
@@ -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");
diff --git a/src/libsystemd/sd-bus/test-bus-marshal.c b/src/libsystemd/sd-bus/test-bus-marshal.c
index 47a24bd8ef..22c48e38dc 100644
--- a/src/libsystemd/sd-bus/test-bus-marshal.c
+++ b/src/libsystemd/sd-bus/test-bus-marshal.c
@@ -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);
diff --git a/src/libsystemd/sd-bus/test-bus-match.c b/src/libsystemd/sd-bus/test-bus-match.c
index 05b84d51c3..527911c5af 100644
--- a/src/libsystemd/sd-bus/test-bus-match.c
+++ b/src/libsystemd/sd-bus/test-bus-match.c
@@ -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);
diff --git a/src/libsystemd/sd-bus/test-bus-track.c b/src/libsystemd/sd-bus/test-bus-track.c
index b75703f14f..8a3dcf1654 100644
--- a/src/libsystemd/sd-bus/test-bus-track.c
+++ b/src/libsystemd/sd-bus/test-bus-track.c
@@ -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);
diff --git a/src/network/test-network.c b/src/network/test-network.c
index a04257d3fd..e8c10bc15c 100644
--- a/src/network/test-network.c
+++ b/src/network/test-network.c
@@ -10,6 +10,7 @@
#include "network-internal.h"
#include "networkd-manager.h"
#include "string-util.h"
+#include "tests.h"
static void test_deserialize_in_addr(void) {
_cleanup_free_ struct in_addr *addresses = NULL;
@@ -231,10 +232,9 @@ int main(void) {
assert_se(manager_new(&manager) >= 0);
r = test_load_config(manager);
- if (r == -EPERM) {
- log_info_errno(r, "Skipping tests: %m");
- return EXIT_TEST_SKIP;
- }
+ if (r == -EPERM)
+ return log_tests_skipped("Cannot load configuration");
+ assert_se(r == 0);
assert_se(sd_device_new_from_syspath(&loopback, "/sys/class/net/lo") >= 0);
assert_se(loopback);
diff --git a/src/shared/tests.c b/src/shared/tests.c
index cb5b7b6dea..884f34bc72 100644
--- a/src/shared/tests.c
+++ b/src/shared/tests.c
@@ -9,6 +9,7 @@
#include "alloc-util.h"
#include "env-util.h"
#include "fileio.h"
+#include "log.h"
#include "path-util.h"
#include "strv.h"
#include "tests.h"
@@ -89,3 +90,9 @@ bool slow_tests_enabled(void) {
log_warning_errno(r, "Cannot parse $SYSTEMD_SLOW_TESTS, ignoring.");
return SYSTEMD_SLOW_TESTS_DEFAULT;
}
+
+int log_tests_skipped(const char *message) {
+ log_notice("%s: %s, skipping tests.",
+ program_invocation_short_name, message);
+ return EXIT_TEST_SKIP;
+}
diff --git a/src/shared/tests.h b/src/shared/tests.h
index 44b52f5589..67d5e1ce4a 100644
--- a/src/shared/tests.h
+++ b/src/shared/tests.h
@@ -5,3 +5,4 @@ char* setup_fake_runtime_dir(void);
const char* get_testdata_dir(void);
const char* get_catalog_dir(void);
bool slow_tests_enabled(void);
+int log_tests_skipped(const char *message);
diff --git a/src/test/test-architecture.c b/src/test/test-architecture.c
index 81b1e276fc..6cd64b60b2 100644
--- a/src/test/test-architecture.c
+++ b/src/test/test-architecture.c
@@ -2,6 +2,7 @@
#include "architecture.h"
#include "log.h"
+#include "tests.h"
#include "util.h"
#include "virt.h"
@@ -17,10 +18,8 @@ int main(int argc, char *argv[]) {
assert_se(architecture_from_string(architecture_to_string(1)) == 1);
v = detect_virtualization();
- if (IN_SET(v, -EPERM, -EACCES)) {
- log_info_errno(v, "Skipping tests: %m");
- return EXIT_TEST_SKIP;
- }
+ if (IN_SET(v, -EPERM, -EACCES))
+ return log_tests_skipped("Cannot detect virtualization");
assert_se(v >= 0);
diff --git a/src/test/test-barrier.c b/src/test/test-barrier.c
index c59fe03e92..2a735695a1 100644
--- a/src/test/test-barrier.c
+++ b/src/test/test-barrier.c
@@ -424,11 +424,8 @@ int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
- if (!slow_tests_enabled()) {
- log_notice("%s: slow tests are disabled, exiting.",
- program_invocation_short_name);
- return EXIT_TEST_SKIP;
- }
+ if (!slow_tests_enabled())
+ return log_tests_skipped("slow tests are disabled");
test_barrier_sync();
test_barrier_wait_next();
diff --git a/src/test/test-boot-timestamps.c b/src/test/test-boot-timestamps.c
index e7deee5d5f..578aa5b304 100644
--- a/src/test/test-boot-timestamps.c
+++ b/src/test/test-boot-timestamps.c
@@ -4,6 +4,7 @@
#include "boot-timestamps.h"
#include "efivars.h"
#include "log.h"
+#include "tests.h"
#include "util.h"
static int test_acpi_fpdt(void) {
@@ -91,10 +92,8 @@ int main(int argc, char* argv[]) {
r = test_boot_timestamps();
assert(r >= 0);
- bool any = p > 0 || q > 0 || r > 0;
- if (!any)
- log_notice("%s: access to firmware variable not possible, skipping tests.",
- program_invocation_short_name);
+ if (p == 0 && q == 0 && r == 0)
+ return log_tests_skipped("access to firmware variables not possible");
- return any ? EXIT_SUCCESS : EXIT_TEST_SKIP;
+ return EXIT_SUCCESS;
}
diff --git a/src/test/test-bpf.c b/src/test/test-bpf.c
index a4975bf13a..a055fea802 100644
--- a/src/test/test-bpf.c
+++ b/src/test/test-bpf.c
@@ -33,10 +33,8 @@ int main(int argc, char *argv[]) {
log_open();
r = enter_cgroup_subroot();
- if (r == -ENOMEDIUM) {
- log_notice("cgroupfs not available, skipping tests");
- return EXIT_TEST_SKIP;
- }
+ if (r == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
assert_se(set_unit_path(get_testdata_dir()) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
@@ -47,16 +45,12 @@ int main(int argc, char *argv[]) {
r = bpf_program_add_instructions(p, exit_insn, ELEMENTSOF(exit_insn));
assert(r == 0);
- if (getuid() != 0) {
- log_notice("Not running as root, skipping kernel related tests.");
- return EXIT_TEST_SKIP;
- }
+ if (getuid() != 0)
+ return log_tests_skipped("not running as root");
r = bpf_firewall_supported();
- if (r == BPF_FIREWALL_UNSUPPORTED) {
- log_notice("BPF firewalling not supported, skipping");
- return EXIT_TEST_SKIP;
- }
+ if (r == BPF_FIREWALL_UNSUPPORTED)
+ return log_tests_skipped("BPF firewalling not supported");
assert_se(r > 0);
if (r == BPF_FIREWALL_SUPPORTED_WITH_MULTI)
@@ -110,10 +104,8 @@ int main(int argc, char *argv[]) {
unit_dump(u, stdout, NULL);
r = bpf_firewall_compile(u);
- if (IN_SET(r, -ENOTTY, -ENOSYS, -EPERM)) {
- log_info_errno(r, "Kernel doesn't support the necessary bpf bits, or masked out via seccomp? Skipping tests: %m");
- return EXIT_TEST_SKIP;
- }
+ if (IN_SET(r, -ENOTTY, -ENOSYS, -EPERM))
+ return log_tests_skipped("Kernel doesn't support the necessary bpf bits (masked out via seccomp?)");
assert_se(r >= 0);
assert(u->ip_bpf_ingress);
diff --git a/src/test/test-capability.c b/src/test/test-capability.c
index 5e2d21bee9..79ddca9554 100644
--- a/src/test/test-capability.c
+++ b/src/test/test-capability.c
@@ -14,6 +14,7 @@
#include "fileio.h"
#include "macro.h"
#include "parse-util.h"
+#include "tests.h"
#include "util.h"
static uid_t test_uid = -1;
@@ -217,7 +218,6 @@ static void test_set_ambient_caps(void) {
}
int main(int argc, char *argv[]) {
- int r;
bool run_ambient;
test_last_cap_file();
@@ -228,16 +228,11 @@ int main(int argc, char *argv[]) {
log_info("have ambient caps: %s", yes_no(ambient_capabilities_supported()));
- if (getuid() != 0) {
- log_notice("%s: not root, skipping tests.", program_invocation_short_name);
- return EXIT_TEST_SKIP;
- }
+ if (getuid() != 0)
+ return log_tests_skipped("not running as root");
- r = setup_tests(&run_ambient);
- if (r < 0) {
- log_notice("%s: skipping tests.", program_invocation_short_name);
- return EXIT_TEST_SKIP;
- }
+ if (setup_tests(&run_ambient) < 0)
+ return log_tests_skipped("setup failed");
show_capabilities();
diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c
index 8dc1639720..0dd673e3e5 100644
--- a/src/test/test-cgroup-mask.c
+++ b/src/test/test-cgroup-mask.c
@@ -17,19 +17,18 @@ static int test_cgroup_mask(void) {
int r;
r = enter_cgroup_subroot();
- if (r == -ENOMEDIUM) {
- puts("Skipping test: cgroupfs not available");
- return EXIT_TEST_SKIP;
- }
+ if (r == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
/* Prepare the manager. */
assert_se(set_unit_path(get_testdata_dir()) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (IN_SET(r, -EPERM, -EACCES)) {
- puts("manager_new: Permission denied. Skipping test.");
- return EXIT_TEST_SKIP;
+ log_error_errno(r, "manager_new: %m");
+ return log_tests_skipped("cannot create manager");
}
+
assert_se(r >= 0);
/* Turn off all kinds of default accouning, so that we can
@@ -117,13 +116,13 @@ static void test_cg_mask_to_string(void) {
}
int main(int argc, char* argv[]) {
- int rc = 0;
+ int rc = EXIT_SUCCESS;
log_parse_environment();
log_open();
- TEST_REQ_RUNNING_SYSTEMD(rc = test_cgroup_mask());
test_cg_mask_to_string();
+ TEST_REQ_RUNNING_SYSTEMD(rc = test_cgroup_mask());
return rc;
}
diff --git a/src/test/test-engine.c b/src/test/test-engine.c
index 0f3e244dc1..f7435bd4fb 100644
--- a/src/test/test-engine.c
+++ b/src/test/test-engine.c
@@ -23,10 +23,8 @@ int main(int argc, char *argv[]) {
log_open();
r = enter_cgroup_subroot();
- if (r == -ENOMEDIUM) {
- log_notice_errno(r, "Skipping test: cgroupfs not available");
- return EXIT_TEST_SKIP;
- }
+ if (r == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
/* prepare the test */
assert_se(set_unit_path(get_testdata_dir()) >= 0);
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
index b37e601753..0d2f35734e 100644
--- a/src/test/test-execute.c
+++ b/src/test/test-execute.c
@@ -733,16 +733,12 @@ int main(int argc, char *argv[]) {
(void) unsetenv("SHELL");
/* It is needed otherwise cgroup creation fails */
- if (getuid() != 0) {
- puts("Skipping test: not root");
- return EXIT_TEST_SKIP;
- }
+ if (getuid() != 0)
+ return log_tests_skipped("not root");
r = enter_cgroup_subroot();
- if (r == -ENOMEDIUM) {
- puts("Skipping test: cgroupfs not available");
- return EXIT_TEST_SKIP;
- }
+ if (r == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
assert_se(runtime_dir = setup_fake_runtime_dir());
test_execute_path = path_join(NULL, get_testdata_dir(), "test-execute");
diff --git a/src/test/test-hash.c b/src/test/test-hash.c
index f5bc131846..ea56b74d0f 100644
--- a/src/test/test-hash.c
+++ b/src/test/test-hash.c
@@ -7,6 +7,7 @@
#include "log.h"
#include "string-util.h"
#include "khash.h"
+#include "tests.h"
int main(int argc, char *argv[]) {
_cleanup_(khash_unrefp) khash *h = NULL, *copy = NULL;
@@ -20,10 +21,8 @@ int main(int argc, char *argv[]) {
r = khash_supported();
assert_se(r >= 0);
- if (r == 0) {
- puts("khash not supported on this kernel, skipping");
- return EXIT_TEST_SKIP;
- }
+ if (r == 0)
+ return log_tests_skipped("khash not supported on this kernel");
assert_se(khash_new(&h, "foobar") == -EOPNOTSUPP); /* undefined hash function */
diff --git a/src/test/test-ipcrm.c b/src/test/test-ipcrm.c
index a57173144b..1f6d7b4351 100644
--- a/src/test/test-ipcrm.c
+++ b/src/test/test-ipcrm.c
@@ -2,6 +2,7 @@
#include "clean-ipc.h"
#include "user-util.h"
+#include "tests.h"
#include "util.h"
int main(int argc, char *argv[]) {
@@ -10,11 +11,11 @@ int main(int argc, char *argv[]) {
const char* name = argv[1] ?: NOBODY_USER_NAME;
r = get_user_creds(&name, &uid, NULL, NULL, NULL, 0);
+ if (r == -ESRCH)
+ return log_tests_skipped("Failed to resolve user");
if (r < 0) {
- log_full_errno(r == -ESRCH ? LOG_NOTICE : LOG_ERR,
- r, "Failed to resolve \"%s\"%s: %m", name,
- r == -ESRCH ? ", skipping tests" : "");
- return r == -ESRCH ? EXIT_TEST_SKIP : EXIT_FAILURE;
+ log_error_errno(r, "Failed to resolve \"%s\": %m", name);
+ return EXIT_FAILURE;
}
r = clean_ipc_by_uid(uid);
diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c
index b202739719..318bd5bad4 100644
--- a/src/test/test-namespace.c
+++ b/src/test/test-namespace.c
@@ -7,6 +7,7 @@
#include "namespace.h"
#include "process-util.h"
#include "string-util.h"
+#include "tests.h"
#include "util.h"
static void test_tmpdir(const char *id, const char *A, const char *B) {
@@ -46,16 +47,14 @@ static void test_tmpdir(const char *id, const char *A, const char *B) {
assert_se(rmdir(b) >= 0);
}
-static void test_netns(void) {
+static int test_netns(void) {
_cleanup_close_pair_ int s[2] = { -1, -1 };
pid_t pid1, pid2, pid3;
int r, n = 0;
siginfo_t si;
- if (geteuid() > 0) {
- log_info("Skipping test: not root");
- exit(EXIT_TEST_SKIP);
- }
+ if (geteuid() > 0)
+ return log_tests_skipped("not root");
assert_se(socketpair(AF_UNIX, SOCK_DGRAM, 0, s) >= 0);
@@ -102,6 +101,7 @@ static void test_netns(void) {
n += si.si_status;
assert_se(n == 1);
+ return EXIT_SUCCESS;
}
int main(int argc, char *argv[]) {
@@ -128,7 +128,5 @@ int main(int argc, char *argv[]) {
test_tmpdir("sys-devices-pci0000:00-0000:00:1a.0-usb3-3\\x2d1-3\\x2d1:1.0-bluetooth-hci0.device", z, zz);
- test_netns();
-
- return 0;
+ return test_netns();
}
diff --git a/src/test/test-netlink-manual.c b/src/test/test-netlink-manual.c
index e887a9a780..39826dfdb9 100644
--- a/src/test/test-netlink-manual.c
+++ b/src/test/test-netlink-manual.c
@@ -10,6 +10,7 @@
#include "macro.h"
#include "module-util.h"
+#include "tests.h"
#include "util.h"
static int load_module(const char *mod_name) {
@@ -57,10 +58,8 @@ static int test_tunnel_configure(sd_netlink *rtnl) {
return EXIT_TEST_SKIP;
}
- if (getuid() != 0) {
- log_info("Skipping tests: not root");
- return EXIT_TEST_SKIP;
- }
+ if (getuid() != 0)
+ return log_tests_skipped("not root");
/* IPIP tunnel */
assert_se(sd_rtnl_message_new_link(rtnl, &m, RTM_NEWLINK, 0) >= 0);
diff --git a/src/test/test-path.c b/src/test/test-path.c
index 5e78a560ff..7e664ec849 100644
--- a/src/test/test-path.c
+++ b/src/test/test-path.c
@@ -33,15 +33,13 @@ static int setup_test(Manager **m) {
assert_se(m);
r = enter_cgroup_subroot();
- if (r == -ENOMEDIUM) {
- log_notice_errno(r, "Skipping test: cgroupfs not available");
- return -EXIT_TEST_SKIP;
- }
+ if (r == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &tmp);
if (MANAGER_SKIP_TEST(r)) {
log_notice_errno(r, "Skipping test: manager_new: %m");
- return -EXIT_TEST_SKIP;
+ return EXIT_TEST_SKIP;
}
assert_se(r >= 0);
assert_se(manager_startup(tmp, NULL, NULL) >= 0);
@@ -266,8 +264,8 @@ int main(int argc, char *argv[]) {
/* We create a clean environment for each test */
r = setup_test(&m);
- if (r < 0)
- return -r;
+ if (r != 0)
+ return r;
(*test)(m);
diff --git a/src/test/test-sched-prio.c b/src/test/test-sched-prio.c
index 60012e47d2..c594336325 100644
--- a/src/test/test-sched-prio.c
+++ b/src/test/test-sched-prio.c
@@ -20,10 +20,8 @@ int main(int argc, char *argv[]) {
int r;
r = enter_cgroup_subroot();
- if (r == -ENOMEDIUM) {
- log_notice_errno(r, "Skipping test: cgroupfs not available");
- return EXIT_TEST_SKIP;
- }
+ if (r == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
/* prepare the test */
assert_se(set_unit_path(get_testdata_dir()) >= 0);
diff --git a/src/test/test-sigbus.c b/src/test/test-sigbus.c
index 999dbe6be4..518e48e1ec 100644
--- a/src/test/test-sigbus.c
+++ b/src/test/test-sigbus.c
@@ -2,12 +2,14 @@
#include <sys/mman.h>
+#if HAVE_VALGRIND_VALGRIND_H
+# include <valgrind/valgrind.h>
+#endif
+
#include "fd-util.h"
#include "sigbus.h"
+#include "tests.h"
#include "util.h"
-#if HAVE_VALGRIND_VALGRIND_H
-#include <valgrind/valgrind.h>
-#endif
int main(int argc, char *argv[]) {
_cleanup_close_ int fd = -1;
@@ -15,17 +17,14 @@ int main(int argc, char *argv[]) {
void *addr = NULL;
uint8_t *p;
+#ifdef __SANITIZE_ADDRESS__
+ return log_tests_skipped("address-sanitizer is enabled");
+#endif
#if HAVE_VALGRIND_VALGRIND_H
- if (RUNNING_ON_VALGRIND) {
- puts("This test cannot run on valgrind, skipping tests.");
- return EXIT_TEST_SKIP;
- }
+ if (RUNNING_ON_VALGRIND)
+ return log_tests_skipped("This test cannot run on valgrind");
#endif
-#ifdef __SANITIZE_ADDRESS__
- puts("Address sanitization is enabled, skipping tests.");
- return EXIT_TEST_SKIP;
-#endif
sigbus_install();
assert_se(sigbus_pop(&addr) == 0);
diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c
index a8ad302f71..0198d34f19 100644
--- a/src/test/test-sleep.c
+++ b/src/test/test-sleep.c
@@ -8,6 +8,7 @@
#include "log.h"
#include "sleep-config.h"
#include "strv.h"
+#include "tests.h"
#include "util.h"
static void test_parse_sleep_config(void) {
@@ -26,10 +27,8 @@ static int test_fiemap(const char *path) {
if (fd < 0)
return log_error_errno(errno, "failed to open %s: %m", path);
r = read_fiemap(fd, &fiemap);
- if (r == -EOPNOTSUPP) {
- log_info("Skipping test, not supported");
- exit(EXIT_TEST_SKIP);
- }
+ if (r == -EOPNOTSUPP)
+ exit(log_tests_skipped("Not supported"));
if (r < 0)
return log_error_errno(r, "Unable to read extent map for '%s': %m", path);
log_info("extent map information for %s:", path);
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
index 09b0179fa1..0b84d4c4ed 100644
--- a/src/test/test-unit-file.c
+++ b/src/test/test-unit-file.c
@@ -900,10 +900,8 @@ int main(int argc, char *argv[]) {
log_open();
r = enter_cgroup_subroot();
- if (r == -ENOMEDIUM) {
- log_notice_errno(r, "Skipping test: cgroupfs not available");
- return EXIT_TEST_SKIP;
- }
+ if (r == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
assert_se(runtime_dir = setup_fake_runtime_dir());
diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
index 2b00ef8cb7..7fd3f82d4d 100644
--- a/src/test/test-unit-name.c
+++ b/src/test/test-unit-name.c
@@ -815,10 +815,8 @@ int main(int argc, char* argv[]) {
log_open();
r = enter_cgroup_subroot();
- if (r == -ENOMEDIUM) {
- log_notice_errno(r, "Skipping test: cgroupfs not available");
- return EXIT_TEST_SKIP;
- }
+ if (r == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
assert_se(runtime_dir = setup_fake_runtime_dir());
diff --git a/src/test/test-watch-pid.c b/src/test/test-watch-pid.c
index 4e349ab927..615ded186b 100644
--- a/src/test/test-watch-pid.c
+++ b/src/test/test-watch-pid.c
@@ -17,16 +17,11 @@ int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
- if (getuid() != 0) {
- log_notice("Not running as root, skipping kernel related tests.");
- return EXIT_TEST_SKIP;
- }
-
+ if (getuid() != 0)
+ return log_tests_skipped("not root");
r = enter_cgroup_subroot();
- if (r == -ENOMEDIUM) {
- log_notice("cgroupfs not available, skipping tests");
- return EXIT_TEST_SKIP;
- }
+ if (r == -ENOMEDIUM)
+ return log_tests_skipped("cgroupfs not available");
assert_se(set_unit_path(get_testdata_dir()) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());