From: Amir Goldstein <amir73il@gmail.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 06/10] syscalls/fcntl: New test for F_NOTIFY (dnotify)
Date: Wed, 9 Sep 2020 20:57:03 +0300 [thread overview]
Message-ID: <20200909175707.10670-7-amir73il@gmail.com> (raw)
In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com>
Check that signal is delivered for both watching parent and watching subdir
when subdir metadata changes.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
runtest/syscalls | 2 +
testcases/kernel/syscalls/fcntl/fcntl38.c | 96 +++++++++++++++++++++++
2 files changed, 98 insertions(+)
create mode 100644 testcases/kernel/syscalls/fcntl/fcntl38.c
diff --git a/runtest/syscalls b/runtest/syscalls
index dc0ca5626..376a2bc6b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -316,6 +316,8 @@ fcntl36 fcntl36
fcntl36_64 fcntl36_64
fcntl37 fcntl37
fcntl37_64 fcntl37_64
+fcntl38 fcntl38
+fcntl38_64 fcntl38_64
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/testcases/kernel/syscalls/fcntl/fcntl38.c b/testcases/kernel/syscalls/fcntl/fcntl38.c
new file mode 100644
index 000000000..6185d3209
--- /dev/null
+++ b/testcases/kernel/syscalls/fcntl/fcntl38.c
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2020 CTERA Networks. All Rights Reserved.
+ *
+ * Started by Amir Goldstein <amir73il@gmail.com>
+ *
+ * DESCRIPTION
+ * Check that dnotify event is reported to both parent and subdir
+ */
+
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "tst_test.h"
+#include "lapi/fcntl.h"
+
+#define TEST_DIR "test_dir"
+
+#define TEST_SIG SIGRTMIN+1
+
+static int parent_fd, subdir_fd;
+static int got_parent_event, got_subdir_event;
+
+static void dnotify_handler(int sig, siginfo_t *si, void *data __attribute__((unused)))
+{
+ if (si->si_fd == parent_fd)
+ got_parent_event = 1;
+ else if (si->si_fd == subdir_fd)
+ got_subdir_event = 1;
+ else
+ tst_brk(TBROK, "Got unexpected signal %d with si_fd %d", sig, si->si_fd);
+}
+
+static void setup_dnotify(int fd)
+{
+ struct sigaction act;
+
+ act.sa_sigaction = dnotify_handler;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = SA_SIGINFO;
+ sigaction(TEST_SIG, &act, NULL);
+
+ TEST(fcntl(fd, F_SETSIG, TEST_SIG));
+ if (TST_RET != 0) {
+ tst_brk(TBROK, "F_SETSIG failed errno = %d : %s",
+ TST_ERR, strerror(TST_ERR));
+ }
+ TEST(fcntl(fd, F_NOTIFY, DN_ATTRIB|DN_MULTISHOT));
+ if (TST_RET != 0) {
+ tst_brk(TBROK, "F_NOTIFY failed errno = %d : %s",
+ TST_ERR, strerror(TST_ERR));
+ }
+}
+
+static void verify_dnotify(void)
+{
+ parent_fd = SAFE_OPEN(".", O_RDONLY);
+ subdir_fd = SAFE_OPEN(TEST_DIR, O_RDONLY);
+ /* Watch "." and its children for changes */
+ setup_dnotify(parent_fd);
+ /* Also watch subdir itself for changes */
+ setup_dnotify(subdir_fd);
+ /* Generate DN_ATTRIB event on subdir that should send a signal on both fds */
+ SAFE_CHMOD(TEST_DIR, 0755);
+ if (got_parent_event)
+ tst_res(TPASS, "Got event on parent as expected");
+ else
+ tst_res(TFAIL, "Missing event on parent");
+ if (got_subdir_event)
+ tst_res(TPASS, "Got event on subdir as expected");
+ else
+ tst_res(TFAIL, "Missing event on subdir");
+ SAFE_CLOSE(parent_fd);
+ SAFE_CLOSE(subdir_fd);
+}
+
+static void setup(void)
+{
+ SAFE_MKDIR(TEST_DIR, 00700);
+}
+
+static void cleanup(void)
+{
+ if (parent_fd > 0)
+ SAFE_CLOSE(parent_fd);
+ if (subdir_fd > 0)
+ SAFE_CLOSE(subdir_fd);
+}
+
+static struct tst_test test = {
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_dnotify,
+};
--
2.17.1
next prev parent reply other threads:[~2020-09-09 17:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 17:56 [LTP] [PATCH 00/10] Fanotify tests for v5.9 Amir Goldstein
2020-09-09 17:56 ` [LTP] [PATCH 01/10] syscalls/fanotify14: Test cases for FAN_REPORT_DFID_NAME Amir Goldstein
2020-09-09 17:56 ` [LTP] [PATCH 02/10] syscalls/fanotify16: Adjust test to use FAN_REPORT_DFID_NAME Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 03/10] syscalls/fanotify16: Test more event types with name Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 04/10] syscalls/fanotify16: Add test cases more init flag combinations Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 05/10] syscalls/fanotify16: Verify child fid info Amir Goldstein
2020-09-09 17:57 ` Amir Goldstein [this message]
2020-09-09 17:57 ` [LTP] [PATCH 07/10] syscalls/inotify: New test for watches on both parent and child Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 08/10] syscalls/fanotify09: Add test case with parent and subdir marks Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 09/10] syscalls/fanotify10: Test with group flag FAN_REPORT_NAME Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 10/10] syscalls/fanotify10: Add test cases for merge with ignored mask on directory Amir Goldstein
2020-09-10 8:16 ` [LTP] [PATCH 00/10] Fanotify tests for v5.9 Petr Vorel
2020-09-10 8:34 ` Petr Vorel
2020-09-10 11:27 ` Petr Vorel
2020-09-10 13:36 ` Amir Goldstein
2020-09-10 13:50 ` Amir Goldstein
2020-09-10 14:43 ` 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=20200909175707.10670-7-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=ltp@lists.linux.it \
/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.