kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1 | /* |
| 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" |
brianosman | b6095ae | 2016-06-16 13:32:51 -0700 | [diff] [blame] | 9 | #include "SkColorSpace.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 10 | #include "Test.h" |
| 11 | #include <initializer_list> |
| 12 | |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 13 | using sk_gpu_test::GrContextFactory; |
| 14 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 15 | namespace { |
| 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. |
| 24 | SkCommandLineFlags::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 | } |
| 32 | DEF_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() |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 45 | == GrContextFactory::kNativeGL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 46 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR() == false); |
| 47 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false); |
| 48 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0); |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 49 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorType() == kN32_SkColorType); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 50 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getColorSpace() == nullptr); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 51 | #endif |
| 52 | } |
| 53 | |
| 54 | DEF_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")); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 61 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 62 | 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")); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 66 | |
| 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")); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | DEF_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", |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 78 | "nonrendering", "null", "nullgpu", "nvpr16", "nvpr4", "nvprdit16", "nvprdit4", "pdf", |
halcanary | 94b87bd | 2016-04-04 06:12:15 -0700 | [diff] [blame] | 79 | "skp", "svg", "xps", "angle", "angle-gl", "commandbuffer", "mesa", "hwui", |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 80 | "gpuf16", "gpusrgb", "gl", "glnvpr4", "glnvprdit4", "glsrgb", "glmsaa4", "vk" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 81 | }); |
| 82 | |
| 83 | SkCommandLineConfigArray configs; |
| 84 | ParseConfigs(config1, &configs); |
| 85 | |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 86 | auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
| 87 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 88 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 89 | for (int i = 0; i < config1.count(); ++i) { |
| 90 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 91 | REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0); |
| 92 | } |
| 93 | #if SK_SUPPORT_GPU |
| 94 | REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()); |
| 95 | REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 96 | REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()); |
| 97 | REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()); |
| 98 | REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()); |
| 99 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getUseDIText()); |
| 100 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()); |
| 101 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 16); |
| 102 | REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 4); |
| 103 | REPORTER_ASSERT(reporter, !configs[9]->asConfigGpu()); |
| 104 | REPORTER_ASSERT(reporter, !configs[10]->asConfigGpu()); |
| 105 | REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()); |
| 106 | REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 16); |
| 107 | REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR()); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 108 | REPORTER_ASSERT(reporter, !configs[12]->asConfigGpu()->getUseDIText()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 109 | REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 4); |
| 110 | REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR()); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 111 | REPORTER_ASSERT(reporter, !configs[13]->asConfigGpu()->getUseDIText()); |
| 112 | REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getSamples() == 16); |
| 113 | REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseNVPR()); |
| 114 | REPORTER_ASSERT(reporter, configs[14]->asConfigGpu()->getUseDIText()); |
| 115 | REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getSamples() == 4); |
| 116 | REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseNVPR()); |
| 117 | REPORTER_ASSERT(reporter, configs[15]->asConfigGpu()->getUseDIText()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 118 | REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu()); |
| 119 | REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu()); |
| 120 | REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu()); |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 121 | REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu()); |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 122 | REPORTER_ASSERT(reporter, !configs[24]->asConfigGpu()); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 123 | REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorType() == kRGBA_F16_SkColorType); |
| 124 | REPORTER_ASSERT(reporter, configs[25]->asConfigGpu()->getColorSpace() == nullptr); |
| 125 | REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorType() == kN32_SkColorType); |
| 126 | REPORTER_ASSERT(reporter, configs[26]->asConfigGpu()->getColorSpace() == srgbColorSpace.get()); |
| 127 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 128 | #if SK_ANGLE |
| 129 | #ifdef SK_BUILD_FOR_WIN |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 130 | REPORTER_ASSERT(reporter, configs[20]->asConfigGpu()); |
| 131 | #else |
| 132 | REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu()); |
| 133 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 134 | REPORTER_ASSERT(reporter, configs[21]->asConfigGpu()); |
| 135 | #else |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 136 | REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 137 | REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu()); |
| 138 | #endif |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 139 | #if SK_COMMAND_BUFFER |
halcanary | 3c4521a | 2016-04-04 12:14:46 -0700 | [diff] [blame] | 140 | REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()); |
| 141 | #else |
| 142 | REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu()); |
| 143 | #endif |
| 144 | #if SK_MESA |
cdalton | c28afdb | 2016-03-29 20:05:07 -0700 | [diff] [blame] | 145 | REPORTER_ASSERT(reporter, configs[23]->asConfigGpu()); |
| 146 | #else |
| 147 | REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu()); |
| 148 | #endif |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 149 | REPORTER_ASSERT(reporter, configs[27]->asConfigGpu()); |
| 150 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()); |
| 151 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getSamples() == 4); |
| 152 | REPORTER_ASSERT(reporter, configs[28]->asConfigGpu()->getUseNVPR()); |
| 153 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()); |
| 154 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getSamples() == 4); |
| 155 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseNVPR()); |
| 156 | REPORTER_ASSERT(reporter, configs[29]->asConfigGpu()->getUseDIText()); |
| 157 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()); |
| 158 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorType() == kN32_SkColorType); |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 159 | REPORTER_ASSERT(reporter, configs[30]->asConfigGpu()->getColorSpace() == srgbColorSpace.get()); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 160 | REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()); |
| 161 | REPORTER_ASSERT(reporter, configs[31]->asConfigGpu()->getSamples() == 4); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 162 | #ifdef SK_VULKAN |
| 163 | REPORTER_ASSERT(reporter, configs[32]->asConfigGpu()); |
| 164 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 165 | #endif |
| 166 | } |
| 167 | |
| 168 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) { |
| 169 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
kkinnunen | e3c2f80 | 2015-12-29 08:57:32 -0800 | [diff] [blame] | 170 | "gpu(nvpr=true,dit=false)", |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 171 | "gpu(api=angle)", |
| 172 | "gpu(api=angle-gl)", |
| 173 | "gpu(api=mesa,samples=77)", |
| 174 | "gpu(dit=true,api=commandbuffer)", |
| 175 | "gpu()", |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 176 | "gpu(api=gles)", |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 177 | "gpu(api=gl)", |
| 178 | "gpu(api=vulkan)", |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 179 | }); |
| 180 | |
| 181 | SkCommandLineConfigArray configs; |
| 182 | ParseConfigs(config1, &configs); |
| 183 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 184 | for (int i = 0; i < config1.count(); ++i) { |
| 185 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 186 | } |
| 187 | #if SK_SUPPORT_GPU |
| 188 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 189 | GrContextFactory::kNativeGL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 190 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR()); |
kkinnunen | e3c2f80 | 2015-12-29 08:57:32 -0800 | [diff] [blame] | 191 | REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()->getUseDIText()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 192 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0); |
| 193 | #if SK_ANGLE |
| 194 | #ifdef SK_BUILD_FOR_WIN |
| 195 | REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 196 | GrContextFactory::kANGLE_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 197 | #else |
| 198 | REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 199 | #endif |
| 200 | REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 201 | GrContextFactory::kANGLE_GL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 202 | #else |
| 203 | REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 204 | REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu()); |
| 205 | #endif |
| 206 | #if SK_MESA |
| 207 | REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 208 | GrContextFactory::kMESA_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 209 | #else |
| 210 | REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu()); |
| 211 | #endif |
| 212 | #if SK_COMMAND_BUFFER |
| 213 | REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 214 | GrContextFactory::kCommandBuffer_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 215 | |
| 216 | #else |
| 217 | REPORTER_ASSERT(reporter, !configs[4]->asConfigGpu()); |
| 218 | #endif |
| 219 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 220 | GrContextFactory::kNativeGL_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 221 | REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR()); |
| 222 | REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText()); |
| 223 | REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0); |
| 224 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 225 | GrContextFactory::kGLES_ContextType); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 226 | REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR()); |
| 227 | REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText()); |
| 228 | REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 229 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getContextType() == |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 230 | GrContextFactory::kGL_ContextType); |
bsalomon | b8797bb | 2016-04-05 08:49:38 -0700 | [diff] [blame] | 231 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR()); |
| 232 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText()); |
| 233 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0); |
bsalomon | dc0fcd4 | 2016-04-11 14:21:33 -0700 | [diff] [blame] | 234 | #ifdef SK_VULKAN |
| 235 | REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getContextType() == |
| 236 | GrContextFactory::kVulkan_ContextType); |
| 237 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseNVPR()); |
| 238 | REPORTER_ASSERT(reporter, !configs[7]->asConfigGpu()->getUseDIText()); |
| 239 | REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 0); |
| 240 | #endif |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 241 | #endif |
| 242 | } |
| 243 | |
| 244 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) { |
| 245 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 246 | "gpu(nvpr=1)", // Number as bool. |
| 247 | "gpu(api=gl,)", // Trailing in comma. |
| 248 | "gpu(api=angle-glu)", // Unknown api. |
| 249 | "gpu(api=,samples=0)", // Empty api. |
| 250 | "gpu(samples=true)", // Value true as a number. |
| 251 | "gpu(samples=0,samples=0)", // Duplicate option key. |
| 252 | "gpu(,samples=0)", // Leading comma. |
| 253 | "gpu(samples=54", // Missing closing parenthesis. |
| 254 | ",,", |
| 255 | "gpu(", // Missing parenthesis. |
| 256 | "samples=54" // No backend. |
| 257 | "gpu(nvpr=true )", // Space. |
| 258 | }); |
| 259 | |
| 260 | SkCommandLineConfigArray configs; |
| 261 | ParseConfigs(config1, &configs); |
| 262 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 263 | for (int i = 0; i < config1.count(); ++i) { |
| 264 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 265 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i])); |
| 266 | #if SK_SUPPORT_GPU |
| 267 | REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu()); |
| 268 | #endif |
| 269 | } |
| 270 | } |
| 271 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 272 | DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) { |
| 273 | // These just list explicitly some properties of the system. |
| 274 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 275 | // Options are not canonized -> two same configs have a different tag. |
| 276 | "gpu(nvpr=true,dit=true)", "gpu(dit=true,nvpr=true)", |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 277 | "gpu(api=debug)", "gpu(api=gl)", "gpu(api=gles)", "" |
| 278 | "gpu", "gpu()", "gpu(samples=0)", "gpu(api=gles,samples=0)" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 279 | }); |
| 280 | SkCommandLineConfigArray configs; |
| 281 | ParseConfigs(config1, &configs); |
| 282 | REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 283 | for (int i = 0; i < config1.count(); ++i) { |
| 284 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 285 | #if SK_SUPPORT_GPU |
| 286 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu")); |
| 287 | REPORTER_ASSERT(reporter, configs[i]->asConfigGpu()); |
| 288 | #else |
| 289 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i])); |
| 290 | #endif |
| 291 | } |
| 292 | } |
| 293 | DEF_TEST(ParseConfigs_ViaParsing, reporter) { |
| 294 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 295 | "a-b-c-8888", |
| 296 | "zz-qq-gpu", |
| 297 | "a-angle-gl" |
| 298 | }); |
| 299 | |
| 300 | SkCommandLineConfigArray configs; |
| 301 | ParseConfigs(config1, &configs); |
| 302 | const struct { |
| 303 | const char* backend; |
| 304 | const char* vias[3]; |
| 305 | } expectedConfigs[] = { |
| 306 | {"8888", {"a", "b", "c"}}, |
| 307 | {"gpu", {"zz", "qq", nullptr}}, |
| 308 | {"angle-gl", {"a", nullptr, nullptr}} // The angle-gl tag is only tag that contains |
| 309 | // hyphen. |
| 310 | }; |
| 311 | for (int i = 0; i < config1.count(); ++i) { |
| 312 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 313 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend)); |
| 314 | for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) { |
| 315 | if (!expectedConfigs[i].vias[j]) { |
| 316 | REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j); |
| 317 | break; |
| 318 | } |
| 319 | REPORTER_ASSERT(reporter, |
| 320 | configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j])); |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) { |
| 326 | SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 327 | "zz-qq-gpu(api=gles)", |
| 328 | "a-gpu(samples=1", |
| 329 | "abc-def-angle-gl(samples=1)", |
| 330 | }); |
| 331 | |
| 332 | SkCommandLineConfigArray configs; |
| 333 | ParseConfigs(config1, &configs); |
| 334 | const struct { |
| 335 | const char* backend; |
| 336 | const char* vias[3]; |
| 337 | } expectedConfigs[] = { |
| 338 | #if SK_SUPPORT_GPU |
| 339 | {"gpu", {"zz", "qq", nullptr}}, |
| 340 | #else |
| 341 | {"gpu(api=gles)", {"zz", "qq", nullptr}}, |
| 342 | #endif |
| 343 | {"gpu(samples=1", {"a", nullptr, nullptr}}, // This is not extended form, but via still |
| 344 | // works as expected. |
| 345 | {"gl(samples=1)", {"abc", "def", "angle"}} // This is not extended form. Also |
| 346 | // angle-gl is not a "backend" in this case. |
| 347 | }; |
| 348 | for (int i = 0; i < config1.count(); ++i) { |
| 349 | REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 350 | REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfigs[i].backend)); |
| 351 | for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].vias)); ++j) { |
| 352 | if (!expectedConfigs[i].vias[j]) { |
| 353 | REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == |
| 354 | static_cast<int>(j)); |
| 355 | break; |
| 356 | } |
| 357 | REPORTER_ASSERT(reporter, |
| 358 | configs[i]->getViaParts()[j].equals(expectedConfigs[i].vias[j])); |
| 359 | } |
| 360 | } |
| 361 | #if SK_SUPPORT_GPU |
| 362 | REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()); |
| 363 | REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 364 | REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu()); |
| 365 | #endif |
| 366 | } |