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
3 // found in the LICENSE file.
6 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
7 #include "gpu/command_buffer/service/gpu_service_test.h"
8 #include "gpu/command_buffer/service/gpu_tracer.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gl/gl_context.h"
11 #include "ui/gl/gl_mock.h"
12 #include "ui/gl/gpu_timing.h"
13 #include "ui/gl/gpu_timing_fake.h"
20 using ::testing::AtMost
;
21 using ::testing::Exactly
;
22 using ::testing::Invoke
;
23 using ::testing::Return
;
25 int64 g_fakeCPUTime
= 0;
30 class MockOutputter
: public Outputter
{
33 MOCK_METHOD5(TraceDevice
,
34 void(GpuTracerSource source
,
35 const std::string
& category
, const std::string
& name
,
36 int64 start_time
, int64 end_time
));
38 MOCK_METHOD3(TraceServiceBegin
,
39 void(GpuTracerSource source
,
40 const std::string
& category
, const std::string
& name
));
42 MOCK_METHOD3(TraceServiceEnd
,
43 void(GpuTracerSource source
,
44 const std::string
& category
, const std::string
& name
));
50 class GPUTracerTester
: public GPUTracer
{
52 explicit GPUTracerTester(gles2::GLES2Decoder
* decoder
)
53 : GPUTracer(decoder
), tracing_enabled_(0) {
54 gpu_timing_client_
->SetCpuTimeForTesting(base::Bind(&FakeCpuTime
));
56 // Force tracing to be dependent on our mock variable here.
57 gpu_trace_srv_category
= &tracing_enabled_
;
58 gpu_trace_dev_category
= &tracing_enabled_
;
61 ~GPUTracerTester() override
{}
63 void SetTracingEnabled(bool enabled
) {
64 tracing_enabled_
= enabled
? 1 : 0;
67 void SetOutputter(scoped_refptr
<Outputter
> outputter
) {
68 set_outputter_
= outputter
;
72 scoped_refptr
<Outputter
> CreateOutputter(const std::string
& name
) override
{
73 if (set_outputter_
.get()) {
74 return set_outputter_
;
76 return new MockOutputter();
79 void PostTask() override
{
80 // Process synchronously.
84 unsigned char tracing_enabled_
;
86 scoped_refptr
<Outputter
> set_outputter_
;
89 class BaseGpuTest
: public GpuServiceTest
{
91 explicit BaseGpuTest(gfx::GPUTiming::TimerType test_timer_type
)
92 : test_timer_type_(test_timer_type
) {
96 void SetUp() override
{
98 const char* gl_version
= "3.2";
99 const char* extensions
= "";
100 if (GetTimerType() == gfx::GPUTiming::kTimerTypeEXT
) {
101 gl_version
= "opengl 2.1";
102 extensions
= "GL_EXT_timer_query";
103 } else if (GetTimerType() == gfx::GPUTiming::kTimerTypeDisjoint
) {
104 gl_version
= "opengl es 3.0";
105 extensions
= "GL_EXT_disjoint_timer_query";
106 } else if (GetTimerType() == gfx::GPUTiming::kTimerTypeARB
) {
107 // TODO(sievers): The tracer should not depend on ARB_occlusion_query.
108 // Try merge Query APIs (core, ARB, EXT) into a single binding each.
109 extensions
= "GL_ARB_timer_query GL_ARB_occlusion_query";
111 GpuServiceTest::SetUpWithGLVersion(gl_version
, extensions
);
113 // Disjoint check should only be called by kTracerTypeDisjointTimer type.
114 if (GetTimerType() == gfx::GPUTiming::kTimerTypeDisjoint
)
115 gl_fake_queries_
.ExpectDisjointCalls(*gl_
);
117 gl_fake_queries_
.ExpectNoDisjointCalls(*gl_
);
119 gpu_timing_client_
= GetGLContext()->CreateGPUTimingClient();
120 gpu_timing_client_
->SetCpuTimeForTesting(base::Bind(&FakeCpuTime
));
121 gl_fake_queries_
.Reset();
123 outputter_ref_
= new MockOutputter();
126 void TearDown() override
{
127 outputter_ref_
= NULL
;
128 gpu_timing_client_
= NULL
;
130 gl_fake_queries_
.Reset();
131 GpuServiceTest::TearDown();
134 void ExpectTraceQueryMocks() {
135 if (gpu_timing_client_
->IsAvailable()) {
136 // Delegate query APIs used by GPUTrace to a GlFakeQueries
137 const bool elapsed
= (GetTimerType() == gfx::GPUTiming::kTimerTypeEXT
);
138 gl_fake_queries_
.ExpectGPUTimerQuery(*gl_
, elapsed
);
142 void ExpectOutputterBeginMocks(MockOutputter
* outputter
,
143 GpuTracerSource source
,
144 const std::string
& category
,
145 const std::string
& name
) {
146 EXPECT_CALL(*outputter
,
147 TraceServiceBegin(source
, category
, name
));
150 void ExpectOutputterEndMocks(MockOutputter
* outputter
,
151 GpuTracerSource source
,
152 const std::string
& category
,
153 const std::string
& name
, int64 expect_start_time
,
154 int64 expect_end_time
,
158 EXPECT_CALL(*outputter
,
159 TraceServiceEnd(source
, category
, name
));
163 EXPECT_CALL(*outputter
,
164 TraceDevice(source
, category
, name
,
165 expect_start_time
, expect_end_time
))
168 EXPECT_CALL(*outputter
, TraceDevice(source
, category
, name
,
169 expect_start_time
, expect_end_time
))
174 void ExpectDisjointOutputMocks(MockOutputter
* outputter
,
175 int64 expect_start_time
,
176 int64 expect_end_time
) {
177 EXPECT_CALL(*outputter
,
178 TraceDevice(kTraceDisjoint
, "DisjointEvent", _
,
179 expect_start_time
, expect_end_time
))
183 void ExpectNoDisjointOutputMocks(MockOutputter
* outputter
) {
184 EXPECT_CALL(*outputter
,
185 TraceDevice(kTraceDisjoint
, "DisjointEvent", _
, _
, _
))
189 void ExpectOutputterMocks(MockOutputter
* outputter
,
190 bool tracing_service
,
192 GpuTracerSource source
,
193 const std::string
& category
,
194 const std::string
& name
, int64 expect_start_time
,
195 int64 expect_end_time
) {
197 ExpectOutputterBeginMocks(outputter
, source
, category
, name
);
198 const bool valid_timer
= tracing_device
&&
199 gpu_timing_client_
->IsAvailable();
200 ExpectOutputterEndMocks(outputter
, source
, category
, name
,
201 expect_start_time
, expect_end_time
,
202 tracing_service
, valid_timer
);
205 void ExpectTracerOffsetQueryMocks() {
206 if (GetTimerType() != gfx::GPUTiming::kTimerTypeARB
) {
207 gl_fake_queries_
.ExpectNoOffsetCalculationQuery(*gl_
);
209 gl_fake_queries_
.ExpectOffsetCalculationQuery(*gl_
);
213 gfx::GPUTiming::TimerType
GetTimerType() { return test_timer_type_
; }
215 gfx::GPUTiming::TimerType test_timer_type_
;
216 gfx::GPUTimingFake gl_fake_queries_
;
218 scoped_refptr
<gfx::GPUTimingClient
> gpu_timing_client_
;
219 scoped_refptr
<MockOutputter
> outputter_ref_
;
222 // Test GPUTrace calls all the correct gl calls.
223 class BaseGpuTraceTest
: public BaseGpuTest
{
225 explicit BaseGpuTraceTest(gfx::GPUTiming::TimerType test_timer_type
)
226 : BaseGpuTest(test_timer_type
) {}
228 void DoTraceTest(bool tracing_service
, bool tracing_device
) {
230 const GpuTracerSource tracer_source
= kTraceCHROMIUM
;
231 const std::string
category_name("trace_category");
232 const std::string
trace_name("trace_test");
233 const int64 offset_time
= 3231;
234 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
235 const GLint64 end_timestamp
= 32 * base::Time::kNanosecondsPerMicrosecond
;
236 const int64 expect_start_time
=
237 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
239 const int64 expect_end_time
=
240 (end_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) + offset_time
;
242 ExpectOutputterMocks(outputter_ref_
.get(), tracing_service
, tracing_device
,
243 tracer_source
, category_name
, trace_name
,
244 expect_start_time
, expect_end_time
);
247 ExpectTraceQueryMocks();
249 scoped_refptr
<GPUTrace
> trace
= new GPUTrace(
250 outputter_ref_
, gpu_timing_client_
.get(), tracer_source
,
251 category_name
, trace_name
, tracing_service
, tracing_device
);
253 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
254 g_fakeCPUTime
= expect_start_time
;
257 // Shouldn't be available before End() call
258 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
);
259 g_fakeCPUTime
= expect_end_time
;
261 EXPECT_FALSE(trace
->IsAvailable());
265 // Shouldn't be available until the queries complete
266 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
-
267 base::Time::kNanosecondsPerMicrosecond
);
268 g_fakeCPUTime
= expect_end_time
- 1;
270 EXPECT_FALSE(trace
->IsAvailable());
272 // Now it should be available
273 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
);
274 g_fakeCPUTime
= expect_end_time
;
275 EXPECT_TRUE(trace
->IsAvailable());
277 // Proces should output expected Trace results to MockOutputter
280 // Destroy trace after we are done.
281 trace
->Destroy(true);
283 outputter_ref_
= NULL
;
287 class GpuARBTimerTraceTest
: public BaseGpuTraceTest
{
289 GpuARBTimerTraceTest() : BaseGpuTraceTest(gfx::GPUTiming::kTimerTypeARB
) {}
292 class GpuDisjointTimerTraceTest
: public BaseGpuTraceTest
{
294 GpuDisjointTimerTraceTest()
295 : BaseGpuTraceTest(gfx::GPUTiming::kTimerTypeDisjoint
) {}
298 TEST_F(GpuARBTimerTraceTest
, ARBTimerTraceTestOff
) {
299 DoTraceTest(false, false);
302 TEST_F(GpuARBTimerTraceTest
, ARBTimerTraceTestServiceOnly
) {
303 DoTraceTest(true, false);
306 TEST_F(GpuARBTimerTraceTest
, ARBTimerTraceTestDeviceOnly
) {
307 DoTraceTest(false, true);
310 TEST_F(GpuARBTimerTraceTest
, ARBTimerTraceTestBothOn
) {
311 DoTraceTest(true, true);
314 TEST_F(GpuDisjointTimerTraceTest
, DisjointTimerTraceTestOff
) {
315 DoTraceTest(false, false);
318 TEST_F(GpuDisjointTimerTraceTest
, DisjointTimerTraceTestServiceOnly
) {
319 DoTraceTest(true, false);
322 TEST_F(GpuDisjointTimerTraceTest
, DisjointTimerTraceTestDeviceOnly
) {
323 DoTraceTest(false, true);
326 TEST_F(GpuDisjointTimerTraceTest
, DisjointTimerTraceTestBothOn
) {
327 DoTraceTest(true, true);
330 // Test GPUTracer calls all the correct gl calls.
331 class BaseGpuTracerTest
: public BaseGpuTest
{
333 explicit BaseGpuTracerTest(gfx::GPUTiming::TimerType test_timer_type
)
334 : BaseGpuTest(test_timer_type
) {}
336 void DoBasicTracerTest() {
337 ExpectTracerOffsetQueryMocks();
339 MockGLES2Decoder decoder
;
340 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
341 GPUTracerTester
tracer(&decoder
);
342 tracer
.SetTracingEnabled(true);
344 tracer
.SetOutputter(outputter_ref_
);
346 ASSERT_TRUE(tracer
.BeginDecoding());
347 ASSERT_TRUE(tracer
.EndDecoding());
349 outputter_ref_
= NULL
;
352 void DoDisabledTracingTest() {
353 ExpectTracerOffsetQueryMocks();
355 const GpuTracerSource source
= static_cast<GpuTracerSource
>(0);
357 MockGLES2Decoder decoder
;
358 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
359 GPUTracerTester
tracer(&decoder
);
360 tracer
.SetTracingEnabled(false);
361 tracer
.SetOutputter(outputter_ref_
);
363 ASSERT_TRUE(tracer
.BeginDecoding());
364 ASSERT_TRUE(tracer
.Begin("disabled_category", "disabled_name", source
));
365 ASSERT_TRUE(tracer
.End(source
));
366 ASSERT_TRUE(tracer
.EndDecoding());
369 void DoTracerMarkersTest() {
370 ExpectTracerOffsetQueryMocks();
371 gl_fake_queries_
.ExpectGetErrorCalls(*gl_
);
373 const std::string
category_name("trace_category");
374 const std::string
trace_name("trace_test");
375 const int64 offset_time
= 3231;
376 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
377 const GLint64 end_timestamp
= 32 * base::Time::kNanosecondsPerMicrosecond
;
378 const int64 expect_start_time
=
379 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
381 const int64 expect_end_time
=
382 (end_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) + offset_time
;
384 MockGLES2Decoder decoder
;
385 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
386 GPUTracerTester
tracer(&decoder
);
387 tracer
.SetTracingEnabled(true);
389 tracer
.SetOutputter(outputter_ref_
);
391 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
392 g_fakeCPUTime
= expect_start_time
;
394 ASSERT_TRUE(tracer
.BeginDecoding());
396 ExpectTraceQueryMocks();
398 // This will test multiple marker sources which overlap one another.
399 for (int i
= 0; i
< NUM_TRACER_SOURCES
; ++i
) {
400 // Set times so each source has a different time.
401 gl_fake_queries_
.SetCurrentGLTime(
403 (i
* base::Time::kNanosecondsPerMicrosecond
));
404 g_fakeCPUTime
= expect_start_time
+ i
;
406 // Each trace name should be different to differentiate.
407 const char num_char
= static_cast<char>('0' + i
);
408 std::string source_category
= category_name
+ num_char
;
409 std::string source_trace_name
= trace_name
+ num_char
;
411 const GpuTracerSource source
= static_cast<GpuTracerSource
>(i
);
412 ExpectOutputterBeginMocks(outputter_ref_
.get(), source
,
413 source_category
, source_trace_name
);
414 ASSERT_TRUE(tracer
.Begin(source_category
, source_trace_name
, source
));
416 for (int i
= 0; i
< NUM_TRACER_SOURCES
; ++i
) {
417 // Set times so each source has a different time.
418 gl_fake_queries_
.SetCurrentGLTime(
420 (i
* base::Time::kNanosecondsPerMicrosecond
));
421 g_fakeCPUTime
= expect_end_time
+ i
;
423 // Each trace name should be different to differentiate.
424 const char num_char
= static_cast<char>('0' + i
);
425 std::string source_category
= category_name
+ num_char
;
426 std::string source_trace_name
= trace_name
+ num_char
;
428 const bool valid_timer
= gpu_timing_client_
->IsAvailable();
430 const GpuTracerSource source
= static_cast<GpuTracerSource
>(i
);
431 ExpectOutputterEndMocks(outputter_ref_
.get(), source
, source_category
,
432 source_trace_name
, expect_start_time
+ i
,
433 expect_end_time
+ i
, true, valid_timer
);
434 // Check if the current category/name are correct for this source.
435 ASSERT_EQ(source_category
, tracer
.CurrentCategory(source
));
436 ASSERT_EQ(source_trace_name
, tracer
.CurrentName(source
));
438 ASSERT_TRUE(tracer
.End(source
));
440 ASSERT_TRUE(tracer
.EndDecoding());
441 outputter_ref_
= NULL
;
444 void DoOngoingTracerMarkerTest() {
445 ExpectTracerOffsetQueryMocks();
446 gl_fake_queries_
.ExpectGetErrorCalls(*gl_
);
448 const std::string
category_name("trace_category");
449 const std::string
trace_name("trace_test");
450 const GpuTracerSource source
= static_cast<GpuTracerSource
>(0);
451 const int64 offset_time
= 3231;
452 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
453 const int64 expect_start_time
=
454 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
456 const bool valid_timer
= gpu_timing_client_
->IsAvailable();
458 MockGLES2Decoder decoder
;
459 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
460 GPUTracerTester
tracer(&decoder
);
461 tracer
.SetOutputter(outputter_ref_
);
463 // Create trace marker while traces are disabled.
464 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
465 g_fakeCPUTime
= expect_start_time
;
467 tracer
.SetTracingEnabled(false);
468 ASSERT_TRUE(tracer
.BeginDecoding());
469 ASSERT_TRUE(tracer
.Begin(category_name
, trace_name
, source
));
470 ASSERT_TRUE(tracer
.EndDecoding());
472 // Enable traces now.
473 tracer
.SetTracingEnabled(true);
474 ExpectTraceQueryMocks();
476 // trace should happen when decoding begins, at time start+1.
477 gl_fake_queries_
.SetCurrentGLTime(
479 (1 * base::Time::kNanosecondsPerMicrosecond
));
480 g_fakeCPUTime
= expect_start_time
+ 1;
481 ASSERT_TRUE(tracer
.BeginDecoding());
483 // End decoding at time start+2.
484 ExpectOutputterEndMocks(outputter_ref_
.get(), source
, category_name
,
485 trace_name
, expect_start_time
+ 1,
486 expect_start_time
+ 2, true, valid_timer
);
487 gl_fake_queries_
.SetCurrentGLTime(
489 (2 * base::Time::kNanosecondsPerMicrosecond
));
490 g_fakeCPUTime
= expect_start_time
+ 2;
491 ASSERT_TRUE(tracer
.EndDecoding());
493 // Begin decoding again at time start+3.
494 gl_fake_queries_
.SetCurrentGLTime(
496 (3 * base::Time::kNanosecondsPerMicrosecond
));
497 g_fakeCPUTime
= expect_start_time
+ 3;
498 ASSERT_TRUE(tracer
.BeginDecoding());
500 // End trace at time start+4
501 gl_fake_queries_
.SetCurrentGLTime(
503 (4 * base::Time::kNanosecondsPerMicrosecond
));
504 g_fakeCPUTime
= expect_start_time
+ 4;
505 ExpectOutputterEndMocks(outputter_ref_
.get(), source
, category_name
,
506 trace_name
, expect_start_time
+ 3,
507 expect_start_time
+ 4, true, valid_timer
);
508 ASSERT_TRUE(tracer
.End(source
));
510 // Increment time before we end decoding to test trace does not stop here.
511 gl_fake_queries_
.SetCurrentGLTime(
513 (5 * base::Time::kNanosecondsPerMicrosecond
));
514 g_fakeCPUTime
= expect_start_time
+ 5;
515 ASSERT_TRUE(tracer
.EndDecoding());
518 void DoDisjointTest() {
519 // Cause a disjoint in a middle of a trace and expect no output calls.
520 ExpectTracerOffsetQueryMocks();
521 gl_fake_queries_
.ExpectGetErrorCalls(*gl_
);
523 const std::string
category_name("trace_category");
524 const std::string
trace_name("trace_test");
525 const GpuTracerSource source
= static_cast<GpuTracerSource
>(0);
526 const int64 offset_time
= 3231;
527 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
528 const GLint64 end_timestamp
= 32 * base::Time::kNanosecondsPerMicrosecond
;
529 const int64 expect_start_time
=
530 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
532 const int64 expect_end_time
=
533 (end_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) + offset_time
;
535 MockGLES2Decoder decoder
;
536 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
537 GPUTracerTester
tracer(&decoder
);
538 tracer
.SetTracingEnabled(true);
540 tracer
.SetOutputter(outputter_ref_
);
542 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
543 g_fakeCPUTime
= expect_start_time
;
545 ASSERT_TRUE(tracer
.BeginDecoding());
547 ExpectTraceQueryMocks();
549 ExpectOutputterBeginMocks(outputter_ref_
.get(), source
,
550 category_name
, trace_name
);
551 ASSERT_TRUE(tracer
.Begin(category_name
, trace_name
, source
));
553 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
);
554 g_fakeCPUTime
= expect_end_time
;
556 // Create GPUTimingClient to make sure disjoint value is correct. This
557 // should not interfere with the tracer's disjoint value.
558 scoped_refptr
<gfx::GPUTimingClient
> disjoint_client
=
559 GetGLContext()->CreateGPUTimingClient();
561 // We assert here based on the disjoint_client because if disjoints are not
562 // working properly there is no point testing the tracer output.
563 ASSERT_FALSE(disjoint_client
->CheckAndResetTimerErrors());
564 gl_fake_queries_
.SetDisjoint();
565 ASSERT_TRUE(disjoint_client
->CheckAndResetTimerErrors());
567 ExpectDisjointOutputMocks(outputter_ref_
.get(),
568 expect_start_time
, expect_end_time
);
570 ExpectOutputterEndMocks(outputter_ref_
.get(), source
,
571 category_name
, trace_name
,
572 expect_start_time
, expect_end_time
, true, false);
574 ASSERT_TRUE(tracer
.End(source
));
575 ASSERT_TRUE(tracer
.EndDecoding());
577 outputter_ref_
= NULL
;
580 void DoOutsideDisjointTest() {
581 ExpectTracerOffsetQueryMocks();
582 gl_fake_queries_
.ExpectGetErrorCalls(*gl_
);
584 const std::string
category_name("trace_category");
585 const std::string
trace_name("trace_test");
586 const GpuTracerSource source
= static_cast<GpuTracerSource
>(0);
587 const int64 offset_time
= 3231;
588 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
589 const GLint64 end_timestamp
= 32 * base::Time::kNanosecondsPerMicrosecond
;
590 const int64 expect_start_time
=
591 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
593 const int64 expect_end_time
=
594 (end_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) + offset_time
;
596 MockGLES2Decoder decoder
;
597 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
598 EXPECT_CALL(decoder
, MakeCurrent()).WillRepeatedly(Return(true));
599 GPUTracerTester
tracer(&decoder
);
600 tracer
.SetOutputter(outputter_ref_
);
602 // Start a trace before tracing is enabled.
603 tracer
.SetTracingEnabled(false);
604 ASSERT_TRUE(tracer
.BeginDecoding());
605 ASSERT_TRUE(tracer
.Begin(category_name
, trace_name
, source
));
606 ASSERT_TRUE(tracer
.EndDecoding());
608 // Enabling traces now, trace should be ongoing.
609 tracer
.SetTracingEnabled(true);
610 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
611 g_fakeCPUTime
= expect_start_time
;
613 // Disjoints before we start tracing anything should not do anything.
614 ExpectNoDisjointOutputMocks(outputter_ref_
.get());
615 gl_fake_queries_
.SetDisjoint();
617 ExpectTraceQueryMocks();
618 ExpectOutputterBeginMocks(outputter_ref_
.get(), source
,
619 category_name
, trace_name
);
620 ASSERT_TRUE(tracer
.BeginDecoding());
622 // Set times so each source has a different time.
623 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
);
624 g_fakeCPUTime
= expect_end_time
;
626 ExpectOutputterEndMocks(outputter_ref_
.get(), source
, category_name
,
627 trace_name
, expect_start_time
,
628 expect_end_time
, true, true);
630 ASSERT_TRUE(tracer
.End(source
));
631 ASSERT_TRUE(tracer
.EndDecoding());
635 class InvalidTimerTracerTest
: public BaseGpuTracerTest
{
637 InvalidTimerTracerTest()
638 : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeInvalid
) {}
641 class GpuEXTTimerTracerTest
: public BaseGpuTracerTest
{
643 GpuEXTTimerTracerTest() : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeEXT
) {}
646 class GpuARBTimerTracerTest
: public BaseGpuTracerTest
{
648 GpuARBTimerTracerTest()
649 : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeARB
) {}
652 class GpuDisjointTimerTracerTest
: public BaseGpuTracerTest
{
654 GpuDisjointTimerTracerTest()
655 : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeDisjoint
) {}
658 TEST_F(InvalidTimerTracerTest
, InvalidTimerBasicTracerTest
) {
662 TEST_F(GpuEXTTimerTracerTest
, EXTTimerBasicTracerTest
) {
666 TEST_F(GpuARBTimerTracerTest
, ARBTimerBasicTracerTest
) {
670 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerBasicTracerTest
) {
674 TEST_F(InvalidTimerTracerTest
, InvalidTimerDisabledTest
) {
675 DoDisabledTracingTest();
678 TEST_F(GpuEXTTimerTracerTest
, EXTTimerDisabledTest
) {
679 DoDisabledTracingTest();
682 TEST_F(GpuARBTimerTracerTest
, ARBTimerDisabledTest
) {
683 DoDisabledTracingTest();
686 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerDisabledTest
) {
687 DoDisabledTracingTest();
690 TEST_F(InvalidTimerTracerTest
, InvalidTimerTracerMarkersTest
) {
691 DoTracerMarkersTest();
694 TEST_F(GpuEXTTimerTracerTest
, EXTTimerTracerMarkersTest
) {
695 DoTracerMarkersTest();
698 TEST_F(GpuARBTimerTracerTest
, ARBTimerTracerMarkersTest
) {
699 DoTracerMarkersTest();
702 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerBasicTracerMarkersTest
) {
703 DoTracerMarkersTest();
706 TEST_F(InvalidTimerTracerTest
, InvalidTimerOngoingTracerMarkersTest
) {
707 DoOngoingTracerMarkerTest();
710 TEST_F(GpuEXTTimerTracerTest
, EXTTimerOngoingTracerMarkersTest
) {
711 DoOngoingTracerMarkerTest();
714 TEST_F(GpuARBTimerTracerTest
, ARBTimerBasicOngoingTracerMarkersTest
) {
715 DoOngoingTracerMarkerTest();
718 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerOngoingTracerMarkersTest
) {
719 DoOngoingTracerMarkerTest();
722 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerDisjointTraceTest
) {
726 TEST_F(GpuDisjointTimerTracerTest
, NonrelevantDisjointTraceTest
) {
727 DoOutsideDisjointTest();
730 class GPUTracerTest
: public GpuServiceTest
{
732 void SetUp() override
{
734 GpuServiceTest::SetUpWithGLVersion("3.2", "");
735 decoder_
.reset(new MockGLES2Decoder());
736 EXPECT_CALL(*decoder_
, GetGLContext())
738 .WillRepeatedly(Return(GetGLContext()));
739 tracer_tester_
.reset(new GPUTracerTester(decoder_
.get()));
742 void TearDown() override
{
743 tracer_tester_
= nullptr;
745 GpuServiceTest::TearDown();
747 scoped_ptr
<MockGLES2Decoder
> decoder_
;
748 scoped_ptr
<GPUTracerTester
> tracer_tester_
;
751 TEST_F(GPUTracerTest
, IsTracingTest
) {
752 EXPECT_FALSE(tracer_tester_
->IsTracing());
753 tracer_tester_
->SetTracingEnabled(true);
754 EXPECT_TRUE(tracer_tester_
->IsTracing());
756 // Test basic functionality of the GPUTracerTester.
757 TEST_F(GPUTracerTest
, DecodeTest
) {
758 ASSERT_TRUE(tracer_tester_
->BeginDecoding());
759 EXPECT_FALSE(tracer_tester_
->BeginDecoding());
760 ASSERT_TRUE(tracer_tester_
->EndDecoding());
761 EXPECT_FALSE(tracer_tester_
->EndDecoding());
764 TEST_F(GPUTracerTest
, TraceDuringDecodeTest
) {
765 const std::string
category_name("trace_category");
766 const std::string
trace_name("trace_test");
769 tracer_tester_
->Begin(category_name
, trace_name
, kTraceCHROMIUM
));
771 ASSERT_TRUE(tracer_tester_
->BeginDecoding());
773 tracer_tester_
->Begin(category_name
, trace_name
, kTraceCHROMIUM
));
774 ASSERT_TRUE(tracer_tester_
->EndDecoding());
777 TEST_F(GpuDisjointTimerTracerTest
, MultipleClientsDisjointTest
) {
778 scoped_refptr
<gfx::GPUTimingClient
> client1
=
779 GetGLContext()->CreateGPUTimingClient();
780 scoped_refptr
<gfx::GPUTimingClient
> client2
=
781 GetGLContext()->CreateGPUTimingClient();
783 // Test both clients are initialized as no errors.
784 ASSERT_FALSE(client1
->CheckAndResetTimerErrors());
785 ASSERT_FALSE(client2
->CheckAndResetTimerErrors());
788 gl_fake_queries_
.SetDisjoint();
790 ASSERT_TRUE(client1
->CheckAndResetTimerErrors());
791 ASSERT_TRUE(client2
->CheckAndResetTimerErrors());
793 // Test both are now reset.
794 ASSERT_FALSE(client1
->CheckAndResetTimerErrors());
795 ASSERT_FALSE(client2
->CheckAndResetTimerErrors());
798 gl_fake_queries_
.SetDisjoint();
800 // Test new client disjoint value is cleared.
801 scoped_refptr
<gfx::GPUTimingClient
> client3
=
802 GetGLContext()->CreateGPUTimingClient();
803 ASSERT_TRUE(client1
->CheckAndResetTimerErrors());
804 ASSERT_TRUE(client2
->CheckAndResetTimerErrors());
805 ASSERT_FALSE(client3
->CheckAndResetTimerErrors());