blob: f718994b56788a2912c906bc56cdaaf05a31338e [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"));
61 SkCommandLineFlags::StringArray config2 = make_string_array({"8888"});
62 ParseConfigs(config2, &configs);
63 REPORTER_ASSERT(reporter, configs.count() == 1);
64 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("8888"));
65}
66
67DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
68 // Parses all default configs and returns correct "tag".
69
70 SkCommandLineFlags::StringArray config1 = make_string_array({
71 "565", "8888", "debug", "gpu", "gpudebug", "gpudft", "gpunull", "msaa16", "msaa4",
cdaltonc28afdb2016-03-29 20:05:07 -070072 "nonrendering", "null", "nullgpu", "nvpr16", "nvpr4", "nvprdit16", "nvprdit4", "pdf",
halcanary94b87bd2016-04-04 06:12:15 -070073 "skp", "svg", "xps", "angle", "angle-gl", "commandbuffer", "mesa", "hwui",
brianosman8e478812016-03-10 09:47:56 -080074 "gpuf16", "gpusrgb"
kkinnunen3e980c32015-12-23 01:33:00 -080075 });
76
77 SkCommandLineConfigArray configs;
78 ParseConfigs(config1, &configs);
79
80 REPORTER_ASSERT(reporter, configs.count() == config1.count());
81 for (int i = 0; i < config1.count(); ++i) {
82 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
83 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
84 }
85#if SK_SUPPORT_GPU
86 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
87 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
88 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
89 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
90 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu());
91 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getUseDIText());
92 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu());
93 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 16);
94 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 4);
95 REPORTER_ASSERT(reporter, !configs[9]->asConfigGpu());
96 REPORTER_ASSERT(reporter, !configs[10]->asConfigGpu());
97 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu());
98 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 16);
99 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700100 REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800101 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 4);
102 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700103 REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu()->getUseDIText());
104 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 16);
105 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR());
106 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText());
107 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getSamples() == 4);
108 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseNVPR());
109 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800110 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
111 REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu());
112 REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu());
cdaltonc28afdb2016-03-29 20:05:07 -0700113 REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu());
halcanary3c4521a2016-04-04 12:14:46 -0700114 REPORTER_ASSERT(reporter, !configs[24]->asConfigGpu());
115 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType()
brianosmand93c1202016-03-10 07:49:08 -0800116 == kRGBA_F16_SkColorType);
halcanary3c4521a2016-04-04 12:14:46 -0700117 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getProfileType()
brianosmand93c1202016-03-10 07:49:08 -0800118 == kLinear_SkColorProfileType);
halcanary3c4521a2016-04-04 12:14:46 -0700119 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType()
brianosmand93c1202016-03-10 07:49:08 -0800120 == kN32_SkColorType);
halcanary3c4521a2016-04-04 12:14:46 -0700121 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getProfileType()
brianosmand93c1202016-03-10 07:49:08 -0800122 == kSRGB_SkColorProfileType);
kkinnunen3e980c32015-12-23 01:33:00 -0800123#if SK_ANGLE
124#ifdef SK_BUILD_FOR_WIN
halcanary3c4521a2016-04-04 12:14:46 -0700125 REPORTER_ASSERT(reporter, configs[20]->asConfigGpu());
126#else
127 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu());
128#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800129 REPORTER_ASSERT(reporter, configs[21]->asConfigGpu());
130#else
halcanary3c4521a2016-04-04 12:14:46 -0700131 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800132 REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu());
133#endif
cdaltonc28afdb2016-03-29 20:05:07 -0700134#if SK_COMMAND_BUFFER
halcanary3c4521a2016-04-04 12:14:46 -0700135 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu());
136#else
137 REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu());
138#endif
139#if SK_MESA
cdaltonc28afdb2016-03-29 20:05:07 -0700140 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu());
141#else
142 REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu());
143#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800144#endif
145}
146
147DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
148 SkCommandLineFlags::StringArray config1 = make_string_array({
kkinnunene3c2f802015-12-29 08:57:32 -0800149 "gpu(nvpr=true,dit=false)",
kkinnunen3e980c32015-12-23 01:33:00 -0800150 "gpu(api=angle)",
151 "gpu(api=angle-gl)",
152 "gpu(api=mesa,samples=77)",
153 "gpu(dit=true,api=commandbuffer)",
154 "gpu()",
155 "gpu(api=gles)"
156 });
157
158 SkCommandLineConfigArray configs;
159 ParseConfigs(config1, &configs);
160 REPORTER_ASSERT(reporter, configs.count() == config1.count());
161 for (int i = 0; i < config1.count(); ++i) {
162 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
163 }
164#if SK_SUPPORT_GPU
165 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700166 GrContextFactory::kNative_GLContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800167 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
kkinnunene3c2f802015-12-29 08:57:32 -0800168 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800169 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
170#if SK_ANGLE
171#ifdef SK_BUILD_FOR_WIN
172 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700173 GrContextFactory::kANGLE_GLContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800174#else
175 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
176#endif
177 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700178 GrContextFactory::kANGLE_GL_GLContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800179#else
180 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
181 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
182#endif
183#if SK_MESA
184 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700185 GrContextFactory::kMESA_GLContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800186#else
187 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
188#endif
189#if SK_COMMAND_BUFFER
190 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700191 GrContextFactory::kCommandBuffer_GLContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800192
193#else
194 REPORTER_ASSERT(reporter, !configs[4]->asConfigGpu());
195#endif
196 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700197 GrContextFactory::kNative_GLContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800198 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
199 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
200 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0);
201 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
bsalomonb4b4cf32016-04-04 05:56:59 -0700202 GrContextFactory::kGLES_GLContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800203 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
204 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
205 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0);
bsalomonb4b4cf32016-04-04 05:56:59 -0700206
kkinnunen3e980c32015-12-23 01:33:00 -0800207#endif
208}
209
210DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
211 SkCommandLineFlags::StringArray config1 = make_string_array({
212 "gpu(nvpr=1)", // Number as bool.
213 "gpu(api=gl,)", // Trailing in comma.
214 "gpu(api=angle-glu)", // Unknown api.
215 "gpu(api=,samples=0)", // Empty api.
216 "gpu(samples=true)", // Value true as a number.
217 "gpu(samples=0,samples=0)", // Duplicate option key.
218 "gpu(,samples=0)", // Leading comma.
219 "gpu(samples=54", // Missing closing parenthesis.
220 ",,",
221 "gpu(", // Missing parenthesis.
222 "samples=54" // No backend.
223 "gpu(nvpr=true )", // Space.
224 });
225
226 SkCommandLineConfigArray configs;
227 ParseConfigs(config1, &configs);
228 REPORTER_ASSERT(reporter, configs.count() == config1.count());
229 for (int i = 0; i < config1.count(); ++i) {
230 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
231 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
232#if SK_SUPPORT_GPU
233 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
234#endif
235 }
236}
237
bsalomonb4b4cf32016-04-04 05:56:59 -0700238
kkinnunen3e980c32015-12-23 01:33:00 -0800239DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
240 // These just list explicitly some properties of the system.
241 SkCommandLineFlags::StringArray config1 = make_string_array({
242 // Options are not canonized -> two same configs have a different tag.
243 "gpu(nvpr=true,dit=true)", "gpu(dit=true,nvpr=true)",
bsalomonb4b4cf32016-04-04 05:56:59 -0700244 // API native is alias for gl or gles, but it's not canonized -> different tag.
245 "gpu(api=native)", "gpu(api=gl)", "gpu(api=gles)", ""
246 // Default values are not canonized -> different tag.
247 "gpu", "gpu()", "gpu(samples=0)", "gpu(api=native,samples=0)"
kkinnunen3e980c32015-12-23 01:33:00 -0800248 });
249 SkCommandLineConfigArray configs;
250 ParseConfigs(config1, &configs);
251 REPORTER_ASSERT(reporter, configs.count() == config1.count());
252 for (int i = 0; i < config1.count(); ++i) {
253 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
254#if SK_SUPPORT_GPU
255 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
256 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
257#else
258 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
259#endif
260 }
261}
262DEF_TEST(ParseConfigs_ViaParsing, reporter) {
263 SkCommandLineFlags::StringArray config1 = make_string_array({
264 "a-b-c-8888",
265 "zz-qq-gpu",
266 "a-angle-gl"
267 });
268
269 SkCommandLineConfigArray configs;
270 ParseConfigs(config1, &configs);
271 const struct {
272 const char* backend;
273 const char* vias[3];
274 } expectedConfigs[] = {
275 {"8888", {"a", "b", "c"}},
276 {"gpu", {"zz", "qq", nullptr}},
277 {"angle-gl", {"a", nullptr, nullptr}} // The angle-gl tag is only tag that contains
278 // hyphen.
279 };
280 for (int i = 0; i < config1.count(); ++i) {
281 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
282 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
283 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
284 if (!expectedConfigs[i].vias[j]) {
285 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
286 break;
287 }
288 REPORTER_ASSERT(reporter,
289 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
290 }
291 }
292}
293
294DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
295 SkCommandLineFlags::StringArray config1 = make_string_array({
296 "zz-qq-gpu(api=gles)",
297 "a-gpu(samples=1",
298 "abc-def-angle-gl(samples=1)",
299 });
300
301 SkCommandLineConfigArray configs;
302 ParseConfigs(config1, &configs);
303 const struct {
304 const char* backend;
305 const char* vias[3];
306 } expectedConfigs[] = {
307#if SK_SUPPORT_GPU
308 {"gpu", {"zz", "qq", nullptr}},
309#else
310 {"gpu(api=gles)", {"zz", "qq", nullptr}},
311#endif
312 {"gpu(samples=1", {"a", nullptr, nullptr}}, // This is not extended form, but via still
313 // works as expected.
314 {"gl(samples=1)", {"abc", "def", "angle"}} // This is not extended form. Also
315 // angle-gl is not a "backend" in this case.
316 };
317 for (int i = 0; i < config1.count(); ++i) {
318 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
319 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
320 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
321 if (!expectedConfigs[i].vias[j]) {
322 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
323 static_cast<int>(j));
324 break;
325 }
326 REPORTER_ASSERT(reporter,
327 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
328 }
329 }
330#if SK_SUPPORT_GPU
331 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
332 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
333 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
334#endif
335}