• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Amber Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/verifier.h"
16 
17 #include <memory>
18 #include <utility>
19 #include <vector>
20 
21 #include "amber/result.h"
22 #include "amber/value.h"
23 #include "gtest/gtest.h"
24 #include "src/command.h"
25 #include "src/make_unique.h"
26 #include "src/pipeline.h"
27 #include "src/type_parser.h"
28 
29 namespace amber {
30 namespace {
31 
32 class VerifierTest : public testing::Test {
33  public:
34   VerifierTest() = default;
35   ~VerifierTest() = default;
36 
GetColorFormat()37   const Format* GetColorFormat() {
38     if (color_frame_format_)
39       return color_frame_format_.get();
40 
41     TypeParser parser;
42     color_frame_type_ = parser.Parse("B8G8R8A8_UNORM");
43 
44     color_frame_format_ = MakeUnique<Format>(color_frame_type_.get());
45     return color_frame_format_.get();
46   }
47 
48  private:
49   std::unique_ptr<type::Type> color_frame_type_;
50   std::unique_ptr<Format> color_frame_format_;
51 };
52 
53 }  // namespace
54 
TEST_F(VerifierTest,ProbeFrameBufferWholeWindow)55 TEST_F(VerifierTest, ProbeFrameBufferWholeWindow) {
56   Pipeline pipeline(PipelineType::kGraphics);
57   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
58 
59   ProbeCommand probe(color_buf.get());
60   probe.SetWholeWindow();
61   probe.SetProbeRect();
62   probe.SetIsRGBA();
63   probe.SetB(0.5f);
64   probe.SetG(0.25f);
65   probe.SetR(0.2f);
66   probe.SetA(0.8f);
67 
68   const uint8_t frame_buffer[3][3][4] = {
69       {
70           {128, 64, 51, 204},
71           {128, 64, 51, 204},
72           {128, 64, 51, 204},
73       },
74       {
75           {128, 64, 51, 204},
76           {128, 64, 51, 204},
77           {128, 64, 51, 204},
78       },
79       {
80           {128, 64, 51, 204},
81           {128, 64, 51, 204},
82           {128, 64, 51, 204},
83       },
84   };
85 
86   Verifier verifier;
87   Result r = verifier.Probe(&probe, GetColorFormat(), 4, 12, 3, 3,
88                             static_cast<const void*>(frame_buffer));
89   EXPECT_TRUE(r.IsSuccess()) << r.Error();
90 }
91 
TEST_F(VerifierTest,ProbeFrameBufferRelative)92 TEST_F(VerifierTest, ProbeFrameBufferRelative) {
93   Pipeline pipeline(PipelineType::kGraphics);
94   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
95 
96   ProbeCommand probe(color_buf.get());
97   probe.SetProbeRect();
98   probe.SetRelative();
99   probe.SetIsRGBA();
100   probe.SetX(0.1f);
101   probe.SetY(0.2f);
102   probe.SetWidth(0.4f);
103   probe.SetHeight(0.6f);
104   probe.SetB(0.5f);
105   probe.SetG(0.25f);
106   probe.SetR(0.2f);
107   probe.SetA(0.8f);
108 
109   uint8_t frame_buffer[10][10][4] = {};
110   for (uint8_t x = 1; x < 5; ++x) {
111     for (uint8_t y = 2; y < 8; ++y) {
112       frame_buffer[y][x][0] = 128;
113       frame_buffer[y][x][1] = 64;
114       frame_buffer[y][x][2] = 51;
115       frame_buffer[y][x][3] = 204;
116     }
117   }
118 
119   Verifier verifier;
120   Result r = verifier.Probe(&probe, GetColorFormat(), 4, 40, 10, 10,
121                             static_cast<const void*>(frame_buffer));
122   EXPECT_TRUE(r.IsSuccess()) << r.Error();
123 }
124 
TEST_F(VerifierTest,ProbeFrameBufferRelativeSmallExpectFail)125 TEST_F(VerifierTest, ProbeFrameBufferRelativeSmallExpectFail) {
126   Pipeline pipeline(PipelineType::kGraphics);
127   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
128 
129   ProbeCommand probe(color_buf.get());
130   probe.SetProbeRect();
131   probe.SetRelative();
132   probe.SetIsRGBA();
133   probe.SetX(0.9f);
134   probe.SetY(0.9f);
135   probe.SetWidth(0.1f);
136   probe.SetHeight(0.1f);
137   probe.SetR(0.1f);
138   probe.SetG(0.0);
139   probe.SetB(0.0f);
140   probe.SetA(0.0f);
141 
142   uint8_t frame_buffer[250][250][4] = {};
143 
144   Verifier verifier;
145   Result r = verifier.Probe(&probe, GetColorFormat(), 4, 1000, 250, 250,
146                             static_cast<const void*>(frame_buffer));
147   EXPECT_EQ(
148       "Line 1: Probe failed at: 225, 225\n  Expected: 25.500000, "
149       "0.000000, 0.000000, 0.000000\n    Actual: 0.000000, 0.000000, "
150       "0.000000, 0.000000\nProbe failed in 625 pixels",
151       r.Error());
152 }
153 
TEST_F(VerifierTest,ProbeFrameBuffer)154 TEST_F(VerifierTest, ProbeFrameBuffer) {
155   Pipeline pipeline(PipelineType::kGraphics);
156   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
157 
158   ProbeCommand probe(color_buf.get());
159   probe.SetProbeRect();
160   probe.SetIsRGBA();
161   probe.SetX(1.0f);
162   probe.SetY(2.0f);
163   probe.SetWidth(4.0f);
164   probe.SetHeight(6.0f);
165   probe.SetB(0.5f);
166   probe.SetG(0.25f);
167   probe.SetR(0.2f);
168   probe.SetA(0.8f);
169 
170   uint8_t frame_buffer[10][10][4] = {};
171   for (uint8_t x = 1; x < 5; ++x) {
172     for (uint8_t y = 2; y < 8; ++y) {
173       frame_buffer[y][x][0] = 128;
174       frame_buffer[y][x][1] = 64;
175       frame_buffer[y][x][2] = 51;
176       frame_buffer[y][x][3] = 204;
177     }
178   }
179 
180   Verifier verifier;
181   Result r = verifier.Probe(&probe, GetColorFormat(), 4, 40, 10, 10,
182                             static_cast<const void*>(frame_buffer));
183   EXPECT_TRUE(r.IsSuccess()) << r.Error();
184 }
185 
TEST_F(VerifierTest,ProbeFrameBufferUInt8)186 TEST_F(VerifierTest, ProbeFrameBufferUInt8) {
187   Pipeline pipeline(PipelineType::kGraphics);
188   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
189 
190   ProbeCommand probe(color_buf.get());
191   probe.SetIsRGBA();
192   probe.SetX(0.0f);
193   probe.SetY(0.0f);
194   probe.SetR(255);
195   probe.SetG(14);
196   probe.SetB(75);
197   probe.SetA(8);
198 
199   uint8_t frame_buffer[4] = {255, 14, 75, 8};
200 
201   TypeParser parser;
202   auto type = parser.Parse("R8G8B8A8_UINT");
203   Format fmt(type.get());
204 
205   Verifier verifier;
206   Result r =
207       verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(uint8_t)),
208                      4 * static_cast<uint32_t>(sizeof(uint8_t)), 1, 1,
209                      static_cast<const void*>(&frame_buffer));
210   EXPECT_TRUE(r.IsSuccess());
211 }
212 
TEST_F(VerifierTest,ProbeFrameBufferUInt16)213 TEST_F(VerifierTest, ProbeFrameBufferUInt16) {
214   Pipeline pipeline(PipelineType::kGraphics);
215   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
216 
217   ProbeCommand probe(color_buf.get());
218   probe.SetIsRGBA();
219   probe.SetX(0.0f);
220   probe.SetY(0.0f);
221   probe.SetR(65535);
222   probe.SetG(14);
223   probe.SetB(1875);
224   probe.SetA(8);
225 
226   uint16_t frame_buffer[4] = {65535, 14, 1875, 8};
227 
228   TypeParser parser;
229   auto type = parser.Parse("R16G16B16A16_UINT");
230   Format fmt(type.get());
231 
232   Verifier verifier;
233   Result r =
234       verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(uint16_t)),
235                      4 * static_cast<uint32_t>(sizeof(uint16_t)), 1, 1,
236                      static_cast<const void*>(&frame_buffer));
237   EXPECT_TRUE(r.IsSuccess());
238 }
239 
TEST_F(VerifierTest,ProbeFrameBufferUInt32)240 TEST_F(VerifierTest, ProbeFrameBufferUInt32) {
241   Pipeline pipeline(PipelineType::kGraphics);
242   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
243 
244   ProbeCommand probe(color_buf.get());
245   probe.SetIsRGBA();
246   probe.SetX(0.0f);
247   probe.SetY(0.0f);
248   probe.SetR(6);
249   probe.SetG(14);
250   probe.SetB(1171875);
251   probe.SetA(8);
252 
253   uint32_t frame_buffer[4] = {6, 14, 1171875, 8};
254 
255   TypeParser parser;
256   auto type = parser.Parse("R32G32B32A32_UINT");
257   Format fmt(type.get());
258 
259   Verifier verifier;
260   Result r =
261       verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(uint32_t)),
262                      4 * static_cast<uint32_t>(sizeof(uint32_t)), 1, 1,
263                      static_cast<const void*>(&frame_buffer));
264   EXPECT_TRUE(r.IsSuccess());
265 }
266 
TEST_F(VerifierTest,ProbeFrameBufferUInt64)267 TEST_F(VerifierTest, ProbeFrameBufferUInt64) {
268   Pipeline pipeline(PipelineType::kGraphics);
269   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
270 
271   ProbeCommand probe(color_buf.get());
272   probe.SetIsRGBA();
273   probe.SetX(0.0f);
274   probe.SetY(0.0f);
275   probe.SetR(6);
276   probe.SetG(14);
277   probe.SetB(1171875);
278   probe.SetA(8);
279 
280   uint64_t frame_buffer[4] = {6, 14, 1171875, 8};
281 
282   TypeParser parser;
283   auto type = parser.Parse("R64G64B64A64_UINT");
284   Format fmt(type.get());
285 
286   Verifier verifier;
287   Result r =
288       verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(uint64_t)),
289                      4 * static_cast<uint32_t>(sizeof(uint64_t)), 1, 1,
290                      static_cast<const void*>(&frame_buffer));
291   EXPECT_TRUE(r.IsSuccess());
292 }
293 
TEST_F(VerifierTest,ProbeFrameBufferSInt8)294 TEST_F(VerifierTest, ProbeFrameBufferSInt8) {
295   Pipeline pipeline(PipelineType::kGraphics);
296   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
297 
298   ProbeCommand probe(color_buf.get());
299   probe.SetIsRGBA();
300   probe.SetX(0.0f);
301   probe.SetY(0.0f);
302   probe.SetR(-6);
303   probe.SetG(14);
304   probe.SetB(75);
305   probe.SetA(8);
306 
307   int8_t frame_buffer[4] = {-6, 14, 75, 8};
308 
309   TypeParser parser;
310   auto type = parser.Parse("R8G8B8A8_SINT");
311   Format fmt(type.get());
312 
313   Verifier verifier;
314   Result r =
315       verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(int8_t)),
316                      4 * static_cast<uint32_t>(sizeof(int8_t)), 1, 1,
317                      static_cast<const void*>(&frame_buffer));
318   EXPECT_TRUE(r.IsSuccess());
319 }
320 
TEST_F(VerifierTest,ProbeFrameBufferSInt16)321 TEST_F(VerifierTest, ProbeFrameBufferSInt16) {
322   Pipeline pipeline(PipelineType::kGraphics);
323   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
324 
325   ProbeCommand probe(color_buf.get());
326   probe.SetIsRGBA();
327   probe.SetX(0.0f);
328   probe.SetY(0.0f);
329   probe.SetR(-6);
330   probe.SetG(14);
331   probe.SetB(1875);
332   probe.SetA(8);
333 
334   int16_t frame_buffer[4] = {-6, 14, 1875, 8};
335 
336   TypeParser parser;
337   auto type = parser.Parse("R16G16B16A16_SINT");
338   Format fmt(type.get());
339 
340   Verifier verifier;
341   Result r =
342       verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(int16_t)),
343                      4 * static_cast<uint32_t>(sizeof(int16_t)), 1, 1,
344                      static_cast<const void*>(&frame_buffer));
345   EXPECT_TRUE(r.IsSuccess());
346 }
347 
TEST_F(VerifierTest,ProbeFrameBufferSInt32)348 TEST_F(VerifierTest, ProbeFrameBufferSInt32) {
349   Pipeline pipeline(PipelineType::kGraphics);
350   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
351 
352   ProbeCommand probe(color_buf.get());
353   probe.SetIsRGBA();
354   probe.SetX(0.0f);
355   probe.SetY(0.0f);
356   probe.SetR(-6);
357   probe.SetG(14);
358   probe.SetB(1171875);
359   probe.SetA(8);
360 
361   int32_t frame_buffer[4] = {-6, 14, 1171875, 8};
362 
363   TypeParser parser;
364   auto type = parser.Parse("R32G32B32A32_SINT");
365   Format fmt(type.get());
366 
367   Verifier verifier;
368   Result r =
369       verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(int32_t)),
370                      4 * static_cast<uint32_t>(sizeof(int32_t)), 1, 1,
371                      static_cast<const void*>(&frame_buffer));
372   EXPECT_TRUE(r.IsSuccess());
373 }
374 
TEST_F(VerifierTest,ProbeFrameBufferSInt64)375 TEST_F(VerifierTest, ProbeFrameBufferSInt64) {
376   Pipeline pipeline(PipelineType::kGraphics);
377   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
378 
379   ProbeCommand probe(color_buf.get());
380   probe.SetIsRGBA();
381   probe.SetX(0.0f);
382   probe.SetY(0.0f);
383   probe.SetR(-6);
384   probe.SetG(14);
385   probe.SetB(1171875);
386   probe.SetA(8);
387 
388   int64_t frame_buffer[4] = {-6, 14, 1171875, 8};
389 
390   TypeParser parser;
391   auto type = parser.Parse("R64G64B64A64_SINT");
392   Format fmt(type.get());
393 
394   Verifier verifier;
395   Result r =
396       verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(int64_t)),
397                      4 * static_cast<uint32_t>(sizeof(int64_t)), 1, 1,
398                      static_cast<const void*>(&frame_buffer));
399   EXPECT_TRUE(r.IsSuccess());
400 }
401 
TEST_F(VerifierTest,ProbeFrameBufferFloat32)402 TEST_F(VerifierTest, ProbeFrameBufferFloat32) {
403   Pipeline pipeline(PipelineType::kGraphics);
404   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
405 
406   ProbeCommand probe(color_buf.get());
407   probe.SetIsRGBA();
408   probe.SetX(0.0f);
409   probe.SetY(0.0f);
410   probe.SetR(-6.0f);
411   probe.SetG(14.0f);
412   probe.SetB(0.1171875f);
413   probe.SetA(0.8f);
414 
415   float frame_buffer[4] = {-6.0f, 14.0f, 0.1171875f, 0.8f};
416 
417   TypeParser parser;
418   auto type = parser.Parse("R32G32B32A32_SFLOAT");
419   Format fmt(type.get());
420 
421   Verifier verifier;
422   Result r =
423       verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(float)),
424                      4 * static_cast<uint32_t>(sizeof(float)), 1, 1,
425                      static_cast<const void*>(&frame_buffer));
426   EXPECT_TRUE(r.IsSuccess());
427 }
428 
TEST_F(VerifierTest,ProbeFrameBufferFloat64)429 TEST_F(VerifierTest, ProbeFrameBufferFloat64) {
430   Pipeline pipeline(PipelineType::kGraphics);
431   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
432 
433   ProbeCommand probe(color_buf.get());
434   probe.SetIsRGBA();
435   probe.SetX(0.0f);
436   probe.SetY(0.0f);
437   probe.SetR(-6.0f);
438   probe.SetG(14.0f);
439   probe.SetB(0.1171875f);
440   probe.SetA(0.8f);
441 
442   double frame_buffer[4] = {-6.0, 14.0, 0.1171875, 0.8};
443 
444   TypeParser parser;
445   auto type = parser.Parse("R64G64B64A64_SFLOAT");
446   Format fmt(type.get());
447 
448   Verifier verifier;
449   Result r =
450       verifier.Probe(&probe, &fmt, 4 * static_cast<uint32_t>(sizeof(double)),
451                      4 * static_cast<uint32_t>(sizeof(double)), 1, 1,
452                      static_cast<const void*>(&frame_buffer));
453   EXPECT_TRUE(r.IsSuccess());
454 }
455 
TEST_F(VerifierTest,HexFloatToFloatR16G11B10)456 TEST_F(VerifierTest, HexFloatToFloatR16G11B10) {
457   Pipeline pipeline(PipelineType::kGraphics);
458   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
459 
460   ProbeCommand probe(color_buf.get());
461   probe.SetX(0.0f);
462   probe.SetY(0.0f);
463 
464   uint64_t frame_buffer = 0;
465 
466   // 16 bits float to float
467   //   Sig / Exp / Mantissa     Sig / Exp / Mantissa
468   //     1 /  17 /      512 -->   1 / 129 /  4194304 = -1.1(2) * 2^2 = -6
469   frame_buffer = 50688ULL;
470   probe.SetR(-6.0f);
471 
472   // 11 bits float to float
473   //   Sig / Exp / Mantissa     Sig / Exp / Mantissa
474   //     0 /  18 /       48 -->   0 / 130 / 12582912 = 1.11(2) * 2^3 = 14
475   frame_buffer |= 1200ULL << 16ULL;
476   probe.SetG(14.0f);
477 
478   // 10 bits float to float
479   //   Sig / Exp / Mantissa     Sig / Exp / Mantissa
480   //     0 /  11 /       28 -->   1 / 123 / 14680064 = 1.111(2) * 2^-4
481   //                                                 = 0.1171875
482   frame_buffer |= 380ULL << (16ULL + 11ULL);
483   probe.SetB(0.1171875f);
484 
485   auto list = MakeUnique<type::List>();
486   list->AddMember(FormatComponentType::kR, FormatMode::kSFloat, 16);
487   list->AddMember(FormatComponentType::kG, FormatMode::kSFloat, 11);
488   list->AddMember(FormatComponentType::kB, FormatMode::kSFloat, 10);
489 
490   Format format(list.get());
491 
492   Verifier verifier;
493   Result r = verifier.Probe(&probe, &format, 6, 6, 1, 1,
494                             static_cast<const void*>(&frame_buffer));
495   EXPECT_TRUE(r.IsSuccess()) << r.Error();
496 }
497 
TEST_F(VerifierTest,HexFloatToFloatR11G16B10)498 TEST_F(VerifierTest, HexFloatToFloatR11G16B10) {
499   Pipeline pipeline(PipelineType::kGraphics);
500   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
501 
502   ProbeCommand probe(color_buf.get());
503   probe.SetX(0.0f);
504   probe.SetY(0.0f);
505 
506   uint64_t frame_buffer = 0;
507 
508   // 11 bits float to float
509   //   Sig / Exp / Mantissa     Sig / Exp / Mantissa
510   //     0 /  18 /       48 -->   0 / 130 / 12582912 = 1.11(2) * 2^3 = 14
511   frame_buffer = 1200ULL;
512   probe.SetR(14.0f);
513 
514   // 16 bits float to float
515   //   Sig / Exp / Mantissa     Sig / Exp / Mantissa
516   //     1 /  17 /      512 -->   1 / 129 /  4194304 = -1.1(2) * 2^2 = -6
517   frame_buffer |= 50688ULL << 11ULL;
518   probe.SetG(-6.0f);
519 
520   // 10 bits float to float
521   //   Sig / Exp / Mantissa     Sig / Exp / Mantissa
522   //     0 /  11 /       28 -->   1 / 123 / 14680064 = 1.111(2) * 2^-4
523   //                                                 = 0.1171875
524   frame_buffer |= 380ULL << (16ULL + 11ULL);
525   probe.SetB(0.1171875f);
526 
527   auto list = MakeUnique<type::List>();
528   list->AddMember(FormatComponentType::kR, FormatMode::kSFloat, 11);
529   list->AddMember(FormatComponentType::kG, FormatMode::kSFloat, 16);
530   list->AddMember(FormatComponentType::kB, FormatMode::kSFloat, 10);
531 
532   Format format(list.get());
533 
534   Verifier verifier;
535   Result r = verifier.Probe(&probe, &format, 6, 6, 1, 1,
536                             static_cast<const void*>(&frame_buffer));
537   EXPECT_TRUE(r.IsSuccess()) << r.Error();
538 }
539 
TEST_F(VerifierTest,HexFloatToFloatR10G11B16)540 TEST_F(VerifierTest, HexFloatToFloatR10G11B16) {
541   Pipeline pipeline(PipelineType::kGraphics);
542   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
543 
544   ProbeCommand probe(color_buf.get());
545   probe.SetX(0.0f);
546   probe.SetY(0.0f);
547 
548   uint64_t frame_buffer = 0;
549 
550   // 10 bits float to float
551   //   Sig / Exp / Mantissa     Sig / Exp / Mantissa
552   //     0 /  11 /       28 -->   1 / 123 / 14680064 = 1.111(2) * 2^-4
553   //                                                 = 0.1171875
554   frame_buffer = 380ULL;
555   probe.SetR(0.1171875f);
556 
557   // 11 bits float to float
558   //   Sig / Exp / Mantissa     Sig / Exp / Mantissa
559   //     0 /  18 /       48 -->   0 / 130 / 12582912 = 1.11(2) * 2^3 = 14
560   frame_buffer |= 1200ULL << 10ULL;
561   probe.SetG(14.0f);
562 
563   // 16 bits float to float
564   //   Sig / Exp / Mantissa     Sig / Exp / Mantissa
565   //     1 /  17 /      512 -->   1 / 129 /  4194304 = -1.1(2) * 2^2 = -6
566   frame_buffer |= 50688ULL << (10ULL + 11ULL);
567   probe.SetB(-6.0f);
568 
569   auto list = MakeUnique<type::List>();
570   list->AddMember(FormatComponentType::kR, FormatMode::kSFloat, 10);
571   list->AddMember(FormatComponentType::kG, FormatMode::kSFloat, 11);
572   list->AddMember(FormatComponentType::kB, FormatMode::kSFloat, 16);
573 
574   Format format(list.get());
575 
576   Verifier verifier;
577   Result r = verifier.Probe(&probe, &format, 6, 6, 1, 1,
578                             static_cast<const void*>(&frame_buffer));
579   EXPECT_TRUE(r.IsSuccess()) << r.Error();
580 }
581 
TEST_F(VerifierTest,ProbeFrameBufferNotRect)582 TEST_F(VerifierTest, ProbeFrameBufferNotRect) {
583   uint8_t frame_buffer[10][10][4] = {};
584 
585   frame_buffer[2][1][0] = 128;
586   frame_buffer[2][1][1] = 64;
587   frame_buffer[2][1][2] = 51;
588   frame_buffer[2][1][3] = 204;
589 
590   Pipeline pipeline(PipelineType::kGraphics);
591   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
592 
593   ProbeCommand probe(color_buf.get());
594   probe.SetIsRGBA();
595   probe.SetX(1.0f);
596   probe.SetY(2.0f);
597   probe.SetB(0.5f);
598   probe.SetG(0.25f);
599   probe.SetR(0.2f);
600   probe.SetA(0.8f);
601 
602   Verifier verifier;
603   Result r = verifier.Probe(&probe, GetColorFormat(), 4, 40, 10, 10,
604                             static_cast<const void*>(frame_buffer));
605   EXPECT_TRUE(r.IsSuccess()) << r.Error();
606 }
607 
TEST_F(VerifierTest,ProbeFrameBufferRGB)608 TEST_F(VerifierTest, ProbeFrameBufferRGB) {
609   Pipeline pipeline(PipelineType::kGraphics);
610   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
611 
612   ProbeCommand probe(color_buf.get());
613   probe.SetWholeWindow();
614   probe.SetProbeRect();
615   probe.SetB(0.5f);
616   probe.SetG(0.25f);
617   probe.SetR(0.2f);
618 
619   const uint8_t frame_buffer[3][3][4] = {
620       {
621           {128, 64, 51, 255},
622           {128, 64, 51, 255},
623           {128, 64, 51, 255},
624       },
625       {
626           {128, 64, 51, 255},
627           {128, 64, 51, 255},
628           {128, 64, 51, 255},
629       },
630       {
631           {128, 64, 51, 255},
632           {128, 64, 51, 255},
633           {128, 64, 51, 255},
634       },
635   };
636 
637   Verifier verifier;
638   Result r = verifier.Probe(&probe, GetColorFormat(), 4, 12, 3, 3,
639                             static_cast<const void*>(frame_buffer));
640   EXPECT_TRUE(r.IsSuccess()) << r.Error();
641 }
642 
TEST_F(VerifierTest,ProbeFrameBufferBadRowStride)643 TEST_F(VerifierTest, ProbeFrameBufferBadRowStride) {
644   Pipeline pipeline(PipelineType::kGraphics);
645   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
646 
647   ProbeCommand probe(color_buf.get());
648   probe.SetWholeWindow();
649   probe.SetProbeRect();
650 
651   const uint8_t frame_buffer[4] = {128, 64, 51, 255};
652 
653   Verifier verifier;
654   Result r = verifier.Probe(&probe, GetColorFormat(), 4, 3, 1, 1,
655                             static_cast<const void*>(frame_buffer));
656   EXPECT_FALSE(r.IsSuccess());
657   EXPECT_EQ(
658       "Line 1: Verifier::Probe Row stride of 3 is too small for 1 texels of 4 "
659       "bytes each",
660       r.Error());
661 }
662 
TEST_F(VerifierTest,ProbeSSBOUint8Single)663 TEST_F(VerifierTest, ProbeSSBOUint8Single) {
664   Pipeline pipeline(PipelineType::kGraphics);
665   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
666 
667   ProbeSSBOCommand probe_ssbo(color_buf.get());
668 
669   TypeParser parser;
670   auto type = parser.Parse("R8_UINT");
671   Format fmt(type.get());
672 
673   probe_ssbo.SetFormat(&fmt);
674   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
675 
676   std::vector<Value> values;
677   values.emplace_back();
678   values.back().SetIntValue(13);
679   probe_ssbo.SetValues(std::move(values));
680 
681   uint8_t ssbo = 13U;
682 
683   Verifier verifier;
684   Result r =
685       verifier.ProbeSSBO(&probe_ssbo, 1, static_cast<const void*>(&ssbo));
686   EXPECT_TRUE(r.IsSuccess()) << r.Error();
687 }
688 
TEST_F(VerifierTest,ProbeSSBOUint8Multiple)689 TEST_F(VerifierTest, ProbeSSBOUint8Multiple) {
690   Pipeline pipeline(PipelineType::kGraphics);
691   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
692 
693   ProbeSSBOCommand probe_ssbo(color_buf.get());
694 
695   TypeParser parser;
696   auto type = parser.Parse("R8_UINT");
697   Format fmt(type.get());
698 
699   probe_ssbo.SetFormat(&fmt);
700   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
701 
702   std::vector<Value> values;
703   values.resize(3);
704   values[0].SetIntValue(2);
705   values[1].SetIntValue(0);
706   values[2].SetIntValue(10);
707   probe_ssbo.SetValues(std::move(values));
708 
709   const uint8_t ssbo[3] = {2U, 0U, 10U};
710 
711   Verifier verifier;
712   Result r = verifier.ProbeSSBO(&probe_ssbo, 3, ssbo);
713   EXPECT_TRUE(r.IsSuccess()) << r.Error();
714 }
715 
TEST_F(VerifierTest,ProbeSSBOUint8Many)716 TEST_F(VerifierTest, ProbeSSBOUint8Many) {
717   Pipeline pipeline(PipelineType::kGraphics);
718   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
719 
720   ProbeSSBOCommand probe_ssbo(color_buf.get());
721 
722   TypeParser parser;
723   auto type = parser.Parse("R8_UINT");
724   Format fmt(type.get());
725 
726   probe_ssbo.SetFormat(&fmt);
727   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
728 
729   std::vector<Value> values;
730   values.resize(200);
731   for (size_t i = 0; i < values.size(); ++i) {
732     values[i].SetIntValue(255 - i);
733   }
734   probe_ssbo.SetValues(std::move(values));
735 
736   std::vector<uint8_t> ssbo;
737   ssbo.resize(200);
738   for (size_t i = 0; i < ssbo.size(); ++i) {
739     ssbo[i] = static_cast<uint8_t>(255U) - static_cast<uint8_t>(i);
740   }
741 
742   Verifier verifier;
743   Result r = verifier.ProbeSSBO(&probe_ssbo, 200, ssbo.data());
744   EXPECT_TRUE(r.IsSuccess()) << r.Error();
745 }
746 
TEST_F(VerifierTest,ProbeSSBOUint32Single)747 TEST_F(VerifierTest, ProbeSSBOUint32Single) {
748   Pipeline pipeline(PipelineType::kGraphics);
749   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
750 
751   ProbeSSBOCommand probe_ssbo(color_buf.get());
752 
753   TypeParser parser;
754   auto type = parser.Parse("R32_UINT");
755   Format fmt(type.get());
756 
757   probe_ssbo.SetFormat(&fmt);
758   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
759 
760   std::vector<Value> values;
761   values.emplace_back();
762   values.back().SetIntValue(13);
763   probe_ssbo.SetValues(std::move(values));
764 
765   uint32_t ssbo = 13U;
766 
767   Verifier verifier;
768   Result r =
769       verifier.ProbeSSBO(&probe_ssbo, 1, static_cast<const void*>(&ssbo));
770   EXPECT_TRUE(r.IsSuccess()) << r.Error();
771 }
772 
TEST_F(VerifierTest,ProbeSSBOUint32Multiple)773 TEST_F(VerifierTest, ProbeSSBOUint32Multiple) {
774   Pipeline pipeline(PipelineType::kGraphics);
775   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
776 
777   ProbeSSBOCommand probe_ssbo(color_buf.get());
778 
779   TypeParser parser;
780   auto type = parser.Parse("R32_UINT");
781   Format fmt(type.get());
782 
783   probe_ssbo.SetFormat(&fmt);
784   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
785 
786   std::vector<Value> values;
787   values.resize(4);
788   values[0].SetIntValue(2);
789   values[1].SetIntValue(0);
790   values[2].SetIntValue(10);
791   values[3].SetIntValue(1234);
792   probe_ssbo.SetValues(std::move(values));
793 
794   const uint32_t ssbo[4] = {2U, 0U, 10U, 1234U};
795 
796   Verifier verifier;
797   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
798   EXPECT_TRUE(r.IsSuccess()) << r.Error();
799 }
800 
TEST_F(VerifierTest,ProbeSSBOUint32Many)801 TEST_F(VerifierTest, ProbeSSBOUint32Many) {
802   Pipeline pipeline(PipelineType::kGraphics);
803   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
804 
805   ProbeSSBOCommand probe_ssbo(color_buf.get());
806 
807   TypeParser parser;
808   auto type = parser.Parse("R32_UINT");
809   Format fmt(type.get());
810 
811   probe_ssbo.SetFormat(&fmt);
812   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
813 
814   std::vector<Value> values;
815   values.resize(200);
816   for (size_t i = 0; i < values.size(); ++i) {
817     values[i].SetIntValue(i * i);
818   }
819   probe_ssbo.SetValues(std::move(values));
820 
821   std::vector<uint32_t> ssbo;
822   ssbo.resize(200);
823   for (size_t i = 0; i < ssbo.size(); ++i) {
824     ssbo[i] = static_cast<uint32_t>(i) * static_cast<uint32_t>(i);
825   }
826 
827   Verifier verifier;
828   Result r = verifier.ProbeSSBO(&probe_ssbo, 200, ssbo.data());
829   EXPECT_TRUE(r.IsSuccess()) << r.Error();
830 }
831 
TEST_F(VerifierTest,ProbeSSBOFloatSingle)832 TEST_F(VerifierTest, ProbeSSBOFloatSingle) {
833   Pipeline pipeline(PipelineType::kGraphics);
834   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
835 
836   ProbeSSBOCommand probe_ssbo(color_buf.get());
837 
838   TypeParser parser;
839   auto type = parser.Parse("R32_SFLOAT");
840   Format fmt(type.get());
841 
842   probe_ssbo.SetFormat(&fmt);
843   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
844 
845   std::vector<Value> values;
846   values.emplace_back();
847   values.back().SetDoubleValue(13.7);
848   probe_ssbo.SetValues(std::move(values));
849 
850   float ssbo = 13.7f;
851 
852   Verifier verifier;
853   Result r =
854       verifier.ProbeSSBO(&probe_ssbo, 1, static_cast<const void*>(&ssbo));
855   EXPECT_TRUE(r.IsSuccess()) << r.Error();
856 }
857 
TEST_F(VerifierTest,ProbeSSBOFloatMultiple)858 TEST_F(VerifierTest, ProbeSSBOFloatMultiple) {
859   Pipeline pipeline(PipelineType::kGraphics);
860   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
861 
862   ProbeSSBOCommand probe_ssbo(color_buf.get());
863 
864   TypeParser parser;
865   auto type = parser.Parse("R32_SFLOAT");
866   Format fmt(type.get());
867 
868   probe_ssbo.SetFormat(&fmt);
869   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
870 
871   std::vector<Value> values;
872   values.resize(4);
873   values[0].SetDoubleValue(2.9);
874   values[1].SetDoubleValue(0.73);
875   values[2].SetDoubleValue(10.0);
876   values[3].SetDoubleValue(1234.56);
877   probe_ssbo.SetValues(std::move(values));
878 
879   const float ssbo[4] = {2.9f, 0.73f, 10.0f, 1234.56f};
880 
881   Verifier verifier;
882   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
883   EXPECT_TRUE(r.IsSuccess()) << r.Error();
884 }
885 
TEST_F(VerifierTest,ProbeSSBOFloatMany)886 TEST_F(VerifierTest, ProbeSSBOFloatMany) {
887   Pipeline pipeline(PipelineType::kGraphics);
888   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
889 
890   ProbeSSBOCommand probe_ssbo(color_buf.get());
891 
892   TypeParser parser;
893   auto type = parser.Parse("R32_SFLOAT");
894   Format fmt(type.get());
895 
896   probe_ssbo.SetFormat(&fmt);
897   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
898 
899   std::vector<Value> values;
900   values.resize(200);
901   for (size_t i = 0; i < values.size(); ++i) {
902     values[i].SetDoubleValue(static_cast<double>(i) / 1.7);
903   }
904   probe_ssbo.SetValues(std::move(values));
905 
906   std::vector<float> ssbo;
907   ssbo.resize(200);
908   for (size_t i = 0; i < ssbo.size(); ++i) {
909     ssbo[i] = static_cast<float>(static_cast<double>(i) / 1.7);
910   }
911 
912   Verifier verifier;
913   Result r = verifier.ProbeSSBO(&probe_ssbo, 200, ssbo.data());
914   EXPECT_TRUE(r.IsSuccess()) << r.Error();
915 }
916 
TEST_F(VerifierTest,ProbeSSBODoubleSingle)917 TEST_F(VerifierTest, ProbeSSBODoubleSingle) {
918   Pipeline pipeline(PipelineType::kGraphics);
919   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
920 
921   ProbeSSBOCommand probe_ssbo(color_buf.get());
922 
923   TypeParser parser;
924   auto type = parser.Parse("R64_SFLOAT");
925   Format fmt(type.get());
926 
927   probe_ssbo.SetFormat(&fmt);
928   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
929 
930   std::vector<Value> values;
931   values.emplace_back();
932   values.back().SetDoubleValue(13.7);
933   probe_ssbo.SetValues(std::move(values));
934 
935   double ssbo = 13.7;
936 
937   Verifier verifier;
938   Result r =
939       verifier.ProbeSSBO(&probe_ssbo, 1, static_cast<const void*>(&ssbo));
940   EXPECT_TRUE(r.IsSuccess()) << r.Error();
941 }
942 
TEST_F(VerifierTest,ProbeSSBODoubleMultiple)943 TEST_F(VerifierTest, ProbeSSBODoubleMultiple) {
944   Pipeline pipeline(PipelineType::kGraphics);
945   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
946 
947   ProbeSSBOCommand probe_ssbo(color_buf.get());
948 
949   TypeParser parser;
950   auto type = parser.Parse("R64_SFLOAT");
951   Format fmt(type.get());
952 
953   probe_ssbo.SetFormat(&fmt);
954   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
955 
956   std::vector<Value> values;
957   values.resize(4);
958   values[0].SetDoubleValue(2.9);
959   values[1].SetDoubleValue(0.73);
960   values[2].SetDoubleValue(10.0);
961   values[3].SetDoubleValue(1234.56);
962   probe_ssbo.SetValues(std::move(values));
963 
964   const double ssbo[4] = {2.9, 0.73, 10.0, 1234.56};
965 
966   Verifier verifier;
967   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
968   EXPECT_TRUE(r.IsSuccess()) << r.Error();
969 }
970 
TEST_F(VerifierTest,ProbeSSBODoubleMany)971 TEST_F(VerifierTest, ProbeSSBODoubleMany) {
972   Pipeline pipeline(PipelineType::kGraphics);
973   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
974 
975   ProbeSSBOCommand probe_ssbo(color_buf.get());
976 
977   TypeParser parser;
978   auto type = parser.Parse("R64_SFLOAT");
979   Format fmt(type.get());
980 
981   probe_ssbo.SetFormat(&fmt);
982   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
983 
984   std::vector<Value> values;
985   values.resize(200);
986   for (size_t i = 0; i < values.size(); ++i) {
987     values[i].SetDoubleValue(static_cast<double>(i) / 1.7);
988   }
989   probe_ssbo.SetValues(std::move(values));
990 
991   std::vector<double> ssbo;
992   ssbo.resize(200);
993   for (size_t i = 0; i < ssbo.size(); ++i) {
994     ssbo[i] = static_cast<double>(i) / 1.7;
995   }
996 
997   Verifier verifier;
998   Result r = verifier.ProbeSSBO(&probe_ssbo, 200, ssbo.data());
999   EXPECT_TRUE(r.IsSuccess()) << r.Error();
1000 }
1001 
TEST_F(VerifierTest,ProbeSSBOEqualFail)1002 TEST_F(VerifierTest, ProbeSSBOEqualFail) {
1003   Pipeline pipeline(PipelineType::kGraphics);
1004   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1005 
1006   ProbeSSBOCommand probe_ssbo(color_buf.get());
1007 
1008   TypeParser parser;
1009   auto type = parser.Parse("R64_SFLOAT");
1010   Format fmt(type.get());
1011 
1012   probe_ssbo.SetFormat(&fmt);
1013   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kEqual);
1014 
1015   std::vector<Value> values;
1016   values.resize(4);
1017   values[0].SetDoubleValue(2.9);
1018   values[1].SetDoubleValue(0.73);
1019   values[2].SetDoubleValue(10.0);
1020   values[3].SetDoubleValue(1234.56);
1021   probe_ssbo.SetValues(std::move(values));
1022 
1023   const double ssbo[4] = {2.8, 0.72, 9.0, 1234.55};
1024 
1025   Verifier verifier;
1026   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1027   EXPECT_FALSE(r.IsSuccess());
1028   EXPECT_EQ("Line 1: Verifier failed: 2.800000 == 2.900000, at index 0",
1029             r.Error());
1030 }
1031 
TEST_F(VerifierTest,ProbeSSBOFuzzyEqualWithAbsoluteTolerance)1032 TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithAbsoluteTolerance) {
1033   Pipeline pipeline(PipelineType::kGraphics);
1034   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1035 
1036   ProbeSSBOCommand probe_ssbo(color_buf.get());
1037 
1038   TypeParser parser;
1039   auto type = parser.Parse("R64_SFLOAT");
1040   Format fmt(type.get());
1041 
1042   probe_ssbo.SetFormat(&fmt);
1043   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
1044 
1045   std::vector<Probe::Tolerance> tolerances;
1046   tolerances.emplace_back(false, 0.1);
1047   probe_ssbo.SetTolerances(tolerances);
1048 
1049   std::vector<Value> values;
1050   values.resize(4);
1051   values[0].SetDoubleValue(2.9);
1052   values[1].SetDoubleValue(0.73);
1053   values[2].SetDoubleValue(10.0);
1054   values[3].SetDoubleValue(1234.56);
1055   probe_ssbo.SetValues(std::move(values));
1056 
1057   const double ssbo_more[4] = {2.999, 0.829, 10.099, 1234.659};
1058 
1059   Verifier verifier;
1060   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo_more);
1061   EXPECT_TRUE(r.IsSuccess());
1062 
1063   const double ssbo_less[4] = {2.801, 0.631, 9.901, 1234.461};
1064 
1065   r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo_less);
1066   EXPECT_TRUE(r.IsSuccess()) << r.Error();
1067 }
1068 
TEST_F(VerifierTest,ProbeSSBOFuzzyEqualWithAbsoluteToleranceFail)1069 TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithAbsoluteToleranceFail) {
1070   Pipeline pipeline(PipelineType::kGraphics);
1071   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1072 
1073   ProbeSSBOCommand probe_ssbo(color_buf.get());
1074 
1075   TypeParser parser;
1076   auto type = parser.Parse("R64_SFLOAT");
1077   Format fmt(type.get());
1078 
1079   probe_ssbo.SetFormat(&fmt);
1080   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
1081 
1082   std::vector<Probe::Tolerance> tolerances;
1083   tolerances.emplace_back(false, 0.1);
1084   probe_ssbo.SetTolerances(tolerances);
1085 
1086   std::vector<Value> values;
1087   values.resize(4);
1088   values[0].SetDoubleValue(2.9);
1089   values[1].SetDoubleValue(0.73);
1090   values[2].SetDoubleValue(10.0);
1091   values[3].SetDoubleValue(1234.56);
1092   probe_ssbo.SetValues(std::move(values));
1093 
1094   const double ssbo[4] = {3.001, 0.831, 10.101, 1234.661};
1095 
1096   Verifier verifier;
1097   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1098   EXPECT_FALSE(r.IsSuccess());
1099   EXPECT_EQ("Line 1: Verifier failed: 3.001000 ~= 2.900000, at index 0",
1100             r.Error());
1101 }
1102 
TEST_F(VerifierTest,ProbeSSBOFuzzyEqualWithRelativeTolerance)1103 TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithRelativeTolerance) {
1104   Pipeline pipeline(PipelineType::kGraphics);
1105   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1106 
1107   ProbeSSBOCommand probe_ssbo(color_buf.get());
1108 
1109   TypeParser parser;
1110   auto type = parser.Parse("R64_SFLOAT");
1111   Format fmt(type.get());
1112 
1113   probe_ssbo.SetFormat(&fmt);
1114   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
1115 
1116   std::vector<Probe::Tolerance> tolerances;
1117   tolerances.emplace_back(true, 0.1);
1118   probe_ssbo.SetTolerances(tolerances);
1119 
1120   std::vector<Value> values;
1121   values.resize(4);
1122   values[0].SetDoubleValue(2.9);
1123   values[1].SetDoubleValue(0.73);
1124   values[2].SetDoubleValue(10.0);
1125   values[3].SetDoubleValue(1234.56);
1126   probe_ssbo.SetValues(std::move(values));
1127 
1128   const double ssbo_more[4] = {2.9028, 0.73072, 10.009, 1235.79455};
1129 
1130   Verifier verifier;
1131   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo_more);
1132   EXPECT_TRUE(r.IsSuccess()) << r.Error();
1133 
1134   const double ssbo_less[4] = {2.8972, 0.72928, 9.991, 1233.32545};
1135 
1136   r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo_less);
1137   EXPECT_TRUE(r.IsSuccess()) << r.Error();
1138 }
1139 
TEST_F(VerifierTest,ProbeSSBOFuzzyEqualWithRelativeToleranceFail)1140 TEST_F(VerifierTest, ProbeSSBOFuzzyEqualWithRelativeToleranceFail) {
1141   Pipeline pipeline(PipelineType::kGraphics);
1142   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1143 
1144   ProbeSSBOCommand probe_ssbo(color_buf.get());
1145 
1146   TypeParser parser;
1147   auto type = parser.Parse("R64_SFLOAT");
1148   Format fmt(type.get());
1149 
1150   probe_ssbo.SetFormat(&fmt);
1151   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kFuzzyEqual);
1152 
1153   std::vector<Probe::Tolerance> tolerances;
1154   tolerances.emplace_back(true, 0.1);
1155   probe_ssbo.SetTolerances(tolerances);
1156 
1157   std::vector<Value> values;
1158   values.resize(4);
1159   values[0].SetDoubleValue(2.9);
1160   values[1].SetDoubleValue(0.73);
1161   values[2].SetDoubleValue(10.0);
1162   values[3].SetDoubleValue(1234.56);
1163   probe_ssbo.SetValues(std::move(values));
1164 
1165   const double ssbo[4] = {2.903, 0.73074, 10.011, 1235.79457};
1166 
1167   Verifier verifier;
1168   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1169   EXPECT_FALSE(r.IsSuccess());
1170   EXPECT_EQ("Line 1: Verifier failed: 2.903000 ~= 2.900000, at index 0",
1171             r.Error());
1172 }
1173 
TEST_F(VerifierTest,ProbeSSBONotEqual)1174 TEST_F(VerifierTest, ProbeSSBONotEqual) {
1175   Pipeline pipeline(PipelineType::kGraphics);
1176   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1177 
1178   ProbeSSBOCommand probe_ssbo(color_buf.get());
1179 
1180   TypeParser parser;
1181   auto type = parser.Parse("R64_SFLOAT");
1182   Format fmt(type.get());
1183 
1184   probe_ssbo.SetFormat(&fmt);
1185   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kNotEqual);
1186 
1187   std::vector<Value> values;
1188   values.resize(4);
1189   values[0].SetDoubleValue(2.9);
1190   values[1].SetDoubleValue(0.73);
1191   values[2].SetDoubleValue(10.0);
1192   values[3].SetDoubleValue(1234.56);
1193   probe_ssbo.SetValues(std::move(values));
1194 
1195   const double ssbo[4] = {3.9, 0.83, 10.1, 1234.57};
1196 
1197   Verifier verifier;
1198   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1199   EXPECT_TRUE(r.IsSuccess()) << r.Error();
1200 }
1201 
TEST_F(VerifierTest,ProbeSSBONotEqualFail)1202 TEST_F(VerifierTest, ProbeSSBONotEqualFail) {
1203   Pipeline pipeline(PipelineType::kGraphics);
1204   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1205 
1206   ProbeSSBOCommand probe_ssbo(color_buf.get());
1207 
1208   TypeParser parser;
1209   auto type = parser.Parse("R64_SFLOAT");
1210   Format fmt(type.get());
1211 
1212   probe_ssbo.SetFormat(&fmt);
1213   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kNotEqual);
1214 
1215   std::vector<Value> values;
1216   values.resize(4);
1217   values[0].SetDoubleValue(2.9);
1218   values[1].SetDoubleValue(0.73);
1219   values[2].SetDoubleValue(10.0);
1220   values[3].SetDoubleValue(1234.56);
1221   probe_ssbo.SetValues(std::move(values));
1222 
1223   const double ssbo[4] = {2.9, 0.73, 10.0, 1234.56};
1224 
1225   Verifier verifier;
1226   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1227   EXPECT_FALSE(r.IsSuccess());
1228   EXPECT_EQ("Line 1: Verifier failed: 2.900000 != 2.900000, at index 0",
1229             r.Error());
1230 }
1231 
TEST_F(VerifierTest,ProbeSSBOLess)1232 TEST_F(VerifierTest, ProbeSSBOLess) {
1233   Pipeline pipeline(PipelineType::kGraphics);
1234   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1235 
1236   ProbeSSBOCommand probe_ssbo(color_buf.get());
1237 
1238   TypeParser parser;
1239   auto type = parser.Parse("R64_SFLOAT");
1240   Format fmt(type.get());
1241 
1242   probe_ssbo.SetFormat(&fmt);
1243   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLess);
1244 
1245   std::vector<Value> values;
1246   values.resize(4);
1247   values[0].SetDoubleValue(2.9);
1248   values[1].SetDoubleValue(0.73);
1249   values[2].SetDoubleValue(10.0);
1250   values[3].SetDoubleValue(1234.56);
1251   probe_ssbo.SetValues(std::move(values));
1252 
1253   const double ssbo[4] = {1.9, 0.63, 9.99, 1234.559};
1254 
1255   Verifier verifier;
1256   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1257   EXPECT_TRUE(r.IsSuccess()) << r.Error();
1258 }
1259 
TEST_F(VerifierTest,ProbeSSBOLessFail)1260 TEST_F(VerifierTest, ProbeSSBOLessFail) {
1261   Pipeline pipeline(PipelineType::kGraphics);
1262   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1263 
1264   ProbeSSBOCommand probe_ssbo(color_buf.get());
1265 
1266   TypeParser parser;
1267   auto type = parser.Parse("R64_SFLOAT");
1268   Format fmt(type.get());
1269 
1270   probe_ssbo.SetFormat(&fmt);
1271   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLess);
1272 
1273   std::vector<Value> values;
1274   values.resize(4);
1275   values[0].SetDoubleValue(2.9);
1276   values[1].SetDoubleValue(0.73);
1277   values[2].SetDoubleValue(10.0);
1278   values[3].SetDoubleValue(1234.56);
1279   probe_ssbo.SetValues(std::move(values));
1280 
1281   const double ssbo[4] = {3.9, 0.83, 10.1, 1234.57};
1282 
1283   Verifier verifier;
1284   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1285   EXPECT_FALSE(r.IsSuccess());
1286   EXPECT_EQ("Line 1: Verifier failed: 3.900000 < 2.900000, at index 0",
1287             r.Error());
1288 }
1289 
TEST_F(VerifierTest,ProbeSSBOLessOrEqual)1290 TEST_F(VerifierTest, ProbeSSBOLessOrEqual) {
1291   Pipeline pipeline(PipelineType::kGraphics);
1292   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1293 
1294   ProbeSSBOCommand probe_ssbo(color_buf.get());
1295 
1296   TypeParser parser;
1297   auto type = parser.Parse("R64_SFLOAT");
1298   Format fmt(type.get());
1299 
1300   probe_ssbo.SetFormat(&fmt);
1301   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLessOrEqual);
1302 
1303   std::vector<Value> values;
1304   values.resize(4);
1305   values[0].SetDoubleValue(2.9);
1306   values[1].SetDoubleValue(0.73);
1307   values[2].SetDoubleValue(10.0);
1308   values[3].SetDoubleValue(1234.56);
1309   probe_ssbo.SetValues(std::move(values));
1310 
1311   const double ssbo[4] = {1.9, 0.73, 9.99, 1234.560};
1312 
1313   Verifier verifier;
1314   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1315   EXPECT_TRUE(r.IsSuccess()) << r.Error();
1316 }
1317 
TEST_F(VerifierTest,ProbeSSBOLessOrEqualFail)1318 TEST_F(VerifierTest, ProbeSSBOLessOrEqualFail) {
1319   Pipeline pipeline(PipelineType::kGraphics);
1320   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1321 
1322   ProbeSSBOCommand probe_ssbo(color_buf.get());
1323 
1324   TypeParser parser;
1325   auto type = parser.Parse("R64_SFLOAT");
1326   Format fmt(type.get());
1327 
1328   probe_ssbo.SetFormat(&fmt);
1329   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLessOrEqual);
1330 
1331   std::vector<Value> values;
1332   values.resize(4);
1333   values[0].SetDoubleValue(2.9);
1334   values[1].SetDoubleValue(0.73);
1335   values[2].SetDoubleValue(10.0);
1336   values[3].SetDoubleValue(1234.56);
1337   probe_ssbo.SetValues(std::move(values));
1338 
1339   const double ssbo[4] = {1.9, 0.73, 9.99, 1234.561};
1340 
1341   Verifier verifier;
1342   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1343   EXPECT_FALSE(r.IsSuccess());
1344   EXPECT_EQ("Line 1: Verifier failed: 1234.561000 <= 1234.560000, at index 3",
1345             r.Error());
1346 }
1347 
TEST_F(VerifierTest,ProbeSSBOGreater)1348 TEST_F(VerifierTest, ProbeSSBOGreater) {
1349   Pipeline pipeline(PipelineType::kGraphics);
1350   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1351 
1352   ProbeSSBOCommand probe_ssbo(color_buf.get());
1353 
1354   TypeParser parser;
1355   auto type = parser.Parse("R64_SFLOAT");
1356   Format fmt(type.get());
1357 
1358   probe_ssbo.SetFormat(&fmt);
1359   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kGreater);
1360 
1361   std::vector<Value> values;
1362   values.resize(4);
1363   values[0].SetDoubleValue(2.9);
1364   values[1].SetDoubleValue(0.73);
1365   values[2].SetDoubleValue(10.0);
1366   values[3].SetDoubleValue(1234.56);
1367   probe_ssbo.SetValues(std::move(values));
1368 
1369   const double ssbo[4] = {3.9, 0.83, 10.1, 1234.57};
1370 
1371   Verifier verifier;
1372   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1373   EXPECT_TRUE(r.IsSuccess()) << r.Error();
1374 }
1375 
TEST_F(VerifierTest,ProbeSSBOGreaterFail)1376 TEST_F(VerifierTest, ProbeSSBOGreaterFail) {
1377   Pipeline pipeline(PipelineType::kGraphics);
1378   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1379 
1380   ProbeSSBOCommand probe_ssbo(color_buf.get());
1381 
1382   TypeParser parser;
1383   auto type = parser.Parse("R64_SFLOAT");
1384   Format fmt(type.get());
1385 
1386   probe_ssbo.SetFormat(&fmt);
1387   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kGreater);
1388 
1389   std::vector<Value> values;
1390   values.resize(4);
1391   values[0].SetDoubleValue(2.9);
1392   values[1].SetDoubleValue(0.73);
1393   values[2].SetDoubleValue(10.0);
1394   values[3].SetDoubleValue(1234.56);
1395   probe_ssbo.SetValues(std::move(values));
1396 
1397   const double ssbo[4] = {3.9, 0.73, 10.1, 1234.57};
1398 
1399   Verifier verifier;
1400   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1401   EXPECT_FALSE(r.IsSuccess());
1402   EXPECT_EQ("Line 1: Verifier failed: 0.730000 > 0.730000, at index 1",
1403             r.Error());
1404 }
1405 
TEST_F(VerifierTest,ProbeSSBOGreaterOrEqual)1406 TEST_F(VerifierTest, ProbeSSBOGreaterOrEqual) {
1407   Pipeline pipeline(PipelineType::kGraphics);
1408   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1409 
1410   ProbeSSBOCommand probe_ssbo(color_buf.get());
1411 
1412   TypeParser parser;
1413   auto type = parser.Parse("R64_SFLOAT");
1414   Format fmt(type.get());
1415 
1416   probe_ssbo.SetFormat(&fmt);
1417   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kGreaterOrEqual);
1418 
1419   std::vector<Value> values;
1420   values.resize(4);
1421   values[0].SetDoubleValue(2.9);
1422   values[1].SetDoubleValue(0.73);
1423   values[2].SetDoubleValue(10.0);
1424   values[3].SetDoubleValue(1234.56);
1425   probe_ssbo.SetValues(std::move(values));
1426 
1427   const double ssbo[4] = {3.9, 0.73, 10.1, 1234.56};
1428 
1429   Verifier verifier;
1430   Result r = verifier.ProbeSSBO(&probe_ssbo, sizeof(double) * 4, ssbo);
1431   EXPECT_TRUE(r.IsSuccess()) << r.Error();
1432 }
1433 
TEST_F(VerifierTest,ProbeSSBOGreaterOrEqualFail)1434 TEST_F(VerifierTest, ProbeSSBOGreaterOrEqualFail) {
1435   Pipeline pipeline(PipelineType::kGraphics);
1436   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1437 
1438   ProbeSSBOCommand probe_ssbo(color_buf.get());
1439 
1440   TypeParser parser;
1441   auto type = parser.Parse("R64_SFLOAT");
1442   Format fmt(type.get());
1443 
1444   probe_ssbo.SetFormat(&fmt);
1445   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kGreaterOrEqual);
1446 
1447   std::vector<Value> values;
1448   values.resize(4);
1449   values[0].SetDoubleValue(2.9);
1450   values[1].SetDoubleValue(0.73);
1451   values[2].SetDoubleValue(10.0);
1452   values[3].SetDoubleValue(1234.56);
1453   probe_ssbo.SetValues(std::move(values));
1454 
1455   const double ssbo[4] = {3.9, 0.73, 10.1, 1234.559};
1456 
1457   Verifier verifier;
1458   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1459   EXPECT_FALSE(r.IsSuccess());
1460   EXPECT_EQ("Line 1: Verifier failed: 1234.559000 >= 1234.560000, at index 3",
1461             r.Error());
1462 }
1463 
TEST_F(VerifierTest,CheckRGBAOrderForFailure)1464 TEST_F(VerifierTest, CheckRGBAOrderForFailure) {
1465   Pipeline pipeline(PipelineType::kGraphics);
1466   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1467 
1468   ProbeCommand probe(color_buf.get());
1469   probe.SetIsRGBA();
1470   probe.SetX(0.0f);
1471   probe.SetY(0.0f);
1472   probe.SetR(0.6f);
1473   probe.SetG(0.4f);
1474   probe.SetB(0.0f);
1475   probe.SetA(0.3f);
1476 
1477   uint8_t frame_buffer[4] = {255, 14, 75, 8};
1478 
1479   Verifier verifier;
1480   Result r = verifier.Probe(&probe, GetColorFormat(),
1481                             4U * static_cast<uint32_t>(sizeof(uint8_t)),
1482                             4U * static_cast<uint32_t>(sizeof(uint8_t)), 1U, 1U,
1483                             static_cast<const void*>(&frame_buffer));
1484   EXPECT_FALSE(r.IsSuccess());
1485   EXPECT_EQ(
1486       "Line 1: Probe failed at: 0, 0\n  Expected: 153.000000, 102.000000, "
1487       "0.000000, 76.500000\n    Actual: 75.000000, 14.000000, 255.000000, "
1488       "8.000000\nProbe failed in 1 pixels",
1489       r.Error());
1490 }
1491 
TEST_F(VerifierTest,ProbeSSBOWithPadding)1492 TEST_F(VerifierTest, ProbeSSBOWithPadding) {
1493   Pipeline pipeline(PipelineType::kGraphics);
1494   auto color_buf = pipeline.GenerateDefaultColorAttachmentBuffer();
1495 
1496   ProbeSSBOCommand probe_ssbo(color_buf.get());
1497 
1498   TypeParser parser;
1499   auto type = parser.Parse("float/vec2");
1500   Format fmt(type.get());
1501 
1502   probe_ssbo.SetFormat(&fmt);
1503   ASSERT_TRUE(probe_ssbo.GetFormat() != nullptr);
1504 
1505   probe_ssbo.SetComparator(ProbeSSBOCommand::Comparator::kLessOrEqual);
1506 
1507   std::vector<Value> values;
1508   values.resize(4);
1509   values[0].SetDoubleValue(2.9);
1510   values[1].SetDoubleValue(0.73);
1511   values[2].SetDoubleValue(10.0);
1512   values[3].SetDoubleValue(1234.56);
1513   probe_ssbo.SetValues(std::move(values));
1514 
1515   // The vec2 will get padded to 4 bytes in std430.
1516   const float ssbo[8] = {1.9f, 0.73f, 0.0f, 0.0f, 9.99f, 1234.560f, 0.0f, 0.0f};
1517 
1518   Verifier verifier;
1519   Result r = verifier.ProbeSSBO(&probe_ssbo, 4, ssbo);
1520   EXPECT_TRUE(r.IsSuccess()) << r.Error();
1521 }
1522 
1523 }  // namespace amber
1524