Changeset View
Changeset View
Standalone View
Standalone View
contrib/netbsd-tests/lib/libpthread/t_condwait.c
/* $NetBSD: t_condwait.c,v 1.5 2017/01/16 16:29:19 christos Exp $ */ | /* $NetBSD: t_condwait.c,v 1.8 2019/08/11 11:42:23 martin Exp $ */ | ||||
/* | /* | ||||
* Copyright (c) 2013 The NetBSD Foundation, Inc. | * Copyright (c) 2013 The NetBSD Foundation, Inc. | ||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
Show All 11 Lines | |||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||||
* POSSIBILITY OF SUCH DAMAGE. | * POSSIBILITY OF SUCH DAMAGE. | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__RCSID("$NetBSD: t_condwait.c,v 1.5 2017/01/16 16:29:19 christos Exp $"); | __RCSID("$NetBSD: t_condwait.c,v 1.8 2019/08/11 11:42:23 martin Exp $"); | ||||
#include <sys/time.h> | #include <sys/time.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <atf-c.h> | #include <atf-c.h> | ||||
#include "isqemu.h" | #include "isqemu.h" | ||||
#include "h_common.h" | #include "h_common.h" | ||||
#define WAITTIME 2 /* Timeout wait secound */ | #define WAITTIME 2 /* Timeout wait secound */ | ||||
static const int debug = 1; | static const int debug = 1; | ||||
static void * | static void * | ||||
run(void *param) | run(void *param) | ||||
{ | { | ||||
struct timespec ts, to, te; | struct timespec ts, to, te, twmin, twmax; | ||||
#ifdef __FreeBSD__ | |||||
struct timespec tw; | |||||
#endif | |||||
clockid_t clck; | clockid_t clck; | ||||
pthread_condattr_t attr; | pthread_condattr_t attr; | ||||
pthread_cond_t cond; | pthread_cond_t cond; | ||||
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; | pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; | ||||
int ret = 0; | int ret = 0; | ||||
clck = *(clockid_t *)param; | clck = *(clockid_t *)param; | ||||
Show All 18 Lines | case ETIMEDOUT: | ||||
ATF_REQUIRE_EQ(clock_gettime(clck, &te), 0); | ATF_REQUIRE_EQ(clock_gettime(clck, &te), 0); | ||||
timespecsub(&te, &to, &to); | timespecsub(&te, &to, &to); | ||||
if (debug) { | if (debug) { | ||||
printf("timeout: %lld.%09ld sec\n", | printf("timeout: %lld.%09ld sec\n", | ||||
(long long)te.tv_sec, te.tv_nsec); | (long long)te.tv_sec, te.tv_nsec); | ||||
printf("elapsed: %lld.%09ld sec\n", | printf("elapsed: %lld.%09ld sec\n", | ||||
(long long)to.tv_sec, to.tv_nsec); | (long long)to.tv_sec, to.tv_nsec); | ||||
} | } | ||||
twmin.tv_sec = WAITTIME; | |||||
twmin.tv_nsec = 0; | |||||
if (isQEMU()) { | if (isQEMU()) { | ||||
double to_seconds = to.tv_sec + 1e-9 * to.tv_nsec; | struct timespec td, t; | ||||
ATF_REQUIRE(to_seconds >= WAITTIME * 0.9); | // td.tv_sec = 0; | ||||
/* Loose upper limit because of qemu timing bugs */ | // td.tv_nsec = 900000000; | ||||
ATF_REQUIRE(to_seconds < WAITTIME * 2.5); | t = twmin; | ||||
// timespecsub(&t, &td, &twmin); | |||||
td.tv_sec = 2; | |||||
td.tv_nsec = 500000000; | |||||
timespecadd(&t, &td, &twmax); | |||||
} else { | } else { | ||||
#ifdef __FreeBSD__ | twmax = twmin; | ||||
tw.tv_sec = WAITTIME; | twmax.tv_sec++; | ||||
tw.tv_nsec = 0; | |||||
ATF_REQUIRE(timespeccmp(&to, &tw, >=)); | |||||
tw.tv_sec++; | |||||
ATF_REQUIRE(timespeccmp(&to, &tw, <=)); | |||||
#else | |||||
ATF_REQUIRE_EQ(to.tv_sec, WAITTIME); | |||||
#endif | |||||
} | } | ||||
ATF_REQUIRE(timespeccmp(&to, &twmin, >=)); | |||||
ATF_REQUIRE(timespeccmp(&to, &twmax, <=)); | |||||
break; | break; | ||||
default: | default: | ||||
ATF_REQUIRE_MSG(0, "pthread_cond_timedwait: %s", strerror(ret)); | ATF_REQUIRE_MSG(0, "pthread_cond_timedwait: %s", strerror(ret)); | ||||
} | } | ||||
ATF_REQUIRE_MSG(!(ret = pthread_mutex_unlock(&m)), | ATF_REQUIRE_MSG(!(ret = pthread_mutex_unlock(&m)), | ||||
"pthread_mutex_unlock: %s", strerror(ret)); | "pthread_mutex_unlock: %s", strerror(ret)); | ||||
pthread_exit(&ret); | pthread_exit(&ret); | ||||
Show All 32 Lines | |||||
ATF_TC_BODY(cond_wait_mono, tc) { | ATF_TC_BODY(cond_wait_mono, tc) { | ||||
cond_wait(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); | cond_wait(CLOCK_MONOTONIC, "CLOCK_MONOTONIC"); | ||||
} | } | ||||
ATF_TP_ADD_TCS(tp) | ATF_TP_ADD_TCS(tp) | ||||
{ | { | ||||
ATF_TP_ADD_TC(tp, cond_wait_real); | ATF_TP_ADD_TC(tp, cond_wait_real); | ||||
ATF_TP_ADD_TC(tp, cond_wait_mono); | ATF_TP_ADD_TC(tp, cond_wait_mono); | ||||
return 0; | return atf_no_error(); | ||||
} | } |