[LTP] [PATCH v2 2/2] syscalls/faccessat02: Move errnos check to faccessat02

Yang Xu xuyang2018.jy@fujitsu.com
Mon Aug 21 13:35:55 CEST 2023


Check 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   | 67 +++++++++++++++++++
 3 files changed, 69 insertions(+)
 create mode 100644 testcases/kernel/syscalls/faccessat/faccessat02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 119710d63..7f30d87ca 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..1add695c1
--- /dev/null
+++ b/testcases/kernel/syscalls/faccessat/faccessat02.c
@@ -0,0 +1,67 @@
+// 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"
+
+#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



More information about the ltp mailing list