diff options
Diffstat (limited to 'src/test/test-capability.c')
-rw-r--r-- | src/test/test-capability.c | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/src/test/test-capability.c b/src/test/test-capability.c index af6d808b6d..dae85f2f91 100644 --- a/src/test/test-capability.c +++ b/src/test/test-capability.c @@ -14,13 +14,19 @@ #include "fileio.h" #include "macro.h" #include "parse-util.h" +#include "tests.h" #include "util.h" static uid_t test_uid = -1; static gid_t test_gid = -1; +#if HAS_FEATURE_ADDRESS_SANITIZER +/* Keep CAP_SYS_PTRACE when running under Address Sanitizer */ +static const uint64_t test_flags = UINT64_C(1) << CAP_SYS_PTRACE; +#else /* We keep CAP_DAC_OVERRIDE to avoid errors with gcov when doing test coverage */ -static uint64_t test_flags = 1ULL << CAP_DAC_OVERRIDE; +static const uint64_t test_flags = UINT64_C(1) << CAP_DAC_OVERRIDE; +#endif /* verify cap_last_cap() against /proc/sys/kernel/cap_last_cap */ static void test_last_cap_file(void) { @@ -91,10 +97,9 @@ static int setup_tests(bool *run_ambient) { int r; nobody = getpwnam(NOBODY_USER_NAME); - if (!nobody) { - log_error_errno(errno, "Could not find nobody user: %m"); - return -EXIT_TEST_SKIP; - } + if (!nobody) + return log_error_errno(errno, "Could not find nobody user: %m"); + test_uid = nobody->pw_uid; test_gid = nobody->pw_gid; @@ -180,8 +185,6 @@ static void test_update_inherited_set(void) { caps = cap_get_proc(); assert_se(caps); - assert_se(!cap_get_flag(caps, CAP_CHOWN, CAP_INHERITABLE, &fv)); - assert(fv == CAP_CLEAR); set = (UINT64_C(1) << CAP_CHOWN); @@ -197,12 +200,6 @@ static void test_set_ambient_caps(void) { uint64_t set = 0; cap_flag_value_t fv; - caps = cap_get_proc(); - assert_se(caps); - assert_se(!cap_get_flag(caps, CAP_CHOWN, CAP_INHERITABLE, &fv)); - assert(fv == CAP_CLEAR); - cap_free(caps); - assert_se(prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_IS_SET, CAP_CHOWN, 0, 0) == 0); set = (UINT64_C(1) << CAP_CHOWN); @@ -218,23 +215,20 @@ static void test_set_ambient_caps(void) { } int main(int argc, char *argv[]) { - int r; bool run_ambient; + test_setup_logging(LOG_INFO); + test_last_cap_file(); test_last_cap_probe(); - log_parse_environment(); - log_open(); - log_info("have ambient caps: %s", yes_no(ambient_capabilities_supported())); if (getuid() != 0) - return EXIT_TEST_SKIP; + return log_tests_skipped("not running as root"); - r = setup_tests(&run_ambient); - if (r < 0) - return -r; + if (setup_tests(&run_ambient) < 0) + return log_tests_skipped("setup failed"); show_capabilities(); |