[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/callback.h" |
| 6 | #include "base/memory/scoped_ptr.h" |
| 7 | #include "cc/debug/micro_benchmark.h" |
| 8 | #include "cc/debug/micro_benchmark_controller.h" |
| 9 | #include "cc/layers/layer.h" |
| 10 | #include "cc/resources/resource_update_queue.h" |
| 11 | #include "cc/test/fake_layer_tree_host.h" |
| 12 | #include "cc/test/fake_proxy.h" |
| 13 | #include "testing/gtest/include/gtest/gtest.h" |
| 14 | |
| 15 | namespace cc { |
| 16 | namespace { |
| 17 | |
| 18 | class MicroBenchmarkControllerTest : public testing::Test { |
| 19 | public: |
| 20 | virtual void SetUp() { |
| 21 | layer_tree_host_ = FakeLayerTreeHost::Create(); |
| 22 | layer_tree_host_->SetRootLayer(Layer::Create()); |
| 23 | layer_tree_host_->InitializeForTesting( |
| 24 | scoped_ptr<Proxy>(new FakeProxy)); |
| 25 | } |
| 26 | |
| 27 | scoped_ptr<FakeLayerTreeHost> layer_tree_host_; |
| 28 | }; |
| 29 | |
| 30 | void Noop(scoped_ptr<base::Value> value) { |
| 31 | } |
| 32 | |
| 33 | void IncrementCallCount(int* count, scoped_ptr<base::Value> value) { |
| 34 | ++(*count); |
| 35 | } |
| 36 | |
| 37 | TEST_F(MicroBenchmarkControllerTest, ScheduleFail) { |
| 38 | bool result = layer_tree_host_->ScheduleMicroBenchmark( |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame^] | 39 | "non_existant_benchmark", scoped_ptr<base::Value>(), base::Bind(&Noop)); |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 40 | EXPECT_FALSE(result); |
| 41 | } |
| 42 | |
| 43 | TEST_F(MicroBenchmarkControllerTest, CommitScheduled) { |
| 44 | EXPECT_FALSE(layer_tree_host_->needs_commit()); |
| 45 | bool result = layer_tree_host_->ScheduleMicroBenchmark( |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame^] | 46 | "unittest_only_benchmark", scoped_ptr<base::Value>(), base::Bind(&Noop)); |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 47 | EXPECT_TRUE(result); |
| 48 | EXPECT_TRUE(layer_tree_host_->needs_commit()); |
| 49 | } |
| 50 | |
| 51 | TEST_F(MicroBenchmarkControllerTest, BenchmarkRan) { |
| 52 | int run_count = 0; |
| 53 | bool result = layer_tree_host_->ScheduleMicroBenchmark( |
| 54 | "unittest_only_benchmark", |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame^] | 55 | scoped_ptr<base::Value>(), |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 56 | base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
| 57 | EXPECT_TRUE(result); |
| 58 | |
| 59 | scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue); |
| 60 | layer_tree_host_->SetOutputSurfaceLostForTesting(false); |
| 61 | layer_tree_host_->UpdateLayers(queue.get()); |
| 62 | |
| 63 | EXPECT_EQ(1, run_count); |
| 64 | } |
| 65 | |
| 66 | TEST_F(MicroBenchmarkControllerTest, MultipleBenchmarkRan) { |
| 67 | int run_count = 0; |
| 68 | bool result = layer_tree_host_->ScheduleMicroBenchmark( |
| 69 | "unittest_only_benchmark", |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame^] | 70 | scoped_ptr<base::Value>(), |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 71 | base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
| 72 | EXPECT_TRUE(result); |
| 73 | result = layer_tree_host_->ScheduleMicroBenchmark( |
| 74 | "unittest_only_benchmark", |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame^] | 75 | scoped_ptr<base::Value>(), |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 76 | base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
| 77 | EXPECT_TRUE(result); |
| 78 | |
| 79 | scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue); |
| 80 | layer_tree_host_->SetOutputSurfaceLostForTesting(false); |
| 81 | layer_tree_host_->UpdateLayers(queue.get()); |
| 82 | |
| 83 | EXPECT_EQ(2, run_count); |
| 84 | |
| 85 | result = layer_tree_host_->ScheduleMicroBenchmark( |
| 86 | "unittest_only_benchmark", |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame^] | 87 | scoped_ptr<base::Value>(), |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 88 | base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
| 89 | EXPECT_TRUE(result); |
| 90 | result = layer_tree_host_->ScheduleMicroBenchmark( |
| 91 | "unittest_only_benchmark", |
[email protected] | 752e2cf | 2013-10-21 21:41:15 | [diff] [blame^] | 92 | scoped_ptr<base::Value>(), |
[email protected] | 666d7cf | 2013-10-12 01:30:29 | [diff] [blame] | 93 | base::Bind(&IncrementCallCount, base::Unretained(&run_count))); |
| 94 | EXPECT_TRUE(result); |
| 95 | |
| 96 | layer_tree_host_->UpdateLayers(queue.get()); |
| 97 | EXPECT_EQ(4, run_count); |
| 98 | |
| 99 | layer_tree_host_->UpdateLayers(queue.get()); |
| 100 | EXPECT_EQ(4, run_count); |
| 101 | } |
| 102 | |
| 103 | } // namespace |
| 104 | } // namespace cc |