|
16 | 16 | #include <poll.h> |
17 | 17 | #include <signal.h> |
18 | 18 | #include <stdio.h> |
19 | | -#include <string.h> |
20 | 19 | #include <sys/signalfd.h> |
| 20 | +#include <sys/syscall.h> |
21 | 21 | #include <unistd.h> |
22 | 22 |
|
| 23 | +#include <ctime> |
23 | 24 | #include <functional> |
24 | | -#include <vector> |
| 25 | +#include <string> |
25 | 26 |
|
| 27 | +#include "gmock/gmock.h" |
26 | 28 | #include "gtest/gtest.h" |
| 29 | +#include "absl/strings/str_cat.h" |
27 | 30 | #include "absl/synchronization/mutex.h" |
| 31 | +#include "absl/time/clock.h" |
| 32 | +#include "absl/time/time.h" |
28 | 33 | #include "test/util/file_descriptor.h" |
| 34 | +#include "test/util/logging.h" |
29 | 35 | #include "test/util/posix_error.h" |
30 | 36 | #include "test/util/signal_util.h" |
31 | 37 | #include "test/util/test_util.h" |
@@ -341,6 +347,34 @@ TEST(Signalfd, KillStillKills) { |
341 | 347 | EXPECT_EXIT(tgkill(getpid(), gettid(), SIGKILL), KilledBySignal(SIGKILL), ""); |
342 | 348 | } |
343 | 349 |
|
| 350 | +TEST(Signalfd, RtQueueDeliversPayload) { |
| 351 | + const int signo = kSignoMax; |
| 352 | + sigset_t mask; |
| 353 | + sigemptyset(&mask); |
| 354 | + sigaddset(&mask, signo); |
| 355 | + |
| 356 | + const auto scoped_sigmask = |
| 357 | + ASSERT_NO_ERRNO_AND_VALUE(ScopedSignalMask(SIG_BLOCK, signo)); |
| 358 | + FileDescriptor fd = |
| 359 | + ASSERT_NO_ERRNO_AND_VALUE(NewSignalFD(&mask, SFD_NONBLOCK)); |
| 360 | + |
| 361 | + sigval_t first, second; |
| 362 | + first.sival_int = 101; |
| 363 | + second.sival_int = 102; |
| 364 | + ASSERT_THAT(sigqueue(getpid(), signo, first), SyscallSucceeds()); |
| 365 | + ASSERT_THAT(sigqueue(getpid(), signo, second), SyscallSucceeds()); |
| 366 | + |
| 367 | + struct signalfd_siginfo ssi; |
| 368 | + ASSERT_THAT(read(fd.get(), &ssi, sizeof(ssi)), |
| 369 | + SyscallSucceedsWithValue(sizeof(ssi))); |
| 370 | + EXPECT_EQ(ssi.ssi_signo, signo); |
| 371 | + EXPECT_EQ(ssi.ssi_int, first.sival_int); |
| 372 | + ASSERT_THAT(read(fd.get(), &ssi, sizeof(ssi)), |
| 373 | + SyscallSucceedsWithValue(sizeof(ssi))); |
| 374 | + EXPECT_EQ(ssi.ssi_signo, signo); |
| 375 | + EXPECT_EQ(ssi.ssi_int, second.sival_int); |
| 376 | +} |
| 377 | + |
344 | 378 | } // namespace |
345 | 379 |
|
346 | 380 | } // namespace testing |
|
0 commit comments