Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Elliott Hughes | afe58ad | 2014-09-04 13:54:42 -0700 | [diff] [blame] | 17 | #include <signal.h> |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 18 | |
Elliott Hughes | afe58ad | 2014-09-04 13:54:42 -0700 | [diff] [blame] | 19 | #include <gtest/gtest.h> |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 20 | |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 21 | #include <errno.h> |
| 22 | |
Christopher Ferris | 1361313 | 2013-10-28 15:24:04 -0700 | [diff] [blame] | 23 | #include "ScopedSignalHandler.h" |
| 24 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 25 | static size_t SIGNAL_MIN() { |
| 26 | return 1; // Signals start at 1 (SIGHUP), not 0. |
| 27 | } |
| 28 | |
| 29 | static size_t SIGNAL_MAX() { |
| 30 | size_t result = SIGRTMAX; |
| 31 | |
| 32 | #if defined(__BIONIC__) && !defined(__mips__) && !defined(__LP64__) |
| 33 | // 32-bit bionic's sigset_t is too small for ARM and x86: 32 bits instead of 64. |
| 34 | // This means you can't refer to any of the real-time signals. |
| 35 | // See http://b/3038348 and http://b/5828899. |
| 36 | result = 32; |
| 37 | #else |
| 38 | // Otherwise, C libraries should be perfectly capable of using their largest signal. |
| 39 | if (sizeof(sigset_t) * 8 < static_cast<size_t>(SIGRTMAX)) { |
| 40 | abort(); |
| 41 | } |
| 42 | #endif |
| 43 | |
| 44 | return result; |
| 45 | } |
| 46 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 47 | template <typename Fn> |
| 48 | static void TestSigSet1(Fn fn) { |
| 49 | // NULL sigset_t*. |
| 50 | sigset_t* set_ptr = NULL; |
| 51 | errno = 0; |
| 52 | ASSERT_EQ(-1, fn(set_ptr)); |
| 53 | ASSERT_EQ(EINVAL, errno); |
| 54 | |
| 55 | // Non-NULL. |
| 56 | sigset_t set; |
| 57 | errno = 0; |
| 58 | ASSERT_EQ(0, fn(&set)); |
| 59 | ASSERT_EQ(0, errno); |
| 60 | } |
| 61 | |
| 62 | template <typename Fn> |
| 63 | static void TestSigSet2(Fn fn) { |
| 64 | // NULL sigset_t*. |
| 65 | sigset_t* set_ptr = NULL; |
| 66 | errno = 0; |
| 67 | ASSERT_EQ(-1, fn(set_ptr, SIGSEGV)); |
| 68 | ASSERT_EQ(EINVAL, errno); |
| 69 | |
| 70 | sigset_t set; |
| 71 | sigemptyset(&set); |
| 72 | |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 73 | // Bad signal number: too small. |
| 74 | errno = 0; |
| 75 | ASSERT_EQ(-1, fn(&set, 0)); |
| 76 | ASSERT_EQ(EINVAL, errno); |
| 77 | |
| 78 | // Bad signal number: too high. |
| 79 | errno = 0; |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 80 | ASSERT_EQ(-1, fn(&set, SIGNAL_MAX() + 1)); |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 81 | ASSERT_EQ(EINVAL, errno); |
| 82 | |
| 83 | // Good signal numbers, low and high ends of range. |
| 84 | errno = 0; |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 85 | ASSERT_EQ(0, fn(&set, SIGNAL_MIN())); |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 86 | ASSERT_EQ(0, errno); |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 87 | ASSERT_EQ(0, fn(&set, SIGNAL_MAX())); |
Elliott Hughes | da73f65 | 2012-11-30 16:40:55 -0800 | [diff] [blame] | 88 | ASSERT_EQ(0, errno); |
| 89 | } |
| 90 | |
| 91 | TEST(signal, sigismember_invalid) { |
| 92 | TestSigSet2(sigismember); |
| 93 | } |
| 94 | |
| 95 | TEST(signal, sigaddset_invalid) { |
| 96 | TestSigSet2(sigaddset); |
| 97 | } |
| 98 | |
| 99 | TEST(signal, sigdelset_invalid) { |
| 100 | TestSigSet2(sigdelset); |
| 101 | } |
| 102 | |
| 103 | TEST(signal, sigemptyset_invalid) { |
| 104 | TestSigSet1(sigemptyset); |
| 105 | } |
| 106 | |
| 107 | TEST(signal, sigfillset_invalid) { |
| 108 | TestSigSet1(sigfillset); |
| 109 | } |
Chris Dearman | d8a5a6f | 2012-12-07 18:41:10 -0800 | [diff] [blame] | 110 | |
| 111 | TEST(signal, raise_invalid) { |
| 112 | errno = 0; |
| 113 | ASSERT_EQ(-1, raise(-1)); |
| 114 | ASSERT_EQ(EINVAL, errno); |
| 115 | } |
Elliott Hughes | c5d028f | 2013-01-10 14:42:14 -0800 | [diff] [blame] | 116 | |
Elliott Hughes | fae89fc | 2013-02-21 11:22:23 -0800 | [diff] [blame] | 117 | static void raise_in_signal_handler_helper(int signal_number) { |
| 118 | ASSERT_EQ(SIGALRM, signal_number); |
| 119 | static int count = 0; |
| 120 | if (++count == 1) { |
| 121 | raise(SIGALRM); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | TEST(signal, raise_in_signal_handler) { |
| 126 | ScopedSignalHandler ssh(SIGALRM, raise_in_signal_handler_helper); |
| 127 | raise(SIGALRM); |
| 128 | } |
| 129 | |
Elliott Hughes | c5d028f | 2013-01-10 14:42:14 -0800 | [diff] [blame] | 130 | static void HandleSIGALRM(int signal_number) { |
| 131 | ASSERT_EQ(SIGALRM, signal_number); |
| 132 | } |
| 133 | |
| 134 | TEST(signal, sigwait) { |
Elliott Hughes | fae89fc | 2013-02-21 11:22:23 -0800 | [diff] [blame] | 135 | ScopedSignalHandler ssh(SIGALRM, HandleSIGALRM); |
Elliott Hughes | c5d028f | 2013-01-10 14:42:14 -0800 | [diff] [blame] | 136 | |
| 137 | sigset_t wait_set; |
| 138 | sigemptyset(&wait_set); |
| 139 | sigaddset(&wait_set, SIGALRM); |
| 140 | |
| 141 | alarm(1); |
| 142 | |
| 143 | int received_signal; |
| 144 | errno = 0; |
| 145 | ASSERT_EQ(0, sigwait(&wait_set, &received_signal)); |
| 146 | ASSERT_EQ(0, errno); |
| 147 | ASSERT_EQ(SIGALRM, received_signal); |
| 148 | } |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 149 | |
Elliott Hughes | 1728b23 | 2014-05-14 10:02:03 -0700 | [diff] [blame] | 150 | static int g_sigsuspend_test_helper_call_count = 0; |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 151 | |
| 152 | static void SigSuspendTestHelper(int) { |
Elliott Hughes | 1728b23 | 2014-05-14 10:02:03 -0700 | [diff] [blame] | 153 | ++g_sigsuspend_test_helper_call_count; |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 156 | TEST(signal, sigsuspend_sigpending) { |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 157 | // Block SIGALRM. |
| 158 | sigset_t just_SIGALRM; |
| 159 | sigemptyset(&just_SIGALRM); |
| 160 | sigaddset(&just_SIGALRM, SIGALRM); |
| 161 | sigset_t original_set; |
| 162 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, &original_set)); |
| 163 | |
Elliott Hughes | 1195207 | 2013-10-24 15:15:14 -0700 | [diff] [blame] | 164 | ScopedSignalHandler ssh(SIGALRM, SigSuspendTestHelper); |
| 165 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 166 | // There should be no pending signals. |
| 167 | sigset_t pending; |
| 168 | sigemptyset(&pending); |
| 169 | ASSERT_EQ(0, sigpending(&pending)); |
| 170 | for (size_t i = SIGNAL_MIN(); i <= SIGNAL_MAX(); ++i) { |
| 171 | EXPECT_FALSE(sigismember(&pending, i)) << i; |
| 172 | } |
| 173 | |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 174 | // Raise SIGALRM and check our signal handler wasn't called. |
| 175 | raise(SIGALRM); |
Elliott Hughes | 1728b23 | 2014-05-14 10:02:03 -0700 | [diff] [blame] | 176 | ASSERT_EQ(0, g_sigsuspend_test_helper_call_count); |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 177 | |
Elliott Hughes | 40d105c | 2013-10-16 12:53:58 -0700 | [diff] [blame] | 178 | // We should now have a pending SIGALRM but nothing else. |
| 179 | sigemptyset(&pending); |
| 180 | ASSERT_EQ(0, sigpending(&pending)); |
| 181 | for (size_t i = SIGNAL_MIN(); i <= SIGNAL_MAX(); ++i) { |
| 182 | EXPECT_EQ((i == SIGALRM), sigismember(&pending, i)); |
| 183 | } |
| 184 | |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 185 | // Use sigsuspend to block everything except SIGALRM... |
| 186 | sigset_t not_SIGALRM; |
| 187 | sigfillset(¬_SIGALRM); |
| 188 | sigdelset(¬_SIGALRM, SIGALRM); |
| 189 | ASSERT_EQ(-1, sigsuspend(¬_SIGALRM)); |
| 190 | ASSERT_EQ(EINTR, errno); |
| 191 | // ...and check that we now receive our pending SIGALRM. |
Elliott Hughes | 1728b23 | 2014-05-14 10:02:03 -0700 | [diff] [blame] | 192 | ASSERT_EQ(1, g_sigsuspend_test_helper_call_count); |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 193 | |
| 194 | // Restore the original set. |
Elliott Hughes | 1195207 | 2013-10-24 15:15:14 -0700 | [diff] [blame] | 195 | ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, NULL)); |
Elliott Hughes | 1f5af92 | 2013-10-15 18:01:56 -0700 | [diff] [blame] | 196 | } |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 197 | |
| 198 | static void EmptySignalHandler(int) {} |
| 199 | static void EmptySignalAction(int, siginfo_t*, void*) {} |
| 200 | |
| 201 | TEST(signal, sigaction) { |
Elliott Hughes | afe58ad | 2014-09-04 13:54:42 -0700 | [diff] [blame] | 202 | // Both bionic and glibc set SA_RESTORER when talking to the kernel on arm, |
| 203 | // arm64, x86, and x86-64. The version of glibc we're using also doesn't |
| 204 | // define SA_RESTORER, but luckily it's the same value everywhere, and mips |
| 205 | // doesn't use the bit for anything. |
Elliott Hughes | aa13e83 | 2014-09-04 15:43:10 -0700 | [diff] [blame] | 206 | static const unsigned sa_restorer = 0x4000000; |
Elliott Hughes | afe58ad | 2014-09-04 13:54:42 -0700 | [diff] [blame] | 207 | |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 208 | // See what's currently set for SIGALRM. |
Elliott Hughes | 1195207 | 2013-10-24 15:15:14 -0700 | [diff] [blame] | 209 | struct sigaction original_sa; |
| 210 | memset(&original_sa, 0, sizeof(original_sa)); |
| 211 | ASSERT_EQ(0, sigaction(SIGALRM, NULL, &original_sa)); |
| 212 | ASSERT_TRUE(original_sa.sa_handler == NULL); |
| 213 | ASSERT_TRUE(original_sa.sa_sigaction == NULL); |
Elliott Hughes | aa13e83 | 2014-09-04 15:43:10 -0700 | [diff] [blame] | 214 | ASSERT_EQ(0U, original_sa.sa_flags & ~sa_restorer); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 215 | |
| 216 | // Set a traditional sa_handler signal handler. |
Elliott Hughes | 1195207 | 2013-10-24 15:15:14 -0700 | [diff] [blame] | 217 | struct sigaction sa; |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 218 | memset(&sa, 0, sizeof(sa)); |
| 219 | sigaddset(&sa.sa_mask, SIGALRM); |
| 220 | sa.sa_flags = SA_ONSTACK; |
| 221 | sa.sa_handler = EmptySignalHandler; |
| 222 | ASSERT_EQ(0, sigaction(SIGALRM, &sa, NULL)); |
| 223 | |
| 224 | // Check that we can read it back. |
| 225 | memset(&sa, 0, sizeof(sa)); |
| 226 | ASSERT_EQ(0, sigaction(SIGALRM, NULL, &sa)); |
| 227 | ASSERT_TRUE(sa.sa_handler == EmptySignalHandler); |
| 228 | ASSERT_TRUE((void*) sa.sa_sigaction == (void*) sa.sa_handler); |
Elliott Hughes | aa13e83 | 2014-09-04 15:43:10 -0700 | [diff] [blame] | 229 | ASSERT_EQ(static_cast<unsigned>(SA_ONSTACK), sa.sa_flags & ~sa_restorer); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 230 | |
| 231 | // Set a new-style sa_sigaction signal handler. |
| 232 | memset(&sa, 0, sizeof(sa)); |
| 233 | sigaddset(&sa.sa_mask, SIGALRM); |
| 234 | sa.sa_flags = SA_ONSTACK | SA_SIGINFO; |
| 235 | sa.sa_sigaction = EmptySignalAction; |
| 236 | ASSERT_EQ(0, sigaction(SIGALRM, &sa, NULL)); |
| 237 | |
| 238 | // Check that we can read it back. |
| 239 | memset(&sa, 0, sizeof(sa)); |
| 240 | ASSERT_EQ(0, sigaction(SIGALRM, NULL, &sa)); |
| 241 | ASSERT_TRUE(sa.sa_sigaction == EmptySignalAction); |
| 242 | ASSERT_TRUE((void*) sa.sa_sigaction == (void*) sa.sa_handler); |
Elliott Hughes | aa13e83 | 2014-09-04 15:43:10 -0700 | [diff] [blame] | 243 | ASSERT_EQ(static_cast<unsigned>(SA_ONSTACK | SA_SIGINFO), sa.sa_flags & ~sa_restorer); |
Elliott Hughes | 1195207 | 2013-10-24 15:15:14 -0700 | [diff] [blame] | 244 | |
| 245 | // Put everything back how it was. |
| 246 | ASSERT_EQ(0, sigaction(SIGALRM, &original_sa, NULL)); |
Elliott Hughes | c7e9b23 | 2013-10-16 22:27:54 -0700 | [diff] [blame] | 247 | } |
Elliott Hughes | aa0ebda | 2014-02-11 19:57:06 -0800 | [diff] [blame] | 248 | |
| 249 | TEST(signal, sys_signame) { |
Elliott Hughes | 671e236 | 2014-02-12 19:04:27 -0800 | [diff] [blame] | 250 | #if defined(__BIONIC__) |
Elliott Hughes | aa0ebda | 2014-02-11 19:57:06 -0800 | [diff] [blame] | 251 | ASSERT_TRUE(sys_signame[0] == NULL); |
| 252 | ASSERT_STREQ("HUP", sys_signame[SIGHUP]); |
| 253 | #else |
| 254 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 255 | #endif |
| 256 | } |
| 257 | |
| 258 | TEST(signal, sys_siglist) { |
| 259 | ASSERT_TRUE(sys_siglist[0] == NULL); |
| 260 | ASSERT_STREQ("Hangup", sys_siglist[SIGHUP]); |
| 261 | } |
Elliott Hughes | 0990d4f | 2014-04-30 09:45:40 -0700 | [diff] [blame] | 262 | |
| 263 | TEST(signal, limits) { |
| 264 | // This comes from the kernel. |
| 265 | ASSERT_EQ(32, __SIGRTMIN); |
| 266 | |
| 267 | // We reserve a non-zero number at the bottom for ourselves. |
| 268 | ASSERT_GT(SIGRTMIN, __SIGRTMIN); |
| 269 | |
| 270 | // MIPS has more signals than everyone else. |
| 271 | #if defined(__mips__) |
| 272 | ASSERT_EQ(128, __SIGRTMAX); |
| 273 | #else |
| 274 | ASSERT_EQ(64, __SIGRTMAX); |
| 275 | #endif |
| 276 | |
| 277 | // We don't currently reserve any at the top. |
| 278 | ASSERT_EQ(SIGRTMAX, __SIGRTMAX); |
| 279 | } |
Yabin Cui | 6348160 | 2014-12-01 17:41:04 -0800 | [diff] [blame] | 280 | |
| 281 | static int g_sigqueue_signal_handler_call_count = 0; |
| 282 | |
| 283 | static void SigqueueSignalHandler(int signum, siginfo_t* info, void*) { |
| 284 | ASSERT_EQ(SIGALRM, signum); |
| 285 | ASSERT_EQ(SIGALRM, info->si_signo); |
| 286 | ASSERT_EQ(SI_QUEUE, info->si_code); |
| 287 | ASSERT_EQ(1, info->si_value.sival_int); |
| 288 | ++g_sigqueue_signal_handler_call_count; |
| 289 | } |
| 290 | |
| 291 | TEST(signal, sigqueue) { |
| 292 | ScopedSignalHandler ssh(SIGALRM, SigqueueSignalHandler, SA_SIGINFO); |
| 293 | sigval_t sigval; |
| 294 | sigval.sival_int = 1; |
| 295 | errno = 0; |
| 296 | ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval)); |
| 297 | ASSERT_EQ(0, errno); |
| 298 | ASSERT_EQ(1, g_sigqueue_signal_handler_call_count); |
| 299 | } |
| 300 | |
| 301 | TEST(signal, sigwaitinfo) { |
| 302 | // Block SIGALRM. |
| 303 | sigset_t just_SIGALRM; |
| 304 | sigemptyset(&just_SIGALRM); |
| 305 | sigaddset(&just_SIGALRM, SIGALRM); |
| 306 | sigset_t original_set; |
| 307 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, &original_set)); |
| 308 | |
| 309 | // Raise SIGALRM. |
| 310 | sigval_t sigval; |
| 311 | sigval.sival_int = 1; |
| 312 | ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval)); |
| 313 | |
| 314 | // Get pending SIGALRM. |
| 315 | siginfo_t info; |
| 316 | errno = 0; |
| 317 | ASSERT_EQ(SIGALRM, sigwaitinfo(&just_SIGALRM, &info)); |
| 318 | ASSERT_EQ(0, errno); |
| 319 | ASSERT_EQ(SIGALRM, info.si_signo); |
| 320 | ASSERT_EQ(1, info.si_value.sival_int); |
| 321 | |
| 322 | ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, NULL)); |
| 323 | } |
| 324 | |
| 325 | TEST(signal, sigtimedwait) { |
| 326 | // Block SIGALRM. |
| 327 | sigset_t just_SIGALRM; |
| 328 | sigemptyset(&just_SIGALRM); |
| 329 | sigaddset(&just_SIGALRM, SIGALRM); |
| 330 | sigset_t original_set; |
| 331 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, &original_set)); |
| 332 | |
| 333 | // Raise SIGALRM. |
| 334 | sigval_t sigval; |
| 335 | sigval.sival_int = 1; |
| 336 | ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval)); |
| 337 | |
| 338 | // Get pending SIGALRM. |
| 339 | siginfo_t info; |
| 340 | struct timespec timeout; |
| 341 | timeout.tv_sec = 2; |
| 342 | timeout.tv_nsec = 0; |
| 343 | errno = 0; |
| 344 | ASSERT_EQ(SIGALRM, sigtimedwait(&just_SIGALRM, &info, &timeout)); |
| 345 | ASSERT_EQ(0, errno); |
| 346 | |
| 347 | ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, NULL)); |
| 348 | } |
| 349 | |
| 350 | static int64_t NanoTime() { |
| 351 | struct timespec t; |
| 352 | t.tv_sec = t.tv_nsec = 0; |
| 353 | clock_gettime(CLOCK_MONOTONIC, &t); |
| 354 | return static_cast<int64_t>(t.tv_sec) * 1000000000LL + t.tv_nsec; |
| 355 | } |
| 356 | |
| 357 | TEST(signal, sigtimedwait_timeout) { |
| 358 | // Block SIGALRM. |
| 359 | sigset_t just_SIGALRM; |
| 360 | sigemptyset(&just_SIGALRM); |
| 361 | sigaddset(&just_SIGALRM, SIGALRM); |
| 362 | sigset_t original_set; |
| 363 | ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, &original_set)); |
| 364 | |
| 365 | // Wait timeout. |
| 366 | int64_t start_time = NanoTime(); |
| 367 | siginfo_t info; |
| 368 | struct timespec timeout; |
| 369 | timeout.tv_sec = 0; |
| 370 | timeout.tv_nsec = 1000000; |
| 371 | errno = 0; |
| 372 | ASSERT_EQ(-1, sigtimedwait(&just_SIGALRM, &info, &timeout)); |
| 373 | ASSERT_EQ(EAGAIN, errno); |
| 374 | ASSERT_GE(NanoTime() - start_time, 1000000); |
| 375 | |
| 376 | ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, NULL)); |
| 377 | } |