From afd9e5e8014f911bbee211a7e5f49543376d33e4 Mon Sep 17 00:00:00 2001
From: Eugene Syromyatnikov <evgsyr@gmail.com>
Date: Wed, 17 Jan 2018 02:39:21 +0100
Subject: [PATCH] tests: check path tracing of old mmap syscall

* tests/old_mmap.c [!TEST_FD]: Define TEST_FD.
(main) <args1_c>: Replace 5th argument with TEST_FD.
(main): Wrap the output for the calls that do not use TEST_FD
with #ifndef PATH_TRACING.
* tests/old_mmap-P.c: New file.
* tests/pure_executables.list: Add old_mmap-P.
* tests/.gitignore: Likewise.
* tests/gen_tests.in: Add old_mmap-P test.
---
 tests/.gitignore            |  1 +
 tests/gen_tests.in          |  1 +
 tests/old_mmap-P.c          |  3 +++
 tests/old_mmap.c            | 10 +++++++++-
 tests/pure_executables.list |  1 +
 5 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 tests/old_mmap-P.c

diff --git a/tests/.gitignore b/tests/.gitignore
index 68bda389..becb265a 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -267,6 +267,7 @@ nlattr_unix_diag_msg
 nsyscalls
 nsyscalls-d
 old_mmap
+old_mmap-P
 old_mmap-v-none
 oldfstat
 oldlstat
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index 3f1d1a9b..1e2453a2 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -240,6 +240,7 @@ nlattr_tcamsg			+netlink_sock_diag.test
 nlattr_tcmsg			+netlink_sock_diag.test
 nlattr_unix_diag_msg		+netlink_sock_diag.test
 old_mmap	-a11 -e trace=mmap
+old_mmap-P	-e trace=mmap -P "/dev/full" 9>>/dev/full
 old_mmap-v-none	-a11 -e trace=mmap -e verbose=none
 oldfstat	-a18 -v -P stat.sample
 oldlstat	-a32 -v -P stat.sample -P /dev/full
diff --git a/tests/old_mmap-P.c b/tests/old_mmap-P.c
new file mode 100644
index 00000000..bb28e889
--- /dev/null
+++ b/tests/old_mmap-P.c
@@ -0,0 +1,3 @@
+#define TEST_FD 9
+#define PATH_TRACING
+#include "old_mmap.c"
diff --git a/tests/old_mmap.c b/tests/old_mmap.c
index 2725fb75..000a78ee 100644
--- a/tests/old_mmap.c
+++ b/tests/old_mmap.c
@@ -47,18 +47,24 @@
 # include <sys/mman.h>
 # include <unistd.h>
 
+# ifndef TEST_FD
+#  define TEST_FD -2U
+# endif
+
 int
 main(void)
 {
 	long rc = syscall(__NR_mmap, 0);
+# ifndef PATH_TRACING
 	printf("mmap(NULL) = %ld %s (%m)\n", rc, errno2name());
+# endif
 
 	const unsigned int args1_c[6] = {
 		0xdeadbeef,		/* addr */
 		0xfacefeed,		/* len */
 		PROT_READ|PROT_EXEC,	/* prot */
 		MAP_FILE|MAP_FIXED,	/* flags */
-		-2U,			/* fd */
+		TEST_FD,		/* fd */
 		0xbadc0ded		/* offset */
 	};
 	const unsigned int page_size = get_page_size();
@@ -80,9 +86,11 @@ main(void)
 
 	memcpy(args, args2_c, sizeof(args2_c));
 	rc = syscall(__NR_mmap, args);
+# ifndef PATH_TRACING
 	printf("mmap(NULL, %u, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS"
 	       ", %d, %#x) = %#lx\n",
 	       args2_c[1], args2_c[4], args2_c[5], rc);
+# endif
 
 	void *addr = (void *) rc;
 	if (mprotect(addr, page_size, PROT_NONE))
diff --git a/tests/pure_executables.list b/tests/pure_executables.list
index 9ceaacab..274d95ed 100755
--- a/tests/pure_executables.list
+++ b/tests/pure_executables.list
@@ -224,6 +224,7 @@ nlattr_tcamsg
 nlattr_tcmsg
 nlattr_unix_diag_msg
 old_mmap
+old_mmap-P
 old_mmap-v-none
 oldfstat
 oldlstat
-- 
2.40.0