[PATCH v2 3/3] tests: check -z and -Z options

Paul Chaignon paul.chaignon at gmail.com
Tue Apr 2 19:57:28 UTC 2019


This patch adds two test cases for the -z and -Z options.

Signed-off-by: Paul Chaignon <paul.chaignon at gmail.com>
---
 tests/.gitignore            |  2 ++
 tests/gen_tests.in          |  2 ++
 tests/open-Z.c              | 59 +++++++++++++++++++++++++++++++++++++
 tests/open-z.c              | 58 ++++++++++++++++++++++++++++++++++++
 tests/pure_executables.list |  2 ++
 5 files changed, 123 insertions(+)
 create mode 100644 tests/open-Z.c
 create mode 100644 tests/open-z.c

diff --git a/tests/.gitignore b/tests/.gitignore
index 5a601641..f837656a 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -362,6 +362,8 @@ oldselect-efault
 oldselect-efault-P
 oldstat
 open
+open-z
+open-Z
 openat
 orphaned_process_group
 osf_utimes
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index 314608eb..d4ba061e 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -309,6 +309,8 @@ oldselect-efault	-a13 -e trace=select
 oldselect-efault-P	-a13 -e trace=select -P /dev/full 9>>/dev/full
 oldstat	-a32 -v -P stat.sample -P /dev/full
 open	-a30 -P $NAME.sample
+open-Z	-a30 -e trace=open -P open.sample -Z
+open-z	-a30 -e trace=open -P open.sample -z
 openat	-a36 -P $NAME.sample
 orphaned_process_group	. "${srcdir=.}/PTRACE_SEIZE.sh"; run_strace_match_diff -f -e trace=none -e signal='!chld'
 osf_utimes	-a21
diff --git a/tests/open-Z.c b/tests/open-Z.c
new file mode 100644
index 00000000..b692502f
--- /dev/null
+++ b/tests/open-Z.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2019 Paul Chaignon <paul.chaignon at gmail.com>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "tests.h"
+#include <asm/unistd.h>
+
+#ifdef __NR_open
+
+# include <asm/fcntl.h>
+# include <stdio.h>
+# include <unistd.h>
+
+int
+main(void)
+{
+	static const char sample[] = "open.sample";
+	long fd = syscall(__NR_open, sample, O_RDONLY | O_CREAT, 0400);
+
+	if (fd == -1)
+		printf("open(\"%s\", O_RDONLY|O_CREAT, 0400) = %s\n",
+		       sample, sprintrc(fd));
+
+	if (fd != -1) {
+		close(fd);
+		if (unlink(sample))
+			perror_msg_and_fail("unlink");
+
+		fd = syscall(__NR_open, sample, O_RDONLY);
+		if (fd == -1)
+			printf("open(\"%s\", O_RDONLY) = %s\n", sample,
+			       sprintrc(fd));
+
+		fd = syscall(__NR_open, sample,
+			     O_WRONLY | O_NONBLOCK | 0x80000000);
+		if (fd == -1)
+			printf("open(\"%s\", O_WRONLY|O_NONBLOCK|0x80000000) = %s\n",
+			       sample, sprintrc(fd));
+	}
+
+# ifdef O_TMPFILE
+	fd = syscall(__NR_open, sample, O_WRONLY | O_TMPFILE, 0600);
+	if (fd == -1)
+		printf("open(\"%s\", O_WRONLY|O_TMPFILE, 0600) = %s\n",
+		       sample, sprintrc(fd));
+# endif /* O_TMPFILE */
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_open")
+
+#endif
diff --git a/tests/open-z.c b/tests/open-z.c
new file mode 100644
index 00000000..ab988105
--- /dev/null
+++ b/tests/open-z.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2019 Paul Chaignon <paul.chaignon at gmail.com>
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "tests.h"
+#include <asm/unistd.h>
+
+#ifdef __NR_open
+
+# include <asm/fcntl.h>
+# include <stdio.h>
+# include <unistd.h>
+
+int
+main(void)
+{
+	static const char sample[] = "open.sample";
+	long fd = syscall(__NR_open, sample, O_RDONLY | O_CREAT, 0400);
+
+	if (fd != -1) {
+		printf("open(\"%s\", O_RDONLY|O_CREAT, 0400) = %s\n",
+		       sample, sprintrc(fd));
+
+		close(fd);
+		if (unlink(sample))
+			perror_msg_and_fail("unlink");
+
+		fd = syscall(__NR_open, sample, O_RDONLY);
+		if (fd != -1)
+			printf("open(\"%s\", O_RDONLY) = %s\n", sample,
+			       sprintrc(fd));
+
+		fd = syscall(__NR_open, sample,
+			     O_WRONLY | O_NONBLOCK | 0x80000000);
+		if (fd != -1)
+			printf("open(\"%s\", O_WRONLY|O_NONBLOCK|0x80000000) = %s\n",
+			       sample, sprintrc(fd));
+	}
+
+# ifdef O_TMPFILE
+	fd = syscall(__NR_open, sample, O_WRONLY | O_TMPFILE, 0600);
+	if (fd != -1)
+		printf("open(\"%s\", O_WRONLY|O_TMPFILE, 0600) = %s\n",
+		       sample, sprintrc(fd));
+# endif /* O_TMPFILE */
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_open")
+
+#endif
diff --git a/tests/pure_executables.list b/tests/pure_executables.list
index b695a0ec..210ccb57 100755
--- a/tests/pure_executables.list
+++ b/tests/pure_executables.list
@@ -310,6 +310,8 @@ oldselect
 oldselect-efault
 oldstat
 open
+open-z
+open-Z
 openat
 osf_utimes
 pause
-- 
2.17.1



More information about the Strace-devel mailing list