OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 signals_received_.push_back(signum); | 476 signals_received_.push_back(signum); |
477 signaled_thread_ = Thread::Current(); | 477 signaled_thread_ = Thread::Current(); |
478 } | 478 } |
479 | 479 |
480 protected: | 480 protected: |
481 void SetUp() { | 481 void SetUp() { |
482 ss_.reset(new PhysicalSocketServer()); | 482 ss_.reset(new PhysicalSocketServer()); |
483 } | 483 } |
484 | 484 |
485 void TearDown() { | 485 void TearDown() { |
486 ss_.reset(NULL); | 486 ss_.reset(nullptr); |
487 signals_received_.clear(); | 487 signals_received_.clear(); |
488 signaled_thread_ = NULL; | 488 signaled_thread_ = nullptr; |
489 } | 489 } |
490 | 490 |
491 bool ExpectSignal(int signum) { | 491 bool ExpectSignal(int signum) { |
492 if (signals_received_.empty()) { | 492 if (signals_received_.empty()) { |
493 LOG(LS_ERROR) << "ExpectSignal(): No signal received"; | 493 LOG(LS_ERROR) << "ExpectSignal(): No signal received"; |
494 return false; | 494 return false; |
495 } | 495 } |
496 if (signals_received_[0] != signum) { | 496 if (signals_received_[0] != signum) { |
497 LOG(LS_ERROR) << "ExpectSignal(): Received signal " << | 497 LOG(LS_ERROR) << "ExpectSignal(): Received signal " << |
498 signals_received_[0] << ", expected " << signum; | 498 signals_received_[0] << ", expected " << signum; |
(...skipping 12 matching lines...) Expand all Loading... |
511 return ret; | 511 return ret; |
512 } | 512 } |
513 | 513 |
514 static std::vector<int> signals_received_; | 514 static std::vector<int> signals_received_; |
515 static Thread *signaled_thread_; | 515 static Thread *signaled_thread_; |
516 | 516 |
517 std::unique_ptr<PhysicalSocketServer> ss_; | 517 std::unique_ptr<PhysicalSocketServer> ss_; |
518 }; | 518 }; |
519 | 519 |
520 std::vector<int> PosixSignalDeliveryTest::signals_received_; | 520 std::vector<int> PosixSignalDeliveryTest::signals_received_; |
521 Thread *PosixSignalDeliveryTest::signaled_thread_ = NULL; | 521 Thread* PosixSignalDeliveryTest::signaled_thread_ = nullptr; |
522 | 522 |
523 // Test receiving a synchronous signal while not in Wait() and then entering | 523 // Test receiving a synchronous signal while not in Wait() and then entering |
524 // Wait() afterwards. | 524 // Wait() afterwards. |
525 TEST_F(PosixSignalDeliveryTest, RaiseThenWait) { | 525 TEST_F(PosixSignalDeliveryTest, RaiseThenWait) { |
526 ASSERT_TRUE(ss_->SetPosixSignalHandler(SIGTERM, &RecordSignal)); | 526 ASSERT_TRUE(ss_->SetPosixSignalHandler(SIGTERM, &RecordSignal)); |
527 raise(SIGTERM); | 527 raise(SIGTERM); |
528 EXPECT_TRUE(ss_->Wait(0, true)); | 528 EXPECT_TRUE(ss_->Wait(0, true)); |
529 EXPECT_TRUE(ExpectSignal(SIGTERM)); | 529 EXPECT_TRUE(ExpectSignal(SIGTERM)); |
530 EXPECT_TRUE(ExpectNone()); | 530 EXPECT_TRUE(ExpectNone()); |
531 } | 531 } |
(...skipping 24 matching lines...) Expand all Loading... |
556 } | 556 } |
557 | 557 |
558 class RaiseSigTermRunnable : public Runnable { | 558 class RaiseSigTermRunnable : public Runnable { |
559 void Run(Thread *thread) { | 559 void Run(Thread *thread) { |
560 thread->socketserver()->Wait(1000, false); | 560 thread->socketserver()->Wait(1000, false); |
561 | 561 |
562 // Allow SIGTERM. This will be the only thread with it not masked so it will | 562 // Allow SIGTERM. This will be the only thread with it not masked so it will |
563 // be delivered to us. | 563 // be delivered to us. |
564 sigset_t mask; | 564 sigset_t mask; |
565 sigemptyset(&mask); | 565 sigemptyset(&mask); |
566 pthread_sigmask(SIG_SETMASK, &mask, NULL); | 566 pthread_sigmask(SIG_SETMASK, &mask, nullptr); |
567 | 567 |
568 // Raise it. | 568 // Raise it. |
569 raise(SIGTERM); | 569 raise(SIGTERM); |
570 } | 570 } |
571 }; | 571 }; |
572 | 572 |
573 // Test that it works no matter what thread the kernel chooses to give the | 573 // Test that it works no matter what thread the kernel chooses to give the |
574 // signal to (since it's not guaranteed to be the one that Wait() runs on). | 574 // signal to (since it's not guaranteed to be the one that Wait() runs on). |
575 TEST_F(PosixSignalDeliveryTest, SignalOnDifferentThread) { | 575 TEST_F(PosixSignalDeliveryTest, SignalOnDifferentThread) { |
576 ss_->SetPosixSignalHandler(SIGTERM, &RecordSignal); | 576 ss_->SetPosixSignalHandler(SIGTERM, &RecordSignal); |
577 // Mask out SIGTERM so that it can't be delivered to this thread. | 577 // Mask out SIGTERM so that it can't be delivered to this thread. |
578 sigset_t mask; | 578 sigset_t mask; |
579 sigemptyset(&mask); | 579 sigemptyset(&mask); |
580 sigaddset(&mask, SIGTERM); | 580 sigaddset(&mask, SIGTERM); |
581 EXPECT_EQ(0, pthread_sigmask(SIG_SETMASK, &mask, NULL)); | 581 EXPECT_EQ(0, pthread_sigmask(SIG_SETMASK, &mask, nullptr)); |
582 // Start a new thread that raises it. It will have to be delivered to that | 582 // Start a new thread that raises it. It will have to be delivered to that |
583 // thread. Our implementation should safely handle it and dispatch | 583 // thread. Our implementation should safely handle it and dispatch |
584 // RecordSignal() on this thread. | 584 // RecordSignal() on this thread. |
585 std::unique_ptr<Thread> thread(new Thread()); | 585 std::unique_ptr<Thread> thread(new Thread()); |
586 std::unique_ptr<RaiseSigTermRunnable> runnable(new RaiseSigTermRunnable()); | 586 std::unique_ptr<RaiseSigTermRunnable> runnable(new RaiseSigTermRunnable()); |
587 thread->Start(runnable.get()); | 587 thread->Start(runnable.get()); |
588 EXPECT_TRUE(ss_->Wait(1500, true)); | 588 EXPECT_TRUE(ss_->Wait(1500, true)); |
589 EXPECT_TRUE(ExpectSignal(SIGTERM)); | 589 EXPECT_TRUE(ExpectSignal(SIGTERM)); |
590 EXPECT_EQ(Thread::Current(), signaled_thread_); | 590 EXPECT_EQ(Thread::Current(), signaled_thread_); |
591 EXPECT_TRUE(ExpectNone()); | 591 EXPECT_TRUE(ExpectNone()); |
592 } | 592 } |
593 | 593 |
594 #endif | 594 #endif |
595 | 595 |
596 } // namespace rtc | 596 } // namespace rtc |
OLD | NEW |