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 #if defined(OS_POSIX) | |
276 TEST(PlatformThreadTest, GetNiceValueToThreadPriority) { | |
277 using internal::NiceValueToThreadPriority; | |
278 using internal::kThreadPriorityToNiceValueMap; | |
279 | |
280 EXPECT_EQ(ThreadPriority::BACKGROUND, | |
281 kThreadPriorityToNiceValueMap[0].priority); | |
282 EXPECT_EQ(ThreadPriority::NORMAL, | |
283 kThreadPriorityToNiceValueMap[1].priority); | |
284 EXPECT_EQ(ThreadPriority::DISPLAY, | |
285 kThreadPriorityToNiceValueMap[2].priority); | |
286 EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, | |
287 kThreadPriorityToNiceValueMap[3].priority); | |
288 | |
289 static const int kBackgroundNiceValue = | |
290 kThreadPriorityToNiceValueMap[0].nice_value; | |
291 static const int kNormalNiceValue = | |
292 kThreadPriorityToNiceValueMap[1].nice_value; | |
293 static const int kDisplayNiceValue = | |
294 kThreadPriorityToNiceValueMap[2].nice_value; | |
295 static const int kRealtimeAudioNiceValue = | |
gab
2016/04/12 13:20:46
static is good for compound const locals (e.g. arr
| |
296 kThreadPriorityToNiceValueMap[3].nice_value; | |
297 | |
298 // The tests below assume the nice values specified in the map are within | |
299 // the range below (both ends exclusive). | |
300 static const int kHighestNiceValue = 19; | |
301 static const int kLowestNiceValue = -20; | |
302 | |
303 EXPECT_GT(kHighestNiceValue, kBackgroundNiceValue); | |
304 EXPECT_GT(kBackgroundNiceValue, kNormalNiceValue); | |
305 EXPECT_GT(kNormalNiceValue, kDisplayNiceValue); | |
306 EXPECT_GT(kDisplayNiceValue, kRealtimeAudioNiceValue); | |
307 EXPECT_GT(kRealtimeAudioNiceValue, kLowestNiceValue); | |
308 | |
309 EXPECT_EQ(ThreadPriority::BACKGROUND, | |
310 NiceValueToThreadPriority(kHighestNiceValue)); | |
311 EXPECT_EQ(ThreadPriority::BACKGROUND, | |
312 NiceValueToThreadPriority(kBackgroundNiceValue + 1)); | |
313 EXPECT_EQ(ThreadPriority::BACKGROUND, | |
314 NiceValueToThreadPriority(kBackgroundNiceValue)); | |
315 EXPECT_EQ(ThreadPriority::BACKGROUND, | |
316 NiceValueToThreadPriority(kNormalNiceValue + 1)); | |
317 EXPECT_EQ(ThreadPriority::NORMAL, | |
318 NiceValueToThreadPriority(kNormalNiceValue)); | |
319 EXPECT_EQ(ThreadPriority::NORMAL, | |
320 NiceValueToThreadPriority(kDisplayNiceValue + 1)); | |
321 EXPECT_EQ(ThreadPriority::DISPLAY, | |
322 NiceValueToThreadPriority(kDisplayNiceValue)); | |
323 EXPECT_EQ(ThreadPriority::DISPLAY, | |
324 NiceValueToThreadPriority(kRealtimeAudioNiceValue + 1)); | |
325 EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, | |
326 NiceValueToThreadPriority(kRealtimeAudioNiceValue)); | |
327 EXPECT_EQ(ThreadPriority::REALTIME_AUDIO, | |
328 NiceValueToThreadPriority(kLowestNiceValue)); | |
329 } | |
330 #endif | |
331 | |
274 } // namespace base | 332 } // namespace base |
OLD | NEW |