diff options
Diffstat (limited to 'src/test/test-execute.c')
-rw-r--r-- | src/test/test-execute.c | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/src/test/test-execute.c b/src/test/test-execute.c index bc9a2021f9..90540b884b 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -35,6 +35,7 @@ #endif #include "stat-util.h" #include "test-helper.h" +#include "tests.h" #include "unit.h" #include "util.h" #include "virt.h" @@ -145,11 +146,11 @@ static void test_exec_privatetmp(Manager *m) { static void test_exec_privatedevices(Manager *m) { if (detect_container() > 0) { - log_notice("testing in container, skipping private device tests"); + log_notice("testing in container, skipping %s", __func__); return; } if (!is_inaccessible_available()) { - log_notice("testing without inaccessible, skipping private device tests"); + log_notice("testing without inaccessible, skipping %s", __func__); return; } @@ -158,12 +159,22 @@ static void test_exec_privatedevices(Manager *m) { } static void test_exec_privatedevices_capabilities(Manager *m) { + int r; + if (detect_container() > 0) { - log_notice("testing in container, skipping private device tests"); + log_notice("testing in container, skipping %s", __func__); return; } if (!is_inaccessible_available()) { - log_notice("testing without inaccessible, skipping private device tests"); + log_notice("testing without inaccessible, skipping %s", __func__); + return; + } + + /* We use capsh to test if the capabilities are + * properly set, so be sure that it exists */ + r = find_binary("capsh", NULL); + if (r < 0) { + log_error_errno(r, "Skipping %s, could not find capsh binary: %m", __func__); return; } @@ -174,15 +185,24 @@ static void test_exec_privatedevices_capabilities(Manager *m) { } static void test_exec_protectkernelmodules(Manager *m) { + int r; + if (detect_container() > 0) { - log_notice("testing in container, skipping protectkernelmodules tests"); + log_notice("testing in container, skipping %s", __func__); return; } if (!is_inaccessible_available()) { - log_notice("testing without inaccessible, skipping protectkernelmodules tests"); + log_notice("testing without inaccessible, skipping %s", __func__); return; } + r = find_binary("capsh", NULL); + if (r < 0) { + log_error_errno(r, "Skipping %s, could not find capsh binary: %m", __func__); + return; + } + + test(m, "exec-protectkernelmodules-no-capabilities.service", 0, CLD_EXITED); test(m, "exec-protectkernelmodules-yes-capabilities.service", 0, CLD_EXITED); test(m, "exec-protectkernelmodules-yes-mount-propagation.service", 0, CLD_EXITED); @@ -253,7 +273,7 @@ static void test_exec_systemcall_system_mode_with_user(Manager *m) { else if (getpwnam("nfsnobody")) test(m, "exec-systemcallfilter-system-user-nfsnobody.service", 0, CLD_EXITED); else - log_error_errno(errno, "Skipping test_exec_systemcall_system_mode_with_user, could not find nobody/nfsnobody user: %m"); + log_error_errno(errno, "Skipping %s, could not find nobody/nfsnobody user: %m", __func__); #endif } @@ -263,7 +283,7 @@ static void test_exec_user(Manager *m) { else if (getpwnam("nfsnobody")) test(m, "exec-user-nfsnobody.service", 0, CLD_EXITED); else - log_error_errno(errno, "Skipping test_exec_user, could not find nobody/nfsnobody user: %m"); + log_error_errno(errno, "Skipping %s, could not find nobody/nfsnobody user: %m", __func__); } static void test_exec_group(Manager *m) { @@ -272,7 +292,7 @@ static void test_exec_group(Manager *m) { else if (getgrnam("nfsnobody")) test(m, "exec-group-nfsnobody.service", 0, CLD_EXITED); else - log_error_errno(errno, "Skipping test_exec_group, could not find nobody/nfsnobody group: %m"); + log_error_errno(errno, "Skipping %s, could not find nobody/nfsnobody group: %m", __func__); } static void test_exec_supplementary_groups(Manager *m) { @@ -353,17 +373,15 @@ static void test_exec_runtimedirectory(Manager *m) { else if (getgrnam("nfsnobody")) test(m, "exec-runtimedirectory-owner-nfsnobody.service", 0, CLD_EXITED); else - log_error_errno(errno, "Skipping test_exec_runtimedirectory-owner, could not find nobody/nfsnobody group: %m"); + log_error_errno(errno, "Skipping %s, could not find nobody/nfsnobody group: %m", __func__); } static void test_exec_capabilityboundingset(Manager *m) { int r; - /* We use capsh to test if the capabilities are - * properly set, so be sure that it exists */ r = find_binary("capsh", NULL); if (r < 0) { - log_error_errno(r, "Skipping test_exec_capabilityboundingset, could not find capsh binary: %m"); + log_error_errno(r, "Skipping %s, could not find capsh binary: %m", __func__); return; } @@ -389,9 +407,9 @@ static void test_exec_capabilityambientset(Manager *m) { test(m, "exec-capabilityambientset-nfsnobody.service", 0, CLD_EXITED); test(m, "exec-capabilityambientset-merge-nfsnobody.service", 0, CLD_EXITED); } else - log_error_errno(errno, "Skipping test_exec_capabilityambientset, could not find nobody/nfsnobody user: %m"); + log_error_errno(errno, "Skipping %s, could not find nobody/nfsnobody user: %m", __func__); } else - log_error_errno(errno, "Skipping test_exec_capabilityambientset, the kernel does not support ambient capabilities: %m"); + log_error_errno(errno, "Skipping %s, the kernel does not support ambient capabilities: %m", __func__); } static void test_exec_privatenetwork(Manager *m) { @@ -399,7 +417,7 @@ static void test_exec_privatenetwork(Manager *m) { r = find_binary("ip", NULL); if (r < 0) { - log_error_errno(r, "Skipping test_exec_privatenetwork, could not find ip binary: %m"); + log_error_errno(r, "Skipping %s, could not find ip binary: %m", __func__); return; } @@ -422,6 +440,10 @@ static void test_exec_spec_interpolation(Manager *m) { test(m, "exec-spec-interpolation.service", 0, CLD_EXITED); } +static void test_exec_read_only_path_suceed(Manager *m) { + test(m, "exec-read-only-path-succeed.service", 0, CLD_EXITED); +} + static int run_tests(UnitFileScope scope, const test_function_t *tests) { const test_function_t *test = NULL; Manager *m = NULL; @@ -475,6 +497,7 @@ int main(int argc, char *argv[]) { test_exec_oomscoreadjust, test_exec_ioschedulingclass, test_exec_spec_interpolation, + test_exec_read_only_path_suceed, NULL, }; static const test_function_t system_tests[] = { @@ -494,7 +517,7 @@ int main(int argc, char *argv[]) { } assert_se(setenv("XDG_RUNTIME_DIR", "/tmp/", 1) == 0); - assert_se(set_unit_path(TEST_DIR "/test-execute/") >= 0); + assert_se(set_unit_path(get_testdata_dir("/test-execute")) >= 0); /* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test * cases, otherwise (and if they are present in the environment), |