Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: tests/TestConfigParsing.cpp

Issue 1490113005: Add config options to run different GPU APIs to dm and nanobench (Closed) Base URL: https://skia.googlesource.com/skia.git@commandbuffer-as-api-03-context-factory-glcontext-type
Patch Set: fix errorneous config handling Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkCommonFlagsConfig.h"
9 #include "Test.h"
10
11 DEF_TEST(ParseConfigs_Gpu, reporter) {
12 // Parses a normal config and returns correct "tag".
13 // Gpu config defaults work.
14 DEFINE_string(config1, "gpu", "");
15 SkCommandLineConfigArray configs;
16 ParseConfigs(FLAGS_config1, &configs);
17
18 REPORTER_ASSERT(reporter, configs.count() == 1);
19 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu"));
20 REPORTER_ASSERT(reporter, configs[0]->getViaParts().count() == 0);
21 #if SK_SUPPORT_GPU
22 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
23 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getAPI() == SkCommandLi neConfigGpu::kNative_API);
24 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR() == false);
25 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false );
26 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
27 #endif
28 }
29
30 DEF_TEST(ParseConfigs_OutParam, reporter) {
31 // Clears the out parameter.
32 DEFINE_string(config1, "gpu", "");
33 SkCommandLineConfigArray configs;
34 ParseConfigs(FLAGS_config1, &configs);
35 REPORTER_ASSERT(reporter, configs.count() == 1);
36 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu"));
37 DEFINE_string(config2, "8888", "");
38 ParseConfigs(FLAGS_config2, &configs);
39 REPORTER_ASSERT(reporter, configs.count() == 1);
40 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("8888"));
41 }
42
43 DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
44 // Parses all default configs and returns correct "tag".
45
46 DEFINE_string(config1, "565 8888 debug gpu gpudebug gpudft gpunull "
47 "msaa16 msaa4 nonrendering null nullgpu nvprmsaa16 nvprmsaa4 "
48 "pdf pdf_poppler skp svg xps angle angle-gl commandbuffer "
49 "mesa hwui", "");
50
51 SkCommandLineConfigArray configs;
52 ParseConfigs(FLAGS_config1, &configs);
53
54 const char* expectedConfigs[] = {
55 "565", "8888", "debug", "gpu", "gpudebug", "gpudft", "gpunull", "msaa16" , "msaa4",
56 "nonrendering", "null", "nullgpu", "nvprmsaa16", "nvprmsaa4", "pdf", "pd f_poppler",
57 "skp", "svg", "xps", "angle", "angle-gl", "commandbuffer", "mesa", "hwui "
58 };
59 REPORTER_ASSERT(reporter, configs.count() == SK_ARRAY_COUNT(expectedConfigs) );
60 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedConfigs); ++i) {
61 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedConfigs[i] ));
62 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
63 }
64 #if SK_SUPPORT_GPU
65 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
66 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
67 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
68 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
69 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu());
70 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getUseDIText());
71 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu());
72 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 16);
73 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 4);
74 REPORTER_ASSERT(reporter, !configs[9]->asConfigGpu());
75 REPORTER_ASSERT(reporter, !configs[10]->asConfigGpu());
76 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu());
77 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 16);
78 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
79 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 4);
80 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR());
81 REPORTER_ASSERT(reporter, !configs[14]->asConfigGpu());
82 REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu());
83 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
84 REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu());
85 REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu());
86 REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu());
87 #if SK_ANGLE
88 #ifdef SK_BUILD_FOR_WIN
89 REPORTER_ASSERT(reporter, configs[19]->asConfigGpu());
90 #else
91 REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu());
92 #endif
93 REPORTER_ASSERT(reporter, configs[20]->asConfigGpu());
94 #else
95 REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu());
96 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu());
97 #endif
98 #if SK_COMMAND_BUFFER
99 REPORTER_ASSERT(reporter, configs[21]->asConfigGpu());
100 #else
101 REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu());
102 #endif
103 #if SK_MESA
104 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu());
105 #else
106 REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu());
107 #endif
108 #endif
109 }
110
111 DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
112 DEFINE_string(config1, "gpu(nvpr=true,dit=true) gpu(api=angle) gpu(api=angle -gl) "
113 "gpu(api=mesa,samples=77) gpu(dit=true,api=commandbuffer) gpu( ) gpu(api=gles)", "");
114
115 SkCommandLineConfigArray configs;
116 ParseConfigs(FLAGS_config1, &configs);
117 const char* expectedTags[] = {
118 "gpu(nvpr=true,dit=true)",
119 "gpu(api=angle)",
120 "gpu(api=angle-gl)",
121 "gpu(api=mesa,samples=77)",
122 "gpu(dit=true,api=commandbuffer)",
123 "gpu()",
124 "gpu(api=gles)"
125 };
126 REPORTER_ASSERT(reporter, configs.count() == SK_ARRAY_COUNT(expectedTags));
127 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedTags); ++i) {
128 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedTags[i]));
129 }
130 #if SK_SUPPORT_GPU
131 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getAPI() ==
132 SkCommandLineConfigGpu::kNative_API);
133 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
134 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText());
135 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
136 #if SK_ANGLE
137 #ifdef SK_BUILD_FOR_WIN
138 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getAPI() ==
139 SkCommandLineConfigGpu::kANGLE_API);
140 #else
141 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
142 #endif
143 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getAPI() ==
144 SkCommandLineConfigGpu::kANGLE_GL_API);
145 #else
146 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
147 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
148 #endif
149 #if SK_MESA
150 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getAPI() ==
151 SkCommandLineConfigGpu::kMESA_API);
152 #else
153 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
154 #endif
155 #if SK_COMMAND_BUFFER
156 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getAPI() ==
157 SkCommandLineConfigGpu::kCommandBuffer_API);
158
159 #else
160 REPORTER_ASSERT(reporter, !configs[4]->asConfigGpu());
161 #endif
162 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getAPI() ==
163 SkCommandLineConfigGpu::kNative_API);
164 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
165 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
166 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0);
167 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getAPI() ==
168 SkCommandLineConfigGpu::kGLES_API);
169 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
170 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
171 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0);
172
173 #endif
174 }
175
176 DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
177 DEFINE_string(config1, "gpu(nvpr=1) gpu(api=gl,) gpu(api=angle-glu) "
178 "gpu(api=,samples=0) gpu(samples=true) gpu(samples=0,samples=0 ) "
179 "gpu(,samples=0) gpu(samples=54 ,, gpu( samples=54", "");
180
181 SkCommandLineConfigArray configs;
182 ParseConfigs(FLAGS_config1, &configs);
183 const char* expectedTags[] = {
184 "gpu(nvpr=1)", // Number as bool.
185 "gpu(api=gl,)", // Trailing in comma.
186 "gpu(api=angle-glu)", // Unknown api.
187 "gpu(api=,samples=0)", // Empty api.
188 "gpu(samples=true)", // Value true as a number.
189 "gpu(samples=0,samples=0)", // Duplicate option key.
190 "gpu(,samples=0)", // Leading comma.
191 "gpu(samples=54", // Missing closing parenthesis.
192 ",,",
193 "gpu(", // Missing parenthesis.
194 "samples=54" // No backend.
195 };
196 REPORTER_ASSERT(reporter, configs.count() == SK_ARRAY_COUNT(expectedTags));
197 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedTags); ++i) {
198 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedTags[i]));
199 #if SK_SUPPORT_GPU
200 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
201 #endif
202 }
203 }
204
205
206 DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
207 // These just list explicitly some properties of the system.
208 DEFINE_string(config1, "gpu(nvpr=true,dit=true) gpu(dit=true,nvpr=true) "
209 "gpu(api=native) gpu(api=gl) gpu(api=gles) "
210 "gpu gpu() gpu(samples=0) gpu(api=native,samples=0)", "");
211
212 SkCommandLineConfigArray configs;
213 ParseConfigs(FLAGS_config1, &configs);
214 const char* expectedTags[] = {
215 // Options are not canonized -> two same configs have a different tag.
216 "gpu(nvpr=true,dit=true)", "gpu(dit=true,nvpr=true)",
217 // API native is alias for gl or gles, but it's not canonized -> differe nt tag.
218 "gpu(api=native)", "gpu(api=gl)", "gpu(api=gles)", ""
219 // Default values are not canonized -> different tag.
220 "gpu", "gpu()", "gpu(samples=0)", "gpu(api=native,samples=0)"
221 };
222 REPORTER_ASSERT(reporter, configs.count() == SK_ARRAY_COUNT(expectedTags));
223 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedTags); ++i) {
224 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedTags[i]));
225 #if SK_SUPPORT_GPU
226 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
227 #endif
228 }
229 }
230 DEF_TEST(ParseConfigs_ViaParsing, reporter) {
231 DEFINE_string(config1, "a-b-c-33-8888 zz-qq-gpu a-angle-gl", "");
232
233 SkCommandLineConfigArray configs;
234 ParseConfigs(FLAGS_config1, &configs);
235 const struct {
236 const char* tag;
237 const char* vias[3];
238 } expectedConfigs[] = {
239 { "8888", {"a", "b", "c"}},
240 { "gpu", {"zz", "qq", nullptr}},
241 { "angle-gl", {"a", nullptr, nullptr } } // The angle-gl tag is only tag that contains
242 // hyphen.
243 };
244 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedConfigs); ++i) {
245 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedConfigs[i] .tag));
246 for (size_t j = 0; j < SK_ARRAY_COUNT(expectedConfigs[i].vias); ++j) {
247 if (!expectedConfigs[i].vias[j]) {
248 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == s tatic_cast<int>(j));
249 break;
250 }
251 REPORTER_ASSERT(reporter, configs[i]->getViaParts()[j].equals(expect edConfigs[i].vias[j]));
252 }
253 }
254 }
255
256 DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
257 DEFINE_string(config1, "zz-qq-gpu(api=gles) a-gpu(samples=1", "");
258
259 SkCommandLineConfigArray configs;
260 ParseConfigs(FLAGS_config1, &configs);
261 const struct {
262 const char* tag;
263 const char* vias[3];
264 } expectedConfigs[] = {
265 { "gpu(api=gles)", {"zz", "qq", nullptr}},
266 { "gpu(samples=1", {"a", nullptr, nullptr } } // This is not extended fo rm, but via still
267 // works as expected.
268 };
269 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedConfigs); ++i) {
270 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedConfigs[i] .tag));
271 for (size_t j = 0; j < SK_ARRAY_COUNT(expectedConfigs[i].vias); ++j) {
272 if (!expectedConfigs[i].vias[j]) {
273 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == s tatic_cast<int>(j));
274 break;
275 }
276 REPORTER_ASSERT(reporter, configs[i]->getViaParts()[j].equals(expect edConfigs[i].vias[j]));
277 }
278 }
279 #if SK_SUPPORT_GPU
280 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
281 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
282 #endif
283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698