]> granicus.if.org Git - strace/commitdiff
tests: check decoding of fadvise64 and fadvise64_64 syscalls
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 21 Sep 2016 21:21:57 +0000 (00:21 +0300)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 28 Sep 2016 03:00:10 +0000 (03:00 +0000)
* tests/fadvise.h: New file.
* tests/fadvise64.c: Likewise.
* tests/fadvise64_64.c: Likewise.
* tests/fadvise64.test: New test.
* tests/fadvise64_64.test: Likewise.
* tests/.gitignore: Add fadvise64 and fadvise64_64.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(DECODER_TESTS): Add fadvise64.test, fadvise64_64.test.
(EXTRA_DIST): Add fadvise.h.

tests/.gitignore
tests/Makefile.am
tests/fadvise.h [new file with mode: 0644]
tests/fadvise64.c [new file with mode: 0644]
tests/fadvise64.test [new file with mode: 0755]
tests/fadvise64_64.c [new file with mode: 0644]
tests/fadvise64_64.test [new file with mode: 0755]

index 12c7a577007e380d4992faa59c313854f53bd079..9ee036be389f5a44ce2a25443ee236c30f7fbf4e 100644 (file)
@@ -44,6 +44,8 @@ execve-v
 execveat
 execveat-v
 faccessat
+fadvise64
+fadvise64_64
 fallocate
 fanotify_mark
 fchdir
index 0e4ad140ced7a861881e909361120fcea0c912d0..86672fc10558fd7996710a2b86828ff6c3d97f8a 100644 (file)
@@ -103,6 +103,8 @@ check_PROGRAMS = \
        execveat \
        execveat-v \
        faccessat \
+       fadvise64 \
+       fadvise64_64 \
        fallocate \
        fanotify_mark \
        fchdir \
@@ -445,6 +447,8 @@ DECODER_TESTS = \
        execveat-v.test \
        execveat.test \
        faccessat.test \
+       fadvise64.test \
+       fadvise64_64.test \
        fallocate.test \
        fanotify_mark.test \
        fchdir.test \
@@ -749,6 +753,7 @@ EXTRA_DIST = init.sh run.sh match.awk \
             caps.awk \
             count-f.expected \
             eventfd.expected \
+            fadvise.h \
             filter-unavailable.expected \
             fstatat.c \
             fstatx.c \
