Chromium Code Reviews| Index: base/threading/platform_thread_unittest.cc |
| diff --git a/base/threading/platform_thread_unittest.cc b/base/threading/platform_thread_unittest.cc |
| index 673877556a1f0550415be3db522715073b613855..49e28f3a549a88b23e67c5427ad6c0317421044f 100644 |
| --- a/base/threading/platform_thread_unittest.cc |
| +++ b/base/threading/platform_thread_unittest.cc |
| @@ -14,6 +14,7 @@ |
| #if defined(OS_POSIX) |
| #include <sys/types.h> |
| #include <unistd.h> |
| +#include "base/threading/platform_thread_internal_posix.h" |
| #elif defined(OS_WIN) |
| #include <windows.h> |
| #endif |
| @@ -271,4 +272,61 @@ TEST(PlatformThreadTest, ThreadPriorityCurrentThread) { |
| } |
| } |
| +#if defined(OS_POSIX) |
| +TEST(PlatformThreadTest, GetNiceValueToThreadPriority) { |
| + using internal::NiceValueToThreadPriority; |
| + using internal::kThreadPriorityToNiceValueMap; |
| + |
| + EXPECT_EQ(ThreadPriority::BACKGROUND, |
| + kThreadPriorityToNiceValueMap[0].priority); |
| + EXPECT_EQ(ThreadPriority::NORMAL, |
| + kThreadPriorityToNiceValueMap[1].priority); |
| + EXPECT_EQ(ThreadPriority::DISPLAY, |
| + kThreadPriorityToNiceValueMap[2].priority); |
| + EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, |
| + kThreadPriorityToNiceValueMap[3].priority); |
| + |
| + static const int kBackgroundNiceValue = |
| + kThreadPriorityToNiceValueMap[0].nice_value; |
| + static const int kNormalNiceValue = |
| + kThreadPriorityToNiceValueMap[1].nice_value; |
| + static const int kDisplayNiceValue = |
| + kThreadPriorityToNiceValueMap[2].nice_value; |
| + static const int kRealtimeAudioNiceValue = |
|
gab
2016/04/12 13:20:46
static is good for compound const locals (e.g. arr
|
| + kThreadPriorityToNiceValueMap[3].nice_value; |
| + |
| + // The tests below assume the nice values specified in the map are within |
| + // the range below (both ends exclusive). |
| + static const int kHighestNiceValue = 19; |
| + static const int kLowestNiceValue = -20; |
| + |
| + EXPECT_GT(kHighestNiceValue, kBackgroundNiceValue); |
| + EXPECT_GT(kBackgroundNiceValue, kNormalNiceValue); |
| + EXPECT_GT(kNormalNiceValue, kDisplayNiceValue); |
| + EXPECT_GT(kDisplayNiceValue, kRealtimeAudioNiceValue); |
| + EXPECT_GT(kRealtimeAudioNiceValue, kLowestNiceValue); |
| + |
| + EXPECT_EQ(ThreadPriority::BACKGROUND, |
| + NiceValueToThreadPriority(kHighestNiceValue)); |
| + EXPECT_EQ(ThreadPriority::BACKGROUND, |
| + NiceValueToThreadPriority(kBackgroundNiceValue + 1)); |
| + EXPECT_EQ(ThreadPriority::BACKGROUND, |
| + NiceValueToThreadPriority(kBackgroundNiceValue)); |
| + EXPECT_EQ(ThreadPriority::BACKGROUND, |
| + NiceValueToThreadPriority(kNormalNiceValue + 1)); |
| + EXPECT_EQ(ThreadPriority::NORMAL, |
| + NiceValueToThreadPriority(kNormalNiceValue)); |
| + EXPECT_EQ(ThreadPriority::NORMAL, |
| + NiceValueToThreadPriority(kDisplayNiceValue + 1)); |
| + EXPECT_EQ(ThreadPriority::DISPLAY, |
| + NiceValueToThreadPriority(kDisplayNiceValue)); |
| + EXPECT_EQ(ThreadPriority::DISPLAY, |
| + NiceValueToThreadPriority(kRealtimeAudioNiceValue + 1)); |
| + EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, |
| + NiceValueToThreadPriority(kRealtimeAudioNiceValue)); |
| + EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, |
| + NiceValueToThreadPriority(kLowestNiceValue)); |
| +} |
| +#endif |
| + |
| } // namespace base |