tests: add helper to unify skipping a test and exiting
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+8
-16
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
+10
-11
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user