fix occasional assertion failure of gnulib tests
... that check ctime
This commit is contained in:
parent
a2e0798d1e
commit
48f014bf39
|
@ -0,0 +1,183 @@
|
|||
From 60a155ed296dbeb5fad69a9611e7f5959f99902b Mon Sep 17 00:00:00 2001
|
||||
From: Kamil Dudka <kdudka@redhat.com>
|
||||
Date: Thu, 14 May 2015 18:22:34 +0200
|
||||
Subject: [PATCH] gnulib-tests/nap.h: update from coreutils-8.22
|
||||
|
||||
---
|
||||
gnulib-tests/nap.h | 137 +++++++++++++++++++++++++++++++----------------------
|
||||
1 file changed, 81 insertions(+), 56 deletions(-)
|
||||
|
||||
diff --git a/gnulib-tests/nap.h b/gnulib-tests/nap.h
|
||||
index 342a70c..229e4d3 100644
|
||||
--- a/gnulib-tests/nap.h
|
||||
+++ b/gnulib-tests/nap.h
|
||||
@@ -19,19 +19,37 @@
|
||||
#ifndef GLTEST_NAP_H
|
||||
# define GLTEST_NAP_H
|
||||
|
||||
+# include <limits.h>
|
||||
+# include <stdbool.h>
|
||||
+
|
||||
+/* File descriptor used for the witness file. */
|
||||
+static int nap_fd = -1;
|
||||
+
|
||||
+/* Return A - B, in ns.
|
||||
+ Return 0 if the true result would be negative.
|
||||
+ Return INT_MAX if the true result would be greater than INT_MAX. */
|
||||
static int
|
||||
-lt_mtime (struct stat const *a, struct stat const *b)
|
||||
+diff_timespec (struct timespec a, struct timespec b)
|
||||
{
|
||||
- time_t as = a->st_mtime;
|
||||
- time_t bs = b->st_mtime;
|
||||
- int ans = get_stat_mtime_ns (a);
|
||||
- int bns = get_stat_mtime_ns (b);
|
||||
+ time_t as = a.tv_sec;
|
||||
+ time_t bs = b.tv_sec;
|
||||
+ int ans = a.tv_nsec;
|
||||
+ int bns = b.tv_nsec;
|
||||
|
||||
- return as < bs || (as == bs && ans < bns);
|
||||
+ if (! (bs < as || (bs == as && bns < ans)))
|
||||
+ return 0;
|
||||
+ if (as - bs <= INT_MAX / 1000000000)
|
||||
+ {
|
||||
+ int sdiff = (as - bs) * 1000000000;
|
||||
+ int usdiff = ans - bns;
|
||||
+ if (usdiff < INT_MAX - sdiff)
|
||||
+ return sdiff + usdiff;
|
||||
+ }
|
||||
+ return INT_MAX;
|
||||
}
|
||||
|
||||
static void
|
||||
-get_mtime (int fd, struct stat *st, int do_write)
|
||||
+get_stat (int fd, struct stat *st, int do_write)
|
||||
{
|
||||
if (do_write)
|
||||
ASSERT (write (fd, "\n", 1) == 1);
|
||||
@@ -39,65 +57,72 @@ get_mtime (int fd, struct stat *st, int do_write)
|
||||
}
|
||||
|
||||
/* Given a file whose descriptor is FD, see whether delaying by DELAY
|
||||
- microseconds causes a change in a file's time stamp. If the time
|
||||
- stamps differ, repeat the test one more time, in case we crossed a
|
||||
- quantization boundary on a file system with lower resolution. *ST
|
||||
- is the file's status, recently gotten. Update *ST to reflect the
|
||||
- latest status gotten. */
|
||||
-static int
|
||||
-nap_works (int fd, int delay, struct stat *st)
|
||||
+ nanoseconds causes a change in a file's ctime and mtime.
|
||||
+ OLD_ST is the file's status, recently gotten. */
|
||||
+static bool
|
||||
+nap_works (int fd, int delay, struct stat old_st)
|
||||
{
|
||||
- struct stat old_st;
|
||||
- old_st = *st;
|
||||
- usleep (delay);
|
||||
- get_mtime (fd, st, 1);
|
||||
- if (! lt_mtime (&old_st, st))
|
||||
- return 0;
|
||||
- old_st = *st;
|
||||
- usleep (delay);
|
||||
- get_mtime (fd, st, 1);
|
||||
- return lt_mtime (&old_st, st);
|
||||
+ struct stat st;
|
||||
+ struct timespec delay_spec;
|
||||
+ delay_spec.tv_sec = delay / 1000000000;
|
||||
+ delay_spec.tv_nsec = delay % 1000000000;
|
||||
+ ASSERT (nanosleep (&delay_spec, 0) == 0);
|
||||
+ get_stat (fd, &st, 1);
|
||||
+
|
||||
+ if ( diff_timespec (get_stat_ctime (&st), get_stat_ctime (&old_st))
|
||||
+ && diff_timespec (get_stat_mtime (&st), get_stat_mtime (&old_st)))
|
||||
+ return true;
|
||||
+
|
||||
+ return false;
|
||||
}
|
||||
|
||||
-static int
|
||||
-guess_delay (void)
|
||||
+#define TEMPFILE BASE "nap.tmp"
|
||||
+
|
||||
+static void
|
||||
+clear_temp_file (void)
|
||||
{
|
||||
- /* Try a 1-microsecond sleep first, for speed. If that doesn't
|
||||
- work, try a 1 ms sleep; that should work with ext. If it doesn't
|
||||
- work, try a 20 ms sleep. xfs has a quantization of about 10
|
||||
- milliseconds, even though it has a granularity of 1 nanosecond,
|
||||
- and NTFS has a default quantization of 15.25 milliseconds, even
|
||||
- though it has a granularity of 100 nanoseconds, so 20 ms is a
|
||||
- good quantization to try. If that doesn't work, try 1 second.
|
||||
- The worst case is 2 seconds, needed for FAT. */
|
||||
- static int const delaytab[] = {1, 1000, 20000, 1000000 };
|
||||
- int fd = creat (BASE "tmp", 0600);
|
||||
- int i;
|
||||
- int delay = 2000000;
|
||||
- struct stat st;
|
||||
- ASSERT (0 <= fd);
|
||||
- get_mtime (fd, &st, 0);
|
||||
- for (i = 0; i < sizeof delaytab / sizeof delaytab[0]; i++)
|
||||
- if (nap_works (fd, delaytab[i], &st))
|
||||
- {
|
||||
- delay = delaytab[i];
|
||||
- break;
|
||||
- }
|
||||
- ASSERT (close (fd) == 0);
|
||||
- ASSERT (unlink (BASE "tmp") == 0);
|
||||
- return delay;
|
||||
+ if (0 <= nap_fd)
|
||||
+ {
|
||||
+ ASSERT (close (nap_fd) != -1);
|
||||
+ ASSERT (unlink (TEMPFILE) != -1);
|
||||
+ }
|
||||
}
|
||||
|
||||
/* Sleep long enough to notice a timestamp difference on the file
|
||||
- system in the current directory. Assumes that BASE is defined,
|
||||
- and requires that the test module depends on usleep. */
|
||||
+ system in the current directory. Use an adaptive approach, trying
|
||||
+ to find the smallest delay which works on the current file system
|
||||
+ to make the timestamp difference appear. Assert a maximum delay of
|
||||
+ ~2 seconds, more precisely sum(2^n) from 0 to 30 = 2^31 - 1 = 2.1s.
|
||||
+ Assumes that BASE is defined, and requires that the test module
|
||||
+ depends on nanosleep. */
|
||||
static void
|
||||
nap (void)
|
||||
{
|
||||
- static int delay;
|
||||
- if (!delay)
|
||||
- delay = guess_delay ();
|
||||
- usleep (delay);
|
||||
+ struct stat old_st;
|
||||
+ static int delay = 1;
|
||||
+
|
||||
+ if (-1 == nap_fd)
|
||||
+ {
|
||||
+ atexit (clear_temp_file);
|
||||
+ ASSERT ((nap_fd = creat (TEMPFILE, 0600)) != -1);
|
||||
+ get_stat (nap_fd, &old_st, 0);
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ ASSERT (0 <= nap_fd);
|
||||
+ get_stat (nap_fd, &old_st, 1);
|
||||
+ }
|
||||
+
|
||||
+ if (1 < delay)
|
||||
+ delay = delay / 2; /* Try half of the previous delay. */
|
||||
+ ASSERT (0 < delay);
|
||||
+
|
||||
+ for ( ; delay <= 2147483647; delay = delay * 2)
|
||||
+ if (nap_works (nap_fd, delay, old_st))
|
||||
+ return;
|
||||
+
|
||||
+ /* Bummer: even the highest nap delay didn't work. */
|
||||
+ ASSERT (0);
|
||||
}
|
||||
|
||||
#endif /* GLTEST_NAP_H */
|
||||
--
|
||||
2.4.0
|
||||
|
|
@ -19,6 +19,8 @@ Patch3: coreutils-8.21-ln-updateexisting.patch
|
|||
Patch4: coreutils-8.22-datetzcrash.patch
|
||||
#backport of patch from gnulib fixing tests on powerPC
|
||||
Patch5: coreutils-ppc-gnulib-tests.patch
|
||||
#fix occasional assertion failure of gnulib tests that check ctime
|
||||
Patch6: coreutils-8.21-gnulib-tests-ctime.patch
|
||||
|
||||
# Our patches
|
||||
#general patch to workaround koji build system issues
|
||||
|
@ -136,6 +138,7 @@ the old GNU fileutils, sh-utils, and textutils packages.
|
|||
%patch3 -p1 -b .exist
|
||||
%patch4 -p1 -b .tzcrash
|
||||
%patch5 -p1 -b .ppc
|
||||
%patch6 -p1 -b .ctime
|
||||
|
||||
# Our patches
|
||||
%patch100 -p1 -b .configure
|
||||
|
@ -168,6 +171,10 @@ find ./po/ -name "*.p*" | xargs \
|
|||
sed -i \
|
||||
-e 's/-dpR/-cdpR/'
|
||||
|
||||
# make gnulib tests compatible with [-Werror=format-security]
|
||||
sed -e 's/xasprintf (empty)/xasprintf ("%s", empty)/' \
|
||||
-i gnulib-tests/test-xvasprintf.c
|
||||
|
||||
%build
|
||||
export CFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing -fpic"
|
||||
%{expand:%%global optflags %{optflags} -D_GNU_SOURCE=1}
|
||||
|
@ -384,6 +391,7 @@ fi
|
|||
|
||||
%changelog
|
||||
* Thu May 14 2015 Kamil Dudka <kdudka@redhat.com> 8.21-22
|
||||
- fix occasional assertion failure of gnulib tests that check ctime
|
||||
- sort - fix buffer overflow in some case conversions
|
||||
- patch by Pádraig Brady
|
||||
- Adjust LS_COLORS in 256 color mode; brighten some, remove hardlink colors (#1196642)
|
||||
|
|
Loading…
Reference in New Issue