OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/callback.h" | 5 #include "base/callback.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "cc/debug/micro_benchmark.h" | 7 #include "cc/debug/micro_benchmark.h" |
8 #include "cc/debug/micro_benchmark_controller.h" | 8 #include "cc/debug/micro_benchmark_controller.h" |
9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
10 #include "cc/resources/resource_update_queue.h" | 10 #include "cc/resources/resource_update_queue.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 }; | 42 }; |
43 | 43 |
44 void Noop(scoped_ptr<base::Value> value) { | 44 void Noop(scoped_ptr<base::Value> value) { |
45 } | 45 } |
46 | 46 |
47 void IncrementCallCount(int* count, scoped_ptr<base::Value> value) { | 47 void IncrementCallCount(int* count, scoped_ptr<base::Value> value) { |
48 ++(*count); | 48 ++(*count); |
49 } | 49 } |
50 | 50 |
51 TEST_F(MicroBenchmarkControllerTest, ScheduleFail) { | 51 TEST_F(MicroBenchmarkControllerTest, ScheduleFail) { |
52 bool result = layer_tree_host_->ScheduleMicroBenchmark( | 52 int id = layer_tree_host_->ScheduleMicroBenchmark( |
53 "non_existant_benchmark", scoped_ptr<base::Value>(), base::Bind(&Noop)); | 53 "non_existant_benchmark", scoped_ptr<base::Value>(), base::Bind(&Noop)); |
54 EXPECT_FALSE(result); | 54 EXPECT_EQ(id, 0); |
55 } | 55 } |
56 | 56 |
57 TEST_F(MicroBenchmarkControllerTest, CommitScheduled) { | 57 TEST_F(MicroBenchmarkControllerTest, CommitScheduled) { |
58 EXPECT_FALSE(layer_tree_host_->needs_commit()); | 58 EXPECT_FALSE(layer_tree_host_->needs_commit()); |
59 bool result = layer_tree_host_->ScheduleMicroBenchmark( | 59 int id = layer_tree_host_->ScheduleMicroBenchmark( |
60 "unittest_only_benchmark", scoped_ptr<base::Value>(), base::Bind(&Noop)); | 60 "unittest_only_benchmark", scoped_ptr<base::Value>(), base::Bind(&Noop)); |
61 EXPECT_TRUE(result); | 61 EXPECT_GT(id, 0); |
62 EXPECT_TRUE(layer_tree_host_->needs_commit()); | 62 EXPECT_TRUE(layer_tree_host_->needs_commit()); |
63 } | 63 } |
64 | 64 |
65 TEST_F(MicroBenchmarkControllerTest, BenchmarkRan) { | 65 TEST_F(MicroBenchmarkControllerTest, BenchmarkRan) { |
66 int run_count = 0; | 66 int run_count = 0; |
67 bool result = layer_tree_host_->ScheduleMicroBenchmark( | 67 int id = layer_tree_host_->ScheduleMicroBenchmark( |
68 "unittest_only_benchmark", | 68 "unittest_only_benchmark", |
69 scoped_ptr<base::Value>(), | 69 scoped_ptr<base::Value>(), |
70 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); | 70 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
71 EXPECT_TRUE(result); | 71 EXPECT_GT(id, 0); |
72 | 72 |
73 scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue); | 73 scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue); |
74 layer_tree_host_->SetOutputSurfaceLostForTesting(false); | 74 layer_tree_host_->SetOutputSurfaceLostForTesting(false); |
75 layer_tree_host_->UpdateLayers(queue.get()); | 75 layer_tree_host_->UpdateLayers(queue.get()); |
76 | 76 |
77 EXPECT_EQ(1, run_count); | 77 EXPECT_EQ(1, run_count); |
78 } | 78 } |
79 | 79 |
80 TEST_F(MicroBenchmarkControllerTest, MultipleBenchmarkRan) { | 80 TEST_F(MicroBenchmarkControllerTest, MultipleBenchmarkRan) { |
81 int run_count = 0; | 81 int run_count = 0; |
82 bool result = layer_tree_host_->ScheduleMicroBenchmark( | 82 int id = layer_tree_host_->ScheduleMicroBenchmark( |
83 "unittest_only_benchmark", | 83 "unittest_only_benchmark", |
84 scoped_ptr<base::Value>(), | 84 scoped_ptr<base::Value>(), |
85 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); | 85 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
86 EXPECT_TRUE(result); | 86 EXPECT_GT(id, 0); |
87 result = layer_tree_host_->ScheduleMicroBenchmark( | 87 id = layer_tree_host_->ScheduleMicroBenchmark( |
88 "unittest_only_benchmark", | 88 "unittest_only_benchmark", |
89 scoped_ptr<base::Value>(), | 89 scoped_ptr<base::Value>(), |
90 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); | 90 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
91 EXPECT_TRUE(result); | 91 EXPECT_GT(id, 0); |
92 | 92 |
93 scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue); | 93 scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue); |
94 layer_tree_host_->SetOutputSurfaceLostForTesting(false); | 94 layer_tree_host_->SetOutputSurfaceLostForTesting(false); |
95 layer_tree_host_->UpdateLayers(queue.get()); | 95 layer_tree_host_->UpdateLayers(queue.get()); |
96 | 96 |
97 EXPECT_EQ(2, run_count); | 97 EXPECT_EQ(2, run_count); |
98 | 98 |
99 result = layer_tree_host_->ScheduleMicroBenchmark( | 99 id = layer_tree_host_->ScheduleMicroBenchmark( |
100 "unittest_only_benchmark", | 100 "unittest_only_benchmark", |
101 scoped_ptr<base::Value>(), | 101 scoped_ptr<base::Value>(), |
102 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); | 102 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
103 EXPECT_TRUE(result); | 103 EXPECT_GT(id, 0); |
104 result = layer_tree_host_->ScheduleMicroBenchmark( | 104 id = layer_tree_host_->ScheduleMicroBenchmark( |
105 "unittest_only_benchmark", | 105 "unittest_only_benchmark", |
106 scoped_ptr<base::Value>(), | 106 scoped_ptr<base::Value>(), |
107 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); | 107 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
108 EXPECT_TRUE(result); | 108 EXPECT_GT(id, 0); |
109 | 109 |
110 layer_tree_host_->UpdateLayers(queue.get()); | 110 layer_tree_host_->UpdateLayers(queue.get()); |
111 EXPECT_EQ(4, run_count); | 111 EXPECT_EQ(4, run_count); |
112 | 112 |
113 layer_tree_host_->UpdateLayers(queue.get()); | 113 layer_tree_host_->UpdateLayers(queue.get()); |
114 EXPECT_EQ(4, run_count); | 114 EXPECT_EQ(4, run_count); |
115 } | 115 } |
116 | 116 |
117 TEST_F(MicroBenchmarkControllerTest, BenchmarkImplRan) { | 117 TEST_F(MicroBenchmarkControllerTest, BenchmarkImplRan) { |
118 int run_count = 0; | 118 int run_count = 0; |
119 scoped_ptr<base::DictionaryValue> settings(new base::DictionaryValue); | 119 scoped_ptr<base::DictionaryValue> settings(new base::DictionaryValue); |
120 settings->SetBoolean("run_benchmark_impl", true); | 120 settings->SetBoolean("run_benchmark_impl", true); |
121 | 121 |
122 // Schedule a main thread benchmark. | 122 // Schedule a main thread benchmark. |
123 bool result = layer_tree_host_->ScheduleMicroBenchmark( | 123 int id = layer_tree_host_->ScheduleMicroBenchmark( |
124 "unittest_only_benchmark", | 124 "unittest_only_benchmark", |
125 settings.PassAs<base::Value>(), | 125 settings.PassAs<base::Value>(), |
126 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); | 126 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
127 EXPECT_TRUE(result); | 127 EXPECT_GT(id, 0); |
128 | 128 |
129 // Schedule impl benchmarks. In production code, this is run in commit. | 129 // Schedule impl benchmarks. In production code, this is run in commit. |
130 layer_tree_host_->GetMicroBenchmarkController()->ScheduleImplBenchmarks( | 130 layer_tree_host_->GetMicroBenchmarkController()->ScheduleImplBenchmarks( |
131 layer_tree_host_impl_.get()); | 131 layer_tree_host_impl_.get()); |
132 | 132 |
133 // Now complete the commit (as if on the impl thread). | 133 // Now complete the commit (as if on the impl thread). |
134 layer_tree_host_impl_->CommitComplete(); | 134 layer_tree_host_impl_->CommitComplete(); |
135 | 135 |
136 // Make sure all posted messages run. | 136 // Make sure all posted messages run. |
137 base::MessageLoop::current()->RunUntilIdle(); | 137 base::MessageLoop::current()->RunUntilIdle(); |
138 | 138 |
139 EXPECT_EQ(1, run_count); | 139 EXPECT_EQ(1, run_count); |
140 } | 140 } |
141 | 141 |
| 142 TEST_F(MicroBenchmarkControllerTest, SendMessage) { |
| 143 // Send valid message to invalid benchmark (id = 0) |
| 144 scoped_ptr<base::DictionaryValue> message(new base::DictionaryValue); |
| 145 message->SetBoolean("can_handle", true); |
| 146 bool message_handled = layer_tree_host_->SendMessageToMicroBenchmark( |
| 147 0, message.PassAs<base::Value>()); |
| 148 EXPECT_FALSE(message_handled); |
| 149 |
| 150 // Schedule a benchmark |
| 151 int run_count = 0; |
| 152 int id = layer_tree_host_->ScheduleMicroBenchmark( |
| 153 "unittest_only_benchmark", |
| 154 scoped_ptr<base::Value>(), |
| 155 base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
| 156 EXPECT_GT(id, 0); |
| 157 |
| 158 // Send valid message to valid benchmark |
| 159 message = scoped_ptr<base::DictionaryValue>(new base::DictionaryValue); |
| 160 message->SetBoolean("can_handle", true); |
| 161 message_handled = layer_tree_host_->SendMessageToMicroBenchmark( |
| 162 id, message.PassAs<base::Value>()); |
| 163 EXPECT_TRUE(message_handled); |
| 164 |
| 165 // Send invalid message to valid benchmark |
| 166 message = scoped_ptr<base::DictionaryValue>(new base::DictionaryValue); |
| 167 message->SetBoolean("can_handle", false); |
| 168 message_handled = layer_tree_host_->SendMessageToMicroBenchmark( |
| 169 id, message.PassAs<base::Value>()); |
| 170 EXPECT_FALSE(message_handled); |
| 171 } |
| 172 |
142 } // namespace | 173 } // namespace |
143 } // namespace cc | 174 } // namespace cc |
OLD | NEW |