Chromium Code Reviews| Index: gm/gmmain.cpp |
| diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp |
| index 958a511eb7446dc07e12313b6b73684508aca76c..328f3c04414b4a362e7291fcba35484a0fdbb5a6 100644 |
| --- a/gm/gmmain.cpp |
| +++ b/gm/gmmain.cpp |
| @@ -1767,41 +1767,12 @@ bool prepare_subdirectories(const char *root, bool useFileHierarchy, |
| return true; |
| } |
| -int tool_main(int argc, char** argv); |
| -int tool_main(int argc, char** argv) { |
| - |
| -#if SK_ENABLE_INST_COUNT |
| - gPrintInstCount = true; |
| -#endif |
| - |
| - SkGraphics::Init(); |
| - // we don't need to see this during a run |
| - gSkSuppressFontCachePurgeSpew = true; |
| - |
| - setSystemPreferences(); |
| - GMMain gmmain; |
| - |
| - SkTDArray<size_t> configs; |
| +bool parse_flags_configs(SkTDArray<size_t>* outConfigs, |
|
edisonn
2013/08/02 12:32:41
static
ducky
2013/08/02 18:14:38
Fixed as of latest patchset last night, after I re
|
| + GrContextFactory* grFactory) { |
| SkTDArray<size_t> excludeConfigs; |
| - bool userConfig = false; |
| - |
| - SkString usage; |
| - usage.printf("Run the golden master tests.\n"); |
| - SkCommandLineFlags::SetUsage(usage.c_str()); |
| - SkCommandLineFlags::Parse(argc, argv); |
| - |
| - gmmain.fUseFileHierarchy = FLAGS_hierarchy; |
| - gmmain.fWriteChecksumBasedFilenames = FLAGS_writeChecksumBasedFilenames; |
| - if (FLAGS_mismatchPath.count() == 1) { |
| - gmmain.fMismatchPath = FLAGS_mismatchPath[0]; |
| - } |
| - if (FLAGS_missingExpectationsPath.count() == 1) { |
| - gmmain.fMissingExpectationsPath = FLAGS_missingExpectationsPath[0]; |
| - } |
| for (int i = 0; i < FLAGS_config.count(); i++) { |
| const char* config = FLAGS_config[i]; |
| - userConfig = true; |
| bool exclude = false; |
| if (*config == kExcludeConfigChar) { |
| exclude = true; |
| @@ -1812,23 +1783,22 @@ int tool_main(int argc, char** argv) { |
| if (exclude) { |
| *excludeConfigs.append() = index; |
| } else { |
| - appendUnique<size_t>(&configs, index); |
| + appendUnique<size_t>(outConfigs, index); |
| } |
| } else if (0 == strcmp(kDefaultsConfigStr, config)) { |
| + if (exclude) { |
| + gm_fprintf(stderr, "%c%s is not allowed.\n", |
| + kExcludeConfigChar, kDefaultsConfigStr); |
| + return false; |
| + } |
| for (size_t c = 0; c < SK_ARRAY_COUNT(gRec); ++c) { |
| if (gRec[c].fRunByDefault) { |
| - if (exclude) { |
| - gm_fprintf(stderr, "%c%s is not allowed.\n", |
| - kExcludeConfigChar, kDefaultsConfigStr); |
| - return -1; |
| - } else { |
| - appendUnique<size_t>(&configs, c); |
| - } |
| + appendUnique<size_t>(outConfigs, c); |
| } |
| } |
| } else { |
| gm_fprintf(stderr, "unrecognized config %s\n", config); |
| - return -1; |
| + return false; |
| } |
| } |
| @@ -1838,147 +1808,216 @@ int tool_main(int argc, char** argv) { |
| *excludeConfigs.append() = index; |
| } else { |
| gm_fprintf(stderr, "unrecognized excludeConfig %s\n", FLAGS_excludeConfig[i]); |
| - return -1; |
| + return false; |
| } |
| } |
| - int moduloRemainder = -1; |
| - int moduloDivisor = -1; |
| + if (outConfigs->count() == 0) { |
| + // if no config is specified by user, add the defaults |
| + for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| + if (gRec[i].fRunByDefault) { |
| + *outConfigs->append() = i; |
| + } |
| + } |
| + } |
| + // now remove any explicitly excluded configs |
| + for (int i = 0; i < excludeConfigs.count(); ++i) { |
| + int index = outConfigs->find(excludeConfigs[i]); |
| + if (index >= 0) { |
| + outConfigs->remove(index); |
| + // now assert that there was only one copy in configs[] |
| + SkASSERT(outConfigs->find(excludeConfigs[i]) < 0); |
| + } |
| + } |
| - if (FLAGS_modulo.count() == 2) { |
| - moduloRemainder = atoi(FLAGS_modulo[0]); |
| - moduloDivisor = atoi(FLAGS_modulo[1]); |
| - if (moduloRemainder < 0 || moduloDivisor <= 0 || moduloRemainder >= moduloDivisor) { |
| - gm_fprintf(stderr, "invalid modulo values."); |
| - return -1; |
| + if (grFactory != NULL) { |
| + for (int i = 0; i < outConfigs->count(); ++i) { |
| + size_t index = (*outConfigs)[i]; |
| + if (kGPU_Backend == gRec[index].fBackend) { |
| + GrContext* ctx = grFactory->get(gRec[index].fGLContextType); |
| + if (NULL == ctx) { |
| + gm_fprintf(stderr, "GrContext could not be created for config %s." |
| + " Config will be skipped.\n", gRec[index].fName); |
| + outConfigs->remove(i); |
| + --i; |
| + continue; |
| + } |
| + if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) { |
| + gm_fprintf(stderr, "Sample count (%d) of config %s is not supported." |
| + " Config will be skipped.\n", |
| + gRec[index].fSampleCnt, gRec[index].fName); |
| + outConfigs->remove(i); |
| + --i; |
| + } |
| + } |
| } |
| } |
| + if (outConfigs->isEmpty()) { |
| + gm_fprintf(stderr, "No configs to run."); |
| + return false; |
| + } |
| + |
| + // now show the user the set of configs that will be run. |
| + SkString configStr("These configs will be run: "); |
| + // show the user the config that will run. |
| + for (int i = 0; i < outConfigs->count(); ++i) { |
| + configStr.appendf("%s%s", gRec[(*outConfigs)[i]].fName, |
| + (i == outConfigs->count() - 1) ? "\n" : " "); |
|
edisonn
2013/08/02 12:32:41
make it (i < outConfigs->count()) ? " " : "");
an
ducky
2013/08/02 18:14:38
Done. It now just adds a space all the time, since
|
| + } |
| + gm_fprintf(stdout, "%s", configStr.c_str()); |
| + |
| + return true; |
| +} |
| + |
| +bool parse_flags_ignore_error_types(ErrorCombination* outErrorTypes) { |
|
edisonn
2013/08/02 12:32:41
static
ducky
2013/08/02 18:14:38
Done.
|
| if (FLAGS_ignoreErrorTypes.count() > 0) { |
| - gmmain.fIgnorableErrorTypes = ErrorCombination(); |
| + *outErrorTypes = ErrorCombination(); |
| for (int i = 0; i < FLAGS_ignoreErrorTypes.count(); i++) { |
| ErrorType type; |
| const char *name = FLAGS_ignoreErrorTypes[i]; |
| if (!getErrorTypeByName(name, &type)) { |
| gm_fprintf(stderr, "cannot find ErrorType with name '%s'\n", name); |
| - return -1; |
| + return false; |
| } else { |
| - gmmain.fIgnorableErrorTypes.add(type); |
| + outErrorTypes->add(type); |
| } |
| } |
| } |
| + return true; |
| +} |
| -#if SK_SUPPORT_GPU |
| +bool parse_flags_modulo(int* moduloRemainder, int* moduloDivisor) { |
|
edisonn
2013/08/02 12:32:41
make it static, otherwise you might get a warning
ducky
2013/08/02 18:14:38
Done.
|
| + if (FLAGS_modulo.count() == 2) { |
| + *moduloRemainder = atoi(FLAGS_modulo[0]); |
| + *moduloDivisor = atoi(FLAGS_modulo[1]); |
| + if (*moduloRemainder < 0 || *moduloDivisor <= 0 || |
| + *moduloRemainder >= *moduloDivisor) { |
| + gm_fprintf(stderr, "invalid modulo values."); |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| + |
| +bool parse_flags_gpu_cache(int* sizeBytes, int* sizeCount) { |
|
edisonn
2013/08/02 12:32:41
static
ducky
2013/08/02 18:14:38
Done.
|
| if (FLAGS_gpuCacheSize.count() > 0) { |
| if (FLAGS_gpuCacheSize.count() != 2) { |
| gm_fprintf(stderr, "--gpuCacheSize requires two arguments\n"); |
| - return -1; |
| + return false; |
| } |
| - gGpuCacheSizeBytes = atoi(FLAGS_gpuCacheSize[0]); |
| - gGpuCacheSizeCount = atoi(FLAGS_gpuCacheSize[1]); |
| + *sizeBytes = atoi(FLAGS_gpuCacheSize[0]); |
| + *sizeCount = atoi(FLAGS_gpuCacheSize[1]); |
| } else { |
| - gGpuCacheSizeBytes = DEFAULT_CACHE_VALUE; |
| - gGpuCacheSizeCount = DEFAULT_CACHE_VALUE; |
| + *sizeBytes = DEFAULT_CACHE_VALUE; |
| + *sizeCount = DEFAULT_CACHE_VALUE; |
| } |
| -#endif |
| + return true; |
| +} |
| - SkTDArray<SkScalar> tileGridReplayScales; |
| - *tileGridReplayScales.append() = SK_Scalar1; // By default only test at scale 1.0 |
| +bool parse_tile_grid_replay_scales(SkTDArray<SkScalar>* outScales) { |
|
edisonn
2013/08/02 12:32:41
static
ducky
2013/08/02 18:14:38
Done.
|
| + *outScales->append() = SK_Scalar1; // By default only test at scale 1.0 |
| if (FLAGS_tileGridReplayScales.count() > 0) { |
| - tileGridReplayScales.reset(); |
| + outScales->reset(); |
| for (int i = 0; i < FLAGS_tileGridReplayScales.count(); i++) { |
| double val = atof(FLAGS_tileGridReplayScales[i]); |
| if (0 < val) { |
| - *tileGridReplayScales.append() = SkDoubleToScalar(val); |
| + *outScales->append() = SkDoubleToScalar(val); |
| } |
| } |
| - if (0 == tileGridReplayScales.count()) { |
| + if (0 == outScales->count()) { |
| // Should have at least one scale |
| gm_fprintf(stderr, "--tileGridReplayScales requires at least one scale.\n"); |
| - return -1; |
| + return false; |
| } |
| } |
| + return true; |
| +} |
| - if (!userConfig) { |
| - // if no config is specified by user, add the defaults |
| - for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| - if (gRec[i].fRunByDefault) { |
| - *configs.append() = i; |
| +bool parse_read_path(SkAutoTUnref<ExpectationsSource>* source) { |
|
edisonn
2013/08/02 12:32:41
static
ducky
2013/08/02 18:14:38
Done.
|
| + if (FLAGS_readPath.count() == 1) { |
| + const char* readPath = FLAGS_readPath[0]; |
| + if (!sk_exists(readPath)) { |
| + gm_fprintf(stderr, "readPath %s does not exist!\n", readPath); |
| + return false; |
| + } |
| + if (sk_isdir(readPath)) { |
| + if (FLAGS_verbose) { |
| + gm_fprintf(stdout, "reading from %s\n", readPath); |
| + } |
| + source->reset(SkNEW_ARGS( |
| + IndividualImageExpectationsSource, (readPath))); |
| + } else { |
| + if (FLAGS_verbose) { |
| + gm_fprintf(stdout, "reading expectations from JSON summary file %s\n", readPath); |
| } |
| + source->reset(SkNEW_ARGS(JsonExpectationsSource, (readPath))); |
| } |
| } |
| - // now remove any explicitly excluded configs |
| - for (int i = 0; i < excludeConfigs.count(); ++i) { |
| - int index = configs.find(excludeConfigs[i]); |
| - if (index >= 0) { |
| - configs.remove(index); |
| - // now assert that there was only one copy in configs[] |
| - SkASSERT(configs.find(excludeConfigs[i]) < 0); |
| - } |
| + return true; |
| +} |
| + |
| +bool parse_match_strs(SkTDArray<const char*>* matchStrs) { |
|
edisonn
2013/08/02 12:32:41
static
ducky
2013/08/02 18:14:38
Done.
|
| + for (int i = 0; i < FLAGS_match.count(); ++i) { |
| + matchStrs->push(FLAGS_match[i]); |
| + } |
| + return true; |
| +} |
| + |
| +int tool_main(int argc, char** argv); |
| +int tool_main(int argc, char** argv) { |
| + |
| +#if SK_ENABLE_INST_COUNT |
| + gPrintInstCount = true; |
| +#endif |
| + |
| + SkGraphics::Init(); |
| + // we don't need to see this during a run |
| + gSkSuppressFontCachePurgeSpew = true; |
| + |
| + setSystemPreferences(); |
| + GMMain gmmain; |
| + |
| + SkString usage; |
| + usage.printf("Run the golden master tests.\n"); |
| + SkCommandLineFlags::SetUsage(usage.c_str()); |
| + SkCommandLineFlags::Parse(argc, argv); |
| + |
| + gmmain.fUseFileHierarchy = FLAGS_hierarchy; |
| + gmmain.fWriteChecksumBasedFilenames = FLAGS_writeChecksumBasedFilenames; |
| + if (FLAGS_mismatchPath.count() == 1) { |
| + gmmain.fMismatchPath = FLAGS_mismatchPath[0]; |
| + } |
| + if (FLAGS_missingExpectationsPath.count() == 1) { |
| + gmmain.fMissingExpectationsPath = FLAGS_missingExpectationsPath[0]; |
| } |
| + SkTDArray<size_t> configs; |
| + int moduloRemainder = -1, moduloDivisor = -1; |
| + SkTDArray<SkScalar> tileGridReplayScales; |
| #if SK_SUPPORT_GPU |
| GrContextFactory* grFactory = new GrContextFactory; |
| - for (int i = 0; i < configs.count(); ++i) { |
| - size_t index = configs[i]; |
| - if (kGPU_Backend == gRec[index].fBackend) { |
| - GrContext* ctx = grFactory->get(gRec[index].fGLContextType); |
| - if (NULL == ctx) { |
| - gm_fprintf(stderr, "GrContext could not be created for config %s." |
| - " Config will be skipped.\n", gRec[index].fName); |
| - configs.remove(i); |
| - --i; |
| - continue; |
| - } |
| - if (gRec[index].fSampleCnt > ctx->getMaxSampleCount()) { |
| - gm_fprintf(stderr, "Sample count (%d) of config %s is not supported." |
| - " Config will be skipped.\n", gRec[index].fSampleCnt, gRec[index].fName); |
| - configs.remove(i); |
| - --i; |
| - } |
| - } |
| - } |
| #else |
| GrContextFactory* grFactory = NULL; |
| #endif |
| + SkTDArray<const char*> matchStrs; |
| - if (configs.isEmpty()) { |
| - gm_fprintf(stderr, "No configs to run."); |
| + if (!parse_flags_configs(&configs, grFactory) || |
| + !parse_flags_ignore_error_types(&(gmmain.fIgnorableErrorTypes)) || |
| + !parse_flags_modulo(&moduloRemainder, &moduloDivisor) || |
| +#if SK_SUPPORT_GPU |
| + !parse_flags_gpu_cache(&gGpuCacheSizeBytes, &gGpuCacheSizeCount) || |
| +#endif |
| + !parse_tile_grid_replay_scales(&tileGridReplayScales) || |
| + !parse_read_path(&gmmain.fExpectationsSource) || |
| + !parse_match_strs(&matchStrs)) { |
| return -1; |
| } |
| - // now show the user the set of configs that will be run. |
| - SkString configStr("These configs will be run: "); |
| - // show the user the config that will run. |
| - for (int i = 0; i < configs.count(); ++i) { |
| - configStr.appendf("%s%s", gRec[configs[i]].fName, (i == configs.count() - 1) ? "\n" : " "); |
| - } |
| - gm_fprintf(stdout, "%s", configStr.c_str()); |
| - |
| if (FLAGS_resourcePath.count() == 1) { |
| GM::SetResourcePath(FLAGS_resourcePath[0]); |
| } |
| - if (FLAGS_readPath.count() == 1) { |
| - const char* readPath = FLAGS_readPath[0]; |
| - if (!sk_exists(readPath)) { |
| - gm_fprintf(stderr, "readPath %s does not exist!\n", readPath); |
| - return -1; |
| - } |
| - if (sk_isdir(readPath)) { |
| - if (FLAGS_verbose) { |
| - gm_fprintf(stdout, "reading from %s\n", readPath); |
| - } |
| - gmmain.fExpectationsSource.reset(SkNEW_ARGS( |
| - IndividualImageExpectationsSource, (readPath))); |
| - } else { |
| - if (FLAGS_verbose) { |
| - gm_fprintf(stdout, "reading expectations from JSON summary file %s\n", readPath); |
| - } |
| - gmmain.fExpectationsSource.reset(SkNEW_ARGS( |
| - JsonExpectationsSource, (readPath))); |
| - } |
| - } |
| if (FLAGS_verbose) { |
| if (FLAGS_writePath.count() == 1) { |
| gm_fprintf(stdout, "writing to %s\n", FLAGS_writePath[0]); |
| @@ -1998,13 +2037,6 @@ int tool_main(int argc, char** argv) { |
| } |
| } |
| - if (moduloDivisor <= 0) { |
| - moduloRemainder = -1; |
| - } |
| - if (moduloRemainder < 0 || moduloRemainder >= moduloDivisor) { |
| - moduloRemainder = -1; |
| - } |
| - |
| int gmsRun = 0; |
| int gmIndex = -1; |
| SkString moduloStr; |
| @@ -2045,10 +2077,6 @@ int tool_main(int argc, char** argv) { |
| const char* shortName = gm->shortName(); |
| - SkTDArray<const char*> matchStrs; |
| - for (int i = 0; i < FLAGS_match.count(); ++i) { |
| - matchStrs.push(FLAGS_match[i]); |
| - } |
| if (SkCommandLineFlags::ShouldSkip(matchStrs, shortName)) { |
| continue; |
| } |