blob: 301f6a2d9afd9a3ed43f12c27287a7d6f025a5f4 [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()
bsalomonb4b4cf32016-04-04 05:56:59 -070044 == GrContextFactory::kNative_GLContextType);
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() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700187 GrContextFactory::kNative_GLContextType);
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() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700194 GrContextFactory::kANGLE_GLContextType);
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() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700199 GrContextFactory::kANGLE_GL_GLContextType);
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() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700206 GrContextFactory::kMESA_GLContextType);
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() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700212 GrContextFactory::kCommandBuffer_GLContextType);
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() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700218 GrContextFactory::kNative_GLContextType);
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() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700223 GrContextFactory::kGLES_GLContextType);
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() ==
228 GrContextFactory::kGL_GLContextType);
229 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
bsalomonb4b4cf32016-04-04 05:56:59 -0700263
kkinnunen3e980c32015-12-23 01:33:00 -0800264DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
265 // These just list explicitly some properties of the system.
266 SkCommandLineFlags::StringArray config1 = make_string_array({
267 // Options are not canonized -> two same configs have a different tag.
268 "gpu(nvpr=true,dit=true)", "gpu(dit=true,nvpr=true)",
bsalomonb4b4cf32016-04-04 05:56:59 -0700269 // API native is alias for gl or gles, but it's not canonized -> different tag.
270 "gpu(api=native)", "gpu(api=gl)", "gpu(api=gles)", ""
271 // Default values are not canonized -> different tag.
272 "gpu", "gpu()", "gpu(samples=0)", "gpu(api=native,samples=0)"
kkinnunen3e980c32015-12-23 01:33:00 -0800273 });
274 SkCommandLineConfigArray configs;
275 ParseConfigs(config1, &configs);
276 REPORTER_ASSERT(reporter, configs.count() == config1.count());
277 for (int i = 0; i < config1.count(); ++i) {
278 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
279#if SK_SUPPORT_GPU
280 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
281 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
282#else
283 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
284#endif
285 }
286}
287DEF_TEST(ParseConfigs_ViaParsing, reporter) {
288 SkCommandLineFlags::StringArray config1 = make_string_array({
289 "a-b-c-8888",
290 "zz-qq-gpu",
291 "a-angle-gl"
292 });
293
294 SkCommandLineConfigArray configs;
295 ParseConfigs(config1, &configs);
296 const struct {
297 const char* backend;
298 const char* vias[3];
299 } expectedConfigs[] = {
300 {"8888", {"a", "b", "c"}},
301 {"gpu", {"zz", "qq", nullptr}},
302 {"angle-gl", {"a", nullptr, nullptr}} // The angle-gl tag is only tag that contains
303 // hyphen.
304 };
305 for (int i = 0; i < config1.count(); ++i) {
306 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
307 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
308 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
309 if (!expectedConfigs[i].vias[j]) {
310 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
311 break;
312 }
313 REPORTER_ASSERT(reporter,
314 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
315 }
316 }
317}
318
319DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
320 SkCommandLineFlags::StringArray config1 = make_string_array({
321 "zz-qq-gpu(api=gles)",
322 "a-gpu(samples=1",
323 "abc-def-angle-gl(samples=1)",
324 });
325
326 SkCommandLineConfigArray configs;
327 ParseConfigs(config1, &configs);
328 const struct {
329 const char* backend;
330 const char* vias[3];
331 } expectedConfigs[] = {
332#if SK_SUPPORT_GPU
333 {"gpu", {"zz", "qq", nullptr}},
334#else
335 {"gpu(api=gles)", {"zz", "qq", nullptr}},
336#endif
337 {"gpu(samples=1", {"a", nullptr, nullptr}}, // This is not extended form, but via still
338 // works as expected.
339 {"gl(samples=1)", {"abc", "def", "angle"}} // This is not extended form. Also
340 // angle-gl is not a "backend" in this case.
341 };
342 for (int i = 0; i < config1.count(); ++i) {
343 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
344 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
345 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
346 if (!expectedConfigs[i].vias[j]) {
347 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
348 static_cast<int>(j));
349 break;
350 }
351 REPORTER_ASSERT(reporter,
352 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
353 }
354 }
355#if SK_SUPPORT_GPU
356 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
357 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
358 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
359#endif
360}