Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: gpu/command_buffer/service/gpu_tracer_unittest.cc

Issue 1162203006: Unit tests have been created for the GPUTiming. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reverted egl unit test changes, wrong cl Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/gl/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
6 #include <set>
7
8 #include "base/bind.h" 5 #include "base/bind.h"
9 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" 6 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h"
10 #include "gpu/command_buffer/service/gpu_service_test.h" 7 #include "gpu/command_buffer/service/gpu_service_test.h"
11 #include "gpu/command_buffer/service/gpu_tracer.h" 8 #include "gpu/command_buffer/service/gpu_tracer.h"
12 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gl/gl_mock.h" 10 #include "ui/gl/gl_mock.h"
14 #include "ui/gl/gpu_timing.h" 11 #include "ui/gl/gpu_timing.h"
12 #include "ui/gl/gpu_timing_fake.h"
15 13
16 namespace gpu { 14 namespace gpu {
17 namespace gles2 { 15 namespace gles2 {
18 namespace { 16 namespace {
19 17
20 using ::testing::_; 18 using ::testing::_;
21 using ::testing::AtLeast;
22 using ::testing::AtMost; 19 using ::testing::AtMost;
23 using ::testing::Exactly; 20 using ::testing::Exactly;
24 using ::testing::Invoke; 21 using ::testing::Invoke;
25 using ::testing::NotNull;
26 using ::testing::Return; 22 using ::testing::Return;
27 23
28 int64 g_fakeCPUTime = 0; 24 int64 g_fakeCPUTime = 0;
29 int64 FakeCpuTime() { 25 int64 FakeCpuTime() {
30 return g_fakeCPUTime; 26 return g_fakeCPUTime;
31 } 27 }
32 28
33 class MockOutputter : public Outputter { 29 class MockOutputter : public Outputter {
34 public: 30 public:
35 MockOutputter() {} 31 MockOutputter() {}
36 MOCK_METHOD5(TraceDevice, 32 MOCK_METHOD5(TraceDevice,
37 void(GpuTracerSource source, 33 void(GpuTracerSource source,
38 const std::string& category, const std::string& name, 34 const std::string& category, const std::string& name,
39 int64 start_time, int64 end_time)); 35 int64 start_time, int64 end_time));
40 36
41 MOCK_METHOD3(TraceServiceBegin, 37 MOCK_METHOD3(TraceServiceBegin,
42 void(GpuTracerSource source, 38 void(GpuTracerSource source,
43 const std::string& category, const std::string& name)); 39 const std::string& category, const std::string& name));
44 40
45 MOCK_METHOD3(TraceServiceEnd, 41 MOCK_METHOD3(TraceServiceEnd,
46 void(GpuTracerSource source, 42 void(GpuTracerSource source,
47 const std::string& category, const std::string& name)); 43 const std::string& category, const std::string& name));
48 44
49 protected: 45 protected:
50 ~MockOutputter() {} 46 ~MockOutputter() {}
51 }; 47 };
52 48
53 class GlFakeQueries {
54 public:
55 GlFakeQueries() {}
56
57 void Reset() {
58 current_time_ = 0;
59 next_query_id_ = 23;
60 alloced_queries_.clear();
61 query_timestamp_.clear();
62 }
63
64 void SetCurrentGLTime(GLint64 current_time) { current_time_ = current_time; }
65 void SetDisjoint() { disjointed_ = true; }
66
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]);
71 }
72 }
73
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]);
78 }
79 }
80
81 void GetQueryObjectiv(GLuint id, GLenum pname, GLint* params) {
82 switch (pname) {
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_)
86 *params = 1;
87 else
88 *params = 0;
89 break;
90 }
91 default:
92 FAIL() << "Invalid variable passed to GetQueryObjectiv: " << pname;
93 }
94 }
95
96 void QueryCounter(GLuint id, GLenum target) {
97 switch (target) {
98 case GL_TIMESTAMP:
99 ASSERT_TRUE(alloced_queries_.find(id) != alloced_queries_.end());
100 query_timestamp_[id] = current_time_;
101 break;
102 default:
103 FAIL() << "Invalid variable passed to QueryCounter: " << target;
104 }
105 }
106
107 void GetInteger64v(GLenum pname, GLint64 * data) {
108 switch (pname) {
109 case GL_TIMESTAMP:
110 *data = current_time_;
111 break;
112 default:
113 FAIL() << "Invalid variable passed to GetInteger64v: " << pname;
114 }
115 }
116
117 void GetQueryObjectui64v(GLuint id, GLenum pname, GLuint64* params) {
118 switch (pname) {
119 case GL_QUERY_RESULT:
120 ASSERT_TRUE(query_timestamp_.find(id) != query_timestamp_.end());
121 *params = query_timestamp_.find(id)->second;
122 break;
123 default:
124 FAIL() << "Invalid variable passed to GetQueryObjectui64v: " << pname;
125 }
126 }
127
128 void GetIntegerv(GLenum pname, GLint* params) {
129 switch (pname) {
130 case GL_GPU_DISJOINT_EXT:
131 *params = static_cast<GLint>(disjointed_);
132 disjointed_ = false;
133 break;
134 default:
135 FAIL() << "Invalid variable passed to GetIntegerv: " << pname;
136 }
137 }
138
139 void Finish() {
140 }
141
142 GLenum GetError() {
143 return GL_NO_ERROR;
144 }
145
146 protected:
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_;
152 };
153
154 class GPUTracerTester : public GPUTracer { 49 class GPUTracerTester : public GPUTracer {
155 public: 50 public:
156 explicit GPUTracerTester(gles2::GLES2Decoder* decoder) 51 explicit GPUTracerTester(gles2::GLES2Decoder* decoder)
157 : GPUTracer(decoder), tracing_enabled_(0) { 52 : GPUTracer(decoder), tracing_enabled_(0) {
158 gpu_timing_client_->SetCpuTimeForTesting(base::Bind(&FakeCpuTime)); 53 gpu_timing_client_->SetCpuTimeForTesting(base::Bind(&FakeCpuTime));
159 54
160 // Force tracing to be dependent on our mock variable here. 55 // Force tracing to be dependent on our mock variable here.
161 gpu_trace_srv_category = &tracing_enabled_; 56 gpu_trace_srv_category = &tracing_enabled_;
162 gpu_trace_dev_category = &tracing_enabled_; 57 gpu_trace_dev_category = &tracing_enabled_;
163 } 58 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 gl_version = "opengl es 3.0"; 103 gl_version = "opengl es 3.0";
209 extensions = "GL_EXT_disjoint_timer_query"; 104 extensions = "GL_EXT_disjoint_timer_query";
210 } else if (GetTimerType() == gfx::GPUTiming::kTimerTypeARB) { 105 } else if (GetTimerType() == gfx::GPUTiming::kTimerTypeARB) {
211 // TODO(sievers): The tracer should not depend on ARB_occlusion_query. 106 // TODO(sievers): The tracer should not depend on ARB_occlusion_query.
212 // Try merge Query APIs (core, ARB, EXT) into a single binding each. 107 // Try merge Query APIs (core, ARB, EXT) into a single binding each.
213 extensions = "GL_ARB_timer_query GL_ARB_occlusion_query"; 108 extensions = "GL_ARB_timer_query GL_ARB_occlusion_query";
214 } 109 }
215 GpuServiceTest::SetUpWithGLVersion(gl_version, extensions); 110 GpuServiceTest::SetUpWithGLVersion(gl_version, extensions);
216 111
217 // Disjoint check should only be called by kTracerTypeDisjointTimer type. 112 // Disjoint check should only be called by kTracerTypeDisjointTimer type.
218 if (GetTimerType() == gfx::GPUTiming::kTimerTypeDisjoint) { 113 if (GetTimerType() == gfx::GPUTiming::kTimerTypeDisjoint)
219 EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(AtLeast(1)) 114 gl_fake_queries_.ExpectDisjointCalls(*gl_);
220 .WillRepeatedly( 115 else
221 Invoke(&gl_fake_queries_, &GlFakeQueries::GetIntegerv)); 116 gl_fake_queries_.ExpectNoDisjointCalls(*gl_);
222 } else { 117
223 EXPECT_CALL(*gl_, GetIntegerv(GL_GPU_DISJOINT_EXT, _)).Times(Exactly(0));
224 }
225 gpu_timing_client_ = GetGLContext()->CreateGPUTimingClient(); 118 gpu_timing_client_ = GetGLContext()->CreateGPUTimingClient();
226 gpu_timing_client_->SetCpuTimeForTesting(base::Bind(&FakeCpuTime)); 119 gpu_timing_client_->SetCpuTimeForTesting(base::Bind(&FakeCpuTime));
227 gl_fake_queries_.Reset(); 120 gl_fake_queries_.Reset();
228 121
229 outputter_ref_ = new MockOutputter(); 122 outputter_ref_ = new MockOutputter();
230 } 123 }
231 124
232 void TearDown() override { 125 void TearDown() override {
233 outputter_ref_ = NULL; 126 outputter_ref_ = NULL;
234 gpu_timing_client_ = NULL; 127 gpu_timing_client_ = NULL;
235 128
236 gl_fake_queries_.Reset(); 129 gl_fake_queries_.Reset();
237 GpuServiceTest::TearDown(); 130 GpuServiceTest::TearDown();
238 } 131 }
239 132
240 void ExpectTraceQueryMocks() { 133 void ExpectTraceQueryMocks() {
241 if (gpu_timing_client_->IsAvailable() && 134 if (gpu_timing_client_->IsAvailable()) {
242 gpu_timing_client_->IsTimerOffsetAvailable()) {
243 // Delegate query APIs used by GPUTrace to a GlFakeQueries 135 // Delegate query APIs used by GPUTrace to a GlFakeQueries
244 EXPECT_CALL(*gl_, GenQueries(2, NotNull())).Times(AtLeast(1)) 136 const bool elapsed = (GetTimerType() == gfx::GPUTiming::kTimerTypeEXT);
245 .WillRepeatedly( 137 gl_fake_queries_.ExpectGPUTimerQuery(*gl_, elapsed);
246 Invoke(&gl_fake_queries_, &GlFakeQueries::GenQueries));
247
248 EXPECT_CALL(*gl_, GetQueryObjectiv(_, GL_QUERY_RESULT_AVAILABLE,
249 NotNull()))
250 .WillRepeatedly(
251 Invoke(&gl_fake_queries_, &GlFakeQueries::GetQueryObjectiv));
252
253 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, _))
254 .WillRepeatedly(
255 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v));
256
257 EXPECT_CALL(*gl_, QueryCounter(_, GL_TIMESTAMP)).Times(AtLeast(2))
258 .WillRepeatedly(
259 Invoke(&gl_fake_queries_, &GlFakeQueries::QueryCounter));
260
261 EXPECT_CALL(*gl_, GetQueryObjectui64v(_, GL_QUERY_RESULT, NotNull()))
262 .WillRepeatedly(
263 Invoke(&gl_fake_queries_,
264 &GlFakeQueries::GetQueryObjectui64v));
265
266 EXPECT_CALL(*gl_, DeleteQueries(2, NotNull())).Times(AtLeast(1))
267 .WillRepeatedly(
268 Invoke(&gl_fake_queries_, &GlFakeQueries::DeleteQueries));
269 } 138 }
270 } 139 }
271 140
272 void ExpectOutputterBeginMocks(MockOutputter* outputter, 141 void ExpectOutputterBeginMocks(MockOutputter* outputter,
273 GpuTracerSource source, 142 GpuTracerSource source,
274 const std::string& category, 143 const std::string& category,
275 const std::string& name) { 144 const std::string& name) {
276 EXPECT_CALL(*outputter, 145 EXPECT_CALL(*outputter,
277 TraceServiceBegin(source, category, name)); 146 TraceServiceBegin(source, category, name));
278 } 147 }
279 148
280 void ExpectOutputterEndMocks(MockOutputter* outputter, 149 void ExpectOutputterEndMocks(MockOutputter* outputter,
281 GpuTracerSource source, 150 GpuTracerSource source,
282 const std::string& category, 151 const std::string& category,
283 const std::string& name, int64 expect_start_time, 152 const std::string& name, int64 expect_start_time,
284 int64 expect_end_time, 153 int64 expect_end_time,
154 bool trace_service,
285 bool trace_device) { 155 bool trace_device) {
286 EXPECT_CALL(*outputter, 156 if (trace_service) {
287 TraceServiceEnd(source, category, name)); 157 EXPECT_CALL(*outputter,
158 TraceServiceEnd(source, category, name));
159 }
288 160
289 if (trace_device) { 161 if (trace_device) {
290 EXPECT_CALL(*outputter, 162 EXPECT_CALL(*outputter,
291 TraceDevice(source, category, name, 163 TraceDevice(source, category, name,
292 expect_start_time, expect_end_time)) 164 expect_start_time, expect_end_time))
293 .Times(Exactly(1)); 165 .Times(Exactly(1));
294 } else { 166 } else {
295 EXPECT_CALL(*outputter, TraceDevice(source, category, name, 167 EXPECT_CALL(*outputter, TraceDevice(source, category, name,
296 expect_start_time, expect_end_time)) 168 expect_start_time, expect_end_time))
297 .Times(Exactly(0)); 169 .Times(Exactly(0));
298 } 170 }
299 } 171 }
300 172
301 void ExpectOutputterMocks(MockOutputter* outputter, 173 void ExpectOutputterMocks(MockOutputter* outputter,
174 bool tracing_service,
302 bool tracing_device, 175 bool tracing_device,
303 GpuTracerSource source, 176 GpuTracerSource source,
304 const std::string& category, 177 const std::string& category,
305 const std::string& name, int64 expect_start_time, 178 const std::string& name, int64 expect_start_time,
306 int64 expect_end_time) { 179 int64 expect_end_time) {
307 ExpectOutputterBeginMocks(outputter, source, category, name); 180 if (tracing_service)
308 bool valid_timer = tracing_device && 181 ExpectOutputterBeginMocks(outputter, source, category, name);
309 gpu_timing_client_->IsAvailable() && 182 const bool valid_timer = tracing_device &&
310 gpu_timing_client_->IsTimerOffsetAvailable(); 183 gpu_timing_client_->IsAvailable() &&
184 GetTimerType() != gfx::GPUTiming::kTimerTypeEXT;
311 ExpectOutputterEndMocks(outputter, source, category, name, 185 ExpectOutputterEndMocks(outputter, source, category, name,
312 expect_start_time, expect_end_time, valid_timer); 186 expect_start_time, expect_end_time,
187 tracing_service, valid_timer);
313 } 188 }
314 189
315 void ExpectTracerOffsetQueryMocks() { 190 void ExpectTracerOffsetQueryMocks() {
316 if (GetTimerType() != gfx::GPUTiming::kTimerTypeARB) { 191 if (GetTimerType() != gfx::GPUTiming::kTimerTypeARB) {
317 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) 192 gl_fake_queries_.ExpectNoOffsetCalculationQuery(*gl_);
318 .Times(Exactly(0));
319 } else { 193 } else {
320 EXPECT_CALL(*gl_, GetInteger64v(GL_TIMESTAMP, NotNull())) 194 gl_fake_queries_.ExpectOffsetCalculationQuery(*gl_);
321 .Times(AtMost(1))
322 .WillRepeatedly(
323 Invoke(&gl_fake_queries_, &GlFakeQueries::GetInteger64v));
324 } 195 }
325 } 196 }
326 197
327 gfx::GPUTiming::TimerType GetTimerType() { return test_timer_type_; } 198 gfx::GPUTiming::TimerType GetTimerType() { return test_timer_type_; }
328 199
329 gfx::GPUTiming::TimerType test_timer_type_; 200 gfx::GPUTiming::TimerType test_timer_type_;
330 GlFakeQueries gl_fake_queries_; 201 gfx::GPUTimingFake gl_fake_queries_;
331 202
332 scoped_refptr<gfx::GPUTimingClient> gpu_timing_client_; 203 scoped_refptr<gfx::GPUTimingClient> gpu_timing_client_;
333 scoped_refptr<MockOutputter> outputter_ref_; 204 scoped_refptr<MockOutputter> outputter_ref_;
334 }; 205 };
335 206
336 // Test GPUTrace calls all the correct gl calls. 207 // Test GPUTrace calls all the correct gl calls.
337 class BaseGpuTraceTest : public BaseGpuTest { 208 class BaseGpuTraceTest : public BaseGpuTest {
338 public: 209 public:
339 explicit BaseGpuTraceTest(gfx::GPUTiming::TimerType test_timer_type) 210 explicit BaseGpuTraceTest(gfx::GPUTiming::TimerType test_timer_type)
340 : BaseGpuTest(test_timer_type) {} 211 : BaseGpuTest(test_timer_type) {}
341 212
342 void DoTraceTest(bool tracing_service, bool tracing_device) { 213 void DoTraceTest(bool tracing_service, bool tracing_device) {
343 // Expected results 214 // Expected results
344 const GpuTracerSource tracer_source = kTraceGroupMarker; 215 const GpuTracerSource tracer_source = kTraceGroupMarker;
345 const std::string category_name("trace_category"); 216 const std::string category_name("trace_category");
346 const std::string trace_name("trace_test"); 217 const std::string trace_name("trace_test");
347 const int64 offset_time = 3231; 218 const int64 offset_time = 3231;
348 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; 219 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond;
349 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; 220 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond;
350 const int64 expect_start_time = 221 const int64 expect_start_time =
351 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + 222 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) +
352 offset_time; 223 offset_time;
353 const int64 expect_end_time = 224 const int64 expect_end_time =
354 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time; 225 (end_timestamp / base::Time::kNanosecondsPerMicrosecond) + offset_time;
355 226
356 if (tracing_service) 227 ExpectOutputterMocks(outputter_ref_.get(), tracing_service, tracing_device,
357 ExpectOutputterMocks(outputter_ref_.get(), tracing_device, tracer_source, 228 tracer_source, category_name, trace_name,
358 category_name, trace_name, 229 expect_start_time, expect_end_time);
359 expect_start_time, expect_end_time);
360 230
361 if (tracing_device) 231 if (tracing_device)
362 ExpectTraceQueryMocks(); 232 ExpectTraceQueryMocks();
363 233
364 scoped_refptr<GPUTrace> trace = new GPUTrace( 234 scoped_refptr<GPUTrace> trace = new GPUTrace(
365 outputter_ref_, gpu_timing_client_.get(), tracer_source, 235 outputter_ref_, gpu_timing_client_.get(), tracer_source,
366 category_name, trace_name, tracing_service, tracing_device); 236 category_name, trace_name, tracing_service, tracing_device);
367 237
368 gl_fake_queries_.SetCurrentGLTime(start_timestamp); 238 gl_fake_queries_.SetCurrentGLTime(start_timestamp);
369 g_fakeCPUTime = expect_start_time; 239 g_fakeCPUTime = expect_start_time;
370 trace->Start(); 240 trace->Start();
371 241
372 // Shouldn't be available before End() call 242 // Shouldn't be available before End() call
373 gl_fake_queries_.SetCurrentGLTime(end_timestamp); 243 gl_fake_queries_.SetCurrentGLTime(end_timestamp);
374 g_fakeCPUTime = expect_end_time; 244 g_fakeCPUTime = expect_end_time;
375 if (tracing_device) 245 if (tracing_device)
376 EXPECT_FALSE(trace->IsAvailable()); 246 EXPECT_FALSE(trace->IsAvailable());
377 247
378 trace->End(); 248 trace->End();
379 249
380 // Shouldn't be available until the queries complete 250 // Shouldn't be available until the queries complete
381 gl_fake_queries_.SetCurrentGLTime(end_timestamp - 251 gl_fake_queries_.SetCurrentGLTime(end_timestamp -
382 base::Time::kNanosecondsPerMicrosecond); 252 base::Time::kNanosecondsPerMicrosecond);
253 g_fakeCPUTime = expect_end_time - 1;
383 if (tracing_device) 254 if (tracing_device)
384 EXPECT_FALSE(trace->IsAvailable()); 255 EXPECT_FALSE(trace->IsAvailable());
385 256
386 // Now it should be available 257 // Now it should be available
387 gl_fake_queries_.SetCurrentGLTime(end_timestamp); 258 gl_fake_queries_.SetCurrentGLTime(end_timestamp);
259 g_fakeCPUTime = expect_end_time;
388 EXPECT_TRUE(trace->IsAvailable()); 260 EXPECT_TRUE(trace->IsAvailable());
389 261
390 // Proces should output expected Trace results to MockOutputter 262 // Proces should output expected Trace results to MockOutputter
391 trace->Process(); 263 trace->Process();
392 264
393 // Destroy trace after we are done. 265 // Destroy trace after we are done.
394 trace->Destroy(true); 266 trace->Destroy(true);
395 267
396 outputter_ref_ = NULL; 268 outputter_ref_ = NULL;
397 } 269 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 tracer.SetOutputter(outputter_ref_); 329 tracer.SetOutputter(outputter_ref_);
458 330
459 ASSERT_TRUE(tracer.BeginDecoding()); 331 ASSERT_TRUE(tracer.BeginDecoding());
460 ASSERT_TRUE(tracer.EndDecoding()); 332 ASSERT_TRUE(tracer.EndDecoding());
461 333
462 outputter_ref_ = NULL; 334 outputter_ref_ = NULL;
463 } 335 }
464 336
465 void DoTracerMarkersTest() { 337 void DoTracerMarkersTest() {
466 ExpectTracerOffsetQueryMocks(); 338 ExpectTracerOffsetQueryMocks();
467 339 gl_fake_queries_.ExpectGetErrorCalls(*gl_);
468 EXPECT_CALL(*gl_, GetError()).Times(AtLeast(0))
469 .WillRepeatedly(
470 Invoke(&gl_fake_queries_, &GlFakeQueries::GetError));
471 340
472 const std::string category_name("trace_category"); 341 const std::string category_name("trace_category");
473 const std::string trace_name("trace_test"); 342 const std::string trace_name("trace_test");
474 const int64 offset_time = 3231; 343 const int64 offset_time = 3231;
475 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; 344 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond;
476 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; 345 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond;
477 const int64 expect_start_time = 346 const int64 expect_start_time =
478 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + 347 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) +
479 offset_time; 348 offset_time;
480 const int64 expect_end_time = 349 const int64 expect_end_time =
(...skipping 24 matching lines...) Expand all
505 // Each trace name should be different to differentiate. 374 // Each trace name should be different to differentiate.
506 const char num_char = static_cast<char>('0' + i); 375 const char num_char = static_cast<char>('0' + i);
507 std::string source_category = category_name + num_char; 376 std::string source_category = category_name + num_char;
508 std::string source_trace_name = trace_name + num_char; 377 std::string source_trace_name = trace_name + num_char;
509 378
510 const GpuTracerSource source = static_cast<GpuTracerSource>(i); 379 const GpuTracerSource source = static_cast<GpuTracerSource>(i);
511 ExpectOutputterBeginMocks(outputter_ref_.get(), source, 380 ExpectOutputterBeginMocks(outputter_ref_.get(), source,
512 source_category, source_trace_name); 381 source_category, source_trace_name);
513 ASSERT_TRUE(tracer.Begin(source_category, source_trace_name, source)); 382 ASSERT_TRUE(tracer.Begin(source_category, source_trace_name, source));
514 } 383 }
515
516 for (int i = 0; i < NUM_TRACER_SOURCES; ++i) { 384 for (int i = 0; i < NUM_TRACER_SOURCES; ++i) {
517 // Set times so each source has a different time. 385 // Set times so each source has a different time.
518 gl_fake_queries_.SetCurrentGLTime( 386 gl_fake_queries_.SetCurrentGLTime(
519 end_timestamp + 387 end_timestamp +
520 (i * base::Time::kNanosecondsPerMicrosecond)); 388 (i * base::Time::kNanosecondsPerMicrosecond));
521 g_fakeCPUTime = expect_end_time + i; 389 g_fakeCPUTime = expect_end_time + i;
522 390
523 // Each trace name should be different to differentiate. 391 // Each trace name should be different to differentiate.
524 const char num_char = static_cast<char>('0' + i); 392 const char num_char = static_cast<char>('0' + i);
525 std::string source_category = category_name + num_char; 393 std::string source_category = category_name + num_char;
526 std::string source_trace_name = trace_name + num_char; 394 std::string source_trace_name = trace_name + num_char;
527 395
528 bool valid_timer = gpu_timing_client_->IsAvailable() && 396 const bool valid_timer = gpu_timing_client_->IsAvailable() &&
529 gpu_timing_client_->IsTimerOffsetAvailable(); 397 GetTimerType() != gfx::GPUTiming::kTimerTypeEXT;
530 398
531 const GpuTracerSource source = static_cast<GpuTracerSource>(i); 399 const GpuTracerSource source = static_cast<GpuTracerSource>(i);
532 ExpectOutputterEndMocks(outputter_ref_.get(), source, source_category, 400 ExpectOutputterEndMocks(outputter_ref_.get(), source, source_category,
533 source_trace_name, expect_start_time + i, 401 source_trace_name, expect_start_time + i,
534 expect_end_time + i, valid_timer); 402 expect_end_time + i, true, valid_timer);
535
536 // Check if the current category/name are correct for this source. 403 // Check if the current category/name are correct for this source.
537 ASSERT_EQ(source_category, tracer.CurrentCategory(source)); 404 ASSERT_EQ(source_category, tracer.CurrentCategory(source));
538 ASSERT_EQ(source_trace_name, tracer.CurrentName(source)); 405 ASSERT_EQ(source_trace_name, tracer.CurrentName(source));
539 406
540 ASSERT_TRUE(tracer.End(source)); 407 ASSERT_TRUE(tracer.End(source));
541 } 408 }
542
543 ASSERT_TRUE(tracer.EndDecoding()); 409 ASSERT_TRUE(tracer.EndDecoding());
544
545 outputter_ref_ = NULL; 410 outputter_ref_ = NULL;
546 } 411 }
547 412
548 void DoDisjointTest() { 413 void DoDisjointTest() {
549 // Cause a disjoint in a middle of a trace and expect no output calls. 414 // Cause a disjoint in a middle of a trace and expect no output calls.
550 ExpectTracerOffsetQueryMocks(); 415 ExpectTracerOffsetQueryMocks();
551 416 gl_fake_queries_.ExpectGetErrorCalls(*gl_);
552 EXPECT_CALL(*gl_, GetError()).Times(AtLeast(0))
553 .WillRepeatedly(
554 Invoke(&gl_fake_queries_, &GlFakeQueries::GetError));
555 417
556 const GpuTracerSource tracer_source = kTraceGroupMarker; 418 const GpuTracerSource tracer_source = kTraceGroupMarker;
557 const std::string category_name("trace_category"); 419 const std::string category_name("trace_category");
558 const std::string trace_name("trace_test"); 420 const std::string trace_name("trace_test");
559 const GpuTracerSource source = static_cast<GpuTracerSource>(0); 421 const GpuTracerSource source = static_cast<GpuTracerSource>(0);
560 const int64 offset_time = 3231; 422 const int64 offset_time = 3231;
561 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond; 423 const GLint64 start_timestamp = 7 * base::Time::kNanosecondsPerMicrosecond;
562 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond; 424 const GLint64 end_timestamp = 32 * base::Time::kNanosecondsPerMicrosecond;
563 const int64 expect_start_time = 425 const int64 expect_start_time =
564 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) + 426 (start_timestamp / base::Time::kNanosecondsPerMicrosecond) +
(...skipping 17 matching lines...) Expand all
582 444
583 ExpectOutputterBeginMocks(outputter_ref_.get(), tracer_source, 445 ExpectOutputterBeginMocks(outputter_ref_.get(), tracer_source,
584 category_name, trace_name); 446 category_name, trace_name);
585 ASSERT_TRUE(tracer.Begin(category_name, trace_name, source)); 447 ASSERT_TRUE(tracer.Begin(category_name, trace_name, source));
586 448
587 gl_fake_queries_.SetCurrentGLTime(end_timestamp); 449 gl_fake_queries_.SetCurrentGLTime(end_timestamp);
588 g_fakeCPUTime = expect_end_time; 450 g_fakeCPUTime = expect_end_time;
589 451
590 // Create GPUTimingClient to make sure disjoint value is correct. This 452 // Create GPUTimingClient to make sure disjoint value is correct. This
591 // should not interfere with the tracer's disjoint value. 453 // should not interfere with the tracer's disjoint value.
592 scoped_refptr<gfx::GPUTimingClient> disjoint_client = 454 scoped_refptr<gfx::GPUTimingClient> disjoint_client =
593 GetGLContext()->CreateGPUTimingClient(); 455 GetGLContext()->CreateGPUTimingClient();
594 456
595 // We assert here based on the disjoint_client because if disjoints are not 457 // We assert here based on the disjoint_client because if disjoints are not
596 // working properly there is no point testing the tracer output. 458 // working properly there is no point testing the tracer output.
597 ASSERT_FALSE(disjoint_client->CheckAndResetTimerErrors()); 459 ASSERT_FALSE(disjoint_client->CheckAndResetTimerErrors());
598 gl_fake_queries_.SetDisjoint(); 460 gl_fake_queries_.SetDisjoint();
599 ASSERT_TRUE(disjoint_client->CheckAndResetTimerErrors()); 461 ASSERT_TRUE(disjoint_client->CheckAndResetTimerErrors());
600 462
601 ExpectOutputterEndMocks(outputter_ref_.get(), tracer_source, 463 ExpectOutputterEndMocks(outputter_ref_.get(), tracer_source,
602 category_name, trace_name, 464 category_name, trace_name,
603 expect_start_time, expect_end_time, false); 465 expect_start_time, expect_end_time, true, false);
604 466
605 ASSERT_TRUE(tracer.End(source)); 467 ASSERT_TRUE(tracer.End(source));
606 ASSERT_TRUE(tracer.EndDecoding()); 468 ASSERT_TRUE(tracer.EndDecoding());
607 469
608 outputter_ref_ = NULL; 470 outputter_ref_ = NULL;
609 } 471 }
610 }; 472 };
611 473
612 class InvalidTimerTracerTest : public BaseGpuTracerTest { 474 class InvalidTimerTracerTest : public BaseGpuTracerTest {
613 public: 475 public:
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 scoped_refptr<gfx::GPUTimingClient> client3 = 604 scoped_refptr<gfx::GPUTimingClient> client3 =
743 GetGLContext()->CreateGPUTimingClient(); 605 GetGLContext()->CreateGPUTimingClient();
744 ASSERT_TRUE(client1->CheckAndResetTimerErrors()); 606 ASSERT_TRUE(client1->CheckAndResetTimerErrors());
745 ASSERT_TRUE(client2->CheckAndResetTimerErrors()); 607 ASSERT_TRUE(client2->CheckAndResetTimerErrors());
746 ASSERT_FALSE(client3->CheckAndResetTimerErrors()); 608 ASSERT_FALSE(client3->CheckAndResetTimerErrors());
747 } 609 }
748 610
749 } // namespace 611 } // namespace
750 } // namespace gles2 612 } // namespace gles2
751 } // namespace gpu 613 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | ui/gl/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698