[LTP] [PATCH v1 2/3] syscalls/dup206: Add a test when newfd equals oldfd
Yang Xu
xuyang2018.jy@fujitsu.com
Wed Sep 22 07:39:41 CEST 2021
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/dup2/.gitignore | 1 +
testcases/kernel/syscalls/dup2/dup206.c | 51 +++++++++++++++++++++++
3 files changed, 53 insertions(+)
create mode 100644 testcases/kernel/syscalls/dup2/dup206.c
diff --git a/runtest/syscalls b/runtest/syscalls
index 29d7752c7..068fba456 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -153,6 +153,7 @@ dup202 dup202
dup203 dup203
dup204 dup204
dup205 dup205
+dup206 dup206
dup3_01 dup3_01
dup3_02 dup3_02
diff --git a/testcases/kernel/syscalls/dup2/.gitignore b/testcases/kernel/syscalls/dup2/.gitignore
index 6c4685b80..e2e008b58 100644
--- a/testcases/kernel/syscalls/dup2/.gitignore
+++ b/testcases/kernel/syscalls/dup2/.gitignore
@@ -3,3 +3,4 @@
/dup203
/dup204
/dup205
+/dup206
diff --git a/testcases/kernel/syscalls/dup2/dup206.c b/testcases/kernel/syscalls/dup2/dup206.c
new file mode 100644
index 000000000..e5074ea83
--- /dev/null
+++ b/testcases/kernel/syscalls/dup2/dup206.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * If oldfd is a valid file descriptor, and newfd has the same value as oldfd,
+ * then dup2() does nothing, and returns newfd.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include "tst_test.h"
+
+static int fd = -1;
+
+static void verify_dup2(void)
+{
+ TST_EXP_FD_SILENT(dup2(fd, fd), "dup2(%d, %d)", fd, fd);
+
+ if (TST_RET != fd) {
+ tst_res(TFAIL, "dup2(%d, %d) returns wrong newfd(%ld)", fd, fd, TST_RET);
+ SAFE_CLOSE(TST_RET);
+ return;
+ }
+ tst_res(TPASS, "dup2(%d, %d) returns newfd(%d)", fd, fd, fd);
+}
+
+static void setup(void)
+{
+ char testfile[40];
+
+ sprintf(testfile, "dup206.%d", getpid());
+ fd = SAFE_OPEN(testfile, O_RDWR | O_CREAT, 0666);
+}
+
+static void cleanup(void)
+{
+ if (fd > -1)
+ SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_dup2,
+};
--
2.23.0
More information about the ltp
mailing list