| OLD | NEW |
| 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 <map> | 5 #include <map> |
| 6 #include <set> | 6 #include <set> |
| 7 | 7 |
| 8 #include "gpu/command_buffer/service/gpu_service_test.h" | |
| 9 #include "gpu/command_buffer/service/gpu_tracer.h" | 8 #include "gpu/command_buffer/service/gpu_tracer.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/gl/gl_mock.h" | 10 #include "ui/gl/gl_mock.h" |
| 12 | 11 |
| 13 namespace gpu { | 12 namespace gpu { |
| 14 namespace gles2 { | 13 namespace gles2 { |
| 15 | 14 |
| 15 using ::gfx::MockGLInterface; |
| 16 using ::testing::InvokeWithoutArgs; | 16 using ::testing::InvokeWithoutArgs; |
| 17 using ::testing::Return; | 17 using ::testing::Return; |
| 18 using ::testing::ReturnRef; | 18 using ::testing::ReturnRef; |
| 19 using ::testing::ReturnPointee; | 19 using ::testing::ReturnPointee; |
| 20 using ::testing::NotNull; | 20 using ::testing::NotNull; |
| 21 using ::testing::ElementsAreArray; | 21 using ::testing::ElementsAreArray; |
| 22 using ::testing::ElementsAre; | 22 using ::testing::ElementsAre; |
| 23 using ::testing::SetArrayArgument; | 23 using ::testing::SetArrayArgument; |
| 24 using ::testing::AtLeast; | 24 using ::testing::AtLeast; |
| 25 using ::testing::SetArgPointee; | 25 using ::testing::SetArgPointee; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 protected: | 105 protected: |
| 106 GLint64 current_time_; | 106 GLint64 current_time_; |
| 107 GLuint next_query_id_; | 107 GLuint next_query_id_; |
| 108 std::set<GLuint> alloced_queries_; | 108 std::set<GLuint> alloced_queries_; |
| 109 std::map<GLuint, GLint64> query_timestamp_; | 109 std::map<GLuint, GLint64> query_timestamp_; |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 class GpuTracerTest : public GpuServiceTest { | 112 class GpuTracerTest : public testing::Test { |
| 113 public: | 113 public: |
| 114 GpuTracerTest() {} | 114 GpuTracerTest() {} |
| 115 | 115 |
| 116 /////////////////////////////////////////////////////////////////////////// | 116 /////////////////////////////////////////////////////////////////////////// |
| 117 | 117 |
| 118 protected: | 118 protected: |
| 119 virtual void SetUp() { | 119 virtual void SetUp() { |
| 120 GpuServiceTest::SetUp(); | 120 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
| 121 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); |
| 121 gl_fake_queries_.Reset(); | 122 gl_fake_queries_.Reset(); |
| 122 } | 123 } |
| 123 | 124 |
| 124 virtual void TearDown() { | 125 virtual void TearDown() { |
| 126 ::gfx::MockGLInterface::SetGLInterface(NULL); |
| 125 gl_.reset(); | 127 gl_.reset(); |
| 126 gl_fake_queries_.Reset(); | 128 gl_fake_queries_.Reset(); |
| 127 GpuServiceTest::TearDown(); | |
| 128 } | 129 } |
| 129 | 130 |
| 130 void SetupTimerQueryMocks() { | 131 void SetupTimerQueryMocks() { |
| 131 // Delegate query APIs used by GLARBTimerTrace to a GlFakeQueries | 132 // Delegate query APIs used by GLARBTimerTrace to a GlFakeQueries |
| 132 EXPECT_CALL(*gl_, GenQueries(_, NotNull())).Times(AtLeast(1)).WillOnce( | 133 EXPECT_CALL(*gl_, GenQueries(_, NotNull())).Times(AtLeast(1)).WillOnce( |
| 133 Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueries)); | 134 Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueries)); |
| 134 | 135 |
| 135 EXPECT_CALL(*gl_, GetQueryObjectiv(_, GL_QUERY_RESULT_AVAILABLE, NotNull())) | 136 EXPECT_CALL(*gl_, GetQueryObjectiv(_, GL_QUERY_RESULT_AVAILABLE, NotNull())) |
| 136 .Times(AtLeast(2)) | 137 .Times(AtLeast(2)) |
| 137 .WillRepeatedly( | 138 .WillRepeatedly( |
| 138 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectiv)); | 139 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectiv)); |
| 139 | 140 |
| 140 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)) | 141 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)) |
| 141 .Times(AtLeast(2)) | 142 .Times(AtLeast(2)) |
| 142 .WillRepeatedly( | 143 .WillRepeatedly( |
| 143 Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); | 144 Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); |
| 144 | 145 |
| 145 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) | 146 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) |
| 146 .Times(AtLeast(2)) | 147 .Times(AtLeast(2)) |
| 147 .WillRepeatedly( | 148 .WillRepeatedly( |
| 148 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectui64v)); | 149 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectui64v)); |
| 149 | 150 |
| 150 EXPECT_CALL(*gl_, DeleteQueries(2, NotNull())) | 151 EXPECT_CALL(*gl_, DeleteQueries(2, NotNull())) |
| 151 .Times(AtLeast(1)) | 152 .Times(AtLeast(1)) |
| 152 .WillRepeatedly( | 153 .WillRepeatedly( |
| 153 Invoke(&gl_fake_queries_, &GlFakeQueries::DeleteQueries)); | 154 Invoke(&gl_fake_queries_, &GlFakeQueries::DeleteQueries)); |
| 154 } | 155 } |
| 155 | 156 |
| 157 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
| 156 GlFakeQueries gl_fake_queries_; | 158 GlFakeQueries gl_fake_queries_; |
| 157 }; | 159 }; |
| 158 | 160 |
| 159 TEST_F(GpuTracerTest, GLARBTimerTrace) { | 161 TEST_F(GpuTracerTest, GLARBTimerTrace) { |
| 160 // Test basic timer query functionality | 162 // Test basic timer query functionality |
| 161 { | 163 { |
| 162 MockOutputter* outputter = new MockOutputter(); | 164 MockOutputter* outputter = new MockOutputter(); |
| 163 scoped_refptr<Outputter> outputter_ref = outputter; | 165 scoped_refptr<Outputter> outputter_ref = outputter; |
| 164 | 166 |
| 165 SetupTimerQueryMocks(); | 167 SetupTimerQueryMocks(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 gl_fake_queries_.SetCurrentGLTime(end_timestamp); | 202 gl_fake_queries_.SetCurrentGLTime(end_timestamp); |
| 201 EXPECT_TRUE(trace->IsAvailable()); | 203 EXPECT_TRUE(trace->IsAvailable()); |
| 202 | 204 |
| 203 // Proces should output expected Trace results to MockOutputter | 205 // Proces should output expected Trace results to MockOutputter |
| 204 trace->Process(); | 206 trace->Process(); |
| 205 } | 207 } |
| 206 } | 208 } |
| 207 | 209 |
| 208 } // namespace gles2 | 210 } // namespace gles2 |
| 209 } // namespace gpu | 211 } // namespace gpu |
| OLD | NEW |