[PATCH v1 12/17] selftests/nolibc: rename chmod_net to chmod_good

From: Zhangjin Wu
Date: Wed Jun 21 2023 - 09:10:51 EST


When CONFIG_NET is not enabled, there would be no /proc/self/net, let's
use /tmp/blah in such case and rename chmod_net to chmod_good.

This allows to test chmod_good with tmpfs even when procfs is not there.

Signed-off-by: Zhangjin Wu <falcon@xxxxxxxxxxx>
---
tools/testing/selftests/nolibc/nolibc-test.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 8b587961e46a..eca0070151b6 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -550,10 +550,22 @@ int run_syscall(int min, int max)
int ret = 0;
void *p1, *p2;
int has_gettid = 1;
+ int has_tmpdir = 0;
+ char *tmpdir = NULL;

/* <has_proc> indicates whether or not /proc is mounted */
has_proc = stat("/proc", &stat_buf) == 0;

+ /* <has_tmpdir> indicates whether or not /tmp/blah is there */
+ if (stat("/proc/self/net", &stat_buf) == 0) {
+ tmpdir = "/proc/self/net";
+ has_tmpdir = 1;
+ } else if (stat("/tmp/.", &stat_buf) == 0) {
+ tmpdir = "/tmp/blah";
+ if (mkdir(tmpdir, 0755) == 0)
+ has_tmpdir = 1;
+ }
+
/* this will be used to skip certain tests that can't be run unprivileged */
is_root = geteuid() == 0;

@@ -582,7 +594,7 @@ int run_syscall(int min, int max)
CASE_TEST(chdir_root); EXPECT_SYSZR(1, chdir("/")); break;
CASE_TEST(chdir_dot); EXPECT_SYSZR(1, chdir(".")); break;
CASE_TEST(chdir_blah); EXPECT_SYSER(1, chdir("/blah"), -1, ENOENT); break;
- CASE_TEST(chmod_net); EXPECT_SYSZR(has_proc, chmod("/proc/self/net", 0555)); break;
+ CASE_TEST(chmod_good); EXPECT_SYSZR(has_tmpdir, chmod(tmpdir, 0555)); break;
CASE_TEST(chmod_self); EXPECT_SYSER(has_proc, chmod("/proc/self", 0555), -1, EPERM); break;
CASE_TEST(chown_self); EXPECT_SYSER(has_proc, chown("/proc/self", 0, 0), -1, EPERM); break;
CASE_TEST(chroot_root); EXPECT_SYSZR(is_root, chroot("/")); break;
--
2.25.1