Rewrite sigwait tests in the style of the sigwaitinfo tests.

I can't reproduce locally, but treehugger is seeing 6% flake in the
signal.sigwait64_SIGRTMIN test. It's the only test in the file with a
sleep() in it, which always makes me suspicious, and we aren't having
trouble with the (in principle) very similar sigwaitinfo() tests, so
switch over to their style.

Bug: http://b/149934069
Test: treehugger
Change-Id: I2a1193b0cbec50f6548badf7dc7175bb6a49e45f
This commit is contained in:
Elliott Hughes 2020-03-20 16:25:54 -07:00
parent 69046e0842
commit 50fca4d2bd
1 changed files with 43 additions and 48 deletions

View File

@ -154,44 +154,6 @@ TEST(signal, raise_in_signal_handler) {
raise(SIGALRM);
}
TEST(signal, sigwait_SIGALRM) {
ScopedSignalHandler ssh(SIGALRM, [](int sig) { ASSERT_EQ(SIGALRM, sig); });
sigset_t wait_set;
sigemptyset(&wait_set);
sigaddset(&wait_set, SIGALRM);
alarm(1);
int received_signal;
errno = 0;
ASSERT_EQ(0, sigwait(&wait_set, &received_signal));
ASSERT_EQ(0, errno);
ASSERT_EQ(SIGALRM, received_signal);
}
TEST(signal, sigwait64_SIGRTMIN) {
ScopedSignalHandler ssh(SIGRTMIN, [](int sig) { ASSERT_EQ(SIGRTMIN, sig); });
sigset64_t wait_set;
sigemptyset64(&wait_set);
sigaddset64(&wait_set, SIGRTMIN);
pid_t tid = gettid();
std::thread thread([&tid]() {
sleep(1);
tgkill(getpid(), tid, SIGRTMIN);
});
int received_signal;
errno = 0;
ASSERT_EQ(0, sigwait64(&wait_set, &received_signal));
ASSERT_EQ(0, errno);
ASSERT_EQ(SIGRTMIN, received_signal);
thread.join();
}
static int g_sigsuspend_signal_handler_call_count = 0;
TEST(signal, sigsuspend_sigpending) {
@ -620,8 +582,7 @@ static void SigqueueSignalHandler(int signum, siginfo_t* info, void*) {
TEST(signal, sigqueue) {
ScopedSignalHandler ssh(SIGALRM, SigqueueSignalHandler, SA_SIGINFO);
sigval_t sigval;
sigval.sival_int = 1;
sigval_t sigval = {.sival_int = 1};
errno = 0;
ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval));
ASSERT_EQ(0, errno);
@ -630,8 +591,7 @@ TEST(signal, sigqueue) {
TEST(signal, pthread_sigqueue_self) {
ScopedSignalHandler ssh(SIGALRM, SigqueueSignalHandler, SA_SIGINFO);
sigval_t sigval;
sigval.sival_int = 1;
sigval_t sigval = {.sival_int = 1};
errno = 0;
ASSERT_EQ(0, pthread_sigqueue(pthread_self(), SIGALRM, sigval));
ASSERT_EQ(0, errno);
@ -640,8 +600,7 @@ TEST(signal, pthread_sigqueue_self) {
TEST(signal, pthread_sigqueue_other) {
ScopedSignalHandler ssh(SIGALRM, SigqueueSignalHandler, SA_SIGINFO);
sigval_t sigval;
sigval.sival_int = 1;
sigval_t sigval = {.sival_int = 1};
sigset_t mask;
sigfillset(&mask);
@ -664,6 +623,44 @@ TEST(signal, pthread_sigqueue_other) {
ASSERT_EQ(1, g_sigqueue_signal_handler_call_count);
}
TEST(signal, sigwait_SIGALRM) {
SignalMaskRestorer smr;
// Block SIGALRM.
sigset_t just_SIGALRM;
sigemptyset(&just_SIGALRM);
sigaddset(&just_SIGALRM, SIGALRM);
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, nullptr));
// Raise SIGALRM.
sigval_t sigval = {.sival_int = 1};
ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval));
// Get pending SIGALRM.
int sig;
ASSERT_EQ(0, sigwait(&just_SIGALRM, &sig));
ASSERT_EQ(SIGALRM, sig);
}
TEST(signal, sigwait64_SIGRTMIN) {
SignalMaskRestorer smr;
// Block SIGRTMIN.
sigset64_t just_SIGRTMIN;
sigemptyset64(&just_SIGRTMIN);
sigaddset64(&just_SIGRTMIN, SIGRTMIN);
ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, &just_SIGRTMIN, nullptr));
// Raise SIGRTMIN.
sigval_t sigval = {.sival_int = 1};
ASSERT_EQ(0, sigqueue(getpid(), SIGRTMIN, sigval));
// Get pending SIGRTMIN.
int sig;
ASSERT_EQ(0, sigwait64(&just_SIGRTMIN, &sig));
ASSERT_EQ(SIGRTMIN, sig);
}
TEST(signal, sigwaitinfo) {
SignalMaskRestorer smr;
@ -674,8 +671,7 @@ TEST(signal, sigwaitinfo) {
ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, nullptr));
// Raise SIGALRM.
sigval_t sigval;
sigval.sival_int = 1;
sigval_t sigval = {.sival_int = 1};
ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval));
// Get pending SIGALRM.
@ -697,8 +693,7 @@ TEST(signal, sigwaitinfo64_SIGRTMIN) {
ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, &just_SIGRTMIN, nullptr));
// Raise SIGRTMIN.
sigval_t sigval;
sigval.sival_int = 1;
sigval_t sigval = {.sival_int = 1};
ASSERT_EQ(0, sigqueue(getpid(), SIGRTMIN, sigval));
// Get pending SIGRTMIN.