diff --git a/src/shared/tests.c b/src/shared/tests.c index 60e2542634..3882a180c4 100644 --- a/src/shared/tests.c +++ b/src/shared/tests.c @@ -118,18 +118,6 @@ void test_setup_logging(int level) { log_open(); } -int log_tests_skipped(const char *message) { - log_notice("%s: %s, skipping tests.", - program_invocation_short_name, message); - return EXIT_TEST_SKIP; -} - -int log_tests_skipped_errno(int r, const char *message) { - log_notice_errno(r, "%s: %s, skipping tests: %m", - program_invocation_short_name, message); - return EXIT_TEST_SKIP; -} - int write_tmpfile(char *pattern, const char *contents) { _cleanup_close_ int fd = -EBADF; diff --git a/src/shared/tests.h b/src/shared/tests.h index 1baad3e51b..2a6d9d9d30 100644 --- a/src/shared/tests.h +++ b/src/shared/tests.h @@ -28,8 +28,23 @@ int get_testdata_dir(const char *suffix, char **ret); const char* get_catalog_dir(void); bool slow_tests_enabled(void); void test_setup_logging(int level); -int log_tests_skipped(const char *message); -int log_tests_skipped_errno(int r, const char *message); + +#define log_tests_skipped(fmt, ...) \ + ({ \ + log_notice("%s: " fmt ", skipping tests.", \ + program_invocation_short_name, \ + ##__VA_ARGS__); \ + EXIT_TEST_SKIP; \ + }) + +#define log_tests_skipped_errno(error, fmt, ...) \ + ({ \ + log_notice_errno(error, \ + "%s: " fmt ", skipping tests: %m", \ + program_invocation_short_name, \ + ##__VA_ARGS__); \ + EXIT_TEST_SKIP; \ + }) int write_tmpfile(char *pattern, const char *contents); diff --git a/src/test/test-compress.c b/src/test/test-compress.c index 18f8ce3b35..2f20d00116 100644 --- a/src/test/test-compress.c +++ b/src/test/test-compress.c @@ -368,7 +368,6 @@ int main(int argc, char *argv[]) { return 0; #else - log_info("/* XZ, LZ4 and ZSTD tests skipped */"); - return EXIT_TEST_SKIP; + return log_tests_skipped("no compression algorithm supported"); #endif } diff --git a/src/test/test-dev-setup.c b/src/test/test-dev-setup.c index ea9df56aeb..c9022ab973 100644 --- a/src/test/test-dev-setup.c +++ b/src/test/test-dev-setup.c @@ -6,6 +6,7 @@ #include "mkdir.h" #include "path-util.h" #include "rm-rf.h" +#include "tests.h" #include "tmpfile-util.h" int main(int argc, char *argv[]) { @@ -14,7 +15,7 @@ int main(int argc, char *argv[]) { struct stat st; if (have_effective_cap(CAP_DAC_OVERRIDE) <= 0) - return EXIT_TEST_SKIP; + return log_tests_skipped("missing capability (CAP_DAC_OVERRIDE)"); assert_se(mkdtemp_malloc("/tmp/test-dev-setupXXXXXX", &p) >= 0); diff --git a/src/test/test-firewall-util.c b/src/test/test-firewall-util.c index 3ca3108e36..3f47a30aef 100644 --- a/src/test/test-firewall-util.c +++ b/src/test/test-firewall-util.c @@ -107,7 +107,7 @@ int main(int argc, char *argv[]) { assert_se(ctx); if (ctx->backend == FW_BACKEND_NONE) - return EXIT_TEST_SKIP; + return log_tests_skipped("no firewall backend supported"); if (test_v4(ctx) && ctx->backend == FW_BACKEND_NFTABLES) test_v6(ctx); diff --git a/src/test/test-loopback.c b/src/test/test-loopback.c index 1a423e556e..48869ae337 100644 --- a/src/test/test-loopback.c +++ b/src/test/test-loopback.c @@ -13,10 +13,8 @@ TEST_RET(loopback_setup) { int r; if (unshare(CLONE_NEWUSER | CLONE_NEWNET) < 0) { - if (ERRNO_IS_PRIVILEGE(errno) || ERRNO_IS_NOT_SUPPORTED(errno)) { - log_notice("Skipping test, lacking privileges or namespaces not supported"); - return EXIT_TEST_SKIP; - } + if (ERRNO_IS_PRIVILEGE(errno) || ERRNO_IS_NOT_SUPPORTED(errno)) + return log_tests_skipped("lacking privileges or namespaces not supported"); return log_error_errno(errno, "Failed to create user+network namespace: %m"); } diff --git a/src/test/test-recurse-dir.c b/src/test/test-recurse-dir.c index 9362d6729a..8684d064ec 100644 --- a/src/test/test-recurse-dir.c +++ b/src/test/test-recurse-dir.c @@ -132,19 +132,15 @@ int main(int argc, char *argv[]) { p = "/usr/share/man"; /* something hopefully reasonably stable while we run (and limited in size) */ fd = open(p, O_DIRECTORY|O_CLOEXEC); - if (fd < 0 && errno == ENOENT) { - log_warning_errno(errno, "Couldn't open directory %s, ignoring: %m", p); - return EXIT_TEST_SKIP; - } + if (fd < 0 && errno == ENOENT) + return log_tests_skipped_errno(errno, "Couldn't open directory %s", p); assert_se(fd >= 0); /* If the test directory is on an overlayfs then files and their directory may return different * st_dev in stat results, which confuses nftw into thinking they're on different filesystems and * won't return the result when the FTW_MOUNT flag is set. */ - if (fd_is_fs_type(fd, OVERLAYFS_SUPER_MAGIC)) { - log_tests_skipped("nftw mountpoint detection produces false-positives on overlayfs"); - return EXIT_TEST_SKIP; - } + if (fd_is_fs_type(fd, OVERLAYFS_SUPER_MAGIC)) + return log_tests_skipped("nftw mountpoint detection produces false-positives on overlayfs"); /* Enumerate the specified dirs in full, once via nftw(), and once via recurse_dir(), and ensure the * results are identical. nftw() sometimes skips symlinks (see