mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
sem_clockwait_np test: relax time constraint on VMs
In a guest on a busy hypervisor, the time remaining after an interrupted sleep could be much lower than other environments. Relax the lower bound on VMs. MFC after: 1 week Sponsored by: Dell EMC Isilon
This commit is contained in:
parent
a36230f75e
commit
31466594cd
|
@ -60,6 +60,11 @@ __COPYRIGHT("@(#) Copyright (c) 2008, 2010\
|
||||||
The NetBSD Foundation, inc. All rights reserved.");
|
The NetBSD Foundation, inc. All rights reserved.");
|
||||||
__RCSID("$NetBSD: t_sem.c,v 1.3 2017/01/14 20:58:20 christos Exp $");
|
__RCSID("$NetBSD: t_sem.c,v 1.3 2017/01/14 20:58:20 christos Exp $");
|
||||||
|
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
@ -78,6 +83,24 @@ __RCSID("$NetBSD: t_sem.c,v 1.3 2017/01/14 20:58:20 christos Exp $");
|
||||||
#define SEM_REQUIRE(x) \
|
#define SEM_REQUIRE(x) \
|
||||||
ATF_REQUIRE_EQ_MSG(x, 0, "%s", strerror(errno))
|
ATF_REQUIRE_EQ_MSG(x, 0, "%s", strerror(errno))
|
||||||
|
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
static bool
|
||||||
|
machine_is_virtual(void)
|
||||||
|
{
|
||||||
|
char vm_guest[32];
|
||||||
|
int error;
|
||||||
|
|
||||||
|
error = sysctlbyname("kern.vm_guest", vm_guest,
|
||||||
|
&(size_t){sizeof(vm_guest)}, NULL, 0);
|
||||||
|
ATF_CHECK_EQ_MSG(0, error, "sysctlbyname(kern.vm_guest): %s",
|
||||||
|
strerror(errno));
|
||||||
|
if (error != 0) {
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
return (strcmp(vm_guest, "none") != 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ATF_TC_WITH_CLEANUP(basic);
|
ATF_TC_WITH_CLEANUP(basic);
|
||||||
ATF_TC_HEAD(basic, tc)
|
ATF_TC_HEAD(basic, tc)
|
||||||
{
|
{
|
||||||
|
@ -306,15 +329,11 @@ ATF_TC_BODY(timedwait, tc)
|
||||||
ATF_REQUIRE_ERRNO(EINTR, sem_clockwait_np(&sem, CLOCK_MONOTONIC, 0, &ts,
|
ATF_REQUIRE_ERRNO(EINTR, sem_clockwait_np(&sem, CLOCK_MONOTONIC, 0, &ts,
|
||||||
&remain));
|
&remain));
|
||||||
ATF_REQUIRE_MSG(got_sigalrm, "did not get SIGALRM");
|
ATF_REQUIRE_MSG(got_sigalrm, "did not get SIGALRM");
|
||||||
/*
|
|
||||||
* If this nsec comparison turns out to be unreliable due to timing,
|
|
||||||
* it could simply check that nsec < 100 ms.
|
|
||||||
*/
|
|
||||||
ATF_REQUIRE_MSG(remain.tv_sec == 0 &&
|
ATF_REQUIRE_MSG(remain.tv_sec == 0 &&
|
||||||
remain.tv_nsec >= 25*1000*1000 &&
|
(remain.tv_nsec >= 25*1000*1000 || machine_is_virtual()) &&
|
||||||
remain.tv_nsec <= 75*1000*1000,
|
remain.tv_nsec <= 75*1000*1000,
|
||||||
"the remaining time was not as expected when a relative clockwait"
|
"the remaining time was not as expected when a relative clockwait"
|
||||||
" got EINTR" );
|
" got EINTR: %ld.%09ld", remain.tv_sec, remain.tv_nsec);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue