| 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 "base/bind.h" |
| 8 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" |
| 9 #include "gpu/command_buffer/service/gpu_service_test.h" | 10 #include "gpu/command_buffer/service/gpu_service_test.h" |
| 11 #include "gpu/command_buffer/service/gpu_timing.h" |
| 10 #include "gpu/command_buffer/service/gpu_tracer.h" | 12 #include "gpu/command_buffer/service/gpu_tracer.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/gl/gl_context_stub.h" | |
| 13 #include "ui/gl/gl_mock.h" | 14 #include "ui/gl/gl_mock.h" |
| 14 #include "ui/gl/gl_surface_stub.h" | |
| 15 | 15 |
| 16 namespace gpu { | 16 namespace gpu { |
| 17 namespace gles2 { | 17 namespace gles2 { |
| 18 namespace { |
| 18 | 19 |
| 19 using ::testing::_; | 20 using ::testing::_; |
| 20 using ::testing::AtLeast; | 21 using ::testing::AtLeast; |
| 22 using ::testing::AtMost; |
| 21 using ::testing::Exactly; | 23 using ::testing::Exactly; |
| 22 using ::testing::Invoke; | 24 using ::testing::Invoke; |
| 23 using ::testing::NotNull; | 25 using ::testing::NotNull; |
| 24 using ::testing::Return; | 26 using ::testing::Return; |
| 25 | 27 |
| 26 class FakeCPUTime : public CPUTime { | 28 int64 g_fakeCPUTime = 0; |
| 27 public: | 29 int64 FakeCpuTime() { |
| 28 FakeCPUTime() | 30 return g_fakeCPUTime; |
| 29 : current_cpu_time_(0) { | 31 } |
| 30 } | |
| 31 | |
| 32 int64 GetCurrentTime() override { | |
| 33 return current_cpu_time_; | |
| 34 } | |
| 35 | |
| 36 void SetFakeCPUTime(int64 cpu_time) { | |
| 37 current_cpu_time_ = cpu_time; | |
| 38 } | |
| 39 | |
| 40 protected: | |
| 41 ~FakeCPUTime() override {} | |
| 42 | |
| 43 int64 current_cpu_time_; | |
| 44 }; | |
| 45 | 32 |
| 46 class MockOutputter : public Outputter { | 33 class MockOutputter : public Outputter { |
| 47 public: | 34 public: |
| 48 MockOutputter() {} | 35 MockOutputter() {} |
| 49 MOCK_METHOD4(TraceDevice, | 36 MOCK_METHOD4(TraceDevice, |
| 50 void(const std::string& category, const std::string& name, | 37 void(const std::string& category, const std::string& name, |
| 51 int64 start_time, int64 end_time)); | 38 int64 start_time, int64 end_time)); |
| 52 | 39 |
| 53 MOCK_METHOD2(TraceServiceBegin, | 40 MOCK_METHOD2(TraceServiceBegin, |
| 54 void(const std::string& category, const std::string& name)); | 41 void(const std::string& category, const std::string& name)); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 134 } |
| 148 | 135 |
| 149 void Finish() { | 136 void Finish() { |
| 150 } | 137 } |
| 151 | 138 |
| 152 GLenum GetError() { | 139 GLenum GetError() { |
| 153 return GL_NO_ERROR; | 140 return GL_NO_ERROR; |
| 154 } | 141 } |
| 155 | 142 |
| 156 protected: | 143 protected: |
| 157 bool disjointed_; | 144 bool disjointed_ = false; |
| 158 GLint64 current_time_; | 145 GLint64 current_time_ = 0; |
| 159 GLuint next_query_id_; | 146 GLuint next_query_id_ = 0; |
| 160 std::set<GLuint> alloced_queries_; | 147 std::set<GLuint> alloced_queries_; |
| 161 std::map<GLuint, GLint64> query_timestamp_; | 148 std::map<GLuint, GLint64> query_timestamp_; |
| 162 }; | 149 }; |
| 163 | 150 |
| 164 class GPUTracerTester : public GPUTracer { | 151 class GPUTracerTester : public GPUTracer { |
| 165 public: | 152 public: |
| 166 GPUTracerTester(GpuTracerType tracer_type, gles2::GLES2Decoder* decoder) | 153 explicit GPUTracerTester(gles2::GLES2Decoder* decoder) |
| 167 : GPUTracer(decoder), | 154 : GPUTracer(decoder), tracing_enabled_(0) { |
| 168 tracing_enabled_(0), | 155 gpu_timing_.SetCpuTimeForTesting(base::Bind(&FakeCpuTime)); |
| 169 test_tracer_type_(tracer_type) { | 156 |
| 170 // Force tracing to be dependent on our mock variable here. | 157 // Force tracing to be dependent on our mock variable here. |
| 171 gpu_trace_srv_category = &tracing_enabled_; | 158 gpu_trace_srv_category = &tracing_enabled_; |
| 172 gpu_trace_dev_category = &tracing_enabled_; | 159 gpu_trace_dev_category = &tracing_enabled_; |
| 173 } | 160 } |
| 174 | 161 |
| 175 ~GPUTracerTester() override {} | 162 ~GPUTracerTester() override {} |
| 176 | 163 |
| 177 void SetTracingEnabled(bool enabled) { | 164 void SetTracingEnabled(bool enabled) { |
| 178 tracing_enabled_ = enabled ? 1 : 0; | 165 tracing_enabled_ = enabled ? 1 : 0; |
| 179 } | 166 } |
| 180 | 167 |
| 181 void SetOutputter(scoped_refptr<Outputter> outputter) { | 168 void SetOutputter(scoped_refptr<Outputter> outputter) { |
| 182 set_outputter_ = outputter; | 169 set_outputter_ = outputter; |
| 183 } | 170 } |
| 184 | 171 |
| 185 void SetCPUTime(scoped_refptr<CPUTime> cputime) { | |
| 186 set_cputime_ = cputime; | |
| 187 } | |
| 188 | |
| 189 protected: | 172 protected: |
| 190 scoped_refptr<Outputter> CreateOutputter(const std::string& name) override { | 173 scoped_refptr<Outputter> CreateOutputter(const std::string& name) override { |
| 191 if (set_outputter_.get()) { | 174 if (set_outputter_.get()) { |
| 192 return set_outputter_; | 175 return set_outputter_; |
| 193 } | 176 } |
| 194 return new MockOutputter(); | 177 return new MockOutputter(); |
| 195 } | 178 } |
| 196 | 179 |
| 197 scoped_refptr<CPUTime> CreateCPUTime() override { | |
| 198 if (set_cputime_.get()) { | |
| 199 return set_cputime_; | |
| 200 } | |
| 201 return new FakeCPUTime(); | |
| 202 } | |
| 203 | |
| 204 GpuTracerType DetermineTracerType() override { | |
| 205 return test_tracer_type_; | |
| 206 } | |
| 207 | |
| 208 void PostTask() override { | 180 void PostTask() override { |
| 209 // Process synchronously. | 181 // Process synchronously. |
| 210 Process(); | 182 Process(); |
| 211 } | 183 } |
| 212 | 184 |
| 213 unsigned char tracing_enabled_; | 185 unsigned char tracing_enabled_; |
| 214 GpuTracerType test_tracer_type_; | |
| 215 | 186 |
| 216 scoped_refptr<Outputter> set_outputter_; | 187 scoped_refptr<Outputter> set_outputter_; |
| 217 scoped_refptr<CPUTime> set_cputime_; | |
| 218 }; | 188 }; |
| 219 | 189 |
| 220 class BaseGpuTest : public GpuServiceTest { | 190 class BaseGpuTest : public GpuServiceTest { |
| 221 public: | 191 public: |
| 222 BaseGpuTest(GpuTracerType test_tracer_type) | 192 explicit BaseGpuTest(GPUTiming::TimerType test_timer_type) |
| 223 : test_tracer_type_(test_tracer_type) { | 193 : test_timer_type_(test_timer_type) { |
| 194 gpu_timing_.SetCpuTimeForTesting(base::Bind(&FakeCpuTime)); |
| 195 gpu_timing_.SetTimerTypeForTesting(test_timer_type); |
| 224 } | 196 } |
| 225 | 197 |
| 226 protected: | 198 protected: |
| 227 void SetUp() override { | 199 void SetUp() override { |
| 200 g_fakeCPUTime = 0; |
| 228 const char* gl_version = "3.2"; | 201 const char* gl_version = "3.2"; |
| 229 const char* extensions = nullptr; | 202 const char* extensions = ""; |
| 230 if (GetTracerType() == kTracerTypeDisjointTimer) { | 203 if (GetTimerType() == GPUTiming::kTimerTypeDisjoint) { |
| 231 gl_version = "opengl es 3.0"; | 204 gl_version = "opengl es 3.0"; |
| 232 extensions = "GL_EXT_disjoint_timer_query"; | 205 extensions = "GL_EXT_disjoint_timer_query"; |
| 233 } else if (GetTracerType() == kTracerTypeARBTimer) { | 206 } else if (GetTimerType() == GPUTiming::kTimerTypeARB) { |
| 234 // TODO(sievers): The tracer should not depend on ARB_occlusion_query. | 207 // TODO(sievers): The tracer should not depend on ARB_occlusion_query. |
| 235 // Try merge Query APIs (core, ARB, EXT) into a single binding each. | 208 // Try merge Query APIs (core, ARB, EXT) into a single binding each. |
| 236 extensions = "GL_ARB_timer_query GL_ARB_occlusion_query"; | 209 extensions = "GL_ARB_timer_query GL_ARB_occlusion_query"; |
| 237 } | 210 } |
| 238 GpuServiceTest::SetUpWithGLVersion(gl_version, extensions); | 211 GpuServiceTest::SetUpWithGLVersion(gl_version, extensions); |
| 239 gl_fake_queries_.Reset(); | 212 gl_fake_queries_.Reset(); |
| 240 gl_surface_ = new gfx::GLSurfaceStub(); | |
| 241 gl_context_ = new gfx::GLContextStub(); | |
| 242 gl_context_->MakeCurrent(gl_surface_.get()); | |
| 243 | 213 |
| 244 outputter_ref_ = new MockOutputter(); | 214 outputter_ref_ = new MockOutputter(); |
| 245 cpu_time_ref_ = new FakeCPUTime; | |
| 246 } | 215 } |
| 247 | 216 |
| 248 void TearDown() override { | 217 void TearDown() override { |
| 249 outputter_ref_ = NULL; | 218 outputter_ref_ = NULL; |
| 250 cpu_time_ref_ = NULL; | |
| 251 | 219 |
| 252 gl_context_->ReleaseCurrent(gl_surface_.get()); | |
| 253 gl_context_ = NULL; | |
| 254 gl_surface_ = NULL; | |
| 255 | |
| 256 gl_.reset(); | |
| 257 gl_fake_queries_.Reset(); | 220 gl_fake_queries_.Reset(); |
| 258 GpuServiceTest::TearDown(); | 221 GpuServiceTest::TearDown(); |
| 259 } | 222 } |
| 260 | 223 |
| 261 void ExpectTraceQueryMocks() { | 224 void ExpectTraceQueryMocks() { |
| 262 if (GetTracerType() != kTracerTypeInvalid) { | 225 if (GetTimerType() != GPUTiming::kTimerTypeInvalid) { |
| 263 // Delegate query APIs used by GPUTrace to a GlFakeQueries | 226 // Delegate query APIs used by GPUTrace to a GlFakeQueries |
| 264 EXPECT_CALL(*gl_, GenQueriesARB(2, NotNull())).Times(AtLeast(1)) | 227 EXPECT_CALL(*gl_, GenQueriesARB(2, NotNull())).Times(AtLeast(1)) |
| 265 .WillRepeatedly( | 228 .WillRepeatedly( |
| 266 Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueriesARB)); | 229 Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueriesARB)); |
| 267 | 230 |
| 268 EXPECT_CALL(*gl_, GetQueryObjectivARB(_, GL_QUERY_RESULT_AVAILABLE, | 231 EXPECT_CALL(*gl_, GetQueryObjectivARB(_, GL_QUERY_RESULT_AVAILABLE, |
| 269 NotNull())) | 232 NotNull())) |
| 270 .WillRepeatedly( | 233 .WillRepeatedly( |
| 271 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectivARB)); | 234 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectivARB)); |
| 272 | 235 |
| 273 if (GetTracerType() == kTracerTypeDisjointTimer) { | 236 if (GetTimerType() == GPUTiming::kTimerTypeDisjoint) { |
| 274 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, _)) | 237 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, _)) |
| 275 .WillRepeatedly( | 238 .WillRepeatedly( |
| 276 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); | 239 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); |
| 277 } | 240 } |
| 278 | 241 |
| 279 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)).Times(AtLeast(2)) | 242 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)).Times(AtLeast(2)) |
| 280 .WillRepeatedly( | 243 .WillRepeatedly( |
| 281 Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); | 244 Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); |
| 282 | 245 |
| 283 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) | 246 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 expect_start_time, expect_end_time)) | 279 expect_start_time, expect_end_time)) |
| 317 .Times(Exactly(0)); | 280 .Times(Exactly(0)); |
| 318 } | 281 } |
| 319 } | 282 } |
| 320 | 283 |
| 321 void ExpectOutputterMocks(MockOutputter* outputter, | 284 void ExpectOutputterMocks(MockOutputter* outputter, |
| 322 const std::string& category, | 285 const std::string& category, |
| 323 const std::string& name, int64 expect_start_time, | 286 const std::string& name, int64 expect_start_time, |
| 324 int64 expect_end_time) { | 287 int64 expect_end_time) { |
| 325 ExpectOutputterBeginMocks(outputter, category, name); | 288 ExpectOutputterBeginMocks(outputter, category, name); |
| 326 ExpectOutputterEndMocks(outputter, category, name, | 289 ExpectOutputterEndMocks(outputter, category, name, expect_start_time, |
| 327 expect_start_time, expect_end_time, | 290 expect_end_time, |
| 328 GetTracerType() != kTracerTypeInvalid); | 291 GetTimerType() != GPUTiming::kTimerTypeInvalid); |
| 329 } | 292 } |
| 330 | 293 |
| 331 void ExpectTracerOffsetQueryMocks() { | 294 void ExpectTracerOffsetQueryMocks() { |
| 332 // Disjoint check should only be called by kTracerTypeDisjointTimer type. | 295 // Disjoint check should only be called by kTracerTypeDisjointTimer type. |
| 333 if (GetTracerType() == kTracerTypeDisjointTimer) { | 296 if (GetTimerType() == GPUTiming::kTimerTypeDisjoint) { |
| 334 EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(AtLeast(1)) | 297 EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(AtLeast(1)) |
| 335 .WillRepeatedly( | 298 .WillRepeatedly( |
| 336 Invoke(&gl_fake_queries_, &GlFakeQueries::GetIntegerv)); | 299 Invoke(&gl_fake_queries_, &GlFakeQueries::GetIntegerv)); |
| 337 } else { | 300 } else { |
| 338 EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(Exactly(0)); | 301 EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(Exactly(0)); |
| 339 } | 302 } |
| 340 | 303 |
| 341 // Timer offset calculation should only happen for the regular timer. | 304 if (GetTimerType() != GPUTiming::kTimerTypeARB) { |
| 342 if (GetTracerType() != kTracerTypeARBTimer) { | |
| 343 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) | 305 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) |
| 344 .Times(Exactly(0)); | 306 .Times(Exactly(0)); |
| 345 } else { | 307 } else { |
| 346 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) | 308 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) |
| 347 .Times(AtLeast(1)) | 309 .Times(AtMost(1)) |
| 348 .WillRepeatedly( | 310 .WillRepeatedly( |
| 349 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); | 311 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); |
| 350 } | 312 } |
| 351 } | 313 } |
| 352 | 314 |
| 353 GpuTracerType GetTracerType() { return test_tracer_type_; } | 315 GPUTiming::TimerType GetTimerType() { return test_timer_type_; } |
| 354 | 316 |
| 355 GpuTracerType test_tracer_type_; | 317 GPUTiming::TimerType test_timer_type_; |
| 356 GlFakeQueries gl_fake_queries_; | 318 GlFakeQueries gl_fake_queries_; |
| 357 | 319 |
| 320 GPUTiming gpu_timing_; |
| 358 scoped_refptr<MockOutputter> outputter_ref_; | 321 scoped_refptr<MockOutputter> outputter_ref_; |
| 359 scoped_refptr<FakeCPUTime> cpu_time_ref_; | |
| 360 | |
| 361 scoped_refptr<gfx::GLSurface> gl_surface_; | |
| 362 scoped_refptr<gfx::GLContext> gl_context_; | |
| 363 }; | 322 }; |
| 364 | 323 |
| 365 // Test GPUTrace calls all the correct gl calls. | 324 // Test GPUTrace calls all the correct gl calls. |
| 366 class BaseGpuTraceTest : public BaseGpuTest { | 325 class BaseGpuTraceTest : public BaseGpuTest { |
| 367 public: | 326 public: |
| 368 BaseGpuTraceTest(GpuTracerType test_tracer_type) | 327 explicit BaseGpuTraceTest(GPUTiming::TimerType test_timer_type) |
| 369 : BaseGpuTest(test_tracer_type) { | 328 : BaseGpuTest(test_timer_type) {} |
| 370 } | |
| 371 | 329 |
| 372 void DoTraceTest() { | 330 void DoTraceTest() { |
| 373 // Expected results | 331 // Expected results |
| 374 const std::string category_name("trace_category"); | 332 const std::string category_name("trace_category"); |
| 375 const std::string trace_name("trace_test"); | 333 const std::string trace_name("trace_test"); |
| 376 const int64 offset_time = 3231; | 334 const int64 offset_time = 3231; |
| 377 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; | 335 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; |
| 378 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; | 336 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; |
| 379 const int64 expect_start_time = | 337 const int64 expect_start_time = |
| 380 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + | 338 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + |
| 381 offset_time; | 339 offset_time; |
| 382 const int64 expect_end_time = | 340 const int64 expect_end_time = |
| 383 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; | 341 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; |
| 384 | 342 |
| 385 ExpectTraceQueryMocks(); | 343 ExpectTraceQueryMocks(); |
| 386 ExpectOutputterMocks(outputter_ref_.get(), category_name, trace_name, | 344 ExpectOutputterMocks(outputter_ref_.get(), category_name, trace_name, |
| 387 expect_start_time, expect_end_time); | 345 expect_start_time, expect_end_time); |
| 388 | 346 |
| 389 scoped_refptr<GPUTrace> trace = | 347 scoped_refptr<GPUTrace> trace = new GPUTrace( |
| 390 new GPUTrace(outputter_ref_, cpu_time_ref_, category_name, trace_name, | 348 outputter_ref_, &gpu_timing_, category_name, trace_name, true); |
| 391 offset_time, GetTracerType()); | 349 |
| 350 gpu_timing_.SetOffsetForTesting( |
| 351 offset_time, test_timer_type_ == GPUTiming::kTimerTypeARB); |
| 392 | 352 |
| 393 gl_fake_queries_.SetCurrentGLTime(start_timestamp); | 353 gl_fake_queries_.SetCurrentGLTime(start_timestamp); |
| 394 cpu_time_ref_->SetFakeCPUTime(expect_start_time); | 354 g_fakeCPUTime = expect_start_time; |
| 395 trace->Start(true); | 355 trace->Start(true); |
| 396 | 356 |
| 397 // Shouldn't be available before End() call | 357 // Shouldn't be available before End() call |
| 398 gl_fake_queries_.SetCurrentGLTime(end_timestamp); | 358 gl_fake_queries_.SetCurrentGLTime(end_timestamp); |
| 399 EXPECT_FALSE(trace->IsAvailable()); | 359 EXPECT_FALSE(trace->IsAvailable()); |
| 400 | 360 |
| 401 trace->End(true); | 361 trace->End(true); |
| 402 | 362 |
| 403 // Shouldn't be available until the queries complete | 363 // Shouldn't be available until the queries complete |
| 404 gl_fake_queries_.SetCurrentGLTime(end_timestamp - | 364 gl_fake_queries_.SetCurrentGLTime(end_timestamp - |
| 405 base::Time::kNanosecondsPerMicrosecond); | 365 base::Time::kNanosecondsPerMicrosecond); |
| 406 EXPECT_FALSE(trace->IsAvailable()); | 366 EXPECT_FALSE(trace->IsAvailable()); |
| 407 | 367 |
| 408 // Now it should be available | 368 // Now it should be available |
| 409 gl_fake_queries_.SetCurrentGLTime(end_timestamp); | 369 gl_fake_queries_.SetCurrentGLTime(end_timestamp); |
| 410 EXPECT_TRUE(trace->IsAvailable()); | 370 EXPECT_TRUE(trace->IsAvailable()); |
| 411 | 371 |
| 412 // Proces should output expected Trace results to MockOutputter | 372 // Proces should output expected Trace results to MockOutputter |
| 413 trace->Process(); | 373 trace->Process(); |
| 414 | 374 |
| 415 outputter_ref_ = NULL; | 375 outputter_ref_ = NULL; |
| 416 cpu_time_ref_ = NULL; | |
| 417 } | 376 } |
| 418 }; | 377 }; |
| 419 | 378 |
| 420 class GpuARBTimerTraceTest : public BaseGpuTraceTest { | 379 class GpuARBTimerTraceTest : public BaseGpuTraceTest { |
| 421 public: | 380 public: |
| 422 GpuARBTimerTraceTest() | 381 GpuARBTimerTraceTest() : BaseGpuTraceTest(GPUTiming::kTimerTypeARB) {} |
| 423 : BaseGpuTraceTest(kTracerTypeARBTimer) { | |
| 424 } | |
| 425 }; | 382 }; |
| 426 | 383 |
| 427 class GpuDisjointTimerTraceTest : public BaseGpuTraceTest { | 384 class GpuDisjointTimerTraceTest : public BaseGpuTraceTest { |
| 428 public: | 385 public: |
| 429 GpuDisjointTimerTraceTest() | 386 GpuDisjointTimerTraceTest() |
| 430 : BaseGpuTraceTest(kTracerTypeDisjointTimer) { | 387 : BaseGpuTraceTest(GPUTiming::kTimerTypeDisjoint) {} |
| 431 } | |
| 432 }; | 388 }; |
| 433 | 389 |
| 434 TEST_F(GpuARBTimerTraceTest, ARBTimerTraceTest) { | 390 TEST_F(GpuARBTimerTraceTest, ARBTimerTraceTest) { |
| 435 DoTraceTest(); | 391 DoTraceTest(); |
| 436 } | 392 } |
| 437 | 393 |
| 438 TEST_F(GpuDisjointTimerTraceTest, DisjointTimerTraceTest) { | 394 TEST_F(GpuDisjointTimerTraceTest, DisjointTimerTraceTest) { |
| 439 DoTraceTest(); | 395 DoTraceTest(); |
| 440 } | 396 } |
| 441 | 397 |
| 442 // Test GPUTracer calls all the correct gl calls. | 398 // Test GPUTracer calls all the correct gl calls. |
| 443 class BaseGpuTracerTest : public BaseGpuTest { | 399 class BaseGpuTracerTest : public BaseGpuTest { |
| 444 public: | 400 public: |
| 445 BaseGpuTracerTest(GpuTracerType test_tracer_type) | 401 explicit BaseGpuTracerTest(GPUTiming::TimerType test_timer_type) |
| 446 : BaseGpuTest(test_tracer_type) { | 402 : BaseGpuTest(test_timer_type) {} |
| 447 } | |
| 448 | 403 |
| 449 void DoBasicTracerTest() { | 404 void DoBasicTracerTest() { |
| 450 ExpectTracerOffsetQueryMocks(); | 405 ExpectTracerOffsetQueryMocks(); |
| 451 | 406 |
| 452 MockGLES2Decoder decoder; | 407 MockGLES2Decoder decoder; |
| 453 GPUTracerTester tracer(test_tracer_type_, &decoder); | 408 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); |
| 409 GPUTracerTester tracer(&decoder); |
| 454 tracer.SetTracingEnabled(true); | 410 tracer.SetTracingEnabled(true); |
| 455 | 411 |
| 456 tracer.SetOutputter(outputter_ref_); | 412 tracer.SetOutputter(outputter_ref_); |
| 457 tracer.SetCPUTime(cpu_time_ref_); | |
| 458 | 413 |
| 459 ASSERT_TRUE(tracer.BeginDecoding()); | 414 ASSERT_TRUE(tracer.BeginDecoding()); |
| 460 ASSERT_TRUE(tracer.EndDecoding()); | 415 ASSERT_TRUE(tracer.EndDecoding()); |
| 461 | 416 |
| 462 outputter_ref_ = NULL; | 417 outputter_ref_ = NULL; |
| 463 cpu_time_ref_ = NULL; | |
| 464 } | 418 } |
| 465 | 419 |
| 466 void DoTracerMarkersTest() { | 420 void DoTracerMarkersTest() { |
| 467 ExpectTracerOffsetQueryMocks(); | 421 ExpectTracerOffsetQueryMocks(); |
| 468 | 422 |
| 469 EXPECT_CALL(*gl_, GetError()).Times(AtLeast(0)) | 423 EXPECT_CALL(*gl_, GetError()).Times(AtLeast(0)) |
| 470 .WillRepeatedly( | 424 .WillRepeatedly( |
| 471 Invoke(&gl_fake_queries_, &GlFakeQueries::GetError)); | 425 Invoke(&gl_fake_queries_, &GlFakeQueries::GetError)); |
| 472 | 426 |
| 473 const std::string category_name("trace_category"); | 427 const std::string category_name("trace_category"); |
| 474 const std::string trace_name("trace_test"); | 428 const std::string trace_name("trace_test"); |
| 475 const int64 offset_time = 3231; | 429 const int64 offset_time = 3231; |
| 476 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; | 430 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; |
| 477 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; | 431 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; |
| 478 const int64 expect_start_time = | 432 const int64 expect_start_time = |
| 479 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + | 433 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + |
| 480 offset_time; | 434 offset_time; |
| 481 const int64 expect_end_time = | 435 const int64 expect_end_time = |
| 482 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; | 436 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; |
| 483 | 437 |
| 484 MockGLES2Decoder decoder; | 438 MockGLES2Decoder decoder; |
| 485 GPUTracerTester tracer(test_tracer_type_, &decoder); | 439 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); |
| 440 GPUTracerTester tracer(&decoder); |
| 486 tracer.SetTracingEnabled(true); | 441 tracer.SetTracingEnabled(true); |
| 487 | 442 |
| 488 tracer.SetOutputter(outputter_ref_); | 443 tracer.SetOutputter(outputter_ref_); |
| 489 tracer.SetCPUTime(cpu_time_ref_); | |
| 490 | 444 |
| 491 gl_fake_queries_.SetCurrentGLTime(start_timestamp); | 445 gl_fake_queries_.SetCurrentGLTime(start_timestamp); |
| 492 cpu_time_ref_->SetFakeCPUTime(expect_start_time); | 446 g_fakeCPUTime = expect_start_time; |
| 493 | 447 |
| 494 ASSERT_TRUE(tracer.BeginDecoding()); | 448 ASSERT_TRUE(tracer.BeginDecoding()); |
| 495 | 449 |
| 496 ExpectTraceQueryMocks(); | 450 ExpectTraceQueryMocks(); |
| 497 | 451 |
| 498 // This will test multiple marker sources which overlap one another. | 452 // This will test multiple marker sources which overlap one another. |
| 499 for (int i = 0; i < NUM_TRACER_SOURCES; ++i) { | 453 for (int i = 0; i < NUM_TRACER_SOURCES; ++i) { |
| 500 // Set times so each source has a different time. | 454 // Set times so each source has a different time. |
| 501 gl_fake_queries_.SetCurrentGLTime( | 455 gl_fake_queries_.SetCurrentGLTime( |
| 502 start_timestamp + | 456 start_timestamp + |
| 503 (i * base::Time::kNanosecondsPerMicrosecond)); | 457 (i * base::Time::kNanosecondsPerMicrosecond)); |
| 504 cpu_time_ref_->SetFakeCPUTime(expect_start_time + i); | 458 g_fakeCPUTime = expect_start_time + i; |
| 505 | 459 |
| 506 // Each trace name should be different to differentiate. | 460 // Each trace name should be different to differentiate. |
| 507 const char num_char = static_cast<char>('0' + i); | 461 const char num_char = static_cast<char>('0' + i); |
| 508 std::string source_category = category_name + num_char; | 462 std::string source_category = category_name + num_char; |
| 509 std::string source_trace_name = trace_name + num_char; | 463 std::string source_trace_name = trace_name + num_char; |
| 510 | 464 |
| 511 ExpectOutputterBeginMocks(outputter_ref_.get(), | 465 ExpectOutputterBeginMocks(outputter_ref_.get(), |
| 512 source_category, source_trace_name); | 466 source_category, source_trace_name); |
| 513 | 467 |
| 514 const GpuTracerSource source = static_cast<GpuTracerSource>(i); | 468 const GpuTracerSource source = static_cast<GpuTracerSource>(i); |
| 515 ASSERT_TRUE(tracer.Begin(source_category, source_trace_name, source)); | 469 ASSERT_TRUE(tracer.Begin(source_category, source_trace_name, source)); |
| 516 } | 470 } |
| 517 | 471 |
| 518 for (int i = 0; i < NUM_TRACER_SOURCES; ++i) { | 472 for (int i = 0; i < NUM_TRACER_SOURCES; ++i) { |
| 519 // Set times so each source has a different time. | 473 // Set times so each source has a different time. |
| 520 gl_fake_queries_.SetCurrentGLTime( | 474 gl_fake_queries_.SetCurrentGLTime( |
| 521 end_timestamp + | 475 end_timestamp + |
| 522 (i * base::Time::kNanosecondsPerMicrosecond)); | 476 (i * base::Time::kNanosecondsPerMicrosecond)); |
| 523 cpu_time_ref_->SetFakeCPUTime(expect_end_time + i); | 477 g_fakeCPUTime = expect_start_time + i; |
| 524 | 478 |
| 525 // Each trace name should be different to differentiate. | 479 // Each trace name should be different to differentiate. |
| 526 const char num_char = static_cast<char>('0' + i); | 480 const char num_char = static_cast<char>('0' + i); |
| 527 std::string source_category = category_name + num_char; | 481 std::string source_category = category_name + num_char; |
| 528 std::string source_trace_name = trace_name + num_char; | 482 std::string source_trace_name = trace_name + num_char; |
| 529 | 483 |
| 530 ExpectOutputterEndMocks(outputter_ref_.get(), source_category, | 484 ExpectOutputterEndMocks(outputter_ref_.get(), source_category, |
| 531 source_trace_name, | 485 source_trace_name, expect_start_time + i, |
| 532 expect_start_time + i, expect_end_time + i, | 486 expect_end_time + i, |
| 533 GetTracerType() != kTracerTypeInvalid); | 487 GetTimerType() != GPUTiming::kTimerTypeInvalid); |
| 534 | 488 |
| 535 const GpuTracerSource source = static_cast<GpuTracerSource>(i); | 489 const GpuTracerSource source = static_cast<GpuTracerSource>(i); |
| 536 | 490 |
| 537 // Check if the current category/name are correct for this source. | 491 // Check if the current category/name are correct for this source. |
| 538 ASSERT_EQ(source_category, tracer.CurrentCategory(source)); | 492 ASSERT_EQ(source_category, tracer.CurrentCategory(source)); |
| 539 ASSERT_EQ(source_trace_name, tracer.CurrentName(source)); | 493 ASSERT_EQ(source_trace_name, tracer.CurrentName(source)); |
| 540 | 494 |
| 541 ASSERT_TRUE(tracer.End(source)); | 495 ASSERT_TRUE(tracer.End(source)); |
| 542 } | 496 } |
| 543 | 497 |
| 544 ASSERT_TRUE(tracer.EndDecoding()); | 498 ASSERT_TRUE(tracer.EndDecoding()); |
| 545 | 499 |
| 546 outputter_ref_ = NULL; | 500 outputter_ref_ = NULL; |
| 547 cpu_time_ref_ = NULL; | |
| 548 } | 501 } |
| 549 | 502 |
| 550 void DoDisjointTest() { | 503 void DoDisjointTest() { |
| 551 // Cause a disjoint in a middle of a trace and expect no output calls. | 504 // Cause a disjoint in a middle of a trace and expect no output calls. |
| 552 ExpectTracerOffsetQueryMocks(); | 505 ExpectTracerOffsetQueryMocks(); |
| 553 | 506 |
| 554 EXPECT_CALL(*gl_, GetError()).Times(AtLeast(0)) | 507 EXPECT_CALL(*gl_, GetError()).Times(AtLeast(0)) |
| 555 .WillRepeatedly( | 508 .WillRepeatedly( |
| 556 Invoke(&gl_fake_queries_, &GlFakeQueries::GetError)); | 509 Invoke(&gl_fake_queries_, &GlFakeQueries::GetError)); |
| 557 | 510 |
| 558 const std::string category_name("trace_category"); | 511 const std::string category_name("trace_category"); |
| 559 const std::string trace_name("trace_test"); | 512 const std::string trace_name("trace_test"); |
| 560 const GpuTracerSource source = static_cast<GpuTracerSource>(0); | 513 const GpuTracerSource source = static_cast<GpuTracerSource>(0); |
| 561 const int64 offset_time = 3231; | 514 const int64 offset_time = 3231; |
| 562 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; | 515 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; |
| 563 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; | 516 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; |
| 564 const int64 expect_start_time = | 517 const int64 expect_start_time = |
| 565 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + | 518 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + |
| 566 offset_time; | 519 offset_time; |
| 567 const int64 expect_end_time = | 520 const int64 expect_end_time = |
| 568 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; | 521 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; |
| 569 | 522 |
| 570 MockGLES2Decoder decoder; | 523 MockGLES2Decoder decoder; |
| 571 GPUTracerTester tracer(test_tracer_type_, &decoder); | 524 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); |
| 525 GPUTracerTester tracer(&decoder); |
| 572 tracer.SetTracingEnabled(true); | 526 tracer.SetTracingEnabled(true); |
| 573 | 527 |
| 574 tracer.SetOutputter(outputter_ref_); | 528 tracer.SetOutputter(outputter_ref_); |
| 575 tracer.SetCPUTime(cpu_time_ref_); | |
| 576 | 529 |
| 577 gl_fake_queries_.SetCurrentGLTime(start_timestamp); | 530 gl_fake_queries_.SetCurrentGLTime(start_timestamp); |
| 578 cpu_time_ref_->SetFakeCPUTime(expect_start_time); | 531 g_fakeCPUTime = expect_start_time; |
| 579 | 532 |
| 580 ASSERT_TRUE(tracer.BeginDecoding()); | 533 ASSERT_TRUE(tracer.BeginDecoding()); |
| 581 | 534 |
| 582 ExpectTraceQueryMocks(); | 535 ExpectTraceQueryMocks(); |
| 583 | 536 |
| 584 ExpectOutputterBeginMocks(outputter_ref_.get(), | 537 ExpectOutputterBeginMocks(outputter_ref_.get(), |
| 585 category_name, trace_name); | 538 category_name, trace_name); |
| 586 ASSERT_TRUE(tracer.Begin(category_name, trace_name, source)); | 539 ASSERT_TRUE(tracer.Begin(category_name, trace_name, source)); |
| 587 | 540 |
| 588 gl_fake_queries_.SetCurrentGLTime(end_timestamp); | 541 gl_fake_queries_.SetCurrentGLTime(end_timestamp); |
| 589 cpu_time_ref_->SetFakeCPUTime(expect_end_time); | 542 g_fakeCPUTime = expect_end_time; |
| 590 gl_fake_queries_.SetDisjoint(); | 543 gl_fake_queries_.SetDisjoint(); |
| 591 | 544 |
| 592 ExpectOutputterEndMocks(outputter_ref_.get(), category_name, trace_name, | 545 ExpectOutputterEndMocks(outputter_ref_.get(), category_name, trace_name, |
| 593 expect_start_time, expect_end_time, false); | 546 expect_start_time, expect_end_time, false); |
| 594 | 547 |
| 595 ASSERT_TRUE(tracer.End(source)); | 548 ASSERT_TRUE(tracer.End(source)); |
| 596 ASSERT_TRUE(tracer.EndDecoding()); | 549 ASSERT_TRUE(tracer.EndDecoding()); |
| 597 | 550 |
| 598 outputter_ref_ = NULL; | 551 outputter_ref_ = NULL; |
| 599 cpu_time_ref_ = NULL; | |
| 600 } | 552 } |
| 601 }; | 553 }; |
| 602 | 554 |
| 603 class InvalidTimerTracerTest : public BaseGpuTracerTest { | 555 class InvalidTimerTracerTest : public BaseGpuTracerTest { |
| 604 public: | 556 public: |
| 605 InvalidTimerTracerTest() | 557 InvalidTimerTracerTest() : BaseGpuTracerTest(GPUTiming::kTimerTypeInvalid) {} |
| 606 : BaseGpuTracerTest(kTracerTypeInvalid) { | |
| 607 } | |
| 608 }; | 558 }; |
| 609 | 559 |
| 610 class GpuARBTimerTracerTest : public BaseGpuTracerTest { | 560 class GpuARBTimerTracerTest : public BaseGpuTracerTest { |
| 611 public: | 561 public: |
| 612 GpuARBTimerTracerTest() | 562 GpuARBTimerTracerTest() : BaseGpuTracerTest(GPUTiming::kTimerTypeARB) {} |
| 613 : BaseGpuTracerTest(kTracerTypeARBTimer) { | |
| 614 } | |
| 615 }; | 563 }; |
| 616 | 564 |
| 617 class GpuDisjointTimerTracerTest : public BaseGpuTracerTest { | 565 class GpuDisjointTimerTracerTest : public BaseGpuTracerTest { |
| 618 public: | 566 public: |
| 619 GpuDisjointTimerTracerTest() | 567 GpuDisjointTimerTracerTest() |
| 620 : BaseGpuTracerTest(kTracerTypeDisjointTimer) { | 568 : BaseGpuTracerTest(GPUTiming::kTimerTypeDisjoint) {} |
| 621 } | |
| 622 }; | 569 }; |
| 623 | 570 |
| 624 TEST_F(InvalidTimerTracerTest, InvalidTimerBasicTracerTest) { | 571 TEST_F(InvalidTimerTracerTest, InvalidTimerBasicTracerTest) { |
| 625 DoBasicTracerTest(); | 572 DoBasicTracerTest(); |
| 626 } | 573 } |
| 627 | 574 |
| 628 TEST_F(GpuARBTimerTracerTest, ARBTimerBasicTracerTest) { | 575 TEST_F(GpuARBTimerTracerTest, ARBTimerBasicTracerTest) { |
| 629 DoBasicTracerTest(); | 576 DoBasicTracerTest(); |
| 630 } | 577 } |
| 631 | 578 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 642 } | 589 } |
| 643 | 590 |
| 644 TEST_F(GpuDisjointTimerTracerTest, DisjointTimerBasicTracerMarkersTest) { | 591 TEST_F(GpuDisjointTimerTracerTest, DisjointTimerBasicTracerMarkersTest) { |
| 645 DoTracerMarkersTest(); | 592 DoTracerMarkersTest(); |
| 646 } | 593 } |
| 647 | 594 |
| 648 TEST_F(GpuDisjointTimerTracerTest, DisjointTimerDisjointTraceTest) { | 595 TEST_F(GpuDisjointTimerTracerTest, DisjointTimerDisjointTraceTest) { |
| 649 DoDisjointTest(); | 596 DoDisjointTest(); |
| 650 } | 597 } |
| 651 | 598 |
| 599 class GPUTracerTest : public GpuServiceTest { |
| 600 protected: |
| 601 void SetUp() override { |
| 602 g_fakeCPUTime = 0; |
| 603 GpuServiceTest::SetUpWithGLVersion("3.2", ""); |
| 604 decoder_.reset(new MockGLES2Decoder()); |
| 605 EXPECT_CALL(*decoder_, GetGLContext()) |
| 606 .Times(AtMost(1)) |
| 607 .WillRepeatedly(Return(GetGLContext())); |
| 608 tracer_tester_.reset(new GPUTracerTester(decoder_.get())); |
| 609 } |
| 610 |
| 611 void TearDown() override { |
| 612 tracer_tester_ = nullptr; |
| 613 decoder_ = nullptr; |
| 614 GpuServiceTest::TearDown(); |
| 615 } |
| 616 scoped_ptr<MockGLES2Decoder> decoder_; |
| 617 scoped_ptr<GPUTracerTester> tracer_tester_; |
| 618 }; |
| 619 |
| 620 TEST_F(GPUTracerTest, IsTracingTest) { |
| 621 EXPECT_FALSE(tracer_tester_->IsTracing()); |
| 622 tracer_tester_->SetTracingEnabled(true); |
| 623 EXPECT_TRUE(tracer_tester_->IsTracing()); |
| 624 } |
| 652 // Test basic functionality of the GPUTracerTester. | 625 // Test basic functionality of the GPUTracerTester. |
| 653 TEST(GPUTracerTester, IsTracingTest) { | 626 TEST_F(GPUTracerTest, DecodeTest) { |
| 654 MockGLES2Decoder decoder; | 627 ASSERT_TRUE(tracer_tester_->BeginDecoding()); |
| 655 GPUTracerTester tracer_tester(kTracerTypeInvalid, &decoder); | 628 EXPECT_FALSE(tracer_tester_->BeginDecoding()); |
| 656 EXPECT_FALSE(tracer_tester.IsTracing()); | 629 ASSERT_TRUE(tracer_tester_->EndDecoding()); |
| 657 tracer_tester.SetTracingEnabled(true); | 630 EXPECT_FALSE(tracer_tester_->EndDecoding()); |
| 658 EXPECT_TRUE(tracer_tester.IsTracing()); | |
| 659 } | 631 } |
| 660 | 632 |
| 661 TEST(GPUTracerTester, DecodeTest) { | 633 TEST_F(GPUTracerTest, TraceDuringDecodeTest) { |
| 662 MockGLES2Decoder decoder; | |
| 663 GPUTracerTester tracer_tester(kTracerTypeInvalid, &decoder); | |
| 664 ASSERT_TRUE(tracer_tester.BeginDecoding()); | |
| 665 EXPECT_FALSE(tracer_tester.BeginDecoding()); | |
| 666 ASSERT_TRUE(tracer_tester.EndDecoding()); | |
| 667 EXPECT_FALSE(tracer_tester.EndDecoding()); | |
| 668 } | |
| 669 | |
| 670 TEST(GPUTracerTester, TraceDuringDecodeTest) { | |
| 671 MockGLES2Decoder decoder; | |
| 672 GPUTracerTester tracer_tester(kTracerTypeInvalid, &decoder); | |
| 673 const std::string category_name("trace_category"); | 634 const std::string category_name("trace_category"); |
| 674 const std::string trace_name("trace_test"); | 635 const std::string trace_name("trace_test"); |
| 675 | 636 |
| 676 EXPECT_FALSE(tracer_tester.Begin(category_name, trace_name, | 637 EXPECT_FALSE( |
| 677 kTraceGroupMarker)); | 638 tracer_tester_->Begin(category_name, trace_name, kTraceGroupMarker)); |
| 678 | 639 |
| 679 ASSERT_TRUE(tracer_tester.BeginDecoding()); | 640 ASSERT_TRUE(tracer_tester_->BeginDecoding()); |
| 680 EXPECT_TRUE(tracer_tester.Begin(category_name, trace_name, | 641 EXPECT_TRUE( |
| 681 kTraceGroupMarker)); | 642 tracer_tester_->Begin(category_name, trace_name, kTraceGroupMarker)); |
| 682 ASSERT_TRUE(tracer_tester.EndDecoding()); | 643 ASSERT_TRUE(tracer_tester_->EndDecoding()); |
| 683 } | 644 } |
| 684 | 645 |
| 646 } // namespace |
| 685 } // namespace gles2 | 647 } // namespace gles2 |
| 686 } // namespace gpu | 648 } // namespace gpu |
| OLD | NEW |