[LTP] [PATCH 2/5] syscalls/fanotify03: included execve(2) to generate_events()

Matthew Bobrowski mbobrowski@mbobrowski.org
Tue Jan 22 23:35:50 CET 2019


* Created an executable helper program 'fanotify_child' so that can be
  used within fanotify tests

* Defined .resource_files so that additional test resources can be
  copied across to the tmp working directory i.e. fanotify_child

* Updated generate_events() so that it now includes a call to execve()
  on fanotify_child. This is so that we can increase the overall test
  coverage by generating more events on a watched object

* Updated each tcase events[] to accommodate for the additional events
  generated by execve()

Signed-off-by: Matthew Bobrowski <mbobrowski@mbobrowski.org>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
---
 testcases/kernel/syscalls/fanotify/.gitignore      |  1 +
 testcases/kernel/syscalls/fanotify/fanotify03.c    | 82 ++++++++++++++--------
 .../kernel/syscalls/fanotify/fanotify_child.c      | 14 ++++
 3 files changed, 66 insertions(+), 31 deletions(-)
 create mode 100644 testcases/kernel/syscalls/fanotify/fanotify_child.c

diff --git a/testcases/kernel/syscalls/fanotify/.gitignore b/testcases/kernel/syscalls/fanotify/.gitignore
index 3818e241f..e08310ed4 100644
--- a/testcases/kernel/syscalls/fanotify/.gitignore
+++ b/testcases/kernel/syscalls/fanotify/.gitignore
@@ -9,3 +9,4 @@
 /fanotify09
 /fanotify10
 /fanotify11
+/fanotify_child
diff --git a/testcases/kernel/syscalls/fanotify/fanotify03.c b/testcases/kernel/syscalls/fanotify/fanotify03.c
index aa16039a3..3fdd1aba8 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify03.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify03.c
@@ -37,6 +37,7 @@
 
 #define BUF_SIZE 256
 #define TST_TOTAL 3
+#define TEST_APP "fanotify_child"
 
 static char fname[BUF_SIZE];
 static char buf[BUF_SIZE];
@@ -62,28 +63,31 @@ static struct tcase {
 	{
 		"inode mark permission events",
 		INIT_FANOTIFY_MARK_TYPE(INODE),
-		FAN_OPEN_PERM | FAN_ACCESS_PERM, 2,
+		FAN_OPEN_PERM | FAN_ACCESS_PERM, 3,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
-			{FAN_ACCESS_PERM, FAN_DENY}
+			{FAN_ACCESS_PERM, FAN_DENY},
+			{FAN_OPEN_PERM, FAN_DENY}
 		}
 	},
 	{
 		"mount mark permission events",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
-		FAN_OPEN_PERM | FAN_ACCESS_PERM, 2,
+		FAN_OPEN_PERM | FAN_ACCESS_PERM, 3,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
-			{FAN_ACCESS_PERM, FAN_DENY}
+			{FAN_ACCESS_PERM, FAN_DENY},
+			{FAN_OPEN_PERM, FAN_DENY}
 		}
 	},
 	{
 		"filesystem mark permission events",
 		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
-		FAN_OPEN_PERM | FAN_ACCESS_PERM, 2,
+		FAN_OPEN_PERM | FAN_ACCESS_PERM, 3,
 		{
 			{FAN_OPEN_PERM, FAN_ALLOW},
-			{FAN_ACCESS_PERM, FAN_DENY}
+			{FAN_ACCESS_PERM, FAN_DENY},
+			{FAN_OPEN_PERM, FAN_DENY}
 		}
 	}
 };
@@ -91,9 +95,10 @@ static struct tcase {
 static void generate_events(void)
 {
 	int fd;
+	char *const argv[] = {TEST_APP, NULL};
 
 	/*
-	 * generate sequence of events
+	 * Generate sequence of events
 	 */
 	if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1)
 		exit(1);
@@ -106,6 +111,9 @@ static void generate_events(void)
 
 	if (close(fd) == -1)
 		exit(4);
+
+	if (execve(TEST_APP, argv, environ) != -1)
+		exit(5);
 }
 
 static void child_handler(int tmp)
@@ -133,6 +141,7 @@ static void run_child(void)
 	}
 
 	child_pid = SAFE_FORK();
