예제 #1
0
파일: t_condwait.c 프로젝트: Hooman3/minix
static void *
run(void *param)
{
	struct timespec ts, to, te;
	clockid_t clck;
	pthread_condattr_t attr;
	pthread_cond_t cond;
	pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
	int ret = 0;


	clck = *(clockid_t *)param;
	pthread_condattr_init(&attr);
	pthread_condattr_setclock(&attr, clck); /* MONOTONIC or MONOTONIC */
	pthread_cond_init(&cond, &attr);

	ATF_REQUIRE_EQ((ret = pthread_mutex_lock(&m)), 0);

	ATF_REQUIRE_EQ(clock_gettime(clck, &ts), 0);
	to = ts;

	if (debug)
		printf("started: %lld.%09ld sec\n", (long long)to.tv_sec,
		    to.tv_nsec);

	ts.tv_sec += WAITTIME;	/* Timeout wait */

	switch (ret = pthread_cond_timedwait(&cond, &m, &ts)) {
	case ETIMEDOUT:
		/* Timeout */
		ATF_REQUIRE_EQ(clock_gettime(clck, &te), 0);
		timespecsub(&te, &to, &to);
		if (debug) {
			printf("timeout: %lld.%09ld sec\n",
			    (long long)te.tv_sec, te.tv_nsec);
			printf("elapsed: %lld.%09ld sec\n",
			    (long long)to.tv_sec, to.tv_nsec);
		}
		if (isQEMU()) {
			double to_seconds = to.tv_sec + 1e-9 * to.tv_nsec;
			ATF_REQUIRE(to_seconds >= WAITTIME * 0.9);
			/* Loose upper limit because of qemu timing bugs */
			ATF_REQUIRE(to_seconds < WAITTIME * 2.5);
		} else {
			ATF_REQUIRE_EQ(to.tv_sec, WAITTIME);
		}
		break;
	default:
		ATF_REQUIRE_MSG(0, "pthread_cond_timedwait: %s", strerror(ret));
	}

	ATF_REQUIRE_MSG(!(ret = pthread_mutex_unlock(&m)),
	    "pthread_mutex_unlock: %s", strerror(ret));
	pthread_exit(&ret);
}
예제 #2
0
파일: t_siginfo.c 프로젝트: Hooman3/minix
ATF_TC_BODY(sigbus_adraln, tc)
{
	const char *arch = atf_config_get("atf_arch");
	struct sigaction sa;

	if (strcmp(arch, "alpha") == 0) {
		int rv, val;
		size_t len = sizeof(val);
		rv = sysctlbyname("machdep.unaligned_sigbus", &val, &len,
			NULL, 0);
		ATF_REQUIRE(rv == 0);
		if (val == 0)
			atf_tc_skip("SIGBUS signal not enabled for"
				    " unaligned accesses");

	}

	sa.sa_flags = SA_SIGINFO;
	sa.sa_sigaction = sigbus_action;
	sigemptyset(&sa.sa_mask);
	sigaction(SIGBUS, &sa, NULL);

	/* Enable alignement checks for x86. 0x40000 is PSL_AC. */
#if defined(__i386__)
	__asm__("pushf; orl $0x40000, (%esp); popf");
#elif defined(__amd64__)
	__asm__("pushf; orl $0x40000, (%rsp); popf");
#endif

	addr = calloc(2, sizeof(int));
	ATF_REQUIRE(addr != NULL);

	if (isQEMU())
		atf_tc_expect_fail("QEMU fails to trap unaligned accesses");

	/* Force an unaligned access */
	addr++;
	printf("now trying to access unaligned address %p\n", addr);
	ATF_REQUIRE_EQ(*(volatile int *)addr, 0);

	atf_tc_fail("Test did not fault as expected");
}
예제 #3
0
파일: t_sleep.c 프로젝트: ryo/netbsd-src
int
do_kevent(struct timespec *delay, struct timespec *remain)
{
	struct kevent ktimer;
	struct kevent kresult;
	int rtc, kq, kerrno;
	int tmo;

	ATF_REQUIRE_MSG((kq = kqueue()) != -1, "kqueue: %s", strerror(errno));

	tmo = KEVNT_TIMEOUT;

	/*
	 * If we expect the KEVNT_TIMEOUT to fire, and we're running
	 * under QEMU, make sure the delay is long enough to account
	 * for the effects of PR kern/43997 !
	 */
	if (isQEMU() &&
	    tmo/1000 < delay->tv_sec && tmo/500 > delay->tv_sec)
		delay->tv_sec = MAXSLEEP;

	EV_SET(&ktimer, 1, EVFILT_TIMER, EV_ADD, 0, tmo, 0);

	rtc = kevent(kq, &ktimer, 1, &kresult, 1, delay);
	kerrno = errno;

	(void)close(kq);

	if (rtc == -1) {
		ATF_REQUIRE_MSG(kerrno == EINTR, "kevent: %s",
		    strerror(kerrno));
		return 0;
	}

	if (delay->tv_sec * BILLION + delay->tv_nsec > tmo * MILLION)
		ATF_REQUIRE_MSG(rtc > 0,
		    "kevent: KEVNT_TIMEOUT did not cause EVFILT_TIMER event");

	return 0;
}
예제 #4
0
파일: t_siginfo.c 프로젝트: Hooman3/minix
ATF_TC_BODY(sigfpe_flt, tc)
{
	struct sigaction sa;
	double d = strtod("0", NULL);

	if (isQEMU())
		atf_tc_skip("Test does not run correctly under QEMU");
	if (strcmp(atf_config_get("atf_arch"),"powerpc") == 0)
		atf_tc_skip("Test not valid on powerpc");
	if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
		sa.sa_flags = SA_SIGINFO;
		sa.sa_sigaction = sigfpe_flt_action;
		sigemptyset(&sa.sa_mask);
		sigaction(SIGFPE, &sa, NULL);
#ifdef _FLOAT_IEEE754
		fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
#endif
		printf("%g\n", 1 / d);
	}
	if (fltdiv_signalled == 0)
		atf_tc_fail("FPE signal handler was not invoked");
}