| 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/threading/thread.h" | 5 #include "base/threading/thread.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // signal |event|. | 113 // signal |event|. |
| 114 void ReturnThreadId(base::Thread* thread, | 114 void ReturnThreadId(base::Thread* thread, |
| 115 base::PlatformThreadId* id, | 115 base::PlatformThreadId* id, |
| 116 base::WaitableEvent* event) { | 116 base::WaitableEvent* event) { |
| 117 *id = thread->GetThreadId(); | 117 *id = thread->GetThreadId(); |
| 118 event->Signal(); | 118 event->Signal(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace | 121 } // namespace |
| 122 | 122 |
| 123 TEST_F(ThreadTest, Restart) { | |
| 124 Thread a("Restart"); | |
| 125 a.Stop(); | |
| 126 EXPECT_FALSE(a.message_loop()); | |
| 127 EXPECT_FALSE(a.IsRunning()); | |
| 128 EXPECT_TRUE(a.Start()); | |
| 129 EXPECT_TRUE(a.message_loop()); | |
| 130 EXPECT_TRUE(a.IsRunning()); | |
| 131 a.Stop(); | |
| 132 EXPECT_FALSE(a.message_loop()); | |
| 133 EXPECT_FALSE(a.IsRunning()); | |
| 134 EXPECT_TRUE(a.Start()); | |
| 135 EXPECT_TRUE(a.message_loop()); | |
| 136 EXPECT_TRUE(a.IsRunning()); | |
| 137 a.Stop(); | |
| 138 EXPECT_FALSE(a.message_loop()); | |
| 139 EXPECT_FALSE(a.IsRunning()); | |
| 140 a.Stop(); | |
| 141 EXPECT_FALSE(a.message_loop()); | |
| 142 EXPECT_FALSE(a.IsRunning()); | |
| 143 } | |
| 144 | |
| 145 TEST_F(ThreadTest, StartWithOptions_StackSize) { | 123 TEST_F(ThreadTest, StartWithOptions_StackSize) { |
| 146 Thread a("StartWithStackSize"); | 124 Thread a("StartWithStackSize"); |
| 147 // Ensure that the thread can work with only 12 kb and still process a | 125 // Ensure that the thread can work with only 12 kb and still process a |
| 148 // message. | 126 // message. |
| 149 Thread::Options options; | 127 Thread::Options options; |
| 150 #if defined(ADDRESS_SANITIZER) | 128 #if defined(ADDRESS_SANITIZER) |
| 151 // ASan bloats the stack variables and overflows the 12 kb stack. | 129 // ASan bloats the stack variables and overflows the 12 kb stack. |
| 152 options.stack_size = 24*1024; | 130 options.stack_size = 24*1024; |
| 153 #else | 131 #else |
| 154 options.stack_size = 12*1024; | 132 options.stack_size = 12*1024; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 EXPECT_FALSE(a.message_loop()); | 187 EXPECT_FALSE(a.message_loop()); |
| 210 EXPECT_FALSE(a.IsRunning()); | 188 EXPECT_FALSE(a.IsRunning()); |
| 211 // Calling them when not running should also nop. | 189 // Calling them when not running should also nop. |
| 212 a.StopSoon(); | 190 a.StopSoon(); |
| 213 a.Stop(); | 191 a.Stop(); |
| 214 } | 192 } |
| 215 | 193 |
| 216 TEST_F(ThreadTest, StartTwice) { | 194 TEST_F(ThreadTest, StartTwice) { |
| 217 Thread a("StartTwice"); | 195 Thread a("StartTwice"); |
| 218 | 196 |
| 197 EXPECT_FALSE(a.message_loop()); |
| 198 EXPECT_FALSE(a.IsRunning()); |
| 199 |
| 219 EXPECT_TRUE(a.Start()); | 200 EXPECT_TRUE(a.Start()); |
| 220 EXPECT_TRUE(a.message_loop()); | 201 EXPECT_TRUE(a.message_loop()); |
| 221 EXPECT_TRUE(a.IsRunning()); | 202 EXPECT_TRUE(a.IsRunning()); |
| 203 |
| 222 a.Stop(); | 204 a.Stop(); |
| 223 EXPECT_FALSE(a.message_loop()); | 205 EXPECT_FALSE(a.message_loop()); |
| 224 EXPECT_FALSE(a.IsRunning()); | 206 EXPECT_FALSE(a.IsRunning()); |
| 225 | 207 |
| 226 EXPECT_TRUE(a.Start()); | 208 EXPECT_TRUE(a.Start()); |
| 227 EXPECT_TRUE(a.message_loop()); | 209 EXPECT_TRUE(a.message_loop()); |
| 228 EXPECT_TRUE(a.IsRunning()); | 210 EXPECT_TRUE(a.IsRunning()); |
| 211 |
| 229 a.Stop(); | 212 a.Stop(); |
| 230 EXPECT_FALSE(a.message_loop()); | 213 EXPECT_FALSE(a.message_loop()); |
| 231 EXPECT_FALSE(a.IsRunning()); | 214 EXPECT_FALSE(a.IsRunning()); |
| 232 } | 215 } |
| 233 | 216 |
| 234 TEST_F(ThreadTest, ThreadName) { | 217 TEST_F(ThreadTest, ThreadName) { |
| 235 Thread a("ThreadName"); | 218 Thread a("ThreadName"); |
| 236 EXPECT_TRUE(a.Start()); | 219 EXPECT_TRUE(a.Start()); |
| 237 EXPECT_EQ("ThreadName", a.thread_name()); | 220 EXPECT_EQ("ThreadName", a.thread_name()); |
| 238 } | 221 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 EXPECT_FALSE(a.task_runner()); | 308 EXPECT_FALSE(a.task_runner()); |
| 326 } | 309 } |
| 327 | 310 |
| 328 TEST_F(ThreadTest, MultipleWaitUntilThreadStarted) { | 311 TEST_F(ThreadTest, MultipleWaitUntilThreadStarted) { |
| 329 Thread a("MultipleWaitUntilThreadStarted"); | 312 Thread a("MultipleWaitUntilThreadStarted"); |
| 330 EXPECT_TRUE(a.Start()); | 313 EXPECT_TRUE(a.Start()); |
| 331 // It's OK to call WaitUntilThreadStarted() multiple times. | 314 // It's OK to call WaitUntilThreadStarted() multiple times. |
| 332 EXPECT_TRUE(a.WaitUntilThreadStarted()); | 315 EXPECT_TRUE(a.WaitUntilThreadStarted()); |
| 333 EXPECT_TRUE(a.WaitUntilThreadStarted()); | 316 EXPECT_TRUE(a.WaitUntilThreadStarted()); |
| 334 } | 317 } |
| OLD | NEW |