blob: ac7037f9d26192861ff9f68b74d07d1c50c5564d [file] [log] [blame]
kkinnunen3e980c32015-12-23 01:33:00 -08001/*
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#include <initializer_list>
11
bsalomon3724e572016-03-30 18:56:19 -070012using sk_gpu_test::GrContextFactory;
13
kkinnunen3e980c32015-12-23 01:33:00 -080014namespace {
15// The code
16// SkCommandLineFlags::StringArray FLAGS_config1 = make_string_array({"a", "b"})
17// can be used to construct string array that one gets with command line flags.
18// For example, the call above is equivalent of
19// DEFINE_string(config1, "a b", "");
20// in cases where the default command line flag value ("a b") is used.
21// make_string_array can be used to construct StringArray strings that have spaces in
22// them.
23SkCommandLineFlags::StringArray make_string_array(std::initializer_list<const char*> strings) {
24 SkTArray<SkString> array;
25 for (auto& s : strings) {
26 array.push_back(SkString(s));
27 }
28 return SkCommandLineFlags::StringArray(array);
29}
30}
31DEF_TEST(ParseConfigs_Gpu, reporter) {
32 // Parses a normal config and returns correct "tag".
33 // Gpu config defaults work.
34 SkCommandLineFlags::StringArray config1 = make_string_array({"gpu"});
35 SkCommandLineConfigArray configs;
36 ParseConfigs(config1, &configs);
37
38 REPORTER_ASSERT(reporter, configs.count() == 1);
39 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu"));
40 REPORTER_ASSERT(reporter, configs[0]->getViaParts().count() == 0);
41#if SK_SUPPORT_GPU
42 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
43 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType()
bsalomon85b4b532016-04-05 11:06:27 -070044 == GrContextFactory::kNativeGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -080045 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR() == false);
46 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false);
47 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
brianosmand93c1202016-03-10 07:49:08 -080048 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kN32_SkColorType);
49 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getProfileType()
50 == kLinear_SkColorProfileType);
kkinnunen3e980c32015-12-23 01:33:00 -080051#endif
52}
53
54DEF_TEST(ParseConfigs_OutParam, reporter) {
55 // Clears the out parameter.
56 SkCommandLineFlags::StringArray config1 = make_string_array({"gpu"});
57 SkCommandLineConfigArray configs;
58 ParseConfigs(config1, &configs);
59 REPORTER_ASSERT(reporter, configs.count() == 1);
60 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu"));
bsalomonb8797bb2016-04-05 08:49:38 -070061
kkinnunen3e980c32015-12-23 01:33:00 -080062 SkCommandLineFlags::StringArray config2 = make_string_array({"8888"});
63 ParseConfigs(config2, &configs);
64 REPORTER_ASSERT(reporter, configs.count() == 1);
65 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("8888"));
bsalomonb8797bb2016-04-05 08:49:38 -070066
67 SkCommandLineFlags::StringArray config3 = make_string_array({"gl"});
68 ParseConfigs(config3, &configs);
69 REPORTER_ASSERT(reporter, configs.count() == 1);
70 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gl"));
kkinnunen3e980c32015-12-23 01:33:00 -080071}
72
73DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
74 // Parses all default configs and returns correct "tag".
75
76 SkCommandLineFlags::StringArray config1 = make_string_array({
77 "565", "8888", "debug", "gpu", "gpudebug", "gpudft", "gpunull", "msaa16", "msaa4",
cdaltonc28afdb2016-03-29 20:05:07 -070078 "nonrendering", "null", "nullgpu", "nvpr16", "nvpr4", "nvprdit16", "nvprdit4", "pdf",
halcanary94b87bd2016-04-04 06:12:15 -070079 "skp", "svg", "xps", "angle", "angle-gl", "commandbuffer", "mesa", "hwui",
bsalomonb8797bb2016-04-05 08:49:38 -070080 "gpuf16", "gpusrgb", "gl", "glnvpr4", "glnvprdit4", "glsrgb", "glmsaa4"
kkinnunen3e980c32015-12-23 01:33:00 -080081 });
82
83 SkCommandLineConfigArray configs;
84 ParseConfigs(config1, &configs);
85
86 REPORTER_ASSERT(reporter, configs.count() == config1.count());
87 for (int i = 0; i < config1.count(); ++i) {
88 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
89 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
90 }
91#if SK_SUPPORT_GPU
92 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
93 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
94 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
95 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
96 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu());
97 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getUseDIText());
98 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu());
99 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 16);
100 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 4);
101 REPORTER_ASSERT(reporter, !configs[9]->asConfigGpu());
102 REPORTER_ASSERT(reporter, !configs[10]->asConfigGpu());
103 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu());
104 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 16);
105 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700106 REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800107 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 4);
108 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700109 REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu()->getUseDIText());
110 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 16);
111 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR());
112 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText());
113 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getSamples() == 4);
114 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseNVPR());
115 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800116 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
117 REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu());
118 REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu());
cdaltonc28afdb2016-03-29 20:05:07 -0700119 REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu());
halcanary3c4521a2016-04-04 12:14:46 -0700120 REPORTER_ASSERT(reporter, !configs[24]->asConfigGpu());
121 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType()
brianosmand93c1202016-03-10 07:49:08 -0800122 == kRGBA_F16_SkColorType);
halcanary3c4521a2016-04-04 12:14:46 -0700123 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getProfileType()
brianosmand93c1202016-03-10 07:49:08 -0800124 == kLinear_SkColorProfileType);
halcanary3c4521a2016-04-04 12:14:46 -0700125 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType()
brianosmand93c1202016-03-10 07:49:08 -0800126 == kN32_SkColorType);
halcanary3c4521a2016-04-04 12:14:46 -0700127 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getProfileType()
brianosmand93c1202016-03-10 07:49:08 -0800128 == kSRGB_SkColorProfileType);
kkinnunen3e980c32015-12-23 01:33:00 -0800129#if SK_ANGLE
130#ifdef SK_BUILD_FOR_WIN
halcanary3c4521a2016-04-04 12:14:46 -0700131 REPORTER_ASSERT(reporter, configs[20]->asConfigGpu());
132#else
133 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu());
134#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800135 REPORTER_ASSERT(reporter, configs[21]->asConfigGpu());
136#else
halcanary3c4521a2016-04-04 12:14:46 -0700137 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800138 REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu());
139#endif
cdaltonc28afdb2016-03-29 20:05:07 -0700140#if SK_COMMAND_BUFFER
halcanary3c4521a2016-04-04 12:14:46 -0700141 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu());
142#else
143 REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu());
144#endif
145#if SK_MESA
cdaltonc28afdb2016-03-29 20:05:07 -0700146 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu());
147#else
148 REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu());
149#endif
bsalomonb8797bb2016-04-05 08:49:38 -0700150 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu());
151 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu());
152 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getSamples() == 4);
153 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseNVPR());
154 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu());
155 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getSamples() == 4);
156 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseNVPR());
157 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseDIText());
158 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu());
159 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorType() == kN32_SkColorType);
160 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getProfileType() ==
161 kSRGB_SkColorProfileType);
162 REPORTER_ASSERT(reporter, configs[31]->asConfigGpu());
163 REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()->getSamples() == 4);
kkinnunen3e980c32015-12-23 01:33:00 -0800164#endif
165}
166
167DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
168 SkCommandLineFlags::StringArray config1 = make_string_array({
kkinnunene3c2f802015-12-29 08:57:32 -0800169 "gpu(nvpr=true,dit=false)",
kkinnunen3e980c32015-12-23 01:33:00 -0800170 "gpu(api=angle)",
171 "gpu(api=angle-gl)",
172 "gpu(api=mesa,samples=77)",
173 "gpu(dit=true,api=commandbuffer)",
174 "gpu()",
bsalomonb8797bb2016-04-05 08:49:38 -0700175 "gpu(api=gles)",
176 "gpu(api=gl)"
kkinnunen3e980c32015-12-23 01:33:00 -0800177 });
178
179 SkCommandLineConfigArray configs;
180 ParseConfigs(config1, &configs);
181 REPORTER_ASSERT(reporter, configs.count() == config1.count());
182 for (int i = 0; i < config1.count(); ++i) {
183 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
184 }
185#if SK_SUPPORT_GPU
186 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700187 GrContextFactory::kNativeGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800188 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
kkinnunene3c2f802015-12-29 08:57:32 -0800189 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800190 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
191#if SK_ANGLE
192#ifdef SK_BUILD_FOR_WIN
193 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700194 GrContextFactory::kANGLE_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800195#else
196 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
197#endif
198 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700199 GrContextFactory::kANGLE_GL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800200#else
201 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
202 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
203#endif
204#if SK_MESA
205 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700206 GrContextFactory::kMESA_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800207#else
208 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
209#endif
210#if SK_COMMAND_BUFFER
211 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700212 GrContextFactory::kCommandBuffer_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800213
214#else
215 REPORTER_ASSERT(reporter, !configs[4]->asConfigGpu());
216#endif
217 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700218 GrContextFactory::kNativeGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800219 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
220 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
221 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0);
222 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700223 GrContextFactory::kGLES_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800224 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
225 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
226 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0);
bsalomonb8797bb2016-04-05 08:49:38 -0700227 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700228 GrContextFactory::kGL_ContextType);
bsalomonb8797bb2016-04-05 08:49:38 -0700229 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
230 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
231 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0);
kkinnunen3e980c32015-12-23 01:33:00 -0800232#endif
233}
234
235DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
236 SkCommandLineFlags::StringArray config1 = make_string_array({
237 "gpu(nvpr=1)", // Number as bool.
238 "gpu(api=gl,)", // Trailing in comma.
239 "gpu(api=angle-glu)", // Unknown api.
240 "gpu(api=,samples=0)", // Empty api.
241 "gpu(samples=true)", // Value true as a number.
242 "gpu(samples=0,samples=0)", // Duplicate option key.
243 "gpu(,samples=0)", // Leading comma.
244 "gpu(samples=54", // Missing closing parenthesis.
245 ",,",
246 "gpu(", // Missing parenthesis.
247 "samples=54" // No backend.
248 "gpu(nvpr=true )", // Space.
249 });
250
251 SkCommandLineConfigArray configs;
252 ParseConfigs(config1, &configs);
253 REPORTER_ASSERT(reporter, configs.count() == config1.count());
254 for (int i = 0; i < config1.count(); ++i) {
255 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
256 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
257#if SK_SUPPORT_GPU
258 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
259#endif
260 }
261}
262
kkinnunen3e980c32015-12-23 01:33:00 -0800263DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
264 // These just list explicitly some properties of the system.
265 SkCommandLineFlags::StringArray config1 = make_string_array({
266 // Options are not canonized -> two same configs have a different tag.
267 "gpu(nvpr=true,dit=true)", "gpu(dit=true,nvpr=true)",
bsalomon85b4b532016-04-05 11:06:27 -0700268 "gpu(api=debug)", "gpu(api=gl)", "gpu(api=gles)", ""
269 "gpu", "gpu()", "gpu(samples=0)", "gpu(api=gles,samples=0)"
kkinnunen3e980c32015-12-23 01:33:00 -0800270 });
271 SkCommandLineConfigArray configs;
272 ParseConfigs(config1, &configs);
273 REPORTER_ASSERT(reporter, configs.count() == config1.count());
274 for (int i = 0; i < config1.count(); ++i) {
275 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
276#if SK_SUPPORT_GPU
277 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
278 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
279#else
280 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
281#endif
282 }
283}
284DEF_TEST(ParseConfigs_ViaParsing, reporter) {
285 SkCommandLineFlags::StringArray config1 = make_string_array({
286 "a-b-c-8888",
287 "zz-qq-gpu",
288 "a-angle-gl"
289 });
290
291 SkCommandLineConfigArray configs;
292 ParseConfigs(config1, &configs);
293 const struct {
294 const char* backend;
295 const char* vias[3];
296 } expectedConfigs[] = {
297 {"8888", {"a", "b", "c"}},
298 {"gpu", {"zz", "qq", nullptr}},
299 {"angle-gl", {"a", nullptr, nullptr}} // The angle-gl tag is only tag that contains
300 // hyphen.
301 };
302 for (int i = 0; i < config1.count(); ++i) {
303 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
304 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
305 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
306 if (!expectedConfigs[i].vias[j]) {
307 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
308 break;
309 }
310 REPORTER_ASSERT(reporter,
311 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
312 }
313 }
314}
315
316DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
317 SkCommandLineFlags::StringArray config1 = make_string_array({
318 "zz-qq-gpu(api=gles)",
319 "a-gpu(samples=1",
320 "abc-def-angle-gl(samples=1)",
321 });
322
323 SkCommandLineConfigArray configs;
324 ParseConfigs(config1, &configs);
325 const struct {
326 const char* backend;
327 const char* vias[3];
328 } expectedConfigs[] = {
329#if SK_SUPPORT_GPU
330 {"gpu", {"zz", "qq", nullptr}},
331#else
332 {"gpu(api=gles)", {"zz", "qq", nullptr}},
333#endif
334 {"gpu(samples=1", {"a", nullptr, nullptr}}, // This is not extended form, but via still
335 // works as expected.
336 {"gl(samples=1)", {"abc", "def", "angle"}} // This is not extended form. Also
337 // angle-gl is not a "backend" in this case.
338 };
339 for (int i = 0; i < config1.count(); ++i) {
340 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
341 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
342 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
343 if (!expectedConfigs[i].vias[j]) {
344 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
345 static_cast<int>(j));
346 break;
347 }
348 REPORTER_ASSERT(reporter,
349 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
350 }
351 }
352#if SK_SUPPORT_GPU
353 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
354 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
355 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
356#endif
357}