OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/message_loop/message_pump_libevent.h" | 5 #include "base/message_loop/message_pump_libevent.h" |
6 | 6 |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/posix/eintr_wrapper.h" | 16 #include "base/posix/eintr_wrapper.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
20 #include "base/synchronization/waitable_event_watcher.h" | 20 #include "base/synchronization/waitable_event_watcher.h" |
| 21 #include "base/test/gtest_util.h" |
21 #include "base/third_party/libevent/event.h" | 22 #include "base/third_party/libevent/event.h" |
22 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
23 #include "build/build_config.h" | 24 #include "build/build_config.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 namespace base { | 27 namespace base { |
27 | 28 |
28 class MessagePumpLibeventTest : public testing::Test { | 29 class MessagePumpLibeventTest : public testing::Test { |
29 protected: | 30 protected: |
30 MessagePumpLibeventTest() | 31 MessagePumpLibeventTest() |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // nothing useful. | 71 // nothing useful. |
71 class StupidWatcher : public MessagePumpLibevent::Watcher { | 72 class StupidWatcher : public MessagePumpLibevent::Watcher { |
72 public: | 73 public: |
73 ~StupidWatcher() override {} | 74 ~StupidWatcher() override {} |
74 | 75 |
75 // base:MessagePumpLibevent::Watcher interface | 76 // base:MessagePumpLibevent::Watcher interface |
76 void OnFileCanReadWithoutBlocking(int fd) override {} | 77 void OnFileCanReadWithoutBlocking(int fd) override {} |
77 void OnFileCanWriteWithoutBlocking(int fd) override {} | 78 void OnFileCanWriteWithoutBlocking(int fd) override {} |
78 }; | 79 }; |
79 | 80 |
80 #if GTEST_HAS_DEATH_TEST && !defined(NDEBUG) | |
81 | |
82 // Test to make sure that we catch calling WatchFileDescriptor off of the | 81 // Test to make sure that we catch calling WatchFileDescriptor off of the |
83 // wrong thread. | 82 // wrong thread. |
84 #if defined(OS_CHROMEOS) || defined(OS_LINUX) | 83 #if defined(OS_CHROMEOS) || defined(OS_LINUX) |
85 // Flaky on Chrome OS and Linux: crbug.com/138845. | 84 // Flaky on Chrome OS and Linux: crbug.com/138845. |
86 #define MAYBE_TestWatchingFromBadThread DISABLED_TestWatchingFromBadThread | 85 #define MAYBE_TestWatchingFromBadThread DISABLED_TestWatchingFromBadThread |
87 #else | 86 #else |
88 #define MAYBE_TestWatchingFromBadThread TestWatchingFromBadThread | 87 #define MAYBE_TestWatchingFromBadThread TestWatchingFromBadThread |
89 #endif | 88 #endif |
90 TEST_F(MessagePumpLibeventTest, MAYBE_TestWatchingFromBadThread) { | 89 TEST_F(MessagePumpLibeventTest, MAYBE_TestWatchingFromBadThread) { |
91 MessagePumpLibevent::FileDescriptorWatcher watcher; | 90 MessagePumpLibevent::FileDescriptorWatcher watcher; |
92 StupidWatcher delegate; | 91 StupidWatcher delegate; |
93 | 92 |
94 ASSERT_DEATH(io_loop()->WatchFileDescriptor( | 93 ASSERT_DCHECK_DEATH( |
95 STDOUT_FILENO, false, MessageLoopForIO::WATCH_READ, &watcher, &delegate), | 94 io_loop()->WatchFileDescriptor(STDOUT_FILENO, false, |
| 95 MessageLoopForIO::WATCH_READ, &watcher, |
| 96 &delegate), |
96 "Check failed: " | 97 "Check failed: " |
97 "watch_file_descriptor_caller_checker_.CalledOnValidThread\\(\\)"); | 98 "watch_file_descriptor_caller_checker_.CalledOnValidThread\\(\\)"); |
98 } | 99 } |
99 | 100 |
100 TEST_F(MessagePumpLibeventTest, QuitOutsideOfRun) { | 101 TEST_F(MessagePumpLibeventTest, QuitOutsideOfRun) { |
101 std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent); | 102 std::unique_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent); |
102 ASSERT_DEATH(pump->Quit(), "Check failed: in_run_. " | 103 ASSERT_DCHECK_DEATH(pump->Quit(), |
103 "Quit was called outside of Run!"); | 104 "Check failed: in_run_. " |
| 105 "Quit was called outside of Run!"); |
104 } | 106 } |
105 | 107 |
106 #endif // GTEST_HAS_DEATH_TEST && !defined(NDEBUG) | |
107 | |
108 class BaseWatcher : public MessagePumpLibevent::Watcher { | 108 class BaseWatcher : public MessagePumpLibevent::Watcher { |
109 public: | 109 public: |
110 explicit BaseWatcher(MessagePumpLibevent::FileDescriptorWatcher* controller) | 110 explicit BaseWatcher(MessagePumpLibevent::FileDescriptorWatcher* controller) |
111 : controller_(controller) { | 111 : controller_(controller) { |
112 DCHECK(controller_); | 112 DCHECK(controller_); |
113 } | 113 } |
114 ~BaseWatcher() override {} | 114 ~BaseWatcher() override {} |
115 | 115 |
116 // base:MessagePumpLibevent::Watcher interface | 116 // base:MessagePumpLibevent::Watcher interface |
117 void OnFileCanReadWithoutBlocking(int /* fd */) override { NOTREACHED(); } | 117 void OnFileCanReadWithoutBlocking(int /* fd */) override { NOTREACHED(); } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 276 |
277 // StartWatching can move |watcher| to IO thread. Release on IO thread. | 277 // StartWatching can move |watcher| to IO thread. Release on IO thread. |
278 io_loop()->task_runner()->PostTask( | 278 io_loop()->task_runner()->PostTask( |
279 FROM_HERE, | 279 FROM_HERE, |
280 Bind(&WaitableEventWatcher::StopWatching, Owned(watcher.release()))); | 280 Bind(&WaitableEventWatcher::StopWatching, Owned(watcher.release()))); |
281 } | 281 } |
282 | 282 |
283 } // namespace | 283 } // namespace |
284 | 284 |
285 } // namespace base | 285 } // namespace base |
OLD | NEW |