Index: base/threading/platform_thread_unittest.cc |
diff --git a/base/threading/platform_thread_unittest.cc b/base/threading/platform_thread_unittest.cc |
index c4b3d5d7ecc6092a89ca519800b55f92d3fd77da..905bca417afda10b38bbec8f1c13d7d10574d837 100644 |
--- a/base/threading/platform_thread_unittest.cc |
+++ b/base/threading/platform_thread_unittest.cc |
@@ -8,7 +8,10 @@ |
#include "base/threading/platform_thread.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-#if defined(OS_WIN) |
+#if defined(OS_POSIX) |
+#include <sys/types.h> |
+#include <unistd.h> |
+#elif defined(OS_WIN) |
#include <windows.h> |
#endif |
@@ -170,106 +173,46 @@ TEST(PlatformThreadTest, FunctionTimesTen) { |
namespace { |
const ThreadPriority kThreadPriorityTestValues[] = { |
-// Disable non-normal priority toggling on POSIX as it appears to be broken |
-// (http://crbug.com/468793). This is prefered to disabling the tests altogether |
-// on POSIX as it at least provides coverage for running this code under |
-// "normal" priority. |
-#if !defined(OS_POSIX) |
- ThreadPriority::DISPLAY, |
ThreadPriority::REALTIME_AUDIO, |
- // Keep BACKGROUND second to last to test backgrounding from other |
- // priorities. |
- ThreadPriority::BACKGROUND, |
-#endif // !defined(OS_POSIX) |
- // Keep NORMAL last to test unbackgrounding. |
- ThreadPriority::NORMAL |
+ ThreadPriority::DISPLAY, |
+ ThreadPriority::NORMAL, |
+ ThreadPriority::BACKGROUND |
}; |
} // namespace |
-// Test changing another thread's priority. |
-// NOTE: This test is partially disabled on POSIX, see note above and |
-// http://crbug.com/468793. |
-TEST(PlatformThreadTest, ThreadPriorityOtherThread) { |
- PlatformThreadHandle current_handle(PlatformThread::CurrentHandle()); |
- |
- // Confirm that the current thread's priority is as expected. |
- EXPECT_EQ(ThreadPriority::NORMAL, |
- PlatformThread::GetThreadPriority(current_handle)); |
- |
- // Create a test thread. |
- FunctionTestThread thread; |
- PlatformThreadHandle handle; |
- ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); |
- thread.WaitForThreadStart(); |
- EXPECT_NE(thread.thread_id(), kInvalidThreadId); |
- EXPECT_NE(thread.thread_id(), PlatformThread::CurrentId()); |
- |
- // New threads should get normal priority by default. |
- EXPECT_EQ(ThreadPriority::NORMAL, PlatformThread::GetThreadPriority(handle)); |
- |
- // Toggle each supported priority on the test thread and confirm it only |
- // affects it (and not the current thread). |
- for (size_t i = 0; i < arraysize(kThreadPriorityTestValues); ++i) { |
- SCOPED_TRACE(i); |
- |
- // Alter and verify the test thread's priority. |
- PlatformThread::SetThreadPriority(handle, kThreadPriorityTestValues[i]); |
- EXPECT_EQ(kThreadPriorityTestValues[i], |
- PlatformThread::GetThreadPriority(handle)); |
- |
- // Make sure the current thread was otherwise unaffected. |
- EXPECT_EQ(ThreadPriority::NORMAL, |
- PlatformThread::GetThreadPriority(current_handle)); |
- } |
- |
- thread.MarkForTermination(); |
- PlatformThread::Join(handle); |
-} |
- |
// Test changing the current thread's priority (which has different semantics on |
// some platforms). |
-// NOTE: This test is partially disabled on POSIX, see note above and |
-// http://crbug.com/468793. |
TEST(PlatformThreadTest, ThreadPriorityCurrentThread) { |
- PlatformThreadHandle current_handle(PlatformThread::CurrentHandle()); |
- |
// Confirm that the current thread's priority is as expected. |
+#if !defined(OS_MACOSX) |
Lei Zhang
2015/06/23 05:20:08
I would just skip the test entirely on Mac.
Takashi Toyoshima
2015/06/23 11:42:22
Done.
|
+ // PlatformThread::GetCurrentThreadPriority() is not implemented on OS X. |
EXPECT_EQ(ThreadPriority::NORMAL, |
- PlatformThread::GetThreadPriority(current_handle)); |
- |
- // Create a test thread for verification purposes only. |
- FunctionTestThread thread; |
- PlatformThreadHandle handle; |
- ASSERT_TRUE(PlatformThread::Create(0, &thread, &handle)); |
- thread.WaitForThreadStart(); |
- EXPECT_NE(thread.thread_id(), kInvalidThreadId); |
- EXPECT_NE(thread.thread_id(), PlatformThread::CurrentId()); |
- |
- // Confirm that the new thread's priority is as expected. |
- EXPECT_EQ(ThreadPriority::NORMAL, PlatformThread::GetThreadPriority(handle)); |
+ PlatformThread::GetCurrentThreadPriority()); |
+#endif |
// Toggle each supported priority on the current thread and confirm it only |
// affects it (and not the test thread). |
for (size_t i = 0; i < arraysize(kThreadPriorityTestValues); ++i) { |
SCOPED_TRACE(i); |
+#if defined(OS_POSIX) |
+ // Only root or a user with CAP_SYS_NICE permission can raise the thread |
+ // priority. |
+ if (geteuid() != 0 && kThreadPriorityTestValues[i] > ThreadPriority::NORMAL) |
+ continue; |
+#endif |
// Alter and verify the current thread's priority. |
- PlatformThread::SetThreadPriority(current_handle, |
- kThreadPriorityTestValues[i]); |
+ PlatformThread::SetCurrentThreadPriority(kThreadPriorityTestValues[i]); |
+#if !defined(OS_MACOSX) |
+ // PlatformThread::GetCurrentThreadPriority() is not implemented on OS X. |
EXPECT_EQ(kThreadPriorityTestValues[i], |
- PlatformThread::GetThreadPriority(current_handle)); |
- |
- // Make sure the test thread was otherwise unaffected. |
- EXPECT_EQ(ThreadPriority::NORMAL, |
- PlatformThread::GetThreadPriority(handle)); |
+ PlatformThread::GetCurrentThreadPriority()); |
+#endif |
} |
// Restore current thread priority for follow-up tests. |
- PlatformThread::SetThreadPriority(current_handle, ThreadPriority::NORMAL); |
- |
- thread.MarkForTermination(); |
- PlatformThread::Join(handle); |
+ PlatformThread::SetCurrentThreadPriority(ThreadPriority::NORMAL); |
} |
} // namespace base |