OLD | NEW |
(Empty) | |
| 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 |
| 12 namespace { |
| 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 spac
es in |
| 20 // them. |
| 21 SkCommandLineFlags::StringArray make_string_array(std::initializer_list<const ch
ar*> strings) { |
| 22 SkTArray<SkString> array; |
| 23 for (auto& s : strings) { |
| 24 array.push_back(SkString(s)); |
| 25 } |
| 26 return SkCommandLineFlags::StringArray(array); |
| 27 } |
| 28 } |
| 29 DEF_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); |
| 46 #endif |
| 47 } |
| 48 |
| 49 DEF_TEST(ParseConfigs_OutParam, reporter) { |
| 50 // Clears the out parameter. |
| 51 SkCommandLineFlags::StringArray config1 = make_string_array({"gpu"}); |
| 52 SkCommandLineConfigArray configs; |
| 53 ParseConfigs(config1, &configs); |
| 54 REPORTER_ASSERT(reporter, configs.count() == 1); |
| 55 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu")); |
| 56 SkCommandLineFlags::StringArray config2 = make_string_array({"8888"}); |
| 57 ParseConfigs(config2, &configs); |
| 58 REPORTER_ASSERT(reporter, configs.count() == 1); |
| 59 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("8888")); |
| 60 } |
| 61 |
| 62 DEF_TEST(ParseConfigs_DefaultConfigs, reporter) { |
| 63 // Parses all default configs and returns correct "tag". |
| 64 |
| 65 SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 66 "565", "8888", "debug", "gpu", "gpudebug", "gpudft", "gpunull", "msaa16"
, "msaa4", |
| 67 "nonrendering", "null", "nullgpu", "nvprmsaa16", "nvprmsaa4", "pdf", "pd
f_poppler", |
| 68 "skp", "svg", "xps", "angle", "angle-gl", "commandbuffer", "mesa", "hwui
" |
| 69 }); |
| 70 |
| 71 SkCommandLineConfigArray configs; |
| 72 ParseConfigs(config1, &configs); |
| 73 |
| 74 REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 75 for (int i = 0; i < config1.count(); ++i) { |
| 76 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 77 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0); |
| 78 } |
| 79 #if SK_SUPPORT_GPU |
| 80 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()); |
| 81 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 82 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()); |
| 83 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()); |
| 84 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()); |
| 85 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getUseDIText()); |
| 86 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()); |
| 87 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 16); |
| 88 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 4); |
| 89 REPORTER_ASSERT(reporter, !configs[9]->asConfigGpu()); |
| 90 REPORTER_ASSERT(reporter, !configs[10]->asConfigGpu()); |
| 91 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()); |
| 92 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 16); |
| 93 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR()); |
| 94 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 4); |
| 95 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR()); |
| 96 REPORTER_ASSERT(reporter, !configs[14]->asConfigGpu()); |
| 97 REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu()); |
| 98 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu()); |
| 99 REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu()); |
| 100 REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu()); |
| 101 REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu()); |
| 102 #if SK_ANGLE |
| 103 #ifdef SK_BUILD_FOR_WIN |
| 104 REPORTER_ASSERT(reporter, configs[19]->asConfigGpu()); |
| 105 #else |
| 106 REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu()); |
| 107 #endif |
| 108 REPORTER_ASSERT(reporter, configs[20]->asConfigGpu()); |
| 109 #else |
| 110 REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu()); |
| 111 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu()); |
| 112 #endif |
| 113 #if SK_COMMAND_BUFFER |
| 114 REPORTER_ASSERT(reporter, configs[21]->asConfigGpu()); |
| 115 #else |
| 116 REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu()); |
| 117 #endif |
| 118 #if SK_MESA |
| 119 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()); |
| 120 #else |
| 121 REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu()); |
| 122 #endif |
| 123 #endif |
| 124 } |
| 125 |
| 126 DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) { |
| 127 SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 128 "gpu(nvpr=true,dit=true)", |
| 129 "gpu(api=angle)", |
| 130 "gpu(api=angle-gl)", |
| 131 "gpu(api=mesa,samples=77)", |
| 132 "gpu(dit=true,api=commandbuffer)", |
| 133 "gpu()", |
| 134 "gpu(api=gles)" |
| 135 }); |
| 136 |
| 137 SkCommandLineConfigArray configs; |
| 138 ParseConfigs(config1, &configs); |
| 139 REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 140 for (int i = 0; i < config1.count(); ++i) { |
| 141 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 142 } |
| 143 #if SK_SUPPORT_GPU |
| 144 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getContextType() == |
| 145 GrContextFactory::kNative_GLContextType); |
| 146 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR()); |
| 147 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText()); |
| 148 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0); |
| 149 #if SK_ANGLE |
| 150 #ifdef SK_BUILD_FOR_WIN |
| 151 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getContextType() == |
| 152 GrContextFactory::kANGLE_GLContextType); |
| 153 #else |
| 154 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 155 #endif |
| 156 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getContextType() == |
| 157 GrContextFactory::kANGLE_GL_GLContextType); |
| 158 #else |
| 159 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 160 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu()); |
| 161 #endif |
| 162 #if SK_MESA |
| 163 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getContextType() == |
| 164 GrContextFactory::kMESA_GLContextType); |
| 165 #else |
| 166 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu()); |
| 167 #endif |
| 168 #if SK_COMMAND_BUFFER |
| 169 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getContextType() == |
| 170 GrContextFactory::kCommandBuffer_GLContextType); |
| 171 |
| 172 #else |
| 173 REPORTER_ASSERT(reporter, !configs[4]->asConfigGpu()); |
| 174 #endif |
| 175 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getContextType() == |
| 176 GrContextFactory::kNative_GLContextType); |
| 177 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR()); |
| 178 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText()); |
| 179 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0); |
| 180 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getContextType() == |
| 181 GrContextFactory::kGLES_GLContextType); |
| 182 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR()); |
| 183 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText()); |
| 184 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0); |
| 185 |
| 186 #endif |
| 187 } |
| 188 |
| 189 DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) { |
| 190 SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 191 "gpu(nvpr=1)", // Number as bool. |
| 192 "gpu(api=gl,)", // Trailing in comma. |
| 193 "gpu(api=angle-glu)", // Unknown api. |
| 194 "gpu(api=,samples=0)", // Empty api. |
| 195 "gpu(samples=true)", // Value true as a number. |
| 196 "gpu(samples=0,samples=0)", // Duplicate option key. |
| 197 "gpu(,samples=0)", // Leading comma. |
| 198 "gpu(samples=54", // Missing closing parenthesis. |
| 199 ",,", |
| 200 "gpu(", // Missing parenthesis. |
| 201 "samples=54" // No backend. |
| 202 "gpu(nvpr=true )", // Space. |
| 203 }); |
| 204 |
| 205 SkCommandLineConfigArray configs; |
| 206 ParseConfigs(config1, &configs); |
| 207 REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 208 for (int i = 0; i < config1.count(); ++i) { |
| 209 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 210 #if SK_SUPPORT_GPU |
| 211 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu()); |
| 212 #endif |
| 213 } |
| 214 } |
| 215 |
| 216 |
| 217 DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) { |
| 218 // These just list explicitly some properties of the system. |
| 219 SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 220 // Options are not canonized -> two same configs have a different tag. |
| 221 "gpu(nvpr=true,dit=true)", "gpu(dit=true,nvpr=true)", |
| 222 // API native is alias for gl or gles, but it's not canonized -> differe
nt tag. |
| 223 "gpu(api=native)", "gpu(api=gl)", "gpu(api=gles)", "" |
| 224 // Default values are not canonized -> different tag. |
| 225 "gpu", "gpu()", "gpu(samples=0)", "gpu(api=native,samples=0)" |
| 226 }); |
| 227 SkCommandLineConfigArray configs; |
| 228 ParseConfigs(config1, &configs); |
| 229 REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 230 for (int i = 0; i < config1.count(); ++i) { |
| 231 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 232 #if SK_SUPPORT_GPU |
| 233 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu()); |
| 234 #endif |
| 235 } |
| 236 } |
| 237 DEF_TEST(ParseConfigs_ViaParsing, reporter) { |
| 238 SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 239 "a-b-c-8888", |
| 240 "zz-qq-gpu", |
| 241 "a-angle-gl" |
| 242 }); |
| 243 |
| 244 SkCommandLineConfigArray configs; |
| 245 ParseConfigs(config1, &configs); |
| 246 const struct { |
| 247 const char* tag; |
| 248 const char* vias[3]; |
| 249 } expectedConfigs[] = { |
| 250 {"8888", {"a", "b", "c"}}, |
| 251 {"gpu", {"zz", "qq", nullptr}}, |
| 252 {"angle-gl", {"a", nullptr, nullptr}} // The angle-gl tag is only tag t
hat contains |
| 253 // hyphen. |
| 254 }; |
| 255 for (int i = 0; i < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs)); ++i)
{ |
| 256 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedConfigs[i]
.tag)); |
| 257 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].v
ias)); ++j) { |
| 258 if (!expectedConfigs[i].vias[j]) { |
| 259 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j
); |
| 260 break; |
| 261 } |
| 262 REPORTER_ASSERT(reporter, |
| 263 configs[i]->getViaParts()[j].equals(expectedConfigs[
i].vias[j])); |
| 264 } |
| 265 } |
| 266 } |
| 267 |
| 268 DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) { |
| 269 SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 270 "zz-qq-gpu(api=gles)", |
| 271 "a-gpu(samples=1", |
| 272 "abc-def-angle-gl(samples=1)", |
| 273 }); |
| 274 |
| 275 SkCommandLineConfigArray configs; |
| 276 ParseConfigs(config1, &configs); |
| 277 const struct { |
| 278 const char* tag; |
| 279 const char* vias[3]; |
| 280 } expectedConfigs[] = { |
| 281 {"gpu(api=gles)", {"zz", "qq", nullptr}}, |
| 282 {"gpu(samples=1", {"a", nullptr, nullptr}}, // This is not extended form
, but via still |
| 283 // works as expected. |
| 284 {"gl(samples=1)", {"abc", "def", "angle"}} // This is not extended form
. |
| 285 // Also angle-gl is not a "t
ag" in this case. |
| 286 }; |
| 287 for (int i = 0; i < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs)); ++i)
{ |
| 288 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedConfigs[i]
.tag)); |
| 289 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].v
ias)); ++j) { |
| 290 if (!expectedConfigs[i].vias[j]) { |
| 291 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == |
| 292 static_cast<int>(j)); |
| 293 break; |
| 294 } |
| 295 REPORTER_ASSERT(reporter, |
| 296 configs[i]->getViaParts()[j].equals(expectedConfigs[
i].vias[j])); |
| 297 } |
| 298 } |
| 299 #if SK_SUPPORT_GPU |
| 300 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()); |
| 301 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 302 #endif |
| 303 } |
OLD | NEW |