Flutter Engine
The Flutter Engine
Typedefs | Functions
TopoSortTest.cpp File Reference
#include "include/core/SkRefCnt.h"
#include "include/core/SkSpan.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkTArray.h"
#include "src/base/SkRandom.h"
#include "src/gpu/ganesh/GrTTopoSort.h"
#include "tests/Test.h"
#include "tools/ToolUtils.h"
#include <cstddef>
#include <vector>

Go to the source code of this file.

Typedefs

typedef void(* CreateGraphPF) (TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
 

Functions

static void create_graph0 (TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
 
static void create_simple_chain (TArray< sk_sp< ToolUtils::TopoTestNode > > *graph, int n)
 
static void create_graph1 (TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
 
static void create_graph2 (TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
 
static void create_graph3 (TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
 
static void create_graph4 (TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
 
static void create_graph5 (TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
 
static void create_graph6 (TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
 
 DEF_TEST (TopoSort, reporter)
 

Typedef Documentation

◆ CreateGraphPF

typedef void(* CreateGraphPF) (TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)

Definition at line 22 of file TopoSortTest.cpp.

Function Documentation

◆ create_graph0()

static void create_graph0 ( TArray< sk_sp< ToolUtils::TopoTestNode > > *  graph)
static

Definition at line 33 of file TopoSortTest.cpp.

33 {
35
36 (*graph)[0]->dependsOn((*graph)[1].get());
37 (*graph)[0]->dependsOn((*graph)[2].get());
38 (*graph)[1]->dependsOn((*graph)[3].get());
39 (*graph)[2]->dependsOn((*graph)[3].get());
40}
static void AllocNodes(skia_private::TArray< sk_sp< ToolUtils::TopoTestNode > > *graph, int num)
Definition: ToolUtils.h:229
const myers::Point & get(const myers::Segment &)

◆ create_graph1()

static void create_graph1 ( TArray< sk_sp< ToolUtils::TopoTestNode > > *  graph)
static

Definition at line 62 of file TopoSortTest.cpp.

62 {
63 create_simple_chain(graph, 4);
64}
static void create_simple_chain(TArray< sk_sp< ToolUtils::TopoTestNode > > *graph, int n)

◆ create_graph2()

static void create_graph2 ( TArray< sk_sp< ToolUtils::TopoTestNode > > *  graph)
static

Definition at line 73 of file TopoSortTest.cpp.

73 {
75
76 (*graph)[0]->dependsOn((*graph)[1].get());
77 (*graph)[1]->dependsOn((*graph)[2].get());
78 (*graph)[2]->dependsOn((*graph)[0].get());
79}

◆ create_graph3()

static void create_graph3 ( TArray< sk_sp< ToolUtils::TopoTestNode > > *  graph)
static

Definition at line 96 of file TopoSortTest.cpp.

96 {
98
99 (*graph)[0]->dependsOn((*graph)[1].get());
100 (*graph)[0]->dependsOn((*graph)[2].get());
101 (*graph)[1]->dependsOn((*graph)[3].get());
102 (*graph)[2]->dependsOn((*graph)[3].get());
103
104 (*graph)[3]->dependsOn((*graph)[4].get());
105 (*graph)[3]->dependsOn((*graph)[5].get());
106 (*graph)[4]->dependsOn((*graph)[6].get());
107 (*graph)[5]->dependsOn((*graph)[6].get());
108}

◆ create_graph4()

static void create_graph4 ( TArray< sk_sp< ToolUtils::TopoTestNode > > *  graph)
static

Definition at line 119 of file TopoSortTest.cpp.

119 {
121
122 (*graph)[0]->dependsOn((*graph)[1].get());
123 (*graph)[0]->dependsOn((*graph)[2].get());
124 (*graph)[1]->dependsOn((*graph)[3].get());
125 (*graph)[2]->dependsOn((*graph)[3].get());
126
127 (*graph)[4]->dependsOn((*graph)[5].get());
128 (*graph)[4]->dependsOn((*graph)[6].get());
129 (*graph)[5]->dependsOn((*graph)[7].get());
130 (*graph)[6]->dependsOn((*graph)[7].get());
131}

◆ create_graph5()

static void create_graph5 ( TArray< sk_sp< ToolUtils::TopoTestNode > > *  graph)
static

Definition at line 142 of file TopoSortTest.cpp.

142 {
144
145 (*graph)[0]->dependsOn((*graph)[3].get());
146 (*graph)[1]->dependsOn((*graph)[3].get());
147 (*graph)[2]->dependsOn((*graph)[0].get());
148 (*graph)[3]->dependsOn((*graph)[5].get());
149 (*graph)[3]->dependsOn((*graph)[6].get());
150 (*graph)[4]->dependsOn((*graph)[1].get());
151 (*graph)[5]->dependsOn((*graph)[2].get());
152 (*graph)[6]->dependsOn((*graph)[4].get());
153}

◆ create_graph6()

static void create_graph6 ( TArray< sk_sp< ToolUtils::TopoTestNode > > *  graph)
static

Definition at line 162 of file TopoSortTest.cpp.

162 {
164
165 (*graph)[0]->dependsOn((*graph)[1].get());
166 (*graph)[1]->dependsOn((*graph)[2].get());
167 (*graph)[2]->dependsOn((*graph)[0].get());
168
169 (*graph)[3]->dependsOn((*graph)[4].get());
170 (*graph)[4]->dependsOn((*graph)[5].get());
171 (*graph)[5]->dependsOn((*graph)[3].get());
172}

◆ create_simple_chain()

static void create_simple_chain ( TArray< sk_sp< ToolUtils::TopoTestNode > > *  graph,
int  n 
)
static

Definition at line 42 of file TopoSortTest.cpp.

42 {
44
45 for (int i = 0; i < n - 1; ++i) {
46 (*graph)[i+1]->dependsOn((*graph)[i].get());
47 }
48}

◆ DEF_TEST()

DEF_TEST ( TopoSort  ,
reporter   
)

Definition at line 174 of file TopoSortTest.cpp.

174 {
175 SkRandom rand;
176
177 struct {
178 CreateGraphPF fCreate;
179 bool fExpectedResult;
180 } tests[] = {
181 { create_graph0, true },
182 { create_graph1, true },
183 { create_graph2, false },
184 { create_graph3, true },
185 { create_graph4, true },
186 { create_graph5, false },
187 { create_graph6, false },
188 };
189
190 for (size_t i = 0; i < std::size(tests); ++i) {
192
193 (tests[i].fCreate)(&graph);
194
195 const int numNodes = graph.size();
196
198
199 bool actualResult = GrTTopoSort<ToolUtils::TopoTestNode>(graph);
200 REPORTER_ASSERT(reporter, actualResult == tests[i].fExpectedResult);
201 REPORTER_ASSERT(reporter, numNodes == graph.size());
202
203 if (tests[i].fExpectedResult) {
204 for (const auto& node : graph) {
205 REPORTER_ASSERT(reporter, node->check());
206 }
207 } else {
208 // When the topological sort fails all the nodes should still appear in the result
209 // but their order can be somewhat arbitrary.
210 std::vector<bool> seen(numNodes, false);
211
212 for (const auto& node : graph) {
213 SkASSERT(node);
214 SkASSERT(!seen[node->id()]);
215 seen[node->id()] = true;
216 }
217 }
218
219 //SkDEBUGCODE(print(graph);)
220 }
221
222 // Some additional tests that do multiple partial sorts of graphs where we know nothing in an
223 // earlier partion depends on anything in a later partition.
224 for (int n = 2; n < 6; ++n) {
225 for (int split = 1; split < n; ++split) {
227 create_simple_chain(&graph, n);
228 SkSpan spanA = SkSpan(graph.begin(), split);
229 SkSpan spanB = SkSpan(graph.begin() + split, n - split);
232 bool result = GrTTopoSort(spanA);
233 if (!result) {
234 ERRORF(reporter, "Topo sort on partial chain failed.");
235 return;
236 }
237 // Nothing outside of the processed span should have been output.
238 for (const auto& node : spanB) {
240 }
241 result = GrTTopoSort(spanB, split);
242 if (!result) {
243 ERRORF(reporter, "Topo sort on partial chain failed.");
244 return;
245 }
246 for (const auto& node : graph) {
247 REPORTER_ASSERT(reporter, node->check());
248 }
249 }
250 }
251}
static BlurTest tests[]
Definition: BlurTest.cpp:84
reporter
Definition: FontMgrTest.cpp:39
bool GrTTopoSort(SkSpan< sk_sp< T > > graph, uint32_t offset=0)
Definition: GrTTopoSort.h:92
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define ERRORF(r,...)
Definition: Test.h:293
static void create_graph1(TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
static void create_graph5(TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
static void create_graph4(TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
void(* CreateGraphPF)(TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
static void create_graph6(TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
static void create_graph0(TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
static void create_graph3(TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
static void create_graph2(TArray< sk_sp< ToolUtils::TopoTestNode > > *graph)
static bool WasOutput(TopoTestNode *node)
Definition: ToolUtils.h:218
static void Shuffle(SkSpan< sk_sp< TopoTestNode > > graph, SkRandom *rand)
Definition: ToolUtils.h:247
int size() const
Definition: SkTArray.h:421
GAsyncResult * result
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259