[LTP] [PATCH 3/3] syscalls/faccessat02: Move errnos check to faccessat02
Yang Xu
xuyang2018.jy@fujitsu.com
Sat Aug 5 06:07:58 CEST 2023
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
More information about the ltp
mailing list