From 4a3dd59305953d9bde2741bbdf0ef39d8c1321f7 Mon Sep 17 00:00:00 2001 From: justin Date: Fri, 31 Oct 2014 12:22:38 +0000 Subject: [PATCH] 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. --- tests/lib/libc/gen/t_time.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/lib/libc/gen/t_time.c b/tests/lib/libc/gen/t_time.c index bfbdc73d5db7..4496f59efaf0 100644 --- a/tests/lib/libc/gen/t_time.c +++ b/tests/lib/libc/gen/t_time.c @@ -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 -__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 #include @@ -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"); }