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 unsigned char tracing_enabled_
;
80 scoped_refptr
<Outputter
> set_outputter_
;
83 class BaseGpuTest
: public GpuServiceTest
{
85 explicit BaseGpuTest(gfx::GPUTiming::TimerType test_timer_type
)
86 : test_timer_type_(test_timer_type
) {
90 void SetUp() override
{
92 const char* gl_version
= "3.2";
93 const char* extensions
= "";
94 if (GetTimerType() == gfx::GPUTiming::kTimerTypeEXT
) {
95 gl_version
= "opengl 2.1";
96 extensions
= "GL_EXT_timer_query";
97 } else if (GetTimerType() == gfx::GPUTiming::kTimerTypeDisjoint
) {
98 gl_version
= "opengl es 3.0";
99 extensions
= "GL_EXT_disjoint_timer_query";
100 } else if (GetTimerType() == gfx::GPUTiming::kTimerTypeARB
) {
101 // TODO(sievers): The tracer should not depend on ARB_occlusion_query.
102 // Try merge Query APIs (core, ARB, EXT) into a single binding each.
103 extensions
= "GL_ARB_timer_query GL_ARB_occlusion_query";
105 GpuServiceTest::SetUpWithGLVersion(gl_version
, extensions
);
107 // Disjoint check should only be called by kTracerTypeDisjointTimer type.
108 if (GetTimerType() == gfx::GPUTiming::kTimerTypeDisjoint
)
109 gl_fake_queries_
.ExpectDisjointCalls(*gl_
);
111 gl_fake_queries_
.ExpectNoDisjointCalls(*gl_
);
113 gpu_timing_client_
= GetGLContext()->CreateGPUTimingClient();
114 gpu_timing_client_
->SetCpuTimeForTesting(base::Bind(&FakeCpuTime
));
115 gl_fake_queries_
.Reset();
117 outputter_ref_
= new MockOutputter();
120 void TearDown() override
{
121 outputter_ref_
= NULL
;
122 gpu_timing_client_
= NULL
;
124 gl_fake_queries_
.Reset();
125 GpuServiceTest::TearDown();
128 void ExpectTraceQueryMocks() {
129 if (gpu_timing_client_
->IsAvailable()) {
130 // Delegate query APIs used by GPUTrace to a GlFakeQueries
131 const bool elapsed
= (GetTimerType() == gfx::GPUTiming::kTimerTypeEXT
);
132 gl_fake_queries_
.ExpectGPUTimerQuery(*gl_
, elapsed
);
136 void ExpectOutputterBeginMocks(MockOutputter
* outputter
,
137 GpuTracerSource source
,
138 const std::string
& category
,
139 const std::string
& name
) {
140 EXPECT_CALL(*outputter
,
141 TraceServiceBegin(source
, category
, name
));
144 void ExpectOutputterEndMocks(MockOutputter
* outputter
,
145 GpuTracerSource source
,
146 const std::string
& category
,
147 const std::string
& name
, int64 expect_start_time
,
148 int64 expect_end_time
,
152 EXPECT_CALL(*outputter
,
153 TraceServiceEnd(source
, category
, name
));
157 EXPECT_CALL(*outputter
,
158 TraceDevice(source
, category
, name
,
159 expect_start_time
, expect_end_time
))
162 EXPECT_CALL(*outputter
, TraceDevice(source
, category
, name
,
163 expect_start_time
, expect_end_time
))
168 void ExpectDisjointOutputMocks(MockOutputter
* outputter
,
169 int64 expect_start_time
,
170 int64 expect_end_time
) {
171 EXPECT_CALL(*outputter
,
172 TraceDevice(kTraceDisjoint
, "DisjointEvent", _
,
173 expect_start_time
, expect_end_time
))
177 void ExpectNoDisjointOutputMocks(MockOutputter
* outputter
) {
178 EXPECT_CALL(*outputter
,
179 TraceDevice(kTraceDisjoint
, "DisjointEvent", _
, _
, _
))
183 void ExpectOutputterMocks(MockOutputter
* outputter
,
184 bool tracing_service
,
186 GpuTracerSource source
,
187 const std::string
& category
,
188 const std::string
& name
, int64 expect_start_time
,
189 int64 expect_end_time
) {
191 ExpectOutputterBeginMocks(outputter
, source
, category
, name
);
192 const bool valid_timer
= tracing_device
&&
193 gpu_timing_client_
->IsAvailable();
194 ExpectOutputterEndMocks(outputter
, source
, category
, name
,
195 expect_start_time
, expect_end_time
,
196 tracing_service
, valid_timer
);
199 void ExpectTracerOffsetQueryMocks() {
200 if (GetTimerType() != gfx::GPUTiming::kTimerTypeARB
) {
201 gl_fake_queries_
.ExpectNoOffsetCalculationQuery(*gl_
);
203 gl_fake_queries_
.ExpectOffsetCalculationQuery(*gl_
);
207 gfx::GPUTiming::TimerType
GetTimerType() { return test_timer_type_
; }
209 gfx::GPUTiming::TimerType test_timer_type_
;
210 gfx::GPUTimingFake gl_fake_queries_
;
212 scoped_refptr
<gfx::GPUTimingClient
> gpu_timing_client_
;
213 scoped_refptr
<MockOutputter
> outputter_ref_
;
216 // Test GPUTrace calls all the correct gl calls.
217 class BaseGpuTraceTest
: public BaseGpuTest
{
219 explicit BaseGpuTraceTest(gfx::GPUTiming::TimerType test_timer_type
)
220 : BaseGpuTest(test_timer_type
) {}
222 void DoTraceTest(bool tracing_service
, bool tracing_device
) {
224 const GpuTracerSource tracer_source
= kTraceCHROMIUM
;
225 const std::string
category_name("trace_category");
226 const std::string
trace_name("trace_test");
227 const int64 offset_time
= 3231;
228 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
229 const GLint64 end_timestamp
= 32 * base::Time::kNanosecondsPerMicrosecond
;
230 const int64 expect_start_time
=
231 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
233 const int64 expect_end_time
=
234 (end_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) + offset_time
;
236 ExpectOutputterMocks(outputter_ref_
.get(), tracing_service
, tracing_device
,
237 tracer_source
, category_name
, trace_name
,
238 expect_start_time
, expect_end_time
);
241 ExpectTraceQueryMocks();
243 scoped_refptr
<GPUTrace
> trace
= new GPUTrace(
244 outputter_ref_
, gpu_timing_client_
.get(), tracer_source
,
245 category_name
, trace_name
, tracing_service
, tracing_device
);
247 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
248 g_fakeCPUTime
= expect_start_time
;
251 // Shouldn't be available before End() call
252 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
);
253 g_fakeCPUTime
= expect_end_time
;
255 EXPECT_FALSE(trace
->IsAvailable());
259 // Shouldn't be available until the queries complete
260 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
-
261 base::Time::kNanosecondsPerMicrosecond
);
262 g_fakeCPUTime
= expect_end_time
- 1;
264 EXPECT_FALSE(trace
->IsAvailable());
266 // Now it should be available
267 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
);
268 g_fakeCPUTime
= expect_end_time
;
269 EXPECT_TRUE(trace
->IsAvailable());
271 // Proces should output expected Trace results to MockOutputter
274 // Destroy trace after we are done.
275 trace
->Destroy(true);
277 outputter_ref_
= NULL
;
281 class GpuARBTimerTraceTest
: public BaseGpuTraceTest
{
283 GpuARBTimerTraceTest() : BaseGpuTraceTest(gfx::GPUTiming::kTimerTypeARB
) {}
286 class GpuDisjointTimerTraceTest
: public BaseGpuTraceTest
{
288 GpuDisjointTimerTraceTest()
289 : BaseGpuTraceTest(gfx::GPUTiming::kTimerTypeDisjoint
) {}
292 TEST_F(GpuARBTimerTraceTest
, ARBTimerTraceTestOff
) {
293 DoTraceTest(false, false);
296 TEST_F(GpuARBTimerTraceTest
, ARBTimerTraceTestServiceOnly
) {
297 DoTraceTest(true, false);
300 TEST_F(GpuARBTimerTraceTest
, ARBTimerTraceTestDeviceOnly
) {
301 DoTraceTest(false, true);
304 TEST_F(GpuARBTimerTraceTest
, ARBTimerTraceTestBothOn
) {
305 DoTraceTest(true, true);
308 TEST_F(GpuDisjointTimerTraceTest
, DisjointTimerTraceTestOff
) {
309 DoTraceTest(false, false);
312 TEST_F(GpuDisjointTimerTraceTest
, DisjointTimerTraceTestServiceOnly
) {
313 DoTraceTest(true, false);
316 TEST_F(GpuDisjointTimerTraceTest
, DisjointTimerTraceTestDeviceOnly
) {
317 DoTraceTest(false, true);
320 TEST_F(GpuDisjointTimerTraceTest
, DisjointTimerTraceTestBothOn
) {
321 DoTraceTest(true, true);
324 // Test GPUTracer calls all the correct gl calls.
325 class BaseGpuTracerTest
: public BaseGpuTest
{
327 explicit BaseGpuTracerTest(gfx::GPUTiming::TimerType test_timer_type
)
328 : BaseGpuTest(test_timer_type
) {}
330 void DoBasicTracerTest() {
331 ExpectTracerOffsetQueryMocks();
333 MockGLES2Decoder decoder
;
334 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
335 GPUTracerTester
tracer(&decoder
);
336 tracer
.SetTracingEnabled(true);
338 tracer
.SetOutputter(outputter_ref_
);
340 ASSERT_TRUE(tracer
.BeginDecoding());
341 ASSERT_TRUE(tracer
.EndDecoding());
343 outputter_ref_
= NULL
;
346 void DoDisabledTracingTest() {
347 ExpectTracerOffsetQueryMocks();
349 const GpuTracerSource source
= static_cast<GpuTracerSource
>(0);
351 MockGLES2Decoder decoder
;
352 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
353 GPUTracerTester
tracer(&decoder
);
354 tracer
.SetTracingEnabled(false);
355 tracer
.SetOutputter(outputter_ref_
);
357 ASSERT_TRUE(tracer
.BeginDecoding());
358 ASSERT_TRUE(tracer
.Begin("disabled_category", "disabled_name", source
));
359 ASSERT_TRUE(tracer
.End(source
));
360 ASSERT_TRUE(tracer
.EndDecoding());
363 void DoTracerMarkersTest() {
364 ExpectTracerOffsetQueryMocks();
365 gl_fake_queries_
.ExpectGetErrorCalls(*gl_
);
367 const std::string
category_name("trace_category");
368 const std::string
trace_name("trace_test");
369 const int64 offset_time
= 3231;
370 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
371 const GLint64 end_timestamp
= 32 * base::Time::kNanosecondsPerMicrosecond
;
372 const int64 expect_start_time
=
373 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
375 const int64 expect_end_time
=
376 (end_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) + offset_time
;
378 MockGLES2Decoder decoder
;
379 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
380 GPUTracerTester
tracer(&decoder
);
381 tracer
.SetTracingEnabled(true);
383 tracer
.SetOutputter(outputter_ref_
);
385 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
386 g_fakeCPUTime
= expect_start_time
;
388 ASSERT_TRUE(tracer
.BeginDecoding());
390 ExpectTraceQueryMocks();
392 // This will test multiple marker sources which overlap one another.
393 for (int i
= 0; i
< NUM_TRACER_SOURCES
; ++i
) {
394 // Set times so each source has a different time.
395 gl_fake_queries_
.SetCurrentGLTime(
397 (i
* base::Time::kNanosecondsPerMicrosecond
));
398 g_fakeCPUTime
= expect_start_time
+ i
;
400 // Each trace name should be different to differentiate.
401 const char num_char
= static_cast<char>('0' + i
);
402 std::string source_category
= category_name
+ num_char
;
403 std::string source_trace_name
= trace_name
+ num_char
;
405 const GpuTracerSource source
= static_cast<GpuTracerSource
>(i
);
406 ExpectOutputterBeginMocks(outputter_ref_
.get(), source
,
407 source_category
, source_trace_name
);
408 ASSERT_TRUE(tracer
.Begin(source_category
, source_trace_name
, source
));
410 for (int i
= 0; i
< NUM_TRACER_SOURCES
; ++i
) {
411 // Set times so each source has a different time.
412 gl_fake_queries_
.SetCurrentGLTime(
414 (i
* base::Time::kNanosecondsPerMicrosecond
));
415 g_fakeCPUTime
= expect_end_time
+ i
;
417 // Each trace name should be different to differentiate.
418 const char num_char
= static_cast<char>('0' + i
);
419 std::string source_category
= category_name
+ num_char
;
420 std::string source_trace_name
= trace_name
+ num_char
;
422 const bool valid_timer
= gpu_timing_client_
->IsAvailable();
423 const GpuTracerSource source
= static_cast<GpuTracerSource
>(i
);
424 ExpectOutputterEndMocks(outputter_ref_
.get(), source
, source_category
,
425 source_trace_name
, expect_start_time
+ i
,
426 expect_end_time
+ i
, true, valid_timer
);
427 // Check if the current category/name are correct for this source.
428 ASSERT_EQ(source_category
, tracer
.CurrentCategory(source
));
429 ASSERT_EQ(source_trace_name
, tracer
.CurrentName(source
));
431 ASSERT_TRUE(tracer
.End(source
));
433 ASSERT_TRUE(tracer
.EndDecoding());
434 tracer
.ProcessTraces();
435 outputter_ref_
= NULL
;
438 void DoOngoingTracerMarkerTest() {
439 ExpectTracerOffsetQueryMocks();
440 gl_fake_queries_
.ExpectGetErrorCalls(*gl_
);
442 const std::string
category_name("trace_category");
443 const std::string
trace_name("trace_test");
444 const GpuTracerSource source
= static_cast<GpuTracerSource
>(0);
445 const int64 offset_time
= 3231;
446 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
447 const int64 expect_start_time
=
448 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
450 const bool valid_timer
= gpu_timing_client_
->IsAvailable();
452 MockGLES2Decoder decoder
;
453 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
454 GPUTracerTester
tracer(&decoder
);
455 tracer
.SetOutputter(outputter_ref_
);
457 // Create trace marker while traces are disabled.
458 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
459 g_fakeCPUTime
= expect_start_time
;
461 tracer
.SetTracingEnabled(false);
462 ASSERT_TRUE(tracer
.BeginDecoding());
463 ASSERT_TRUE(tracer
.Begin(category_name
, trace_name
, source
));
464 ASSERT_TRUE(tracer
.EndDecoding());
466 // Enable traces now.
467 tracer
.SetTracingEnabled(true);
468 ExpectTraceQueryMocks();
470 // trace should happen when decoding begins, at time start+1.
471 gl_fake_queries_
.SetCurrentGLTime(
473 (1 * base::Time::kNanosecondsPerMicrosecond
));
474 g_fakeCPUTime
= expect_start_time
+ 1;
475 ASSERT_TRUE(tracer
.BeginDecoding());
477 // End decoding at time start+2.
478 ExpectOutputterEndMocks(outputter_ref_
.get(), source
, category_name
,
479 trace_name
, expect_start_time
+ 1,
480 expect_start_time
+ 2, true, valid_timer
);
481 gl_fake_queries_
.SetCurrentGLTime(
483 (2 * base::Time::kNanosecondsPerMicrosecond
));
484 g_fakeCPUTime
= expect_start_time
+ 2;
485 ASSERT_TRUE(tracer
.EndDecoding());
487 // Begin decoding again at time start+3.
488 gl_fake_queries_
.SetCurrentGLTime(
490 (3 * base::Time::kNanosecondsPerMicrosecond
));
491 g_fakeCPUTime
= expect_start_time
+ 3;
492 ASSERT_TRUE(tracer
.BeginDecoding());
494 // End trace at time start+4
495 gl_fake_queries_
.SetCurrentGLTime(
497 (4 * base::Time::kNanosecondsPerMicrosecond
));
498 g_fakeCPUTime
= expect_start_time
+ 4;
499 ExpectOutputterEndMocks(outputter_ref_
.get(), source
, category_name
,
500 trace_name
, expect_start_time
+ 3,
501 expect_start_time
+ 4, true, valid_timer
);
502 ASSERT_TRUE(tracer
.End(source
));
504 // Increment time before we end decoding to test trace does not stop here.
505 gl_fake_queries_
.SetCurrentGLTime(
507 (5 * base::Time::kNanosecondsPerMicrosecond
));
508 g_fakeCPUTime
= expect_start_time
+ 5;
509 ASSERT_TRUE(tracer
.EndDecoding());
510 tracer
.ProcessTraces();
513 void DoDisjointTest() {
514 // Cause a disjoint in a middle of a trace and expect no output calls.
515 ExpectTracerOffsetQueryMocks();
516 gl_fake_queries_
.ExpectGetErrorCalls(*gl_
);
518 const std::string
category_name("trace_category");
519 const std::string
trace_name("trace_test");
520 const GpuTracerSource source
= static_cast<GpuTracerSource
>(0);
521 const int64 offset_time
= 3231;
522 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
523 const GLint64 end_timestamp
= 32 * base::Time::kNanosecondsPerMicrosecond
;
524 const int64 expect_start_time
=
525 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
527 const int64 expect_end_time
=
528 (end_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) + offset_time
;
530 MockGLES2Decoder decoder
;
531 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
532 GPUTracerTester
tracer(&decoder
);
533 tracer
.SetTracingEnabled(true);
535 tracer
.SetOutputter(outputter_ref_
);
537 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
538 g_fakeCPUTime
= expect_start_time
;
540 ASSERT_TRUE(tracer
.BeginDecoding());
542 ExpectTraceQueryMocks();
544 ExpectOutputterBeginMocks(outputter_ref_
.get(), source
,
545 category_name
, trace_name
);
546 ASSERT_TRUE(tracer
.Begin(category_name
, trace_name
, source
));
548 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
);
549 g_fakeCPUTime
= expect_end_time
;
551 // Create GPUTimingClient to make sure disjoint value is correct. This
552 // should not interfere with the tracer's disjoint value.
553 scoped_refptr
<gfx::GPUTimingClient
> disjoint_client
=
554 GetGLContext()->CreateGPUTimingClient();
556 // We assert here based on the disjoint_client because if disjoints are not
557 // working properly there is no point testing the tracer output.
558 ASSERT_FALSE(disjoint_client
->CheckAndResetTimerErrors());
559 gl_fake_queries_
.SetDisjoint();
560 ASSERT_TRUE(disjoint_client
->CheckAndResetTimerErrors());
562 ExpectDisjointOutputMocks(outputter_ref_
.get(),
563 expect_start_time
, expect_end_time
);
565 ExpectOutputterEndMocks(outputter_ref_
.get(), source
,
566 category_name
, trace_name
,
567 expect_start_time
, expect_end_time
, true, false);
569 ASSERT_TRUE(tracer
.End(source
));
570 ASSERT_TRUE(tracer
.EndDecoding());
571 tracer
.ProcessTraces();
573 outputter_ref_
= NULL
;
576 void DoOutsideDisjointTest() {
577 ExpectTracerOffsetQueryMocks();
578 gl_fake_queries_
.ExpectGetErrorCalls(*gl_
);
580 const std::string
category_name("trace_category");
581 const std::string
trace_name("trace_test");
582 const GpuTracerSource source
= static_cast<GpuTracerSource
>(0);
583 const int64 offset_time
= 3231;
584 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
585 const GLint64 end_timestamp
= 32 * base::Time::kNanosecondsPerMicrosecond
;
586 const int64 expect_start_time
=
587 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
589 const int64 expect_end_time
=
590 (end_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) + offset_time
;
592 MockGLES2Decoder decoder
;
593 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
594 EXPECT_CALL(decoder
, MakeCurrent()).WillRepeatedly(Return(true));
595 GPUTracerTester
tracer(&decoder
);
596 tracer
.SetOutputter(outputter_ref_
);
598 // Start a trace before tracing is enabled.
599 tracer
.SetTracingEnabled(false);
600 ASSERT_TRUE(tracer
.BeginDecoding());
601 ASSERT_TRUE(tracer
.Begin(category_name
, trace_name
, source
));
602 ASSERT_TRUE(tracer
.EndDecoding());
604 // Enabling traces now, trace should be ongoing.
605 tracer
.SetTracingEnabled(true);
606 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
607 g_fakeCPUTime
= expect_start_time
;
609 // Disjoints before we start tracing anything should not do anything.
610 ExpectNoDisjointOutputMocks(outputter_ref_
.get());
611 gl_fake_queries_
.SetDisjoint();
613 ExpectTraceQueryMocks();
614 ExpectOutputterBeginMocks(outputter_ref_
.get(), source
,
615 category_name
, trace_name
);
616 ASSERT_TRUE(tracer
.BeginDecoding());
618 // Set times so each source has a different time.
619 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
);
620 g_fakeCPUTime
= expect_end_time
;
622 ExpectOutputterEndMocks(outputter_ref_
.get(), source
, category_name
,
623 trace_name
, expect_start_time
,
624 expect_end_time
, true, true);
626 ASSERT_TRUE(tracer
.End(source
));
627 ASSERT_TRUE(tracer
.EndDecoding());
628 tracer
.ProcessTraces();
632 class InvalidTimerTracerTest
: public BaseGpuTracerTest
{
634 InvalidTimerTracerTest()
635 : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeInvalid
) {}
638 class GpuEXTTimerTracerTest
: public BaseGpuTracerTest
{
640 GpuEXTTimerTracerTest() : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeEXT
) {}
643 class GpuARBTimerTracerTest
: public BaseGpuTracerTest
{
645 GpuARBTimerTracerTest()
646 : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeARB
) {}
649 class GpuDisjointTimerTracerTest
: public BaseGpuTracerTest
{
651 GpuDisjointTimerTracerTest()
652 : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeDisjoint
) {}
655 TEST_F(InvalidTimerTracerTest
, InvalidTimerBasicTracerTest
) {
659 TEST_F(GpuEXTTimerTracerTest
, EXTTimerBasicTracerTest
) {
663 TEST_F(GpuARBTimerTracerTest
, ARBTimerBasicTracerTest
) {
667 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerBasicTracerTest
) {
671 TEST_F(InvalidTimerTracerTest
, InvalidTimerDisabledTest
) {
672 DoDisabledTracingTest();
675 TEST_F(GpuEXTTimerTracerTest
, EXTTimerDisabledTest
) {
676 DoDisabledTracingTest();
679 TEST_F(GpuARBTimerTracerTest
, ARBTimerDisabledTest
) {
680 DoDisabledTracingTest();
683 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerDisabledTest
) {
684 DoDisabledTracingTest();
687 TEST_F(InvalidTimerTracerTest
, InvalidTimerTracerMarkersTest
) {
688 DoTracerMarkersTest();
691 TEST_F(GpuEXTTimerTracerTest
, EXTTimerTracerMarkersTest
) {
692 DoTracerMarkersTest();
695 TEST_F(GpuARBTimerTracerTest
, ARBTimerTracerMarkersTest
) {
696 DoTracerMarkersTest();
699 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerBasicTracerMarkersTest
) {
700 DoTracerMarkersTest();
703 TEST_F(InvalidTimerTracerTest
, InvalidTimerOngoingTracerMarkersTest
) {
704 DoOngoingTracerMarkerTest();
707 TEST_F(GpuEXTTimerTracerTest
, EXTTimerOngoingTracerMarkersTest
) {
708 DoOngoingTracerMarkerTest();
711 TEST_F(GpuARBTimerTracerTest
, ARBTimerBasicOngoingTracerMarkersTest
) {
712 DoOngoingTracerMarkerTest();
715 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerOngoingTracerMarkersTest
) {
716 DoOngoingTracerMarkerTest();
719 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerDisjointTraceTest
) {
723 TEST_F(GpuDisjointTimerTracerTest
, NonrelevantDisjointTraceTest
) {
724 DoOutsideDisjointTest();
727 class GPUTracerTest
: public GpuServiceTest
{
729 void SetUp() override
{
731 GpuServiceTest::SetUpWithGLVersion("3.2", "");
732 decoder_
.reset(new MockGLES2Decoder());
733 EXPECT_CALL(*decoder_
, GetGLContext())
735 .WillRepeatedly(Return(GetGLContext()));
736 tracer_tester_
.reset(new GPUTracerTester(decoder_
.get()));
739 void TearDown() override
{
740 tracer_tester_
= nullptr;
742 GpuServiceTest::TearDown();
744 scoped_ptr
<MockGLES2Decoder
> decoder_
;
745 scoped_ptr
<GPUTracerTester
> tracer_tester_
;
748 TEST_F(GPUTracerTest
, IsTracingTest
) {
749 EXPECT_FALSE(tracer_tester_
->IsTracing());
750 tracer_tester_
->SetTracingEnabled(true);
751 EXPECT_TRUE(tracer_tester_
->IsTracing());
753 // Test basic functionality of the GPUTracerTester.
754 TEST_F(GPUTracerTest
, DecodeTest
) {
755 ASSERT_TRUE(tracer_tester_
->BeginDecoding());
756 EXPECT_FALSE(tracer_tester_
->BeginDecoding());
757 ASSERT_TRUE(tracer_tester_
->EndDecoding());
758 EXPECT_FALSE(tracer_tester_
->EndDecoding());
761 TEST_F(GPUTracerTest
, TraceDuringDecodeTest
) {
762 const std::string
category_name("trace_category");
763 const std::string
trace_name("trace_test");
766 tracer_tester_
->Begin(category_name
, trace_name
, kTraceCHROMIUM
));
768 ASSERT_TRUE(tracer_tester_
->BeginDecoding());
770 tracer_tester_
->Begin(category_name
, trace_name
, kTraceCHROMIUM
));
771 ASSERT_TRUE(tracer_tester_
->EndDecoding());
774 TEST_F(GpuDisjointTimerTracerTest
, MultipleClientsDisjointTest
) {
775 scoped_refptr
<gfx::GPUTimingClient
> client1
=
776 GetGLContext()->CreateGPUTimingClient();
777 scoped_refptr
<gfx::GPUTimingClient
> client2
=
778 GetGLContext()->CreateGPUTimingClient();
780 // Test both clients are initialized as no errors.
781 ASSERT_FALSE(client1
->CheckAndResetTimerErrors());
782 ASSERT_FALSE(client2
->CheckAndResetTimerErrors());
785 gl_fake_queries_
.SetDisjoint();
787 ASSERT_TRUE(client1
->CheckAndResetTimerErrors());
788 ASSERT_TRUE(client2
->CheckAndResetTimerErrors());
790 // Test both are now reset.
791 ASSERT_FALSE(client1
->CheckAndResetTimerErrors());
792 ASSERT_FALSE(client2
->CheckAndResetTimerErrors());
795 gl_fake_queries_
.SetDisjoint();
797 // Test new client disjoint value is cleared.
798 scoped_refptr
<gfx::GPUTimingClient
> client3
=
799 GetGLContext()->CreateGPUTimingClient();
800 ASSERT_TRUE(client1
->CheckAndResetTimerErrors());
801 ASSERT_TRUE(client2
->CheckAndResetTimerErrors());
802 ASSERT_FALSE(client3
->CheckAndResetTimerErrors());