File: viz_debugger_unittest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (506 lines) | stat: -rw-r--r-- 18,571 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stddef.h>

#include <cstdio>
#include <unordered_map>
#include <utility>
#include <vector>

#include "base/rand_util.h"
#include "base/strings/stringprintf.h"
#include "components/viz/service/debugger/viz_debugger.h"
#include "components/viz/service/debugger/viz_debugger_unittests/viz_debugger_internal.h"
#include "components/viz/service/debugger/viz_debugger_unittests/viz_debugger_unittest_base.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/skia/include/core/SkAlphaType.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/vector2d_f.h"

#if VIZ_DEBUGGER_IS_ON()
using testing::_;
using testing::Mock;

namespace viz {

namespace {

static_assert(sizeof(VizDebuggerInternal) == sizeof(VizDebugger),
              "This test code exposes the internals of |VizDebugger| via an "
              "upcast; thus they must be the same size.");

class VisualDebuggerTest : public VisualDebuggerTestBase {};

TEST_F(VisualDebuggerTest, GeneralDrawSubmission) {
  const char kAnnoRect[] = "annorect";
  const char kAnnoText[] = "annotext";
  const char kAnnoLog[] = "annolog";
  const gfx::RectF kTestRect = gfx::RectF(12, 34, 56, 78);
  const gfx::RectF kTestUV = gfx::RectF(0.46, 0.25, 0.38, 1);
  static const int kNumFrames = 4;
  GetInternal()->ForceEnabled();
  for (uint64_t frame_idx = 0; frame_idx < kNumFrames; frame_idx++) {
    SetFilter({TestFilter("")});

    static const int kNumSubmission = 8;
    for (int i = 0; i < kNumSubmission; i++) {
      int buff_id = i;
      DBG_DRAW_RECT_BUFF_UV(kAnnoRect, kTestRect, &buff_id, kTestUV);
      DBG_DRAW_TEXT(kAnnoText, kTestRect.origin(),
                    base::StringPrintf("Text %d", i));
      DBG_LOG(kAnnoLog, "%d", i);
    }

    GetFrameData(true);
    EXPECT_EQ(counter_, frame_idx);
    EXPECT_EQ(window_x_, 256);
    EXPECT_EQ(window_x_, 256);
    EXPECT_EQ(static_cast<int>(draw_calls_cache_.size()), kNumSubmission * 2);
    EXPECT_EQ(static_cast<int>(log_calls_cache_.size()), kNumSubmission);

    if (frame_idx == 0) {
      EXPECT_EQ(sources_cache_.size(), 3u);
      EXPECT_EQ(sources_cache_[0].func, "TestBody");
      EXPECT_EQ(sources_cache_[0].file, __FILE__);
      EXPECT_EQ(sources_cache_[0].anno, kAnnoRect);
      EXPECT_EQ(sources_cache_[1].func, "TestBody");
      EXPECT_EQ(sources_cache_[1].file, __FILE__);
      EXPECT_EQ(sources_cache_[1].anno, kAnnoText);
      EXPECT_EQ(sources_cache_[2].func, "TestBody");
      EXPECT_EQ(sources_cache_[2].file, __FILE__);
      EXPECT_EQ(sources_cache_[2].anno, kAnnoLog);
    } else {
      // After the first frame there are no new sources in the loop.
      EXPECT_EQ(sources_cache_.size(), 0u);
    }

    for (int i = 0; i < kNumSubmission; i++) {
      EXPECT_EQ(draw_calls_cache_[i * 2].uv, kTestUV);
      EXPECT_EQ(draw_calls_cache_[i * 2].pos,
                gfx::Vector2dF(kTestRect.origin().x(), kTestRect.origin().y()));
      EXPECT_EQ(draw_calls_cache_[i * 2].obj_size, kTestRect.size());
      EXPECT_EQ(draw_calls_cache_[i * 2].source_index, 0);
      EXPECT_EQ(draw_calls_cache_[i * 2].draw_index, i * 3);

      EXPECT_EQ(draw_calls_cache_[i * 2 + 1].pos,
                gfx::Vector2dF(kTestRect.origin().x(), kTestRect.origin().y()));
      EXPECT_EQ(draw_calls_cache_[i * 2 + 1].source_index, 1);
      EXPECT_EQ(draw_calls_cache_[i * 2 + 1].draw_index, i * 3 + 1);
      EXPECT_EQ(draw_calls_cache_[i * 2 + 1].text,
                base::StringPrintf("Text %d", i));

      EXPECT_EQ(log_calls_cache_[i].value, base::StringPrintf("%d", i));
      EXPECT_EQ(log_calls_cache_[i].source_index, 2);
      EXPECT_EQ(log_calls_cache_[i].draw_index, i * 3 + 2);
    }
  }
}

static void FunctionNameTest(const char* anno_rect, gfx::RectF rect) {
  DBG_DRAW_RECT(anno_rect, rect);
}

TEST_F(VisualDebuggerTest, FilterDrawSubmission) {
  const char kAnnoRect[] = "annorect";
  const char kAnnoMissing[] = "testmissing";
  const char kAnnoMatch[] = "before_annorect_after";

  GetInternal()->ForceEnabled();
  const gfx::RectF kTestRect = gfx::RectF(10, 30, 50, 70);
  const gfx::RectF kMissingRect = gfx::RectF(11, 33, 55, 77);
  std::vector<int> valid_indices;
  SetFilter({TestFilter("annorect")});
  valid_indices.push_back(GetInternal()->GetSourceCount());
  FunctionNameTest(kAnnoRect, kTestRect);
  valid_indices.push_back(GetInternal()->GetSourceCount());
  DBG_DRAW_RECT(kAnnoRect, kTestRect);
  DBG_DRAW_RECT(kAnnoMissing, kMissingRect);
  valid_indices.push_back(GetInternal()->GetSourceCount());
  DBG_DRAW_RECT(kAnnoMatch, kTestRect);

  SetFilter({TestFilter("", "FunctionNameTest")});
  DBG_DRAW_RECT(kAnnoRect, kMissingRect);
  valid_indices.push_back(0);
  FunctionNameTest(kAnnoRect, kTestRect);

  SetFilter({TestFilter("", "TestBody")});
  FunctionNameTest(kAnnoRect, kMissingRect);
  valid_indices.push_back(GetInternal()->GetSourceCount());
  DBG_DRAW_RECT(kAnnoRect, kTestRect);

  SetFilter({TestFilter("", "", "no_file")});
  DBG_DRAW_RECT(kAnnoRect, kMissingRect);

  SetFilter({TestFilter("", "", __FILE__)});
  valid_indices.push_back(GetInternal()->GetSourceCount());
  DBG_DRAW_RECT(kAnnoRect, kTestRect);

  size_t const kNumDrawCalls = GetInternal()->GetRectCallsTailIdx();
  GetFrameData(true);

  EXPECT_EQ(sources_cache_[0].func, "FunctionNameTest");
  EXPECT_EQ(sources_cache_[0].file, __FILE__);
  EXPECT_EQ(sources_cache_[0].anno, kAnnoRect);
  EXPECT_EQ(sources_cache_[1].func, "TestBody");
  EXPECT_EQ(sources_cache_[1].file, __FILE__);
  EXPECT_EQ(sources_cache_[1].anno, kAnnoRect);
  EXPECT_EQ(sources_cache_[2].anno, kAnnoMissing);
  EXPECT_EQ(sources_cache_[3].anno, kAnnoMatch);

  auto check_draw = [](const VizDebuggerInternal::DrawCall& draw_call,
                       const gfx::RectF& rect, int src_idx, int draw_idx) {
    EXPECT_EQ(draw_call.pos,
              gfx::Vector2dF(rect.origin().x(), rect.origin().y()));
    EXPECT_EQ(draw_call.obj_size, rect.size());
    EXPECT_EQ(draw_call.source_index, src_idx);
    EXPECT_EQ(draw_call.draw_index, draw_idx);
  };
  // Makes sure all valid indices are here and have the correct rect.
  for (size_t i = 0; i < kNumDrawCalls; i++) {
    check_draw(draw_calls_cache_[i], kTestRect, valid_indices[i], i);
  }
}

constexpr const char kTestFlagFunctionAnnoName[] = "testflagfunctionanno";

DBG_FLAG_FBOOL(kTestFlagFunctionAnnoName, check_flag_enabled)

static bool FlagFunctionTestEnable() {
  return check_flag_enabled();
}

TEST_F(VisualDebuggerTest, TestDebugFlagAnnoAndFunction) {
  GetInternal()->ForceEnabled();

  // Set our test flag to be disabled.
  SetFilter({TestFilter(kTestFlagFunctionAnnoName, "", "", true, false)});
  EXPECT_FALSE(FlagFunctionTestEnable());
  SetFilter({TestFilter(kTestFlagFunctionAnnoName, "", "", true, true)});
  EXPECT_TRUE(FlagFunctionTestEnable());
  SetFilter({TestFilter(kTestFlagFunctionAnnoName, "", "", true, false)});
  EXPECT_FALSE(FlagFunctionTestEnable());
}

// This tests makes sure that expensive string logging has no cost unless it is
// actively being filtered.
TEST_F(VisualDebuggerTest, NonFilterActiveNoCost) {
  GetInternal()->ForceEnabled();
  const char* kStrA = "anno_A";
  const char* kStrB = "anno_B";
  // These integers are mutated on a function invocation.
  int count_a = 0;
  int count_b = 0;

  auto get_a_string = [&count_a, &kStrA]() {
    count_a++;
    return std::string(kStrA);
  };
  auto get_b_string = [&count_b, &kStrB]() {
    count_b++;
    return std::string(kStrB);
  };

  // Filter on "anno_A" which should call 'get_a_string'.
  SetFilter({TestFilter(kStrA)});
  DBG_DRAW_TEXT(kStrA, gfx::Point(), get_a_string());
  DBG_DRAW_TEXT(kStrB, gfx::Point(), get_b_string());
  DBG_LOG(kStrA, "%s", get_a_string().c_str());
  DBG_LOG(kStrB, "%s", get_b_string().c_str());
  EXPECT_EQ(2, count_a);
  EXPECT_EQ(0, count_b);

  // Filter on "anno_B" which should call 'get_b_string'.
  SetFilter({TestFilter(kStrB)});
  DBG_DRAW_TEXT(kStrA, gfx::Point(), get_a_string());
  DBG_DRAW_TEXT(kStrB, gfx::Point(), get_b_string());
  DBG_LOG(kStrA, "%s", get_a_string().c_str());
  DBG_LOG(kStrB, "%s", get_b_string().c_str());
  EXPECT_EQ(2, count_a);
  EXPECT_EQ(2, count_b);
}

// This tests passing a single buffer synchronously into the visual debuggeer
TEST_F(VisualDebuggerTest, SingleBufferSync) {
  const char kAnnoRect[] = "annorect";
  const gfx::Rect kTestRect = gfx::Rect(12, 34, 56, 78);
  static const int kNumFrames = 1;
  GetInternal()->ForceEnabled();
  VizDebuggerInternal::BufferInfo buffer_info;
  const int kBufferWidth = 4;
  const int kBufferHeight = 8;
  buffer_info.bitmap.setInfo(
      SkImageInfo::MakeN32(kBufferWidth, kBufferHeight, kUnpremul_SkAlphaType));
  buffer_info.bitmap.allocPixels();
  const auto kFillColor = SkColorSetARGB(0xFF, 0x43, 0x67, 0xAA);
  buffer_info.bitmap.eraseColor(kFillColor);
  VizDebuggerInternal::Buffer buffer;
  buffer.id = 0;
  buffer.buffer_info = buffer_info;
  for (uint64_t frame_idx = 0; frame_idx < kNumFrames; frame_idx++) {
    SetFilter({TestFilter({""})});

    static const int kNumSubmission = 1;
    int id = 0;
    DBG_COMPLETE_BUFFERS(id, buffer.buffer_info);
    DBG_DRAW_RECT_BUFF(kAnnoRect, kTestRect, &id);

    GetFrameData(true);

    EXPECT_EQ(counter_, frame_idx);
    EXPECT_EQ(window_x_, 256);
    EXPECT_EQ(window_x_, 256);
    EXPECT_EQ(draw_calls_cache_.size(), static_cast<size_t>(kNumSubmission));
    EXPECT_EQ(buffers_.size(), static_cast<size_t>(kNumSubmission));

    if (frame_idx == 0) {
      EXPECT_EQ(sources_cache_.size(), 1u);
      EXPECT_EQ(sources_cache_[0].func, "TestBody");
      EXPECT_EQ(sources_cache_[0].file, __FILE__);
      EXPECT_EQ(sources_cache_[0].anno, kAnnoRect);
    } else {
      // After the first frame there are no new sources in the loop.
      EXPECT_EQ(sources_cache_.size(), 0u);
    }

    EXPECT_EQ(draw_calls_cache_[0].buff_id, 0);

    auto& pixmap = buffers_[0].buffer_info.bitmap.pixmap();
    EXPECT_EQ(pixmap.info().width(), kBufferWidth);
    EXPECT_EQ(pixmap.info().height(), kBufferHeight);
    for (int j = 0; j < pixmap.height(); j++) {
      for (int i = 0; i < pixmap.width(); i++) {
        EXPECT_EQ(kFillColor, pixmap.getColor(i, j));
      }
    }
  }
}

// This tests passing multiple buffers into the visual debugger synchronously
TEST_F(VisualDebuggerTest, MultipleBuffersSync) {
  const char kAnnoRect[] = "annorect";
  const gfx::Rect kTestRect = gfx::Rect(12, 34, 56, 78);
  static const int kNumFrames = 1;
  GetInternal()->ForceEnabled();
  VizDebuggerInternal::BufferInfo buffer_info;
  const int kBufferWidth = 4;
  const int kBufferHeight = 8;
  buffer_info.bitmap.setInfo(
      SkImageInfo::MakeN32(kBufferWidth, kBufferHeight, kUnpremul_SkAlphaType));
  buffer_info.bitmap.allocPixels();
  const auto kFillColor = SkColorSetARGB(0xFF, 0x43, 0x67, 0xAA);
  buffer_info.bitmap.eraseColor(kFillColor);
  VizDebuggerInternal::Buffer buffer;
  buffer.id = 0;
  buffer.buffer_info = buffer_info;
  for (uint64_t frame_idx = 0; frame_idx < kNumFrames; frame_idx++) {
    SetFilter({TestFilter("")});

    static const int kNumSubmission = 8;
    for (int i = 0; i < kNumSubmission; i++) {
      int id = i;
      DBG_COMPLETE_BUFFERS(id, buffer.buffer_info);
      DBG_DRAW_RECT_BUFF(kAnnoRect, kTestRect, &id);
    }

    GetFrameData(true);

    EXPECT_EQ(counter_, frame_idx);
    EXPECT_EQ(window_x_, 256);
    EXPECT_EQ(window_x_, 256);
    EXPECT_EQ(draw_calls_cache_.size(), static_cast<size_t>(kNumSubmission));
    EXPECT_EQ(buffers_.size(), static_cast<size_t>(kNumSubmission));

    if (frame_idx == 0) {
      EXPECT_EQ(sources_cache_.size(), 1u);
      EXPECT_EQ(sources_cache_[0].func, "TestBody");
      EXPECT_EQ(sources_cache_[0].file, __FILE__);
      EXPECT_EQ(sources_cache_[0].anno, kAnnoRect);
    } else {
      // After the first frame there are no new sources in the loop.
      EXPECT_EQ(sources_cache_.size(), 0u);
    }
    auto& pixmap = buffers_[0].buffer_info.bitmap.pixmap();
    EXPECT_EQ(pixmap.info().width(), kBufferWidth);
    EXPECT_EQ(pixmap.info().height(), kBufferHeight);
    for (int j = 0; j < pixmap.height(); j++) {
      for (int i = 0; i < pixmap.width(); i++) {
        EXPECT_EQ(kFillColor, pixmap.getColor(i, j));
      }
    }
  }
}

// This tests passing a single buffer into the visual debugger asynchronously
TEST_F(VisualDebuggerTest, SingleBufferAsync) {
  const char kAnnoRect[] = "annorect";
  const gfx::Rect kTestRect = gfx::Rect(12, 34, 56, 78);
  static const int kNumFrames = 2;
  GetInternal()->ForceEnabled();
  VizDebuggerInternal::BufferInfo buffer_info;
  const int kBufferWidth = 4;
  const int kBufferHeight = 8;
  buffer_info.bitmap.setInfo(
      SkImageInfo::MakeN32(kBufferWidth, kBufferHeight, kUnpremul_SkAlphaType));
  buffer_info.bitmap.allocPixels();
  const auto kFillColor = SkColorSetARGB(0xFF, 0x43, 0x67, 0xAA);
  buffer_info.bitmap.eraseColor(kFillColor);
  VizDebuggerInternal::Buffer buffer;
  buffer.id = 0;
  buffer.buffer_info = buffer_info;
  for (uint64_t frame_idx = 0; frame_idx < kNumFrames; frame_idx++) {
    SetFilter({TestFilter("")});

    static const int kNumSubmission = 1;
    static std::vector<VizDebuggerInternal::Buffer> previous_textures;
    for (auto&& each : previous_textures) {
      DBG_COMPLETE_BUFFERS(each.id, each.buffer_info);
    }

    int id = 0;
    DBG_DRAW_RECT_BUFF(kAnnoRect, kTestRect, &id);
    buffer.id = id;
    previous_textures.emplace_back(buffer);

    GetFrameData(true);

    EXPECT_EQ(counter_, frame_idx);
    EXPECT_EQ(window_x_, 256);
    EXPECT_EQ(window_x_, 256);
    EXPECT_EQ(draw_calls_cache_.size(), static_cast<size_t>(kNumSubmission));

    if (frame_idx == 0) {
      EXPECT_EQ(sources_cache_.size(), 1u);
      EXPECT_EQ(sources_cache_[0].func, "TestBody");
      EXPECT_EQ(sources_cache_[0].file, __FILE__);
      EXPECT_EQ(sources_cache_[0].anno, kAnnoRect);
      EXPECT_EQ(buffers_.size(), static_cast<size_t>(0));
    } else {
      // After the first frame there are no new sources in the loop.
      EXPECT_EQ(sources_cache_.size(), 0u);
      EXPECT_EQ(buffers_.size(), static_cast<size_t>(kNumSubmission));
      EXPECT_EQ(draw_calls_cache_[0].buff_id, 1);
      auto& pixmap = buffers_[0].buffer_info.bitmap.pixmap();
      EXPECT_EQ(pixmap.info().width(), kBufferWidth);
      EXPECT_EQ(pixmap.info().height(), kBufferHeight);
      for (int j = 0; j < pixmap.height(); j++) {
        for (int i = 0; i < pixmap.width(); i++) {
          EXPECT_EQ(kFillColor, pixmap.getColor(i, j));
        }
      }
    }
  }
}

// This tests passing multiple buffers into the visual debugger asynchronously
TEST_F(VisualDebuggerTest, MultipleBuffersAsync) {
  const char kAnnoRect[] = "annorect";
  const gfx::Rect kTestRect = gfx::Rect(12, 34, 56, 78);
  static const int kNumFrames = 2;
  GetInternal()->ForceEnabled();
  const int kBufferWidth = 4;
  const int kBufferHeight = 8;

  std::map<int, SkColor> test_buffers_color;
  for (uint64_t frame_idx = 0; frame_idx < kNumFrames; frame_idx++) {
    SetFilter({TestFilter({""})});

    static const int kNumSubmission = 8;

    for (auto&& each : test_buffers_color) {
      VizDebuggerInternal::BufferInfo buffer_info;
      buffer_info.bitmap.setInfo(SkImageInfo::MakeN32(
          kBufferWidth, kBufferHeight, kUnpremul_SkAlphaType));
      buffer_info.bitmap.allocPixels();
      buffer_info.bitmap.eraseColor(each.second);
      DBG_COMPLETE_BUFFERS(each.first, buffer_info);
    }

    for (int i = 0; i < kNumSubmission; i++) {
      int id = i;
      DBG_DRAW_RECT_BUFF(kAnnoRect, kTestRect, &id);
      // Random numbers between 0-255 for BGRA values
      uint8_t temp[4];
      base::RandBytes(temp);
      const auto kFillColor =
          SkColorSetARGB(temp[0], temp[1], temp[2], temp[3]);
      test_buffers_color[id] = kFillColor;
    }

    GetFrameData(true);

    EXPECT_EQ(counter_, frame_idx);
    EXPECT_EQ(window_x_, 256);
    EXPECT_EQ(window_x_, 256);
    EXPECT_EQ(draw_calls_cache_.size(), static_cast<size_t>(kNumSubmission));

    if (frame_idx == 0) {
      EXPECT_EQ(sources_cache_.size(), 1u);
      EXPECT_EQ(sources_cache_[0].func, "TestBody");
      EXPECT_EQ(sources_cache_[0].file, __FILE__);
      EXPECT_EQ(sources_cache_[0].anno, kAnnoRect);
      EXPECT_EQ(buffers_.size(), static_cast<size_t>(0));
    } else {
      // After the first frame there are no new sources in the loop
      EXPECT_EQ(sources_cache_.size(), 0u);
      EXPECT_EQ(buffers_.size(), static_cast<size_t>(kNumSubmission));
      for (int i = 0; i < kNumSubmission; i++) {
        EXPECT_EQ(draw_calls_cache_[i].buff_id, i + 8);
        auto& pixmap = buffers_[i].buffer_info.bitmap.pixmap();

        EXPECT_EQ(pixmap.info().width(), kBufferWidth);
        EXPECT_EQ(pixmap.info().height(), kBufferHeight);
        for (int jj = 0; jj < pixmap.height(); jj++) {
          for (int ii = 0; ii < pixmap.width(); ii++) {
            EXPECT_EQ(test_buffers_color[buffers_[i].id],
                      pixmap.getColor(ii, jj));
          }
        }
      }
    }
  }
}
}  // namespace
}  // namespace viz
#else  // VIZ_DEBUGGER_IS_ON()

