sem test: move sem_clockwait_np tests into individual cases
Move these tests into individual test cases for all the usual reasons. No functional change intended. MFC after: 1 week Sponsored by: Dell EMC Isilon
This commit is contained in:
parent
31466594cd
commit
2334abfd01
@ -221,14 +221,27 @@ sigalrm_handler(int sig __unused)
|
||||
got_sigalrm = 1;
|
||||
}
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
/* This is refactored from the timedwait test case. */
|
||||
static void
|
||||
setup_signals(void)
|
||||
{
|
||||
struct sigaction act = {
|
||||
.sa_handler = sigalrm_handler,
|
||||
.sa_flags = 0 /* not SA_RESTART */
|
||||
};
|
||||
|
||||
ATF_REQUIRE_MSG(sigemptyset(&act.sa_mask) == 0,
|
||||
"%s", strerror(errno));
|
||||
ATF_REQUIRE_MSG(sigaction(SIGALRM, &act, NULL) == 0,
|
||||
"%s", strerror(errno));
|
||||
}
|
||||
#endif
|
||||
|
||||
ATF_TC(timedwait);
|
||||
ATF_TC_HEAD(timedwait, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr", "Tests sem_timedwait(3)"
|
||||
#ifdef __FreeBSD__
|
||||
" and sem_clockwait_np(3)"
|
||||
#endif
|
||||
);
|
||||
atf_tc_set_md_var(tc, "descr", "Tests sem_timedwait(3)");
|
||||
atf_tc_set_md_var(tc, "timeout", "20");
|
||||
}
|
||||
ATF_TC_BODY(timedwait, tc)
|
||||
@ -263,14 +276,10 @@ ATF_TC_BODY(timedwait, tc)
|
||||
ATF_REQUIRE_ERRNO(EINVAL, sem_timedwait(&sem, &ts));
|
||||
|
||||
/* EINTR */
|
||||
struct sigaction act = {
|
||||
.sa_handler = sigalrm_handler,
|
||||
.sa_flags = 0 /* not SA_RESTART */
|
||||
};
|
||||
ATF_REQUIRE_MSG(sigemptyset(&act.sa_mask) == 0,
|
||||
"%s", strerror(errno));
|
||||
ATF_REQUIRE_MSG(sigaction(SIGALRM, &act, NULL) == 0,
|
||||
"%s", strerror(errno));
|
||||
#ifdef __FreeBSD__
|
||||
/* This is refactored into a function. */
|
||||
setup_signals();
|
||||
#endif
|
||||
struct itimerval it = {
|
||||
.it_value.tv_usec = 50*1000
|
||||
};
|
||||
@ -281,9 +290,24 @@ ATF_TC_BODY(timedwait, tc)
|
||||
timespec_add_ms(&ts, 100);
|
||||
ATF_REQUIRE_ERRNO(EINTR, sem_timedwait(&sem, &ts));
|
||||
ATF_REQUIRE_MSG(got_sigalrm, "did not get SIGALRM");
|
||||
}
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
/* CLOCK_MONOTONIC, absolute */
|
||||
|
||||
ATF_TC(clockwait_monotonic_absolute);
|
||||
ATF_TC_HEAD(clockwait_monotonic_absolute, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"sem_clockwait_np(3) with monotonic clock and absolute time");
|
||||
atf_tc_set_md_var(tc, "timeout", "20");
|
||||
}
|
||||
ATF_TC_BODY(clockwait_monotonic_absolute, tc)
|
||||
{
|
||||
struct timespec ts;
|
||||
sem_t sem;
|
||||
|
||||
SEM_REQUIRE(sem_init(&sem, 0, 0));
|
||||
|
||||
SEM_REQUIRE(sem_post(&sem));
|
||||
ATF_REQUIRE_MSG(clock_gettime(CLOCK_MONOTONIC, &ts) == 0,
|
||||
"%s", strerror(errno));
|
||||
@ -292,8 +316,22 @@ ATF_TC_BODY(timedwait, tc)
|
||||
&ts, NULL));
|
||||
ATF_REQUIRE_ERRNO(ETIMEDOUT,
|
||||
sem_clockwait_np(&sem, CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL));
|
||||
}
|
||||
|
||||
ATF_TC(clockwait_monotonic_relative);
|
||||
ATF_TC_HEAD(clockwait_monotonic_relative, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"sem_clockwait_np(3) with monotonic clock and relative time");
|
||||
atf_tc_set_md_var(tc, "timeout", "20");
|
||||
}
|
||||
ATF_TC_BODY(clockwait_monotonic_relative, tc)
|
||||
{
|
||||
struct timespec ts;
|
||||
sem_t sem;
|
||||
|
||||
SEM_REQUIRE(sem_init(&sem, 0, 0));
|
||||
|
||||
/* CLOCK_MONOTONIC, relative */
|
||||
SEM_REQUIRE(sem_post(&sem));
|
||||
ts.tv_sec = 0;
|
||||
ts.tv_nsec = 100*1000*1000;
|
||||
@ -301,11 +339,28 @@ ATF_TC_BODY(timedwait, tc)
|
||||
&ts, NULL));
|
||||
ATF_REQUIRE_ERRNO(ETIMEDOUT,
|
||||
sem_clockwait_np(&sem, CLOCK_MONOTONIC, 0, &ts, NULL));
|
||||
}
|
||||
|
||||
ATF_TC(clockwait_absolute_intr_remaining);
|
||||
ATF_TC_HEAD(clockwait_absolute_intr_remaining, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"sem_clockwait_np(3) with absolute time does not update "
|
||||
"remaining time on EINTR");
|
||||
atf_tc_set_md_var(tc, "timeout", "20");
|
||||
}
|
||||
ATF_TC_BODY(clockwait_absolute_intr_remaining, tc)
|
||||
{
|
||||
struct timespec ts;
|
||||
sem_t sem;
|
||||
|
||||
SEM_REQUIRE(sem_init(&sem, 0, 0));
|
||||
setup_signals();
|
||||
|
||||
/* absolute does not update remaining time on EINTR */
|
||||
struct timespec remain = {42, 1000*1000*1000};
|
||||
got_sigalrm = 0;
|
||||
it.it_value.tv_usec = 50*1000;
|
||||
struct itimerval it = {
|
||||
.it_value.tv_usec = 50*1000
|
||||
};
|
||||
ATF_REQUIRE_MSG(setitimer(ITIMER_REAL, &it, NULL) == 0,
|
||||
"%s", strerror(errno));
|
||||
ATF_REQUIRE_MSG(clock_gettime(CLOCK_MONOTONIC, &ts) == 0,
|
||||
@ -316,12 +371,28 @@ ATF_TC_BODY(timedwait, tc)
|
||||
ATF_REQUIRE_MSG(got_sigalrm, "did not get SIGALRM");
|
||||
ATF_REQUIRE_MSG(remain.tv_sec == 42 && remain.tv_nsec == 1000*1000*1000,
|
||||
"an absolute clockwait modified the remaining time on EINTR");
|
||||
}
|
||||
|
||||
/* relative updates remaining time on EINTR */
|
||||
remain.tv_sec = 42;
|
||||
remain.tv_nsec = 1000*1000*1000;
|
||||
got_sigalrm = 0;
|
||||
it.it_value.tv_usec = 50*1000;
|
||||
ATF_TC(clockwait_relative_intr_remaining);
|
||||
ATF_TC_HEAD(clockwait_relative_intr_remaining, tc)
|
||||
{
|
||||
atf_tc_set_md_var(tc, "descr",
|
||||
"sem_clockwait_np(3) with relative time updates "
|
||||
"remaining time on EINTR");
|
||||
atf_tc_set_md_var(tc, "timeout", "20");
|
||||
}
|
||||
ATF_TC_BODY(clockwait_relative_intr_remaining, tc)
|
||||
{
|
||||
struct timespec ts;
|
||||
sem_t sem;
|
||||
|
||||
SEM_REQUIRE(sem_init(&sem, 0, 0));
|
||||
setup_signals();
|
||||
|
||||
struct timespec remain = {42, 1000*1000*1000};
|
||||
struct itimerval it = {
|
||||
.it_value.tv_usec = 50*1000
|
||||
};
|
||||
ATF_REQUIRE_MSG(setitimer(ITIMER_REAL, &it, NULL) == 0,
|
||||
"%s", strerror(errno));
|
||||
ts.tv_sec = 0;
|
||||
@ -334,15 +405,22 @@ ATF_TC_BODY(timedwait, tc)
|
||||
remain.tv_nsec <= 75*1000*1000,
|
||||
"the remaining time was not as expected when a relative clockwait"
|
||||
" got EINTR: %ld.%09ld", remain.tv_sec, remain.tv_nsec);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
|
||||
ATF_TP_ADD_TC(tp, basic);
|
||||
ATF_TP_ADD_TC(tp, child);
|
||||
ATF_TP_ADD_TC(tp, timedwait);
|
||||
#ifdef __FreeBSD__
|
||||
ATF_TP_ADD_TC(tp, clockwait_monotonic_absolute);
|
||||
ATF_TP_ADD_TC(tp, clockwait_monotonic_relative);
|
||||
ATF_TP_ADD_TC(tp, clockwait_absolute_intr_remaining);
|
||||
ATF_TP_ADD_TC(tp, clockwait_relative_intr_remaining);
|
||||
#endif
|
||||
|
||||
return atf_no_error();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user