Chromium Code Reviews| 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_service_test.h" |
| 9 #include "gpu/command_buffer/service/gpu_tracer.h" | 9 #include "gpu/command_buffer/service/gpu_tracer.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 public: | 23 public: |
| 24 MockOutputter() {} | 24 MockOutputter() {} |
| 25 MOCK_METHOD4(Trace, | 25 MOCK_METHOD4(Trace, |
| 26 void(const std::string& category, const std::string& name, | 26 void(const std::string& category, const std::string& name, |
| 27 int64 start_time, int64 end_time)); | 27 int64 start_time, int64 end_time)); |
| 28 | 28 |
| 29 protected: | 29 protected: |
| 30 ~MockOutputter() {} | 30 ~MockOutputter() {} |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 class GlFakeQueries { | 33 class GlFakeTraceQueries { |
| 34 public: | 34 public: |
| 35 GlFakeQueries() {} | 35 GlFakeTraceQueries() {} |
| 36 | 36 |
| 37 void Reset() { | 37 void Reset() { |
| 38 current_time_ = 0; | 38 current_time_ = 0; |
| 39 next_query_id_ = 23; | 39 next_query_id_ = 23; |
| 40 alloced_queries_.clear(); | 40 alloced_queries_.clear(); |
| 41 query_timestamp_.clear(); | 41 query_timestamp_.clear(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void SetCurrentGLTime(GLint64 current_time) { current_time_ = current_time; } | 44 void SetCurrentGLTime(GLint64 current_time) { current_time_ = current_time; } |
| 45 | 45 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 protected: | 97 protected: |
| 98 GLint64 current_time_; | 98 GLint64 current_time_; |
| 99 GLuint next_query_id_; | 99 GLuint next_query_id_; |
| 100 std::set<GLuint> alloced_queries_; | 100 std::set<GLuint> alloced_queries_; |
| 101 std::map<GLuint, GLint64> query_timestamp_; | 101 std::map<GLuint, GLint64> query_timestamp_; |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 class BaseGpuTracerTest : public GpuServiceTest { | 104 class BaseGpuTraceTest : public GpuServiceTest { |
| 105 public: | 105 public: |
| 106 BaseGpuTracerTest() {} | 106 BaseGpuTraceTest() {} |
| 107 | 107 |
| 108 /////////////////////////////////////////////////////////////////////////// | 108 /////////////////////////////////////////////////////////////////////////// |
| 109 | 109 |
| 110 void DoTraceTest() { | 110 void DoTraceTest() { |
| 111 MockOutputter* outputter = new MockOutputter(); | 111 MockOutputter* outputter = new MockOutputter(); |
| 112 scoped_refptr<Outputter> outputter_ref = outputter; | 112 scoped_refptr<Outputter> outputter_ref = outputter; |
| 113 | 113 |
| 114 SetupTimerQueryMocks(); | 114 SetupTimerQueryMocks(); |
| 115 | 115 |
| 116 // Expected results | 116 // Expected results |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 gl_fake_queries_.Reset(); | 162 gl_fake_queries_.Reset(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void TearDown() override { | 165 void TearDown() override { |
| 166 gl_.reset(); | 166 gl_.reset(); |
| 167 gl_fake_queries_.Reset(); | 167 gl_fake_queries_.Reset(); |
| 168 GpuServiceTest::TearDown(); | 168 GpuServiceTest::TearDown(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 virtual void SetupTimerQueryMocks() { | 171 virtual void SetupTimerQueryMocks() { |
| 172 // Delegate query APIs used by GPUTrace to a GlFakeQueries | 172 // Delegate query APIs used by GPUTrace to a GlFakeTraceQueries |
| 173 EXPECT_CALL(*gl_, GenQueriesARB(_, NotNull())).Times(AtLeast(1)).WillOnce( | 173 EXPECT_CALL(*gl_, GenQueriesARB(_, NotNull())).Times(AtLeast(1)).WillOnce( |
| 174 Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueriesARB)); | 174 Invoke(&gl_fake_queries_, &GlFakeTraceQueries::GenQueriesARB)); |
| 175 | 175 |
| 176 EXPECT_CALL(*gl_, GetQueryObjectiv(_, GL_QUERY_RESULT_AVAILABLE, NotNull())) | 176 EXPECT_CALL(*gl_, GetQueryObjectiv(_, GL_QUERY_RESULT_AVAILABLE, NotNull())) |
| 177 .Times(AtLeast(2)) | 177 .Times(AtLeast(2)) |
| 178 .WillRepeatedly( | 178 .WillRepeatedly( |
| 179 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectiv)); | 179 Invoke(&gl_fake_queries_, &GlFakeTraceQueries::GetQueryObjectiv)); |
| 180 | 180 |
| 181 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)) | 181 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)) |
| 182 .Times(AtLeast(2)) | 182 .Times(AtLeast(2)) |
| 183 .WillRepeatedly( | 183 .WillRepeatedly( |
| 184 Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); | 184 Invoke(&gl_fake_queries_, &GlFakeTraceQueries::QueryCounter)); |
| 185 | 185 |
| 186 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) | 186 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) |
| 187 .Times(AtLeast(2)) | 187 .Times(AtLeast(2)) |
| 188 .WillRepeatedly( | 188 .WillRepeatedly( |
| 189 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectui64v)); | 189 Invoke(&gl_fake_queries_, |
| 190 &GlFakeTraceQueries::GetQueryObjectui64v)); | |
| 190 | 191 |
| 191 EXPECT_CALL(*gl_, DeleteQueriesARB(2, NotNull())) | 192 EXPECT_CALL(*gl_, DeleteQueriesARB(2, NotNull())) |
| 192 .Times(AtLeast(1)) | 193 .Times(AtLeast(1)) |
| 193 .WillRepeatedly( | 194 .WillRepeatedly( |
| 194 Invoke(&gl_fake_queries_, &GlFakeQueries::DeleteQueriesARB)); | 195 Invoke(&gl_fake_queries_, &GlFakeTraceQueries::DeleteQueriesARB)); |
| 195 } | 196 } |
| 196 | 197 |
| 197 virtual GpuTracerType GetTracerType() = 0; | 198 virtual GpuTracerType GetTracerType() = 0; |
| 198 | 199 |
| 199 GlFakeQueries gl_fake_queries_; | 200 GlFakeTraceQueries gl_fake_queries_; |
| 200 }; | 201 }; |
| 201 | 202 |
| 202 class GpuARBTimerTracerTest : public BaseGpuTracerTest { | 203 class GpuARBTimerTraceTest : public BaseGpuTraceTest { |
| 203 protected: | 204 protected: |
| 204 GpuTracerType GetTracerType() override { return kTracerTypeARBTimer; } | 205 GpuTracerType GetTracerType() override { return kTracerTypeARBTimer; } |
| 205 }; | 206 }; |
| 206 | 207 |
| 207 class GpuDisjointTimerTracerTest : public BaseGpuTracerTest { | 208 class GpuDisjointTimerTraceTest : public BaseGpuTraceTest { |
| 208 protected: | 209 protected: |
| 209 GpuTracerType GetTracerType() override { return kTracerTypeDisjointTimer; } | 210 GpuTracerType GetTracerType() override { return kTracerTypeDisjointTimer; } |
| 210 }; | 211 }; |
| 211 | 212 |
| 212 TEST_F(GpuARBTimerTracerTest, GPUTrace) { | 213 TEST_F(GpuARBTimerTraceTest, ARBTimerTest) { |
| 213 // Test basic timer query functionality | 214 // Test basic timer query functionality |
| 214 { | 215 DoTraceTest(); |
| 215 DoTraceTest(); | |
| 216 } | |
| 217 } | 216 } |
| 218 | 217 |
| 219 TEST_F(GpuDisjointTimerTracerTest, GPUTrace) { | 218 TEST_F(GpuDisjointTimerTraceTest, DisjointTimerTest) { |
| 220 // Test basic timer query functionality | 219 // Test basic timer query functionality |
| 221 { | 220 DoTraceTest(); |
| 222 DoTraceTest(); | 221 } |
| 222 | |
| 223 // Test GPU Tracer | |
| 224 class MockGPUTracer : public GPUTracer { | |
|
vmiura
2014/12/19 00:30:15
This is not really a "Mock", I guess.
I think you
| |
| 225 public: | |
| 226 MockGPUTracer() | |
| 227 : GPUTracer(NULL), | |
| 228 tracing_enabled_(0) { | |
| 229 // Do not have the Mock GPU Tracer issue any GL calls. | |
| 230 tracer_type_ = kTracerTypeInvalid; | |
| 231 | |
| 232 // Force tracing to be dependent on our mock variable here. | |
| 233 gpu_trace_srv_category = &tracing_enabled_; | |
| 234 gpu_trace_dev_category = &tracing_enabled_; | |
| 223 } | 235 } |
| 236 | |
| 237 ~MockGPUTracer() { | |
| 238 } | |
| 239 | |
| 240 void SetTracingEnabled(bool enabled) { | |
| 241 tracing_enabled_ = enabled ? 1 : 0; | |
| 242 } | |
| 243 | |
| 244 protected: | |
| 245 unsigned char tracing_enabled_; | |
| 246 }; | |
| 247 | |
| 248 TEST(GpuTracerTest, IsTracingTest) { | |
| 249 MockGPUTracer mock_tracer; | |
| 250 EXPECT_FALSE(mock_tracer.IsTracing()); | |
| 251 mock_tracer.SetTracingEnabled(true); | |
| 252 EXPECT_TRUE(mock_tracer.IsTracing()); | |
| 253 } | |
| 254 | |
| 255 TEST(GpuTracerTest, DecodeTest) { | |
| 256 MockGPUTracer mock_tracer; | |
| 257 ASSERT_TRUE(mock_tracer.BeginDecoding()); | |
| 258 EXPECT_FALSE(mock_tracer.BeginDecoding()); | |
| 259 ASSERT_TRUE(mock_tracer.EndDecoding()); | |
| 260 EXPECT_FALSE(mock_tracer.EndDecoding()); | |
| 261 } | |
| 262 | |
| 263 TEST(GpuTracerTest, TraceDuringDecodeTest) { | |
| 264 MockGPUTracer mock_tracer; | |
| 265 const std::string category_name("trace_category"); | |
| 266 const std::string trace_name("trace_test"); | |
| 267 | |
| 268 EXPECT_FALSE(mock_tracer.Begin(category_name, trace_name, kTraceGroupMarker)); | |
| 269 | |
| 270 ASSERT_TRUE(mock_tracer.BeginDecoding()); | |
| 271 EXPECT_TRUE(mock_tracer.Begin(category_name, trace_name, kTraceGroupMarker)); | |
| 272 ASSERT_TRUE(mock_tracer.EndDecoding()); | |
| 273 } | |
| 274 | |
| 275 TEST(GpuTracerTest, TraceSourceTest) { | |
| 276 MockGPUTracer mock_tracer; | |
| 277 ASSERT_TRUE(mock_tracer.BeginDecoding()); | |
| 278 | |
| 279 // Begin a trace for all each source type. | |
| 280 const std::string group_category("group_category"); | |
| 281 const std::string group_name("group_test"); | |
| 282 ASSERT_TRUE(mock_tracer.Begin(group_category, group_name, kTraceGroupMarker)); | |
| 283 | |
| 284 const std::string chromium_category("chromium_category"); | |
| 285 const std::string chromium_name("chromium_test"); | |
| 286 ASSERT_TRUE(mock_tracer.Begin(chromium_category, chromium_name, | |
| 287 kTraceCHROMIUM)); | |
| 288 | |
| 289 const std::string decoder_category("decoder_category"); | |
| 290 const std::string decoder_name("decoder_test"); | |
| 291 ASSERT_TRUE(mock_tracer.Begin(decoder_category, decoder_name, kTraceDecoder)); | |
| 292 | |
| 293 // Each source type should have it's own current category/name. | |
| 294 EXPECT_EQ(group_category, mock_tracer.CurrentCategory(kTraceGroupMarker)); | |
| 295 EXPECT_EQ(group_name, mock_tracer.CurrentName(kTraceGroupMarker)); | |
| 296 | |
| 297 EXPECT_EQ(chromium_category, mock_tracer.CurrentCategory(kTraceCHROMIUM)); | |
| 298 EXPECT_EQ(chromium_name, mock_tracer.CurrentName(kTraceCHROMIUM)); | |
| 299 | |
| 300 EXPECT_EQ(decoder_category, mock_tracer.CurrentCategory(kTraceDecoder)); | |
| 301 EXPECT_EQ(decoder_name, mock_tracer.CurrentName(kTraceDecoder)); | |
| 302 | |
| 303 // End each source trace. | |
| 304 ASSERT_TRUE(mock_tracer.End(kTraceGroupMarker)); | |
| 305 ASSERT_TRUE(mock_tracer.End(kTraceCHROMIUM)); | |
| 306 ASSERT_TRUE(mock_tracer.End(kTraceDecoder)); | |
| 307 | |
| 308 // Should be nothing tracing now | |
| 309 const std::string empty_string; | |
| 310 EXPECT_EQ(empty_string, mock_tracer.CurrentCategory(kTraceGroupMarker)); | |
| 311 EXPECT_EQ(empty_string, mock_tracer.CurrentName(kTraceGroupMarker)); | |
| 312 | |
| 313 EXPECT_EQ(empty_string, mock_tracer.CurrentCategory(kTraceCHROMIUM)); | |
| 314 EXPECT_EQ(empty_string, mock_tracer.CurrentName(kTraceCHROMIUM)); | |
| 315 | |
| 316 EXPECT_EQ(empty_string, mock_tracer.CurrentCategory(kTraceDecoder)); | |
| 317 EXPECT_EQ(empty_string, mock_tracer.CurrentName(kTraceDecoder)); | |
| 318 | |
| 319 ASSERT_TRUE(mock_tracer.EndDecoding()); | |
| 224 } | 320 } |
| 225 | 321 |
| 226 } // namespace gles2 | 322 } // namespace gles2 |
| 227 } // namespace gpu | 323 } // namespace gpu |
| OLD | NEW |