From a1a42e1f0dc40cd6aeef4b0310ba6f4bca283b8e Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Mon, 24 Oct 2016 04:50:36 +0300 Subject: [PATCH] tests: check decoding of oldfstat, oldlstat, and oldstat syscalls * tests/oldfstat.c: New file. * tests/oldlstat.c: Likewise. * tests/oldstat.c: Likewise. * tests/oldfstat.test: New test. * tests/oldlstat.test: Likewise. * tests/oldstat.test: Likewise. * tests/xstatx.c [!OLD_STAT]: define OLD_STAT to 0. (print_stat) [OLD_STAT]: Print predefined values for st_blksize/st_blocks. (print_stat): Check for !OLD_STAT in nanosecond precision checks. (main) [OLD_STAT]: Ignore EOVERFLOW. (main): Test for successful rc in returned size value check; print address only on non-successful rc. * tests/.gitignore: Add oldfstat, oldlstat, and oldstat. * tests/Makefile.am (check_PROGRAMS): Likewise. (DECODER_TESTS): Add oldfstat.test, oldlstat.test, and oldstat.test. --- tests/.gitignore | 3 +++ tests/Makefile.am | 6 ++++++ tests/oldfstat.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ tests/oldfstat.test | 19 ++++++++++++++++++ tests/oldlstat.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ tests/oldlstat.test | 5 +++++ tests/oldstat.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ tests/oldstat.test | 5 +++++ tests/xstatx.c | 34 +++++++++++++++++++++++-------- 9 files changed, 211 insertions(+), 8 deletions(-) create mode 100644 tests/oldfstat.c create mode 100755 tests/oldfstat.test create mode 100644 tests/oldlstat.c create mode 100755 tests/oldlstat.test create mode 100644 tests/oldstat.c create mode 100755 tests/oldstat.test diff --git a/tests/.gitignore b/tests/.gitignore index 53f4c3b1..2771e612 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -183,7 +183,10 @@ netlink_unix_diag newfstatat nsyscalls old_mmap +oldfstat +oldlstat oldselect +oldstat open openat pause diff --git a/tests/Makefile.am b/tests/Makefile.am index da32d0e3..499eb4b5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -241,7 +241,10 @@ check_PROGRAMS = \ newfstatat \ nsyscalls \ old_mmap \ + oldfstat \ + oldlstat \ oldselect \ + oldstat \ open \ openat \ pause \ @@ -598,7 +601,10 @@ DECODER_TESTS = \ newfstatat.test \ nsyscalls.test \ old_mmap.test \ + oldfstat.test \ + oldlstat.test \ oldselect.test \ + oldstat.test \ open.test \ openat.test \ pause.test \ diff --git a/tests/oldfstat.c b/tests/oldfstat.c new file mode 100644 index 00000000..18d48f73 --- /dev/null +++ b/tests/oldfstat.c @@ -0,0 +1,49 @@ +/* + * Check decoding of oldfstat syscall. + * + * Copyright (c) 2015-2016 Dmitry V. Levin + * Copyright (c) 2016 Eugene Syromyatnikov + * 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 + +#if defined __NR_oldfstat && HAVE_STRUCT___OLD_KERNEL_STAT + +# define OLD_STAT 1 +# define TEST_SYSCALL_NR __NR_oldfstat +# define TEST_SYSCALL_STR "oldfstat" +# define STRUCT_STAT struct __old_kernel_stat +# define STRUCT_STAT_STR "struct __old_kernel_stat" +# define STRUCT_STAT_IS_STAT64 0 +# define SAMPLE_SIZE ((kernel_ulong_t) 23147718418U) +# include "fstatx.c" + +#else + +SKIP_MAIN_UNDEFINED("__NR_oldfstat && HAVE_STRUCT___OLD_KERNEL_STAT") + +#endif diff --git a/tests/oldfstat.test b/tests/oldfstat.test new file mode 100755 index 00000000..66a10561 --- /dev/null +++ b/tests/oldfstat.test @@ -0,0 +1,19 @@ +#!/bin/sh + +# Check oldfstat syscall decoding. + +. "${srcdir=.}/init.sh" + +# strace -P is implemented using /proc/self/fd +[ -d /proc/self/fd/ ] || + framework_skip_ '/proc/self/fd/ is not available' + +syscall=$NAME +run_prog > /dev/null +sample=$syscall.sample +> "$sample" +run_strace -ve$syscall -P$sample -a21 $args > "$OUT" +match_diff "$LOG" "$OUT" +rm -f "$OUT" + +exit 0 diff --git a/tests/oldlstat.c b/tests/oldlstat.c new file mode 100644 index 00000000..9d3cb59f --- /dev/null +++ b/tests/oldlstat.c @@ -0,0 +1,49 @@ +/* + * Check decoding of oldlstat syscall. + * + * Copyright (c) 2015-2016 Dmitry V. Levin + * Copyright (c) 2016 Eugene Syromyatnikov + * 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 + +#if defined __NR_oldlstat && HAVE_STRUCT___OLD_KERNEL_STAT + +# define OLD_STAT 1 +# define TEST_SYSCALL_NR __NR_oldlstat +# define TEST_SYSCALL_STR "oldlstat" +# define STRUCT_STAT struct __old_kernel_stat +# define STRUCT_STAT_STR "struct __old_kernel_stat" +# define STRUCT_STAT_IS_STAT64 0 +# define SAMPLE_SIZE ((kernel_ulong_t) 23147718418U) +# include "lstatx.c" + +#else + +SKIP_MAIN_UNDEFINED("__NR_oldlstat && HAVE_STRUCT___OLD_KERNEL_STAT") + +#endif diff --git a/tests/oldlstat.test b/tests/oldlstat.test new file mode 100755 index 00000000..a0f9ab93 --- /dev/null +++ b/tests/oldlstat.test @@ -0,0 +1,5 @@ +#!/bin/sh + +# Check oldlstat syscall decoding. + +. "${srcdir=.}/statx.sh" diff --git a/tests/oldstat.c b/tests/oldstat.c new file mode 100644 index 00000000..37da4809 --- /dev/null +++ b/tests/oldstat.c @@ -0,0 +1,49 @@ +/* + * Check decoding of oldstat syscall. + * + * Copyright (c) 2015-2016 Dmitry V. Levin + * Copyright (c) 2016 Eugene Syromyatnikov + * 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 + +#if defined __NR_oldstat && HAVE_STRUCT___OLD_KERNEL_STAT + +# define OLD_STAT 1 +# define TEST_SYSCALL_NR __NR_oldstat +# define TEST_SYSCALL_STR "oldstat" +# define STRUCT_STAT struct __old_kernel_stat +# define STRUCT_STAT_STR "struct __old_kernel_stat" +# define STRUCT_STAT_IS_STAT64 0 +# define SAMPLE_SIZE ((kernel_ulong_t) 131478418U) +# include "lstatx.c" + +#else + +SKIP_MAIN_UNDEFINED("__NR_oldstat && HAVE_STRUCT___OLD_KERNEL_STAT") + +#endif diff --git a/tests/oldstat.test b/tests/oldstat.test new file mode 100755 index 00000000..42d70f7f --- /dev/null +++ b/tests/oldstat.test @@ -0,0 +1,5 @@ +#!/bin/sh + +# Check oldstat syscall decoding. + +. "${srcdir=.}/statx.sh" diff --git a/tests/xstatx.c b/tests/xstatx.c index a04a3dab..2fda6f81 100644 --- a/tests/xstatx.c +++ b/tests/xstatx.c @@ -141,6 +141,10 @@ typedef off_t libc_off_t; # define IS_STAT 0 # endif +# ifndef OLD_STAT +# define OLD_STAT 0 +# endif + static void print_ftype(const unsigned int mode) { @@ -176,8 +180,12 @@ print_stat(const STRUCT_STAT *st) printf(", st_nlink=%llu", zero_extend_signed_to_ull(st->st_nlink)); printf(", st_uid=%llu", zero_extend_signed_to_ull(st->st_uid)); printf(", st_gid=%llu", zero_extend_signed_to_ull(st->st_gid)); +# if OLD_STAT + printf(", st_blksize=0, st_blocks=0"); +# else /* !OLD_STAT */ printf(", st_blksize=%llu", zero_extend_signed_to_ull(st->st_blksize)); printf(", st_blocks=%llu", zero_extend_signed_to_ull(st->st_blocks)); +# endif /* OLD_STAT */ switch (st->st_mode & S_IFMT) { case S_IFCHR: case S_IFBLK: @@ -191,19 +199,19 @@ print_stat(const STRUCT_STAT *st) printf(", st_atime="); print_time(sign_extend_unsigned_to_ll(st->st_atime)); -# ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC +# if defined(HAVE_STRUCT_STAT_ST_MTIME_NSEC) && !OLD_STAT if (st->st_atime_nsec) printf(".%09llu", zero_extend_signed_to_ull(st->st_atime_nsec)); # endif printf(", st_mtime="); print_time(sign_extend_unsigned_to_ll(st->st_mtime)); -# ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC +# if defined(HAVE_STRUCT_STAT_ST_MTIME_NSEC) && !OLD_STAT if (st->st_mtime_nsec) printf(".%09llu", zero_extend_signed_to_ull(st->st_mtime_nsec)); # endif printf(", st_ctime="); print_time(sign_extend_unsigned_to_ll(st->st_ctime)); -# ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC +# if defined(HAVE_STRUCT_STAT_ST_MTIME_NSEC) && !OLD_STAT if (st->st_ctime_nsec) printf(".%09llu", zero_extend_signed_to_ull(st->st_ctime_nsec)); # endif @@ -269,12 +277,17 @@ main(void) # endif if ((rc = TEST_SYSCALL_INVOKE(sample, st))) { - perror(TEST_SYSCALL_STR); - (void) unlink(sample); - return 77; +# if OLD_STAT + if (errno != EOVERFLOW) +# endif + { + perror(TEST_SYSCALL_STR); + (void) unlink(sample); + return 77; + } } (void) unlink(sample); - if (zero_extend_signed_to_ull(SAMPLE_SIZE) != + if (!rc && zero_extend_signed_to_ull(SAMPLE_SIZE) != zero_extend_signed_to_ull(st[0].st_size)) { fprintf(stderr, "Size mismatch: " "requested size(%llu) != st_size(%llu)\n", @@ -316,6 +329,7 @@ main(void) ", sizeof(st_size) = %zu\n", STRUCT_STAT_STR, offsetof(STRUCT_STAT, st_size), sizeof(st[0].st_size)); +# if !OLD_STAT fprintf(stderr, "offsetof(%s, st_blksize) = %zu" ", sizeof(st_blksize) = %zu\n", STRUCT_STAT_STR, offsetof(STRUCT_STAT, st_blksize), @@ -324,11 +338,15 @@ main(void) ", sizeof(st_blocks) = %zu\n", STRUCT_STAT_STR, offsetof(STRUCT_STAT, st_blocks), sizeof(st[0].st_blocks)); +# endif /* !OLD_STAT */ return 77; } PRINT_SYSCALL_HEADER(sample); - print_stat(st); + if (rc) + printf("%p", st); + else + print_stat(st); PRINT_SYSCALL_FOOTER(rc); puts("+++ exited with 0 +++"); -- 2.40.0