Browse Source

Fix the testsuite

* tests/sparse05.at: Use autom4te magic to generate mapfile,
instead of the shell command seq, which is not always available.
* tests/listed03.at: Skip the test if xgetcwd fails.
* tests/ckmtime.c: New file.
* tests/Makefile.am: Build ckmtime
* tests/testsuite.at (AT_CHECK_TIMESTAMP): Check whether newly created
files have timestamps consistent with the creation time.  Skip the test
if not.
* tests/incr01.at: Use AT_CHECK_TIMESTAMP
* tests/incr02.at: Likewise.
* tests/incr03.at: Likewise.
* tests/incr04.at: Likewise.
* tests/incr05.at: Likewise.
* tests/incr06.at: Likewise.
* tests/incr07.at: Likewise.
* tests/incr08.at: Likewise.
* tests/incr09.at: Likewise.
* tests/incr10.at: Likewise.
* tests/incr11.at: Likewise.
* tests/incremental.at: Likewise.
* tests/listed01.at: Likewise.
* tests/listed02.at: Likewise.
* tests/listed04.at: Likewise.
* tests/listed05.at: Likewise.
Sergey Poznyakoff 9 years ago
parent
commit
143dc63ffa

+ 1 - 0
tests/.gitignore

@@ -11,3 +11,4 @@ genfile
 download
 ttyemu
 checkseekhole
+ckmtime

+ 1 - 1
tests/Makefile.am

@@ -281,7 +281,7 @@ installcheck-local: $(check_PROGRAMS)
 ## genfile      ##
 ## ------------ ##
 
-check_PROGRAMS = genfile checkseekhole
+check_PROGRAMS = genfile checkseekhole ckmtime
 
 if TAR_COND_GRANTPT
 check_PROGRAMS += ttyemu

+ 48 - 0
tests/ckmtime.c