class VisualDebuggerTest : public testing::Test {};

DBG_FLAG_FBOOL("unit.test.fake.anno", flag_default_value_check)

TEST_F(VisualDebuggerTest, TestDebugFlagAnnoAndFunction) {
  // Visual debugger is disabled at build level this check should always return
  // false.
  EXPECT_FALSE(viz::VizDebugger::GetInstance()->IsEnabled());
  // The default value for a bool flag when the visual debugger is disabled is
  // false.
  EXPECT_FALSE(flag_default_value_check());
}

// This tests makes sure that expressions inside debugging macros are not
// evaluated by default with visual debugger off.
TEST_F(VisualDebuggerTest, DefaultDisabledNoExecute) {
  const char* kStrA = "anno_A";
  // These integers are mutated on a function invocation.
  int count_a = 0;

  auto get_a_string = [&count_a, &kStrA]() {
    count_a++;
    return std::string(kStrA);
  };

  DBG_DRAW_TEXT(kStrA, gfx::Point(), get_a_string());
  DBG_LOG(kStrA, "%s", get_a_string().c_str());
  EXPECT_EQ(0, count_a);

  EXPECT_EQ(get_a_string(), kStrA);
  EXPECT_EQ(1, count_a);
}

// For optimization purposes the flag fbool values return false as a constexpr.
// This allows the compiler to constant propagate and remove unused codepaths.
static_assert(flag_default_value_check() == false,
              "Default value when debugger is disabled is false.");

#endif