From: Eugene Syromyatnikov Date: Wed, 21 Sep 2016 21:21:57 +0000 (+0300) Subject: tests: check decoding of fadvise64 and fadvise64_64 syscalls X-Git-Tag: v4.14~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2402cea20cb2da8feaa69f0059f041ba4e9fb70;p=strace tests: check decoding of fadvise64 and fadvise64_64 syscalls * 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. --- diff --git a/tests/.gitignore b/tests/.gitignore index 12c7a577..9ee036be 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -44,6 +44,8 @@ execve-v execveat execveat-v faccessat +fadvise64 +fadvise64_64 fallocate fanotify_mark fchdir diff --git a/tests/Makefile.am b/tests/Makefile.am index 0e4ad140..86672fc1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 00000000..bc790913 --- /dev/null +++ b/tests/fadvise.h @@ -0,0 +1,64 @@ +/* + * Common definitions for fadvise64 and fadvise64_64 tests. + * + * Copyright (c) 2016 Eugene Syromiatnikov + * Copyright (c) 2016 Dmitry V. Levin + * 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 +# include +# include + +# 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 index 00000000..02d7394b --- /dev/null +++ b/tests/fadvise64.c @@ -0,0 +1,76 @@ +/* + * Check decoding of fadvise64 syscall. + * + * Copyright (c) 2016 Eugene Syromiatnikov + * Copyright (c) 2016 Dmitry V. Levin + * 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 + +#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 index 00000000..9f746720 --- /dev/null +++ b/tests/fadvise64.test @@ -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 index 00000000..69b1c7f3 --- /dev/null +++ b/tests/fadvise64_64.c @@ -0,0 +1,74 @@ +/* + * Check decoding of fadvise64_64 syscall. + * + * Copyright (c) 2016 Eugene Syromiatnikov + * Copyright (c) 2016 Dmitry V. Levin + * 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 + +#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 index 00000000..a50fe2b9 --- /dev/null +++ b/tests/fadvise64_64.test @@ -0,0 +1,5 @@ +#!/bin/sh + +# Check decoding of fadvise64_64 syscall. + +. "${srcdir=.}/fadvise64.test"