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

Side by Side Diff: cc/resources/task_graph_runner_unittest.cc

Issue 645853008: Standardize usage of virtual/override/final in cc/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatted Created 6 years, 2 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 | « cc/resources/task_graph_runner_perftest.cc ('k') | cc/resources/texture_uploader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "cc/resources/task_graph_runner.h" 5 #include "cc/resources/task_graph_runner.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 tasks_[namespace_index].swap(new_tasks); 111 tasks_[namespace_index].swap(new_tasks);
112 } 112 }
113 113
114 protected: 114 protected:
115 class FakeTaskImpl : public Task { 115 class FakeTaskImpl : public Task {
116 public: 116 public:
117 FakeTaskImpl(TaskGraphRunnerTestBase* test, int namespace_index, int id) 117 FakeTaskImpl(TaskGraphRunnerTestBase* test, int namespace_index, int id)
118 : test_(test), namespace_index_(namespace_index), id_(id) {} 118 : test_(test), namespace_index_(namespace_index), id_(id) {}
119 119
120 // Overridden from Task: 120 // Overridden from Task:
121 virtual void RunOnWorkerThread() override { 121 void RunOnWorkerThread() override {
122 test_->RunTaskOnWorkerThread(namespace_index_, id_); 122 test_->RunTaskOnWorkerThread(namespace_index_, id_);
123 } 123 }
124 124
125 virtual void CompleteOnOriginThread() { 125 virtual void CompleteOnOriginThread() {
126 test_->OnTaskCompleted(namespace_index_, id_); 126 test_->OnTaskCompleted(namespace_index_, id_);
127 } 127 }
128 128
129 protected: 129 protected:
130 virtual ~FakeTaskImpl() {} 130 ~FakeTaskImpl() override {}
131 131
132 private: 132 private:
133 TaskGraphRunnerTestBase* test_; 133 TaskGraphRunnerTestBase* test_;
134 int namespace_index_; 134 int namespace_index_;
135 int id_; 135 int id_;
136 136
137 DISALLOW_COPY_AND_ASSIGN(FakeTaskImpl); 137 DISALLOW_COPY_AND_ASSIGN(FakeTaskImpl);
138 }; 138 };
139 139
140 class FakeDependentTaskImpl : public FakeTaskImpl { 140 class FakeDependentTaskImpl : public FakeTaskImpl {
141 public: 141 public:
142 FakeDependentTaskImpl(TaskGraphRunnerTestBase* test, 142 FakeDependentTaskImpl(TaskGraphRunnerTestBase* test,
143 int namespace_index, 143 int namespace_index,
144 int id) 144 int id)
145 : FakeTaskImpl(test, namespace_index, id) {} 145 : FakeTaskImpl(test, namespace_index, id) {}
146 146
147 // Overridden from FakeTaskImpl: 147 // Overridden from FakeTaskImpl:
148 virtual void CompleteOnOriginThread() override {} 148 void CompleteOnOriginThread() override {}
149 149
150 private: 150 private:
151 virtual ~FakeDependentTaskImpl() {} 151 ~FakeDependentTaskImpl() override {}
152 152
153 DISALLOW_COPY_AND_ASSIGN(FakeDependentTaskImpl); 153 DISALLOW_COPY_AND_ASSIGN(FakeDependentTaskImpl);
154 }; 154 };
155 155
156 scoped_ptr<TaskGraphRunner> task_graph_runner_; 156 scoped_ptr<TaskGraphRunner> task_graph_runner_;
157 NamespaceToken namespace_token_[kNamespaceCount]; 157 NamespaceToken namespace_token_[kNamespaceCount];
158 Task::Vector tasks_[kNamespaceCount]; 158 Task::Vector tasks_[kNamespaceCount];
159 Task::Vector dependents_[kNamespaceCount]; 159 Task::Vector dependents_[kNamespaceCount];
160 std::vector<unsigned> run_task_ids_[kNamespaceCount]; 160 std::vector<unsigned> run_task_ids_[kNamespaceCount];
161 base::Lock run_task_ids_lock_; 161 base::Lock run_task_ids_lock_;
(...skipping 20 matching lines...) Expand all
182 virtual void TearDown() override { 182 virtual void TearDown() override {
183 task_graph_runner_->Shutdown(); 183 task_graph_runner_->Shutdown();
184 while (workers_.size()) { 184 while (workers_.size()) {
185 scoped_ptr<base::DelegateSimpleThread> worker = workers_.take_front(); 185 scoped_ptr<base::DelegateSimpleThread> worker = workers_.take_front();
186 worker->Join(); 186 worker->Join();
187 } 187 }
188 } 188 }
189 189
190 private: 190 private:
191 // Overridden from base::DelegateSimpleThread::Delegate: 191 // Overridden from base::DelegateSimpleThread::Delegate:
192 virtual void Run() override { task_graph_runner_->Run(); } 192 void Run() override { task_graph_runner_->Run(); }
193 193
194 ScopedPtrDeque<base::DelegateSimpleThread> workers_; 194 ScopedPtrDeque<base::DelegateSimpleThread> workers_;
195 }; 195 };
196 196
197 TEST_P(TaskGraphRunnerTest, Basic) { 197 TEST_P(TaskGraphRunnerTest, Basic) {
198 for (int i = 0; i < kNamespaceCount; ++i) { 198 for (int i = 0; i < kNamespaceCount; ++i) {
199 EXPECT_EQ(0u, run_task_ids(i).size()); 199 EXPECT_EQ(0u, run_task_ids(i).size());
200 EXPECT_EQ(0u, on_task_completed_ids(i).size()); 200 EXPECT_EQ(0u, on_task_completed_ids(i).size());
201 201
202 ScheduleTasks(i, std::vector<TaskInfo>(1, TaskInfo(i, 0u, 0u, 0u, 0u))); 202 ScheduleTasks(i, std::vector<TaskInfo>(1, TaskInfo(i, 0u, 0u, 0u, 0u)));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 for (int i = 0; i < kNamespaceCount; ++i) 292 for (int i = 0; i < kNamespaceCount; ++i)
293 namespace_token_[i] = task_graph_runner_->GetNamespaceToken(); 293 namespace_token_[i] = task_graph_runner_->GetNamespaceToken();
294 } 294 }
295 virtual void TearDown() override { 295 virtual void TearDown() override {
296 task_graph_runner_->Shutdown(); 296 task_graph_runner_->Shutdown();
297 worker_->Join(); 297 worker_->Join();
298 } 298 }
299 299
300 private: 300 private:
301 // Overridden from base::DelegateSimpleThread::Delegate: 301 // Overridden from base::DelegateSimpleThread::Delegate:
302 virtual void Run() override { task_graph_runner_->Run(); } 302 void Run() override { task_graph_runner_->Run(); }
303 303
304 scoped_ptr<base::DelegateSimpleThread> worker_; 304 scoped_ptr<base::DelegateSimpleThread> worker_;
305 }; 305 };
306 306
307 TEST_F(TaskGraphRunnerSingleThreadTest, Priority) { 307 TEST_F(TaskGraphRunnerSingleThreadTest, Priority) {
308 for (int i = 0; i < kNamespaceCount; ++i) { 308 for (int i = 0; i < kNamespaceCount; ++i) {
309 TaskInfo tasks[] = {TaskInfo(i, 0u, 2u, 1u, 1u), // Priority 1 309 TaskInfo tasks[] = {TaskInfo(i, 0u, 2u, 1u, 1u), // Priority 1
310 TaskInfo(i, 1u, 3u, 1u, 0u) // Priority 0 310 TaskInfo(i, 1u, 3u, 1u, 0u) // Priority 0
311 }; 311 };
312 ScheduleTasks(i, std::vector<TaskInfo>(tasks, tasks + arraysize(tasks))); 312 ScheduleTasks(i, std::vector<TaskInfo>(tasks, tasks + arraysize(tasks)));
313 } 313 }
314 314
315 for (int i = 0; i < kNamespaceCount; ++i) { 315 for (int i = 0; i < kNamespaceCount; ++i) {
316 RunAllTasks(i); 316 RunAllTasks(i);
317 317
318 // Check if tasks ran in order of priority. 318 // Check if tasks ran in order of priority.
319 ASSERT_EQ(4u, run_task_ids(i).size()); 319 ASSERT_EQ(4u, run_task_ids(i).size());
320 EXPECT_EQ(1u, run_task_ids(i)[0]); 320 EXPECT_EQ(1u, run_task_ids(i)[0]);
321 EXPECT_EQ(3u, run_task_ids(i)[1]); 321 EXPECT_EQ(3u, run_task_ids(i)[1]);
322 EXPECT_EQ(0u, run_task_ids(i)[2]); 322 EXPECT_EQ(0u, run_task_ids(i)[2]);
323 EXPECT_EQ(2u, run_task_ids(i)[3]); 323 EXPECT_EQ(2u, run_task_ids(i)[3]);
324 ASSERT_EQ(2u, on_task_completed_ids(i).size()); 324 ASSERT_EQ(2u, on_task_completed_ids(i).size());
325 EXPECT_EQ(1u, on_task_completed_ids(i)[0]); 325 EXPECT_EQ(1u, on_task_completed_ids(i)[0]);
326 EXPECT_EQ(0u, on_task_completed_ids(i)[1]); 326 EXPECT_EQ(0u, on_task_completed_ids(i)[1]);
327 } 327 }
328 } 328 }
329 329
330 } // namespace 330 } // namespace
331 } // namespace cc 331 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/task_graph_runner_perftest.cc ('k') | cc/resources/texture_uploader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698