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

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

Issue 154003006: cc: Switch to vector based TaskGraph implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 10 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 | Annotate | Revision Log
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 "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 return run_task_ids_[namespace_index]; 67 return run_task_ids_[namespace_index];
68 } 68 }
69 69
70 const std::vector<unsigned>& on_task_completed_ids(int namespace_index) { 70 const std::vector<unsigned>& on_task_completed_ids(int namespace_index) {
71 return on_task_completed_ids_[namespace_index]; 71 return on_task_completed_ids_[namespace_index];
72 } 72 }
73 73
74 void ScheduleTasks(int namespace_index, const std::vector<Task>& tasks) { 74 void ScheduleTasks(int namespace_index, const std::vector<Task>& tasks) {
75 internal::Task::Vector new_tasks; 75 internal::Task::Vector new_tasks;
76 internal::Task::Vector new_dependents; 76 internal::Task::Vector new_dependents;
77 internal::GraphNode::Map new_graph; 77 internal::TaskGraph new_graph;
78 78
79 for (std::vector<Task>::const_iterator it = tasks.begin(); 79 for (std::vector<Task>::const_iterator it = tasks.begin();
80 it != tasks.end(); 80 it != tasks.end();
81 ++it) { 81 ++it) {
82 scoped_refptr<FakeTaskImpl> new_task( 82 scoped_refptr<FakeTaskImpl> new_task(
83 new FakeTaskImpl(this, it->namespace_index, it->id)); 83 new FakeTaskImpl(this, it->namespace_index, it->id));
84 scoped_ptr<internal::GraphNode> node( 84 new_graph.nodes.push_back(
85 new internal::GraphNode(new_task.get(), it->priority)); 85 internal::TaskGraph::Node(new_task.get(), it->priority, 0u));
86
87 for (unsigned i = 0; i < it->dependent_count; ++i) { 86 for (unsigned i = 0; i < it->dependent_count; ++i) {
88 scoped_refptr<FakeDependentTaskImpl> new_dependent_task( 87 scoped_refptr<FakeDependentTaskImpl> new_dependent_task(
89 new FakeDependentTaskImpl( 88 new FakeDependentTaskImpl(
90 this, it->namespace_index, it->dependent_id)); 89 this, it->namespace_index, it->dependent_id));
91 scoped_ptr<internal::GraphNode> dependent_node( 90 new_graph.nodes.push_back(internal::TaskGraph::Node(
92 new internal::GraphNode(new_dependent_task.get(), it->priority)); 91 new_dependent_task.get(), it->priority, 1u));
93 node->add_dependent(dependent_node.get()); 92 new_graph.edges.push_back(internal::TaskGraph::Edge(
94 dependent_node->add_dependency(); 93 new_task.get(), new_dependent_task.get()));
95 new_graph.set(new_dependent_task.get(), dependent_node.Pass()); 94
96 new_dependents.push_back(new_dependent_task.get()); 95 new_dependents.push_back(new_dependent_task.get());
97 } 96 }
98 97
99 new_graph.set(new_task.get(), node.Pass());
100 new_tasks.push_back(new_task.get()); 98 new_tasks.push_back(new_task.get());
101 } 99 }
102 100
103 task_graph_runner_->SetTaskGraph(namespace_token_[namespace_index], 101 task_graph_runner_->SetTaskGraph(namespace_token_[namespace_index],
104 &new_graph); 102 &new_graph);
105 103
106 dependents_[namespace_index].swap(new_dependents); 104 dependents_[namespace_index].swap(new_dependents);
107 tasks_[namespace_index].swap(new_tasks); 105 tasks_[namespace_index].swap(new_tasks);
108 } 106 }
109 107
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 ASSERT_EQ(2u, on_task_completed_ids(i).size()); 286 ASSERT_EQ(2u, on_task_completed_ids(i).size());
289 EXPECT_EQ(1u, on_task_completed_ids(i)[0]); 287 EXPECT_EQ(1u, on_task_completed_ids(i)[0]);
290 EXPECT_EQ(0u, on_task_completed_ids(i)[1]); 288 EXPECT_EQ(0u, on_task_completed_ids(i)[1]);
291 } 289 }
292 290
293 for (int i = 0; i < kNamespaceCount; ++i) 291 for (int i = 0; i < kNamespaceCount; ++i)
294 ResetIds(i); 292 ResetIds(i);
295 293
296 for (int i = 0; i < kNamespaceCount; ++i) { 294 for (int i = 0; i < kNamespaceCount; ++i) {
297 std::vector<Task> tasks; 295 std::vector<Task> tasks;
298 tasks.push_back(Task(i, 296 tasks.push_back(Task(i, 0u, 3u, 1u, 2u)); // Priority 2
vmpstr 2014/02/06 19:44:37 heh :) Can you put a brief comment above to just s
reveman 2014/02/06 20:51:52 Removed the test which is no longer useful.
299 0u, 297 tasks.push_back(Task(i, 1u, 4u, 1u, 1u)); // Priority 1
300 3u, 298 tasks.push_back(Task(i, 2u, 5u, 1u, 0u)); // Priority 0
301 1u, // 1 dependent
302 1u)); // Priority 1
303 tasks.push_back(Task(i,
304 1u,
305 4u,
306 2u, // 2 dependents
307 1u)); // Priority 1
308 tasks.push_back(Task(i,
309 2u,
310 5u,
311 1u, // 1 dependent
312 0u)); // Priority 0
313 ScheduleTasks(i, tasks); 299 ScheduleTasks(i, tasks);
314 } 300 }
315 301
316 for (int i = 0; i < kNamespaceCount; ++i) { 302 for (int i = 0; i < kNamespaceCount; ++i) {
317 RunAllTasks(i); 303 RunAllTasks(i);
318 304
319 // Check if tasks ran in order of priority and that task with more 305 // Check if tasks ran in order of priority.
320 // dependents ran first when priority is the same.
321 ASSERT_LE(3u, run_task_ids(i).size()); 306 ASSERT_LE(3u, run_task_ids(i).size());
322 EXPECT_EQ(2u, run_task_ids(i)[0]); 307 EXPECT_EQ(2u, run_task_ids(i)[0]);
323 EXPECT_EQ(5u, run_task_ids(i)[1]); 308 EXPECT_EQ(5u, run_task_ids(i)[1]);
324 EXPECT_EQ(1u, run_task_ids(i)[2]); 309 EXPECT_EQ(1u, run_task_ids(i)[2]);
325 ASSERT_EQ(3u, on_task_completed_ids(i).size()); 310 ASSERT_EQ(3u, on_task_completed_ids(i).size());
326 EXPECT_EQ(2u, on_task_completed_ids(i)[0]); 311 EXPECT_EQ(2u, on_task_completed_ids(i)[0]);
327 EXPECT_EQ(1u, on_task_completed_ids(i)[1]); 312 EXPECT_EQ(1u, on_task_completed_ids(i)[1]);
328 EXPECT_EQ(0u, on_task_completed_ids(i)[2]); 313 EXPECT_EQ(0u, on_task_completed_ids(i)[2]);
329 } 314 }
330 } 315 }
331 316
332 } // namespace 317 } // namespace
333 } // namespace cc 318 } // namespace cc
OLDNEW
« cc/resources/task_graph_runner.cc ('K') | « cc/resources/task_graph_runner_perftest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698