Flutter Engine
The Flutter Engine
Typedefs | Functions
SkSLDebugTracePlayerTest.cpp File Reference
#include "include/core/SkRefCnt.h"
#include "src/base/SkArenaAlloc.h"
#include "src/core/SkRasterPipeline.h"
#include "src/sksl/SkSLCompiler.h"
#include "src/sksl/SkSLProgramKind.h"
#include "src/sksl/SkSLProgramSettings.h"
#include "src/sksl/SkSLString.h"
#include "src/sksl/SkSLUtil.h"
#include "src/sksl/codegen/SkSLRasterPipelineBuilder.h"
#include "src/sksl/codegen/SkSLRasterPipelineCodeGenerator.h"
#include "src/sksl/ir/SkSLFunctionDeclaration.h"
#include "src/sksl/ir/SkSLProgram.h"
#include "src/sksl/tracing/SkSLDebugTracePlayer.h"
#include "src/sksl/tracing/SkSLDebugTracePriv.h"
#include "tests/Test.h"
#include <cstddef>
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

Go to the source code of this file.

Typedefs

using LineNumberMap = SkSL::SkSLDebugTracePlayer::LineNumberMap
 

Functions

static sk_sp< SkSL::DebugTracePrivmake_trace (skiatest::Reporter *r, std::string src)
 
static std::string make_stack_string (const SkSL::DebugTracePriv &trace, const SkSL::SkSLDebugTracePlayer &player)
 
static std::string make_vars_string (const SkSL::DebugTracePriv &trace, const std::vector< SkSL::SkSLDebugTracePlayer::VariableData > &vars)
 
static std::string make_local_vars_string (const SkSL::DebugTracePriv &trace, const SkSL::SkSLDebugTracePlayer &player)
 
static std::string make_global_vars_string (const SkSL::DebugTracePriv &trace, const SkSL::SkSLDebugTracePlayer &player)
 
 DEF_TEST (SkSLTracePlayerCanResetToNull, r)
 
 DEF_TEST (SkSLTracePlayerHelloWorld, r)
 
 DEF_TEST (SkSLTracePlayerReset, r)
 
 DEF_TEST (SkSLTracePlayerFunctions, r)
 
 DEF_TEST (SkSLTracePlayerVariables, r)
 
 DEF_TEST (SkSLTracePlayerVariableGroups, r)
 
 DEF_TEST (SkSLTracePlayerIfStatement, r)
 
 DEF_TEST (SkSLTracePlayerForLoop, r)
 
 DEF_TEST (SkSLTracePlayerStepOut, r)
 
 DEF_TEST (SkSLTracePlayerVariableScope, r)
 
 DEF_TEST (SkSLTracePlayerNestedBlocks, r)
 
 DEF_TEST (SkSLTracePlayerSwitchStatement, r)
 
 DEF_TEST (SkSLTracePlayerBreakpoint, r)
 
 DEF_TEST (SkSLTracePlayerStepOverWithBreakpoint, r)
 
 DEF_TEST (SkSLTracePlayerStepOutWithBreakpoint, r)
 

Typedef Documentation

◆ LineNumberMap

Definition at line 32 of file SkSLDebugTracePlayerTest.cpp.

Function Documentation

◆ DEF_TEST() [1/15]

DEF_TEST ( SkSLTracePlayerBreakpoint  ,
 
)

Definition at line 708 of file SkSLDebugTracePlayerTest.cpp.

708 {19, 1},
709 {20, 1}}));
710 player.step();
711
712 // We should now be inside main.
713 REPORTER_ASSERT(r, player.getCurrentLine() == 3);
714 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "##xy.x = 0.5, ##xy.y = 0.5");
715 player.step();
716
717 REPORTER_ASSERT(r, player.getCurrentLine() == 5);
718 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "##a = 1, xy.x = 0.5, xy.y = 0.5");
719 player.step();
720
721 REPORTER_ASSERT(r, player.getCurrentLine() == 7);
723 r, make_local_vars_string(*trace, player) == "##b = 2, a = 1, xy.x = 0.5, xy.y = 0.5");
724 player.step();
725
726 REPORTER_ASSERT(r, player.getCurrentLine() == 9);
728 r, make_local_vars_string(*trace, player) == "b = 2, a = 1, xy.x = 0.5, xy.y = 0.5");
729 player.step();
730
731 REPORTER_ASSERT(r, player.getCurrentLine() == 11);
732 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "a = 1, xy.x = 0.5, xy.y = 0.5");
733 player.step();
734
735 REPORTER_ASSERT(r, player.getCurrentLine() == 13);
737 r, make_local_vars_string(*trace, player) == "##e = 5, a = 1, xy.x = 0.5, xy.y = 0.5");
738 player.step();
739
740 REPORTER_ASSERT(r, player.getCurrentLine() == 15);
742 make_local_vars_string(*trace, player) ==
743 "##f = 6, e = 5, a = 1, xy.x = 0.5, xy.y = 0.5");
744 player.step();
745
746 REPORTER_ASSERT(r, player.getCurrentLine() == 17);
static std::string make_local_vars_string(const SkSL::DebugTracePriv &trace, const SkSL::SkSLDebugTracePlayer &player)
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286

◆ DEF_TEST() [2/15]

DEF_TEST ( SkSLTracePlayerCanResetToNull  ,
 
)

Definition at line 128 of file SkSLDebugTracePlayerTest.cpp.

128 {
130 player.reset(nullptr);
131
132 // We should be in a reasonable state.
133 REPORTER_ASSERT(r, player.cursor() == 0);
134 REPORTER_ASSERT(r, player.getCurrentLine() == -1);
136 REPORTER_ASSERT(r, player.getCallStack().empty());
137 REPORTER_ASSERT(r, player.getGlobalVariables().empty());
138 REPORTER_ASSERT(r, player.getLineNumbersReached().empty());
139}
const LineNumberMap & getLineNumbersReached() const
void reset(sk_sp< DebugTracePriv > trace)
std::vector< VariableData > getGlobalVariables() const
std::vector< int > getCallStack() const

◆ DEF_TEST() [3/15]

DEF_TEST ( SkSLTracePlayerForLoop  ,
 
)

Definition at line 481 of file SkSLDebugTracePlayerTest.cpp.

483 { // Line 13
484 val = 4; // Line 14
485 } // Line 15
486 return half4(val); // Line 16
487} // Line 17
488)");
489 SkSL::SkSLDebugTracePlayer player;
490 player.reset(trace);
491
492 REPORTER_ASSERT(
493 r,
494 player.getLineNumbersReached() ==
495 LineNumberMap({{3, 1}, {4, 1}, {5, 1}, {6, 1}, {10, 1}, {14, 1}, {16, 1}}));
496 player.step();
497
498 REPORTER_ASSERT(r, player.getCurrentLine() == 3);
499 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "##xy.x = 0.5, ##xy.y = 0.5");
500 player.step();
501
502 REPORTER_ASSERT(r, player.getCurrentLine() == 4);
503 REPORTER_ASSERT(r,
504 make_local_vars_string(*trace, player) == "##val = 0, xy.x = 0.5, xy.y = 0.5");
505 player.step();
506
507 REPORTER_ASSERT(r, player.getCurrentLine() == 5);
508 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "val = 0, xy.x = 0.5, xy.y = 0.5");
509 player.step();
510
511 REPORTER_ASSERT(r, player.getCurrentLine() == 6);
512 REPORTER_ASSERT(r,
513 make_local_vars_string(*trace, player) ==
514 "##temp = 1, val = 0, xy.x = 0.5, xy.y = 0.5");
515 player.step();
516
517 // We skip over the false-branch.
518 REPORTER_ASSERT(r, player.getCurrentLine() == 10);
519 REPORTER_ASSERT(r,
520 make_local_vars_string(*trace, player) == "##val = 1, xy.x = 0.5, xy.y = 0.5");
521 player.step();
522
523 // We skip over the true-branch.
524 REPORTER_ASSERT(r, player.getCurrentLine() == 14);
525 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "val = 1, xy.x = 0.5, xy.y = 0.5");
526 player.step();
527
528 REPORTER_ASSERT(r, player.getCurrentLine() == 16);
529 REPORTER_ASSERT(r,
530 make_local_vars_string(*trace, player) == "##val = 4, xy.x = 0.5, xy.y = 0.5");
531 player.step();
532
533 REPORTER_ASSERT(r, player.traceHasCompleted());
534 REPORTER_ASSERT(r,
535 make_global_vars_string(*trace, player) ==
536 "##[main].result.x = 4, ##[main].result.y = 4, ##[main].result.z = "
537 "4, ##[main].result.w = 4");
538}
539
540DEF_TEST(SkSLTracePlayerForLoop, r) {
541 sk_sp<SkSL::DebugTracePriv> trace = make_trace(r,
542R"( // Line 1
543half4 main(float2 xy) { // Line 2
544 int val = 0; // Line 3
545 for (int x = 1; x < 3; ++x) { // Line 4
546 val = x; // Line 5
547 } // Line 6
double x
Definition: main.py:1
Vec< 4, uint16_t > half4
Definition: SkVx.h:1176
Definition: SkVx.h:83

◆ DEF_TEST() [4/15]

DEF_TEST ( SkSLTracePlayerFunctions  ,
 
)

Definition at line 210 of file SkSLDebugTracePlayerTest.cpp.

218 {
220R"( // Line 1
221int fnB() { // Line 2
222 return 2 + 2; // Line 3
223} // Line 4
224int fnA() { // Line 5
225 return fnB(); // Line 6
226} // Line 7
227half4 main(float2 xy) { // Line 8
228 return half4(fnA()); // Line 9
229} // Line 10
230)");
232 player.reset(trace);
233
234 // We have not started tracing yet.
235 REPORTER_ASSERT(r, player.cursor() == 0);
236 REPORTER_ASSERT(r, player.getCurrentLine() == -1);
238 REPORTER_ASSERT(r, player.getCallStack().empty());
239 REPORTER_ASSERT(r, player.getGlobalVariables().empty());
240 REPORTER_ASSERT(r, player.getLineNumbersReached() == LineNumberMap({{3, 1}, {6, 1}, {9, 1}}));
241
242 player.step();
243
244 // We should now be inside main.
246 REPORTER_ASSERT(r, player.getCurrentLine() == 9);
247 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy)");
248 REPORTER_ASSERT(r, player.getGlobalVariables().empty());
249 REPORTER_ASSERT(r, player.getLocalVariables(0).size() == 2); // xy
250
251 player.stepOver();
252
253 // We should now have completed execution.
255 REPORTER_ASSERT(r, player.getCurrentLine() == -1);
256 REPORTER_ASSERT(r, player.getCallStack().empty());
258 make_global_vars_string(*trace, player) ==
259 "##[main].result.x = 4, ##[main].result.y = 4, ##[main].result.z = "
260 "4, ##[main].result.w = 4");
261
262 // Watch the stack grow and shrink as single-step.
263 player.reset(trace);
264 player.step();
265
266 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy)");
268 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "##xy.x = 0.5, ##xy.y = 0.5");
269 REPORTER_ASSERT(r, make_global_vars_string(*trace, player) == "");
270 player.step();
271
272 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy) -> int fnA()");
275 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "");
276 REPORTER_ASSERT(r, make_global_vars_string(*trace, player) == "");
277 player.step();
278
280 r,
281 make_stack_string(*trace, player) == "half4 main(float2 xy) -> int fnA() -> int fnB()");
282 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "");
283 REPORTER_ASSERT(r, make_global_vars_string(*trace, player) == "");
287 player.step();
288
static std::string make_stack_string(const SkSL::DebugTracePriv &trace, const SkSL::SkSLDebugTracePlayer &player)
SkSL::SkSLDebugTracePlayer::LineNumberMap LineNumberMap
static std::string make_global_vars_string(const SkSL::DebugTracePriv &trace, const SkSL::SkSLDebugTracePlayer &player)
static sk_sp< SkSL::DebugTracePriv > make_trace(skiatest::Reporter *r, std::string src)
std::vector< VariableData > getLocalVariables(int stackFrameIndex) const
int32_t getCurrentLineInStackFrame(int stackFrameIndex) const

◆ DEF_TEST() [5/15]

DEF_TEST ( SkSLTracePlayerHelloWorld  ,
 
)

Definition at line 141 of file SkSLDebugTracePlayerTest.cpp.

141 {
143R"( // Line 1
144half4 main(float2 xy) { // Line 2
145 return half4(2 + 2); // Line 3
146} // Line 4
147)");
149 player.reset(trace);
150
151 // We have not started tracing yet.
152 REPORTER_ASSERT(r, player.cursor() == 0);
153 REPORTER_ASSERT(r, player.getCurrentLine() == -1);
155 REPORTER_ASSERT(r, player.getCallStack().empty());
156 REPORTER_ASSERT(r, player.getGlobalVariables().empty());
157 REPORTER_ASSERT(r, player.getLineNumbersReached() == LineNumberMap({{3, 1}}));
158
159 player.step();
160
161 // We should now be inside main.
162 REPORTER_ASSERT(r, player.cursor() > 0);
164 REPORTER_ASSERT(r, player.getCurrentLine() == 3);
165 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy)");
166 REPORTER_ASSERT(r, player.getGlobalVariables().empty());
167 REPORTER_ASSERT(r, player.getLocalVariables(0).size() == 2); // xy
168
169 player.step();
170
171 // We have now completed the trace.
172 REPORTER_ASSERT(r, player.cursor() > 0);
174 REPORTER_ASSERT(r, player.getCurrentLine() == -1);
175 REPORTER_ASSERT(r, player.getCallStack().empty());

◆ DEF_TEST() [6/15]

DEF_TEST ( SkSLTracePlayerIfStatement  ,
 
)

Definition at line 427 of file SkSLDebugTracePlayerTest.cpp.

469 {
471R"( // Line 1
472half4 main(float2 xy) { // Line 2
473 int val; // Line 3
474 if (true) { // Line 4
475 int temp = 1; // Line 5
476 val = temp; // Line 6
477 } else { // Line 7
478 val = 2; // Line 8
479 } // Line 9

◆ DEF_TEST() [7/15]

DEF_TEST ( SkSLTracePlayerNestedBlocks  ,
 
)

Definition at line 667 of file SkSLDebugTracePlayerTest.cpp.

673 {
675R"( // Line 1
676half4 main(float2 xy) { // Line 2
677 int a = 1; // Line 3
678 { // Line 4
679 int b = 2; // Line 5
680 { // Line 6
681 int c = 3; // Line 7

◆ DEF_TEST() [8/15]

DEF_TEST ( SkSLTracePlayerReset  ,
 
)

Definition at line 178 of file SkSLDebugTracePlayerTest.cpp.

182 {
184R"( // Line 1
185half4 main(float2 xy) { // Line 2
186 return half4(2 + 2); // Line 3
187} // Line 4
188)");
190 player.reset(trace);
191
192 // We have not started tracing yet.
193 REPORTER_ASSERT(r, player.cursor() == 0);
194 REPORTER_ASSERT(r, player.getCurrentLine() == -1);
196 REPORTER_ASSERT(r, player.getCallStack().empty());
197 REPORTER_ASSERT(r, player.getGlobalVariables().empty());
198
199 player.step();
200
201 // We should now be inside main.
202 REPORTER_ASSERT(r, player.cursor() > 0);
203 REPORTER_ASSERT(r, player.getCurrentLine() == 3);
204 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy)");
205 REPORTER_ASSERT(r, player.getGlobalVariables().empty());
206 REPORTER_ASSERT(r, player.getLocalVariables(0).size() == 2); // xy
207
208 player.reset(trace);

◆ DEF_TEST() [9/15]

DEF_TEST ( SkSLTracePlayerStepOut  ,
 
)

Definition at line 549 of file SkSLDebugTracePlayerTest.cpp.

555 {{3, 1}, {4, 3}, {5, 2}, {7, 1}}));
556 player.step();
557
558 REPORTER_ASSERT(r, player.getCurrentLine() == 3);
560 r, player.getLineNumbersReached() == LineNumberMap({{3, 0}, {4, 3}, {5, 2}, {7, 1}}));
561 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "##xy.x = 0.5, ##xy.y = 0.5");
562 player.step();
563
564 REPORTER_ASSERT(r, player.getCurrentLine() == 4);
566 r, player.getLineNumbersReached() == LineNumberMap({{3, 0}, {4, 2}, {5, 2}, {7, 1}}));
568 make_local_vars_string(*trace, player) == "##val = 0, xy.x = 0.5, xy.y = 0.5");
569 player.step();
570
571 REPORTER_ASSERT(r, player.getCurrentLine() == 5);
573 r, player.getLineNumbersReached() == LineNumberMap({{3, 0}, {4, 2}, {5, 1}, {7, 1}}));
575 r,
576 make_local_vars_string(*trace, player) == "##x = 1, val = 0, xy.x = 0.5, xy.y = 0.5");
577 player.step();
578
579 REPORTER_ASSERT(r, player.getCurrentLine() == 4);
581 r, player.getLineNumbersReached() == LineNumberMap({{3, 0}, {4, 1}, {5, 1}, {7, 1}}));
583 r,
584 make_local_vars_string(*trace, player) == "##val = 1, x = 1, xy.x = 0.5, xy.y = 0.5");
585 player.step();
586
587 REPORTER_ASSERT(r, player.getCurrentLine() == 5);
589 r, player.getLineNumbersReached() == LineNumberMap({{3, 0}, {4, 1}, {5, 0}, {7, 1}}));
591 r,
592 make_local_vars_string(*trace, player) == "##x = 2, val = 1, xy.x = 0.5, xy.y = 0.5");
593 player.step();

◆ DEF_TEST() [10/15]

DEF_TEST ( SkSLTracePlayerStepOutWithBreakpoint  ,
 
)

Definition at line 770 of file SkSLDebugTracePlayerTest.cpp.

770 {{{{{{{ // Line 3
771 int a, b; // Line 4
772 }}}}}}} // Line 5
773 return half4(0); // Line 6
774}
775)");
776 SkSL::SkSLDebugTracePlayer player;
777 player.reset(trace);
778 player.step();
779
780 REPORTER_ASSERT(r, player.getCurrentLine() == 4);
781 player.step();
782
783 REPORTER_ASSERT(r, player.getCurrentLine() == 6);
784 player.step();
785
786 REPORTER_ASSERT(r, player.traceHasCompleted());
787}
788
789DEF_TEST(SkSLTracePlayerSwitchStatement, r) {
790 sk_sp<SkSL::DebugTracePriv> trace = make_trace(r,
791R"( // Line 1
792half4 main(float2 xy) { // Line 2
793 int x = 2; // Line 3
794 switch (x) { // Line 4
795 case 1: // Line 5
796 break; // Line 6
int main(int argc, char **argv)
Definition: benchmarking.cc:29
static bool b
struct MyStruct a[10]

◆ DEF_TEST() [11/15]

DEF_TEST ( SkSLTracePlayerStepOverWithBreakpoint  ,
 
)

Definition at line 748 of file SkSLDebugTracePlayerTest.cpp.

766 {
768R"( // Line 1

◆ DEF_TEST() [12/15]

DEF_TEST ( SkSLTracePlayerSwitchStatement  ,
 
)

Definition at line 683 of file SkSLDebugTracePlayerTest.cpp.

686 { // Line 12
687 int f = 6; // Line 13
688 { // Line 14
689 int g = 7; // Line 15
690 } // Line 16
691 int h = 8; // Line 17
692 } // Line 18
693 int i = 9; // Line 19
694 return half4(0); // Line 20
695}
696)");
697 SkSL::SkSLDebugTracePlayer player;
698 player.reset(trace);
699 REPORTER_ASSERT(r,
700 player.getLineNumbersReached() == LineNumberMap({{3, 1},
701 {5, 1},
702 {7, 1},
703 {9, 1},
704 {11, 1},
705 {13, 1},
706 {15, 1},
SkScalar h

◆ DEF_TEST() [13/15]

DEF_TEST ( SkSLTracePlayerVariableGroups  ,
 
)

Definition at line 374 of file SkSLDebugTracePlayerTest.cpp.

405 {
407R"( // Line 1
408struct S { int x, y, z; }; // Line 2
409half4 main(float2 xy) { // Line 3
410 S s; // Line 4
411 int arr[3]; // Line 5
412 s.y = 1; // Line 6
413 arr[1] = 2; // Line 7
414 s.x = 3; // Line 8
415 arr[2] = 4; // Line 9
416 return half4(0); // Line 10
417} // Line 11
418)");
420 player.reset(trace);
421 player.step();
422
423 REPORTER_ASSERT(r, player.getCurrentLine() == 4);
424 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy)");
425 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "##xy.x = 0.5, ##xy.y = 0.5");

◆ DEF_TEST() [14/15]

DEF_TEST ( SkSLTracePlayerVariables  ,
 
)

Definition at line 290 of file SkSLDebugTracePlayerTest.cpp.

308 {
310R"( // Line 1
311float func() { // Line 2
312 float x = 4, y = 5, z = 6; // Line 3
313 return z; // Line 4
314} // Line 5
315half4 main(float2 xy) { // Line 6
316 int a = 123; // Line 7
317 bool b = true; // Line 8
318 func(); // Line 9
319 float4 c = float4(0, 0.5, 1, -1); // Line 10
320 float3x3 d = float3x3(2); // Line 11
321 return half4(a); // Line 12
322} // Line 13
323)");
325 player.reset(trace);
326
328 r,
329 player.getLineNumbersReached() ==
331 {{3, 1}, {4, 1}, {7, 1}, {8, 1}, {9, 1}, {10, 1}, {11, 1}, {12, 1}}));
332 player.step();
333
334 REPORTER_ASSERT(r, player.getCurrentLine() == 7);
335 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy)");
336 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "##xy.x = 0.5, ##xy.y = 0.5");
337 player.step();
338
339 REPORTER_ASSERT(r, player.getCurrentLine() == 8);
340 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy)");
342 make_local_vars_string(*trace, player) == "##a = 123, xy.x = 0.5, xy.y = 0.5");
343 player.step();
344
345 REPORTER_ASSERT(r, player.getCurrentLine() == 9);
346 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy)");
348 make_local_vars_string(*trace, player) ==
349 "##b = true, a = 123, xy.x = 0.5, xy.y = 0.5");
350 player.step();
351
352 REPORTER_ASSERT(r, player.getCurrentLine() == 3);
354 make_stack_string(*trace, player) == "half4 main(float2 xy) -> float func()");
355 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "");
356 player.step();
357
358 REPORTER_ASSERT(r, player.getCurrentLine() == 4);
360 make_stack_string(*trace, player) == "half4 main(float2 xy) -> float func()");
361 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "##z = 6, ##y = 5, ##x = 4");
362 player.step();
363
364 REPORTER_ASSERT(r, player.getCurrentLine() == 9);
365 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy)");
367 make_local_vars_string(*trace, player) ==
368 "##[func].result = 6, b = true, a = 123, xy.x = 0.5, xy.y = 0.5");
369 player.step();
370
371 REPORTER_ASSERT(r, player.getCurrentLine() == 10);
372 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy)");

◆ DEF_TEST() [15/15]

DEF_TEST ( SkSLTracePlayerVariableScope  ,
 
)

Definition at line 595 of file SkSLDebugTracePlayerTest.cpp.

597 {{3, 0}, {4, 0}, {5, 0}, {7, 1}}));
599 r,
600 make_local_vars_string(*trace, player) == "##val = 2, x = 2, xy.x = 0.5, xy.y = 0.5");
601 player.step();
602
603 REPORTER_ASSERT(r, player.getCurrentLine() == 7);
605 r, player.getLineNumbersReached() == LineNumberMap({{3, 0}, {4, 0}, {5, 0}, {7, 0}}));
606 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "val = 2, xy.x = 0.5, xy.y = 0.5");
607 player.step();
608
609 REPORTER_ASSERT(r, player.traceHasCompleted());
611 make_global_vars_string(*trace, player) ==
612 "##[main].result.x = 2, ##[main].result.y = 2, ##[main].result.z = "
613 "2, ##[main].result.w = 2");
614}
615
616DEF_TEST(SkSLTracePlayerStepOut, r) {
618R"( // Line 1
619int fn() { // Line 2
620 int a = 11; // Line 3
621 int b = 22; // Line 4
622 int c = 33; // Line 5
623 int d = 44; // Line 6
624 return d; // Line 7
625} // Line 8
626half4 main(float2 xy) { // Line 9
627 return half4(fn()); // Line 10
628} // Line 11
629)");
631 player.reset(trace);
633 player.getLineNumbersReached() ==
634 LineNumberMap({{3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 1}, {10, 1}}));
635 player.step();
636
637 // We should now be inside main.
638 REPORTER_ASSERT(r, player.getCurrentLine() == 10);
639 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy)");
640 player.step();
641
642 // We should now be inside fn.
643 REPORTER_ASSERT(r, player.getCurrentLine() == 3);
644 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy) -> int fn()");
645 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "");
646 player.step();
647
648 REPORTER_ASSERT(r, player.getCurrentLine() == 4);
649 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy) -> int fn()");
650 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "##a = 11");
651 player.step();
652
653 REPORTER_ASSERT(r, player.getCurrentLine() == 5);
654 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy) -> int fn()");
655 REPORTER_ASSERT(r, make_local_vars_string(*trace, player) == "##b = 22, a = 11");
656 player.stepOut();
657
658 // We should now be back inside main(), right where we left off.
659 REPORTER_ASSERT(r, player.getCurrentLine() == 10);
660 REPORTER_ASSERT(r, make_stack_string(*trace, player) == "half4 main(float2 xy)");
662 r,
663 make_local_vars_string(*trace, player) == "##[fn].result = 44, xy.x = 0.5, xy.y = 0.5");
664 player.stepOut();
665
DEF_TEST(SkSLTracePlayerCanResetToNull, r)

◆ make_global_vars_string()

static std::string make_global_vars_string ( const SkSL::DebugTracePriv trace,
const SkSL::SkSLDebugTracePlayer player 
)
static

Definition at line 123 of file SkSLDebugTracePlayerTest.cpp.

124 {
125 return make_vars_string(trace, player.getGlobalVariables());
126}
static std::string make_vars_string(const SkSL::DebugTracePriv &trace, const std::vector< SkSL::SkSLDebugTracePlayer::VariableData > &vars)

◆ make_local_vars_string()

static std::string make_local_vars_string ( const SkSL::DebugTracePriv trace,
const SkSL::SkSLDebugTracePlayer player 
)
static

Definition at line 117 of file SkSLDebugTracePlayerTest.cpp.

118 {
119 int frame = player.getStackDepth() - 1;
120 return make_vars_string(trace, player.getLocalVariables(frame));
121}
double frame
Definition: examples.cpp:31

◆ make_stack_string()

static std::string make_stack_string ( const SkSL::DebugTracePriv trace,
const SkSL::SkSLDebugTracePlayer player 
)
static

Definition at line 74 of file SkSLDebugTracePlayerTest.cpp.

75 {
76 std::vector<int> callStack = player.getCallStack();
77 std::string text;
78 const char* separator = "";
79 for (int frame : callStack) {
80 text += separator;
81 separator = " -> ";
82
83 if (frame >= 0 && (size_t)frame < trace.fFuncInfo.size()) {
84 text += trace.fFuncInfo[frame].name;
85 } else {
86 text += "???";
87 }
88 }
89
90 return text;
91}
std::vector< FunctionDebugInfo > fFuncInfo
std::u16string text

◆ make_trace()

static sk_sp< SkSL::DebugTracePriv > make_trace ( skiatest::Reporter r,
std::string  src 
)
static

Definition at line 34 of file SkSLDebugTracePlayerTest.cpp.

35 {
36 auto debugTrace = sk_make_sp<SkSL::DebugTracePriv>();
37
40 settings.fOptimize = false;
41
42 std::unique_ptr<SkSL::Program> program =
43 compiler.convertProgram(SkSL::ProgramKind::kRuntimeShader, std::move(src), settings);
44 REPORTER_ASSERT(r, program);
45
46 if (program) {
47 const SkSL::FunctionDeclaration* main = program->getFunction("main");
49
50 if (main) {
51 // Compile our program.
52 SkArenaAlloc alloc(/*firstHeapAllocation=*/1000);
53 SkRasterPipeline pipeline(&alloc);
54 std::unique_ptr<SkSL::RP::Program> rasterProg = SkSL::MakeRasterPipelineProgram(
55 *program, *main->definition(), debugTrace.get(), /*writeTraceOps=*/true);
56 REPORTER_ASSERT(r, rasterProg);
57
58 if (rasterProg) {
59 // Append the SkSL program to the raster pipeline, and run it at xy=(0.5, 0.5).
60 static constexpr float kCoordinates[4] = {0.5f, 0.5f, 0.0f, 1.0f};
61 pipeline.appendConstantColor(&alloc, kCoordinates);
62 rasterProg->appendStages(&pipeline,
63 &alloc,
64 /*callbacks=*/nullptr,
65 /*uniforms=*/{});
66 pipeline.run(0, 0, 1, 1);
67 }
68 }
69 }
70
71 return debugTrace;
72}
std::unique_ptr< RP::Program > MakeRasterPipelineProgram(const SkSL::Program &program, const FunctionDefinition &function, DebugTracePriv *debugTrace, bool writeTraceOps)
compiler
Definition: malisc.py:17

◆ make_vars_string()

static std::string make_vars_string ( const SkSL::DebugTracePriv trace,
const std::vector< SkSL::SkSLDebugTracePlayer::VariableData > &  vars 
)
static

Definition at line 93 of file SkSLDebugTracePlayerTest.cpp.

95 {
96 std::string text;
97 auto separator = SkSL::String::Separator();
99 text += separator();
100
101 if (var.fSlotIndex < 0 || (size_t)var.fSlotIndex >= trace.fSlotInfo.size()) {
102 text += "???";
103 continue;
104 }
105
106 const SkSL::SlotDebugInfo& slot = trace.fSlotInfo[var.fSlotIndex];
107 text += var.fDirty ? "##" : "";
108 text += slot.name;
109 text += trace.getSlotComponentSuffix(var.fSlotIndex);
110 text += " = ";
111 text += trace.slotValueToString(var.fSlotIndex, var.fValue);
112 }
113
114 return text;
115}
std::vector< SlotDebugInfo > fSlotInfo
std::string slotValueToString(int slotIndex, double value) const
std::string getSlotComponentSuffix(int slotIndex) const
std::string void void auto Separator()
Definition: SkSLString.h:30
Definition: __init__.py:1