Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: base/threading/platform_thread_unittest.cc

Issue 1870033002: Fix NiceValueToThreadPriority failing on an unknown nice value. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a comment about exclusion of OSX/iOS. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/threading/platform_thread_internal_posix.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..82221e11009a2490b93cb6bff21182913bcb1548 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,64 @@ TEST(PlatformThreadTest, ThreadPriorityCurrentThread) {
}
}
+// Test for a function defined in platform_thread_internal_posix.cc. On OSX and
+// iOS, platform_thread_internal_posix.cc is not compiled, so these platforms
+// are excluded here, too.
+#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_IOS)
+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 =
+ 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
« no previous file with comments | « base/threading/platform_thread_internal_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698