diff options
| author | Thomas Weißschuh <linux@weissschuh.net> | 2026-05-14 15:05:14 +0300 |
|---|---|---|
| committer | Thomas Weißschuh <linux@weissschuh.net> | 2026-05-14 18:41:22 +0300 |
| commit | 2ee39c5fb3a0cdc5da5026e78718ac7d92ea48c4 (patch) | |
| tree | ca2d396dd2c07bc8a41e7e545973886dc9f75707 | |
| parent | 219d120c195e53dd33076be05641fda0e36bff37 (diff) | |
| download | linux-2ee39c5fb3a0cdc5da5026e78718ac7d92ea48c4.tar.xz | |
selftests/nolibc: test open mode handling
Add a selftest for the new O_TMPFILE open mode handling.
While O_CREAT or openat() are not tested, the code is the same,
so assume these also work.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://patch.msgid.link/20260514-nolibc-open-tmpfile-v2-4-b4c6c5efa266@weissschuh.net
| -rw-r--r-- | tools/testing/selftests/nolibc/nolibc-test.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 1db6e8d55c16..c3867cc570c6 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1305,6 +1305,28 @@ int test_openat(void) return 0; } +int test_open_mode(void) +{ + const mode_t mode = 0444; + struct stat stat_buf; + int fd, ret; + + fd = open("/tmp", O_TMPFILE | O_RDWR, mode); + if (fd == -1) + return -1; + + ret = fstat(fd, &stat_buf); + close(fd); + + if (ret == -1) + return -1; + + if ((stat_buf.st_mode & 0777) != mode) + return -1; + + return 0; +} + int test_nolibc_enosys(void) { if (true) @@ -1540,6 +1562,7 @@ int run_syscall(int min, int max) CASE_TEST(open_tty); EXPECT_SYSNE(1, tmp = open("/dev/null", O_RDONLY), -1); if (tmp != -1) close(tmp); break; CASE_TEST(open_blah); EXPECT_SYSER(1, tmp = open("/proc/self/blah", O_RDONLY), -1, ENOENT); if (tmp != -1) close(tmp); break; CASE_TEST(openat_dir); EXPECT_SYSZR(1, test_openat()); break; + CASE_TEST(open_mode); EXPECT_SYSZR(1, test_open_mode()); break; CASE_TEST(pipe); EXPECT_SYSZR(1, test_pipe()); break; CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break; CASE_TEST(poll_stdout); EXPECT_SYSNE(1, ({ struct pollfd fds = { 1, POLLOUT, 0}; poll(&fds, 1, 0); }), -1); break; |
