[PATCH v3] tests: check decoding of readahead syscall
Eugene Syromyatnikov
evgsyr at gmail.com
Sun Sep 4 23:39:07 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 since v2:
* Added workaround for an old glibc bug
(https://sourceware.org/bugzilla/show_bug.cgi?id=5208) which is still
present in RHEL 5.
tests/.gitignore | 1 +
tests/Makefile.am | 2 ++
tests/readahead.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++
tests/readahead.test | 6 ++++
4 files changed, 98 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..6f50e38
--- /dev/null
+++ b/tests/readahead.c
@@ -0,0 +1,89 @@
+#include "tests.h"
+#include <asm/unistd.h>
+
+#ifdef __NR_readahead
+
+# include <fcntl.h>
+# include <stdio.h>
+# include <unistd.h>
+
+# if !defined(STRACE_READAHEAD_USE_SYSCALL)
+# 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_USE_SYSCALL 0
+# else
+# define STRACE_READAHEAD_USE_SYSCALL 1
+# endif
+# else /* !defined(__GNU_LIBRARY__) */
+# define STRACE_READAHEAD_USE_SYSCALL 0
+# endif /* defined(__GNU_LIBRARY__) */
+# endif /* !defined(READAHED_USE_SYSCALL) */
+
+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,
+};
+
+static inline ssize_t
+do_readahead(int fd, off64_t offset, size_t count)
+{
+#if STRACE_READAHEAD_USE_SYSCALL
+ return syscall(__NR_readahead, fd, offset, count);
+#else
+ return readahead(fd, offset, count);
+#endif
+}
+
+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 = do_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