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 <stdint.h> |
| 6 |
5 #include "base/bind.h" | 7 #include "base/bind.h" |
6 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" | 8 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" |
7 #include "gpu/command_buffer/service/gpu_service_test.h" | 9 #include "gpu/command_buffer/service/gpu_service_test.h" |
8 #include "gpu/command_buffer/service/gpu_tracer.h" | 10 #include "gpu/command_buffer/service/gpu_tracer.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
11 #include "ui/gl/gl_mock.h" | 13 #include "ui/gl/gl_mock.h" |
12 #include "ui/gl/gpu_timing.h" | 14 #include "ui/gl/gpu_timing.h" |
13 #include "ui/gl/gpu_timing_fake.h" | 15 #include "ui/gl/gpu_timing_fake.h" |
14 | 16 |
15 namespace gpu { | 17 namespace gpu { |
16 namespace gles2 { | 18 namespace gles2 { |
17 namespace { | 19 namespace { |
18 | 20 |
19 using ::testing::_; | 21 using ::testing::_; |
20 using ::testing::AtMost; | 22 using ::testing::AtMost; |
21 using ::testing::Exactly; | 23 using ::testing::Exactly; |
22 using ::testing::Invoke; | 24 using ::testing::Invoke; |
23 using ::testing::Return; | 25 using ::testing::Return; |
24 | 26 |
25 int64 g_fakeCPUTime = 0; | 27 int64_t g_fakeCPUTime = 0; |
26 int64 FakeCpuTime() { | 28 int64_t FakeCpuTime() { |
27 return g_fakeCPUTime; | 29 return g_fakeCPUTime; |
28 } | 30 } |
29 | 31 |
30 class MockOutputter : public Outputter { | 32 class MockOutputter : public Outputter { |
31 public: | 33 public: |
32 MockOutputter() {} | 34 MockOutputter() {} |
33 MOCK_METHOD5(TraceDevice, | 35 MOCK_METHOD5(TraceDevice, |
34 void(GpuTracerSource source, | 36 void(GpuTracerSource source, |
35 const std::string& category, const std::string& name, | 37 const std::string& category, |
36 int64 start_time, int64 end_time)); | 38 const std::string& name, |
| 39 int64_t start_time, |
| 40 int64_t end_time)); |
37 | 41 |
38 MOCK_METHOD3(TraceServiceBegin, | 42 MOCK_METHOD3(TraceServiceBegin, |
39 void(GpuTracerSource source, | 43 void(GpuTracerSource source, |
40 const std::string& category, const std::string& name)); | 44 const std::string& category, const std::string& name)); |
41 | 45 |
42 MOCK_METHOD3(TraceServiceEnd, | 46 MOCK_METHOD3(TraceServiceEnd, |
43 void(GpuTracerSource source, | 47 void(GpuTracerSource source, |
44 const std::string& category, const std::string& name)); | 48 const std::string& category, const std::string& name)); |
45 | 49 |
46 protected: | 50 protected: |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 GpuTracerSource source, | 141 GpuTracerSource source, |
138 const std::string& category, | 142 const std::string& category, |
139 const std::string& name) { | 143 const std::string& name) { |
140 EXPECT_CALL(*outputter, | 144 EXPECT_CALL(*outputter, |
141 TraceServiceBegin(source, category, name)); | 145 TraceServiceBegin(source, category, name)); |
142 } | 146 } |
143 | 147 |
144 void ExpectOutputterEndMocks(MockOutputter* outputter, | 148 void ExpectOutputterEndMocks(MockOutputter* outputter, |
145 GpuTracerSource source, | 149 GpuTracerSource source, |
146 const std::string& category, | 150 const std::string& category, |
147 const std::string& name, int64 expect_start_time, | 151 const std::string& name, |
148 int64 expect_end_time, | 152 int64_t expect_start_time, |
| 153 int64_t expect_end_time, |
149 bool trace_service, | 154 bool trace_service, |
150 bool trace_device) { | 155 bool trace_device) { |
151 if (trace_service) { | 156 if (trace_service) { |
152 EXPECT_CALL(*outputter, | 157 EXPECT_CALL(*outputter, |
153 TraceServiceEnd(source, category, name)); | 158 TraceServiceEnd(source, category, name)); |
154 } | 159 } |
155 | 160 |
156 if (trace_device) { | 161 if (trace_device) { |
157 EXPECT_CALL(*outputter, | 162 EXPECT_CALL(*outputter, |
158 TraceDevice(source, category, name, | 163 TraceDevice(source, category, name, |
159 expect_start_time, expect_end_time)) | 164 expect_start_time, expect_end_time)) |
160 .Times(Exactly(1)); | 165 .Times(Exactly(1)); |
161 } else { | 166 } else { |
162 EXPECT_CALL(*outputter, TraceDevice(source, category, name, | 167 EXPECT_CALL(*outputter, TraceDevice(source, category, name, |
163 expect_start_time, expect_end_time)) | 168 expect_start_time, expect_end_time)) |
164 .Times(Exactly(0)); | 169 .Times(Exactly(0)); |
165 } | 170 } |
166 } | 171 } |
167 | 172 |
168 void ExpectDisjointOutputMocks(MockOutputter* outputter, | 173 void ExpectDisjointOutputMocks(MockOutputter* outputter, |
169 int64 expect_start_time, | 174 int64_t expect_start_time, |
170 int64 expect_end_time) { | 175 int64_t expect_end_time) { |
171 EXPECT_CALL(*outputter, | 176 EXPECT_CALL(*outputter, |
172 TraceDevice(kTraceDisjoint, "DisjointEvent", _, | 177 TraceDevice(kTraceDisjoint, "DisjointEvent", _, |
173 expect_start_time, expect_end_time)) | 178 expect_start_time, expect_end_time)) |
174 .Times(Exactly(1)); | 179 .Times(Exactly(1)); |
175 } | 180 } |
176 | 181 |
177 void ExpectNoDisjointOutputMocks(MockOutputter* outputter) { | 182 void ExpectNoDisjointOutputMocks(MockOutputter* outputter) { |
178 EXPECT_CALL(*outputter, | 183 EXPECT_CALL(*outputter, |
179 TraceDevice(kTraceDisjoint, "DisjointEvent", _, _, _)) | 184 TraceDevice(kTraceDisjoint, "DisjointEvent", _, _, _)) |
180 .Times(Exactly(0)); | 185 .Times(Exactly(0)); |
181 } | 186 } |
182 | 187 |
183 void ExpectOutputterMocks(MockOutputter* outputter, | 188 void ExpectOutputterMocks(MockOutputter* outputter, |
184 bool tracing_service, | 189 bool tracing_service, |
185 bool tracing_device, | 190 bool tracing_device, |
186 GpuTracerSource source, | 191 GpuTracerSource source, |
187 const std::string& category, | 192 const std::string& category, |
188 const std::string& name, int64 expect_start_time, | 193 const std::string& name, |
189 int64 expect_end_time) { | 194 int64_t expect_start_time, |
| 195 int64_t expect_end_time) { |
190 if (tracing_service) | 196 if (tracing_service) |
191 ExpectOutputterBeginMocks(outputter, source, category, name); | 197 ExpectOutputterBeginMocks(outputter, source, category, name); |
192 const bool valid_timer = tracing_device && | 198 const bool valid_timer = tracing_device && |
193 gpu_timing_client_->IsAvailable(); | 199 gpu_timing_client_->IsAvailable(); |
194 ExpectOutputterEndMocks(outputter, source, category, name, | 200 ExpectOutputterEndMocks(outputter, source, category, name, |
195 expect_start_time, expect_end_time, | 201 expect_start_time, expect_end_time, |
196 tracing_service, valid_timer); | 202 tracing_service, valid_timer); |
197 } | 203 } |
198 | 204 |
199 void ExpectTracerOffsetQueryMocks() { | 205 void ExpectTracerOffsetQueryMocks() { |
(...skipping 17 matching lines...) Expand all Loading... |
217 class BaseGpuTraceTest : public BaseGpuTest { | 223 class BaseGpuTraceTest : public BaseGpuTest { |
218 public: | 224 public: |
219 explicit BaseGpuTraceTest(gfx::GPUTiming::TimerType test_timer_type) | 225 explicit BaseGpuTraceTest(gfx::GPUTiming::TimerType test_timer_type) |
220 : BaseGpuTest(test_timer_type) {} | 226 : BaseGpuTest(test_timer_type) {} |
221 | 227 |
222 void DoTraceTest(bool tracing_service, bool tracing_device) { | 228 void DoTraceTest(bool tracing_service, bool tracing_device) { |
223 // Expected results | 229 // Expected results |
224 const GpuTracerSource tracer_source = kTraceCHROMIUM; | 230 const GpuTracerSource tracer_source = kTraceCHROMIUM; |
225 const std::string category_name("trace_category"); | 231 const std::string category_name("trace_category"); |
226 const std::string trace_name("trace_test"); | 232 const std::string trace_name("trace_test"); |
227 const int64 offset_time = 3231; | 233 const int64_t offset_time = 3231; |
228 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; | 234 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; |
229 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; | 235 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; |
230 const int64 expect_start_time = | 236 const int64_t expect_start_time = |
231 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + | 237 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + |
232 offset_time; | 238 offset_time; |
233 const int64 expect_end_time = | 239 const int64_t expect_end_time = |
234 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; | 240 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; |
235 | 241 |
236 ExpectOutputterMocks(outputter_ref_.get(), tracing_service, tracing_device, | 242 ExpectOutputterMocks(outputter_ref_.get(), tracing_service, tracing_device, |
237 tracer_source, category_name, trace_name, | 243 tracer_source, category_name, trace_name, |
238 expect_start_time, expect_end_time); | 244 expect_start_time, expect_end_time); |
239 | 245 |
240 if (tracing_device) | 246 if (tracing_device) |
241 ExpectTraceQueryMocks(); | 247 ExpectTraceQueryMocks(); |
242 | 248 |
243 scoped_refptr<GPUTrace> trace = new GPUTrace( | 249 scoped_refptr<GPUTrace> trace = new GPUTrace( |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 ASSERT_TRUE(tracer.End(source)); | 365 ASSERT_TRUE(tracer.End(source)); |
360 ASSERT_TRUE(tracer.EndDecoding()); | 366 ASSERT_TRUE(tracer.EndDecoding()); |
361 } | 367 } |
362 | 368 |
363 void DoTracerMarkersTest() { | 369 void DoTracerMarkersTest() { |
364 ExpectTracerOffsetQueryMocks(); | 370 ExpectTracerOffsetQueryMocks(); |
365 gl_fake_queries_.ExpectGetErrorCalls(*gl_); | 371 gl_fake_queries_.ExpectGetErrorCalls(*gl_); |
366 | 372 |
367 const std::string category_name("trace_category"); | 373 const std::string category_name("trace_category"); |
368 const std::string trace_name("trace_test"); | 374 const std::string trace_name("trace_test"); |
369 const int64 offset_time = 3231; | 375 const int64_t offset_time = 3231; |
370 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; | 376 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; |
371 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; | 377 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; |
372 const int64 expect_start_time = | 378 const int64_t expect_start_time = |
373 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + | 379 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + |
374 offset_time; | 380 offset_time; |
375 const int64 expect_end_time = | 381 const int64_t expect_end_time = |
376 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; | 382 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; |
377 | 383 |
378 MockGLES2Decoder decoder; | 384 MockGLES2Decoder decoder; |
379 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); | 385 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); |
380 GPUTracerTester tracer(&decoder); | 386 GPUTracerTester tracer(&decoder); |
381 tracer.SetTracingEnabled(true); | 387 tracer.SetTracingEnabled(true); |
382 | 388 |
383 tracer.SetOutputter(outputter_ref_); | 389 tracer.SetOutputter(outputter_ref_); |
384 | 390 |
385 gl_fake_queries_.SetCurrentGLTime(start_timestamp); | 391 gl_fake_queries_.SetCurrentGLTime(start_timestamp); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 outputter_ref_ = NULL; | 441 outputter_ref_ = NULL; |
436 } | 442 } |
437 | 443 |
438 void DoOngoingTracerMarkerTest() { | 444 void DoOngoingTracerMarkerTest() { |
439 ExpectTracerOffsetQueryMocks(); | 445 ExpectTracerOffsetQueryMocks(); |
440 gl_fake_queries_.ExpectGetErrorCalls(*gl_); | 446 gl_fake_queries_.ExpectGetErrorCalls(*gl_); |
441 | 447 |
442 const std::string category_name("trace_category"); | 448 const std::string category_name("trace_category"); |
443 const std::string trace_name("trace_test"); | 449 const std::string trace_name("trace_test"); |
444 const GpuTracerSource source = static_cast<GpuTracerSource>(0); | 450 const GpuTracerSource source = static_cast<GpuTracerSource>(0); |
445 const int64 offset_time = 3231; | 451 const int64_t offset_time = 3231; |
446 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; | 452 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; |
447 const int64 expect_start_time = | 453 const int64_t expect_start_time = |
448 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + | 454 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + |
449 offset_time; | 455 offset_time; |
450 const bool valid_timer = gpu_timing_client_->IsAvailable(); | 456 const bool valid_timer = gpu_timing_client_->IsAvailable(); |
451 | 457 |
452 MockGLES2Decoder decoder; | 458 MockGLES2Decoder decoder; |
453 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); | 459 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); |
454 GPUTracerTester tracer(&decoder); | 460 GPUTracerTester tracer(&decoder); |
455 tracer.SetOutputter(outputter_ref_); | 461 tracer.SetOutputter(outputter_ref_); |
456 | 462 |
457 // Create trace marker while traces are disabled. | 463 // Create trace marker while traces are disabled. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 } | 517 } |
512 | 518 |
513 void DoDisjointTest() { | 519 void DoDisjointTest() { |
514 // Cause a disjoint in a middle of a trace and expect no output calls. | 520 // Cause a disjoint in a middle of a trace and expect no output calls. |
515 ExpectTracerOffsetQueryMocks(); | 521 ExpectTracerOffsetQueryMocks(); |
516 gl_fake_queries_.ExpectGetErrorCalls(*gl_); | 522 gl_fake_queries_.ExpectGetErrorCalls(*gl_); |
517 | 523 |
518 const std::string category_name("trace_category"); | 524 const std::string category_name("trace_category"); |
519 const std::string trace_name("trace_test"); | 525 const std::string trace_name("trace_test"); |
520 const GpuTracerSource source = static_cast<GpuTracerSource>(0); | 526 const GpuTracerSource source = static_cast<GpuTracerSource>(0); |
521 const int64 offset_time = 3231; | 527 const int64_t offset_time = 3231; |
522 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; | 528 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; |
523 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; | 529 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; |
524 const int64 expect_start_time = | 530 const int64_t expect_start_time = |
525 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + | 531 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + |
526 offset_time; | 532 offset_time; |
527 const int64 expect_end_time = | 533 const int64_t expect_end_time = |
528 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; | 534 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; |
529 | 535 |
530 MockGLES2Decoder decoder; | 536 MockGLES2Decoder decoder; |
531 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); | 537 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); |
532 GPUTracerTester tracer(&decoder); | 538 GPUTracerTester tracer(&decoder); |
533 tracer.SetTracingEnabled(true); | 539 tracer.SetTracingEnabled(true); |
534 | 540 |
535 tracer.SetOutputter(outputter_ref_); | 541 tracer.SetOutputter(outputter_ref_); |
536 | 542 |
537 gl_fake_queries_.SetCurrentGLTime(start_timestamp); | 543 gl_fake_queries_.SetCurrentGLTime(start_timestamp); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 outputter_ref_ = NULL; | 579 outputter_ref_ = NULL; |
574 } | 580 } |
575 | 581 |
576 void DoOutsideDisjointTest() { | 582 void DoOutsideDisjointTest() { |
577 ExpectTracerOffsetQueryMocks(); | 583 ExpectTracerOffsetQueryMocks(); |
578 gl_fake_queries_.ExpectGetErrorCalls(*gl_); | 584 gl_fake_queries_.ExpectGetErrorCalls(*gl_); |
579 | 585 |
580 const std::string category_name("trace_category"); | 586 const std::string category_name("trace_category"); |
581 const std::string trace_name("trace_test"); | 587 const std::string trace_name("trace_test"); |
582 const GpuTracerSource source = static_cast<GpuTracerSource>(0); | 588 const GpuTracerSource source = static_cast<GpuTracerSource>(0); |
583 const int64 offset_time = 3231; | 589 const int64_t offset_time = 3231; |
584 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; | 590 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; |
585 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; | 591 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; |
586 const int64 expect_start_time = | 592 const int64_t expect_start_time = |
587 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + | 593 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + |
588 offset_time; | 594 offset_time; |
589 const int64 expect_end_time = | 595 const int64_t expect_end_time = |
590 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; | 596 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; |
591 | 597 |
592 MockGLES2Decoder decoder; | 598 MockGLES2Decoder decoder; |
593 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); | 599 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); |
594 EXPECT_CALL(decoder, MakeCurrent()).WillRepeatedly(Return(true)); | 600 EXPECT_CALL(decoder, MakeCurrent()).WillRepeatedly(Return(true)); |
595 GPUTracerTester tracer(&decoder); | 601 GPUTracerTester tracer(&decoder); |
596 tracer.SetOutputter(outputter_ref_); | 602 tracer.SetOutputter(outputter_ref_); |
597 | 603 |
598 // Start a trace before tracing is enabled. | 604 // Start a trace before tracing is enabled. |
599 tracer.SetTracingEnabled(false); | 605 tracer.SetTracingEnabled(false); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 scoped_refptr<gfx::GPUTimingClient> client3 = | 804 scoped_refptr<gfx::GPUTimingClient> client3 = |
799 GetGLContext()->CreateGPUTimingClient(); | 805 GetGLContext()->CreateGPUTimingClient(); |
800 ASSERT_TRUE(client1->CheckAndResetTimerErrors()); | 806 ASSERT_TRUE(client1->CheckAndResetTimerErrors()); |
801 ASSERT_TRUE(client2->CheckAndResetTimerErrors()); | 807 ASSERT_TRUE(client2->CheckAndResetTimerErrors()); |
802 ASSERT_FALSE(client3->CheckAndResetTimerErrors()); | 808 ASSERT_FALSE(client3->CheckAndResetTimerErrors()); |
803 } | 809 } |
804 | 810 |
805 } // namespace | 811 } // namespace |
806 } // namespace gles2 | 812 } // namespace gles2 |
807 } // namespace gpu | 813 } // namespace gpu |
OLD | NEW |