]> granicus.if.org Git - strace/commitdiff
tests: replace old stat tests with stat.test and stat64.test
authorDmitry V. Levin <ldv@altlinux.org>
Sat, 5 Dec 2015 00:03:49 +0000 (00:03 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 5 Dec 2015 00:03:49 +0000 (00:03 +0000)
* tests/stat.c: Replace with a wrapper around lstatx.c
* tests/stat.test: Replace with a wrapper around statx.sh.
* tests/stat32-v.test: Remove.
* tests/stat32.c: Remove.
* tests/stat64-v.test: Remove.
* tests/stat64.c: New file.
* tests/stat64.test: New test.
* tests/Makefile.am (check_PROGRAMS): Replace stat32 with stat64.
(stat_CFLAGS): Rename to stat64_CFLAGS.
(TESTS): Replace stat32-v.test and stat64-v.test with stat64.test.
* tests/.gitignore: Replace stat32 with stat64.

tests/.gitignore
tests/Makefile.am
tests/stat.c
tests/stat.test
tests/stat32-v.test [deleted file]
tests/stat32.c [deleted file]
tests/stat64-v.test [deleted file]
tests/stat64.c [new file with mode: 0644]
tests/stat64.test [new file with mode: 0755]

index 69b09830fef9400d26e76a337095adf6d3599bbb..2a2fca86e570a742f9afa77b013f4afe51627669 100644 (file)
@@ -66,7 +66,7 @@ signalfd
 sigreturn
 stack-fcall
 stat
-stat32
+stat64
 statfs
 struct_flock
 sysinfo
index 85fc147e5dbcebc42fc47d1f960535be4d6574d7..3bb44eb03a1e5e61c7bdb6eeeb0af0718823d341 100644 (file)
@@ -79,7 +79,7 @@ check_PROGRAMS = \
        sigreturn \
        stack-fcall \
        stat \
-       stat32 \
+       stat64 \
        statfs \
        struct_flock \
        sysinfo \
@@ -118,7 +118,7 @@ mmap64_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
 mq_LDADD = -lrt
 newfstatat_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
 pc_LDADD = $(dl_LIBS)
-stat_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
+stat64_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
 statfs_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
 times_LDADD = -lrt
 truncate64_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
@@ -180,8 +180,7 @@ TESTS = \
        signalfd.test \
        sigreturn.test \
        stat.test \
-       stat32-v.test \
-       stat64-v.test \
+       stat64.test \
        statfs.test \
        struct_flock.test \
        sysinfo.test \
index 154c92fb5843e9627fa58a30d8723dd432d8ab34..356f23ada5325fb347041c2dafeda5a7964fdb9f 100644 (file)
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
-#include <assert.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <time.h>
 
-#if defined MAJOR_IN_SYSMACROS
-# include <sys/sysmacros.h>
-#elif defined MAJOR_IN_MKDEV
-# include <sys/mkdev.h>
-#else
-# include <sys/types.h>
-#endif
-
-#undef STAT_PREFIX
-#undef NR_stat
-
-#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
-# include <sys/stat.h>
-# define STAT_PREFIX "(stat(64)?\\(|newfstatat\\(AT_FDCWD, )"
-# undef HAVE_STRUCT_STAT_ST_ATIME_NSEC
-# ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC
-#  define HAVE_STRUCT_STAT_ST_ATIME_NSEC 1
-#  define st_atime_nsec st_atim.tv_nsec
-# endif
-# undef HAVE_STRUCT_STAT_ST_MTIME_NSEC
-# ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
-#  define HAVE_STRUCT_STAT_ST_MTIME_NSEC 1
-#  define st_mtime_nsec st_mtim.tv_nsec
-# endif
-# undef HAVE_STRUCT_STAT_ST_CTIME_NSEC
-# ifdef HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC
-#  define HAVE_STRUCT_STAT_ST_CTIME_NSEC 1
-#  define st_ctime_nsec st_ctim.tv_nsec
-# endif
-#else
-# include <sys/syscall.h>
-# if defined __NR_stat
-#  define NR_stat __NR_stat
-#  define STAT_PREFIX "stat\\("
-# elif defined __NR_newstat
-#  define NR_stat __NR_newstat
-#  define STAT_PREFIX "newstat\\("
-# endif
-# ifdef STAT_PREFIX
-/* for S_IFMT */
-#  define stat libc_stat
-#  define stat64 libc_stat64
-#  include <sys/stat.h>
-#  undef stat
-#  undef stat64
-#  undef st_atime
-#  undef st_mtime
-#  undef st_ctime
-
-#  undef dev_t
-#  undef ino_t
-#  undef mode_t
-#  undef nlink_t
-#  undef uid_t
-#  undef gid_t
-#  undef off_t
-#  undef loff_t
-#  define dev_t __kernel_dev_t
-#  define ino_t __kernel_ino_t
-#  define mode_t __kernel_mode_t
-#  define nlink_t __kernel_nlink_t
-#  define uid_t __kernel_uid_t
-#  define gid_t __kernel_gid_t
-#  define off_t __kernel_off_t
-#  define loff_t __kernel_loff_t
-#  include <asm/stat.h>
-#  endif /* STAT_PREFIX */
-#endif /* _FILE_OFFSET_BITS */
-
-#ifdef STAT_PREFIX
-
-static void
-print_ftype(unsigned int mode)
-{
-       if (S_ISREG(mode))
-               printf("S_IFREG");
-       else if (S_ISDIR(mode))
-               printf("S_IFDIR");
-       else if (S_ISCHR(mode))
-               printf("S_IFCHR");
-       else if (S_ISBLK(mode))
-               printf("S_IFBLK");
-       else
-               printf("%#o", mode & S_IFMT);
-}
-
-static void
-print_perms(unsigned int mode)
-{
-       printf("%#o", mode & ~S_IFMT);
-}
-
-static void
-print_time(time_t t)
-{
-       if (!t) {
-               printf("0");
-               return;
-       }
-
-       struct tm *p = localtime(&t);
-
-       if (p)
-               printf("%02d/%02d/%02d-%02d:%02d:%02d",
-                      p->tm_year + 1900, p->tm_mon + 1, p->tm_mday,
-                      p->tm_hour, p->tm_min, p->tm_sec);
-       else
-               printf("%llu", (unsigned long long) t);
-}
-
-int
-main(int ac, const char **av)
-{
-       assert(ac == 2);
-       struct stat stb;
+#include <sys/syscall.h>
 
-#ifdef NR_stat
-# if defined __x86_64__ && defined __ILP32__
-       return 77;      /* x32 stat is 64-bit */
-# else
-       if (sizeof(stb.st_size) > 4)
-               return 77;
-       assert(syscall(NR_stat, av[1], &stb) == 0);
-       if (!stb.st_mode)
-               return 77;
-# endif
-#else
-       assert(stat(av[1], &stb) == 0);
+#undef TEST_SYSCALL_NAME
+#ifdef __NR_stat
+# define TEST_SYSCALL_NAME stat
+# define SAMPLE_SIZE ((kernel_ulong_t) 43147718418)
 #endif
 
-       printf(STAT_PREFIX "\"%s\", \\{", av[1]);
-       printf("st_dev=makedev\\(%u, %u\\)",
-              (unsigned int) major(stb.st_dev),
-              (unsigned int) minor(stb.st_dev));
-       printf(", st_ino=%llu", (unsigned long long) stb.st_ino);
-       printf(", st_mode=");
-               print_ftype(stb.st_mode);
-               printf("\\|");
-               print_perms(stb.st_mode);
-       printf(", st_nlink=%u", (unsigned int) stb.st_nlink);
-       printf(", st_uid=%u", (unsigned int) stb.st_uid);
-       printf(", st_gid=%u", (unsigned int) stb.st_gid);
-#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
-       printf(", st_blksize=%u", (unsigned int) stb.st_blksize);
-#endif
-#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
-       printf(", st_blocks=%u", (unsigned int) stb.st_blocks);
-#endif
-
-       switch (stb.st_mode & S_IFMT) {
-       case S_IFCHR: case S_IFBLK:
-#ifdef HAVE_STRUCT_STAT_ST_RDEV
-               printf(", st_rdev=makedev\\(%u, %u\\)",
-                      (unsigned int) major(stb.st_rdev),
-                      (unsigned int) minor(stb.st_rdev));
-#else
-               printf(", st_size=makedev\\(%u, %u\\)",
-                      (unsigned int) major(stb.st_size),
-                      (unsigned int) minor(stb.st_size));
-#endif
-               break;
-       default:
-               printf(", st_size=%llu", (unsigned long long) stb.st_size);
-       }
-
-       printf(", st_atime=");
-               print_time(stb.st_atime);
-#ifdef HAVE_STRUCT_STAT_ST_ATIME_NSEC
-       if (stb.st_atime_nsec)
-               printf(".%09lu", (unsigned long) stb.st_atime_nsec);
-#endif
-       printf(", st_mtime=");
-               print_time(stb.st_mtime);
-#ifdef HAVE_STRUCT_STAT_ST_MTIME_NSEC
-       if (stb.st_mtime_nsec)
-               printf(".%09lu", (unsigned long) stb.st_mtime_nsec);
-#endif
-       printf(", st_ctime=");
-               print_time(stb.st_ctime);
-#ifdef HAVE_STRUCT_STAT_ST_CTIME_NSEC
-       if (stb.st_ctime_nsec)
-               printf(".%09lu", (unsigned long) stb.st_ctime_nsec);
-#endif
-       printf("(, st_flags=[0-9]+)?");
-       printf("(, st_fstype=[^,]*)?");
-       printf("(, st_gen=[0-9]+)?");
-       printf("\\}");
-#ifndef NR_stat
-       printf("(, 0)?");
-#endif
-       printf("\\) += 0\n");
-       return 0;
-}
-
-#else /* !STAT_PREFIX */
-int main(void)
-{
-       return 77;
-}
-#endif
+#include "lstatx.c"
index 3e1790a4f60f55f6230ad295b1504e1328f7feac..ba8938c02abf02f67dea9ec703572c451fa7a219 100755 (executable)
@@ -1,61 +1,5 @@
 #!/bin/sh
 
-# Check how ftruncate, lseek and stat family syscalls are traced.
+# Check stat syscall decoding.
 
-. "${srcdir=.}/init.sh"
-
-check_prog dd
-check_prog find
-
-EXPECTED="$LOG.expected"
-size=46118400000
-sample=stat_sample
-
-rm -f $sample
-umask 022
-
-run_prog_skip_if_failed \
-       dd seek=$size bs=1 count=0 if=/dev/null of=$sample
-run_strace -edesc $args
-
-r_ftruncate="ftruncate(64)?\\(1, $size\\) += 0"
-r_lseek="lseek\\(1, $size, SEEK_CUR\\) += $size"
-r_llseek="_llseek\\(1, $size, \\[$size\\], SEEK_CUR\\) += 0"
-
-cat > "$EXPECTED" << __EOF__
-$r_ftruncate
-$r_lseek|$r_llseek
-__EOF__
-
-match_grep "$LOG" "$EXPECTED"
-
-run_prog_skip_if_failed \
-       find -L $sample -quit
-run_strace -efile $args
-
-stat="\\{st_mode=S_IFREG\\|0644, st_size=$size, \\.\\.\\.\\}"
-r_stat="stat(64)?\\(\"$sample\", $stat\\) += 0"
-r_fstatat="(new)?fstatat(64)?\\(AT_FDCWD, \"$sample\", $stat, 0\\) += 0"
-
-cat > "$EXPECTED" << __EOF__
-$r_stat|$r_fstatat
-__EOF__
-
-match_grep "$LOG" "$EXPECTED"
-
-run_prog_skip_if_failed \
-       find $sample -quit
-run_strace -efile $args
-
-r_lstat="lstat(64)?\\(\"$sample\", $stat\\) += 0"
-r_lfstatat="(new)?fstatat(64)?\\(AT_FDCWD, \"$sample\", $stat, AT_SYMLINK_NOFOLLOW\\) += 0"
-
-cat > "$EXPECTED" << __EOF__
-$r_lstat|$r_lfstatat
-__EOF__
-
-match_grep "$LOG" "$EXPECTED"
-
-rm -f "$EXPECTED" $sample
-
-exit 0
+. "${srcdir=.}/statx.sh"
diff --git a/tests/stat32-v.test b/tests/stat32-v.test
deleted file mode 100755 (executable)
index 46e49f4..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-# Check verbose decoding of 32-bit stat syscall.
-
-. "${srcdir=.}/init.sh"
-
-run_prog ./stat32 . > /dev/null
-
-check_prog dd
-check_prog touch
-
-OUT="$LOG.out"
-size=233811181
-sample=stat32_sample
-
-umask 022
-run_prog_skip_if_failed \
-       dd seek=$size bs=1 count=0 if=/dev/null of=$sample
-
-run_prog_skip_if_failed \
-       touch -t 0102030405 $sample
-
-for f in $sample . /dev/null; do
-       run_strace -v -efile ./stat32 $f > "$OUT"
-       match_grep "$LOG" "$OUT"
-done
-
-rm -f $sample "$OUT"
-
-exit 0
diff --git a/tests/stat32.c b/tests/stat32.c
deleted file mode 100644 (file)
index a074251..0000000
+++ /dev/null
@@ -1 +0,0 @@
-#include "stat.c"
diff --git a/tests/stat64-v.test b/tests/stat64-v.test
deleted file mode 100755 (executable)
index a8122f0..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-# Check verbose decoding of 64-bit stat syscall.
-
-. "${srcdir=.}/init.sh"
-
-run_prog ./stat . > /dev/null
-
-check_prog dd
-check_prog touch
-
-OUT="$LOG.out"
-size=46118400000
-sample=stat64_sample
-
-umask 022
-run_prog_skip_if_failed \
-       dd seek=$size bs=1 count=0 if=/dev/null of=$sample
-
-run_prog_skip_if_failed \
-       touch -d '1970-01-01 -42 seconds' $sample
-
-for f in $sample . /dev/null; do
-       run_strace -v -efile ./stat $f > "$OUT"
-       match_grep "$LOG" "$OUT"
-done
-
-rm -f $sample "$OUT"
-
-exit 0
diff --git a/tests/stat64.c b/tests/stat64.c
new file mode 100644 (file)
index 0000000..592ba2e
--- /dev/null
@@ -0,0 +1,14 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <sys/syscall.h>
+
+#undef TEST_SYSCALL_NAME
+#ifdef __NR_stat64
+# define TEST_SYSCALL_NAME stat64
+# define STRUCT_STAT struct stat64
+# define SAMPLE_SIZE ((libc_off_t) 43147718418)
+#endif
+
+#include "lstatx.c"
diff --git a/tests/stat64.test b/tests/stat64.test
new file mode 100755 (executable)
index 0000000..abcfb9e
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+# Check stat64 syscall decoding.
+
+. "${srcdir=.}/statx.sh"