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.
This commit is contained in:
parent
76fdf39e44
commit
4a3dd59305
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue