1 // Copyright 2019 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 parseried.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "gtest/gtest.h"
16 #include "src/amberscript/parser.h"
17
18 namespace amber {
19 namespace amberscript {
20
21 using AmberScriptParserTest = testing::Test;
22
TEST_F(AmberScriptParserTest,ExpectRGB)23 TEST_F(AmberScriptParserTest, ExpectRGB) {
24 std::string in = R"(
25 SHADER vertex my_shader PASSTHROUGH
26 SHADER fragment my_fragment GLSL
27 # GLSL Shader
28 END
29 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
30
31 PIPELINE graphics my_pipeline
32 ATTACH my_shader
33 ATTACH my_fragment
34
35 BIND BUFFER my_fb AS color LOCATION 0
36 END
37
38 EXPECT my_fb IDX 5 6 SIZE 250 150 EQ_RGB 2 128 255)";
39
40 Parser parser;
41 Result r = parser.Parse(in);
42 ASSERT_TRUE(r.IsSuccess()) << r.Error();
43
44 auto script = parser.GetScript();
45 const auto& commands = script->GetCommands();
46 ASSERT_EQ(1U, commands.size());
47
48 auto* cmd = commands[0].get();
49 ASSERT_TRUE(cmd->IsProbe());
50
51 auto* probe = cmd->AsProbe();
52 EXPECT_FALSE(probe->IsRGBA());
53 EXPECT_TRUE(probe->IsProbeRect());
54 EXPECT_FALSE(probe->IsRelative());
55 EXPECT_FALSE(probe->IsWholeWindow());
56 EXPECT_EQ(5U, probe->GetX());
57 EXPECT_EQ(6U, probe->GetY());
58 EXPECT_EQ(250U, probe->GetWidth());
59 EXPECT_EQ(150U, probe->GetHeight());
60 EXPECT_FLOAT_EQ(2.f / 255.f, probe->GetR());
61 EXPECT_FLOAT_EQ(128.f / 255.f, probe->GetG());
62 EXPECT_FLOAT_EQ(255.f / 255.f, probe->GetB());
63 }
64
TEST_F(AmberScriptParserTest,ExpectRGBA)65 TEST_F(AmberScriptParserTest, ExpectRGBA) {
66 std::string in = R"(
67 SHADER vertex my_shader PASSTHROUGH
68 SHADER fragment my_fragment GLSL
69 # GLSL Shader
70 END
71 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
72
73 PIPELINE graphics my_pipeline
74 ATTACH my_shader
75 ATTACH my_fragment
76
77 BIND BUFFER my_fb AS color LOCATION 0
78 END
79
80 EXPECT my_fb IDX 2 7 SIZE 20 88 EQ_RGBA 2 128 255 99)";
81
82 Parser parser;
83 Result r = parser.Parse(in);
84 ASSERT_TRUE(r.IsSuccess()) << r.Error();
85
86 auto script = parser.GetScript();
87 const auto& commands = script->GetCommands();
88 ASSERT_EQ(1U, commands.size());
89
90 auto* cmd = commands[0].get();
91 ASSERT_TRUE(cmd->IsProbe());
92
93 auto* probe = cmd->AsProbe();
94 EXPECT_TRUE(probe->IsRGBA());
95 EXPECT_TRUE(probe->IsProbeRect());
96 EXPECT_FALSE(probe->IsRelative());
97 EXPECT_FALSE(probe->IsWholeWindow());
98 EXPECT_EQ(2U, probe->GetX());
99 EXPECT_EQ(7U, probe->GetY());
100 EXPECT_EQ(20U, probe->GetWidth());
101 EXPECT_EQ(88U, probe->GetHeight());
102 EXPECT_FLOAT_EQ(2.f / 255.f, probe->GetR());
103 EXPECT_FLOAT_EQ(128.f / 255.f, probe->GetG());
104 EXPECT_FLOAT_EQ(255.f / 255.f, probe->GetB());
105 EXPECT_FLOAT_EQ(99.f / 255.f, probe->GetA());
106 }
107
TEST_F(AmberScriptParserTest,ExpectMissingBufferName)108 TEST_F(AmberScriptParserTest, ExpectMissingBufferName) {
109 std::string in = R"(
110 SHADER vertex my_shader PASSTHROUGH
111 SHADER fragment my_fragment GLSL
112 # GLSL Shader
113 END
114 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
115
116 PIPELINE graphics my_pipeline
117 ATTACH my_shader
118 ATTACH my_fragment
119
120 BIND BUFFER my_fb AS color LOCATION 0
121 END
122
123 EXPECT IDX 0 0 SIZE 250 250 EQ_RGB 0 128 255)";
124
125 Parser parser;
126 Result r = parser.Parse(in);
127 ASSERT_FALSE(r.IsSuccess());
128 EXPECT_EQ("15: missing buffer name between EXPECT and IDX", r.Error());
129 }
130
TEST_F(AmberScriptParserTest,ExpectInvalidBufferName)131 TEST_F(AmberScriptParserTest, ExpectInvalidBufferName) {
132 std::string in = R"(
133 SHADER vertex my_shader PASSTHROUGH
134 SHADER fragment my_fragment GLSL
135 # GLSL Shader
136 END
137 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
138
139 PIPELINE graphics my_pipeline
140 ATTACH my_shader
141 ATTACH my_fragment
142
143 BIND BUFFER my_fb AS color LOCATION 0
144 END
145
146 EXPECT unknown_buffer IDX 0 0 SIZE 250 250 EQ_RGB 0 128 255)";
147
148 Parser parser;
149 Result r = parser.Parse(in);
150 ASSERT_FALSE(r.IsSuccess());
151 EXPECT_EQ("15: unknown buffer name for EXPECT command: unknown_buffer",
152 r.Error());
153 }
154
TEST_F(AmberScriptParserTest,ExpectMissingIDX)155 TEST_F(AmberScriptParserTest, ExpectMissingIDX) {
156 std::string in = R"(
157 SHADER vertex my_shader PASSTHROUGH
158 SHADER fragment my_fragment GLSL
159 # GLSL Shader
160 END
161 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
162
163 PIPELINE graphics my_pipeline
164 ATTACH my_shader
165 ATTACH my_fragment
166
167 BIND BUFFER my_fb AS color LOCATION 0
168 END
169
170 EXPECT my_fb 0 0 SIZE 250 250 EQ_RGB 0 128 255)";
171
172 Parser parser;
173 Result r = parser.Parse(in);
174 ASSERT_FALSE(r.IsSuccess());
175 EXPECT_EQ("15: invalid comparator in EXPECT command", r.Error());
176 }
177
TEST_F(AmberScriptParserTest,ExpectMissingIDXValues)178 TEST_F(AmberScriptParserTest, ExpectMissingIDXValues) {
179 std::string in = R"(
180 SHADER vertex my_shader PASSTHROUGH
181 SHADER fragment my_fragment GLSL
182 # GLSL Shader
183 END
184 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
185
186 PIPELINE graphics my_pipeline
187 ATTACH my_shader
188 ATTACH my_fragment
189
190 BIND BUFFER my_fb AS color LOCATION 0
191 END
192
193 EXPECT my_fb IDX SIZE 250 250 EQ_RGB 0 128 255)";
194
195 Parser parser;
196 Result r = parser.Parse(in);
197 ASSERT_FALSE(r.IsSuccess());
198 EXPECT_EQ("15: invalid X value in EXPECT command", r.Error());
199 }
200
TEST_F(AmberScriptParserTest,ExpectMissingIdxY)201 TEST_F(AmberScriptParserTest, ExpectMissingIdxY) {
202 std::string in = R"(
203 SHADER vertex my_shader PASSTHROUGH
204 SHADER fragment my_fragment GLSL
205 # GLSL Shader
206 END
207 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
208
209 PIPELINE graphics my_pipeline
210 ATTACH my_shader
211 ATTACH my_fragment
212
213 BIND BUFFER my_fb AS color LOCATION 0
214 END
215
216 EXPECT my_fb IDX 0 SIZE 250 250 EQ_RGB 0 128 255)";
217
218 Parser parser;
219 Result r = parser.Parse(in);
220 ASSERT_FALSE(r.IsSuccess());
221 EXPECT_EQ("15: invalid Y value in EXPECT command", r.Error());
222 }
223
TEST_F(AmberScriptParserTest,ExpectIdxInvalidX)224 TEST_F(AmberScriptParserTest, ExpectIdxInvalidX) {
225 std::string in = R"(
226 SHADER vertex my_shader PASSTHROUGH
227 SHADER fragment my_fragment GLSL
228 # GLSL Shader
229 END
230 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
231
232 PIPELINE graphics my_pipeline
233 ATTACH my_shader
234 ATTACH my_fragment
235
236 BIND BUFFER my_fb AS color LOCATION 0
237 END
238
239 EXPECT my_fb IDX INVAILD 0 SIZE 250 250 EQ_RGB 0 128 255)";
240
241 Parser parser;
242 Result r = parser.Parse(in);
243 ASSERT_FALSE(r.IsSuccess());
244 EXPECT_EQ("15: invalid X value in EXPECT command", r.Error());
245 }
246
TEST_F(AmberScriptParserTest,ExpectIdxInvalidY)247 TEST_F(AmberScriptParserTest, ExpectIdxInvalidY) {
248 std::string in = R"(
249 SHADER vertex my_shader PASSTHROUGH
250 SHADER fragment my_fragment GLSL
251 # GLSL Shader
252 END
253 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
254
255 PIPELINE graphics my_pipeline
256 ATTACH my_shader
257 ATTACH my_fragment
258
259 BIND BUFFER my_fb AS color LOCATION 0
260 END
261
262 EXPECT my_fb IDX 0 INVALID SIZE 250 250 EQ_RGB 0 128 255)";
263
264 Parser parser;
265 Result r = parser.Parse(in);
266 ASSERT_FALSE(r.IsSuccess());
267 EXPECT_EQ("15: unexpected token in EXPECT command: INVALID", r.Error());
268 }
269
TEST_F(AmberScriptParserTest,ExpectRGBMissingSize)270 TEST_F(AmberScriptParserTest, ExpectRGBMissingSize) {
271 std::string in = R"(
272 SHADER vertex my_shader PASSTHROUGH
273 SHADER fragment my_fragment GLSL
274 # GLSL Shader
275 END
276 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
277
278 PIPELINE graphics my_pipeline
279 ATTACH my_shader
280 ATTACH my_fragment
281
282 BIND BUFFER my_fb AS color LOCATION 0
283 END
284
285 EXPECT my_fb IDX 0 0 250 250 EQ_RGB 0 128 255)";
286
287 Parser parser;
288 Result r = parser.Parse(in);
289 ASSERT_FALSE(r.IsSuccess());
290 EXPECT_EQ("15: unexpected token in EXPECT command: 250", r.Error());
291 }
292
TEST_F(AmberScriptParserTest,ExpectSizeMissingValues)293 TEST_F(AmberScriptParserTest, ExpectSizeMissingValues) {
294 std::string in = R"(
295 SHADER vertex my_shader PASSTHROUGH
296 SHADER fragment my_fragment GLSL
297 # GLSL Shader
298 END
299 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
300
301 PIPELINE graphics my_pipeline
302 ATTACH my_shader
303 ATTACH my_fragment
304
305 BIND BUFFER my_fb AS color LOCATION 0
306 END
307
308 EXPECT my_fb IDX 0 0 SIZE EQ_RGB 0 128 255)";
309
310 Parser parser;
311 Result r = parser.Parse(in);
312 ASSERT_FALSE(r.IsSuccess());
313 EXPECT_EQ("15: invalid width in EXPECT command", r.Error());
314 }
315
TEST_F(AmberScriptParserTest,ExpectSizeMissingHeight)316 TEST_F(AmberScriptParserTest, ExpectSizeMissingHeight) {
317 std::string in = R"(
318 SHADER vertex my_shader PASSTHROUGH
319 SHADER fragment my_fragment GLSL
320 # GLSL Shader
321 END
322 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
323
324 PIPELINE graphics my_pipeline
325 ATTACH my_shader
326 ATTACH my_fragment
327
328 BIND BUFFER my_fb AS color LOCATION 0
329 END
330
331 EXPECT my_fb IDX 0 0 SIZE 250 EQ_RGB 0 128 255)";
332
333 Parser parser;
334 Result r = parser.Parse(in);
335 ASSERT_FALSE(r.IsSuccess());
336 EXPECT_EQ("15: invalid height in EXPECT command", r.Error());
337 }
338
TEST_F(AmberScriptParserTest,ExpectSizeInvalidWidth)339 TEST_F(AmberScriptParserTest, ExpectSizeInvalidWidth) {
340 std::string in = R"(
341 SHADER vertex my_shader PASSTHROUGH
342 SHADER fragment my_fragment GLSL
343 # GLSL Shader
344 END
345 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
346
347 PIPELINE graphics my_pipeline
348 ATTACH my_shader
349 ATTACH my_fragment
350
351 BIND BUFFER my_fb AS color LOCATION 0
352 END
353
354 EXPECT my_fb IDX 0 0 SIZE INVALID 250 EQ_RGB 0 128 255)";
355
356 Parser parser;
357 Result r = parser.Parse(in);
358 ASSERT_FALSE(r.IsSuccess());
359 EXPECT_EQ("15: invalid width in EXPECT command", r.Error());
360 }
361
TEST_F(AmberScriptParserTest,ExpectSizeInvalidHeight)362 TEST_F(AmberScriptParserTest, ExpectSizeInvalidHeight) {
363 std::string in = R"(
364 SHADER vertex my_shader PASSTHROUGH
365 SHADER fragment my_fragment GLSL
366 # GLSL Shader
367 END
368 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
369
370 PIPELINE graphics my_pipeline
371 ATTACH my_shader
372 ATTACH my_fragment
373
374 BIND BUFFER my_fb AS color LOCATION 0
375 END
376
377 EXPECT my_fb IDX 0 0 SIZE 250 INVALID EQ_RGB 0 128 255)";
378
379 Parser parser;
380 Result r = parser.Parse(in);
381 ASSERT_FALSE(r.IsSuccess());
382 EXPECT_EQ("15: invalid height in EXPECT command", r.Error());
383 }
384
TEST_F(AmberScriptParserTest,ExpectSizeInvalidComparitor)385 TEST_F(AmberScriptParserTest, ExpectSizeInvalidComparitor) {
386 std::string in = R"(
387 SHADER vertex my_shader PASSTHROUGH
388 SHADER fragment my_fragment GLSL
389 # GLSL Shader
390 END
391 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
392
393 PIPELINE graphics my_pipeline
394 ATTACH my_shader
395 ATTACH my_fragment
396
397 BIND BUFFER my_fb AS color LOCATION 0
398 END
399
400 EXPECT my_fb IDX 0 0 SIZE 250 250 INVALID 0 128 255)";
401
402 Parser parser;
403 Result r = parser.Parse(in);
404 ASSERT_FALSE(r.IsSuccess());
405 EXPECT_EQ("15: unknown comparator type in EXPECT: INVALID", r.Error());
406 }
407
TEST_F(AmberScriptParserTest,ExpectRGBMissingValues)408 TEST_F(AmberScriptParserTest, ExpectRGBMissingValues) {
409 std::string in = R"(
410 SHADER vertex my_shader PASSTHROUGH
411 SHADER fragment my_fragment GLSL
412 # GLSL Shader
413 END
414 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
415
416 PIPELINE graphics my_pipeline
417 ATTACH my_shader
418 ATTACH my_fragment
419
420 BIND BUFFER my_fb AS color LOCATION 0
421 END
422
423 EXPECT my_fb IDX 0 0 SIZE 250 250 EQ_RGB)";
424
425 Parser parser;
426 Result r = parser.Parse(in);
427 ASSERT_FALSE(r.IsSuccess());
428 EXPECT_EQ("15: invalid R value in EXPECT command", r.Error());
429 }
430
TEST_F(AmberScriptParserTest,ExpectRGBMissingB)431 TEST_F(AmberScriptParserTest, ExpectRGBMissingB) {
432 std::string in = R"(
433 SHADER vertex my_shader PASSTHROUGH
434 SHADER fragment my_fragment GLSL
435 # GLSL Shader
436 END
437 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
438
439 PIPELINE graphics my_pipeline
440 ATTACH my_shader
441 ATTACH my_fragment
442
443 BIND BUFFER my_fb AS color LOCATION 0
444 END
445
446 EXPECT my_fb IDX 0 0 SIZE 250 250 EQ_RGB 0 128)";
447
448 Parser parser;
449 Result r = parser.Parse(in);
450 ASSERT_FALSE(r.IsSuccess());
451 EXPECT_EQ("15: invalid B value in EXPECT command", r.Error());
452 }
453
TEST_F(AmberScriptParserTest,ExpectRGBMissingG)454 TEST_F(AmberScriptParserTest, ExpectRGBMissingG) {
455 std::string in = R"(
456 SHADER vertex my_shader PASSTHROUGH
457 SHADER fragment my_fragment GLSL
458 # GLSL Shader
459 END
460 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
461
462 PIPELINE graphics my_pipeline
463 ATTACH my_shader
464 ATTACH my_fragment
465
466 BIND BUFFER my_fb AS color LOCATION 0
467 END
468
469 EXPECT my_fb IDX 0 0 SIZE 250 250 EQ_RGB 0)";
470
471 Parser parser;
472 Result r = parser.Parse(in);
473 ASSERT_FALSE(r.IsSuccess());
474 EXPECT_EQ("15: invalid G value in EXPECT command", r.Error());
475 }
476
TEST_F(AmberScriptParserTest,ExpectRGBAMissingA)477 TEST_F(AmberScriptParserTest, ExpectRGBAMissingA) {
478 std::string in = R"(
479 SHADER vertex my_shader PASSTHROUGH
480 SHADER fragment my_fragment GLSL
481 # GLSL Shader
482 END
483 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
484
485 PIPELINE graphics my_pipeline
486 ATTACH my_shader
487 ATTACH my_fragment
488
489 BIND BUFFER my_fb AS color LOCATION 0
490 END
491
492 EXPECT my_fb IDX 0 0 SIZE 250 250 EQ_RGBA 0 128 255)";
493
494 Parser parser;
495 Result r = parser.Parse(in);
496 ASSERT_FALSE(r.IsSuccess());
497 EXPECT_EQ("15: invalid A value in EXPECT command", r.Error());
498 }
499
TEST_F(AmberScriptParserTest,ExpectRGBInvalidR)500 TEST_F(AmberScriptParserTest, ExpectRGBInvalidR) {
501 std::string in = R"(
502 SHADER vertex my_shader PASSTHROUGH
503 SHADER fragment my_fragment GLSL
504 # GLSL Shader
505 END
506 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
507
508 PIPELINE graphics my_pipeline
509 ATTACH my_shader
510 ATTACH my_fragment
511
512 BIND BUFFER my_fb AS color LOCATION 0
513 END
514
515 EXPECT my_fb IDX 0 0 SIZE 250 250 EQ_RGB INVALID 128 255)";
516
517 Parser parser;
518 Result r = parser.Parse(in);
519 ASSERT_FALSE(r.IsSuccess());
520 EXPECT_EQ("15: invalid R value in EXPECT command", r.Error());
521 }
522
TEST_F(AmberScriptParserTest,ExpectRGBInvalidG)523 TEST_F(AmberScriptParserTest, ExpectRGBInvalidG) {
524 std::string in = R"(
525 SHADER vertex my_shader PASSTHROUGH
526 SHADER fragment my_fragment GLSL
527 # GLSL Shader
528 END
529 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
530
531 PIPELINE graphics my_pipeline
532 ATTACH my_shader
533 ATTACH my_fragment
534
535 BIND BUFFER my_fb AS color LOCATION 0
536 END
537
538 EXPECT my_fb IDX 0 0 SIZE 250 250 EQ_RGB 0 INVALID 255)";
539
540 Parser parser;
541 Result r = parser.Parse(in);
542 ASSERT_FALSE(r.IsSuccess());
543 EXPECT_EQ("15: invalid G value in EXPECT command", r.Error());
544 }
545
TEST_F(AmberScriptParserTest,ExpectRGBInvalidB)546 TEST_F(AmberScriptParserTest, ExpectRGBInvalidB) {
547 std::string in = R"(
548 SHADER vertex my_shader PASSTHROUGH
549 SHADER fragment my_fragment GLSL
550 # GLSL Shader
551 END
552 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
553
554 PIPELINE graphics my_pipeline
555 ATTACH my_shader
556 ATTACH my_fragment
557
558 BIND BUFFER my_fb AS color LOCATION 0
559 END
560
561 EXPECT my_fb IDX 0 0 SIZE 250 250 EQ_RGB 0 128 INVALID)";
562
563 Parser parser;
564 Result r = parser.Parse(in);
565 ASSERT_FALSE(r.IsSuccess());
566 EXPECT_EQ("15: invalid B value in EXPECT command", r.Error());
567 }
568
TEST_F(AmberScriptParserTest,ExpectRGBAInvalidA)569 TEST_F(AmberScriptParserTest, ExpectRGBAInvalidA) {
570 std::string in = R"(
571 SHADER vertex my_shader PASSTHROUGH
572 SHADER fragment my_fragment GLSL
573 # GLSL Shader
574 END
575 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
576
577 PIPELINE graphics my_pipeline
578 ATTACH my_shader
579 ATTACH my_fragment
580
581 BIND BUFFER my_fb AS color LOCATION 0
582 END
583
584 EXPECT my_fb IDX 0 0 SIZE 250 250 EQ_RGBA 0 128 255 INVALID)";
585
586 Parser parser;
587 Result r = parser.Parse(in);
588 ASSERT_FALSE(r.IsSuccess());
589 EXPECT_EQ("15: invalid A value in EXPECT command", r.Error());
590 }
591
TEST_F(AmberScriptParserTest,ExpectRGBExtraParam)592 TEST_F(AmberScriptParserTest, ExpectRGBExtraParam) {
593 std::string in = R"(
594 SHADER vertex my_shader PASSTHROUGH
595 SHADER fragment my_fragment GLSL
596 # GLSL Shader
597 END
598 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
599
600 PIPELINE graphics my_pipeline
601 ATTACH my_shader
602 ATTACH my_fragment
603
604 BIND BUFFER my_fb AS color LOCATION 0
605 END
606
607 EXPECT my_fb IDX 0 0 SIZE 250 250 EQ_RGB 0 128 255 EXTRA)";
608
609 Parser parser;
610 Result r = parser.Parse(in);
611 ASSERT_FALSE(r.IsSuccess());
612 EXPECT_EQ("15: extra parameters after EXPECT command: EXTRA", r.Error());
613 }
614
TEST_F(AmberScriptParserTest,ExpectRGBAExtraParam)615 TEST_F(AmberScriptParserTest, ExpectRGBAExtraParam) {
616 std::string in = R"(
617 SHADER vertex my_shader PASSTHROUGH
618 SHADER fragment my_fragment GLSL
619 # GLSL Shader
620 END
621 BUFFER my_fb FORMAT R32G32B32A32_SFLOAT
622
623 PIPELINE graphics my_pipeline
624 ATTACH my_shader
625 ATTACH my_fragment
626
627 BIND BUFFER my_fb AS color LOCATION 0
628 END
629
630 EXPECT my_fb IDX 0 0 SIZE 250 250 EQ_RGBA 0 128 255 99 EXTRA)";
631
632 Parser parser;
633 Result r = parser.Parse(in);
634 ASSERT_FALSE(r.IsSuccess());
635 EXPECT_EQ("15: extra parameters after EXPECT command: EXTRA", r.Error());
636 }
637
TEST_F(AmberScriptParserTest,ExpectEQ)638 TEST_F(AmberScriptParserTest, ExpectEQ) {
639 std::string in = R"(
640 BUFFER orig_buf DATA_TYPE int32 SIZE 100 FILL 11
641 EXPECT orig_buf IDX 5 EQ 11)";
642
643 Parser parser;
644 Result r = parser.Parse(in);
645 ASSERT_TRUE(r.IsSuccess()) << r.Error();
646
647 auto script = parser.GetScript();
648 const auto& commands = script->GetCommands();
649 ASSERT_EQ(1U, commands.size());
650
651 auto* cmd = commands[0].get();
652 ASSERT_TRUE(cmd->IsProbeSSBO());
653
654 auto* probe = cmd->AsProbeSSBO();
655 EXPECT_EQ(ProbeSSBOCommand::Comparator::kEqual, probe->GetComparator());
656 EXPECT_EQ(5U, probe->GetOffset());
657 EXPECT_TRUE(probe->GetFormat()->IsInt32());
658 ASSERT_EQ(1U, probe->GetValues().size());
659 EXPECT_EQ(11, probe->GetValues()[0].AsInt32());
660 }
661
TEST_F(AmberScriptParserTest,ExpectEQStruct)662 TEST_F(AmberScriptParserTest, ExpectEQStruct) {
663 std::string in = R"(
664 STRUCT data
665 float a
666 int32 b
667 END
668
669 BUFFER orig_buf DATA_TYPE data DATA 2.3 44 4.4 99 END
670 EXPECT orig_buf IDX 0 EQ 2.3 44
671 EXPECT orig_buf IDX 8 EQ 2.3 44)";
672
673 Parser parser;
674 Result r = parser.Parse(in);
675 ASSERT_TRUE(r.IsSuccess()) << r.Error();
676
677 auto script = parser.GetScript();
678 const auto& commands = script->GetCommands();
679 ASSERT_EQ(2U, commands.size());
680
681 auto* cmd = commands[0].get();
682 ASSERT_TRUE(cmd->IsProbeSSBO());
683
684 auto* probe = cmd->AsProbeSSBO();
685 EXPECT_EQ(ProbeSSBOCommand::Comparator::kEqual, probe->GetComparator());
686 ASSERT_EQ(2U, probe->GetValues().size());
687 EXPECT_EQ(2.3f, probe->GetValues()[0].AsFloat());
688 EXPECT_EQ(44, probe->GetValues()[1].AsInt32());
689
690 cmd = commands[1].get();
691 ASSERT_TRUE(cmd->IsProbeSSBO());
692
693 probe = cmd->AsProbeSSBO();
694 EXPECT_EQ(ProbeSSBOCommand::Comparator::kEqual, probe->GetComparator());
695 ASSERT_EQ(2U, probe->GetValues().size());
696 EXPECT_EQ(2.3f, probe->GetValues()[0].AsFloat());
697 EXPECT_EQ(44, probe->GetValues()[1].AsInt32());
698 }
699
TEST_F(AmberScriptParserTest,ExpectEqMissingValue)700 TEST_F(AmberScriptParserTest, ExpectEqMissingValue) {
701 std::string in = R"(
702 BUFFER orig_buf DATA_TYPE int32 SIZE 100 FILL 11
703 EXPECT orig_buf IDX 5 EQ)";
704
705 Parser parser;
706 Result r = parser.Parse(in);
707 ASSERT_FALSE(r.IsSuccess());
708 EXPECT_EQ("3: missing comparison values for EXPECT command", r.Error());
709 }
710
TEST_F(AmberScriptParserTest,ExpectEQExtraParams)711 TEST_F(AmberScriptParserTest, ExpectEQExtraParams) {
712 std::string in = R"(
713 BUFFER orig_buf DATA_TYPE int32 SIZE 100 FILL 11
714 EXPECT orig_buf IDX 5 EQ 11 EXTRA)";
715
716 Parser parser;
717 Result r = parser.Parse(in);
718 ASSERT_FALSE(r.IsSuccess());
719 EXPECT_EQ("3: Invalid value provided to EXPECT command: EXTRA", r.Error());
720 }
721
TEST_F(AmberScriptParserTest,MultipleExpect)722 TEST_F(AmberScriptParserTest, MultipleExpect) {
723 std::string in = R"(
724 BUFFER orig_buf DATA_TYPE int32 SIZE 100 FILL 11
725 BUFFER dest_buf DATA_TYPE int32 SIZE 100 FILL 22
726
727 EXPECT orig_buf IDX 0 EQ 11
728 EXPECT dest_buf IDX 0 EQ 22)";
729
730 Parser parser;
731 Result r = parser.Parse(in);
732 ASSERT_TRUE(r.IsSuccess()) << r.Error();
733 }
734
TEST_F(AmberScriptParserTest,ExpectEqBuffer)735 TEST_F(AmberScriptParserTest, ExpectEqBuffer) {
736 std::string in = R"(
737 BUFFER buf_1 DATA_TYPE int32 SIZE 10 FILL 11
738 BUFFER buf_2 DATA_TYPE int32 SIZE 10 FILL 11
739 EXPECT buf_1 EQ_BUFFER buf_2)";
740
741 Parser parser;
742 Result r = parser.Parse(in);
743 ASSERT_TRUE(r.IsSuccess()) << r.Error();
744
745 auto script = parser.GetScript();
746 const auto& commands = script->GetCommands();
747 ASSERT_EQ(1U, commands.size());
748
749 auto* cmd = commands[0].get();
750 ASSERT_TRUE(cmd->IsCompareBuffer());
751
752 auto* cmp = cmd->AsCompareBuffer();
753 EXPECT_EQ(cmp->GetComparator(), CompareBufferCommand::Comparator::kEq);
754
755 ASSERT_TRUE(cmp->GetBuffer1() != nullptr);
756 EXPECT_EQ(cmp->GetBuffer1()->GetName(), "buf_1");
757
758 ASSERT_TRUE(cmp->GetBuffer2() != nullptr);
759 EXPECT_EQ(cmp->GetBuffer2()->GetName(), "buf_2");
760 }
761
TEST_F(AmberScriptParserTest,ExpectEqBufferMissingFirstBuffer)762 TEST_F(AmberScriptParserTest, ExpectEqBufferMissingFirstBuffer) {
763 std::string in = R"(
764 BUFFER buf_2 DATA_TYPE int32 SIZE 10 FILL 22
765 EXPECT EQ_BUFFER buf_2)";
766
767 Parser parser;
768 Result r = parser.Parse(in);
769 ASSERT_FALSE(r.IsSuccess());
770 EXPECT_EQ("3: missing buffer name between EXPECT and EQ_BUFFER", r.Error());
771 }
772
TEST_F(AmberScriptParserTest,ExpectEqBufferMissingSecondBuffer)773 TEST_F(AmberScriptParserTest, ExpectEqBufferMissingSecondBuffer) {
774 std::string in = R"(
775 BUFFER buf_1 DATA_TYPE int32 SIZE 10 FILL 11
776 EXPECT buf_1 EQ_BUFFER)";
777
778 Parser parser;
779 Result r = parser.Parse(in);
780 ASSERT_FALSE(r.IsSuccess());
781 EXPECT_EQ("3: invalid buffer name in EXPECT EQ_BUFFER command", r.Error());
782 }
783
TEST_F(AmberScriptParserTest,ExpectEqBufferInvalidFirstBuffer)784 TEST_F(AmberScriptParserTest, ExpectEqBufferInvalidFirstBuffer) {
785 std::string in = R"(EXPECT 123 EQ_BUFFER)";
786
787 Parser parser;
788 Result r = parser.Parse(in);
789 ASSERT_FALSE(r.IsSuccess());
790 EXPECT_EQ("1: invalid buffer name in EXPECT command", r.Error());
791 }
792
TEST_F(AmberScriptParserTest,ExpectEqBufferUnknownFirstBuffer)793 TEST_F(AmberScriptParserTest, ExpectEqBufferUnknownFirstBuffer) {
794 std::string in = R"(EXPECT unknown_buffer EQ_BUFFER)";
795
796 Parser parser;
797 Result r = parser.Parse(in);
798 ASSERT_FALSE(r.IsSuccess());
799 EXPECT_EQ("1: unknown buffer name for EXPECT command: unknown_buffer",
800 r.Error());
801 }
802
TEST_F(AmberScriptParserTest,ExpectEqBufferInvalidSecondBuffer)803 TEST_F(AmberScriptParserTest, ExpectEqBufferInvalidSecondBuffer) {
804 std::string in = R"(
805 BUFFER buf DATA_TYPE int32 SIZE 10 FILL 11
806 EXPECT buf EQ_BUFFER 123)";
807
808 Parser parser;
809 Result r = parser.Parse(in);
810 ASSERT_FALSE(r.IsSuccess());
811 EXPECT_EQ("3: invalid buffer name in EXPECT EQ_BUFFER command", r.Error());
812 }
813
TEST_F(AmberScriptParserTest,ExpectEqBufferUnknownSecondBuffer)814 TEST_F(AmberScriptParserTest, ExpectEqBufferUnknownSecondBuffer) {
815 std::string in = R"(
816 BUFFER buf DATA_TYPE int32 SIZE 10 FILL 11
817 EXPECT buf EQ_BUFFER unknown_buffer)";
818
819 Parser parser;
820 Result r = parser.Parse(in);
821 ASSERT_FALSE(r.IsSuccess());
822 EXPECT_EQ(
823 "3: unknown buffer name for EXPECT EQ_BUFFER command: unknown_buffer",
824 r.Error());
825 }
826
TEST_F(AmberScriptParserTest,ExpectEqBufferDifferentSize)827 TEST_F(AmberScriptParserTest, ExpectEqBufferDifferentSize) {
828 std::string in = R"(
829 BUFFER buf_1 DATA_TYPE int32 SIZE 10 FILL 11
830 BUFFER buf_2 DATA_TYPE int32 SIZE 99 FILL 11
831 EXPECT buf_1 EQ_BUFFER buf_2)";
832
833 Parser parser;
834 Result r = parser.Parse(in);
835 ASSERT_FALSE(r.IsSuccess());
836 EXPECT_EQ(
837 "4: EXPECT EQ_BUFFER command cannot compare buffers of different size: "
838 "10 vs 99",
839 r.Error());
840 }
841
TEST_F(AmberScriptParserTest,ExpectEqBufferDifferentType)842 TEST_F(AmberScriptParserTest, ExpectEqBufferDifferentType) {
843 std::string in = R"(
844 BUFFER buf_1 DATA_TYPE int32 SIZE 10 FILL 11
845 BUFFER buf_2 FORMAT R32G32B32A32_SFLOAT
846 EXPECT buf_1 EQ_BUFFER buf_2)";
847
848 Parser parser;
849 Result r = parser.Parse(in);
850 ASSERT_FALSE(r.IsSuccess());
851 EXPECT_EQ(
852 "4: EXPECT EQ_BUFFER command cannot compare buffers of differing format",
853 r.Error());
854 }
855
TEST_F(AmberScriptParserTest,ExpectToleranceOneValue)856 TEST_F(AmberScriptParserTest, ExpectToleranceOneValue) {
857 std::string in = R"(
858 BUFFER orig_buf DATA_TYPE int32 SIZE 100 FILL 11
859 EXPECT orig_buf IDX 5 TOLERANCE 1 EQ 11)";
860
861 Parser parser;
862 Result r = parser.Parse(in);
863 ASSERT_TRUE(r.IsSuccess()) << r.Error();
864
865 auto script = parser.GetScript();
866 const auto& commands = script->GetCommands();
867 ASSERT_EQ(1U, commands.size());
868
869 auto* cmd = commands[0].get();
870 ASSERT_TRUE(cmd->IsProbeSSBO());
871
872 auto* probe = cmd->AsProbeSSBO();
873 EXPECT_EQ(ProbeSSBOCommand::Comparator::kFuzzyEqual, probe->GetComparator());
874 EXPECT_EQ(5U, probe->GetOffset());
875 EXPECT_TRUE(probe->GetFormat()->IsInt32());
876 ASSERT_EQ(1U, probe->GetValues().size());
877 EXPECT_EQ(11, probe->GetValues()[0].AsInt32());
878 EXPECT_TRUE(probe->HasTolerances());
879
880 auto& tolerances = probe->GetTolerances();
881 ASSERT_EQ(1U, tolerances.size());
882 EXPECT_FALSE(tolerances[0].is_percent);
883 EXPECT_FLOAT_EQ(1.f, static_cast<float>(tolerances[0].value));
884 }
885
TEST_F(AmberScriptParserTest,ExpectToleranceOneValuePercent)886 TEST_F(AmberScriptParserTest, ExpectToleranceOneValuePercent) {
887 std::string in = R"(
888 BUFFER orig_buf DATA_TYPE int32 SIZE 100 FILL 11
889 EXPECT orig_buf IDX 5 TOLERANCE 1% EQ 11)";
890
891 Parser parser;
892 Result r = parser.Parse(in);
893 ASSERT_TRUE(r.IsSuccess()) << r.Error();
894
895 auto script = parser.GetScript();
896 const auto& commands = script->GetCommands();
897 ASSERT_EQ(1U, commands.size());
898
899 auto* cmd = commands[0].get();
900 ASSERT_TRUE(cmd->IsProbeSSBO());
901
902 auto* probe = cmd->AsProbeSSBO();
903 EXPECT_EQ(ProbeSSBOCommand::Comparator::kFuzzyEqual, probe->GetComparator());
904 EXPECT_EQ(5U, probe->GetOffset());
905 EXPECT_TRUE(probe->GetFormat()->IsInt32());
906 ASSERT_EQ(1U, probe->GetValues().size());
907 EXPECT_EQ(11, probe->GetValues()[0].AsInt32());
908 EXPECT_TRUE(probe->HasTolerances());
909
910 auto& tolerances = probe->GetTolerances();
911 ASSERT_EQ(1U, tolerances.size());
912 EXPECT_TRUE(tolerances[0].is_percent);
913 EXPECT_FLOAT_EQ(1.f, static_cast<float>(tolerances[0].value));
914 }
915
TEST_F(AmberScriptParserTest,ExpectToleranceMultiValue)916 TEST_F(AmberScriptParserTest, ExpectToleranceMultiValue) {
917 std::string in = R"(
918 BUFFER orig_buf DATA_TYPE int32 SIZE 100 FILL 11
919 EXPECT orig_buf IDX 5 TOLERANCE 1% .2 3.7% 4 EQ 11)";
920
921 Parser parser;
922 Result r = parser.Parse(in);
923 ASSERT_TRUE(r.IsSuccess()) << r.Error();
924
925 auto script = parser.GetScript();
926 const auto& commands = script->GetCommands();
927 ASSERT_EQ(1U, commands.size());
928
929 auto* cmd = commands[0].get();
930 ASSERT_TRUE(cmd->IsProbeSSBO());
931
932 auto* probe = cmd->AsProbeSSBO();
933 EXPECT_EQ(ProbeSSBOCommand::Comparator::kFuzzyEqual, probe->GetComparator());
934 EXPECT_EQ(5U, probe->GetOffset());
935 EXPECT_TRUE(probe->GetFormat()->IsInt32());
936 ASSERT_EQ(1U, probe->GetValues().size());
937 EXPECT_EQ(11, probe->GetValues()[0].AsInt32());
938
939 EXPECT_TRUE(probe->HasTolerances());
940 auto& tolerances = probe->GetTolerances();
941 ASSERT_EQ(4U, tolerances.size());
942
943 EXPECT_TRUE(tolerances[0].is_percent);
944 EXPECT_FLOAT_EQ(1.f, static_cast<float>(tolerances[0].value));
945
946 EXPECT_FALSE(tolerances[1].is_percent);
947 EXPECT_FLOAT_EQ(.2f, static_cast<float>(tolerances[1].value));
948
949 EXPECT_TRUE(tolerances[2].is_percent);
950 EXPECT_FLOAT_EQ(3.7f, static_cast<float>(tolerances[2].value));
951
952 EXPECT_FALSE(tolerances[3].is_percent);
953 EXPECT_FLOAT_EQ(4.f, static_cast<float>(tolerances[3].value));
954 }
955
TEST_F(AmberScriptParserTest,ExpectToleranceNoValues)956 TEST_F(AmberScriptParserTest, ExpectToleranceNoValues) {
957 std::string in = R"(
958 BUFFER orig_buf DATA_TYPE int32 SIZE 100 FILL 11
959 EXPECT orig_buf IDX 5 TOLERANCE EQ 11)";
960
961 Parser parser;
962 Result r = parser.Parse(in);
963 ASSERT_FALSE(r.IsSuccess());
964 EXPECT_EQ("3: TOLERANCE specified but no tolerances provided", r.Error());
965 }
966
TEST_F(AmberScriptParserTest,ExpectToleranceTooManyValues)967 TEST_F(AmberScriptParserTest, ExpectToleranceTooManyValues) {
968 std::string in = R"(
969 BUFFER orig_buf DATA_TYPE int32 SIZE 100 FILL 11
970 EXPECT orig_buf IDX 5 TOLERANCE 1 2 3 4 5 EQ 11)";
971
972 Parser parser;
973 Result r = parser.Parse(in);
974 ASSERT_FALSE(r.IsSuccess());
975 EXPECT_EQ("3: TOLERANCE has a maximum of 4 values", r.Error());
976 }
977
TEST_F(AmberScriptParserTest,ExpectToleranceNonEqCompator)978 TEST_F(AmberScriptParserTest, ExpectToleranceNonEqCompator) {
979 std::string in = R"(
980 BUFFER orig_buf DATA_TYPE int32 SIZE 100 FILL 11
981 EXPECT orig_buf IDX 5 TOLERANCE 1 2 3 4 NE 11)";
982
983 Parser parser;
984 Result r = parser.Parse(in);
985 ASSERT_FALSE(r.IsSuccess());
986 EXPECT_EQ("3: TOLERANCE only available with EQ probes", r.Error());
987 }
988
TEST_F(AmberScriptParserTest,ExpectEqRgbaToleranceOneValue)989 TEST_F(AmberScriptParserTest, ExpectEqRgbaToleranceOneValue) {
990 std::string in = R"(
991 BUFFER buf FORMAT R8G8B8A8_UNORM
992 EXPECT buf IDX 80 80 SIZE 5 8 EQ_RGBA 128 0 128 255 TOLERANCE 3)";
993
994 Parser parser;
995 Result r = parser.Parse(in);
996 ASSERT_TRUE(r.IsSuccess()) << r.Error();
997
998 auto script = parser.GetScript();
999 const auto& commands = script->GetCommands();
1000 ASSERT_EQ(1U, commands.size());
1001
1002 auto* cmd = commands[0].get();
1003 ASSERT_TRUE(cmd->IsProbe());
1004
1005 auto* probe = cmd->AsProbe();
1006 EXPECT_TRUE(probe->IsRGBA());
1007 EXPECT_TRUE(probe->HasTolerances());
1008
1009 auto& tolerances = probe->GetTolerances();
1010 ASSERT_EQ(1U, tolerances.size());
1011
1012 EXPECT_FALSE(tolerances[0].is_percent);
1013 EXPECT_FLOAT_EQ(3.f, static_cast<float>(tolerances[0].value));
1014 }
1015
TEST_F(AmberScriptParserTest,ExpectEqRgbaToleranceMultiValue)1016 TEST_F(AmberScriptParserTest, ExpectEqRgbaToleranceMultiValue) {
1017 std::string in = R"(
1018 BUFFER buf FORMAT R8G8B8A8_UNORM
1019 EXPECT buf IDX 80 80 SIZE 5 8 EQ_RGBA 128 0 128 255 TOLERANCE 5.2 2% 4 1.5)";
1020
1021 Parser parser;
1022 Result r = parser.Parse(in);
1023 ASSERT_TRUE(r.IsSuccess()) << r.Error();
1024
1025 auto script = parser.GetScript();
1026 const auto& commands = script->GetCommands();
1027 ASSERT_EQ(1U, commands.size());
1028
1029 auto* cmd = commands[0].get();
1030 ASSERT_TRUE(cmd->IsProbe());
1031
1032 auto* probe = cmd->AsProbe();
1033 EXPECT_TRUE(probe->IsRGBA());
1034 EXPECT_TRUE(probe->HasTolerances());
1035
1036 auto& tolerances = probe->GetTolerances();
1037 ASSERT_EQ(4U, tolerances.size());
1038
1039 EXPECT_FALSE(tolerances[0].is_percent);
1040 EXPECT_FLOAT_EQ(5.2f, static_cast<float>(tolerances[0].value));
1041
1042 EXPECT_TRUE(tolerances[1].is_percent);
1043 EXPECT_FLOAT_EQ(2.0f, static_cast<float>(tolerances[1].value));
1044
1045 EXPECT_FALSE(tolerances[2].is_percent);
1046 EXPECT_FLOAT_EQ(4.0f, static_cast<float>(tolerances[2].value));
1047
1048 EXPECT_FALSE(tolerances[3].is_percent);
1049 EXPECT_FLOAT_EQ(1.5f, static_cast<float>(tolerances[3].value));
1050 }
1051
TEST_F(AmberScriptParserTest,ExpectEqRgbaToleranceTooManyValues)1052 TEST_F(AmberScriptParserTest, ExpectEqRgbaToleranceTooManyValues) {
1053 std::string in = R"(
1054 BUFFER buf FORMAT R8G8B8A8_UNORM
1055 EXPECT buf IDX 80 80 SIZE 5 8 EQ_RGBA 128 0 128 255 TOLERANCE 5.2 2% 4 1.5 6)";
1056
1057 Parser parser;
1058 Result r = parser.Parse(in);
1059 ASSERT_FALSE(r.IsSuccess());
1060 EXPECT_EQ("3: TOLERANCE for an RGBA comparison has a maximum of 4 values",
1061 r.Error());
1062 }
1063
TEST_F(AmberScriptParserTest,ExpectEqRgbaToleranceExtraParameters)1064 TEST_F(AmberScriptParserTest, ExpectEqRgbaToleranceExtraParameters) {
1065 std::string in = R"(
1066 BUFFER buf FORMAT R8G8B8A8_UNORM
1067 EXPECT buf IDX 80 80 SIZE 5 8 EQ_RGBA 128 0 128 255 TOLERANCE 3 FOO)";
1068
1069 Parser parser;
1070 Result r = parser.Parse(in);
1071 ASSERT_FALSE(r.IsSuccess());
1072 EXPECT_EQ("3: extra parameters after EXPECT command: FOO", r.Error());
1073 }
1074
TEST_F(AmberScriptParserTest,ExpectEqRgbToleranceOneValue)1075 TEST_F(AmberScriptParserTest, ExpectEqRgbToleranceOneValue) {
1076 std::string in = R"(
1077 BUFFER buf FORMAT R8G8B8_UNORM
1078 EXPECT buf IDX 80 80 SIZE 5 8 EQ_RGB 128 0 128 TOLERANCE 3)";
1079
1080 Parser parser;
1081 Result r = parser.Parse(in);
1082 ASSERT_TRUE(r.IsSuccess()) << r.Error();
1083
1084 auto script = parser.GetScript();
1085 const auto& commands = script->GetCommands();
1086 ASSERT_EQ(1U, commands.size());
1087
1088 auto* cmd = commands[0].get();
1089 ASSERT_TRUE(cmd->IsProbe());
1090
1091 auto* probe = cmd->AsProbe();
1092 EXPECT_FALSE(probe->IsRGBA());
1093 EXPECT_TRUE(probe->HasTolerances());
1094
1095 auto& tolerances = probe->GetTolerances();
1096 ASSERT_EQ(1U, tolerances.size());
1097
1098 EXPECT_FALSE(tolerances[0].is_percent);
1099 EXPECT_FLOAT_EQ(3.f, static_cast<float>(tolerances[0].value));
1100 }
1101
TEST_F(AmberScriptParserTest,ExpectEqRgbToleranceMultiValue)1102 TEST_F(AmberScriptParserTest, ExpectEqRgbToleranceMultiValue) {
1103 std::string in = R"(
1104 BUFFER buf FORMAT R8G8B8_UNORM
1105 EXPECT buf IDX 80 80 SIZE 5 8 EQ_RGB 128 0 128 TOLERANCE 5.2 2% 4)";
1106
1107 Parser parser;
1108 Result r = parser.Parse(in);
1109 ASSERT_TRUE(r.IsSuccess()) << r.Error();
1110
1111 auto script = parser.GetScript();
1112 const auto& commands = script->GetCommands();
1113 ASSERT_EQ(1U, commands.size());
1114
1115 auto* cmd = commands[0].get();
1116 ASSERT_TRUE(cmd->IsProbe());
1117
1118 auto* probe = cmd->AsProbe();
1119 EXPECT_FALSE(probe->IsRGBA());
1120 EXPECT_TRUE(probe->HasTolerances());
1121
1122 auto& tolerances = probe->GetTolerances();
1123 ASSERT_EQ(3U, tolerances.size());
1124
1125 EXPECT_FALSE(tolerances[0].is_percent);
1126 EXPECT_FLOAT_EQ(5.2f, static_cast<float>(tolerances[0].value));
1127
1128 EXPECT_TRUE(tolerances[1].is_percent);
1129 EXPECT_FLOAT_EQ(2.0f, static_cast<float>(tolerances[1].value));
1130
1131 EXPECT_FALSE(tolerances[2].is_percent);
1132 EXPECT_FLOAT_EQ(4.0f, static_cast<float>(tolerances[2].value));
1133 }
1134
TEST_F(AmberScriptParserTest,ExpectEqRgbToleranceTooManyValues)1135 TEST_F(AmberScriptParserTest, ExpectEqRgbToleranceTooManyValues) {
1136 std::string in = R"(
1137 BUFFER buf FORMAT R8G8B8_UNORM
1138 EXPECT buf IDX 80 80 SIZE 5 8 EQ_RGB 128 0 128 TOLERANCE 5.2 2% 4 1.5)";
1139
1140 Parser parser;
1141 Result r = parser.Parse(in);
1142 ASSERT_FALSE(r.IsSuccess());
1143 EXPECT_EQ("3: TOLERANCE for an RGB comparison has a maximum of 3 values",
1144 r.Error());
1145 }
1146
TEST_F(AmberScriptParserTest,ExpectEqRgbToleranceExtraParameters)1147 TEST_F(AmberScriptParserTest, ExpectEqRgbToleranceExtraParameters) {
1148 std::string in = R"(
1149 BUFFER buf FORMAT R8G8B8_UNORM
1150 EXPECT buf IDX 80 80 SIZE 5 8 EQ_RGB 128 0 128 TOLERANCE 3 FOO)";
1151
1152 Parser parser;
1153 Result r = parser.Parse(in);
1154 ASSERT_FALSE(r.IsSuccess());
1155 EXPECT_EQ("3: extra parameters after EXPECT command: FOO", r.Error());
1156 }
1157
TEST_F(AmberScriptParserTest,ExpectRMSEBuffer)1158 TEST_F(AmberScriptParserTest, ExpectRMSEBuffer) {
1159 std::string in = R"(
1160 BUFFER buf_1 DATA_TYPE int32 SIZE 10 FILL 11
1161 BUFFER buf_2 DATA_TYPE int32 SIZE 10 FILL 12
1162 EXPECT buf_1 RMSE_BUFFER buf_2 TOLERANCE 0.1)";
1163
1164 Parser parser;
1165 Result r = parser.Parse(in);
1166 ASSERT_TRUE(r.IsSuccess()) << r.Error();
1167
1168 auto script = parser.GetScript();
1169 const auto& commands = script->GetCommands();
1170 ASSERT_EQ(1U, commands.size());
1171
1172 auto* cmd = commands[0].get();
1173 ASSERT_TRUE(cmd->IsCompareBuffer());
1174
1175 auto* cmp = cmd->AsCompareBuffer();
1176 EXPECT_EQ(cmp->GetComparator(), CompareBufferCommand::Comparator::kRmse);
1177 EXPECT_FLOAT_EQ(cmp->GetTolerance(), 0.1f);
1178
1179 ASSERT_TRUE(cmp->GetBuffer1() != nullptr);
1180 EXPECT_EQ(cmp->GetBuffer1()->GetName(), "buf_1");
1181
1182 ASSERT_TRUE(cmp->GetBuffer2() != nullptr);
1183 EXPECT_EQ(cmp->GetBuffer2()->GetName(), "buf_2");
1184 }
1185
TEST_F(AmberScriptParserTest,ExpectRMSEBufferMissingFirstBuffer)1186 TEST_F(AmberScriptParserTest, ExpectRMSEBufferMissingFirstBuffer) {
1187 std::string in = R"(
1188 BUFFER buf_2 DATA_TYPE int32 SIZE 10 FILL 22
1189 EXPECT RMSE_BUFFER buf_2)";
1190
1191 Parser parser;
1192 Result r = parser.Parse(in);
1193 ASSERT_FALSE(r.IsSuccess());
1194 EXPECT_EQ("3: missing buffer name between EXPECT and RMSE_BUFFER", r.Error());
1195 }
1196
TEST_F(AmberScriptParserTest,ExpectRMSEBufferMissingSecondBuffer)1197 TEST_F(AmberScriptParserTest, ExpectRMSEBufferMissingSecondBuffer) {
1198 std::string in = R"(
1199 BUFFER buf_1 DATA_TYPE int32 SIZE 10 FILL 11
1200 EXPECT buf_1 RMSE_BUFFER)";
1201
1202 Parser parser;
1203 Result r = parser.Parse(in);
1204 ASSERT_FALSE(r.IsSuccess());
1205 EXPECT_EQ("3: invalid buffer name in EXPECT RMSE_BUFFER command", r.Error());
1206 }
1207
TEST_F(AmberScriptParserTest,ExpectRMSEBufferInvalidFirstBuffer)1208 TEST_F(AmberScriptParserTest, ExpectRMSEBufferInvalidFirstBuffer) {
1209 std::string in = R"(EXPECT 123 RMSE_BUFFER)";
1210
1211 Parser parser;
1212 Result r = parser.Parse(in);
1213 ASSERT_FALSE(r.IsSuccess());
1214 EXPECT_EQ("1: invalid buffer name in EXPECT command", r.Error());
1215 }
1216
TEST_F(AmberScriptParserTest,ExpectRMSEBufferUnknownFirstBuffer)1217 TEST_F(AmberScriptParserTest, ExpectRMSEBufferUnknownFirstBuffer) {
1218 std::string in = R"(EXPECT unknown_buffer RMSE_BUFFER)";
1219
1220 Parser parser;
1221 Result r = parser.Parse(in);
1222 ASSERT_FALSE(r.IsSuccess());
1223 EXPECT_EQ("1: unknown buffer name for EXPECT command: unknown_buffer",
1224 r.Error());
1225 }
1226
TEST_F(AmberScriptParserTest,ExpectRMSEBufferInvalidSecondBuffer)1227 TEST_F(AmberScriptParserTest, ExpectRMSEBufferInvalidSecondBuffer) {
1228 std::string in = R"(
1229 BUFFER buf DATA_TYPE int32 SIZE 10 FILL 11
1230 EXPECT buf RMSE_BUFFER 123)";
1231
1232 Parser parser;
1233 Result r = parser.Parse(in);
1234 ASSERT_FALSE(r.IsSuccess());
1235 EXPECT_EQ("3: invalid buffer name in EXPECT RMSE_BUFFER command", r.Error());
1236 }
1237
TEST_F(AmberScriptParserTest,ExpectRMSEBufferUnknownSecondBuffer)1238 TEST_F(AmberScriptParserTest, ExpectRMSEBufferUnknownSecondBuffer) {
1239 std::string in = R"(
1240 BUFFER buf DATA_TYPE int32 SIZE 10 FILL 11
1241 EXPECT buf RMSE_BUFFER unknown_buffer)";
1242
1243 Parser parser;
1244 Result r = parser.Parse(in);
1245 ASSERT_FALSE(r.IsSuccess());
1246 EXPECT_EQ(
1247 "3: unknown buffer name for EXPECT RMSE_BUFFER command: unknown_buffer",
1248 r.Error());
1249 }
1250
TEST_F(AmberScriptParserTest,ExpectRMSEBufferDifferentSize)1251 TEST_F(AmberScriptParserTest, ExpectRMSEBufferDifferentSize) {
1252 std::string in = R"(
1253 BUFFER buf_1 DATA_TYPE int32 SIZE 10 FILL 11
1254 BUFFER buf_2 DATA_TYPE int32 SIZE 99 FILL 11
1255 EXPECT buf_1 RMSE_BUFFER buf_2)";
1256
1257 Parser parser;
1258 Result r = parser.Parse(in);
1259 ASSERT_FALSE(r.IsSuccess());
1260 EXPECT_EQ(
1261 "4: EXPECT RMSE_BUFFER command cannot compare buffers of different size: "
1262 "10 vs 99",
1263 r.Error());
1264 }
1265
TEST_F(AmberScriptParserTest,ExpectRMSEBufferDifferentType)1266 TEST_F(AmberScriptParserTest, ExpectRMSEBufferDifferentType) {
1267 std::string in = R"(
1268 BUFFER buf_1 DATA_TYPE int32 SIZE 10 FILL 11
1269 BUFFER buf_2 FORMAT R32G32B32A32_SFLOAT
1270 EXPECT buf_1 RMSE_BUFFER buf_2)";
1271
1272 Parser parser;
1273 Result r = parser.Parse(in);
1274 ASSERT_FALSE(r.IsSuccess());
1275 EXPECT_EQ(
1276 "4: EXPECT RMSE_BUFFER command cannot compare buffers of differing "
1277 "format",
1278 r.Error());
1279 }
1280
TEST_F(AmberScriptParserTest,ExpectAllowIntegerHexValue)1281 TEST_F(AmberScriptParserTest, ExpectAllowIntegerHexValue) {
1282 std::string in = R"(
1283 BUFFER b1 DATA_TYPE uint32 SIZE 4 FILL 0
1284 EXPECT b1 IDX 0 EQ 0x0 0x1 0x2 0x3
1285 )";
1286
1287 Parser parser;
1288 Result r = parser.Parse(in);
1289 ASSERT_TRUE(r.IsSuccess());
1290
1291 auto script = parser.GetScript();
1292 const auto& commands = script->GetCommands();
1293 ASSERT_EQ(1U, commands.size());
1294
1295 auto* cmd = commands[0].get();
1296 ASSERT_TRUE(cmd->IsProbeSSBO());
1297
1298 auto* probe = cmd->AsProbeSSBO();
1299 EXPECT_EQ(probe->GetComparator(), ProbeSSBOCommand::Comparator::kEqual);
1300
1301 EXPECT_EQ(4, probe->GetValues().size());
1302 EXPECT_EQ(0, probe->GetValues()[0].AsUint64());
1303 EXPECT_EQ(1, probe->GetValues()[1].AsUint64());
1304 EXPECT_EQ(2, probe->GetValues()[2].AsUint64());
1305 EXPECT_EQ(3, probe->GetValues()[3].AsUint64());
1306 }
1307
TEST_F(AmberScriptParserTest,ExpectAllowFloatHexValue)1308 TEST_F(AmberScriptParserTest, ExpectAllowFloatHexValue) {
1309 std::string in = R"(
1310 BUFFER b1 DATA_TYPE float SIZE 4 FILL 0
1311 EXPECT b1 IDX 0 EQ 0x0 0x1 0x2 0x3
1312 )";
1313
1314 Parser parser;
1315 Result r = parser.Parse(in);
1316 ASSERT_TRUE(r.IsSuccess());
1317
1318 auto script = parser.GetScript();
1319 const auto& commands = script->GetCommands();
1320 ASSERT_EQ(1U, commands.size());
1321
1322 auto* cmd = commands[0].get();
1323 ASSERT_TRUE(cmd->IsProbeSSBO());
1324
1325 auto* probe = cmd->AsProbeSSBO();
1326 EXPECT_EQ(probe->GetComparator(), ProbeSSBOCommand::Comparator::kEqual);
1327
1328 EXPECT_EQ(4, probe->GetValues().size());
1329 EXPECT_EQ(static_cast<double>(0), probe->GetValues()[0].AsDouble());
1330 EXPECT_EQ(static_cast<double>(1), probe->GetValues()[1].AsDouble());
1331 EXPECT_EQ(static_cast<double>(2), probe->GetValues()[2].AsDouble());
1332 EXPECT_EQ(static_cast<double>(3), probe->GetValues()[3].AsDouble());
1333 }
1334
1335 } // namespace amberscript
1336 } // namespace amber
1337