]> granicus.if.org Git - strace/commitdiff
tests: check decoding of oldfstat, oldlstat, and oldstat syscalls
authorEugene Syromyatnikov <evgsyr@gmail.com>
Mon, 24 Oct 2016 01:50:36 +0000 (04:50 +0300)
committerEugene Syromyatnikov <evgsyr@gmail.com>
Sun, 30 Oct 2016 21:49:28 +0000 (00:49 +0300)
* 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
tests/Makefile.am
tests/oldfstat.c [new file with mode: 0644]
tests/oldfstat.test [new file with mode: 0755]
tests/oldlstat.c [new file with mode: 0644]
tests/oldlstat.test [new file with mode: 0755]
tests/oldstat.c [new file with mode: 0644]
tests/oldstat.test [new file with mode: 0755]
tests/xstatx.c

index 53f4c3b137f306ebe607cdff75637b6a6d55279a..2771e612c35eff603488bfb3933bb079d544259d 100644 (file)
@@ -183,7 +183,10 @@ netlink_unix_diag
 newfstatat
 nsyscalls
 old_mmap
+oldfstat
+oldlstat
 oldselect
+oldstat
 open
 openat
 pause
index da32d0e33852905d66b93d3cdad5bc555b7dc971..499eb4b548492485dee8d1bd246dc59cffd6eeac 100644 (file)
@@ -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 (file)
index 0000000..18d48f7
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Check decoding of oldfstat syscall.
+ *
+ * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
+ * 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>
+
+#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 (executable)
index 0000000..66a1056
--- /dev/null
@@ -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 (file)
index 0000000..9d3cb59
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Check decoding of oldlstat syscall.
+ *
+ * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
+ * 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>
+
+#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 (executable)
index 0000000..a0f9ab9
--- /dev/null
@@ -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 (file)
index 0000000..37da480
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Check decoding of oldstat syscall.
+ *
+ * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
+ * 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>
+
+#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 (executable)
index 0000000..42d70f7
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+# Check oldstat syscall decoding.
+
+. "${srcdir=.}/statx.sh"
index a04a3dabacab752679651436229deb59992b8be4..2fda6f813c567062bcfdf4b4742013fca61cea87 100644 (file)
@@ -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 +++");