From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3] fcntl40.c: Test fcntl using F_CREATED_QUERY
Date: Tue, 1 Apr 2025 03:56:42 -0400 [thread overview]
Message-ID: <20250401075642.16656-1-wegao@suse.com> (raw)
In-Reply-To: <20250301063134.14515-1-wegao@suse.com>
Signed-off-by: Wei Gao <wegao@suse.com>
This is new test case for fcntl using new F_CREATED_QUERY operation.
Based on a kernel selftest.
Signed-off-by: Wei Gao <wegao@suse.com>
---
include/lapi/fcntl.h | 8 ++++
runtest/syscalls | 2 +
testcases/kernel/syscalls/fcntl/.gitignore | 2 +
testcases/kernel/syscalls/fcntl/fcntl40.c | 52 ++++++++++++++++++++++
4 files changed, 64 insertions(+)
create mode 100644 testcases/kernel/syscalls/fcntl/fcntl40.c
diff --git a/include/lapi/fcntl.h b/include/lapi/fcntl.h
index 761331798..7c0502488 100644
--- a/include/lapi/fcntl.h
+++ b/include/lapi/fcntl.h
@@ -154,6 +154,14 @@
# define RENAME_WHITEOUT (1 << 2)
#endif
+#ifndef F_LINUX_SPECIFIC_BASE
+#define F_LINUX_SPECIFIC_BASE 1024
+#endif
+
+#ifndef F_CREATED_QUERY
+#define F_CREATED_QUERY (F_LINUX_SPECIFIC_BASE + 4)
+#endif
+
/* splice, vmsplice, tee */
#ifndef SPLICE_F_NONBLOCK
diff --git a/runtest/syscalls b/runtest/syscalls
index 5cd1ae656..5ba2315d1 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -364,6 +364,8 @@ fcntl38 fcntl38
fcntl38_64 fcntl38_64
fcntl39 fcntl39
fcntl39_64 fcntl39_64
+fcntl40 fcntl40
+fcntl40_64 fcntl40_64
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/testcases/kernel/syscalls/fcntl/.gitignore b/testcases/kernel/syscalls/fcntl/.gitignore
index e60176973..e3486ee45 100644
--- a/testcases/kernel/syscalls/fcntl/.gitignore
+++ b/testcases/kernel/syscalls/fcntl/.gitignore
@@ -72,3 +72,5 @@
/fcntl38_64
/fcntl39
/fcntl39_64
+/fcntl40
+/fcntl40_64
diff --git a/testcases/kernel/syscalls/fcntl/fcntl40.c b/testcases/kernel/syscalls/fcntl/fcntl40.c
new file mode 100644
index 000000000..882e0163f
--- /dev/null
+++ b/testcases/kernel/syscalls/fcntl/fcntl40.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE Wei Gao <wegao@suse.com>
+ */
+
+/*\
+ * Basic test for fcntl using F_CREATED_QUERY.
+ * Verify if the fcntl() syscall is recognizing whether a file has been
+ * created or not via O_CREAT when O_CLOEXEC is also used.
+ *
+ * Test is based on a kernel selftests.
+ */
+
+#include "lapi/fcntl.h"
+#include "tst_test.h"
+
+#define TEST_NAME "LTP_FCNTL_CREATED_QUERY_TEST"
+
+static void verify_fcntl(void)
+{
+ int fd;
+
+ fd = SAFE_OPEN("/dev/null", O_RDONLY | O_CLOEXEC);
+
+ /* We didn't create "/dev/null". */
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
+ SAFE_CLOSE(fd);
+
+ fd = SAFE_OPEN(TEST_NAME, O_CREAT | O_RDONLY | O_CLOEXEC, 0600);
+
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 1);
+ SAFE_CLOSE(fd);
+
+ fd = SAFE_OPEN(TEST_NAME, O_RDONLY | O_CLOEXEC);
+
+ /* We're opening it again, so no positive creation check. */
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
+ SAFE_CLOSE(fd);
+ SAFE_UNLINK(TEST_NAME);
+
+ /* tst_res(TPASS, "fcntl F_CREATED_QUERY check pass"); */
+}
+
+static struct tst_test test = {
+ .test_all = verify_fcntl,
+ .needs_tmpdir = 1,
+ .min_kver = "6.12",
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "d0fe8920cbe4"},
+ {}
+ }
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-04-01 7:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-28 11:44 [LTP] [PATCH v1] fcntl40.c: Test fcntl using F_CREATED_QUERY Wei Gao via ltp
2025-02-20 12:34 ` Andrea Cervesato via ltp
2025-03-01 6:31 ` [LTP] [PATCH v2] " Wei Gao via ltp
2025-03-03 8:24 ` Andrea Cervesato via ltp
2025-04-01 7:56 ` Wei Gao via ltp [this message]
2025-04-02 10:29 ` [LTP] [PATCH v3] " Cyril Hrubis
2025-04-03 6:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
2025-04-07 11:31 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250401075642.16656-1-wegao@suse.com \
--to=ltp@lists.linux.it \
--cc=wegao@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.