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 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i])); |
| 211 #if SK_SUPPORT_GPU |
| 212 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu()); |
| 213 #endif |
| 214 } |
| 215 } |
| 216 |
| 217 |
| 218 DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) { |
| 219 // These just list explicitly some properties of the system. |
| 220 SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 221 // Options are not canonized -> two same configs have a different tag. |
| 222 "gpu(nvpr=true,dit=true)", "gpu(dit=true,nvpr=true)", |
| 223 // API native is alias for gl or gles, but it's not canonized -> differe
nt tag. |
| 224 "gpu(api=native)", "gpu(api=gl)", "gpu(api=gles)", "" |
| 225 // Default values are not canonized -> different tag. |
| 226 "gpu", "gpu()", "gpu(samples=0)", "gpu(api=native,samples=0)" |
| 227 }); |
| 228 SkCommandLineConfigArray configs; |
| 229 ParseConfigs(config1, &configs); |
| 230 REPORTER_ASSERT(reporter, configs.count() == config1.count()); |
| 231 for (int i = 0; i < config1.count(); ++i) { |
| 232 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 233 #if SK_SUPPORT_GPU |
| 234 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals("gpu")); |
| 235 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu()); |
| 236 #else |
| 237 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(config1[i])); |
| 238 #endif |
| 239 } |
| 240 } |
| 241 DEF_TEST(ParseConfigs_ViaParsing, reporter) { |
| 242 SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 243 "a-b-c-8888", |
| 244 "zz-qq-gpu", |
| 245 "a-angle-gl" |
| 246 }); |
| 247 |
| 248 SkCommandLineConfigArray configs; |
| 249 ParseConfigs(config1, &configs); |
| 250 const struct { |
| 251 const char* backend; |
| 252 const char* vias[3]; |
| 253 } expectedConfigs[] = { |
| 254 {"8888", {"a", "b", "c"}}, |
| 255 {"gpu", {"zz", "qq", nullptr}}, |
| 256 {"angle-gl", {"a", nullptr, nullptr}} // The angle-gl tag is only tag t
hat contains |
| 257 // hyphen. |
| 258 }; |
| 259 for (int i = 0; i < config1.count(); ++i) { |
| 260 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 261 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfig
s[i].backend)); |
| 262 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].v
ias)); ++j) { |
| 263 if (!expectedConfigs[i].vias[j]) { |
| 264 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == j
); |
| 265 break; |
| 266 } |
| 267 REPORTER_ASSERT(reporter, |
| 268 configs[i]->getViaParts()[j].equals(expectedConfigs[
i].vias[j])); |
| 269 } |
| 270 } |
| 271 } |
| 272 |
| 273 DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) { |
| 274 SkCommandLineFlags::StringArray config1 = make_string_array({ |
| 275 "zz-qq-gpu(api=gles)", |
| 276 "a-gpu(samples=1", |
| 277 "abc-def-angle-gl(samples=1)", |
| 278 }); |
| 279 |
| 280 SkCommandLineConfigArray configs; |
| 281 ParseConfigs(config1, &configs); |
| 282 const struct { |
| 283 const char* backend; |
| 284 const char* vias[3]; |
| 285 } expectedConfigs[] = { |
| 286 #if SK_SUPPORT_GPU |
| 287 {"gpu", {"zz", "qq", nullptr}}, |
| 288 #else |
| 289 {"gpu(api=gles)", {"zz", "qq", nullptr}}, |
| 290 #endif |
| 291 {"gpu(samples=1", {"a", nullptr, nullptr}}, // This is not extended form
, but via still |
| 292 // works as expected. |
| 293 {"gl(samples=1)", {"abc", "def", "angle"}} // This is not extended form
. Also |
| 294 // angle-gl is not a "backen
d" in this case. |
| 295 }; |
| 296 for (int i = 0; i < config1.count(); ++i) { |
| 297 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(config1[i])); |
| 298 REPORTER_ASSERT(reporter, configs[i]->getBackend().equals(expectedConfig
s[i].backend)); |
| 299 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(expectedConfigs[i].v
ias)); ++j) { |
| 300 if (!expectedConfigs[i].vias[j]) { |
| 301 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == |
| 302 static_cast<int>(j)); |
| 303 break; |
| 304 } |
| 305 REPORTER_ASSERT(reporter, |
| 306 configs[i]->getViaParts()[j].equals(expectedConfigs[
i].vias[j])); |
| 307 } |
| 308 } |
| 309 #if SK_SUPPORT_GPU |
| 310 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()); |
| 311 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); |
| 312 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu()); |
| 313 #endif |
| 314 } |
OLD | NEW |