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

Side by Side Diff: base/task_scheduler/task_scheduler_impl_unittest.cc

Issue 1951453002: Name TaskScheduler's worker threads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b7_fdoray_fixtracing
Patch Set: review:fdoray-robliao#5-6 Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « base/task_scheduler/task_scheduler_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/task_scheduler/task_scheduler_impl.h" 5 #include "base/task_scheduler/task_scheduler_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits>
9 #include <utility> 10 #include <utility>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
14 #include "base/callback.h" 15 #include "base/callback.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_piece.h"
20 #include "base/strings/string_util.h"
17 #include "base/synchronization/waitable_event.h" 21 #include "base/synchronization/waitable_event.h"
18 #include "base/task_scheduler/task_traits.h" 22 #include "base/task_scheduler/task_traits.h"
19 #include "base/task_scheduler/test_task_factory.h" 23 #include "base/task_scheduler/test_task_factory.h"
20 #include "base/threading/platform_thread.h" 24 #include "base/threading/platform_thread.h"
21 #include "base/threading/simple_thread.h" 25 #include "base/threading/simple_thread.h"
22 #include "base/threading/thread.h" 26 #include "base/threading/thread.h"
23 #include "base/threading/thread_restrictions.h" 27 #include "base/threading/thread_restrictions.h"
24 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
25 29
26 namespace base { 30 namespace base {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 EXPECT_EQ(traits.priority() == TaskPriority::BACKGROUND 72 EXPECT_EQ(traits.priority() == TaskPriority::BACKGROUND
69 ? ThreadPriority::BACKGROUND 73 ? ThreadPriority::BACKGROUND
70 : ThreadPriority::NORMAL, 74 : ThreadPriority::NORMAL,
71 PlatformThread::GetCurrentThreadPriority()); 75 PlatformThread::GetCurrentThreadPriority());
72 76
73 #if ENABLE_THREAD_RESTRICTIONS 77 #if ENABLE_THREAD_RESTRICTIONS
74 // The #if above is required because GetIOAllowed() always returns true when 78 // The #if above is required because GetIOAllowed() always returns true when
75 // !ENABLE_THREAD_RESTRICTIONS, even when |traits| don't allow file I/O. 79 // !ENABLE_THREAD_RESTRICTIONS, even when |traits| don't allow file I/O.
76 EXPECT_EQ(traits.with_file_io(), GetIOAllowed()); 80 EXPECT_EQ(traits.with_file_io(), GetIOAllowed());
77 #endif 81 #endif
82
83 // Verify that the thread the task is running on is named as expected
84 // (appropriate prefix label and index for its traits).
85 std::string expected_thread_name = "TaskScheduler";
86 expected_thread_name += traits.priority() == TaskPriority::BACKGROUND
87 ? "Background"
88 : "Foreground";
89 if (traits.with_file_io())
90 expected_thread_name += "FileIO";
91 expected_thread_name += "Worker";
92
93 const std::string actual_thread_name(PlatformThread::GetName());
94 EXPECT_TRUE(StartsWith(actual_thread_name, expected_thread_name,
95 CompareCase::SENSITIVE));
96
97 size_t thread_index_in_pool = std::numeric_limits<size_t>::max();
98 EXPECT_TRUE(base::StringToSizeT(
99 StringPiece(actual_thread_name).substr(expected_thread_name.size()),
100 &thread_index_in_pool));
101 if (traits.priority() == TaskPriority::BACKGROUND) {
fdoray 2016/05/04 19:04:32 I would remove lines 101-109 because we shouldn't
gab 2016/05/04 21:00:02 Done.
102 EXPECT_EQ(0U, thread_index_in_pool);
103 } else if (traits.priority() == TaskPriority::BACKGROUND) {
104 EXPECT_GE(thread_index_in_pool, 0U);
105 EXPECT_LT(thread_index_in_pool, 4U);
106 } else {
107 EXPECT_GE(thread_index_in_pool, 0U);
108 EXPECT_LT(thread_index_in_pool, 12U);
109 }
78 } 110 }
79 111
80 void VerifyTaskEnvironementAndSignalEvent(const TaskTraits& traits, 112 void VerifyTaskEnvironementAndSignalEvent(const TaskTraits& traits,
81 WaitableEvent* event) { 113 WaitableEvent* event) {
82 DCHECK(event); 114 DCHECK(event);
83 VerifyTaskEnvironement(traits); 115 VerifyTaskEnvironement(traits);
84 event->Signal(); 116 event->Signal();
85 } 117 }
86 118
87 class ThreadPostingTasks : public SimpleThread { 119 class ThreadPostingTasks : public SimpleThread {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 229 }
198 230
199 scheduler->JoinForTesting(); 231 scheduler->JoinForTesting();
200 } 232 }
201 233
202 // TODO(fdoray): Add tests with Sequences that move around thread pools once 234 // TODO(fdoray): Add tests with Sequences that move around thread pools once
203 // child TaskRunners are supported. 235 // child TaskRunners are supported.
204 236
205 } // namespace internal 237 } // namespace internal
206 } // namespace base 238 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/task_scheduler_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698