public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Edward Liaw via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: kernel-team@android.com
Subject: [LTP] [PATCH] close_range: check for kernel support below 5.9
Date: Tue, 31 Jan 2023 00:25:32 +0000	[thread overview]
Message-ID: <20230131002532.459456-1-edliaw@google.com> (raw)

Check for close_range syscall support in the kernel before running
close_range01 and close_range02 tests.

Signed-off-by: Edward Liaw <edliaw@google.com>
---
 include/lapi/close_range.h                          | 13 +++++++++++++
 .../kernel/syscalls/close_range/close_range01.c     |  2 ++
 .../kernel/syscalls/close_range/close_range02.c     |  1 +
 3 files changed, 16 insertions(+)

diff --git a/include/lapi/close_range.h b/include/lapi/close_range.h
index 19db52d3d..0e464bb30 100644
--- a/include/lapi/close_range.h
+++ b/include/lapi/close_range.h
@@ -25,4 +25,17 @@ static inline int close_range(unsigned int fd, unsigned int max_fd,
 	return tst_syscall(__NR_close_range, fd, max_fd, flags);
 }
 # endif
+
+static inline void close_range_supported_by_kernel(void)
+{
+	long ret;
+
+	if ((tst_kvercmp(5, 9, 0)) < 0) {
+		/* Check if the syscall is backported on an older kernel */
+		ret = syscall(__NR_close_range, 1, 0, 0);
+		if (ret == -1 && errno == ENOSYS)
+			tst_brk(TCONF, "Test not supported on kernel version < v5.9");
+	}
+}
+
 #endif	/* LAPI_CLOSE_RANGE_H__ */
diff --git a/testcases/kernel/syscalls/close_range/close_range01.c b/testcases/kernel/syscalls/close_range/close_range01.c
index 30bb600b6..072bbab66 100644
--- a/testcases/kernel/syscalls/close_range/close_range01.c
+++ b/testcases/kernel/syscalls/close_range/close_range01.c
@@ -53,6 +53,8 @@ static inline void do_close_range(unsigned int fd, unsigned int max_fd,
 
 static void setup(void)
 {
+	close_range_supported_by_kernel();
+
 	struct rlimit nfd;
 
 	SAFE_GETRLIMIT(RLIMIT_NOFILE, &nfd);
diff --git a/testcases/kernel/syscalls/close_range/close_range02.c b/testcases/kernel/syscalls/close_range/close_range02.c
index aec899261..2aa6d2c9f 100644
--- a/testcases/kernel/syscalls/close_range/close_range02.c
+++ b/testcases/kernel/syscalls/close_range/close_range02.c
@@ -111,4 +111,5 @@ static struct tst_test test = {
 	.tcnt = 6,
 	.forks_child = 1,
 	.test = run,
+	.setup = close_range_supported_by_kernel,
 };
-- 
2.39.1.456.gfc5497dd1b-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2023-01-31  0:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-31  0:25 Edward Liaw via ltp [this message]
2023-02-01 12:24 ` [LTP] [PATCH] close_range: check for kernel support below 5.9 Petr Vorel
2023-02-01 18:31   ` Edward Liaw via ltp
2023-02-02  7:49     ` Petr Vorel
2023-02-02  8:11       ` Jan Stancek
2023-02-02  8:20         ` Petr Vorel
2023-02-03  2:03           ` Edward Liaw via ltp
2023-02-03 10:18             ` Petr Vorel
2023-02-03 10:25               ` Petr Vorel
2023-02-03 19:30                 ` Edward Liaw via ltp
2023-02-06  5:36                   ` Petr Vorel
2023-02-06 18:38                     ` Edward Liaw via ltp
2023-02-03  8:30 ` Li Wang

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=20230131002532.459456-1-edliaw@google.com \
    --to=ltp@lists.linux.it \
    --cc=edliaw@google.com \
    --cc=kernel-team@android.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox