[PATCH v3.1] tests: check decoding of readahead syscall

Eugene Syromyatnikov evgsyr at gmail.com
Mon Sep 5 00:30:00 UTC 2016


* tests/readahead.c: New file.
* tests/readahead.test: New test.
* tests/.gitignore: Add readahead.
* tests/Makefile.am (check_PROGRAMS): Likewise.
  (DECODER_TESTS): Add readahead.test.
---
Changes from v3:
 * Scraping incorrect attempt to work around glibc bug, now just skipping
   the test.

 tests/.gitignore     |    1 +
 tests/Makefile.am    |    2 ++
 tests/readahead.c    |   79 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/readahead.test |    6 ++++
 4 files changed, 88 insertions(+)
 create mode 100644 tests/readahead.c
 create mode 100755 tests/readahead.test

diff --git a/tests/.gitignore b/tests/.gitignore
index 5c5d092..8c41bea 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -185,6 +185,7 @@ pselect6
 ptrace
 pwritev
 read-write
+readahead
 readdir
 readlink
 readlinkat
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2cf9674..0b3b818 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -242,6 +242,7 @@ check_PROGRAMS = \
 	ptrace \
 	pwritev \
 	read-write \
+	readahead \
 	readdir \
 	readlink \
 	readlinkat \
@@ -569,6 +570,7 @@ DECODER_TESTS = \
 	ptrace.test \
 	pwritev.test \
 	read-write.test \
+	readahead.test \
 	readdir.test \
 	readlink.test \
 	readlinkat.test \
diff --git a/tests/readahead.c b/tests/readahead.c
new file mode 100644
index 0000000..f5972af
--- /dev/null
+++ b/tests/readahead.c
@@ -0,0 +1,79 @@
+#include "tests.h"
+#include <asm/unistd.h>
+
+#if !defined(STRACE_READAHEAD_BROKEN)
+# if defined(__GNU_LIBRARY__)
+/* Check for glibc readahead off64_t argument passing bug,
+ * see https://sourceware.org/bugzilla/show_bug.cgi?id=5208 */
+#  if defined(__GLIBC__) && defined(__GLIBC_MINOR__) && \
+	(__GLIBC__ * 1000 + __GLIBC_MINOR__ <= 2007)
+#   define STRACE_READAHEAD_BROKEN 1
+#  endif
+# endif /* defined(__GNU_LIBRARY__) */
+#endif /* !defined(STRACE_READAHEAD_BROKEN) */
+
+#if defined(STRACE_READAHEAD_BROKEN) && STRACE_READAHEAD_BROKEN && \
+	defined(__NR_readahead)
+# undef __NR_readahead
+#endif
+
+#ifdef __NR_readahead
+
+# include <fcntl.h>
+# include <stdio.h>
+# include <unistd.h>
+
+static const int fds[] = {
+	-0x80000000,
+	-100,
+	-1,
+	0,
+	1,
+	2,
+	0x7fffffff,
+};
+
+static const off64_t offsets[] = {
+	-0x8000000000000000LL,
+	-0x5060708090a0b0c0LL,
+	-1LL,
+	 0,
+	 1,
+	 0xbadfaced,
+	 0x7fffffffffffffffLL,
+};
+
+static const unsigned long counts[] = {
+	0UL,
+	0xdeadca75,
+	(unsigned long)0xface1e55beeff00dULL,
+	(unsigned long)0xffffffffffffffffULL,
+};
+
+int
+main(void)
+{
+	unsigned i;
+	unsigned j;
+	unsigned k;
+	ssize_t rc;
+
+	for (i = 0; i < ARRAY_SIZE(fds); i++)
+		for (j = 0; j < ARRAY_SIZE(offsets); j++)
+			for (k = 0; k < ARRAY_SIZE(counts); k++) {
+				rc = readahead(fds[i], offsets[j], counts[k]);
+
+				printf("readahead(%d, %lld, %lu) = %s\n",
+					fds[i], (long long)offsets[j],
+					counts[k], sprintrc(rc));
+			}
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_readahead")
+
+#endif
diff --git a/tests/readahead.test b/tests/readahead.test
new file mode 100755
index 0000000..397c690
--- /dev/null
+++ b/tests/readahead.test
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# Check readahead syscall decoding.
+
+. "${srcdir=.}/init.sh"
+run_strace_match_diff -a1
-- 
1.7.10.4





More information about the Strace-devel mailing list