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.
9 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
10 #include "gpu/command_buffer/service/gpu_service_test.h"
11 #include "gpu/command_buffer/service/gpu_tracer.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gl/gl_mock.h"
14 #include "ui/gl/gpu_timing.h"
21 using ::testing::AtLeast
;
22 using ::testing::AtMost
;
23 using ::testing::Exactly
;
24 using ::testing::Invoke
;
25 using ::testing::NotNull
;
26 using ::testing::Return
;
28 int64 g_fakeCPUTime
= 0;
33 class MockOutputter
: public Outputter
{
36 MOCK_METHOD5(TraceDevice
,
37 void(GpuTracerSource source
,
38 const std::string
& category
, const std::string
& name
,
39 int64 start_time
, int64 end_time
));
41 MOCK_METHOD3(TraceServiceBegin
,
42 void(GpuTracerSource source
,
43 const std::string
& category
, const std::string
& name
));
45 MOCK_METHOD3(TraceServiceEnd
,
46 void(GpuTracerSource source
,
47 const std::string
& category
, const std::string
& name
));
60 alloced_queries_
.clear();
61 query_timestamp_
.clear();
64 void SetCurrentGLTime(GLint64 current_time
) { current_time_
= current_time
; }
65 void SetDisjoint() { disjointed_
= true; }
67 void GenQueries(GLsizei n
, GLuint
* ids
) {
68 for (GLsizei i
= 0; i
< n
; i
++) {
69 ids
[i
] = next_query_id_
++;
70 alloced_queries_
.insert(ids
[i
]);
74 void DeleteQueries(GLsizei n
, const GLuint
* ids
) {
75 for (GLsizei i
= 0; i
< n
; i
++) {
76 alloced_queries_
.erase(ids
[i
]);
77 query_timestamp_
.erase(ids
[i
]);
81 void GetQueryObjectiv(GLuint id
, GLenum pname
, GLint
* params
) {
83 case GL_QUERY_RESULT_AVAILABLE
: {
84 std::map
<GLuint
, GLint64
>::iterator it
= query_timestamp_
.find(id
);
85 if (it
!= query_timestamp_
.end() && it
->second
<= current_time_
)
92 FAIL() << "Invalid variable passed to GetQueryObjectiv: " << pname
;
96 void QueryCounter(GLuint id
, GLenum target
) {
99 ASSERT_TRUE(alloced_queries_
.find(id
) != alloced_queries_
.end());
100 query_timestamp_
[id
] = current_time_
;
103 FAIL() << "Invalid variable passed to QueryCounter: " << target
;
107 void GetInteger64v(GLenum pname
, GLint64
* data
) {
110 *data
= current_time_
;
113 FAIL() << "Invalid variable passed to GetInteger64v: " << pname
;
117 void GetQueryObjectui64v(GLuint id
, GLenum pname
, GLuint64
* params
) {
119 case GL_QUERY_RESULT
:
120 ASSERT_TRUE(query_timestamp_
.find(id
) != query_timestamp_
.end());
121 *params
= query_timestamp_
.find(id
)->second
;
124 FAIL() << "Invalid variable passed to GetQueryObjectui64v: " << pname
;
128 void GetIntegerv(GLenum pname
, GLint
* params
) {
130 case GL_GPU_DISJOINT_EXT
:
131 *params
= static_cast<GLint
>(disjointed_
);
135 FAIL() << "Invalid variable passed to GetIntegerv: " << pname
;
147 bool disjointed_
= false;
148 GLint64 current_time_
= 0;
149 GLuint next_query_id_
= 0;
150 std::set
<GLuint
> alloced_queries_
;
151 std::map
<GLuint
, GLint64
> query_timestamp_
;
154 class GPUTracerTester
: public GPUTracer
{
156 explicit GPUTracerTester(gles2::GLES2Decoder
* decoder
)
157 : GPUTracer(decoder
), tracing_enabled_(0) {
158 gpu_timing_client_
->SetCpuTimeForTesting(base::Bind(&FakeCpuTime
));
160 // Force tracing to be dependent on our mock variable here.
161 gpu_trace_srv_category
= &tracing_enabled_
;
162 gpu_trace_dev_category
= &tracing_enabled_
;
165 ~GPUTracerTester() override
{}
167 void SetTracingEnabled(bool enabled
) {
168 tracing_enabled_
= enabled
? 1 : 0;
171 void SetOutputter(scoped_refptr
<Outputter
> outputter
) {
172 set_outputter_
= outputter
;
176 scoped_refptr
<Outputter
> CreateOutputter(const std::string
& name
) override
{
177 if (set_outputter_
.get()) {
178 return set_outputter_
;
180 return new MockOutputter();
183 void PostTask() override
{
184 // Process synchronously.
188 unsigned char tracing_enabled_
;
190 scoped_refptr
<Outputter
> set_outputter_
;
193 class BaseGpuTest
: public GpuServiceTest
{
195 explicit BaseGpuTest(gfx::GPUTiming::TimerType test_timer_type
)
196 : test_timer_type_(test_timer_type
) {
200 void SetUp() override
{
202 const char* gl_version
= "3.2";
203 const char* extensions
= "";
204 if (GetTimerType() == gfx::GPUTiming::kTimerTypeEXT
) {
205 gl_version
= "opengl 2.1";
206 extensions
= "GL_EXT_timer_query";
207 } else if (GetTimerType() == gfx::GPUTiming::kTimerTypeDisjoint
) {
208 gl_version
= "opengl es 3.0";
209 extensions
= "GL_EXT_disjoint_timer_query";
210 } else if (GetTimerType() == gfx::GPUTiming::kTimerTypeARB
) {
211 // TODO(sievers): The tracer should not depend on ARB_occlusion_query.
212 // Try merge Query APIs (core, ARB, EXT) into a single binding each.
213 extensions
= "GL_ARB_timer_query GL_ARB_occlusion_query";
215 GpuServiceTest::SetUpWithGLVersion(gl_version
, extensions
);
217 // Disjoint check should only be called by kTracerTypeDisjointTimer type.
218 if (GetTimerType() == gfx::GPUTiming::kTimerTypeDisjoint
) {
219 EXPECT_CALL(*gl_
, GetIntegerv(GL_GPU_DISJOINT_EXT
, _
)).Times(AtLeast(1))
221 Invoke(&gl_fake_queries_
, &GlFakeQueries::GetIntegerv
));
223 EXPECT_CALL(*gl_
, GetIntegerv(GL_GPU_DISJOINT_EXT
, _
)).Times(Exactly(0));
225 gpu_timing_client_
= GetGLContext()->CreateGPUTimingClient();
226 gpu_timing_client_
->SetCpuTimeForTesting(base::Bind(&FakeCpuTime
));
227 gl_fake_queries_
.Reset();
229 outputter_ref_
= new MockOutputter();
232 void TearDown() override
{
233 outputter_ref_
= NULL
;
234 gpu_timing_client_
= NULL
;
236 gl_fake_queries_
.Reset();
237 GpuServiceTest::TearDown();
240 void ExpectTraceQueryMocks() {
241 if (gpu_timing_client_
->IsAvailable() &&
242 gpu_timing_client_
->IsTimerOffsetAvailable()) {
243 // Delegate query APIs used by GPUTrace to a GlFakeQueries
244 EXPECT_CALL(*gl_
, GenQueries(2, NotNull())).Times(AtLeast(1))
246 Invoke(&gl_fake_queries_
, &GlFakeQueries::GenQueries
));
248 EXPECT_CALL(*gl_
, GetQueryObjectiv(_
, GL_QUERY_RESULT_AVAILABLE
,
251 Invoke(&gl_fake_queries_
, &GlFakeQueries::GetQueryObjectiv
));
253 EXPECT_CALL(*gl_
, GetInteger64v(GL_TIMESTAMP
, _
))
255 Invoke(&gl_fake_queries_
, &GlFakeQueries::GetInteger64v
));
257 EXPECT_CALL(*gl_
, QueryCounter(_
, GL_TIMESTAMP
)).Times(AtLeast(2))
259 Invoke(&gl_fake_queries_
, &GlFakeQueries::QueryCounter
));
261 EXPECT_CALL(*gl_
, GetQueryObjectui64v(_
, GL_QUERY_RESULT
, NotNull()))
263 Invoke(&gl_fake_queries_
,
264 &GlFakeQueries::GetQueryObjectui64v
));
266 EXPECT_CALL(*gl_
, DeleteQueries(2, NotNull())).Times(AtLeast(1))
268 Invoke(&gl_fake_queries_
, &GlFakeQueries::DeleteQueries
));
272 void ExpectOutputterBeginMocks(MockOutputter
* outputter
,
273 GpuTracerSource source
,
274 const std::string
& category
,
275 const std::string
& name
) {
276 EXPECT_CALL(*outputter
,
277 TraceServiceBegin(source
, category
, name
));
280 void ExpectOutputterEndMocks(MockOutputter
* outputter
,
281 GpuTracerSource source
,
282 const std::string
& category
,
283 const std::string
& name
, int64 expect_start_time
,
284 int64 expect_end_time
,
286 EXPECT_CALL(*outputter
,
287 TraceServiceEnd(source
, category
, name
));
290 EXPECT_CALL(*outputter
,
291 TraceDevice(source
, category
, name
,
292 expect_start_time
, expect_end_time
))
295 EXPECT_CALL(*outputter
, TraceDevice(source
, category
, name
,
296 expect_start_time
, expect_end_time
))
301 void ExpectOutputterMocks(MockOutputter
* outputter
,
303 GpuTracerSource source
,
304 const std::string
& category
,
305 const std::string
& name
, int64 expect_start_time
,
306 int64 expect_end_time
) {
307 ExpectOutputterBeginMocks(outputter
, source
, category
, name
);
308 bool valid_timer
= tracing_device
&&
309 gpu_timing_client_
->IsAvailable() &&
310 gpu_timing_client_
->IsTimerOffsetAvailable();
311 ExpectOutputterEndMocks(outputter
, source
, category
, name
,
312 expect_start_time
, expect_end_time
, valid_timer
);
315 void ExpectTracerOffsetQueryMocks() {
316 if (GetTimerType() != gfx::GPUTiming::kTimerTypeARB
) {
317 EXPECT_CALL(*gl_
, GetInteger64v(GL_TIMESTAMP
, NotNull()))
320 EXPECT_CALL(*gl_
, GetInteger64v(GL_TIMESTAMP
, NotNull()))
323 Invoke(&gl_fake_queries_
, &GlFakeQueries::GetInteger64v
));
327 gfx::GPUTiming::TimerType
GetTimerType() { return test_timer_type_
; }
329 gfx::GPUTiming::TimerType test_timer_type_
;
330 GlFakeQueries gl_fake_queries_
;
332 scoped_refptr
<gfx::GPUTimingClient
> gpu_timing_client_
;
333 scoped_refptr
<MockOutputter
> outputter_ref_
;
336 // Test GPUTrace calls all the correct gl calls.
337 class BaseGpuTraceTest
: public BaseGpuTest
{
339 explicit BaseGpuTraceTest(gfx::GPUTiming::TimerType test_timer_type
)
340 : BaseGpuTest(test_timer_type
) {}
342 void DoTraceTest(bool tracing_service
, bool tracing_device
) {
344 const GpuTracerSource tracer_source
= kTraceGroupMarker
;
345 const std::string
category_name("trace_category");
346 const std::string
trace_name("trace_test");
347 const int64 offset_time
= 3231;
348 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
349 const GLint64 end_timestamp
= 32 * base::Time::kNanosecondsPerMicrosecond
;
350 const int64 expect_start_time
=
351 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
353 const int64 expect_end_time
=
354 (end_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) + offset_time
;
357 ExpectOutputterMocks(outputter_ref_
.get(), tracing_device
, tracer_source
,
358 category_name
, trace_name
,
359 expect_start_time
, expect_end_time
);
362 ExpectTraceQueryMocks();
364 scoped_refptr
<GPUTrace
> trace
= new GPUTrace(
365 outputter_ref_
, gpu_timing_client_
.get(), tracer_source
,
366 category_name
, trace_name
, tracing_service
, tracing_device
);
368 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
369 g_fakeCPUTime
= expect_start_time
;
372 // Shouldn't be available before End() call
373 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
);
374 g_fakeCPUTime
= expect_end_time
;
376 EXPECT_FALSE(trace
->IsAvailable());
380 // Shouldn't be available until the queries complete
381 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
-
382 base::Time::kNanosecondsPerMicrosecond
);
384 EXPECT_FALSE(trace
->IsAvailable());
386 // Now it should be available
387 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
);
388 EXPECT_TRUE(trace
->IsAvailable());
390 // Proces should output expected Trace results to MockOutputter
393 // Destroy trace after we are done.
394 trace
->Destroy(true);
396 outputter_ref_
= NULL
;
400 class GpuARBTimerTraceTest
: public BaseGpuTraceTest
{
402 GpuARBTimerTraceTest() : BaseGpuTraceTest(gfx::GPUTiming::kTimerTypeARB
) {}
405 class GpuDisjointTimerTraceTest
: public BaseGpuTraceTest
{
407 GpuDisjointTimerTraceTest()
408 : BaseGpuTraceTest(gfx::GPUTiming::kTimerTypeDisjoint
) {}
411 TEST_F(GpuARBTimerTraceTest
, ARBTimerTraceTestOff
) {
412 DoTraceTest(false, false);
415 TEST_F(GpuARBTimerTraceTest
, ARBTimerTraceTestServiceOnly
) {
416 DoTraceTest(true, false);
419 TEST_F(GpuARBTimerTraceTest
, ARBTimerTraceTestDeviceOnly
) {
420 DoTraceTest(false, true);
423 TEST_F(GpuARBTimerTraceTest
, ARBTimerTraceTestBothOn
) {
424 DoTraceTest(true, true);
427 TEST_F(GpuDisjointTimerTraceTest
, DisjointTimerTraceTestOff
) {
428 DoTraceTest(false, false);
431 TEST_F(GpuDisjointTimerTraceTest
, DisjointTimerTraceTestServiceOnly
) {
432 DoTraceTest(true, false);
435 TEST_F(GpuDisjointTimerTraceTest
, DisjointTimerTraceTestDeviceOnly
) {
436 DoTraceTest(false, true);
439 TEST_F(GpuDisjointTimerTraceTest
, DisjointTimerTraceTestBothOn
) {
440 DoTraceTest(true, true);
443 // Test GPUTracer calls all the correct gl calls.
444 class BaseGpuTracerTest
: public BaseGpuTest
{
446 explicit BaseGpuTracerTest(gfx::GPUTiming::TimerType test_timer_type
)
447 : BaseGpuTest(test_timer_type
) {}
449 void DoBasicTracerTest() {
450 ExpectTracerOffsetQueryMocks();
452 MockGLES2Decoder decoder
;
453 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
454 GPUTracerTester
tracer(&decoder
);
455 tracer
.SetTracingEnabled(true);
457 tracer
.SetOutputter(outputter_ref_
);
459 ASSERT_TRUE(tracer
.BeginDecoding());
460 ASSERT_TRUE(tracer
.EndDecoding());
462 outputter_ref_
= NULL
;
465 void DoTracerMarkersTest() {
466 ExpectTracerOffsetQueryMocks();
468 EXPECT_CALL(*gl_
, GetError()).Times(AtLeast(0))
470 Invoke(&gl_fake_queries_
, &GlFakeQueries::GetError
));
472 const std::string
category_name("trace_category");
473 const std::string
trace_name("trace_test");
474 const int64 offset_time
= 3231;
475 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
476 const GLint64 end_timestamp
= 32 * base::Time::kNanosecondsPerMicrosecond
;
477 const int64 expect_start_time
=
478 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
480 const int64 expect_end_time
=
481 (end_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) + offset_time
;
483 MockGLES2Decoder decoder
;
484 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
485 GPUTracerTester
tracer(&decoder
);
486 tracer
.SetTracingEnabled(true);
488 tracer
.SetOutputter(outputter_ref_
);
490 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
491 g_fakeCPUTime
= expect_start_time
;
493 ASSERT_TRUE(tracer
.BeginDecoding());
495 ExpectTraceQueryMocks();
497 // This will test multiple marker sources which overlap one another.
498 for (int i
= 0; i
< NUM_TRACER_SOURCES
; ++i
) {
499 // Set times so each source has a different time.
500 gl_fake_queries_
.SetCurrentGLTime(
502 (i
* base::Time::kNanosecondsPerMicrosecond
));
503 g_fakeCPUTime
= expect_start_time
+ i
;
505 // Each trace name should be different to differentiate.
506 const char num_char
= static_cast<char>('0' + i
);
507 std::string source_category
= category_name
+ num_char
;
508 std::string source_trace_name
= trace_name
+ num_char
;
510 const GpuTracerSource source
= static_cast<GpuTracerSource
>(i
);
511 ExpectOutputterBeginMocks(outputter_ref_
.get(), source
,
512 source_category
, source_trace_name
);
513 ASSERT_TRUE(tracer
.Begin(source_category
, source_trace_name
, source
));
516 for (int i
= 0; i
< NUM_TRACER_SOURCES
; ++i
) {
517 // Set times so each source has a different time.
518 gl_fake_queries_
.SetCurrentGLTime(
520 (i
* base::Time::kNanosecondsPerMicrosecond
));
521 g_fakeCPUTime
= expect_end_time
+ i
;
523 // Each trace name should be different to differentiate.
524 const char num_char
= static_cast<char>('0' + i
);
525 std::string source_category
= category_name
+ num_char
;
526 std::string source_trace_name
= trace_name
+ num_char
;
528 bool valid_timer
= gpu_timing_client_
->IsAvailable() &&
529 gpu_timing_client_
->IsTimerOffsetAvailable();
531 const GpuTracerSource source
= static_cast<GpuTracerSource
>(i
);
532 ExpectOutputterEndMocks(outputter_ref_
.get(), source
, source_category
,
533 source_trace_name
, expect_start_time
+ i
,
534 expect_end_time
+ i
, valid_timer
);
536 // Check if the current category/name are correct for this source.
537 ASSERT_EQ(source_category
, tracer
.CurrentCategory(source
));
538 ASSERT_EQ(source_trace_name
, tracer
.CurrentName(source
));
540 ASSERT_TRUE(tracer
.End(source
));
543 ASSERT_TRUE(tracer
.EndDecoding());
545 outputter_ref_
= NULL
;
548 void DoDisjointTest() {
549 // Cause a disjoint in a middle of a trace and expect no output calls.
550 ExpectTracerOffsetQueryMocks();
552 EXPECT_CALL(*gl_
, GetError()).Times(AtLeast(0))
554 Invoke(&gl_fake_queries_
, &GlFakeQueries::GetError
));
556 const GpuTracerSource tracer_source
= kTraceGroupMarker
;
557 const std::string
category_name("trace_category");
558 const std::string
trace_name("trace_test");
559 const GpuTracerSource source
= static_cast<GpuTracerSource
>(0);
560 const int64 offset_time
= 3231;
561 const GLint64 start_timestamp
= 7 * base::Time::kNanosecondsPerMicrosecond
;
562 const GLint64 end_timestamp
= 32 * base::Time::kNanosecondsPerMicrosecond
;
563 const int64 expect_start_time
=
564 (start_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) +
566 const int64 expect_end_time
=
567 (end_timestamp
/ base::Time::kNanosecondsPerMicrosecond
) + offset_time
;
569 MockGLES2Decoder decoder
;
570 EXPECT_CALL(decoder
, GetGLContext()).WillOnce(Return(GetGLContext()));
571 GPUTracerTester
tracer(&decoder
);
572 tracer
.SetTracingEnabled(true);
574 tracer
.SetOutputter(outputter_ref_
);
576 gl_fake_queries_
.SetCurrentGLTime(start_timestamp
);
577 g_fakeCPUTime
= expect_start_time
;
579 ASSERT_TRUE(tracer
.BeginDecoding());
581 ExpectTraceQueryMocks();
583 ExpectOutputterBeginMocks(outputter_ref_
.get(), tracer_source
,
584 category_name
, trace_name
);
585 ASSERT_TRUE(tracer
.Begin(category_name
, trace_name
, source
));
587 gl_fake_queries_
.SetCurrentGLTime(end_timestamp
);
588 g_fakeCPUTime
= expect_end_time
;
590 // Create GPUTimingClient to make sure disjoint value is correct. This
591 // should not interfere with the tracer's disjoint value.
592 scoped_refptr
<gfx::GPUTimingClient
> disjoint_client
=
593 GetGLContext()->CreateGPUTimingClient();
595 // We assert here based on the disjoint_client because if disjoints are not
596 // working properly there is no point testing the tracer output.
597 ASSERT_FALSE(disjoint_client
->CheckAndResetTimerErrors());
598 gl_fake_queries_
.SetDisjoint();
599 ASSERT_TRUE(disjoint_client
->CheckAndResetTimerErrors());
601 ExpectOutputterEndMocks(outputter_ref_
.get(), tracer_source
,
602 category_name
, trace_name
,
603 expect_start_time
, expect_end_time
, false);
605 ASSERT_TRUE(tracer
.End(source
));
606 ASSERT_TRUE(tracer
.EndDecoding());
608 outputter_ref_
= NULL
;
612 class InvalidTimerTracerTest
: public BaseGpuTracerTest
{
614 InvalidTimerTracerTest()
615 : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeInvalid
) {}
618 class GpuEXTTimerTracerTest
: public BaseGpuTracerTest
{
620 GpuEXTTimerTracerTest() : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeEXT
) {}
623 class GpuARBTimerTracerTest
: public BaseGpuTracerTest
{
625 GpuARBTimerTracerTest()
626 : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeARB
) {}
629 class GpuDisjointTimerTracerTest
: public BaseGpuTracerTest
{
631 GpuDisjointTimerTracerTest()
632 : BaseGpuTracerTest(gfx::GPUTiming::kTimerTypeDisjoint
) {}
635 TEST_F(InvalidTimerTracerTest
, InvalidTimerBasicTracerTest
) {
639 TEST_F(GpuEXTTimerTracerTest
, EXTTimerBasicTracerTest
) {
643 TEST_F(GpuARBTimerTracerTest
, ARBTimerBasicTracerTest
) {
647 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerBasicTracerTest
) {
651 TEST_F(InvalidTimerTracerTest
, InvalidTimerTracerMarkersTest
) {
652 DoTracerMarkersTest();
655 TEST_F(GpuEXTTimerTracerTest
, EXTTimerTracerMarkersTest
) {
656 DoTracerMarkersTest();
659 TEST_F(GpuARBTimerTracerTest
, ARBTimerBasicTracerMarkersTest
) {
660 DoTracerMarkersTest();
663 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerBasicTracerMarkersTest
) {
664 DoTracerMarkersTest();
667 TEST_F(GpuDisjointTimerTracerTest
, DisjointTimerDisjointTraceTest
) {
671 class GPUTracerTest
: public GpuServiceTest
{
673 void SetUp() override
{
675 GpuServiceTest::SetUpWithGLVersion("3.2", "");
676 decoder_
.reset(new MockGLES2Decoder());
677 EXPECT_CALL(*decoder_
, GetGLContext())
679 .WillRepeatedly(Return(GetGLContext()));
680 tracer_tester_
.reset(new GPUTracerTester(decoder_
.get()));
683 void TearDown() override
{
684 tracer_tester_
= nullptr;
686 GpuServiceTest::TearDown();
688 scoped_ptr
<MockGLES2Decoder
> decoder_
;
689 scoped_ptr
<GPUTracerTester
> tracer_tester_
;
692 TEST_F(GPUTracerTest
, IsTracingTest
) {
693 EXPECT_FALSE(tracer_tester_
->IsTracing());
694 tracer_tester_
->SetTracingEnabled(true);
695 EXPECT_TRUE(tracer_tester_
->IsTracing());
697 // Test basic functionality of the GPUTracerTester.
698 TEST_F(GPUTracerTest
, DecodeTest
) {
699 ASSERT_TRUE(tracer_tester_
->BeginDecoding());
700 EXPECT_FALSE(tracer_tester_
->BeginDecoding());
701 ASSERT_TRUE(tracer_tester_
->EndDecoding());
702 EXPECT_FALSE(tracer_tester_
->EndDecoding());
705 TEST_F(GPUTracerTest
, TraceDuringDecodeTest
) {
706 const std::string
category_name("trace_category");
707 const std::string
trace_name("trace_test");
710 tracer_tester_
->Begin(category_name
, trace_name
, kTraceGroupMarker
));
712 ASSERT_TRUE(tracer_tester_
->BeginDecoding());
714 tracer_tester_
->Begin(category_name
, trace_name
, kTraceGroupMarker
));
715 ASSERT_TRUE(tracer_tester_
->EndDecoding());
718 TEST_F(GpuDisjointTimerTracerTest
, MultipleClientsDisjointTest
) {
719 scoped_refptr
<gfx::GPUTimingClient
> client1
=
720 GetGLContext()->CreateGPUTimingClient();
721 scoped_refptr
<gfx::GPUTimingClient
> client2
=
722 GetGLContext()->CreateGPUTimingClient();
724 // Test both clients are initialized as no errors.
725 ASSERT_FALSE(client1
->CheckAndResetTimerErrors());
726 ASSERT_FALSE(client2
->CheckAndResetTimerErrors());
729 gl_fake_queries_
.SetDisjoint();
731 ASSERT_TRUE(client1
->CheckAndResetTimerErrors());
732 ASSERT_TRUE(client2
->CheckAndResetTimerErrors());
734 // Test both are now reset.
735 ASSERT_FALSE(client1
->CheckAndResetTimerErrors());
736 ASSERT_FALSE(client2
->CheckAndResetTimerErrors());
739 gl_fake_queries_
.SetDisjoint();
741 // Test new client disjoint value is cleared.
742 scoped_refptr
<gfx::GPUTimingClient
> client3
=
743 GetGLContext()->CreateGPUTimingClient();
744 ASSERT_TRUE(client1
->CheckAndResetTimerErrors());
745 ASSERT_TRUE(client2
->CheckAndResetTimerErrors());
746 ASSERT_FALSE(client3
->CheckAndResetTimerErrors());