Chromium Code Reviews| 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 | |
| 11 DEF_TEST(ParseConfigs_Gpu, reporter) { | |
| 12 // Parses a normal config and returs correct "tag". | |
|
bsalomon
2015/12/02 23:22:42
returns
Kimmo Kinnunen
2015/12/04 14:26:18
Done.
| |
| 13 // Gpu config defaults work. | |
| 14 DEFINE_string(config1, "gpu", ""); | |
| 15 SkCommandLineConfigArray configs; | |
| 16 ParseConfigs(FLAGS_config1, &configs); | |
| 17 | |
| 18 REPORTER_ASSERT(reporter, configs.count() == 1); | |
| 19 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu")); | |
| 20 REPORTER_ASSERT(reporter, configs[0]->getViaParts().count() == 0); | |
| 21 #if SK_SUPPORT_GPU | |
| 22 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()); | |
| 23 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getAPI() == SkCommandLi neConfigGpu::kNative_API); | |
| 24 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR() == false); | |
| 25 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText() == false ); | |
| 26 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0); | |
| 27 #endif | |
| 28 } | |
| 29 | |
| 30 DEF_TEST(ParseConfigs_OutParam, reporter) { | |
| 31 // Clears the out parameter. | |
| 32 DEFINE_string(config1, "gpu", ""); | |
| 33 SkCommandLineConfigArray configs; | |
| 34 ParseConfigs(FLAGS_config1, &configs); | |
| 35 REPORTER_ASSERT(reporter, configs.count() == 1); | |
| 36 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("gpu")); | |
| 37 DEFINE_string(config2, "8888", ""); | |
| 38 ParseConfigs(FLAGS_config2, &configs); | |
| 39 REPORTER_ASSERT(reporter, configs.count() == 1); | |
| 40 REPORTER_ASSERT(reporter, configs[0]->getTag().equals("8888")); | |
| 41 } | |
| 42 | |
| 43 DEF_TEST(ParseConfigs_DefaultConfigs, reporter) { | |
| 44 // Parses all default configs and returns correct "tag". | |
| 45 | |
| 46 DEFINE_string(config1, "565 8888 debug gpu gpudebug gpudft gpunull " | |
| 47 "msaa16 msaa4 nonrendering null nullgpu nvprmsaa16 nvprmsaa4 " | |
| 48 "pdf pdf_poppler skp svg xps angle angle-gl commandbuffer " | |
| 49 "mesa hwui", ""); | |
| 50 | |
| 51 SkCommandLineConfigArray configs; | |
| 52 ParseConfigs(FLAGS_config1, &configs); | |
| 53 | |
| 54 const char* expectedConfigs[] = { | |
| 55 "565", "8888", "debug", "gpu", "gpudebug", "gpudft", "gpunull", "msaa16" , "msaa4", | |
| 56 "nonrendering", "null", "nullgpu", "nvprmsaa16", "nvprmsaa4", "pdf", "pd f_poppler", | |
| 57 "skp", "svg", "xps", "angle", "angle-gl", "commandbuffer", "mesa", "hwui " | |
| 58 }; | |
| 59 REPORTER_ASSERT(reporter, configs.count() == SK_ARRAY_COUNT(expectedConfigs) ); | |
| 60 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedConfigs); ++i) { | |
| 61 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedConfigs[i] )); | |
| 62 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == 0); | |
| 63 } | |
| 64 #if SK_SUPPORT_GPU | |
| 65 REPORTER_ASSERT(reporter, !configs[0]->asConfigGpu()); | |
| 66 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); | |
| 67 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()); | |
| 68 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()); | |
| 69 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()); | |
| 70 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getUseDIText()); | |
| 71 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()); | |
| 72 REPORTER_ASSERT(reporter, configs[7]->asConfigGpu()->getSamples() == 16); | |
| 73 REPORTER_ASSERT(reporter, configs[8]->asConfigGpu()->getSamples() == 4); | |
| 74 REPORTER_ASSERT(reporter, !configs[9]->asConfigGpu()); | |
| 75 REPORTER_ASSERT(reporter, configs[10]->asConfigGpu()); | |
| 76 REPORTER_ASSERT(reporter, configs[11]->asConfigGpu()); | |
| 77 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getSamples() == 16); | |
| 78 REPORTER_ASSERT(reporter, configs[12]->asConfigGpu()->getUseNVPR()); | |
| 79 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getSamples() == 4); | |
| 80 REPORTER_ASSERT(reporter, configs[13]->asConfigGpu()->getUseNVPR()); | |
| 81 REPORTER_ASSERT(reporter, !configs[14]->asConfigGpu()); | |
| 82 REPORTER_ASSERT(reporter, !configs[15]->asConfigGpu()); | |
| 83 REPORTER_ASSERT(reporter, !configs[16]->asConfigGpu()); | |
| 84 REPORTER_ASSERT(reporter, !configs[17]->asConfigGpu()); | |
| 85 REPORTER_ASSERT(reporter, !configs[18]->asConfigGpu()); | |
| 86 REPORTER_ASSERT(reporter, !configs[23]->asConfigGpu()); | |
| 87 #if SK_ANGLE | |
| 88 REPORTER_ASSERT(reporter, configs[19]->asConfigGpu()); | |
| 89 REPORTER_ASSERT(reporter, configs[20]->asConfigGpu()); | |
| 90 #else | |
| 91 REPORTER_ASSERT(reporter, !configs[19]->asConfigGpu()); | |
| 92 REPORTER_ASSERT(reporter, !configs[20]->asConfigGpu()); | |
| 93 #endif | |
| 94 #if SK_COMMAND_BUFFER | |
| 95 REPORTER_ASSERT(reporter, configs[21]->asConfigGpu()); | |
| 96 #else | |
| 97 REPORTER_ASSERT(reporter, !configs[21]->asConfigGpu()); | |
| 98 #endif | |
| 99 #if SK_MESA | |
| 100 REPORTER_ASSERT(reporter, configs[22]->asConfigGpu()); | |
| 101 #else | |
| 102 REPORTER_ASSERT(reporter, !configs[22]->asConfigGpu()); | |
| 103 #endif | |
| 104 #endif | |
| 105 } | |
| 106 | |
| 107 DEF_TEST(ParseConfigs_ExtendedGpuConfigsCorrect, reporter) { | |
| 108 DEFINE_string(config1, "gpu(nvpr=true,dit=true) gpu(api=angle) gpu(api=angle -gl) " | |
| 109 "gpu(api=mesa,samples=77) gpu(dit=true,api=commandbuffer) gpu( ) gpu(api=gles)", ""); | |
| 110 | |
| 111 SkCommandLineConfigArray configs; | |
| 112 ParseConfigs(FLAGS_config1, &configs); | |
| 113 const char* expectedTags[] = { | |
| 114 "gpu(nvpr=true,dit=true)", | |
| 115 "gpu(api=angle)", | |
| 116 "gpu(api=angle-gl)", | |
| 117 "gpu(api=mesa,samples=77)", | |
| 118 "gpu(dit=true,api=commandbuffer)", | |
| 119 "gpu()", | |
| 120 "gpu(api=gles)" | |
| 121 }; | |
| 122 REPORTER_ASSERT(reporter, configs.count() == SK_ARRAY_COUNT(expectedTags)); | |
| 123 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedTags); ++i) { | |
| 124 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedTags[i])); | |
| 125 } | |
| 126 #if SK_SUPPORT_GPU | |
| 127 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getAPI() == | |
| 128 SkCommandLineConfigGpu::kNative_API); | |
| 129 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseNVPR()); | |
| 130 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getUseDIText()); | |
| 131 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()->getSamples() == 0); | |
| 132 #if SK_ANGLE | |
| 133 REPORTER_ASSERT(reporter, configs[1]->asConfigGpu()->getAPI() == | |
| 134 SkCommandLineConfigGpu::kANGLE_API); | |
| 135 REPORTER_ASSERT(reporter, configs[2]->asConfigGpu()->getAPI() == | |
| 136 SkCommandLineConfigGpu::kANGLE_GL_API); | |
| 137 #else | |
| 138 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); | |
| 139 REPORTER_ASSERT(reporter, !configs[2]->asConfigGpu()); | |
| 140 #endif | |
| 141 #if SK_MESA | |
| 142 REPORTER_ASSERT(reporter, configs[3]->asConfigGpu()->getAPI() == | |
| 143 SkCommandLineConfigGpu::kMESA_API); | |
| 144 #else | |
| 145 REPORTER_ASSERT(reporter, !configs[3]->asConfigGpu()); | |
| 146 #endif | |
| 147 #if SK_COMMAND_BUFFER | |
| 148 REPORTER_ASSERT(reporter, configs[4]->asConfigGpu()->getAPI() == | |
| 149 SkCommandLineConfigGpu::kCommandBuffer_API); | |
| 150 | |
| 151 #else | |
| 152 REPORTER_ASSERT(reporter, !configs[4]->asConfigGpu()); | |
| 153 #endif | |
| 154 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getAPI() == | |
| 155 SkCommandLineConfigGpu::kNative_API); | |
| 156 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseNVPR()); | |
| 157 REPORTER_ASSERT(reporter, !configs[5]->asConfigGpu()->getUseDIText()); | |
| 158 REPORTER_ASSERT(reporter, configs[5]->asConfigGpu()->getSamples() == 0); | |
| 159 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getAPI() == | |
| 160 SkCommandLineConfigGpu::kGLES_API); | |
| 161 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseNVPR()); | |
| 162 REPORTER_ASSERT(reporter, !configs[6]->asConfigGpu()->getUseDIText()); | |
| 163 REPORTER_ASSERT(reporter, configs[6]->asConfigGpu()->getSamples() == 0); | |
| 164 | |
| 165 #endif | |
| 166 } | |
| 167 | |
| 168 DEF_TEST(ParseConfigs_ExtendedGpuConfigsIncorrect, reporter) { | |
| 169 DEFINE_string(config1, "gpu(nvpr=1) gpu(api=gl,) gpu(api=angle-glu) " | |
| 170 "gpu(api=,samples=0) gpu(samples=true) gpu(samples=0,samples=0 ) " | |
| 171 "gpu(,samples=0) gpu(samples=54 ,, gpu( samples=54", ""); | |
| 172 | |
| 173 SkCommandLineConfigArray configs; | |
| 174 ParseConfigs(FLAGS_config1, &configs); | |
| 175 const char* expectedTags[] = { | |
| 176 "gpu(nvpr=1)", // Number as bool. | |
| 177 "gpu(api=gl,)", // Trailing in comma. | |
| 178 "gpu(api=angle-glu)", // Unknown api. | |
| 179 "gpu(api=,samples=0)", // Empty api. | |
| 180 "gpu(samples=true)", // Value true as a number. | |
| 181 "gpu(samples=0,samples=0)", // Duplicate option key. | |
| 182 "gpu(,samples=0)", // Leading comma. | |
| 183 "gpu(samples=54", // Missing closing parenthesis. | |
| 184 ",,", | |
| 185 "gpu(", // Missing parenthesis. | |
| 186 "samples=54" // No backend. | |
| 187 }; | |
| 188 REPORTER_ASSERT(reporter, configs.count() == SK_ARRAY_COUNT(expectedTags)); | |
| 189 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedTags); ++i) { | |
| 190 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedTags[i])); | |
| 191 #if SK_SUPPORT_GPU | |
| 192 REPORTER_ASSERT(reporter, !configs[i]->asConfigGpu()); | |
| 193 #endif | |
| 194 } | |
| 195 } | |
| 196 | |
| 197 | |
| 198 DEF_TEST(ParseConfigs_ExtendedGpuConfigsSurprises, reporter) { | |
| 199 // These just list explicitly some properties of the system. | |
| 200 DEFINE_string(config1, "gpu(nvpr=true,dit=true) gpu(dit=true,nvpr=true) " | |
| 201 "gpu(api=native) gpu(api=gl) gpu(api=gles) " | |
| 202 "gpu gpu() gpu(samples=0) gpu(api=native,samples=0)", ""); | |
| 203 | |
| 204 SkCommandLineConfigArray configs; | |
| 205 ParseConfigs(FLAGS_config1, &configs); | |
| 206 const char* expectedTags[] = { | |
| 207 // Options are not canonized -> two same configs have a different tag. | |
| 208 "gpu(nvpr=true,dit=true)", "gpu(dit=true,nvpr=true)", | |
| 209 // API native is alias for gl or gles, but it's not canonized -> differe nt tag. | |
| 210 "gpu(api=native)", "gpu(api=gl)", "gpu(api=gles)", "" | |
| 211 // Default values are not canonized -> different tag. | |
| 212 "gpu", "gpu()", "gpu(samples=0)", "gpu(api=native,samples=0)" | |
| 213 }; | |
| 214 REPORTER_ASSERT(reporter, configs.count() == SK_ARRAY_COUNT(expectedTags)); | |
| 215 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedTags); ++i) { | |
| 216 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedTags[i])); | |
| 217 #if SK_SUPPORT_GPU | |
| 218 REPORTER_ASSERT(reporter, configs[i]->asConfigGpu()); | |
| 219 #endif | |
| 220 } | |
| 221 } | |
| 222 DEF_TEST(ParseConfigs_ViaParsing, reporter) { | |
| 223 DEFINE_string(config1, "a-b-c-33-8888 zz-qq-gpu a-angle-gl", ""); | |
| 224 | |
| 225 SkCommandLineConfigArray configs; | |
| 226 ParseConfigs(FLAGS_config1, &configs); | |
| 227 const struct { | |
| 228 const char* tag; | |
| 229 const char* vias[3]; | |
| 230 } expectedConfigs[] = { | |
| 231 { "8888", {"a", "b", "c"}}, | |
| 232 { "gpu", {"zz", "qq", nullptr}}, | |
| 233 { "angle-gl", {"a", nullptr, nullptr } } // The angle-gl tag is only tag that contains | |
| 234 // hyphen. | |
| 235 }; | |
| 236 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedConfigs); ++i) { | |
| 237 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedConfigs[i] .tag)); | |
| 238 for (size_t j = 0; j < SK_ARRAY_COUNT(expectedConfigs[i].vias); ++j) { | |
| 239 if (!expectedConfigs[i].vias[j]) { | |
| 240 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == s tatic_cast<int>(j)); | |
| 241 break; | |
| 242 } | |
| 243 REPORTER_ASSERT(reporter, configs[i]->getViaParts()[j].equals(expect edConfigs[i].vias[j])); | |
| 244 } | |
| 245 } | |
| 246 } | |
| 247 | |
| 248 DEF_TEST(ParseConfigs_ViaParsingExtendedForm, reporter) { | |
| 249 DEFINE_string(config1, "zz-qq-gpu(api=gles) a-gpu(samples=1", ""); | |
| 250 | |
| 251 SkCommandLineConfigArray configs; | |
| 252 ParseConfigs(FLAGS_config1, &configs); | |
| 253 const struct { | |
| 254 const char* tag; | |
| 255 const char* vias[3]; | |
| 256 } expectedConfigs[] = { | |
| 257 { "gpu(api=gles)", {"zz", "qq", nullptr}}, | |
| 258 { "gpu(samples=1", {"a", nullptr, nullptr } } // This is not extended fo rm, but via still | |
| 259 // works as expected. | |
| 260 }; | |
| 261 for (size_t i = 0; i < SK_ARRAY_COUNT(expectedConfigs); ++i) { | |
| 262 REPORTER_ASSERT(reporter, configs[i]->getTag().equals(expectedConfigs[i] .tag)); | |
| 263 for (size_t j = 0; j < SK_ARRAY_COUNT(expectedConfigs[i].vias); ++j) { | |
| 264 if (!expectedConfigs[i].vias[j]) { | |
| 265 REPORTER_ASSERT(reporter, configs[i]->getViaParts().count() == s tatic_cast<int>(j)); | |
| 266 break; | |
| 267 } | |
| 268 REPORTER_ASSERT(reporter, configs[i]->getViaParts()[j].equals(expect edConfigs[i].vias[j])); | |
| 269 } | |
| 270 } | |
| 271 #if SK_SUPPORT_GPU | |
| 272 REPORTER_ASSERT(reporter, configs[0]->asConfigGpu()); | |
| 273 REPORTER_ASSERT(reporter, !configs[1]->asConfigGpu()); | |
| 274 #endif | |
| 275 } | |
| OLD | NEW |