Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/gen PR misc/49342 fix issue where time can ti...



details:   https://anonhg.NetBSD.org/src/rev/764c00dbe1a6
branches:  trunk
changeset: 333377:764c00dbe1a6
user:      justin <justin%NetBSD.org@localhost>
date:      Fri Oct 31 12:22:38 2014 +0000

description:
PR misc/49342 fix issue where time can tick during tests

Note there are still potential issues as the clock being tested is not
monotonic but it should now not fail unless time is being adjusted.

diffstat:

 tests/lib/libc/gen/t_time.c |  13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diffs (39 lines):

diff -r e8fddb72f2a8 -r 764c00dbe1a6 tests/lib/libc/gen/t_time.c
--- a/tests/lib/libc/gen/t_time.c       Fri Oct 31 09:11:42 2014 +0000
+++ b/tests/lib/libc/gen/t_time.c       Fri Oct 31 12:22:38 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_time.c,v 1.2 2011/11/11 05:03:38 jruoho Exp $ */
+/*     $NetBSD: t_time.c,v 1.3 2014/10/31 12:22:38 justin Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_time.c,v 1.2 2011/11/11 05:03:38 jruoho Exp $");
+__RCSID("$NetBSD: t_time.c,v 1.3 2014/10/31 12:22:38 justin Exp $");
 
 #include <atf-c.h>
 #include <errno.h>
@@ -91,15 +91,16 @@
 ATF_TC_BODY(time_timeofday, tc)
 {
        struct timeval tv = { 0, 0 };
-       time_t t;
+       time_t t1, t2;
 
-       t = time(NULL);
+       t1 = time(NULL);
        ATF_REQUIRE(gettimeofday(&tv, NULL) == 0);
+       t2 = time(NULL);
 
        (void)fprintf(stderr, "%"PRId64" vs. %"PRId64"\n",
-           (int64_t)t, (int64_t)tv.tv_sec);
+           (int64_t)t1, (int64_t)tv.tv_sec);
 
-       if (t != tv.tv_sec)
+       if (t1 > tv.tv_sec || t2 < tv.tv_sec)
                atf_tc_fail("time(3) and gettimeofday(2) differ");
 }
 



Home | Main Index | Thread Index | Old Index