Tiezhu Yang (2): selftests: pid_namespace: Include sys/mount.h selftests: pid_namespace: Skip tests if not root
tools/testing/selftests/pid_namespace/pid_max.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
When executing "make -C tools/testing/selftests/pid_namespace", there exist many errors such as:
$ make -C tools/testing/selftests/pid_namespace ... pid_max.c:42:15: error: implicit declaration of function 'mount' [-Wimplicit-function-declaration] ... pid_max.c:42:36: error: 'MS_PRIVATE' undeclared (first use in this function); did you mean 'MAP_PRIVATE'? ... pid_max.c:42:49: error: 'MS_REC' undeclared (first use in this function) ...
Include sys/mount.h to fix the errors, tested on x86_64 and LoongArch.
Reported-by: Haiyong Sun sunhaiyong@loongson.cn Fixes: 615ab43b838b ("tests/pid_namespace: add pid_max tests") Signed-off-by: Tiezhu Yang yangtiezhu@loongson.cn --- tools/testing/selftests/pid_namespace/pid_max.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/pid_namespace/pid_max.c b/tools/testing/selftests/pid_namespace/pid_max.c index 51c414faabb0..96f274f0582b 100644 --- a/tools/testing/selftests/pid_namespace/pid_max.c +++ b/tools/testing/selftests/pid_namespace/pid_max.c @@ -10,6 +10,7 @@ #include <stdlib.h> #include <string.h> #include <syscall.h> +#include <sys/mount.h> #include <sys/wait.h>
#include "../kselftest_harness.h"
CLONE_NEWPID or CLONE_NEWNS requires CAP_SYS_ADMIN, if the tests are not running as root, just skip tests rather than fail and also give a warning to the user.
Before:
$ make -C tools/testing/selftests/pid_namespace $ tools/testing/selftests/pid_namespace/pid_max ... # RUN global.pid_max_simple ... # pid_max.c:337:pid_max_simple:Expected pid (-1) > 0 (0) ... # RUN global.pid_max_nested_limit ... # pid_max.c:346:pid_max_nested_limit:Expected pid (-1) > 0 (0) ... # RUN global.pid_max_nested ... # pid_max.c:355:pid_max_nested:Expected pid (-1) > 0 (0) ... # Totals: pass:0 fail:3 xfail:0 xpass:0 skip:0 error:0
After:
$ make -C tools/testing/selftests/pid_namespace $ tools/testing/selftests/pid_namespace/pid_max ... # RUN global.pid_max_simple ... # SKIP Must be run as root ... # RUN global.pid_max_nested_limit ... # SKIP Must be run as root ... # RUN global.pid_max_nested ... # SKIP Must be run as root ... # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:3 error:0
While at it, remove the blank line in the TEST(pid_max_simple).
Fixes: 615ab43b838b ("tests/pid_namespace: add pid_max tests") Signed-off-by: Tiezhu Yang yangtiezhu@loongson.cn --- tools/testing/selftests/pid_namespace/pid_max.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/pid_namespace/pid_max.c b/tools/testing/selftests/pid_namespace/pid_max.c index 96f274f0582b..30937c5ee12b 100644 --- a/tools/testing/selftests/pid_namespace/pid_max.c +++ b/tools/testing/selftests/pid_namespace/pid_max.c @@ -332,8 +332,10 @@ TEST(pid_max_simple) { pid_t pid;
- pid = do_clone(pid_max_cb, NULL, CLONE_NEWPID | CLONE_NEWNS); + if (errno == EPERM) + SKIP(return, "Must be run as root"); + ASSERT_GT(pid, 0); ASSERT_EQ(0, wait_for_pid(pid)); } @@ -343,6 +345,9 @@ TEST(pid_max_nested_limit) pid_t pid;
pid = do_clone(pid_max_nested_limit_outer, NULL, CLONE_NEWPID | CLONE_NEWNS); + if (errno == EPERM) + SKIP(return, "Must be run as root"); + ASSERT_GT(pid, 0); ASSERT_EQ(0, wait_for_pid(pid)); } @@ -352,6 +357,9 @@ TEST(pid_max_nested) pid_t pid;
pid = do_clone(pid_max_nested_outer, NULL, CLONE_NEWPID | CLONE_NEWNS); + if (errno == EPERM) + SKIP(return, "Must be run as root"); + ASSERT_GT(pid, 0); ASSERT_EQ(0, wait_for_pid(pid)); }
linux-kselftest-mirror@lists.linaro.org