* [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h
@ 2023-08-05 4:07 Yang Xu
2023-08-05 4:07 ` [LTP] [PATCH 2/3] syscalls/faccessat01: Convert to new API Yang Xu
` (6 more replies)
0 siblings, 7 replies; 13+ messages in thread
From: Yang Xu @ 2023-08-05 4:07 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
include/lapi/faccessat.h | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 include/lapi/faccessat.h
diff --git a/include/lapi/faccessat.h b/include/lapi/faccessat.h
new file mode 100644
index 000000000..f3318fd7a
--- /dev/null
+++ b/include/lapi/faccessat.h
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
+ * Copyright (c) Linux Test Project, 2003-2023
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+#ifndef FACCESSAT_H
+#define FACCESSAT_H
+
+#include <sys/types.h>
+#include "lapi/syscalls.h"
+
+#ifndef HAVE_FACCESSAT
+int faccessat(int dirfd, const char *pathname, int mode, int flags)
+{
+ return tst_syscall(__NR_faccessat, dirfd, pathname, mode, flags);
+}
+#endif
+
+#endif /* FACCESSAT_H */
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH 2/3] syscalls/faccessat01: Convert to new API
2023-08-05 4:07 [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h Yang Xu
@ 2023-08-05 4:07 ` Yang Xu
2023-08-05 4:07 ` [LTP] [PATCH 3/3] syscalls/faccessat02: Move errnos check to faccessat02 Yang Xu
` (5 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Yang Xu @ 2023-08-05 4:07 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
.../kernel/syscalls/faccessat/faccessat01.c | 208 +++++++-----------
1 file changed, 76 insertions(+), 132 deletions(-)
diff --git a/testcases/kernel/syscalls/faccessat/faccessat01.c b/testcases/kernel/syscalls/faccessat/faccessat01.c
index d11e8cf12..52f6454fd 100644
--- a/testcases/kernel/syscalls/faccessat/faccessat01.c
+++ b/testcases/kernel/syscalls/faccessat/faccessat01.c
@@ -1,151 +1,95 @@
-/******************************************************************************
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2006
+ * Copyright (c) Linux Test Project, 2003-2023
+ * Author: Yi Yang <yyangcdl@cn.ibm.com>
+ */
+
+/*\
+ * [Description]
*
- * Copyright (c) International Business Machines Corp., 2006
+ * Check the basic functionality of the faccessat() system call.
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * - faccessat() passes if dir_fd is file descriptor to the directory
+ * where the file is located and pathname is relative path of the file.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
+ * - faccessat() passes if dir_fd is a bad file descriptor and pathname is
+ * absolute path of the file.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * NAME
- * faccessat01.c
- *
- * DESCRIPTION
- * This test case will verify basic function of faccessat
- * added by kernel 2.6.16 or up.
- *
- * Author
- * Yi Yang <yyangcdl@cn.ibm.com>
- *
- * History
- * 08/28/2006 Created first by Yi Yang <yyangcdl@cn.ibm.com>
- *
- *****************************************************************************/
-
-#define _GNU_SOURCE
+ * - faccessat() passes if dir_fd is AT_FDCWD and pathname is interpreted
+ * relative to the current working directory of the calling process.
+ */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-#include "safe_macros.h"
-#include "lapi/syscalls.h"
-
-#define TEST_CASES 6
-#ifndef AT_FDCWD
-#define AT_FDCWD -100
-#endif
-void setup();
-void cleanup();
-
-char *TCID = "faccessat01";
-int TST_TOTAL = TEST_CASES;
-static char pathname[256];
-static char testfile[256];
-static char testfile2[256];
-static char testfile3[256];
-static int fds[TEST_CASES];
-static char *filenames[TEST_CASES];
-static int expected_errno[TEST_CASES] = { 0, 0, ENOTDIR, EBADF, 0, 0 };
-
-int myfaccessat(int dirfd, const char *filename, int mode)
-{
- return tst_syscall(__NR_faccessat, dirfd, filename, mode);
-}
-
-int main(int ac, char **av)
+#include <stdio.h>
+#include "tst_test.h"
+#include "lapi/fcntl.h"
+#include "lapi/faccessat.h"
+
+#define TESTDIR "faccessatdir"
+#define TESTFILE "faccessatfile"
+#define FILEPATH "faccessatdir/faccessatfile"
+
+static int dir_fd, file_fd;
+static int atcwd_fd = AT_FDCWD;
+static char *filenames[4];
+static char abs_path[128];
+
+static struct tcase {
+ int *fd;
+ char **filename;
+ int exp_errno;
+} tcases[] = {
+ {&dir_fd, &filenames[0], 0},
+ {&dir_fd, &filenames[1], 0},
+ {&dir_fd, &filenames[0], 0},
+ {&atcwd_fd, &filenames[2], 0},
+};
+
+static void verify_faccessat(unsigned int i)
{
- int lc;
- int i;
-
- tst_parse_opts(ac, av, NULL, NULL);
+ struct tcase *tc = &tcases[i];
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
-
- /*
- * Call faccessat
- */
- for (i = 0; i < TST_TOTAL; i++) {
- TEST(myfaccessat(fds[i], filenames[i], R_OK));
-
- /* check return code */
- if (TEST_ERRNO == expected_errno[i]) {
- tst_resm(TPASS,
- "faccessat() returned the expected errno %d: %s",
- TEST_ERRNO,
- strerror(TEST_ERRNO));
- } else {
- tst_resm(TFAIL,
- "faccessdat() Failed, errno=%d : %s",
- TEST_ERRNO, strerror(TEST_ERRNO));
- }
- }
- }
-
- cleanup();
- tst_exit();
+ TST_EXP_PASS(faccessat(*tc->fd, *tc->filename, R_OK, 0),
+ "faccessat(%d, %s, R_OK, 0)",
+ *tc->fd, *tc->filename);
}
-void setup(void)
+static void setup(void)
{
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
- tst_tmpdir();
-
- char *abs_path = tst_get_tmpdir();
- int p = getpid();
-
- /* Initialize test dir and file names */
- sprintf(pathname, "faccessattestdir%d", p);
- sprintf(testfile, "faccessattestfile%d.txt", p);
- sprintf(testfile2, "%s/faccessattestfile%d.txt", abs_path, p);
- sprintf(testfile3, "faccessattestdir%d/faccessattestfile%d.txt", p, p);
+ char *tmpdir_path = tst_get_tmpdir();
- free(abs_path);
+ sprintf(abs_path, "%s/%s", tmpdir_path, FILEPATH);
+ free(tmpdir_path);
- SAFE_MKDIR(cleanup, pathname, 0700);
+ SAFE_MKDIR(TESTDIR, 0700);
+ dir_fd = SAFE_OPEN(TESTDIR, O_DIRECTORY);
+ file_fd = SAFE_OPEN(FILEPATH, O_CREAT | O_RDWR, 0600);
- fds[0] = SAFE_OPEN(cleanup, pathname, O_DIRECTORY);
- fds[1] = fds[4] = fds[0];
-
- SAFE_FILE_PRINTF(cleanup, testfile, "%s", testfile);
- SAFE_FILE_PRINTF(cleanup, testfile2, "%s", testfile2);
-
- fds[2] = SAFE_OPEN(cleanup, testfile3, O_CREAT | O_RDWR, 0600);
-
- fds[3] = 100;
- fds[5] = AT_FDCWD;
-
- filenames[0] = filenames[2] = filenames[3] = filenames[4] = testfile;
- filenames[1] = testfile2;
- filenames[5] = testfile3;
-
- TEST_PAUSE;
+ filenames[0] = TESTFILE;
+ filenames[1] = abs_path;
+ filenames[2] = FILEPATH;
}
-void cleanup(void)
+static void cleanup(void)
{
- if (fds[0] > 0)
- close(fds[0]);
- if (fds[2] > 0)
- close(fds[2]);
+ if (dir_fd > -1)
+ SAFE_CLOSE(dir_fd);
- tst_rmdir();
+ if (file_fd > -1)
+ SAFE_CLOSE(file_fd);
}
+
+static struct tst_test test = {
+ .test = verify_faccessat,
+ .tcnt = ARRAY_SIZE(tcases),
+ .setup = setup,
+ .cleanup = cleanup,
+ .bufs = (struct tst_buffers []) {
+ {&filenames[0], .size = sizeof(*filenames[0])},
+ {&filenames[1], .size = sizeof(*filenames[1])},
+ {&filenames[2], .size = sizeof(*filenames[2])},
+ {},
+ },
+ .needs_tmpdir = 1,
+};
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH 3/3] syscalls/faccessat02: Move errnos check to faccessat02
2023-08-05 4:07 [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h Yang Xu
2023-08-05 4:07 ` [LTP] [PATCH 2/3] syscalls/faccessat01: Convert to new API Yang Xu
@ 2023-08-05 4:07 ` Yang Xu
2023-08-05 4:07 ` [LTP] [PATCH 1/2] syscalls/faccessat201: Add new testcase Yang Xu
` (4 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Yang Xu @ 2023-08-05 4:07 UTC (permalink / raw)
To: ltp
Check various errnos for faccessat().
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
runtest/syscalls | 1 +
.../kernel/syscalls/faccessat/.gitignore | 1 +
.../kernel/syscalls/faccessat/faccessat02.c | 68 +++++++++++++++++++
3 files changed, 70 insertions(+)
create mode 100644 testcases/kernel/syscalls/faccessat/faccessat02.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 1028e45fc..1aed336ee 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -215,6 +215,7 @@ exit_group01 exit_group01
#faccessat test cases
faccessat01 faccessat01
+faccessat02 faccessat02
#fallocate test cases
fallocate01 fallocate01
diff --git a/testcases/kernel/syscalls/faccessat/.gitignore b/testcases/kernel/syscalls/faccessat/.gitignore
index 9551ab97e..276caca45 100644
--- a/testcases/kernel/syscalls/faccessat/.gitignore
+++ b/testcases/kernel/syscalls/faccessat/.gitignore
@@ -1 +1,2 @@
/faccessat01
+/faccessat02
diff --git a/testcases/kernel/syscalls/faccessat/faccessat02.c b/testcases/kernel/syscalls/faccessat/faccessat02.c
new file mode 100644
index 000000000..8e148dce0
--- /dev/null
+++ b/testcases/kernel/syscalls/faccessat/faccessat02.c
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2006
+ * Copyright (c) Linux Test Project, 2003-2023
+ * Author: Yi Yang <yyangcdl@cn.ibm.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * - faccessat() fails with ENOTDIR if dir_fd is file descriptor to the file
+ * and pathname is relative path of the file.
+ *
+ * - faccessat() fails with EBADF if dir_fd is invalid.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "tst_test.h"
+#include "lapi/fcntl.h"
+#include "lapi/faccessat.h"
+
+#define TESTDIR "faccessatdir"
+#define TESTFILE "faccessatfile"
+#define FILEPATH "faccessatdir/faccessatfile"
+
+static int dir_fd, file_fd;
+static int bad_fd = -1;
+
+static struct tcase {
+ int *fd;
+ int exp_errno;
+} tcases[] = {
+ {&file_fd, ENOTDIR},
+ {&bad_fd, EBADF},
+};
+
+static void verify_faccessat(unsigned int i)
+{
+ struct tcase *tc = &tcases[i];
+
+ TST_EXP_FAIL(faccessat(*tc->fd, TESTFILE, R_OK, 0),
+ tc->exp_errno, "faccessat(%d, TESTFILE, R_OK, 0)", *tc->fd);
+}
+
+static void setup(void)
+{
+ SAFE_MKDIR(TESTDIR, 0700);
+ dir_fd = SAFE_OPEN(TESTDIR, O_DIRECTORY);
+ file_fd = SAFE_OPEN(FILEPATH, O_CREAT | O_RDWR, 0600);
+}
+
+static void cleanup(void)
+{
+ if (dir_fd > -1)
+ SAFE_CLOSE(dir_fd);
+
+ if (file_fd > -1)
+ SAFE_CLOSE(file_fd);
+}
+
+static struct tst_test test = {
+ .test = verify_faccessat,
+ .tcnt = ARRAY_SIZE(tcases),
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_tmpdir = 1,
+};
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH 1/2] syscalls/faccessat201: Add new testcase
2023-08-05 4:07 [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h Yang Xu
2023-08-05 4:07 ` [LTP] [PATCH 2/3] syscalls/faccessat01: Convert to new API Yang Xu
2023-08-05 4:07 ` [LTP] [PATCH 3/3] syscalls/faccessat02: Move errnos check to faccessat02 Yang Xu
@ 2023-08-05 4:07 ` Yang Xu
2023-08-10 14:54 ` Cyril Hrubis
2023-08-05 4:08 ` [LTP] [PATCH 2/2] syscalls/faccessat202: " Yang Xu
` (3 subsequent siblings)
6 siblings, 1 reply; 13+ messages in thread
From: Yang Xu @ 2023-08-05 4:07 UTC (permalink / raw)
To: ltp
Check the basic functionality of faccessat2().
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
include/lapi/faccessat2.h | 20 +++
include/lapi/syscalls/aarch64.in | 1 +
include/lapi/syscalls/arc.in | 1 +
include/lapi/syscalls/arm.in | 1 +
include/lapi/syscalls/hppa.in | 1 +
include/lapi/syscalls/i386.in | 1 +
include/lapi/syscalls/ia64.in | 1 +
include/lapi/syscalls/powerpc.in | 1 +
include/lapi/syscalls/powerpc64.in | 1 +
include/lapi/syscalls/s390.in | 1 +
include/lapi/syscalls/s390x.in | 1 +
include/lapi/syscalls/sh.in | 1 +
include/lapi/syscalls/sparc.in | 1 +
include/lapi/syscalls/sparc64.in | 1 +
include/lapi/syscalls/x86_64.in | 1 +
runtest/syscalls | 3 +
.../kernel/syscalls/faccessat2/.gitignore | 1 +
testcases/kernel/syscalls/faccessat2/Makefile | 9 ++
.../kernel/syscalls/faccessat2/faccessat201.c | 115 ++++++++++++++++++
19 files changed, 162 insertions(+)
create mode 100644 include/lapi/faccessat2.h
create mode 100644 testcases/kernel/syscalls/faccessat2/.gitignore
create mode 100644 testcases/kernel/syscalls/faccessat2/Makefile
create mode 100644 testcases/kernel/syscalls/faccessat2/faccessat201.c
diff --git a/include/lapi/faccessat2.h b/include/lapi/faccessat2.h
new file mode 100644
index 000000000..e8b27d6b1
--- /dev/null
+++ b/include/lapi/faccessat2.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+#ifndef LAPI_FACCESSAT2_H__
+#define LAPI_FACCESSAT2_H__
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+#ifndef HAVE_FACCESSAT2
+int faccessat2(int dirfd, const char *pathname, int mode, int flags)
+{
+ return tst_syscall(__NR_faccessat2, dirfd, pathname, mode, flags);
+}
+#endif
+
+#endif /* LAPI_FACCESSAT2_H__ */
diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in
index de4ed5fb1..2cb6c2d87 100644
--- a/include/lapi/syscalls/aarch64.in
+++ b/include/lapi/syscalls/aarch64.in
@@ -293,6 +293,7 @@ clone3 435
close_range 436
openat2 437
pidfd_getfd 438
+faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
diff --git a/include/lapi/syscalls/arc.in b/include/lapi/syscalls/arc.in
index 9f11381db..3e2ee9061 100644
--- a/include/lapi/syscalls/arc.in
+++ b/include/lapi/syscalls/arc.in
@@ -313,6 +313,7 @@ clone3 435
close_range 436
openat2 437
pidfd_getfd 438
+faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in
index 4b0f63a28..7bdbca533 100644
--- a/include/lapi/syscalls/arm.in
+++ b/include/lapi/syscalls/arm.in
@@ -391,6 +391,7 @@ clone3 (__NR_SYSCALL_BASE+435)
close_range (__NR_SYSCALL_BASE+436)
openat2 (__NR_SYSCALL_BASE+437)
pidfd_getfd (__NR_SYSCALL_BASE+438)
+faccessat2 (__NR_SYSCALL_BASE+439)
epoll_pwait2 (__NR_SYSCALL_BASE+441)
quotactl_fd (__NR_SYSCALL_BASE+443)
futex_waitv (__NR_SYSCALL_BASE+449)
diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in
index b6d32d386..8ebdafafb 100644
--- a/include/lapi/syscalls/hppa.in
+++ b/include/lapi/syscalls/hppa.in
@@ -40,6 +40,7 @@ fsmount 432
fspick 433
pidfd_open 434
close_range 436
+faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in
index d0e6e9a4b..1472631c4 100644
--- a/include/lapi/syscalls/i386.in
+++ b/include/lapi/syscalls/i386.in
@@ -427,6 +427,7 @@ clone3 435
close_range 436
openat2 437
pidfd_getfd 438
+faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in
index 123200624..0ea6e9722 100644
--- a/include/lapi/syscalls/ia64.in
+++ b/include/lapi/syscalls/ia64.in
@@ -340,6 +340,7 @@ pidfd_open 1458
close_range 1460
openat2 1461
pidfd_getfd 1462
+faccessat2 1463
epoll_pwait2 1465
quotactl_fd 1467
futex_waitv 1473
diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in
index d5de621e1..545d9d3d6 100644
--- a/include/lapi/syscalls/powerpc.in
+++ b/include/lapi/syscalls/powerpc.in
@@ -420,6 +420,7 @@ clone3 435
close_range 436
openat2 437
pidfd_getfd 438
+faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in
index d5de621e1..545d9d3d6 100644
--- a/include/lapi/syscalls/powerpc64.in
+++ b/include/lapi/syscalls/powerpc64.in
@@ -420,6 +420,7 @@ clone3 435
close_range 436
openat2 437
pidfd_getfd 438
+faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in
index 6505f3822..7213ac5f8 100644
--- a/include/lapi/syscalls/s390.in
+++ b/include/lapi/syscalls/s390.in
@@ -407,6 +407,7 @@ clone3 435
close_range 436
openat2 437
pidfd_getfd 438
+faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in
index bc5d2b34c..879012e2b 100644
--- a/include/lapi/syscalls/s390x.in
+++ b/include/lapi/syscalls/s390x.in
@@ -355,6 +355,7 @@ clone3 435
close_range 436
openat2 437
pidfd_getfd 438
+faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in
index 316ffe5f1..7d5192a27 100644
--- a/include/lapi/syscalls/sh.in
+++ b/include/lapi/syscalls/sh.in
@@ -401,6 +401,7 @@ pidfd_open 434
close_range 436
openat2 437
pidfd_getfd 438
+faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in
index e0c60a360..91d2fb1c2 100644
--- a/include/lapi/syscalls/sparc.in
+++ b/include/lapi/syscalls/sparc.in
@@ -406,6 +406,7 @@ pidfd_open 434
close_range 436
openat2 437
pidfd_getfd 438
+faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in
index 0acde6856..1f2fc59b7 100644
--- a/include/lapi/syscalls/sparc64.in
+++ b/include/lapi/syscalls/sparc64.in
@@ -371,6 +371,7 @@ pidfd_open 434
close_range 436
openat2 437
pidfd_getfd 438
+faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in
index 1863e1df7..dc61aa56e 100644
--- a/include/lapi/syscalls/x86_64.in
+++ b/include/lapi/syscalls/x86_64.in
@@ -348,6 +348,7 @@ clone3 435
close_range 436
openat2 437
pidfd_getfd 438
+faccessat2 439
epoll_pwait2 441
quotactl_fd 443
futex_waitv 449
diff --git a/runtest/syscalls b/runtest/syscalls
index 1028e45fc..948c39030 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -216,6 +216,9 @@ exit_group01 exit_group01
#faccessat test cases
faccessat01 faccessat01
+#faccessat2 test cases
+faccessat201 faccessat201
+
#fallocate test cases
fallocate01 fallocate01
fallocate02 fallocate02
diff --git a/testcases/kernel/syscalls/faccessat2/.gitignore b/testcases/kernel/syscalls/faccessat2/.gitignore
new file mode 100644
index 000000000..53f700bac
--- /dev/null
+++ b/testcases/kernel/syscalls/faccessat2/.gitignore
@@ -0,0 +1 @@
+/faccessat201
diff --git a/testcases/kernel/syscalls/faccessat2/Makefile b/testcases/kernel/syscalls/faccessat2/Makefile
new file mode 100644
index 000000000..aaac6b703
--- /dev/null
+++ b/testcases/kernel/syscalls/faccessat2/Makefile
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
+# Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+
+top_srcdir ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/faccessat2/faccessat201.c b/testcases/kernel/syscalls/faccessat2/faccessat201.c
new file mode 100644
index 000000000..658d1dd81
--- /dev/null
+++ b/testcases/kernel/syscalls/faccessat2/faccessat201.c
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Check the basic functionality of faccessat2().
+ *
+ * Minimum Linux version required is v5.8.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <pwd.h>
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/faccessat2.h"
+
+#define TESTUSER "nobody"
+#define TESTDIR "faccessat2dir"
+#define TESTFILE "faccessat2file"
+#define RELPATH "faccessat2dir/faccessat2file"
+#define TESTSYMLINK "faccessat2symlink"
+
+static int dir_fd = -1, bad_fd = -1;
+static int atcwd_fd = AT_FDCWD;
+static char *filepaths[4];
+static char abs_path[128];
+static struct passwd *ltpuser;
+
+static struct tcase {
+ int *fd;
+ char **filename;
+ int flags;
+ int exp_errno;
+} tcases[] = {
+ {&dir_fd, &filepaths[0], 0, 0},
+ {&bad_fd, &filepaths[1], 0, 0},
+ {&atcwd_fd, &filepaths[2], 0, 0},
+ {&dir_fd, &filepaths[0], AT_EACCESS, 0},
+ {&bad_fd, &filepaths[1], AT_EACCESS, 0},
+ {&atcwd_fd, &filepaths[2], AT_EACCESS, 0},
+ {&dir_fd, &filepaths[0], AT_EACCESS, EACCES},
+ {&bad_fd, &filepaths[1], AT_EACCESS, EACCES},
+ {&atcwd_fd, &filepaths[2], AT_EACCESS, EACCES},
+ {&atcwd_fd, &filepaths[3], AT_SYMLINK_NOFOLLOW, 0},
+};
+
+static void verify_faccessat2(unsigned int i)
+{
+ struct tcase *tc = &tcases[i];
+
+ if (tc->exp_errno == EACCES) {
+ if (SAFE_FORK() == 0) {
+ SAFE_SETUID(ltpuser->pw_uid);
+ TST_EXP_FAIL(faccessat2(*tc->fd, *tc->filename, R_OK, tc->flags),
+ tc->exp_errno, "faccessat2(%d, %s, R_OK, %d) as %s",
+ *tc->fd, *tc->filename, tc->flags, TESTUSER);
+ }
+
+ tst_reap_children();
+ } else {
+ TST_EXP_PASS(faccessat2(*tc->fd, *tc->filename, R_OK, tc->flags),
+ "faccessat2(%d, %s, R_OK, %d) as root",
+ *tc->fd, *tc->filename, tc->flags);
+ }
+}
+
+static void setup(void)
+{
+ char *tmpdir_path = tst_get_tmpdir();
+
+ sprintf(abs_path, "%s/%s", tmpdir_path, RELPATH);
+ free(tmpdir_path);
+
+ SAFE_MKDIR(TESTDIR, 0666);
+ dir_fd = SAFE_OPEN(TESTDIR, O_DIRECTORY);
+ SAFE_TOUCH(abs_path, 0444, NULL);
+ SAFE_SYMLINK(abs_path, TESTSYMLINK);
+
+ filepaths[0] = TESTFILE;
+ filepaths[1] = abs_path;
+ filepaths[2] = RELPATH;
+ filepaths[3] = TESTSYMLINK;
+
+ ltpuser = SAFE_GETPWNAM(TESTUSER);
+}
+
+static void cleanup(void)
+{
+ if (dir_fd > 0)
+ SAFE_CLOSE(dir_fd);
+}
+
+static struct tst_test test = {
+ .test = verify_faccessat2,
+ .tcnt = ARRAY_SIZE(tcases),
+ .setup = setup,
+ .cleanup = cleanup,
+ .bufs = (struct tst_buffers []) {
+ {&filepaths[0], .size = sizeof(*filepaths[0])},
+ {&filepaths[1], .size = sizeof(*filepaths[1])},
+ {&filepaths[2], .size = sizeof(*filepaths[2])},
+ {&filepaths[3], .size = sizeof(*filepaths[3])},
+ {<puser, .size = sizeof(ltpuser)},
+ {},
+ },
+ .needs_tmpdir = 1,
+ .forks_child = 1,
+ .needs_root = 1,
+};
--
2.23.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH 2/2] syscalls/faccessat202: Add new testcase
2023-08-05 4:07 [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h Yang Xu
` (2 preceding siblings ...)
2023-08-05 4:07 ` [LTP] [PATCH 1/2] syscalls/faccessat201: Add new testcase Yang Xu
@ 2023-08-05 4:08 ` Yang Xu
2023-08-05 4:08 ` [LTP] [PATCH 1/2] syscalls/readlinkat01: Convert to new API Yang Xu
` (2 subsequent siblings)
6 siblings, 0 replies; 13+ messages in thread
From: Yang Xu @ 2023-08-05 4:08 UTC (permalink / raw)
To: ltp
Check various errnos for faccessat2().
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
runtest/syscalls | 1 +
.../kernel/syscalls/faccessat2/.gitignore | 1 +
.../kernel/syscalls/faccessat2/faccessat202.c | 90 +++++++++++++++++++
3 files changed, 92 insertions(+)
create mode 100644 testcases/kernel/syscalls/faccessat2/faccessat202.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 948c39030..9ccc1c7b6 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -218,6 +218,7 @@ faccessat01 faccessat01
#faccessat2 test cases
faccessat201 faccessat201
+faccessat202 faccessat202
#fallocate test cases
fallocate01 fallocate01
diff --git a/testcases/kernel/syscalls/faccessat2/.gitignore b/testcases/kernel/syscalls/faccessat2/.gitignore
index 53f700bac..f58f045f4 100644
--- a/testcases/kernel/syscalls/faccessat2/.gitignore
+++ b/testcases/kernel/syscalls/faccessat2/.gitignore
@@ -1 +1,2 @@
/faccessat201
+/faccessat202
diff --git a/testcases/kernel/syscalls/faccessat2/faccessat202.c b/testcases/kernel/syscalls/faccessat2/faccessat202.c
new file mode 100644
index 000000000..061dcf8ce
--- /dev/null
+++ b/testcases/kernel/syscalls/faccessat2/faccessat202.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test basic error handling of faccessat2 syscall:
+ *
+ * - faccessat2() fails with EFAULT if pathname is a bad pathname point.
+ * - faccessat2() fails with EINVAL if flags is -1.
+ * - faccessat2() fails with EINVAL if mode is -1.
+ * - faccessat2() fails with EBADF if dirfd is -1.
+ * - faccessat2() fails with ENOTDIR if pathname is relative path to the
+ * file and dir_fd is file descriptor for this file.
+ *
+ * Minimum Linux version required is v5.8.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <pwd.h>
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/faccessat2.h"
+
+#define TESTDIR "faccessat2dir"
+#define TESTFILE "faccessat2dir/faccessat2file"
+
+static int fd = -1, bad_fd = -1;
+static int atcwd_fd = AT_FDCWD;
+static char *bad_path, *file_path;
+static struct passwd *ltpuser;
+
+static struct tcase {
+ int *fd;
+ char **filepath;
+ int mode;
+ int flags;
+ int exp_errno;
+} tcases[] = {
+ {&atcwd_fd, &bad_path, R_OK, 0, EFAULT},
+ {&atcwd_fd, &file_path, R_OK, -1, EINVAL},
+ {&atcwd_fd, &file_path, -1, 0, EINVAL},
+ {&bad_fd, &file_path, R_OK, 0, EBADF},
+ {&fd, &file_path, R_OK, 0, ENOTDIR},
+};
+
+static void verify_faccessat2(unsigned int i)
+{
+ struct tcase *tc = &tcases[i];
+
+ TST_EXP_FAIL(faccessat2(*tc->fd, *tc->filepath, tc->mode, tc->flags),
+ tc->exp_errno);
+}
+
+static void setup(void)
+{
+ SAFE_MKDIR(TESTDIR, 0666);
+ SAFE_TOUCH(TESTFILE, 0444, NULL);
+
+ fd = SAFE_OPEN(TESTFILE, O_RDONLY);
+
+ bad_path = tst_get_bad_addr(NULL);
+ file_path = TESTFILE;
+}
+
+static void cleanup(void)
+{
+ if (fd > 0)
+ SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+ .test = verify_faccessat2,
+ .tcnt = ARRAY_SIZE(tcases),
+ .setup = setup,
+ .cleanup = cleanup,
+ .bufs = (struct tst_buffers []) {
+ {&bad_path, .size = sizeof(*bad_path)},
+ {&file_path, .size = sizeof(*file_path)},
+ {<puser, .size = sizeof(ltpuser)},
+ {},
+ },
+ .needs_tmpdir = 1,
+ .needs_root = 1,
+};
--
2.23.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH 1/2] syscalls/readlinkat01: Convert to new API
2023-08-05 4:07 [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h Yang Xu
` (3 preceding siblings ...)
2023-08-05 4:08 ` [LTP] [PATCH 2/2] syscalls/faccessat202: " Yang Xu
@ 2023-08-05 4:08 ` Yang Xu
2023-08-05 4:08 ` [LTP] [PATCH 2/2] syscalls/readlinkat02: " Yang Xu
2023-08-10 14:29 ` [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h Cyril Hrubis
6 siblings, 0 replies; 13+ messages in thread
From: Yang Xu @ 2023-08-05 4:08 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
.../kernel/syscalls/readlinkat/readlinkat01.c | 152 ++++++------------
1 file changed, 53 insertions(+), 99 deletions(-)
diff --git a/testcases/kernel/syscalls/readlinkat/readlinkat01.c b/testcases/kernel/syscalls/readlinkat/readlinkat01.c
index 985890ebe..965afbd5d 100644
--- a/testcases/kernel/syscalls/readlinkat/readlinkat01.c
+++ b/testcases/kernel/syscalls/readlinkat/readlinkat01.c
@@ -1,143 +1,97 @@
-/******************************************************************************
- *
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
* Copyright (c) International Business Machines Corp., 2006
- * Author: Yi Yang <yyangcdl@cn.ibm.com>
* Copyright (c) Cyril Hrubis 2014 <chrubis@suse.cz>
+ * Copyright (c) Linux Test Project, 2003-2023
+ * Author: Yi Yang <yyangcdl@cn.ibm.com>
+ */
+
+/*\
+ * [Description]
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Check the basic functionality of the readlinkat() system call.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
+ * - faccessat() passes if dir_fd is file descriptor to the directory and
+ * pathname is interpreted to the symbolic link file.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * - faccessat() passes if dir_fd is file descriptor to the directory and
+ * pathname is absolute path of the file.
*
- * This test case will verify basic function of readlinkat
- * added by kernel 2.6.16 or up.
+ * - faccessat() passes if dir_fd is file descriptor to the file and
+ * pathname is absolute path of the file.
*
- *****************************************************************************/
-
-#define _GNU_SOURCE
+ * - faccessat() passes if dir_fd is AT_FDCWD and pathname is interpreted
+ * relative to the symbolic link file.
+ *
+ * - faccessat() passes if dir_fd is AT_FDCWD and pathname is absolute
+ * path of the file.
+ */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <fcntl.h>
#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <stdio.h>
+#include "tst_test.h"
+#include "lapi/fcntl.h"
#include "lapi/readlinkat.h"
+#include "lapi/syscalls.h"
-static void setup(void);
-static void cleanup(void);
-
-char *TCID = "readlinkat01";
+#define TEST_FILE "readlink_file"
+#define TEST_SYMLINK "readlink_symlink"
-static int dir_fd, fd;
-static int fd_invalid = 100;
+static int file_fd, dir_fd;
static int fd_atcwd = AT_FDCWD;
-
-#define TEST_SYMLINK "readlink_symlink"
-#define TEST_FILE "readlink_file"
-
static char abspath[1024];
-static struct test_case {
- int *dir_fd;
+static struct tcase {
+ int *fd;
const char *path;
const char *exp_buf;
int exp_ret;
int exp_errno;
-} test_cases[] = {
+} tcases[] = {
{&dir_fd, TEST_SYMLINK, TEST_FILE, sizeof(TEST_FILE)-1, 0},
{&dir_fd, abspath, TEST_FILE, sizeof(TEST_FILE)-1, 0},
- {&fd, TEST_SYMLINK, NULL, -1, ENOTDIR},
- {&fd_invalid, TEST_SYMLINK, NULL, -1, EBADF},
+ {&file_fd, abspath, TEST_FILE, sizeof(TEST_FILE)-1, 0},
{&fd_atcwd, TEST_SYMLINK, TEST_FILE, sizeof(TEST_FILE)-1, 0},
+ {&fd_atcwd, abspath, TEST_FILE, sizeof(TEST_FILE)-1, 0},
};
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-static void verify_readlinkat(struct test_case *test)
+static void verify_readlinkat(unsigned int i)
{
char buf[1024];
+ struct tcase *tc = &tcases[i];
memset(buf, 0, sizeof(buf));
- TEST(readlinkat(*test->dir_fd, test->path, buf, sizeof(buf)));
-
- if (TEST_RETURN != test->exp_ret) {
- tst_resm(TFAIL | TTERRNO,
- "readlinkat() returned %ld, expected %d",
- TEST_RETURN, test->exp_ret);
- return;
- }
-
- if (TEST_ERRNO != test->exp_errno) {
- tst_resm(TFAIL | TTERRNO,
- "readlinkat() returned %ld, expected %d",
- TEST_RETURN, test->exp_ret);
- return;
- }
-
- if (test->exp_ret > 0 && strcmp(test->exp_buf, buf)) {
- tst_resm(TFAIL, "Unexpected buffer have '%s', expected '%s'",
- buf, test->exp_buf);
- return;
- }
-
- tst_resm(TPASS | TTERRNO, "readlinkat() returned %ld", TEST_RETURN);
-}
-
-int main(int ac, char **av)
-{
- int lc;
- int i;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- for (i = 0; i < TST_TOTAL; i++)
- verify_readlinkat(&test_cases[i]);
- }
-
- cleanup();
- tst_exit();
+ TST_EXP_POSITIVE(readlinkat(*tc->fd, tc->path, buf, sizeof(buf)),
+ "readlinkat(%d, %s, %s, %ld)",
+ *tc->fd, tc->path, buf, sizeof(buf));
}
static void setup(void)
{
- tst_tmpdir();
char *tmpdir = tst_get_tmpdir();
snprintf(abspath, sizeof(abspath), "%s/" TEST_SYMLINK, tmpdir);
free(tmpdir);
- fd = SAFE_OPEN(cleanup, TEST_FILE, O_CREAT, 0600);
- SAFE_SYMLINK(cleanup, TEST_FILE, TEST_SYMLINK);
- dir_fd = SAFE_OPEN(cleanup, ".", O_DIRECTORY);
-
- TEST_PAUSE;
+ file_fd = SAFE_OPEN(TEST_FILE, O_CREAT, 0600);
+ SAFE_SYMLINK(TEST_FILE, TEST_SYMLINK);
+ dir_fd = SAFE_OPEN(".", O_DIRECTORY);
}
static void cleanup(void)
{
- if (fd > 0 && close(fd))
- tst_resm(TWARN | TERRNO, "Failed to close fd");
-
- if (dir_fd > 0 && close(dir_fd))
- tst_resm(TWARN | TERRNO, "Failed to close dir_fd");
+ if (file_fd > -1)
+ SAFE_CLOSE(file_fd);
- tst_rmdir();
+ if (dir_fd > -1)
+ SAFE_CLOSE(dir_fd);
}
+
+static struct tst_test test = {
+ .test = verify_readlinkat,
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .tcnt = ARRAY_SIZE(tcases),
+};
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH 2/2] syscalls/readlinkat02: Convert to new API
2023-08-05 4:07 [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h Yang Xu
` (4 preceding siblings ...)
2023-08-05 4:08 ` [LTP] [PATCH 1/2] syscalls/readlinkat01: Convert to new API Yang Xu
@ 2023-08-05 4:08 ` Yang Xu
2023-08-10 14:29 ` [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h Cyril Hrubis
6 siblings, 0 replies; 13+ messages in thread
From: Yang Xu @ 2023-08-05 4:08 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
.../kernel/syscalls/readlinkat/readlinkat02.c | 125 +++++++-----------
1 file changed, 45 insertions(+), 80 deletions(-)
diff --git a/testcases/kernel/syscalls/readlinkat/readlinkat02.c b/testcases/kernel/syscalls/readlinkat/readlinkat02.c
index d30c1917a..cc2691715 100644
--- a/testcases/kernel/syscalls/readlinkat/readlinkat02.c
+++ b/testcases/kernel/syscalls/readlinkat/readlinkat02.c
@@ -1,39 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2014 Fujitsu Ltd.
+ * Copyright (c) Linux Test Project, 2003-2023
* Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
+ */
+
+/*\
+ * [Description]
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Test for EINVAL, ENOTDIR, EBADF errors.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
+ * - readlinkat() fails with EINVAL if the bufsiz is 0.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * - readlinkat() fails with EINVAL if the named file is not a symbolic link.
*
- */
-/*
- * Test Description:
- * Verify that,
- * 1. bufsiz is 0, EINVAL should be returned.
- * 2. The named file is not a symbolic link, EINVAL should be returned.
- * 3. The component of the path prefix is not a directory, ENOTDIR should be
- * returned.
- * 4. pathname is relative and dirfd is a file descriptor referring to a file
- * other than a directory, ENOTDIR should be returned.
+ * - readlinkat() fails with ENOTDIR if the component of the path prefix is
+ * not a directory.
+ *
+ * - readlinkat() fails with ENOTDIR if the pathname is relative and
+ * dirfd is a file descriptor referring to a fileother than a directory.
+ *
+ * - readlinkat() fails with EBADF if the file descriptor is invalid.
*/
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
+#include "lapi/fcntl.h"
#include "lapi/readlinkat.h"
#include "lapi/syscalls.h"
@@ -42,81 +33,55 @@
#define BUFF_SIZE 256
static int file_fd, dir_fd;
+static int fd_invalid = -1;
-static struct test_case_t {
- int *dirfd;
+static struct tcase {
+ int *fd;
const char *pathname;
size_t bufsiz;
int exp_errno;
-} test_cases[] = {
+} tcases[] = {
{&dir_fd, SYMLINK_FILE, 0, EINVAL},
{&dir_fd, TEST_FILE, BUFF_SIZE, EINVAL},
{&file_fd, SYMLINK_FILE, BUFF_SIZE, ENOTDIR},
{&dir_fd, "test_file/test_file", BUFF_SIZE, ENOTDIR},
+ {&fd_invalid, SYMLINK_FILE, BUFF_SIZE, EBADF},
};
-char *TCID = "readlinkat02";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-static void setup(void);
-static void cleanup(void);
-static void readlinkat_verify(const struct test_case_t *);
-
-int main(int argc, char **argv)
+static void verify_readlinkat(unsigned int i)
{
- int i, lc;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- setup();
+ char buf[BUFF_SIZE];
+ struct tcase *tc = &tcases[i];
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
- for (i = 0; i < TST_TOTAL; i++)
- readlinkat_verify(&test_cases[i]);
- }
+ memset(buf, 0, sizeof(buf));
- cleanup();
- tst_exit();
+ TST_EXP_FAIL(readlinkat(*tc->fd, tc->pathname, buf, tc->bufsiz),
+ tc->exp_errno, "readlinkat(%d, %s, NULL, %ld)",
+ *tc->fd, tc->pathname, tc->bufsiz);
}
static void setup(void)
{
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ dir_fd = SAFE_OPEN(".", O_RDONLY);
- TEST_PAUSE;
+ file_fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT, 0644);
- tst_tmpdir();
-
- dir_fd = SAFE_OPEN(cleanup, "./", O_RDONLY);
-
- file_fd = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_CREAT, 0644);
-
- SAFE_SYMLINK(cleanup, TEST_FILE, SYMLINK_FILE);
-}
-
-static void readlinkat_verify(const struct test_case_t *test)
-{
- char buf[BUFF_SIZE];
- TEST(readlinkat(*test->dirfd, test->pathname, buf, test->bufsiz));
-
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "readlinkat succeeded unexpectedly");
- return;
- }
-
- if (TEST_ERRNO == test->exp_errno) {
- tst_resm(TPASS | TTERRNO, "readlinkat failed as expected");
- } else {
- tst_resm(TFAIL | TTERRNO,
- "readlinkat failed unexpectedly; expected: %d - %s",
- test->exp_errno, strerror(test->exp_errno));
- }
+ SAFE_SYMLINK(TEST_FILE, SYMLINK_FILE);
}
static void cleanup(void)
{
- close(dir_fd);
- close(file_fd);
+ if (file_fd > -1)
+ SAFE_CLOSE(file_fd);
- tst_rmdir();
+ if (dir_fd > -1)
+ SAFE_CLOSE(dir_fd);
}
+
+static struct tst_test test = {
+ .test = verify_readlinkat,
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .tcnt = ARRAY_SIZE(tcases),
+};
--
2.39.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h
2023-08-05 4:07 [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h Yang Xu
` (5 preceding siblings ...)
2023-08-05 4:08 ` [LTP] [PATCH 2/2] syscalls/readlinkat02: " Yang Xu
@ 2023-08-10 14:29 ` Cyril Hrubis
2023-08-21 11:26 ` Yang Xu (Fujitsu)
6 siblings, 1 reply; 13+ messages in thread
From: Cyril Hrubis @ 2023-08-10 14:29 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> include/lapi/faccessat.h | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
> create mode 100644 include/lapi/faccessat.h
>
> diff --git a/include/lapi/faccessat.h b/include/lapi/faccessat.h
> new file mode 100644
> index 000000000..f3318fd7a
> --- /dev/null
> +++ b/include/lapi/faccessat.h
> @@ -0,0 +1,21 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
> + * Copyright (c) Linux Test Project, 2003-2023
> + * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
> + */
> +
> +#ifndef FACCESSAT_H
> +#define FACCESSAT_H
> +
> +#include <sys/types.h>
> +#include "lapi/syscalls.h"
> +
> +#ifndef HAVE_FACCESSAT
> +int faccessat(int dirfd, const char *pathname, int mode, int flags)
> +{
> + return tst_syscall(__NR_faccessat, dirfd, pathname, mode, flags);
> +}
> +#endif
I guess that this will not work without:
diff --git a/configure.ac b/configure.ac
index e4aa2cadf..7beca3d9f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -92,6 +92,7 @@ AC_CHECK_FUNCS_ONCE([ \
epoll_pwait \
epoll_pwait2 \
execveat \
+ faccessat \
fallocate \
fchownat \
fsconfig \
However looking at man faccessat, it was added into glibc 2.10 and since
the oldest glibc we support is 2.17 (see
doc/supported-kernel-libc-versions.txt) we can as well completely drop
this fallback definition.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 1/2] syscalls/faccessat201: Add new testcase
2023-08-05 4:07 ` [LTP] [PATCH 1/2] syscalls/faccessat201: Add new testcase Yang Xu
@ 2023-08-10 14:54 ` Cyril Hrubis
2023-08-11 11:59 ` Cyril Hrubis
2023-08-22 9:45 ` Yang Xu (Fujitsu)
0 siblings, 2 replies; 13+ messages in thread
From: Cyril Hrubis @ 2023-08-10 14:54 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
> diff --git a/include/lapi/faccessat2.h b/include/lapi/faccessat2.h
> new file mode 100644
> index 000000000..e8b27d6b1
> --- /dev/null
> +++ b/include/lapi/faccessat2.h
> @@ -0,0 +1,20 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
> + * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
> + */
> +
> +#ifndef LAPI_FACCESSAT2_H__
> +#define LAPI_FACCESSAT2_H__
> +
> +#include "tst_test.h"
> +#include "lapi/syscalls.h"
> +
> +#ifndef HAVE_FACCESSAT2
> +int faccessat2(int dirfd, const char *pathname, int mode, int flags)
> +{
> + return tst_syscall(__NR_faccessat2, dirfd, pathname, mode, flags);
> +}
> +#endif
> +
> +#endif /* LAPI_FACCESSAT2_H__ */
This one needs the configure check, and I would call the header just
faccessat.h.
> diff --git a/testcases/kernel/syscalls/faccessat2/faccessat201.c b/testcases/kernel/syscalls/faccessat2/faccessat201.c
> new file mode 100644
> index 000000000..658d1dd81
> --- /dev/null
> +++ b/testcases/kernel/syscalls/faccessat2/faccessat201.c
> @@ -0,0 +1,115 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
> + * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Check the basic functionality of faccessat2().
> + *
> + * Minimum Linux version required is v5.8.
> + */
> +
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include <pwd.h>
> +
> +#include "tst_test.h"
> +#include "lapi/syscalls.h"
> +#include "lapi/faccessat2.h"
> +
> +#define TESTUSER "nobody"
> +#define TESTDIR "faccessat2dir"
> +#define TESTFILE "faccessat2file"
> +#define RELPATH "faccessat2dir/faccessat2file"
> +#define TESTSYMLINK "faccessat2symlink"
There is a mix of tabs and spaces in this part that should be cleaned
up.
> +static int dir_fd = -1, bad_fd = -1;
> +static int atcwd_fd = AT_FDCWD;
> +static char *filepaths[4];
> +static char abs_path[128];
> +static struct passwd *ltpuser;
> +
> +static struct tcase {
> + int *fd;
> + char **filename;
> + int flags;
> + int exp_errno;
> +} tcases[] = {
> + {&dir_fd, &filepaths[0], 0, 0},
> + {&bad_fd, &filepaths[1], 0, 0},
> + {&atcwd_fd, &filepaths[2], 0, 0},
> + {&dir_fd, &filepaths[0], AT_EACCESS, 0},
> + {&bad_fd, &filepaths[1], AT_EACCESS, 0},
> + {&atcwd_fd, &filepaths[2], AT_EACCESS, 0},
> + {&dir_fd, &filepaths[0], AT_EACCESS, EACCES},
> + {&bad_fd, &filepaths[1], AT_EACCESS, EACCES},
> + {&atcwd_fd, &filepaths[2], AT_EACCESS, EACCES},
> + {&atcwd_fd, &filepaths[3], AT_SYMLINK_NOFOLLOW, 0},
> +};
> +
> +static void verify_faccessat2(unsigned int i)
> +{
> + struct tcase *tc = &tcases[i];
> +
> + if (tc->exp_errno == EACCES) {
> + if (SAFE_FORK() == 0) {
> + SAFE_SETUID(ltpuser->pw_uid);
> + TST_EXP_FAIL(faccessat2(*tc->fd, *tc->filename, R_OK, tc->flags),
> + tc->exp_errno, "faccessat2(%d, %s, R_OK, %d) as %s",
> + *tc->fd, *tc->filename, tc->flags, TESTUSER);
> + }
> +
> + tst_reap_children();
I would just put the EACCESS tests to a separate testcase, which would
make the test more straightforward and easier to read.
> + } else {
> + TST_EXP_PASS(faccessat2(*tc->fd, *tc->filename, R_OK, tc->flags),
> + "faccessat2(%d, %s, R_OK, %d) as root",
> + *tc->fd, *tc->filename, tc->flags);
> + }
> +}
> +
> +static void setup(void)
> +{
> + char *tmpdir_path = tst_get_tmpdir();
> +
> + sprintf(abs_path, "%s/%s", tmpdir_path, RELPATH);
> + free(tmpdir_path);
> +
> + SAFE_MKDIR(TESTDIR, 0666);
> + dir_fd = SAFE_OPEN(TESTDIR, O_DIRECTORY);
> + SAFE_TOUCH(abs_path, 0444, NULL);
> + SAFE_SYMLINK(abs_path, TESTSYMLINK);
> +
> + filepaths[0] = TESTFILE;
> + filepaths[1] = abs_path;
> + filepaths[2] = RELPATH;
> + filepaths[3] = TESTSYMLINK;
> +
> + ltpuser = SAFE_GETPWNAM(TESTUSER);
> +}
> +
> +static void cleanup(void)
> +{
> + if (dir_fd > 0)
> + SAFE_CLOSE(dir_fd);
> +}
> +
> +static struct tst_test test = {
> + .test = verify_faccessat2,
> + .tcnt = ARRAY_SIZE(tcases),
> + .setup = setup,
> + .cleanup = cleanup,
> + .bufs = (struct tst_buffers []) {
> + {&filepaths[0], .size = sizeof(*filepaths[0])},
> + {&filepaths[1], .size = sizeof(*filepaths[1])},
> + {&filepaths[2], .size = sizeof(*filepaths[2])},
> + {&filepaths[3], .size = sizeof(*filepaths[3])},
> + {<puser, .size = sizeof(ltpuser)},
Why do we allocate anything here when we replace the pointers in the
test setup anyways?
If anything it would make sense to allocate the buffers in the test
setup instead of using static strings there. Also filepath[x] way less
readable than actually giving the variables proper names such as
abs_path.
I guess that we can as well add a helper to the buffer library such as:
diff --git a/include/tst_buffers.h b/include/tst_buffers.h
index d19ac8cf0..a12d70a62 100644
--- a/include/tst_buffers.h
+++ b/include/tst_buffers.h
@@ -46,6 +46,11 @@ char *tst_strdup(const char *str);
*/
void *tst_alloc(size_t size);
+/*
+ * Strdup into a guarded buffer.
+ */
+char *tst_strdup(const char *str);
+
/*
* Allocates iovec structure including the buffers.
*
diff --git a/lib/tst_buffers.c b/lib/tst_buffers.c
index b8b597a12..4488f458e 100644
--- a/lib/tst_buffers.c
+++ b/lib/tst_buffers.c
@@ -76,6 +76,13 @@ void *tst_alloc(size_t size)
return ret + map->buf_shift;
}
+char *tst_strup(const char *str)
+{
+ char *ret = tst_alloc(strlen(str) + 1);
+
+ return strcpy(ret, str);
+}
+
static int count_iovec(int *sizes)
{
int ret = 0;
And slightly more complicated would be addition of tst_aprintf() that
would printf into buffer allocated by tst_alloc(). I will send a patch
that adds this tomorrow.
Once that is done we can use these in the test setup such as:
static char *abs_path;
static char *testfile;
static struct tcase {
int *fd;
char **filename;
int flags;
int exp_errno;
} tcases[] = {
{..., &abs_path, ...},
{..., &testfile, ...},
}
static void setup(void)
{
...
testfile = tst_strdup(TESTFILE);
abs_path = tst_aprintf(abs_path, "%s/%s", tmpdir_path, TESTFILE);
...
}
Which allocates the exact sized guarded buffers so that the canaries are
exaclty after end of the data, not at the end of the rather large
buffer.
We can't pre-allocate buffers in the tst_test structure for data whose
size is not known in advance, which is the case for the tmpdir_path.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 1/2] syscalls/faccessat201: Add new testcase
2023-08-10 14:54 ` Cyril Hrubis
@ 2023-08-11 11:59 ` Cyril Hrubis
2023-08-22 9:50 ` Yang Xu (Fujitsu)
2023-08-22 9:45 ` Yang Xu (Fujitsu)
1 sibling, 1 reply; 13+ messages in thread
From: Cyril Hrubis @ 2023-08-11 11:59 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
> Why do we allocate anything here when we replace the pointers in the
> test setup anyways?
>
> If anything it would make sense to allocate the buffers in the test
> setup instead of using static strings there. Also filepath[x] way less
> readable than actually giving the variables proper names such as
> abs_path.
And it turns out that tst_strdup() was already there, however I've send
a patch to add .str member to the tst_buffers structure as well as
tst_aprintf(). The usage should be clear from the few tests I've
converted to use the new API.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h
2023-08-10 14:29 ` [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h Cyril Hrubis
@ 2023-08-21 11:26 ` Yang Xu (Fujitsu)
0 siblings, 0 replies; 13+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-08-21 11:26 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp@lists.linux.it
Hi Cyril
> Hi!
>> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
>> ---
>> include/lapi/faccessat.h | 21 +++++++++++++++++++++
>> 1 file changed, 21 insertions(+)
>> create mode 100644 include/lapi/faccessat.h
>>
>> diff --git a/include/lapi/faccessat.h b/include/lapi/faccessat.h
>> new file mode 100644
>> index 000000000..f3318fd7a
>> --- /dev/null
>> +++ b/include/lapi/faccessat.h
>> @@ -0,0 +1,21 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
>> + * Copyright (c) Linux Test Project, 2003-2023
>> + * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
>> + */
>> +
>> +#ifndef FACCESSAT_H
>> +#define FACCESSAT_H
>> +
>> +#include <sys/types.h>
>> +#include "lapi/syscalls.h"
>> +
>> +#ifndef HAVE_FACCESSAT
>> +int faccessat(int dirfd, const char *pathname, int mode, int flags)
>> +{
>> + return tst_syscall(__NR_faccessat, dirfd, pathname, mode, flags);
>> +}
>> +#endif
>
> I guess that this will not work without:
>
> diff --git a/configure.ac b/configure.ac
> index e4aa2cadf..7beca3d9f 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -92,6 +92,7 @@ AC_CHECK_FUNCS_ONCE([ \
> epoll_pwait \
> epoll_pwait2 \
> execveat \
> + faccessat \
> fallocate \
> fchownat \
> fsconfig \
>
>
> However looking at man faccessat, it was added into glibc 2.10 and since
> the oldest glibc we support is 2.17 (see
> doc/supported-kernel-libc-versions.txt) we can as well completely drop
> this fallback definition.
>
I agree with your suggestion, and I will remove faccessat.h in the v2
version. After this is merged, I will also drop those unnecessary
fallback definition.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 1/2] syscalls/faccessat201: Add new testcase
2023-08-10 14:54 ` Cyril Hrubis
2023-08-11 11:59 ` Cyril Hrubis
@ 2023-08-22 9:45 ` Yang Xu (Fujitsu)
1 sibling, 0 replies; 13+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-08-22 9:45 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp@lists.linux.it
Hi Cyril
> Hi!
>> diff --git a/include/lapi/faccessat2.h b/include/lapi/faccessat2.h
>> new file mode 100644
>> index 000000000..e8b27d6b1
>> --- /dev/null
>> +++ b/include/lapi/faccessat2.h
>> @@ -0,0 +1,20 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
>> + * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
>> + */
>> +
>> +#ifndef LAPI_FACCESSAT2_H__
>> +#define LAPI_FACCESSAT2_H__
>> +
>> +#include "tst_test.h"
>> +#include "lapi/syscalls.h"
>> +
>> +#ifndef HAVE_FACCESSAT2
>> +int faccessat2(int dirfd, const char *pathname, int mode, int flags)
>> +{
>> + return tst_syscall(__NR_faccessat2, dirfd, pathname, mode, flags);
>> +}
>> +#endif
>> +
>> +#endif /* LAPI_FACCESSAT2_H__ */
> This one needs the configure check, and I would call the header just
> faccessat.h.
i will update it.
>> diff --git a/testcases/kernel/syscalls/faccessat2/faccessat201.c b/testcases/kernel/syscalls/faccessat2/faccessat201.c
>> new file mode 100644
>> index 000000000..658d1dd81
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/faccessat2/faccessat201.c
>> @@ -0,0 +1,115 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (c) 2023 FUJITSU LIMITED. All rights reserved.
>> + * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
>> + */
>> +
>> +/*\
>> + * [Description]
>> + *
>> + * Check the basic functionality of faccessat2().
>> + *
>> + * Minimum Linux version required is v5.8.
>> + */
>> +
>> +#include <stdlib.h>
>> +#include <stdio.h>
>> +#include <pwd.h>
>> +
>> +#include "tst_test.h"
>> +#include "lapi/syscalls.h"
>> +#include "lapi/faccessat2.h"
>> +
>> +#define TESTUSER "nobody"
>> +#define TESTDIR "faccessat2dir"
>> +#define TESTFILE "faccessat2file"
>> +#define RELPATH "faccessat2dir/faccessat2file"
>> +#define TESTSYMLINK "faccessat2symlink"
> There is a mix of tabs and spaces in this part that should be cleaned
> up.
My mistake, I will correct it.
>> +static int dir_fd = -1, bad_fd = -1;
>> +static int atcwd_fd = AT_FDCWD;
>> +static char *filepaths[4];
>> +static char abs_path[128];
>> +static struct passwd *ltpuser;
>> +
>> +static struct tcase {
>> + int *fd;
>> + char **filename;
>> + int flags;
>> + int exp_errno;
>> +} tcases[] = {
>> + {&dir_fd, &filepaths[0], 0, 0},
>> + {&bad_fd, &filepaths[1], 0, 0},
>> + {&atcwd_fd, &filepaths[2], 0, 0},
>> + {&dir_fd, &filepaths[0], AT_EACCESS, 0},
>> + {&bad_fd, &filepaths[1], AT_EACCESS, 0},
>> + {&atcwd_fd, &filepaths[2], AT_EACCESS, 0},
>> + {&dir_fd, &filepaths[0], AT_EACCESS, EACCES},
>> + {&bad_fd, &filepaths[1], AT_EACCESS, EACCES},
>> + {&atcwd_fd, &filepaths[2], AT_EACCESS, EACCES},
>> + {&atcwd_fd, &filepaths[3], AT_SYMLINK_NOFOLLOW, 0},
>> +};
>> +
>> +static void verify_faccessat2(unsigned int i)
>> +{
>> + struct tcase *tc = &tcases[i];
>> +
>> + if (tc->exp_errno == EACCES) {
>> + if (SAFE_FORK() == 0) {
>> + SAFE_SETUID(ltpuser->pw_uid);
>> + TST_EXP_FAIL(faccessat2(*tc->fd, *tc->filename, R_OK, tc->flags),
>> + tc->exp_errno, "faccessat2(%d, %s, R_OK, %d) as %s",
>> + *tc->fd, *tc->filename, tc->flags, TESTUSER);
>> + }
>> +
>> + tst_reap_children();
> I would just put the EACCESS tests to a separate testcase, which would
> make the test more straightforward and easier to read.
ok.
>> + } else {
>> + TST_EXP_PASS(faccessat2(*tc->fd, *tc->filename, R_OK, tc->flags),
>> + "faccessat2(%d, %s, R_OK, %d) as root",
>> + *tc->fd, *tc->filename, tc->flags);
>> + }
>> +}
>> +
>> +static void setup(void)
>> +{
>> + char *tmpdir_path = tst_get_tmpdir();
>> +
>> + sprintf(abs_path, "%s/%s", tmpdir_path, RELPATH);
>> + free(tmpdir_path);
>> +
>> + SAFE_MKDIR(TESTDIR, 0666);
>> + dir_fd = SAFE_OPEN(TESTDIR, O_DIRECTORY);
>> + SAFE_TOUCH(abs_path, 0444, NULL);
>> + SAFE_SYMLINK(abs_path, TESTSYMLINK);
>> +
>> + filepaths[0] = TESTFILE;
>> + filepaths[1] = abs_path;
>> + filepaths[2] = RELPATH;
>> + filepaths[3] = TESTSYMLINK;
>> +
>> + ltpuser = SAFE_GETPWNAM(TESTUSER);
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> + if (dir_fd > 0)
>> + SAFE_CLOSE(dir_fd);
>> +}
>> +
>> +static struct tst_test test = {
>> + .test = verify_faccessat2,
>> + .tcnt = ARRAY_SIZE(tcases),
>> + .setup = setup,
>> + .cleanup = cleanup,
>> + .bufs = (struct tst_buffers []) {
>> + {&filepaths[0], .size = sizeof(*filepaths[0])},
>> + {&filepaths[1], .size = sizeof(*filepaths[1])},
>> + {&filepaths[2], .size = sizeof(*filepaths[2])},
>> + {&filepaths[3], .size = sizeof(*filepaths[3])},
>> + {<puser, .size = sizeof(ltpuser)},
> Why do we allocate anything here when we replace the pointers in the
> test setup anyways?
>
> If anything it would make sense to allocate the buffers in the test
> setup instead of using static strings there. Also filepath[x] way less
> readable than actually giving the variables proper names such as
> abs_path.
>
> I guess that we can as well add a helper to the buffer library such as:
>
> diff --git a/include/tst_buffers.h b/include/tst_buffers.h
> index d19ac8cf0..a12d70a62 100644
> --- a/include/tst_buffers.h
> +++ b/include/tst_buffers.h
> @@ -46,6 +46,11 @@ char *tst_strdup(const char *str);
> */
> void *tst_alloc(size_t size);
>
> +/*
> + * Strdup into a guarded buffer.
> + */
> +char *tst_strdup(const char *str);
> +
> /*
> * Allocates iovec structure including the buffers.
> *
> diff --git a/lib/tst_buffers.c b/lib/tst_buffers.c
> index b8b597a12..4488f458e 100644
> --- a/lib/tst_buffers.c
> +++ b/lib/tst_buffers.c
> @@ -76,6 +76,13 @@ void *tst_alloc(size_t size)
> return ret + map->buf_shift;
> }
>
> +char *tst_strup(const char *str)
> +{
> + char *ret = tst_alloc(strlen(str) + 1);
> +
> + return strcpy(ret, str);
> +}
> +
> static int count_iovec(int *sizes)
> {
> int ret = 0;
>
>
> And slightly more complicated would be addition of tst_aprintf() that
> would printf into buffer allocated by tst_alloc(). I will send a patch
> that adds this tomorrow.
>
> Once that is done we can use these in the test setup such as:
>
> static char *abs_path;
> static char *testfile;
>
> static struct tcase {
> int *fd;
> char **filename;
> int flags;
> int exp_errno;
> } tcases[] = {
> {..., &abs_path, ...},
> {..., &testfile, ...},
> }
>
> static void setup(void)
> {
> ...
>
> testfile = tst_strdup(TESTFILE);
> abs_path = tst_aprintf(abs_path, "%s/%s", tmpdir_path, TESTFILE);
>
> ...
> }
>
> Which allocates the exact sized guarded buffers so that the canaries are
> exaclty after end of the data, not at the end of the rather large
> buffer.
>
> We can't pre-allocate buffers in the tst_test structure for data whose
> size is not known in advance, which is the case for the tmpdir_path.
I have overlooked these issues and will make modifications based on your
suggestions.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH 1/2] syscalls/faccessat201: Add new testcase
2023-08-11 11:59 ` Cyril Hrubis
@ 2023-08-22 9:50 ` Yang Xu (Fujitsu)
0 siblings, 0 replies; 13+ messages in thread
From: Yang Xu (Fujitsu) @ 2023-08-22 9:50 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp@lists.linux.it
Hi Cyril
> Hi!
>> Why do we allocate anything here when we replace the pointers in the
>> test setup anyways?
>>
>> If anything it would make sense to allocate the buffers in the test
>> setup instead of using static strings there. Also filepath[x] way less
>> readable than actually giving the variables proper names such as
>> abs_path.
> And it turns out that tst_strdup() was already there, however I've send
> a patch to add .str member to the tst_buffers structure as well as
> tst_aprintf(). The usage should be clear from the few tests I've
> converted to use the new API.
I see, I will use these in the v2 version.Thank you for your suggestion.
Best Regards
Yang Xu
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-08-22 9:51 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-05 4:07 [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h Yang Xu
2023-08-05 4:07 ` [LTP] [PATCH 2/3] syscalls/faccessat01: Convert to new API Yang Xu
2023-08-05 4:07 ` [LTP] [PATCH 3/3] syscalls/faccessat02: Move errnos check to faccessat02 Yang Xu
2023-08-05 4:07 ` [LTP] [PATCH 1/2] syscalls/faccessat201: Add new testcase Yang Xu
2023-08-10 14:54 ` Cyril Hrubis
2023-08-11 11:59 ` Cyril Hrubis
2023-08-22 9:50 ` Yang Xu (Fujitsu)
2023-08-22 9:45 ` Yang Xu (Fujitsu)
2023-08-05 4:08 ` [LTP] [PATCH 2/2] syscalls/faccessat202: " Yang Xu
2023-08-05 4:08 ` [LTP] [PATCH 1/2] syscalls/readlinkat01: Convert to new API Yang Xu
2023-08-05 4:08 ` [LTP] [PATCH 2/2] syscalls/readlinkat02: " Yang Xu
2023-08-10 14:29 ` [LTP] [PATCH 1/3] include/faccessat.h: Add header file faccessat.h Cyril Hrubis
2023-08-21 11:26 ` Yang Xu (Fujitsu)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox