]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: add helper to unify skipping a test and exiting
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 13 Sep 2018 11:34:12 +0000 (13:34 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 14 Sep 2018 07:29:57 +0000 (09:29 +0200)
34 files changed:
src/journal/test-compress-benchmark.c
src/journal/test-journal-interleaving.c
src/journal/test-journal-stream.c
src/journal/test-journal-verify.c
src/journal/test-journal.c
src/libsystemd-network/test-dhcp-server.c
src/libsystemd/sd-bus/test-bus-chat.c
src/libsystemd/sd-bus/test-bus-cleanup.c
src/libsystemd/sd-bus/test-bus-creds.c
src/libsystemd/sd-bus/test-bus-marshal.c
src/libsystemd/sd-bus/test-bus-match.c
src/libsystemd/sd-bus/test-bus-track.c
src/network/test-network.c
src/shared/tests.c
src/shared/tests.h
src/test/test-architecture.c
src/test/test-barrier.c
src/test/test-boot-timestamps.c
src/test/test-bpf.c
src/test/test-capability.c
src/test/test-cgroup-mask.c
src/test/test-engine.c
src/test/test-execute.c
src/test/test-hash.c
src/test/test-ipcrm.c
src/test/test-namespace.c
src/test/test-netlink-manual.c
src/test/test-path.c
src/test/test-sched-prio.c
src/test/test-sigbus.c
src/test/test-sleep.c
src/test/test-unit-file.c
src/test/test-unit-name.c
src/test/test-watch-pid.c

index 8701fe7954d180c17377d1a6ee727a53ef1d4dd0..0633fe6ea44804597f0236eeb00bcdd5fab68a0d 100644 (file)
@@ -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
 }
index a227dec646564864b1b3dfe724fd01d98bc22272..82da68e0eabfad884bf6ea2080fff98eaeaaa428 100644 (file)
@@ -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;
 
index 9fe32081007623b774abf99489322a9dc43f8c72..d7fdf907c8cf47bada2699fdf87d4c0e52995a58 100644 (file)
@@ -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);
 
index ba962cd42ef52be011b3b6608e36f578d914ddb5..c2a21cef9cad19e42d2b942f88ef997fcf1da5af 100644 (file)
@@ -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);
 
index 3cdaad4b4039ce6b8ebd25a8ba879badca9a109c..7e188420db0cc54b21dab2d3bbe87da9f591a725 100644 (file)
@@ -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();
index 3de25b02c25a584e177e40f00f27c0f8d82332c2..2854e04abc2e235543bf131c8bb4f0f050aa8d49 100644 (file)
@@ -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();
index f3ff856e42c80192ca9c58b98aa3838f7b2aaadd..28922e6a699eb7ebc3fe387ef1bc27c4d2d372c7 100644 (file)
@@ -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...");
 
index d1d962ebb2d0cdcf9d7c2dafaa66f950e53f5989..a70f4823db4db95eea8de8e89601cbe83b27f51f 100644 (file)
@@ -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();
index 69f1f3e34501e078ea1deee759de4c357fe44b99..a99fbc3bc5dbf615d2507693886e16bc5736685f 100644 (file)
@@ -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");
index 47a24bd8ef48bfe7bb2f40032f381e3108d288c9..22c48e38dcb876c217166302844491e578b71697 100644 (file)
@@ -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);
index 05b84d51c3e9638e2c3e176d63ea371c05b81d0d..527911c5af8bb0b638762c56d1228d27efaf7a53 100644 (file)
@@ -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);
index b75703f14ff254f4eed214c2567198edf0052b84..8a3dcf1654abfc0dac9bef16c30754e37e7fd805 100644 (file)
@@ -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);
index a04257d3fdc35e1cc750f2422bbe9ef27fe1067c..e8c10bc15cde5a2a5ddd39031273eebc56e6892a 100644 (file)
@@ -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);
index cb5b7b6deaeb9105911ff69a30dc4c523272fea5..884f34bc72e9c165fdda179a2369b583b905bd3e 100644 (file)
@@ -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;
+}
index 44b52f5589dad4eb8607fbe0c2bd2c6dfdafbcd4..67d5e1ce4a08dcc88f9081acaec47b6240c932fd 100644 (file)
@@ -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);
index 81b1e276fc1c56a3bf03bb5d3a79d984745715c3..6cd64b60b2bcc1f8d8cbafd7bd36429d477cb88f 100644 (file)
@@ -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);
 
index c59fe03e92af3a490c01fe9922cca58b6421bf14..2a735695a1ba95ecfd4a4379359105ea05186e85 100644 (file)
@@ -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();
index e7deee5d5fafbd466e7d3a497381e37ff55e260b..578aa5b30480aede1f04c392c80e5108c079e3ac 100644 (file)
@@ -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;
 }
index a4975bf13a42e969631b5c7635fac4b25dc3490a..a055fea8024b211098b3804190a2e9cc8b3c834d 100644 (file)
@@ -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);
index 5e2d21bee9c441d520d20f644d97ae9bd5b14c47..79ddca955419c5618739e49dde7e15795e3511fd 100644 (file)
@@ -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();
 
index 8dc1639720c26468470b51c3d4e7699699bfdd08..0dd673e3e57fc826a71dfc3d0ca51213657aaf59 100644 (file)
@@ -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;
 }
index 0f3e244dc1c7bdbd58b612676b83184c504298de..f7435bd4fbc247d514a97b33216fa6320b3f1005 100644 (file)
@@ -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);
index b37e6017538e3d46c01de546c1fcc43a7812d160..0d2f35734e31e0ed7c17201e60e6519cb835066e 100644 (file)
@@ -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");
index f5bc131846e0e1e6e3815060d8f984962650a8b1..ea56b74d0f77226f6090c31d14b2029242dccb5b 100644 (file)
@@ -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 */
 
index a57173144baab576ff1d1520bb268685c2c1c59b..1f6d7b4351dc93a691ec8cecc3fb60fc9aefcedd 100644 (file)
@@ -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);
index b202739719c58b4a4e686d667a6d936584ed666f..318bd5bad4deb2a7dc8e317800fd6d3f989221ab 100644 (file)
@@ -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();
 }
index e887a9a7801f524e383d260bc56ec5790a790639..39826dfdb9942b1f638e0692cd75e4066fcc0f6b 100644 (file)
@@ -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);
index 5e78a560ffe8135ee6e6d3ddab4e21746ad5be89..7e664ec849fa82200a042f81d8ae6e9a372426d7 100644 (file)
@@ -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);
 
index 60012e47d28818e38d3689891a09b4016c14b5b3..c5943363259286b858b29bc5ac4b4c25d9fe7df7 100644 (file)
@@ -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);
index 999dbe6be429e5adbe55c87f0d6da41874b32e96..518e48e1ec1c1465e9ad874281bf9968b2809ad3 100644 (file)
@@ -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);
index a8ad302f710089a1dba25dbe054c69181b2c5e98..0198d34f194bcd475922fa2e36133c0598351951 100644 (file)
@@ -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);
index 09b0179fa1a070d4c70fb3fd8417877bd0fcae07..0b84d4c4ed227939f5436f1213bb6e2a4b03c4a1 100644 (file)
@@ -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());
 
index 2b00ef8cb7347c19da8b8331f6d8cfeebe3d6a81..7fd3f82d4db2f467a32ca2d2fd7cfa2ab0110244 100644 (file)
@@ -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());
 
index 4e349ab927b5302853b130f7138b22e546f0e65e..615ded186bf286d08810c224781b3b443f33f935 100644 (file)
@@ -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());