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" |
8 #include "gpu/command_buffer/service/gpu_tracer.h" | 9 #include "gpu/command_buffer/service/gpu_tracer.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/gl/gl_mock.h" | 11 #include "ui/gl/gl_mock.h" |
11 | 12 |
12 namespace gpu { | 13 namespace gpu { |
13 namespace gles2 { | 14 namespace gles2 { |
14 | 15 |
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 testing::Test { | 112 class GpuTracerTest : public GpuServiceTest { |
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 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); | 120 GpuServiceTest::SetUp(); |
121 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); | |
122 gl_fake_queries_.Reset(); | 121 gl_fake_queries_.Reset(); |
123 } | 122 } |
124 | 123 |
125 virtual void TearDown() { | 124 virtual void TearDown() { |
126 ::gfx::MockGLInterface::SetGLInterface(NULL); | |
127 gl_.reset(); | 125 gl_.reset(); |
128 gl_fake_queries_.Reset(); | 126 gl_fake_queries_.Reset(); |
| 127 GpuServiceTest::TearDown(); |
129 } | 128 } |
130 | 129 |
131 void SetupTimerQueryMocks() { | 130 void SetupTimerQueryMocks() { |
132 // Delegate query APIs used by GLARBTimerTrace to a GlFakeQueries | 131 // Delegate query APIs used by GLARBTimerTrace to a GlFakeQueries |
133 EXPECT_CALL(*gl_, GenQueries(_, NotNull())).Times(AtLeast(1)).WillOnce( | 132 EXPECT_CALL(*gl_, GenQueries(_, NotNull())).Times(AtLeast(1)).WillOnce( |
134 Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueries)); | 133 Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueries)); |
135 | 134 |
136 EXPECT_CALL(*gl_, GetQueryObjectiv(_, GL_QUERY_RESULT_AVAILABLE, NotNull())) | 135 EXPECT_CALL(*gl_, GetQueryObjectiv(_, GL_QUERY_RESULT_AVAILABLE, NotNull())) |
137 .Times(AtLeast(2)) | 136 .Times(AtLeast(2)) |
138 .WillRepeatedly( | 137 .WillRepeatedly( |
139 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectiv)); | 138 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectiv)); |
140 | 139 |
141 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)) | 140 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)) |
142 .Times(AtLeast(2)) | 141 .Times(AtLeast(2)) |
143 .WillRepeatedly( | 142 .WillRepeatedly( |
144 Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); | 143 Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); |
145 | 144 |
146 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) | 145 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) |
147 .Times(AtLeast(2)) | 146 .Times(AtLeast(2)) |
148 .WillRepeatedly( | 147 .WillRepeatedly( |
149 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectui64v)); | 148 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectui64v)); |
150 | 149 |
151 EXPECT_CALL(*gl_, DeleteQueries(2, NotNull())) | 150 EXPECT_CALL(*gl_, DeleteQueries(2, NotNull())) |
152 .Times(AtLeast(1)) | 151 .Times(AtLeast(1)) |
153 .WillRepeatedly( | 152 .WillRepeatedly( |
154 Invoke(&gl_fake_queries_, &GlFakeQueries::DeleteQueries)); | 153 Invoke(&gl_fake_queries_, &GlFakeQueries::DeleteQueries)); |
155 } | 154 } |
156 | 155 |
157 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; | |
158 GlFakeQueries gl_fake_queries_; | 156 GlFakeQueries gl_fake_queries_; |
159 }; | 157 }; |
160 | 158 |
161 TEST_F(GpuTracerTest, GLARBTimerTrace) { | 159 TEST_F(GpuTracerTest, GLARBTimerTrace) { |
162 // Test basic timer query functionality | 160 // Test basic timer query functionality |
163 { | 161 { |
164 MockOutputter* outputter = new MockOutputter(); | 162 MockOutputter* outputter = new MockOutputter(); |
165 scoped_refptr<Outputter> outputter_ref = outputter; | 163 scoped_refptr<Outputter> outputter_ref = outputter; |
166 | 164 |
167 SetupTimerQueryMocks(); | 165 SetupTimerQueryMocks(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 gl_fake_queries_.SetCurrentGLTime(end_timestamp); | 200 gl_fake_queries_.SetCurrentGLTime(end_timestamp); |
203 EXPECT_TRUE(trace->IsAvailable()); | 201 EXPECT_TRUE(trace->IsAvailable()); |
204 | 202 |
205 // Proces should output expected Trace results to MockOutputter | 203 // Proces should output expected Trace results to MockOutputter |
206 trace->Process(); | 204 trace->Process(); |
207 } | 205 } |
208 } | 206 } |
209 | 207 |
210 } // namespace gles2 | 208 } // namespace gles2 |
211 } // namespace gpu | 209 } // namespace gpu |
OLD | NEW |