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