Module Name:    src
Committed By:   justin
Date:           Fri Oct 31 12:22:38 UTC 2014

Modified Files:
        src/tests/lib/libc/gen: t_time.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/gen/t_time.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libc/gen/t_time.c
diff -u src/tests/lib/libc/gen/t_time.c:1.2 src/tests/lib/libc/gen/t_time.c:1.3
--- src/tests/lib/libc/gen/t_time.c:1.2	Fri Nov 11 05:03:38 2011
+++ src/tests/lib/libc/gen/t_time.c	Fri Oct 31 12:22:38 2014
@@ -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_HEAD(time_timeofday, tc)
 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");
 }
 

Reply via email to