diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2017-11-28 14:14:54 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2017-11-28 14:14:54 +0100 |
commit | 4c1a95fd84206ee96c8a0d855780d2d99ff020bc (patch) | |
tree | baac5ad60d9b4300713f262c4c149f54bb6a619b /src | |
parent | cap-list: check range of numeric value (diff) | |
download | systemd-4c1a95fd84206ee96c8a0d855780d2d99ff020bc.tar.xz systemd-4c1a95fd84206ee96c8a0d855780d2d99ff020bc.zip |
test: move tests about cap_list_cap() from test-cap-list to test-capability
Diffstat (limited to 'src')
-rw-r--r-- | src/test/test-cap-list.c | 36 | ||||
-rw-r--r-- | src/test/test-capability.c | 39 |
2 files changed, 39 insertions, 36 deletions
diff --git a/src/test/test-cap-list.c b/src/test/test-cap-list.c index 9c82e618f5..f6978cc588 100644 --- a/src/test/test-cap-list.c +++ b/src/test/test-cap-list.c @@ -23,7 +23,6 @@ #include "alloc-util.h" #include "cap-list.h" #include "capability-util.h" -#include "fileio.h" #include "parse-util.h" #include "string-util.h" #include "util.h" @@ -71,39 +70,6 @@ static void test_cap_list(void) { } } -/* verify cap_last_cap() against /proc/sys/kernel/cap_last_cap */ -static void test_last_cap_file(void) { - _cleanup_free_ char *content = NULL; - unsigned long val = 0; - int r; - - r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content); - assert_se(r >= 0); - - r = safe_atolu(content, &val); - assert_se(r >= 0); - assert_se(val != 0); - assert_se(val == cap_last_cap()); -} - -/* verify cap_last_cap() against syscall probing */ -static void test_last_cap_probe(void) { - unsigned long p = (unsigned long)CAP_LAST_CAP; - - if (prctl(PR_CAPBSET_READ, p) < 0) { - for (p--; p > 0; p --) - if (prctl(PR_CAPBSET_READ, p) >= 0) - break; - } else { - for (;; p++) - if (prctl(PR_CAPBSET_READ, p+1) < 0) - break; - } - - assert_se(p != 0); - assert_se(p == cap_last_cap()); -} - static void test_capability_set_to_string_alloc(void) { _cleanup_free_ char *t1 = NULL, *t2 = NULL, *t3 = NULL; @@ -119,8 +85,6 @@ static void test_capability_set_to_string_alloc(void) { int main(int argc, char *argv[]) { test_cap_list(); - test_last_cap_file(); - test_last_cap_probe(); test_capability_set_to_string_alloc(); return 0; diff --git a/src/test/test-capability.c b/src/test/test-capability.c index 367614708f..6c41e1ca15 100644 --- a/src/test/test-capability.c +++ b/src/test/test-capability.c @@ -26,9 +26,12 @@ #include <sys/wait.h> #include <unistd.h> +#include "alloc-util.h" #include "capability-util.h" #include "fd-util.h" +#include "fileio.h" #include "macro.h" +#include "parse-util.h" #include "util.h" static uid_t test_uid = -1; @@ -37,6 +40,39 @@ static gid_t test_gid = -1; /* We keep CAP_DAC_OVERRIDE to avoid errors with gcov when doing test coverage */ static uint64_t test_flags = 1ULL << CAP_DAC_OVERRIDE; +/* verify cap_last_cap() against /proc/sys/kernel/cap_last_cap */ +static void test_last_cap_file(void) { + _cleanup_free_ char *content = NULL; + unsigned long val = 0; + int r; + + r = read_one_line_file("/proc/sys/kernel/cap_last_cap", &content); + assert_se(r >= 0); + + r = safe_atolu(content, &val); + assert_se(r >= 0); + assert_se(val != 0); + assert_se(val == cap_last_cap()); +} + +/* verify cap_last_cap() against syscall probing */ +static void test_last_cap_probe(void) { + unsigned long p = (unsigned long)CAP_LAST_CAP; + + if (prctl(PR_CAPBSET_READ, p) < 0) { + for (p--; p > 0; p --) + if (prctl(PR_CAPBSET_READ, p) >= 0) + break; + } else { + for (;; p++) + if (prctl(PR_CAPBSET_READ, p+1) < 0) + break; + } + + assert_se(p != 0); + assert_se(p == cap_last_cap()); +} + static void fork_test(void (*test_func)(void)) { pid_t pid = 0; @@ -203,6 +239,9 @@ int main(int argc, char *argv[]) { int r; bool run_ambient; + test_last_cap_file(); + test_last_cap_probe(); + log_parse_environment(); log_open(); |