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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 #if defined(OS_POSIX) | 14 #if defined(OS_POSIX) |
15 #include <sys/types.h> | 15 #include <sys/types.h> |
16 #include <unistd.h> | 16 #include <unistd.h> |
| 17 #include "base/threading/platform_thread_internal_posix.h" |
17 #elif defined(OS_WIN) | 18 #elif defined(OS_WIN) |
18 #include <windows.h> | 19 #include <windows.h> |
19 #endif | 20 #endif |
20 | 21 |
21 namespace base { | 22 namespace base { |
22 | 23 |
23 // Trivial tests that thread runs and doesn't crash on create and join --------- | 24 // Trivial tests that thread runs and doesn't crash on create and join --------- |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); | 265 ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); |
265 thread.WaitForTerminationReady(); | 266 thread.WaitForTerminationReady(); |
266 ASSERT_TRUE(thread.IsRunning()); | 267 ASSERT_TRUE(thread.IsRunning()); |
267 | 268 |
268 thread.MarkForTermination(); | 269 thread.MarkForTermination(); |
269 PlatformThread::Join(handle); | 270 PlatformThread::Join(handle); |
270 ASSERT_FALSE(thread.IsRunning()); | 271 ASSERT_FALSE(thread.IsRunning()); |
271 } | 272 } |
272 } | 273 } |
273 | 274 |
| 275 // Test for a function defined in platform_thread_internal_posix.cc. On OSX and |
| 276 // iOS, platform_thread_internal_posix.cc is not compiled, so these platforms |
| 277 // are excluded here, too. |
| 278 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_IOS) |
| 279 TEST(PlatformThreadTest, GetNiceValueToThreadPriority) { |
| 280 using internal::NiceValueToThreadPriority; |
| 281 using internal::kThreadPriorityToNiceValueMap; |
| 282 |
| 283 EXPECT_EQ(ThreadPriority::BACKGROUND, |
| 284 kThreadPriorityToNiceValueMap[0].priority); |
| 285 EXPECT_EQ(ThreadPriority::NORMAL, |
| 286 kThreadPriorityToNiceValueMap[1].priority); |
| 287 EXPECT_EQ(ThreadPriority::DISPLAY, |
| 288 kThreadPriorityToNiceValueMap[2].priority); |
| 289 EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, |
| 290 kThreadPriorityToNiceValueMap[3].priority); |
| 291 |
| 292 static const int kBackgroundNiceValue = |
| 293 kThreadPriorityToNiceValueMap[0].nice_value; |
| 294 static const int kNormalNiceValue = |
| 295 kThreadPriorityToNiceValueMap[1].nice_value; |
| 296 static const int kDisplayNiceValue = |
| 297 kThreadPriorityToNiceValueMap[2].nice_value; |
| 298 static const int kRealtimeAudioNiceValue = |
| 299 kThreadPriorityToNiceValueMap[3].nice_value; |
| 300 |
| 301 // The tests below assume the nice values specified in the map are within |
| 302 // the range below (both ends exclusive). |
| 303 static const int kHighestNiceValue = 19; |
| 304 static const int kLowestNiceValue = -20; |
| 305 |
| 306 EXPECT_GT(kHighestNiceValue, kBackgroundNiceValue); |
| 307 EXPECT_GT(kBackgroundNiceValue, kNormalNiceValue); |
| 308 EXPECT_GT(kNormalNiceValue, kDisplayNiceValue); |
| 309 EXPECT_GT(kDisplayNiceValue, kRealtimeAudioNiceValue); |
| 310 EXPECT_GT(kRealtimeAudioNiceValue, kLowestNiceValue); |
| 311 |
| 312 EXPECT_EQ(ThreadPriority::BACKGROUND, |
| 313 NiceValueToThreadPriority(kHighestNiceValue)); |
| 314 EXPECT_EQ(ThreadPriority::BACKGROUND, |
| 315 NiceValueToThreadPriority(kBackgroundNiceValue + 1)); |
| 316 EXPECT_EQ(ThreadPriority::BACKGROUND, |
| 317 NiceValueToThreadPriority(kBackgroundNiceValue)); |
| 318 EXPECT_EQ(ThreadPriority::BACKGROUND, |
| 319 NiceValueToThreadPriority(kNormalNiceValue + 1)); |
| 320 EXPECT_EQ(ThreadPriority::NORMAL, |
| 321 NiceValueToThreadPriority(kNormalNiceValue)); |
| 322 EXPECT_EQ(ThreadPriority::NORMAL, |
| 323 NiceValueToThreadPriority(kDisplayNiceValue + 1)); |
| 324 EXPECT_EQ(ThreadPriority::DISPLAY, |
| 325 NiceValueToThreadPriority(kDisplayNiceValue)); |
| 326 EXPECT_EQ(ThreadPriority::DISPLAY, |
| 327 NiceValueToThreadPriority(kRealtimeAudioNiceValue + 1)); |
| 328 EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, |
| 329 NiceValueToThreadPriority(kRealtimeAudioNiceValue)); |
| 330 EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, |
| 331 NiceValueToThreadPriority(kLowestNiceValue)); |
| 332 } |
| 333 #endif |
| 334 |
274 } // namespace base | 335 } // namespace base |
OLD | NEW |