+
 	if (child_pid == 0) {
 		/* Child will generate events now */
 		close(fd_notify);
@@ -163,37 +172,43 @@ static void check_child(void)
 
 static int setup_mark(unsigned int n)
 {
+	unsigned int i = 0;
 	struct tcase *tc = &tcases[n];
 	struct fanotify_mark_type *mark = &tc->mark;
+	char *const files[] = {fname, TEST_APP};
 
+	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
 	fd_notify = SAFE_FANOTIFY_INIT(FAN_CLASS_CONTENT, O_RDONLY);
 
-	if (fanotify_mark(fd_notify, FAN_MARK_ADD | mark->flag, tc->mask,
-			  AT_FDCWD, fname) < 0) {
-		if (errno == EINVAL && mark->flag == FAN_MARK_FILESYSTEM) {
-			tst_res(TCONF,
-				"FAN_MARK_FILESYSTEM not supported in kernel?");
-			return -1;
-		} else if (errno == EINVAL) {
-			tst_brk(TCONF | TERRNO,
-				"CONFIG_FANOTIFY_ACCESS_PERMISSIONS not "
-				"configured in kernel?");
+	for (; i < ARRAY_SIZE(files); i++) {
+		if (fanotify_mark(fd_notify, FAN_MARK_ADD | mark->flag,
+				  tc->mask, AT_FDCWD, files[i]) < 0) {
+			if (errno == EINVAL && 
+				mark->flag == FAN_MARK_FILESYSTEM) {
+				tst_res(TCONF,
+					"FAN_MARK_FILESYSTEM not supported in "
+					"kernel?");
+				return -1;
+			} else if (errno == EINVAL) {
+				tst_brk(TCONF | TERRNO,
+					"CONFIG_FANOTIFY_ACCESS_PERMISSIONS "
+					"not configured in kernel?");
+			} else {
+				tst_brk(TBROK | TERRNO,
+					"fanotify_mark (%d, FAN_MARK_ADD | %s, "
+					"FAN_ACCESS_PERM | FAN_OPEN_PERM, "
+					"AT_FDCWD, %s) failed.",
+					fd_notify, mark->name, fname);
+			}
 		} else {
-			tst_brk(TBROK | TERRNO,
-				"fanotify_mark (%d, FAN_MARK_ADD | %s, "
-				"FAN_ACCESS_PERM | FAN_OPEN_PERM, "
-				"AT_FDCWD, %s) failed.",
-				fd_notify, mark->name, fname);
+			/*
+			 * To distinguish between perm event not supported and
+			 * filesystem mark not supported.
+			 */
+			support_perm_events = 1;
 		}
-	} else {
-		/*
-		 * To distinguish between perm event not supported and
-		 * filesystem mark not supported.
-		 */
-		support_perm_events = 1;
 	}
 
-	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
 	return 0;
 }
 
@@ -299,14 +314,19 @@ static void cleanup(void)
 		SAFE_CLOSE(fd_notify);
 }
 
+static const char *const resource_files[] = {
+	TEST_APP,
+	NULL
+};
+
 static struct tst_test test = {
 	.test = test_fanotify,
 	.tcnt = ARRAY_SIZE(tcases),
 	.setup = setup,
 	.cleanup = cleanup,
-	.needs_tmpdir = 1,
 	.forks_child = 1,
-	.needs_root = 1
+	.needs_root = 1,
+	.resource_files = resource_files
 };
 
 #else
diff --git a/testcases/kernel/syscalls/fanotify/fanotify_child.c b/testcases/kernel/syscalls/fanotify/fanotify_child.c
new file mode 100644
index 000000000..2e4e189cb
--- /dev/null
+++ b/testcases/kernel/syscalls/fanotify/fanotify_child.c
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018 Matthew Bobrowski. All Rights Reserved.
+ *
+ * Started by Matthew Bobrowski <mbobrowski@mbobrowski.org>
+ *
+ * DESCRIPTION
+ *    Simple helper program that can be invoked from fanotify tests.
+ */
+
+int main(void)
+{
+	return 0;
+}
-- 
2.16.4


-- 
Matthew Bobrowski


More information about the ltp mailing list