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 <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/bind.h" | |
8 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" | 9 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" |
9 #include "gpu/command_buffer/service/gpu_service_test.h" | 10 #include "gpu/command_buffer/service/gpu_service_test.h" |
11 #include "gpu/command_buffer/service/gpu_timing.h" | |
10 #include "gpu/command_buffer/service/gpu_tracer.h" | 12 #include "gpu/command_buffer/service/gpu_tracer.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/gl/gl_context_stub.h" | |
13 #include "ui/gl/gl_mock.h" | 14 #include "ui/gl/gl_mock.h" |
14 #include "ui/gl/gl_surface_stub.h" | |
15 | 15 |
16 namespace gpu { | 16 namespace gpu { |
17 namespace gles2 { | 17 namespace gles2 { |
18 namespace { | |
18 | 19 |
19 using ::testing::_; | 20 using ::testing::_; |
20 using ::testing::AtLeast; | 21 using ::testing::AtLeast; |
22 using ::testing::AtMost; | |
21 using ::testing::Exactly; | 23 using ::testing::Exactly; |
22 using ::testing::Invoke; | 24 using ::testing::Invoke; |
23 using ::testing::NotNull; | 25 using ::testing::NotNull; |
24 using ::testing::Return; | 26 using ::testing::Return; |
25 | 27 |
26 class FakeCPUTime : public CPUTime { | 28 int64 g_fakeCPUTime = 0; |
David Yen
2015/02/10 22:30:01
Since this is a global variable, should it be rese
Daniele Castagna
2015/02/10 22:42:36
Done.
| |
27 public: | 29 int64 FakeCpuTime() { |
28 FakeCPUTime() | 30 return g_fakeCPUTime; |
29 : current_cpu_time_(0) { | 31 } |
30 } | |
31 | |
32 int64 GetCurrentTime() override { | |
33 return current_cpu_time_; | |
34 } | |
35 | |
36 void SetFakeCPUTime(int64 cpu_time) { | |
37 current_cpu_time_ = cpu_time; | |
38 } | |
39 | |
40 protected: | |
41 ~FakeCPUTime() override {} | |
42 | |
43 int64 current_cpu_time_; | |
44 }; | |
45 | 32 |
46 class MockOutputter : public Outputter { | 33 class MockOutputter : public Outputter { |
47 public: | 34 public: |
48 MockOutputter() {} | 35 MockOutputter() {} |
49 MOCK_METHOD4(TraceDevice, | 36 MOCK_METHOD4(TraceDevice, |
50 void(const std::string& category, const std::string& name, | 37 void(const std::string& category, const std::string& name, |
51 int64 start_time, int64 end_time)); | 38 int64 start_time, int64 end_time)); |
52 | 39 |
53 MOCK_METHOD2(TraceServiceBegin, | 40 MOCK_METHOD2(TraceServiceBegin, |
54 void(const std::string& category, const std::string& name)); | 41 void(const std::string& category, const std::string& name)); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 protected: | 143 protected: |
157 bool disjointed_; | 144 bool disjointed_; |
158 GLint64 current_time_; | 145 GLint64 current_time_; |
159 GLuint next_query_id_; | 146 GLuint next_query_id_; |
160 std::set<GLuint> alloced_queries_; | 147 std::set<GLuint> alloced_queries_; |
161 std::map<GLuint, GLint64> query_timestamp_; | 148 std::map<GLuint, GLint64> query_timestamp_; |
162 }; | 149 }; |
163 | 150 |
164 class GPUTracerTester : public GPUTracer { | 151 class GPUTracerTester : public GPUTracer { |
165 public: | 152 public: |
166 GPUTracerTester(GpuTracerType tracer_type, gles2::GLES2Decoder* decoder) | 153 explicit GPUTracerTester(gles2::GLES2Decoder* decoder) |
167 : GPUTracer(decoder), | 154 : GPUTracer(decoder), tracing_enabled_(0) { |
168 tracing_enabled_(0), | 155 gpu_timing_.SetCpuTimeForTesting(base::Bind(&FakeCpuTime)); |
169 test_tracer_type_(tracer_type) { | 156 |
170 // Force tracing to be dependent on our mock variable here. | 157 // Force tracing to be dependent on our mock variable here. |
171 gpu_trace_srv_category = &tracing_enabled_; | 158 gpu_trace_srv_category = &tracing_enabled_; |
172 gpu_trace_dev_category = &tracing_enabled_; | 159 gpu_trace_dev_category = &tracing_enabled_; |
173 } | 160 } |
174 | 161 |
175 ~GPUTracerTester() override {} | 162 ~GPUTracerTester() override {} |
176 | 163 |
177 void SetTracingEnabled(bool enabled) { | 164 void SetTracingEnabled(bool enabled) { |
178 tracing_enabled_ = enabled ? 1 : 0; | 165 tracing_enabled_ = enabled ? 1 : 0; |
179 } | 166 } |
180 | 167 |
181 void SetOutputter(scoped_refptr<Outputter> outputter) { | 168 void SetOutputter(scoped_refptr<Outputter> outputter) { |
182 set_outputter_ = outputter; | 169 set_outputter_ = outputter; |
183 } | 170 } |
184 | 171 |
185 void SetCPUTime(scoped_refptr<CPUTime> cputime) { | |
186 set_cputime_ = cputime; | |
187 } | |
188 | |
189 protected: | 172 protected: |
190 scoped_refptr<Outputter> CreateOutputter(const std::string& name) override { | 173 scoped_refptr<Outputter> CreateOutputter(const std::string& name) override { |
191 if (set_outputter_.get()) { | 174 if (set_outputter_.get()) { |
192 return set_outputter_; | 175 return set_outputter_; |
193 } | 176 } |
194 return new MockOutputter(); | 177 return new MockOutputter(); |
195 } | 178 } |
196 | 179 |
197 scoped_refptr<CPUTime> CreateCPUTime() override { | |
198 if (set_cputime_.get()) { | |
199 return set_cputime_; | |
200 } | |
201 return new FakeCPUTime(); | |
202 } | |
203 | |
204 GpuTracerType DetermineTracerType() override { | |
205 return test_tracer_type_; | |
206 } | |
207 | |
208 void PostTask() override { | 180 void PostTask() override { |
209 // Process synchronously. | 181 // Process synchronously. |
210 Process(); | 182 Process(); |
211 } | 183 } |
212 | 184 |
213 unsigned char tracing_enabled_; | 185 unsigned char tracing_enabled_; |
214 GpuTracerType test_tracer_type_; | |
215 | 186 |
216 scoped_refptr<Outputter> set_outputter_; | 187 scoped_refptr<Outputter> set_outputter_; |
217 scoped_refptr<CPUTime> set_cputime_; | |
218 }; | 188 }; |
219 | 189 |
220 class BaseGpuTest : public GpuServiceTest { | 190 class BaseGpuTest : public GpuServiceTest { |
221 public: | 191 public: |
222 BaseGpuTest(GpuTracerType test_tracer_type) | 192 explicit BaseGpuTest(GPUTiming::TimerType test_timer_type) |
223 : test_tracer_type_(test_tracer_type) { | 193 : test_timer_type_(test_timer_type) { |
194 gpu_timing_.SetCpuTimeForTesting(base::Bind(&FakeCpuTime)); | |
195 gpu_timing_.SetTimerTypeForTesting(test_timer_type); | |
224 } | 196 } |
225 | 197 |
226 protected: | 198 protected: |
227 void SetUp() override { | 199 void SetUp() override { |
228 const char* gl_version = "3.2"; | 200 const char* gl_version = "3.2"; |
229 const char* extensions = nullptr; | 201 const char* extensions = ""; |
230 if (GetTracerType() == kTracerTypeDisjointTimer) { | 202 if (GetTimerType() == GPUTiming::kTimerTypeDisjoint) { |
231 gl_version = "opengl es 3.0"; | 203 gl_version = "opengl es 3.0"; |
232 extensions = "GL_EXT_disjoint_timer_query"; | 204 extensions = "GL_EXT_disjoint_timer_query"; |
233 } else if (GetTracerType() == kTracerTypeARBTimer) { | 205 } else if (GetTimerType() == GPUTiming::kTimerTypeARB) { |
234 // TODO(sievers): The tracer should not depend on ARB_occlusion_query. | 206 // TODO(sievers): The tracer should not depend on ARB_occlusion_query. |
235 // Try merge Query APIs (core, ARB, EXT) into a single binding each. | 207 // Try merge Query APIs (core, ARB, EXT) into a single binding each. |
236 extensions = "GL_ARB_timer_query GL_ARB_occlusion_query"; | 208 extensions = "GL_ARB_timer_query GL_ARB_occlusion_query"; |
237 } | 209 } |
238 GpuServiceTest::SetUpWithGLVersion(gl_version, extensions); | 210 GpuServiceTest::SetUpWithGLVersion(gl_version, extensions); |
239 gl_fake_queries_.Reset(); | 211 gl_fake_queries_.Reset(); |
240 gl_surface_ = new gfx::GLSurfaceStub(); | |
241 gl_context_ = new gfx::GLContextStub(); | |
242 gl_context_->MakeCurrent(gl_surface_.get()); | |
243 | 212 |
244 outputter_ref_ = new MockOutputter(); | 213 outputter_ref_ = new MockOutputter(); |
245 cpu_time_ref_ = new FakeCPUTime; | |
246 } | 214 } |
247 | 215 |
248 void TearDown() override { | 216 void TearDown() override { |
249 outputter_ref_ = NULL; | 217 outputter_ref_ = NULL; |
250 cpu_time_ref_ = NULL; | |
251 | 218 |
252 gl_context_->ReleaseCurrent(gl_surface_.get()); | |
253 gl_context_ = NULL; | |
254 gl_surface_ = NULL; | |
255 | |
256 gl_.reset(); | |
257 gl_fake_queries_.Reset(); | 219 gl_fake_queries_.Reset(); |
258 GpuServiceTest::TearDown(); | 220 GpuServiceTest::TearDown(); |
259 } | 221 } |
260 | 222 |
261 void ExpectTraceQueryMocks() { | 223 void ExpectTraceQueryMocks() { |
262 if (GetTracerType() != kTracerTypeInvalid) { | 224 if (GetTimerType() != GPUTiming::kTimerTypeInvalid) { |
263 // Delegate query APIs used by GPUTrace to a GlFakeQueries | 225 // Delegate query APIs used by GPUTrace to a GlFakeQueries |
264 EXPECT_CALL(*gl_, GenQueriesARB(2, NotNull())).Times(AtLeast(1)) | 226 EXPECT_CALL(*gl_, GenQueriesARB(2, NotNull())).Times(AtLeast(1)) |
265 .WillRepeatedly( | 227 .WillRepeatedly( |
266 Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueriesARB)); | 228 Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueriesARB)); |
267 | 229 |
268 EXPECT_CALL(*gl_, GetQueryObjectivARB(_, GL_QUERY_RESULT_AVAILABLE, | 230 EXPECT_CALL(*gl_, GetQueryObjectivARB(_, GL_QUERY_RESULT_AVAILABLE, |
269 NotNull())) | 231 NotNull())) |
270 .WillRepeatedly( | 232 .WillRepeatedly( |
271 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectivARB)); | 233 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectivARB)); |
272 | 234 |
273 if (GetTracerType() == kTracerTypeDisjointTimer) { | 235 if (GetTimerType() == GPUTiming::kTimerTypeDisjoint) { |
274 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, _)) | 236 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, _)) |
275 .WillRepeatedly( | 237 .WillRepeatedly( |
276 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); | 238 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); |
277 } | 239 } |
278 | 240 |
279 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)).Times(AtLeast(2)) | 241 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)).Times(AtLeast(2)) |
280 .WillRepeatedly( | 242 .WillRepeatedly( |
281 Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); | 243 Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter)); |
282 | 244 |
283 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) | 245 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull())) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 expect_start_time, expect_end_time)) | 278 expect_start_time, expect_end_time)) |
317 .Times(Exactly(0)); | 279 .Times(Exactly(0)); |
318 } | 280 } |
319 } | 281 } |
320 | 282 |
321 void ExpectOutputterMocks(MockOutputter* outputter, | 283 void ExpectOutputterMocks(MockOutputter* outputter, |
322 const std::string& category, | 284 const std::string& category, |
323 const std::string& name, int64 expect_start_time, | 285 const std::string& name, int64 expect_start_time, |
324 int64 expect_end_time) { | 286 int64 expect_end_time) { |
325 ExpectOutputterBeginMocks(outputter, category, name); | 287 ExpectOutputterBeginMocks(outputter, category, name); |
326 ExpectOutputterEndMocks(outputter, category, name, | 288 ExpectOutputterEndMocks(outputter, category, name, expect_start_time, |
327 expect_start_time, expect_end_time, | 289 expect_end_time, |
328 GetTracerType() != kTracerTypeInvalid); | 290 GetTimerType() != GPUTiming::kTimerTypeInvalid); |
329 } | 291 } |
330 | 292 |
331 void ExpectTracerOffsetQueryMocks() { | 293 void ExpectTracerOffsetQueryMocks() { |
332 // Disjoint check should only be called by kTracerTypeDisjointTimer type. | 294 // Disjoint check should only be called by kTracerTypeDisjointTimer type. |
333 if (GetTracerType() == kTracerTypeDisjointTimer) { | 295 if (GetTimerType() == GPUTiming::kTimerTypeDisjoint) { |
334 EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(AtLeast(1)) | 296 EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(AtLeast(1)) |
335 .WillRepeatedly( | 297 .WillRepeatedly( |
336 Invoke(&gl_fake_queries_, &GlFakeQueries::GetIntegerv)); | 298 Invoke(&gl_fake_queries_, &GlFakeQueries::GetIntegerv)); |
337 } else { | 299 } else { |
338 EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(Exactly(0)); | 300 EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(Exactly(0)); |
339 } | 301 } |
340 | 302 |
341 // Timer offset calculation should only happen for the regular timer. | 303 if (GetTimerType() != GPUTiming::kTimerTypeARB) { |
342 if (GetTracerType() != kTracerTypeARBTimer) { | |
343 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) | 304 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) |
344 .Times(Exactly(0)); | 305 .Times(Exactly(0)); |
345 } else { | 306 } else { |
346 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) | 307 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) |
347 .Times(AtLeast(1)) | 308 .Times(AtMost(1)) |
348 .WillRepeatedly( | 309 .WillRepeatedly( |
349 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); | 310 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v)); |
350 } | 311 } |
351 } | 312 } |
352 | 313 |
353 GpuTracerType GetTracerType() { return test_tracer_type_; } | 314 GPUTiming::TimerType GetTimerType() { return test_timer_type_; } |
354 | 315 |
355 GpuTracerType test_tracer_type_; | 316 GPUTiming::TimerType test_timer_type_; |
356 GlFakeQueries gl_fake_queries_; | 317 GlFakeQueries gl_fake_queries_; |
357 | 318 |
319 GPUTiming gpu_timing_; | |
358 scoped_refptr<MockOutputter> outputter_ref_; | 320 scoped_refptr<MockOutputter> outputter_ref_; |
359 scoped_refptr<FakeCPUTime> cpu_time_ref_; | |
360 | |
361 scoped_refptr<gfx::GLSurface> gl_surface_; | |
362 scoped_refptr<gfx::GLContext> gl_context_; | |
363 }; | 321 }; |
364 | 322 |
365 // Test GPUTrace calls all the correct gl calls. | 323 // Test GPUTrace calls all the correct gl calls. |
366 class BaseGpuTraceTest : public BaseGpuTest { | 324 class BaseGpuTraceTest : public BaseGpuTest { |
367 public: | 325 public: |
368 BaseGpuTraceTest(GpuTracerType test_tracer_type) | 326 explicit BaseGpuTraceTest(GPUTiming::TimerType test_timer_type) |
369 : BaseGpuTest(test_tracer_type) { | 327 : BaseGpuTest(test_timer_type) {} |
370 } | |
371 | 328 |
372 void DoTraceTest() { | 329 void DoTraceTest() { |
373 // Expected results | 330 // Expected results |
374 const std::string category_name("trace_category"); | 331 const std::string category_name("trace_category"); |
375 const std::string trace_name("trace_test"); | 332 const std::string trace_name("trace_test"); |
376 const int64 offset_time = 3231; | 333 const int64 offset_time = 3231; |
377 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; | 334 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; |
378 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; | 335 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; |
379 const int64 expect_start_time = | 336 const int64 expect_start_time = |
380 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + | 337 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + |
381 offset_time; | 338 offset_time; |
382 const int64 expect_end_time = | 339 const int64 expect_end_time = |
383 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; | 340 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; |
384 | 341 |
385 ExpectTraceQueryMocks(); | 342 ExpectTraceQueryMocks(); |
386 ExpectOutputterMocks(outputter_ref_.get(), category_name, trace_name, | 343 ExpectOutputterMocks(outputter_ref_.get(), category_name, trace_name, |
387 expect_start_time, expect_end_time); | 344 expect_start_time, expect_end_time); |
388 | 345 |
389 scoped_refptr<GPUTrace> trace = | 346 scoped_refptr<GPUTrace> trace = new GPUTrace( |
390 new GPUTrace(outputter_ref_, cpu_time_ref_, category_name, trace_name, | 347 outputter_ref_, &gpu_timing_, category_name, trace_name, true); |
391 offset_time, GetTracerType()); | 348 |
349 gpu_timing_.SetOffsetForTesting( | |
350 offset_time, test_timer_type_ == GPUTiming::kTimerTypeARB); | |
392 | 351 |
393 gl_fake_queries_.SetCurrentGLTime(start_timestamp); | 352 gl_fake_queries_.SetCurrentGLTime(start_timestamp); |
394 cpu_time_ref_->SetFakeCPUTime(expect_start_time); | 353 g_fakeCPUTime = expect_start_time; |
395 trace->Start(true); | 354 trace->Start(true); |
396 | 355 |
397 // Shouldn't be available before End() call | 356 // Shouldn't be available before End() call |
398 gl_fake_queries_.SetCurrentGLTime(end_timestamp); | 357 gl_fake_queries_.SetCurrentGLTime(end_timestamp); |
399 EXPECT_FALSE(trace->IsAvailable()); | 358 EXPECT_FALSE(trace->IsAvailable()); |
400 | 359 |
401 trace->End(true); | 360 trace->End(true); |
402 | 361 |
403 // Shouldn't be available until the queries complete | 362 // Shouldn't be available until the queries complete |
404 gl_fake_queries_.SetCurrentGLTime(end_timestamp - | 363 gl_fake_queries_.SetCurrentGLTime(end_timestamp - |
405 base::Time::kNanosecondsPerMicrosecond); | 364 base::Time::kNanosecondsPerMicrosecond); |
406 EXPECT_FALSE(trace->IsAvailable()); | 365 EXPECT_FALSE(trace->IsAvailable()); |
407 | 366 |
408 // Now it should be available | 367 // Now it should be available |
409 gl_fake_queries_.SetCurrentGLTime(end_timestamp); | 368 gl_fake_queries_.SetCurrentGLTime(end_timestamp); |
410 EXPECT_TRUE(trace->IsAvailable()); | 369 EXPECT_TRUE(trace->IsAvailable()); |
411 | 370 |
412 // Proces should output expected Trace results to MockOutputter | 371 // Proces should output expected Trace results to MockOutputter |
413 trace->Process(); | 372 trace->Process(); |
414 | 373 |
415 outputter_ref_ = NULL; | 374 outputter_ref_ = NULL; |
416 cpu_time_ref_ = NULL; | |
417 } | 375 } |
418 }; | 376 }; |
419 | 377 |
420 class GpuARBTimerTraceTest : public BaseGpuTraceTest { | 378 class GpuARBTimerTraceTest : public BaseGpuTraceTest { |
421 public: | 379 public: |
422 GpuARBTimerTraceTest() | 380 GpuARBTimerTraceTest() : BaseGpuTraceTest(GPUTiming::kTimerTypeARB) {} |
423 : BaseGpuTraceTest(kTracerTypeARBTimer) { | |
424 } | |
425 }; | 381 }; |
426 | 382 |
427 class GpuDisjointTimerTraceTest : public BaseGpuTraceTest { | 383 class GpuDisjointTimerTraceTest : public BaseGpuTraceTest { |
428 public: | 384 public: |
429 GpuDisjointTimerTraceTest() | 385 GpuDisjointTimerTraceTest() |
430 : BaseGpuTraceTest(kTracerTypeDisjointTimer) { | 386 : BaseGpuTraceTest(GPUTiming::kTimerTypeDisjoint) {} |
431 } | |
432 }; | 387 }; |
433 | 388 |
434 TEST_F(GpuARBTimerTraceTest, ARBTimerTraceTest) { | 389 TEST_F(GpuARBTimerTraceTest, ARBTimerTraceTest) { |
435 DoTraceTest(); | 390 DoTraceTest(); |
436 } | 391 } |
437 | 392 |
438 TEST_F(GpuDisjointTimerTraceTest, DisjointTimerTraceTest) { | 393 TEST_F(GpuDisjointTimerTraceTest, DisjointTimerTraceTest) { |
439 DoTraceTest(); | 394 DoTraceTest(); |
440 } | 395 } |
441 | 396 |
442 // Test GPUTracer calls all the correct gl calls. | 397 // Test GPUTracer calls all the correct gl calls. |
443 class BaseGpuTracerTest : public BaseGpuTest { | 398 class BaseGpuTracerTest : public BaseGpuTest { |
444 public: | 399 public: |
445 BaseGpuTracerTest(GpuTracerType test_tracer_type) | 400 explicit BaseGpuTracerTest(GPUTiming::TimerType test_timer_type) |
446 : BaseGpuTest(test_tracer_type) { | 401 : BaseGpuTest(test_timer_type) {} |
447 } | |
448 | 402 |
449 void DoBasicTracerTest() { | 403 void DoBasicTracerTest() { |
450 ExpectTracerOffsetQueryMocks(); | 404 ExpectTracerOffsetQueryMocks(); |
451 | 405 |
452 MockGLES2Decoder decoder; | 406 MockGLES2Decoder decoder; |
453 GPUTracerTester tracer(test_tracer_type_, &decoder); | 407 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); |
408 GPUTracerTester tracer(&decoder); | |
454 tracer.SetTracingEnabled(true); | 409 tracer.SetTracingEnabled(true); |
455 | 410 |
456 tracer.SetOutputter(outputter_ref_); | 411 tracer.SetOutputter(outputter_ref_); |
457 tracer.SetCPUTime(cpu_time_ref_); | |
458 | 412 |
459 ASSERT_TRUE(tracer.BeginDecoding()); | 413 ASSERT_TRUE(tracer.BeginDecoding()); |
460 ASSERT_TRUE(tracer.EndDecoding()); | 414 ASSERT_TRUE(tracer.EndDecoding()); |
461 | 415 |
462 outputter_ref_ = NULL; | 416 outputter_ref_ = NULL; |
463 cpu_time_ref_ = NULL; | |
464 } | 417 } |
465 | 418 |
466 void DoTracerMarkersTest() { | 419 void DoTracerMarkersTest() { |
467 ExpectTracerOffsetQueryMocks(); | 420 ExpectTracerOffsetQueryMocks(); |
468 | 421 |
469 EXPECT_CALL(*gl_, GetError()).Times(AtLeast(0)) | 422 EXPECT_CALL(*gl_, GetError()).Times(AtLeast(0)) |
470 .WillRepeatedly( | 423 .WillRepeatedly( |
471 Invoke(&gl_fake_queries_, &GlFakeQueries::GetError)); | 424 Invoke(&gl_fake_queries_, &GlFakeQueries::GetError)); |
472 | 425 |
473 const std::string category_name("trace_category"); | 426 const std::string category_name("trace_category"); |
474 const std::string trace_name("trace_test"); | 427 const std::string trace_name("trace_test"); |
475 const int64 offset_time = 3231; | 428 const int64 offset_time = 3231; |
476 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; | 429 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; |
477 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; | 430 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; |
478 const int64 expect_start_time = | 431 const int64 expect_start_time = |
479 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + | 432 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + |
480 offset_time; | 433 offset_time; |
481 const int64 expect_end_time = | 434 const int64 expect_end_time = |
482 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; | 435 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; |
483 | 436 |
484 MockGLES2Decoder decoder; | 437 MockGLES2Decoder decoder; |
485 GPUTracerTester tracer(test_tracer_type_, &decoder); | 438 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); |
439 GPUTracerTester tracer(&decoder); | |
486 tracer.SetTracingEnabled(true); | 440 tracer.SetTracingEnabled(true); |
487 | 441 |
488 tracer.SetOutputter(outputter_ref_); | 442 tracer.SetOutputter(outputter_ref_); |
489 tracer.SetCPUTime(cpu_time_ref_); | |
490 | 443 |
491 gl_fake_queries_.SetCurrentGLTime(start_timestamp); | 444 gl_fake_queries_.SetCurrentGLTime(start_timestamp); |
492 cpu_time_ref_->SetFakeCPUTime(expect_start_time); | 445 g_fakeCPUTime = expect_start_time; |
493 | 446 |
494 ASSERT_TRUE(tracer.BeginDecoding()); | 447 ASSERT_TRUE(tracer.BeginDecoding()); |
495 | 448 |
496 ExpectTraceQueryMocks(); | 449 ExpectTraceQueryMocks(); |
497 | 450 |
498 // This will test multiple marker sources which overlap one another. | 451 // This will test multiple marker sources which overlap one another. |
499 for (int i = 0; i < NUM_TRACER_SOURCES; ++i) { | 452 for (int i = 0; i < NUM_TRACER_SOURCES; ++i) { |
500 // Set times so each source has a different time. | 453 // Set times so each source has a different time. |
501 gl_fake_queries_.SetCurrentGLTime( | 454 gl_fake_queries_.SetCurrentGLTime( |
502 start_timestamp + | 455 start_timestamp + |
503 (i * base::Time::kNanosecondsPerMicrosecond)); | 456 (i * base::Time::kNanosecondsPerMicrosecond)); |
504 cpu_time_ref_->SetFakeCPUTime(expect_start_time + i); | 457 g_fakeCPUTime = expect_start_time + i; |
505 | 458 |
506 // Each trace name should be different to differentiate. | 459 // Each trace name should be different to differentiate. |
507 const char num_char = static_cast<char>('0' + i); | 460 const char num_char = static_cast<char>('0' + i); |
508 std::string source_category = category_name + num_char; | 461 std::string source_category = category_name + num_char; |
509 std::string source_trace_name = trace_name + num_char; | 462 std::string source_trace_name = trace_name + num_char; |
510 | 463 |
511 ExpectOutputterBeginMocks(outputter_ref_.get(), | 464 ExpectOutputterBeginMocks(outputter_ref_.get(), |
512 source_category, source_trace_name); | 465 source_category, source_trace_name); |
513 | 466 |
514 const GpuTracerSource source = static_cast<GpuTracerSource>(i); | 467 const GpuTracerSource source = static_cast<GpuTracerSource>(i); |
515 ASSERT_TRUE(tracer.Begin(source_category, source_trace_name, source)); | 468 ASSERT_TRUE(tracer.Begin(source_category, source_trace_name, source)); |
516 } | 469 } |
517 | 470 |
518 for (int i = 0; i < NUM_TRACER_SOURCES; ++i) { | 471 for (int i = 0; i < NUM_TRACER_SOURCES; ++i) { |
519 // Set times so each source has a different time. | 472 // Set times so each source has a different time. |
520 gl_fake_queries_.SetCurrentGLTime( | 473 gl_fake_queries_.SetCurrentGLTime( |
521 end_timestamp + | 474 end_timestamp + |
522 (i * base::Time::kNanosecondsPerMicrosecond)); | 475 (i * base::Time::kNanosecondsPerMicrosecond)); |
523 cpu_time_ref_->SetFakeCPUTime(expect_end_time + i); | 476 g_fakeCPUTime = expect_start_time + i; |
524 | 477 |
525 // Each trace name should be different to differentiate. | 478 // Each trace name should be different to differentiate. |
526 const char num_char = static_cast<char>('0' + i); | 479 const char num_char = static_cast<char>('0' + i); |
527 std::string source_category = category_name + num_char; | 480 std::string source_category = category_name + num_char; |
528 std::string source_trace_name = trace_name + num_char; | 481 std::string source_trace_name = trace_name + num_char; |
529 | 482 |
530 ExpectOutputterEndMocks(outputter_ref_.get(), source_category, | 483 ExpectOutputterEndMocks(outputter_ref_.get(), source_category, |
531 source_trace_name, | 484 source_trace_name, expect_start_time + i, |
532 expect_start_time + i, expect_end_time + i, | 485 expect_end_time + i, |
533 GetTracerType() != kTracerTypeInvalid); | 486 GetTimerType() != GPUTiming::kTimerTypeInvalid); |
534 | 487 |
535 const GpuTracerSource source = static_cast<GpuTracerSource>(i); | 488 const GpuTracerSource source = static_cast<GpuTracerSource>(i); |
536 | 489 |
537 // Check if the current category/name are correct for this source. | 490 // Check if the current category/name are correct for this source. |
538 ASSERT_EQ(source_category, tracer.CurrentCategory(source)); | 491 ASSERT_EQ(source_category, tracer.CurrentCategory(source)); |
539 ASSERT_EQ(source_trace_name, tracer.CurrentName(source)); | 492 ASSERT_EQ(source_trace_name, tracer.CurrentName(source)); |
540 | 493 |
541 ASSERT_TRUE(tracer.End(source)); | 494 ASSERT_TRUE(tracer.End(source)); |
542 } | 495 } |
543 | 496 |
544 ASSERT_TRUE(tracer.EndDecoding()); | 497 ASSERT_TRUE(tracer.EndDecoding()); |
545 | 498 |
546 outputter_ref_ = NULL; | 499 outputter_ref_ = NULL; |
547 cpu_time_ref_ = NULL; | |
548 } | 500 } |
549 | 501 |
550 void DoDisjointTest() { | 502 void DoDisjointTest() { |
551 // Cause a disjoint in a middle of a trace and expect no output calls. | 503 // Cause a disjoint in a middle of a trace and expect no output calls. |
552 ExpectTracerOffsetQueryMocks(); | 504 ExpectTracerOffsetQueryMocks(); |
553 | 505 |
554 EXPECT_CALL(*gl_, GetError()).Times(AtLeast(0)) | 506 EXPECT_CALL(*gl_, GetError()).Times(AtLeast(0)) |
555 .WillRepeatedly( | 507 .WillRepeatedly( |
556 Invoke(&gl_fake_queries_, &GlFakeQueries::GetError)); | 508 Invoke(&gl_fake_queries_, &GlFakeQueries::GetError)); |
557 | 509 |
558 const std::string category_name("trace_category"); | 510 const std::string category_name("trace_category"); |
559 const std::string trace_name("trace_test"); | 511 const std::string trace_name("trace_test"); |
560 const GpuTracerSource source = static_cast<GpuTracerSource>(0); | 512 const GpuTracerSource source = static_cast<GpuTracerSource>(0); |
561 const int64 offset_time = 3231; | 513 const int64 offset_time = 3231; |
562 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; | 514 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; |
563 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; | 515 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; |
564 const int64 expect_start_time = | 516 const int64 expect_start_time = |
565 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + | 517 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + |
566 offset_time; | 518 offset_time; |
567 const int64 expect_end_time = | 519 const int64 expect_end_time = |
568 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; | 520 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; |
569 | 521 |
570 MockGLES2Decoder decoder; | 522 MockGLES2Decoder decoder; |
571 GPUTracerTester tracer(test_tracer_type_, &decoder); | 523 EXPECT_CALL(decoder, GetGLContext()).WillOnce(Return(GetGLContext())); |
524 GPUTracerTester tracer(&decoder); | |
572 tracer.SetTracingEnabled(true); | 525 tracer.SetTracingEnabled(true); |
573 | 526 |
574 tracer.SetOutputter(outputter_ref_); | 527 tracer.SetOutputter(outputter_ref_); |
575 tracer.SetCPUTime(cpu_time_ref_); | |
576 | 528 |
577 gl_fake_queries_.SetCurrentGLTime(start_timestamp); | 529 gl_fake_queries_.SetCurrentGLTime(start_timestamp); |
578 cpu_time_ref_->SetFakeCPUTime(expect_start_time); | 530 g_fakeCPUTime = expect_start_time; |
579 | 531 |
580 ASSERT_TRUE(tracer.BeginDecoding()); | 532 ASSERT_TRUE(tracer.BeginDecoding()); |
581 | 533 |
582 ExpectTraceQueryMocks(); | 534 ExpectTraceQueryMocks(); |
583 | 535 |
584 ExpectOutputterBeginMocks(outputter_ref_.get(), | 536 ExpectOutputterBeginMocks(outputter_ref_.get(), |
585 category_name, trace_name); | 537 category_name, trace_name); |
586 ASSERT_TRUE(tracer.Begin(category_name, trace_name, source)); | 538 ASSERT_TRUE(tracer.Begin(category_name, trace_name, source)); |
587 | 539 |
588 gl_fake_queries_.SetCurrentGLTime(end_timestamp); | 540 gl_fake_queries_.SetCurrentGLTime(end_timestamp); |
589 cpu_time_ref_->SetFakeCPUTime(expect_end_time); | 541 g_fakeCPUTime = expect_end_time; |
590 gl_fake_queries_.SetDisjoint(); | 542 gl_fake_queries_.SetDisjoint(); |
591 | 543 |
592 ExpectOutputterEndMocks(outputter_ref_.get(), category_name, trace_name, | 544 ExpectOutputterEndMocks(outputter_ref_.get(), category_name, trace_name, |
593 expect_start_time, expect_end_time, false); | 545 expect_start_time, expect_end_time, false); |
594 | 546 |
595 ASSERT_TRUE(tracer.End(source)); | 547 ASSERT_TRUE(tracer.End(source)); |
596 ASSERT_TRUE(tracer.EndDecoding()); | 548 ASSERT_TRUE(tracer.EndDecoding()); |
597 | 549 |
598 outputter_ref_ = NULL; | 550 outputter_ref_ = NULL; |
599 cpu_time_ref_ = NULL; | |
600 } | 551 } |
601 }; | 552 }; |
602 | 553 |
603 class InvalidTimerTracerTest : public BaseGpuTracerTest { | 554 class InvalidTimerTracerTest : public BaseGpuTracerTest { |
604 public: | 555 public: |
605 InvalidTimerTracerTest() | 556 InvalidTimerTracerTest() : BaseGpuTracerTest(GPUTiming::kTimerTypeInvalid) {} |
606 : BaseGpuTracerTest(kTracerTypeInvalid) { | |
607 } | |
608 }; | 557 }; |
609 | 558 |
610 class GpuARBTimerTracerTest : public BaseGpuTracerTest { | 559 class GpuARBTimerTracerTest : public BaseGpuTracerTest { |
611 public: | 560 public: |
612 GpuARBTimerTracerTest() | 561 GpuARBTimerTracerTest() : BaseGpuTracerTest(GPUTiming::kTimerTypeARB) {} |
613 : BaseGpuTracerTest(kTracerTypeARBTimer) { | |
614 } | |
615 }; | 562 }; |
616 | 563 |
617 class GpuDisjointTimerTracerTest : public BaseGpuTracerTest { | 564 class GpuDisjointTimerTracerTest : public BaseGpuTracerTest { |
618 public: | 565 public: |
619 GpuDisjointTimerTracerTest() | 566 GpuDisjointTimerTracerTest() |
620 : BaseGpuTracerTest(kTracerTypeDisjointTimer) { | 567 : BaseGpuTracerTest(GPUTiming::kTimerTypeDisjoint) {} |
621 } | |
622 }; | 568 }; |
623 | 569 |
624 TEST_F(InvalidTimerTracerTest, InvalidTimerBasicTracerTest) { | 570 TEST_F(InvalidTimerTracerTest, InvalidTimerBasicTracerTest) { |
625 DoBasicTracerTest(); | 571 DoBasicTracerTest(); |
626 } | 572 } |
627 | 573 |
628 TEST_F(GpuARBTimerTracerTest, ARBTimerBasicTracerTest) { | 574 TEST_F(GpuARBTimerTracerTest, ARBTimerBasicTracerTest) { |
629 DoBasicTracerTest(); | 575 DoBasicTracerTest(); |
630 } | 576 } |
631 | 577 |
(...skipping 10 matching lines...) Expand all Loading... | |
642 } | 588 } |
643 | 589 |
644 TEST_F(GpuDisjointTimerTracerTest, DisjointTimerBasicTracerMarkersTest) { | 590 TEST_F(GpuDisjointTimerTracerTest, DisjointTimerBasicTracerMarkersTest) { |
645 DoTracerMarkersTest(); | 591 DoTracerMarkersTest(); |
646 } | 592 } |
647 | 593 |
648 TEST_F(GpuDisjointTimerTracerTest, DisjointTimerDisjointTraceTest) { | 594 TEST_F(GpuDisjointTimerTracerTest, DisjointTimerDisjointTraceTest) { |
649 DoDisjointTest(); | 595 DoDisjointTest(); |
650 } | 596 } |
651 | 597 |
598 class GPUTracerTest : public GpuServiceTest { | |
599 protected: | |
600 void SetUp() override { | |
601 GpuServiceTest::SetUpWithGLVersion("3.2", ""); | |
602 decoder_.reset(new MockGLES2Decoder()); | |
603 EXPECT_CALL(*decoder_, GetGLContext()) | |
604 .Times(AtMost(1)) | |
605 .WillRepeatedly(Return(GetGLContext())); | |
606 tracer_tester_.reset(new GPUTracerTester(decoder_.get())); | |
607 } | |
608 | |
609 void TearDown() override { | |
610 tracer_tester_ = nullptr; | |
611 decoder_ = nullptr; | |
612 GpuServiceTest::TearDown(); | |
613 } | |
614 scoped_ptr<MockGLES2Decoder> decoder_; | |
615 scoped_ptr<GPUTracerTester> tracer_tester_; | |
616 }; | |
617 | |
618 TEST_F(GPUTracerTest, IsTracingTest) { | |
619 EXPECT_FALSE(tracer_tester_->IsTracing()); | |
620 tracer_tester_->SetTracingEnabled(true); | |
621 EXPECT_TRUE(tracer_tester_->IsTracing()); | |
622 } | |
652 // Test basic functionality of the GPUTracerTester. | 623 // Test basic functionality of the GPUTracerTester. |
653 TEST(GPUTracerTester, IsTracingTest) { | 624 TEST_F(GPUTracerTest, DecodeTest) { |
654 MockGLES2Decoder decoder; | 625 ASSERT_TRUE(tracer_tester_->BeginDecoding()); |
655 GPUTracerTester tracer_tester(kTracerTypeInvalid, &decoder); | 626 EXPECT_FALSE(tracer_tester_->BeginDecoding()); |
656 EXPECT_FALSE(tracer_tester.IsTracing()); | 627 ASSERT_TRUE(tracer_tester_->EndDecoding()); |
657 tracer_tester.SetTracingEnabled(true); | 628 EXPECT_FALSE(tracer_tester_->EndDecoding()); |
658 EXPECT_TRUE(tracer_tester.IsTracing()); | |
659 } | 629 } |
660 | 630 |
661 TEST(GPUTracerTester, DecodeTest) { | 631 TEST_F(GPUTracerTest, TraceDuringDecodeTest) { |
662 MockGLES2Decoder decoder; | |
663 GPUTracerTester tracer_tester(kTracerTypeInvalid, &decoder); | |
664 ASSERT_TRUE(tracer_tester.BeginDecoding()); | |
665 EXPECT_FALSE(tracer_tester.BeginDecoding()); | |
666 ASSERT_TRUE(tracer_tester.EndDecoding()); | |
667 EXPECT_FALSE(tracer_tester.EndDecoding()); | |
668 } | |
669 | |
670 TEST(GPUTracerTester, TraceDuringDecodeTest) { | |
671 MockGLES2Decoder decoder; | |
672 GPUTracerTester tracer_tester(kTracerTypeInvalid, &decoder); | |
673 const std::string category_name("trace_category"); | 632 const std::string category_name("trace_category"); |
674 const std::string trace_name("trace_test"); | 633 const std::string trace_name("trace_test"); |
675 | 634 |
676 EXPECT_FALSE(tracer_tester.Begin(category_name, trace_name, | 635 EXPECT_FALSE( |
677 kTraceGroupMarker)); | 636 tracer_tester_->Begin(category_name, trace_name, kTraceGroupMarker)); |
678 | 637 |
679 ASSERT_TRUE(tracer_tester.BeginDecoding()); | 638 ASSERT_TRUE(tracer_tester_->BeginDecoding()); |
680 EXPECT_TRUE(tracer_tester.Begin(category_name, trace_name, | 639 EXPECT_TRUE( |
681 kTraceGroupMarker)); | 640 tracer_tester_->Begin(category_name, trace_name, kTraceGroupMarker)); |
682 ASSERT_TRUE(tracer_tester.EndDecoding()); | 641 ASSERT_TRUE(tracer_tester_->EndDecoding()); |
683 } | 642 } |
684 | 643 |
644 } // namespace | |
685 } // namespace gles2 | 645 } // namespace gles2 |
686 } // namespace gpu | 646 } // namespace gpu |
OLD | NEW |