| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" | 6 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" |
| 7 #include "gpu/command_buffer/service/gpu_service_test.h" | 7 #include "gpu/command_buffer/service/gpu_service_test.h" |
| 8 #include "gpu/command_buffer/service/gpu_tracer.h" | 8 #include "gpu/command_buffer/service/gpu_tracer.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/gl/gl_context.h" | 10 #include "ui/gl/gl_context.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 scoped_refptr<Outputter> CreateOutputter(const std::string& name) override { | 72 scoped_refptr<Outputter> CreateOutputter(const std::string& name) override { |
| 73 if (set_outputter_.get()) { | 73 if (set_outputter_.get()) { |
| 74 return set_outputter_; | 74 return set_outputter_; |
| 75 } | 75 } |
| 76 return new MockOutputter(); | 76 return new MockOutputter(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void PostTask() override { | |
| 80 // Process synchronously. | |
| 81 Process(); | |
| 82 } | |
| 83 | |
| 84 unsigned char tracing_enabled_; | 79 unsigned char tracing_enabled_; |
| 85 | |
| 86 scoped_refptr<Outputter> set_outputter_; | 80 scoped_refptr<Outputter> set_outputter_; |
| 87 }; | 81 }; |
| 88 | 82 |
| 89 class BaseGpuTest : public GpuServiceTest { | 83 class BaseGpuTest : public GpuServiceTest { |
| 90 public: | 84 public: |
| 91 explicit BaseGpuTest(gfx::GPUTiming::TimerType test_timer_type) | 85 explicit BaseGpuTest(gfx::GPUTiming::TimerType test_timer_type) |
| 92 : test_timer_type_(test_timer_type) { | 86 : test_timer_type_(test_timer_type) { |
| 93 } | 87 } |
| 94 | 88 |
| 95 protected: | 89 protected: |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 end_timestamp + | 413 end_timestamp + |
| 420 (i * base::Time::kNanosecondsPerMicrosecond)); | 414 (i * base::Time::kNanosecondsPerMicrosecond)); |
| 421 g_fakeCPUTime = expect_end_time + i; | 415 g_fakeCPUTime = expect_end_time + i; |
| 422 | 416 |
| 423 // Each trace name should be different to differentiate. | 417 // Each trace name should be different to differentiate. |
| 424 const char num_char = static_cast<char>('0' + i); | 418 const char num_char = static_cast<char>('0' + i); |
| 425 std::string source_category = category_name + num_char; | 419 std::string source_category = category_name + num_char; |
| 426 std::string source_trace_name = trace_name + num_char; | 420 std::string source_trace_name = trace_name + num_char; |
| 427 | 421 |
| 428 const bool valid_timer = gpu_timing_client_->IsAvailable(); | 422 const bool valid_timer = gpu_timing_client_->IsAvailable(); |
| 429 | |
| 430 const GpuTracerSource source = static_cast<GpuTracerSource>(i); | 423 const GpuTracerSource source = static_cast<GpuTracerSource>(i); |
| 431 ExpectOutputterEndMocks(outputter_ref_.get(), source, source_category, | 424 ExpectOutputterEndMocks(outputter_ref_.get(), source, source_category, |
| 432 source_trace_name, expect_start_time + i, | 425 source_trace_name, expect_start_time + i, |
| 433 expect_end_time + i, true, valid_timer); | 426 expect_end_time + i, true, valid_timer); |
| 434 // Check if the current category/name are correct for this source. | 427 // Check if the current category/name are correct for this source. |
| 435 ASSERT_EQ(source_category, tracer.CurrentCategory(source)); | 428 ASSERT_EQ(source_category, tracer.CurrentCategory(source)); |
| 436 ASSERT_EQ(source_trace_name, tracer.CurrentName(source)); | 429 ASSERT_EQ(source_trace_name, tracer.CurrentName(source)); |
| 437 | 430 |
| 438 ASSERT_TRUE(tracer.End(source)); | 431 ASSERT_TRUE(tracer.End(source)); |
| 439 } | 432 } |
| 440 ASSERT_TRUE(tracer.EndDecoding()); | 433 ASSERT_TRUE(tracer.EndDecoding()); |
| 434 tracer.ProcessTraces(); |
| 441 outputter_ref_ = NULL; | 435 outputter_ref_ = NULL; |
| 442 } | 436 } |
| 443 | 437 |
| 444 void DoOngoingTracerMarkerTest() { | 438 void DoOngoingTracerMarkerTest() { |
| 445 ExpectTracerOffsetQueryMocks(); | 439 ExpectTracerOffsetQueryMocks(); |
| 446 gl_fake_queries_.ExpectGetErrorCalls(*gl_); | 440 gl_fake_queries_.ExpectGetErrorCalls(*gl_); |
| 447 | 441 |
| 448 const std::string category_name("trace_category"); | 442 const std::string category_name("trace_category"); |
| 449 const std::string trace_name("trace_test"); | 443 const std::string trace_name("trace_test"); |
| 450 const GpuTracerSource source = static_cast<GpuTracerSource>(0); | 444 const GpuTracerSource source = static_cast<GpuTracerSource>(0); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 trace_name, expect_start_time + 3, | 500 trace_name, expect_start_time + 3, |
| 507 expect_start_time + 4, true, valid_timer); | 501 expect_start_time + 4, true, valid_timer); |
| 508 ASSERT_TRUE(tracer.End(source)); | 502 ASSERT_TRUE(tracer.End(source)); |
| 509 | 503 |
| 510 // Increment time before we end decoding to test trace does not stop here. | 504 // Increment time before we end decoding to test trace does not stop here. |
| 511 gl_fake_queries_.SetCurrentGLTime( | 505 gl_fake_queries_.SetCurrentGLTime( |
| 512 start_timestamp + | 506 start_timestamp + |
| 513 (5 * base::Time::kNanosecondsPerMicrosecond)); | 507 (5 * base::Time::kNanosecondsPerMicrosecond)); |
| 514 g_fakeCPUTime = expect_start_time + 5; | 508 g_fakeCPUTime = expect_start_time + 5; |
| 515 ASSERT_TRUE(tracer.EndDecoding()); | 509 ASSERT_TRUE(tracer.EndDecoding()); |
| 510 tracer.ProcessTraces(); |
| 516 } | 511 } |
| 517 | 512 |
| 518 void DoDisjointTest() { | 513 void DoDisjointTest() { |
| 519 // Cause a disjoint in a middle of a trace and expect no output calls. | 514 // Cause a disjoint in a middle of a trace and expect no output calls. |
| 520 ExpectTracerOffsetQueryMocks(); | 515 ExpectTracerOffsetQueryMocks(); |
| 521 gl_fake_queries_.ExpectGetErrorCalls(*gl_); | 516 gl_fake_queries_.ExpectGetErrorCalls(*gl_); |
| 522 | 517 |
| 523 const std::string category_name("trace_category"); | 518 const std::string category_name("trace_category"); |
| 524 const std::string trace_name("trace_test"); | 519 const std::string trace_name("trace_test"); |
| 525 const GpuTracerSource source = static_cast<GpuTracerSource>(0); | 520 const GpuTracerSource source = static_cast<GpuTracerSource>(0); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 | 561 |
| 567 ExpectDisjointOutputMocks(outputter_ref_.get(), | 562 ExpectDisjointOutputMocks(outputter_ref_.get(), |
| 568 expect_start_time, expect_end_time); | 563 expect_start_time, expect_end_time); |
| 569 | 564 |
| 570 ExpectOutputterEndMocks(outputter_ref_.get(), source, | 565 ExpectOutputterEndMocks(outputter_ref_.get(), source, |
| 571 category_name, trace_name, | 566 category_name, trace_name, |
| 572 expect_start_time, expect_end_time, true, false); | 567 expect_start_time, expect_end_time, true, false); |
| 573 | 568 |
| 574 ASSERT_TRUE(tracer.End(source)); | 569 ASSERT_TRUE(tracer.End(source)); |
| 575 ASSERT_TRUE(tracer.EndDecoding()); | 570 ASSERT_TRUE(tracer.EndDecoding()); |
| 571 tracer.ProcessTraces(); |
| 576 | 572 |
| 577 outputter_ref_ = NULL; | 573 outputter_ref_ = NULL; |
| 578 } | 574 } |
| 579 | 575 |
| 580 void DoOutsideDisjointTest() { | 576 void DoOutsideDisjointTest() { |
| 581 ExpectTracerOffsetQueryMocks(); | 577 ExpectTracerOffsetQueryMocks(); |
| 582 gl_fake_queries_.ExpectGetErrorCalls(*gl_); | 578 gl_fake_queries_.ExpectGetErrorCalls(*gl_); |
| 583 | 579 |
| 584 const std::string category_name("trace_category"); | 580 const std::string category_name("trace_category"); |
| 585 const std::string trace_name("trace_test"); | 581 const std::string trace_name("trace_test"); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 // Set times so each source has a different time. | 618 // Set times so each source has a different time. |
| 623 gl_fake_queries_.SetCurrentGLTime(end_timestamp); | 619 gl_fake_queries_.SetCurrentGLTime(end_timestamp); |
| 624 g_fakeCPUTime = expect_end_time; | 620 g_fakeCPUTime = expect_end_time; |
| 625 | 621 |
| 626 ExpectOutputterEndMocks(outputter_ref_.get(), source, category_name, | 622 ExpectOutputterEndMocks(outputter_ref_.get(), source, category_name, |
| 627 trace_name, expect_start_time, | 623 trace_name, expect_start_time, |
| 628 expect_end_time, true, true); | 624 expect_end_time, true, true); |
| 629 | 625 |
| 630 ASSERT_TRUE(tracer.End(source)); | 626 ASSERT_TRUE(tracer.End(source)); |
| 631 ASSERT_TRUE(tracer.EndDecoding()); | 627 ASSERT_TRUE(tracer.EndDecoding()); |
| 628 tracer.ProcessTraces(); |
| 632 } | 629 } |
| 633 }; | 630 }; |
| 634 | 631 |
| 635 class InvalidTimerTracerTest : public BaseGpuTracerTest { | 632 class InvalidTimerTracerTest : public BaseGpuTracerTest { |
| 636 public: | 633 public: |
| 637 InvalidTimerTracerTest() | 634 InvalidTimerTracerTest() |
| 638 : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeInvalid) {} | 635 : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeInvalid) {} |
| 639 }; | 636 }; |
| 640 | 637 |
| 641 class GpuEXTTimerTracerTest : public BaseGpuTracerTest { | 638 class GpuEXTTimerTracerTest : public BaseGpuTracerTest { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 scoped_refptr<gfx::GPUTimingClient> client3 = | 798 scoped_refptr<gfx::GPUTimingClient> client3 = |
| 802 GetGLContext()->CreateGPUTimingClient(); | 799 GetGLContext()->CreateGPUTimingClient(); |
| 803 ASSERT_TRUE(client1->CheckAndResetTimerErrors()); | 800 ASSERT_TRUE(client1->CheckAndResetTimerErrors()); |
| 804 ASSERT_TRUE(client2->CheckAndResetTimerErrors()); | 801 ASSERT_TRUE(client2->CheckAndResetTimerErrors()); |
| 805 ASSERT_FALSE(client3->CheckAndResetTimerErrors()); | 802 ASSERT_FALSE(client3->CheckAndResetTimerErrors()); |
| 806 } | 803 } |
| 807 | 804 |
| 808 } // namespace | 805 } // namespace |
| 809 } // namespace gles2 | 806 } // namespace gles2 |
| 810 } // namespace gpu | 807 } // namespace gpu |
| OLD | NEW |