blob: 6f5c64aa2e93d9f6518e4960c0c9a9634919005f [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"
brianosmanb6095ae2016-06-16 13:32:51 -07009#include "SkColorSpace.h"
kkinnunen3e980c32015-12-23 01:33:00 -080010#include "Test.h"
11#include <initializer_list>
12
bsalomon3724e572016-03-30 18:56:19 -070013using sk_gpu_test::GrContextFactory;
14
kkinnunen3e980c32015-12-23 01:33:00 -080015namespace {
16// The code
17// SkCommandLineFlags::StringArray FLAGS_config1 = make_string_array({"a", "b"})
18// can be used to construct string array that one gets with command line flags.
19// For example, the call above is equivalent of
20// DEFINE_string(config1, "a b", "");
21// in cases where the default command line flag value ("a b") is used.
22// make_string_array can be used to construct StringArray strings that have spaces in
23// them.
24SkCommandLineFlags::StringArray make_string_array(std::initializer_list<const char*> strings) {
25 SkTArray<SkString> array;
26 for (auto& s : strings) {
27 array.push_back(SkString(s));
28 }
29 return SkCommandLineFlags::StringArray(array);
30}
31}
32DEF_TEST(ParseConfigs_Gpu, reporter) {
33 // Parses a normal config and returns correct "tag".
34 // Gpu config defaults work.
35 SkCommandLineFlags::StringArray config1 = make_string_array({"gpu"});
36 SkCommandLineConfigArray configs;
37 ParseConfigs(config1, &configs);
38
39 REPORTER_ASSERT(reporter, configs.count() == 1);
40 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu"));
41 REPORTER_ASSERT(reporter, configs[0]->getViaParts().count() == 0);
42#if SK_SUPPORT_GPU
43 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
44 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType()
bsalomon85b4b532016-04-05 11:06:27 -070045 == GrContextFactory::kNativeGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -080046 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR() == false);
csmartdaltone0d36292016-07-29 08:14:20 -070047 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseInstanced() == false);
kkinnunen3e980c32015-12-23 01:33:00 -080048 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false);
49 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
brianosmand93c1202016-03-10 07:49:08 -080050 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kN32_SkColorType);
brianosmanb109b8c2016-06-16 13:03:24 -070051 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorSpace() == nullptr);
kkinnunen3e980c32015-12-23 01:33:00 -080052#endif
53}
54
55DEF_TEST(ParseConfigs_OutParam, reporter) {
56 // Clears the out parameter.
57 SkCommandLineFlags::StringArray config1 = make_string_array({"gpu"});
58 SkCommandLineConfigArray configs;
59 ParseConfigs(config1, &configs);
60 REPORTER_ASSERT(reporter, configs.count() == 1);
61 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu"));
bsalomonb8797bb2016-04-05 08:49:38 -070062
kkinnunen3e980c32015-12-23 01:33:00 -080063 SkCommandLineFlags::StringArray config2 = make_string_array({"8888"});
64 ParseConfigs(config2, &configs);
65 REPORTER_ASSERT(reporter, configs.count() == 1);
66 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("8888"));
bsalomonb8797bb2016-04-05 08:49:38 -070067
68 SkCommandLineFlags::StringArray config3 = make_string_array({"gl"});
69 ParseConfigs(config3, &configs);
70 REPORTER_ASSERT(reporter, configs.count() == 1);
71 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gl"));
kkinnunen3e980c32015-12-23 01:33:00 -080072}
73
74DEF_TEST(ParseConfigs_DefaultConfigs, reporter) {
75 // Parses all default configs and returns correct "tag".
76
77 SkCommandLineFlags::StringArray config1 = make_string_array({
78 "565", "8888", "debug", "gpu", "gpudebug", "gpudft", "gpunull", "msaa16", "msaa4",
csmartdaltone0d36292016-07-29 08:14:20 -070079 "nonrendering", "null", "nullgpu", "nvpr16", "nvpr4", "nvprdit16", "nvprdit4", "pdf", "skp",
80 "svg", "xps", "angle", "angle-gl", "commandbuffer", "mesa", "hwui", "gpuf16", "gpusrgb",
81 "gl", "glnvpr4", "glnvprdit4", "glsrgb", "glmsaa4", "vk", "glinst", "glinst4", "glinstdit4",
82 "glinst16", "glinstdit16", "esinst", "esinst4", "esinstdit4"
kkinnunen3e980c32015-12-23 01:33:00 -080083 });
84
85 SkCommandLineConfigArray configs;
86 ParseConfigs(config1, &configs);
87
brianosmanb109b8c2016-06-16 13:03:24 -070088 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
89
kkinnunen3e980c32015-12-23 01:33:00 -080090 REPORTER_ASSERT(reporter, configs.count() == config1.count());
91 for (int i = 0; i < config1.count(); ++i) {
92 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
93 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0);
94 }
95#if SK_SUPPORT_GPU
96 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu());
97 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
98 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu());
99 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu());
100 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu());
101 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getUseDIText());
102 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu());
103 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 16);
104 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 4);
105 REPORTER_ASSERT(reporter, !configs[9]->asConfigGpu());
106 REPORTER_ASSERT(reporter, !configs[10]->asConfigGpu());
107 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu());
108 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 16);
109 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700110 REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800111 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 4);
112 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR());
cdaltonc28afdb2016-03-29 20:05:07 -0700113 REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu()->getUseDIText());
114 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 16);
115 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR());
116 REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText());
117 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getSamples() == 4);
118 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseNVPR());
119 REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800120 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu());
121 REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu());
122 REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu());
cdaltonc28afdb2016-03-29 20:05:07 -0700123 REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu());
halcanary3c4521a2016-04-04 12:14:46 -0700124 REPORTER_ASSERT(reporter, !configs[24]->asConfigGpu());
brianosmanb109b8c2016-06-16 13:03:24 -0700125 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType);
brianosmanefded512016-07-26 08:11:50 -0700126 REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
brianosmanb109b8c2016-06-16 13:03:24 -0700127 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType() == kN32_SkColorType);
128 REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
csmartdaltone0d36292016-07-29 08:14:20 -0700129 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getContextType() ==
130 GrContextFactory::kGL_ContextType);
131 REPORTER_ASSERT(reporter, configs[33]->asConfigGpu()->getUseInstanced());
132 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getContextType() ==
133 GrContextFactory::kGL_ContextType);
134 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getUseInstanced());
135 REPORTER_ASSERT(reporter, configs[34]->asConfigGpu()->getSamples() == 4);
136 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getContextType() ==
137 GrContextFactory::kGL_ContextType);
138 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getUseInstanced());
139 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getUseDIText());
140 REPORTER_ASSERT(reporter, configs[35]->asConfigGpu()->getSamples() == 4);
141 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getContextType() ==
142 GrContextFactory::kGL_ContextType);
143 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getUseInstanced());
144 REPORTER_ASSERT(reporter, configs[36]->asConfigGpu()->getSamples() == 16);
145 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getContextType() ==
146 GrContextFactory::kGL_ContextType);
147 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseInstanced());
148 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getUseDIText());
149 REPORTER_ASSERT(reporter, configs[37]->asConfigGpu()->getSamples() == 16);
150 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getContextType() ==
151 GrContextFactory::kGLES_ContextType);
152 REPORTER_ASSERT(reporter, configs[38]->asConfigGpu()->getUseInstanced());
153 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getContextType() ==
154 GrContextFactory::kGLES_ContextType);
155 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getUseInstanced());
156 REPORTER_ASSERT(reporter, configs[39]->asConfigGpu()->getSamples() == 4);
157 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getContextType() ==
158 GrContextFactory::kGLES_ContextType);
159 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getUseInstanced());
160 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getUseDIText());
161 REPORTER_ASSERT(reporter, configs[40]->asConfigGpu()->getSamples() == 4);
brianosmanb109b8c2016-06-16 13:03:24 -0700162
kkinnunen3e980c32015-12-23 01:33:00 -0800163#if SK_ANGLE
164#ifdef SK_BUILD_FOR_WIN
halcanary3c4521a2016-04-04 12:14:46 -0700165 REPORTER_ASSERT(reporter, configs[20]->asConfigGpu());
166#else
167 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu());
168#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800169 REPORTER_ASSERT(reporter, configs[21]->asConfigGpu());
170#else
halcanary3c4521a2016-04-04 12:14:46 -0700171 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu());
kkinnunen3e980c32015-12-23 01:33:00 -0800172 REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu());
173#endif
cdaltonc28afdb2016-03-29 20:05:07 -0700174#if SK_COMMAND_BUFFER
halcanary3c4521a2016-04-04 12:14:46 -0700175 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu());
176#else
177 REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu());
178#endif
179#if SK_MESA
cdaltonc28afdb2016-03-29 20:05:07 -0700180 REPORTER_ASSERT(reporter, configs[23]->asConfigGpu());
181#else
182 REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu());
183#endif
bsalomonb8797bb2016-04-05 08:49:38 -0700184 REPORTER_ASSERT(reporter, configs[27]->asConfigGpu());
185 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu());
186 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getSamples() == 4);
187 REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseNVPR());
188 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu());
189 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getSamples() == 4);
190 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseNVPR());
191 REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseDIText());
192 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu());
193 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorType() == kN32_SkColorType);
brianosmanb109b8c2016-06-16 13:03:24 -0700194 REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace() == srgbColorSpace.get());
bsalomonb8797bb2016-04-05 08:49:38 -0700195 REPORTER_ASSERT(reporter, configs[31]->asConfigGpu());
196 REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()->getSamples() == 4);
bsalomondc0fcd42016-04-11 14:21:33 -0700197#ifdef SK_VULKAN
198 REPORTER_ASSERT(reporter, configs[32]->asConfigGpu());
199#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800200#endif
201}
202
203DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) {
204 SkCommandLineFlags::StringArray config1 = make_string_array({
kkinnunene3c2f802015-12-29 08:57:32 -0800205 "gpu(nvpr=true,dit=false)",
kkinnunen3e980c32015-12-23 01:33:00 -0800206 "gpu(api=angle)",
207 "gpu(api=angle-gl)",
208 "gpu(api=mesa,samples=77)",
209 "gpu(dit=true,api=commandbuffer)",
210 "gpu()",
bsalomonb8797bb2016-04-05 08:49:38 -0700211 "gpu(api=gles)",
bsalomondc0fcd42016-04-11 14:21:33 -0700212 "gpu(api=gl)",
213 "gpu(api=vulkan)",
kkinnunen3e980c32015-12-23 01:33:00 -0800214 });
215
216 SkCommandLineConfigArray configs;
217 ParseConfigs(config1, &configs);
218 REPORTER_ASSERT(reporter, configs.count() == config1.count());
219 for (int i = 0; i < config1.count(); ++i) {
220 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
221 }
222#if SK_SUPPORT_GPU
223 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700224 GrContextFactory::kNativeGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800225 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR());
kkinnunene3c2f802015-12-29 08:57:32 -0800226 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText());
kkinnunen3e980c32015-12-23 01:33:00 -0800227 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0);
228#if SK_ANGLE
229#ifdef SK_BUILD_FOR_WIN
230 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700231 GrContextFactory::kANGLE_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800232#else
233 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
234#endif
235 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700236 GrContextFactory::kANGLE_GL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800237#else
238 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
239 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
240#endif
241#if SK_MESA
242 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700243 GrContextFactory::kMESA_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800244#else
245 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu());
246#endif
247#if SK_COMMAND_BUFFER
248 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700249 GrContextFactory::kCommandBuffer_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800250
251#else
252 REPORTER_ASSERT(reporter, !configs[4]->asConfigGpu());
253#endif
254 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700255 GrContextFactory::kNativeGL_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800256 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR());
257 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText());
258 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0);
259 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700260 GrContextFactory::kGLES_ContextType);
kkinnunen3e980c32015-12-23 01:33:00 -0800261 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR());
262 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText());
263 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0);
bsalomonb8797bb2016-04-05 08:49:38 -0700264 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() ==
bsalomon85b4b532016-04-05 11:06:27 -0700265 GrContextFactory::kGL_ContextType);
bsalomonb8797bb2016-04-05 08:49:38 -0700266 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
267 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
268 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0);
bsalomondc0fcd42016-04-11 14:21:33 -0700269#ifdef SK_VULKAN
270 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() ==
271 GrContextFactory::kVulkan_ContextType);
272 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR());
273 REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText());
274 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0);
275#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800276#endif
277}
278
279DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) {
280 SkCommandLineFlags::StringArray config1 = make_string_array({
281 "gpu(nvpr=1)", // Number as bool.
282 "gpu(api=gl,)", // Trailing in comma.
283 "gpu(api=angle-glu)", // Unknown api.
284 "gpu(api=,samples=0)", // Empty api.
285 "gpu(samples=true)", // Value true as a number.
286 "gpu(samples=0,samples=0)", // Duplicate option key.
287 "gpu(,samples=0)", // Leading comma.
288 "gpu(samples=54", // Missing closing parenthesis.
289 ",,",
290 "gpu(", // Missing parenthesis.
291 "samples=54" // No backend.
292 "gpu(nvpr=true )", // Space.
293 });
294
295 SkCommandLineConfigArray configs;
296 ParseConfigs(config1, &configs);
297 REPORTER_ASSERT(reporter, configs.count() == config1.count());
298 for (int i = 0; i < config1.count(); ++i) {
299 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
300 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
301#if SK_SUPPORT_GPU
302 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu());
303#endif
304 }
305}
306
kkinnunen3e980c32015-12-23 01:33:00 -0800307DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) {
308 // These just list explicitly some properties of the system.
309 SkCommandLineFlags::StringArray config1 = make_string_array({
310 // Options are not canonized -> two same configs have a different tag.
311 "gpu(nvpr=true,dit=true)", "gpu(dit=true,nvpr=true)",
bsalomon85b4b532016-04-05 11:06:27 -0700312 "gpu(api=debug)", "gpu(api=gl)", "gpu(api=gles)", ""
313 "gpu", "gpu()", "gpu(samples=0)", "gpu(api=gles,samples=0)"
kkinnunen3e980c32015-12-23 01:33:00 -0800314 });
315 SkCommandLineConfigArray configs;
316 ParseConfigs(config1, &configs);
317 REPORTER_ASSERT(reporter, configs.count() == config1.count());
318 for (int i = 0; i < config1.count(); ++i) {
319 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
320#if SK_SUPPORT_GPU
321 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu"));
322 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu());
323#else
324 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i]));
325#endif
326 }
327}
328DEF_TEST(ParseConfigs_ViaParsing, reporter) {
329 SkCommandLineFlags::StringArray config1 = make_string_array({
330 "a-b-c-8888",
331 "zz-qq-gpu",
332 "a-angle-gl"
333 });
334
335 SkCommandLineConfigArray configs;
336 ParseConfigs(config1, &configs);
337 const struct {
338 const char* backend;
339 const char* vias[3];
340 } expectedConfigs[] = {
341 {"8888", {"a", "b", "c"}},
342 {"gpu", {"zz", "qq", nullptr}},
brianosman577e0252016-07-27 09:21:51 -0700343#if SK_ANGLE
344 { "gpu",{ "a", nullptr, nullptr } } // With SK_ANGLE, angle-gl becomes gpu(api=angle-gl)
345#else
346 { "angle-gl",{ "a", nullptr, nullptr } } // The angle-gl tag is only tag that contains
347 // hyphen.
348#endif
kkinnunen3e980c32015-12-23 01:33:00 -0800349 };
350 for (int i = 0; i < config1.count(); ++i) {
351 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
352 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
353 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
354 if (!expectedConfigs[i].vias[j]) {
355 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j);
356 break;
357 }
358 REPORTER_ASSERT(reporter,
359 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
360 }
361 }
362}
363
364DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) {
365 SkCommandLineFlags::StringArray config1 = make_string_array({
366 "zz-qq-gpu(api=gles)",
367 "a-gpu(samples=1",
368 "abc-def-angle-gl(samples=1)",
369 });
370
371 SkCommandLineConfigArray configs;
372 ParseConfigs(config1, &configs);
373 const struct {
374 const char* backend;
375 const char* vias[3];
376 } expectedConfigs[] = {
377#if SK_SUPPORT_GPU
378 {"gpu", {"zz", "qq", nullptr}},
379#else
380 {"gpu(api=gles)", {"zz", "qq", nullptr}},
381#endif
382 {"gpu(samples=1", {"a", nullptr, nullptr}}, // This is not extended form, but via still
383 // works as expected.
384 {"gl(samples=1)", {"abc", "def", "angle"}} // This is not extended form. Also
385 // angle-gl is not a "backend" in this case.
386 };
387 for (int i = 0; i < config1.count(); ++i) {
388 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i]));
389 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend));
390 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) {
391 if (!expectedConfigs[i].vias[j]) {
392 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() ==
393 static_cast<int>(j));
394 break;
395 }
396 REPORTER_ASSERT(reporter,
397 configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j]));
398 }
399 }
400#if SK_SUPPORT_GPU
401 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu());
402 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu());
403 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu());
404#endif
405}