@@ -0,0 +1,48 @@
+/* Check if filesystem timestamps are consistent with the system time.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+      
+   This program is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published by the
+   Free Software Foundation; either version 3, or (at your option) any later
+   version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+   Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include <config.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stat-time.h>
+#include <timespec.h>
+
+int
+main (int argc, char **argv)
+{
+  FILE *fp;
+  struct timeval tv;
+  struct stat st;
+  struct timespec ts;
+  
+  assert (gettimeofday (&tv, NULL) == 0);
+  ts.tv_sec = tv.tv_sec;
+  ts.tv_nsec = tv.tv_usec * 1000;
+  
+  fp = tmpfile ();
+  assert (fp != NULL);
+  assert (fstat (fileno (fp), &st) == 0);
+  fclose (fp);
+  if (timespec_cmp (get_stat_mtime (&st), ts) >= 0)
+    {
+      fprintf (stderr, "file timestamp unreliable\n");
+      return 1;
+    }
+  return 0;
+}

+ 2 - 0
tests/incr01.at

@@ -28,6 +28,8 @@ AT_SETUP([restore broken symlinks from incremental])
 AT_KEYWORDS([incremental incr01])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
+
 mkdir directory
 $as_ln_s foo directory/bar
 

+ 1 - 0
tests/incr02.at

@@ -33,6 +33,7 @@ AT_SETUP([restoring timestamps from incremental])
 AT_KEYWORDS([incremental timestamp restore incr02])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 # Create directory structure
 mkdir dir
 mkdir dir/subdir1

+ 1 - 0
tests/incr03.at

@@ -30,6 +30,7 @@ AT_SETUP([renamed files in incrementals])
 AT_KEYWORDS([incremental incr03 rename])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 AT_SORT_PREREQ
 mkdir directory
 genfile --file=directory/x

+ 1 - 0
tests/incr04.at

@@ -33,6 +33,7 @@ AT_KEYWORDS([incremental incr04 icontents])
 m4_pushdef([NAME_PREFIX],[a/b/one_31_chars_long_file_name_])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 AT_TAR_MKHIER(a/b)
 awk 'BEGIN {
   for (i=1;i<=142;i++)

+ 1 - 0
tests/incr05.at

@@ -22,6 +22,7 @@ AT_SETUP([incremental dumps with -C])
 AT_KEYWORDS([incremental incr05])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 mkdir dir
 mkdir dir/sub
 genfile --file dir/file1

+ 1 - 0
tests/incr06.at

@@ -22,6 +22,7 @@ AT_SETUP([incremental dumps of nested directories])
 AT_KEYWORDS([incremental incr06])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 mkdir dir
 mkdir dir/sub
 mkdir dir/sub/a

+ 1 - 0
tests/incr07.at

@@ -38,6 +38,7 @@ AT_KEYWORDS([incremental extract incr07])
 #             http://lists.gnu.org/archive/html/bug-tar/2013-03/msg00044.html
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 mkdir dirA
 echo 'a' > dirA/a
 echo 'a' > dirA/b

+ 1 - 0
tests/incr08.at

@@ -39,6 +39,7 @@ AT_SETUP([filename normalization])
 AT_KEYWORDS([incremental create incr08])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 AT_SORT_PREREQ
 mkdir tartest
 cd tartest

+ 1 - 0
tests/incr09.at

@@ -27,6 +27,7 @@ AT_SETUP([incremental with alternating -C])
 AT_KEYWORDS([incremental create incr09])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 AT_SORT_PREREQ
 mkdir foo bar middle
 echo foo/foo_file > foo/foo_file

+ 1 - 0
tests/incr10.at

@@ -26,6 +26,7 @@ AT_KEYWORDS([incremental concat cat incr10])
 #             http://lists.gnu.org/archive/html/bug-tar/2015-04/msg00003.html
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 mkdir in
 mkdir in/dir
 decho Level 0

+ 1 - 0
tests/incr11.at

@@ -26,6 +26,7 @@ AT_SETUP([concatenated incremental archives (renames)])
 AT_KEYWORDS([incremental concat cat incr11])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 AT_SORT_PREREQ
 AT_TAR_MKHIER([data/dir],[file])
 decho Level 0

+ 2 - 0
tests/incremental.at

@@ -24,6 +24,8 @@ AT_SETUP([incremental])
 AT_KEYWORDS([incremental listed incr00])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
+
 mkdir structure
 echo x >structure/file
 

+ 2 - 0
tests/listed01.at

@@ -28,6 +28,8 @@ AT_SETUP([--listed for individual files])
 AT_KEYWORDS([listed incremental listed01])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
+
 mkdir directory
 genfile --length 10240 --pattern zeros --file directory/file1
 # Let the things settle

+ 1 - 0
tests/listed02.at

@@ -30,6 +30,7 @@ AT_SETUP([working --listed])
 AT_KEYWORDS([listed incremental listed02])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 AT_SORT_PREREQ
 echo Create directories
 

+ 6 - 1
tests/listed03.at

@@ -25,6 +25,7 @@ AT_SETUP([incremental dump when the parent directory is unreadable])
 AT_KEYWORDS([listed incremental listed03])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 AT_UNPRIVILEGED_PREREQ
 
 mkdir dir
@@ -34,9 +35,13 @@ genfile --file dir/sub/a/file
 cd dir/sub
 
 chmod a-r ..
-tar -c -f archive.tar --listed-incremental=db.1 -v a
+tar -c -f archive.tar --listed-incremental=db.1 -v a 2>err
 status=$?
 chmod a+r ..
+if test $status -eq 2; then
+  grep '^tar: \.: Cannot getcwd' err >/dev/null 2>&1 && AT_SKIP_TEST
+fi
+cat err >&2
 exit $status
 ],
 [0],

+ 1 - 1
tests/listed04.at

@@ -27,7 +27,7 @@ AT_SETUP([--listed-incremental and --one-file-system])
 AT_KEYWORDS([listed incremental listed04])
 
 AT_TAR_CHECK([
-
+AT_CHECK_TIMESTAMP
 mkdir dir
 echo a >dir/a
 echo b >dir/b

+ 1 - 0
tests/listed05.at

@@ -34,6 +34,7 @@ AT_SETUP([--listed-incremental and remounted directories])
 AT_KEYWORDS([listed incremental listed05])
 
 AT_TAR_CHECK([
+AT_CHECK_TIMESTAMP
 AT_PRIVILEGED_PREREQ
 options="-C tartest --create --one-file-system --verbose"
 rm -rf archive-[01].snar archive-[01].tar tartest subdir

+ 5 - 4
tests/sparse05.at

@@ -29,10 +29,11 @@ AT_KEYWORDS([sparse sparse05])
 #             http://lists.gnu.org/archive/html/bug-tar/2013-01/msg00001.html
 
 AT_TAR_CHECK([
-(echo 0 =2560
-for i in `seq 1 999`; do
-    echo 10M =2560
-done) | genfile --sparse --file BIGFILE --block-size 4K - || AT_SKIP_TEST
+AT_DATA([mapfile],
+[0 =2560
+m4_for([i], 1, 999, 1, [10M =2560
+])])
+genfile --sparse --file BIGFILE --block-size 4K - < mapfile || AT_SKIP_TEST
 tar -f - -c --sparse --posix BIGFILE | tar tvf - | awk '{ print $3, $(NF) }'
 ],
 [0],

+ 4 - 0
tests/testsuite.at

@@ -188,6 +188,10 @@ m4_define([AT_ACLS_PREREQ],[
   fi
 ])
 
+dnl Check whether a newly created file has timestamp consistent with the
+dnl local time.  Skip the test if not.
+m4_define([AT_CHECK_TIMESTAMP],[ckmtime || AT_SKIP_TEST])
+
 m4_include([sparsemvp.at])
 
 AT_INIT