diff --git a/tests/fadvise.h b/tests/fadvise.h
new file mode 100644 (file)
index 0000000..bc79091
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Common definitions for fadvise64 and fadvise64_64 tests.
+ *
+ * Copyright (c) 2016 Eugene Syromiatnikov <evgsyr@gmail.com>
+ * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef STRACE_TESTS_FADVISE_H
+#define STRACE_TESTS_FADVISE_H
+
+# include <limits.h>
+# include <stdio.h>
+# include <unistd.h>
+
+# include "xlat.h"
+# include "xlat/advise.h"
+
+# if WORDS_BIGENDIAN
+#  define LL_PAIR(HI, LO) (HI), (LO)
+# else
+#  define LL_PAIR(HI, LO) (LO), (HI)
+# endif
+# define LL_VAL_TO_PAIR(llval) LL_PAIR((long) ((llval) >> 32), (long) (llval))
+
+static void do_fadvise(long fd, long long offset, long long llen, long advice);
+
+int
+main(void)
+{
+       static const long bogus_fd = (long) 0xfeedf00dbeeffaceULL;
+       static const long long bogus_offset = 0xbadc0dedda7a1057ULL;
+       static const long long bogus_len = 0xbadfaceca7b0d1e5ULL;
+       static const long bogus_advice = (long) 0xf00dfeeddeadca75ULL;
+
+       do_fadvise(bogus_fd, bogus_offset, bogus_len, bogus_advice);
+
+       puts("+++ exited with 0 +++");
+       return 0;
+}
+
+#endif /* !STRACE_TESTS_FADVISE_H */
diff --git a/tests/fadvise64.c b/tests/fadvise64.c
new file mode 100644 (file)
index 0000000..02d7394
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Check decoding of fadvise64 syscall.
+ *
+ * Copyright (c) 2016 Eugene Syromiatnikov <evgsyr@gmail.com>
+ * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+
+#include <asm/unistd.h>
+
+#ifdef __NR_fadvise64
+
+# include "fadvise.h"
+
+static void
+do_fadvise(long fd, long long offset, long long llen, long advice)
+{
+       long ret;
+       const char *errstr;
+
+# if (LONG_MAX > INT_MAX) \
+  || (defined __x86_64__ && defined __ILP32__) \
+  || defined LINUX_MIPSN32
+       ret = syscall(__NR_fadvise64, fd, offset, llen, advice);
+       errstr = sprintrc(ret);
+       printf("fadvise64(%d, %lld, %llu, ", (int) fd, offset, llen);
+# elif defined LINUX_MIPSO32
+       ret = syscall(__NR_fadvise64, fd, 0,
+                     LL_VAL_TO_PAIR(offset), LL_VAL_TO_PAIR(llen), advice);
+       errstr = sprintrc(ret);
+       printf("fadvise64(%d, %lld, %lld, ", (int) fd, offset, llen);
+# else /* LONG_MAX == INT_MAX && !X32 && !LINUX_MIPSN32 */
+       long len = (long) llen;
+#  if defined POWERPC
+       ret = syscall(__NR_fadvise64, fd, 0,
+                     LL_VAL_TO_PAIR(offset), len, advice);
+#  else
+       ret = syscall(__NR_fadvise64, fd,
+                     LL_VAL_TO_PAIR(offset), len, advice);
+#  endif
+       errstr = sprintrc(ret);
+       printf("fadvise64(%d, %lld, %lu, ", (int) fd, offset, len);
+# endif /* LONG_MAX == INT_MAX && !X32 && !LINUX_MIPSN32 */
+       printxval(advise, (unsigned) advice, "POSIX_FADV_???");
+       printf(") = %s\n", errstr);
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_fadvise64");
+
+#endif
diff --git a/tests/fadvise64.test b/tests/fadvise64.test
new file mode 100755 (executable)
index 0000000..9f74672
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+# Check decoding of fadvise64 syscall.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+run_strace -e $NAME $args > "$EXP"
+check_prog grep
+grep -v "^$NAME([0123]," < "$LOG" > "$OUT"
+match_diff "$OUT" "$EXP"
+rm -f "$EXP" "$OUT"
diff --git a/tests/fadvise64_64.c b/tests/fadvise64_64.c
new file mode 100644 (file)
index 0000000..69b1c7f
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Check decoding of fadvise64_64 syscall.
+ *
+ * Copyright (c) 2016 Eugene Syromiatnikov <evgsyr@gmail.com>
+ * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+
+#include <asm/unistd.h>
+
+#ifdef __arm__
+# ifdef __NR_arm_fadvise64_64
+#  undef __NR_fadvise64_64
+#  define __NR_fadvise64_64 __NR_arm_fadvise64_64
+# endif /* __NR_arm_fadvise64_64 */
+#endif /* __arm__ */
+
+#ifdef __NR_fadvise64_64
+
+# include "fadvise.h"
+
+static void
+do_fadvise(long fd, long long offset, long long llen, long advice)
+{
+       long ret;
+       const char *errstr;
+
+# if (LONG_MAX > INT_MAX) \
+  || (defined __x86_64__ && defined __ILP32__) \
+  || defined LINUX_MIPSN32
+       ret = syscall(__NR_fadvise64_64, fd, offset, llen, advice);
+# elif defined __ARM_EABI__ || defined POWERPC || defined XTENSA
+       ret = syscall(__NR_fadvise64_64, fd, advice,
+                     LL_VAL_TO_PAIR(offset), LL_VAL_TO_PAIR(llen));
+# else
+       ret = syscall(__NR_fadvise64_64, fd,
+                     LL_VAL_TO_PAIR(offset), LL_VAL_TO_PAIR(llen), advice);
+# endif
+       errstr = sprintrc(ret);
+
+       printf("fadvise64_64(%d, %lld, %lld, ", (int) fd, offset, llen);
+       printxval(advise, (unsigned) advice, "POSIX_FADV_???");
+       printf(") = %s\n", errstr);
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_fadvise64_64");
+
+#endif
diff --git a/tests/fadvise64_64.test b/tests/fadvise64_64.test
new file mode 100755 (executable)
index 0000000..a50fe2b
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+# Check decoding of fadvise64_64 syscall.
+
+. "${srcdir=.}/fadvise64.test"