blob: 9c030ed9ec3ebd6ace84de1b50d81af8ea1bfea2 [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
12namespace {
13// The code
14// SkCommandLineFlags::StringArray FLAGS_config1 = make_string_array({"a", "b"})
15// can be used to construct string array that one gets with command line flags.
16// For example, the call above is equivalent of
17// DEFINE_string(config1, "a b", "");
18// in cases where the default command line flag value ("a b") is used.
19// make_string_array can be used to construct StringArray strings that have spaces in
20// them.
21SkCommandLineFlags::StringArray make_string_array(std::initializer_list<const char*> strings) {
22 SkTArray<SkString> array;
23 for (auto& s : strings) {
24 array.push_back(SkString(s));
25 }
26 return SkCommandLineFlags::StringArray(array);
27}
28}
29DEF_TEST(ParseConfigs_Gpu, reporter) {
30 // Parses a normal config and returns correct "tag".
31 // Gpu config defaults work.
32 SkCommandLineFlags::StringArray config1 = make_string_array({"gpu"});
33 SkCommandLineConfigArray configs;
34 ParseConfigs(config1, &configs);
35
36 REPORTER_ASSERT(reporter, configs.count() == 1);
37 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu"));
38 REPORTER_ASSERT(reporter, configs[0]->getViaParts().count() == 0);
39#if SK_SUPPORT_GPU
40 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
41 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType()
42 == GrContextFactory::kNative_GLContextType);
43 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR() == false);
44 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false);
45 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
brianosmand93c1202016-03-10 07:49:08 -080046 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kN32_SkColorType);
47 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getProfileType()
48 == kLinear_SkColorProfileType);
kkinnunen3e980c32015-12-23 01:33:00 -080049#endif
50}
51
52DEF_TEST(ParseConfigs_OutParam, reporter) {
53 // Clears the out parameter.
54 SkCommandLineFlags::StringArray config1 = make_string_array({"gpu"});
55 SkCommandLineConfigArray configs;
56 ParseConfigs(config1, &configs);
57 REPORTER_ASSERT(reporter, configs.count() == 1);
58 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu"));
59 SkCommandLineFlags::StringArray config2 = make_string_array({"8888"});
60 ParseConfigs(config2, &configs);
61 REPORTER_ASSERT(reporter, configs.count() == 1);
62 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("8888"));
63}
64
65DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
66 // Parses all default configs and returns correct "tag".
67
68 SkCommandLineFlags::StringArray config1 = make_string_array({
69 "565", "8888", "debug", "gpu", "gpudebug", "gpudft", "gpunull", "msaa16", "msaa4",
cdaltonc28afdb2016-03-29 20:05:07 -070070 "nonrendering", "null", "nullgpu", "nvpr16", "nvpr4", "nvprdit16", "nvprdit4", "pdf",
71 "pdf_poppler", "skp", "svg", "xps", "angle", "angle-gl", "commandbuffer", "mesa", "hwui",
brianosman8e478812016-03-10 09:47:56 -080072 "gpuf16", "gpusrgb"
kkinnunen3e980c32015-12-23 01:33:00 -080073 });
74
75 SkCommandLineConfigArray configs;
76 ParseConfigs(config1, &configs);
77
78 REPORTER_ASSERT(reporter, configs.count() == config1.count());
79 for (int i = 0; i < config1.count(); ++i) {
80 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
81 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
82 }
83#if SK_SUPPORT_GPU
84 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
85 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
86 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
87 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
88 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu());
89 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getUseDIText());
90 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu());
91 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 16);
92 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 4);
93 REPORTER_ASSERT(reporter, !configs[9]->asConfigGpu());
94 REPORTER_ASSERT(reporter, !configs[10]->asConfigGpu());
95 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu());
96 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 16);
97 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -070098 REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -080099 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 4);
100 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700101 REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu()->getUseDIText());
102 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 16);
103 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR());
104 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText());
105 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getSamples() == 4);
106 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseNVPR());
107 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800108 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
109 REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu());
110 REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu());
cdaltonc28afdb2016-03-29 20:05:07 -0700111 REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu());
112 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu());
113 REPORTER_ASSERT(reporter, !configs[25]->asConfigGpu());
114 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType()
brianosmand93c1202016-03-10 07:49:08 -0800115 == kRGBA_F16_SkColorType);
cdaltonc28afdb2016-03-29 20:05:07 -0700116 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getProfileType()
brianosmand93c1202016-03-10 07:49:08 -0800117 == kLinear_SkColorProfileType);
cdaltonc28afdb2016-03-29 20:05:07 -0700118 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getColorType()
brianosmand93c1202016-03-10 07:49:08 -0800119 == kN32_SkColorType);
cdaltonc28afdb2016-03-29 20:05:07 -0700120 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()->getProfileType()
brianosmand93c1202016-03-10 07:49:08 -0800121 == kSRGB_SkColorProfileType);
kkinnunen3e980c32015-12-23 01:33:00 -0800122#if SK_ANGLE
123#ifdef SK_BUILD_FOR_WIN
kkinnunen3e980c32015-12-23 01:33:00 -0800124 REPORTER_ASSERT(reporter, configs[21]->asConfigGpu());
125#else
126 REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu());
127#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800128 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu());
129#else
cdaltonc28afdb2016-03-29 20:05:07 -0700130 REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800131 REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu());
132#endif
cdaltonc28afdb2016-03-29 20:05:07 -0700133#if SK_COMMAND_BUFFER
134 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu());
135#else
136 REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu());
137#endif
138#if SK_MESA
139 REPORTER_ASSERT(reporter, configs[24]->asConfigGpu());
140#else
141 REPORTER_ASSERT(reporter, !configs[24]->asConfigGpu());
142#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800143#endif
144}
145
146DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
147 SkCommandLineFlags::StringArray config1 = make_string_array({
kkinnunene3c2f802015-12-29 08:57:32 -0800148 "gpu(nvpr=true,dit=false)",
kkinnunen3e980c32015-12-23 01:33:00 -0800149 "gpu(api=angle)",
150 "gpu(api=angle-gl)",
151 "gpu(api=mesa,samples=77)",
152 "gpu(dit=true,api=commandbuffer)",
153 "gpu()",
154 "gpu(api=gles)"
155 });
156
157 SkCommandLineConfigArray configs;
158 ParseConfigs(config1, &configs);
159 REPORTER_ASSERT(reporter, configs.count() == config1.count());
160 for (int i = 0; i < config1.count(); ++i) {
161 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
162 }
163#if SK_SUPPORT_GPU
164 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
165 GrContextFactory::kNative_GLContextType);
166 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
kkinnunene3c2f802015-12-29 08:57:32 -0800167 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800168 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
169#if SK_ANGLE
170#ifdef SK_BUILD_FOR_WIN
171 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
172 GrContextFactory::kANGLE_GLContextType);
173#else
174 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
175#endif
176 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
177 GrContextFactory::kANGLE_GL_GLContextType);
178#else
179 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
180 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
181#endif
182#if SK_MESA
183 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() ==
184 GrContextFactory::kMESA_GLContextType);
185#else
186 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
187#endif
188#if SK_COMMAND_BUFFER
189 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
kkinnunenf655e932016-03-03 07:39:48 -0800190 GrContextFactory::kCommandBuffer_GLContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800191
192#else
193 REPORTER_ASSERT(reporter, !configs[4]->asConfigGpu());
194#endif
195 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
196 GrContextFactory::kNative_GLContextType);
197 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
198 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
199 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0);
200 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
201 GrContextFactory::kGLES_GLContextType);
202 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
203 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
204 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0);
205
206#endif
207}
208
209DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
210 SkCommandLineFlags::StringArray config1 = make_string_array({
211 "gpu(nvpr=1)", // Number as bool.
212 "gpu(api=gl,)", // Trailing in comma.
213 "gpu(api=angle-glu)", // Unknown api.
214 "gpu(api=,samples=0)", // Empty api.
215 "gpu(samples=true)", // Value true as a number.
216 "gpu(samples=0,samples=0)", // Duplicate option key.
217 "gpu(,samples=0)", // Leading comma.
218 "gpu(samples=54", // Missing closing parenthesis.
219 ",,",
220 "gpu(", // Missing parenthesis.
221 "samples=54" // No backend.
222 "gpu(nvpr=true )", // Space.
223 });
224
225 SkCommandLineConfigArray configs;
226 ParseConfigs(config1, &configs);
227 REPORTER_ASSERT(reporter, configs.count() == config1.count());
228 for (int i = 0; i < config1.count(); ++i) {
229 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
230 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
231#if SK_SUPPORT_GPU
232 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
233#endif
234 }
235}
236
237
238DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
239 // These just list explicitly some properties of the system.
240 SkCommandLineFlags::StringArray config1 = make_string_array({
241 // Options are not canonized -> two same configs have a different tag.
242 "gpu(nvpr=true,dit=true)", "gpu(dit=true,nvpr=true)",
243 // API native is alias for gl or gles, but it's not canonized -> different tag.
244 "gpu(api=native)", "gpu(api=gl)", "gpu(api=gles)", ""
245 // Default values are not canonized -> different tag.
246 "gpu", "gpu()", "gpu(samples=0)", "gpu(api=native,samples=0)"
247 });
248 SkCommandLineConfigArray configs;
249 ParseConfigs(config1, &configs);
250 REPORTER_ASSERT(reporter, configs.count() == config1.count());
251 for (int i = 0; i < config1.count(); ++i) {
252 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
253#if SK_SUPPORT_GPU
254 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
255 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
256#else
257 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
258#endif
259 }
260}
261DEF_TEST(ParseConfigs_ViaParsing, reporter) {
262 SkCommandLineFlags::StringArray config1 = make_string_array({
263 "a-b-c-8888",
264 "zz-qq-gpu",
265 "a-angle-gl"
266 });
267
268 SkCommandLineConfigArray configs;
269 ParseConfigs(config1, &configs);
270 const struct {
271 const char* backend;
272 const char* vias[3];
273 } expectedConfigs[] = {
274 {"8888", {"a", "b", "c"}},
275 {"gpu", {"zz", "qq", nullptr}},
276 {"angle-gl", {"a", nullptr, nullptr}} // The angle-gl tag is only tag that contains
277 // hyphen.
278 };
279 for (int i = 0; i < config1.count(); ++i) {
280 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
281 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
282 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
283 if (!expectedConfigs[i].vias[j]) {
284 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
285 break;
286 }
287 REPORTER_ASSERT(reporter,
288 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
289 }
290 }
291}
292
293DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
294 SkCommandLineFlags::StringArray config1 = make_string_array({
295 "zz-qq-gpu(api=gles)",
296 "a-gpu(samples=1",
297 "abc-def-angle-gl(samples=1)",
298 });
299
300 SkCommandLineConfigArray configs;
301 ParseConfigs(config1, &configs);
302 const struct {
303 const char* backend;
304 const char* vias[3];
305 } expectedConfigs[] = {
306#if SK_SUPPORT_GPU
307 {"gpu", {"zz", "qq", nullptr}},
308#else
309 {"gpu(api=gles)", {"zz", "qq", nullptr}},
310#endif
311 {"gpu(samples=1", {"a", nullptr, nullptr}}, // This is not extended form, but via still
312 // works as expected.
313 {"gl(samples=1)", {"abc", "def", "angle"}} // This is not extended form. Also
314 // angle-gl is not a "backend" in this case.
315 };
316 for (int i = 0; i < config1.count(); ++i) {
317 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
318 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
319 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
320 if (!expectedConfigs[i].vias[j]) {
321 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
322 static_cast<int>(j));
323 break;
324 }
325 REPORTER_ASSERT(reporter,
326 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
327 }
328 }
329#if SK_SUPPORT_GPU
330 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
331 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
332 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
333#endif
334}