Add timer_settime tests using SIGEV_THREAD.
Note that these tests should work fine on NetBSD and other systems as SIGEV_THREAD is POSIX. Differential Revision: https://reviews.freebsd.org/D7121
This commit is contained in:
parent
57d5dd7907
commit
f21e85a0ce
@ -116,6 +116,61 @@ timer_signal_create(clockid_t cid, bool expire)
|
||||
ATF_REQUIRE(timer_delete(t) == 0);
|
||||
}
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
static void
|
||||
timer_callback(union sigval value)
|
||||
{
|
||||
timer_t *tp;
|
||||
|
||||
tp = value.sival_ptr;
|
||||
|
||||
if (*tp == t)
|
||||
fail = false;
|
||||
}
|
||||
|
||||
static void
|
||||
timer_thread_create(clockid_t cid, bool expire)
|
||||
{
|
||||
struct itimerspec tim;
|
||||
struct sigevent evt;
|
||||
|
||||
t = 0;
|
||||
fail = true;
|
||||
|
||||
(void)memset(&evt, 0, sizeof(struct sigevent));
|
||||
(void)memset(&tim, 0, sizeof(struct itimerspec));
|
||||
|
||||
/*
|
||||
* Create the timer (SIGEV_THREAD).
|
||||
*/
|
||||
evt.sigev_notify_function = timer_callback;
|
||||
evt.sigev_value.sival_ptr = &t;
|
||||
evt.sigev_notify = SIGEV_THREAD;
|
||||
|
||||
ATF_REQUIRE(timer_create(cid, &evt, &t) == 0);
|
||||
|
||||
/*
|
||||
* Start the timer.
|
||||
*/
|
||||
tim.it_value.tv_sec = expire ? 5 : 1;
|
||||
tim.it_value.tv_nsec = 0;
|
||||
|
||||
ATF_REQUIRE(timer_settime(t, 0, &tim, NULL) == 0);
|
||||
|
||||
(void)sleep(2);
|
||||
|
||||
if (expire) {
|
||||
if (!fail)
|
||||
atf_tc_fail("timer fired too soon");
|
||||
} else {
|
||||
if (fail)
|
||||
atf_tc_fail("timer failed to fire");
|
||||
}
|
||||
|
||||
ATF_REQUIRE(timer_delete(t) == 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
ATF_TC(timer_create_err);
|
||||
ATF_TC_HEAD(timer_create_err, tc)
|
||||
{
|
||||
@ -198,6 +253,64 @@ ATF_TC_BODY(timer_create_mono_expire, tc)
|
||||
timer_signal_create(CLOCK_MONOTONIC, true);
|
||||
}
|
||||
|
||||
ATF_TC(timer_thread_create_real);
|
||||
ATF_TC_HEAD(timer_thread_create_real, tc)
|
||||
{
|
||||
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"Checks timer_create(2) with CLOCK_REALTIME and sigevent(3), "
|
||||
"SIGEV_THREAD");
|
||||
}
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
ATF_TC_BODY(timer_thread_create_real, tc)
|
||||
{
|
||||
timer_thread_create(CLOCK_REALTIME, false);
|
||||
}
|
||||
|
||||
ATF_TC(timer_thread_create_mono);
|
||||
ATF_TC_HEAD(timer_thread_create_mono, tc)
|
||||
{
|
||||
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"Checks timer_create(2) with CLOCK_MONOTONIC and sigevent(3), "
|
||||
"SIGEV_THREAD");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(timer_thread_create_mono, tc)
|
||||
{
|
||||
timer_thread_create(CLOCK_MONOTONIC, false);
|
||||
}
|
||||
|
||||
ATF_TC(timer_thread_create_real_expire);
|
||||
ATF_TC_HEAD(timer_thread_create_real_expire, tc)
|
||||
{
|
||||
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"Checks timer_create(2) with CLOCK_REALTIME and sigevent(3), "
|
||||
"SIGEV_THREAD, with expiration");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(timer_thread_create_real_expire, tc)
|
||||
{
|
||||
timer_thread_create(CLOCK_REALTIME, true);
|
||||
}
|
||||
|
||||
ATF_TC(timer_thread_create_mono_expire);
|
||||
ATF_TC_HEAD(timer_thread_create_mono_expire, tc)
|
||||
{
|
||||
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"Checks timer_create(2) with CLOCK_MONOTONIC and sigevent(3), "
|
||||
"SIGEV_THREAD, with expiration");
|
||||
}
|
||||
|
||||
ATF_TC_BODY(timer_thread_create_mono_expire, tc)
|
||||
{
|
||||
timer_thread_create(CLOCK_MONOTONIC, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
|
||||
@ -206,6 +319,12 @@ ATF_TP_ADD_TCS(tp)
|
||||
ATF_TP_ADD_TC(tp, timer_create_mono);
|
||||
ATF_TP_ADD_TC(tp, timer_create_real_expire);
|
||||
ATF_TP_ADD_TC(tp, timer_create_mono_expire);
|
||||
#ifdef __FreeBSD__
|
||||
ATF_TP_ADD_TC(tp, timer_thread_create_real);
|
||||
ATF_TP_ADD_TC(tp, timer_thread_create_mono);
|
||||
ATF_TP_ADD_TC(tp, timer_thread_create_real_expire);
|
||||
ATF_TP_ADD_TC(tp, timer_thread_create_mono_expire);
|
||||
#endif
|
||||
|
||||
return atf_no_error();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user