add wildcard test name matching to gm and bench.

This adds the same set of options in unit tests, i.e:

--match [~][^]match[$] [~][^]match[$] ...
~ causes a matching test to always be skipped
^ requires the start of the test to match
$ requires the end of the test to match
^ and $ requires an exact match

If a test does not match any list entry,
it is skipped unless some list entry starts with ~
Review URL: https://codereview.chromium.org/14746017

git-svn-id: http://skia.googlecode.com/svn/trunk@9096 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
caryclark@google.com 2013-05-10 15:16:13 +00:00
parent 4d98b740cd
commit 512c9b65fc
2 changed files with 73 additions and 22 deletions

View File

@ -271,17 +271,35 @@ static int findConfig(const char config[]) {
} }
static bool skip_name(const SkTDArray<const char*> array, const char name[]) { static bool skip_name(const SkTDArray<const char*> array, const char name[]) {
if (0 == array.count()) { // FIXME: this duplicates the logic in skia_test.cpp, gmmain.cpp -- consolidate
// no names, so don't skip anything int count = array.count();
return false; size_t testLen = strlen(name);
} bool anyExclude = count == 0;
for (int i = 0; i < array.count(); ++i) { for (int i = 0; i < array.count(); ++i) {
if (strstr(name, array[i])) { const char* matchName = array[i];
// found the name, so don't skip size_t matchLen = strlen(matchName);
return false; bool matchExclude, matchStart, matchEnd;
if ((matchExclude = matchName[0] == '~')) {
anyExclude = true;
matchName++;
matchLen--;
}
if ((matchStart = matchName[0] == '^')) {
matchName++;
matchLen--;
}
if ((matchEnd = matchName[matchLen - 1] == '$')) {
matchLen--;
}
if (matchStart ? (!matchEnd || matchLen == testLen)
&& strncmp(name, matchName, matchLen) == 0
: matchEnd ? matchLen <= testLen
&& strncmp(name + testLen - matchLen, matchName, matchLen) == 0
: strstr(name, matchName) != 0) {
return matchExclude;
} }
} }
return true; return !anyExclude;
} }
static void help() { static void help() {
@ -329,7 +347,14 @@ static void help() {
SkDebugf(" -1 for either value means use the default. 0 for either disables the cache.\n"); SkDebugf(" -1 for either value means use the default. 0 for either disables the cache.\n");
#endif #endif
SkDebugf(" --strokeWidth width : The width for path stroke.\n"); SkDebugf(" --strokeWidth width : The width for path stroke.\n");
SkDebugf(" --match name : Only run bench whose name is matched.\n"); SkDebugf(" --match [~][^]substring[$] [...] of test name to run.\n"
" Multiple matches may be separated by spaces.\n"
" ~ causes a matching test to always be skipped\n"
" ^ requires the start of the test to match\n"
" $ requires the end of the test to match\n"
" ^ and $ requires an exact match\n"
" If a test does not match any list entry,\n"
" it is skipped unless some list entry starts with ~\n");
SkDebugf(" --mode normal|deferred|deferredSilent|record|picturerecord :\n" SkDebugf(" --mode normal|deferred|deferredSilent|record|picturerecord :\n"
" Run in the corresponding mode\n" " Run in the corresponding mode\n"
" normal, Use a normal canvas to draw to;\n" " normal, Use a normal canvas to draw to;\n"
@ -526,9 +551,11 @@ int tool_main(int argc, char** argv) {
} }
} else if (strcmp(*argv, "--match") == 0) { } else if (strcmp(*argv, "--match") == 0) {
argv++; argv++;
if (argv < stop) { while (argv < stop && (*argv)[0] != '-') {
*fMatches.append() = *argv; *fMatches.append() = *argv++;
} else { }
argv--;
if (!fMatches.count()) {
logger.logError("missing arg for --match\n"); logger.logError("missing arg for --match\n");
help(); help();
return -1; return -1;

View File

@ -1240,8 +1240,14 @@ DEFINE_bool(hierarchy, false, "Whether to use multilevel directory structure "
DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(), DEFINE_string(ignoreErrorTypes, kDefaultIgnorableErrorTypes.asString(" ").c_str(),
"Space-separated list of ErrorTypes that should be ignored. If any *other* error " "Space-separated list of ErrorTypes that should be ignored. If any *other* error "
"types are encountered, the tool will exit with a nonzero return value."); "types are encountered, the tool will exit with a nonzero return value.");
DEFINE_string(match, "", "Only run tests whose name includes this substring/these substrings " DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n"
"(more than one can be supplied, separated by spaces)."); "Multiple matches may be separated by spaces.\n"
"~ causes a matching test to always be skipped\n"
"^ requires the start of the test to match\n"
"$ requires the end of the test to match\n"
"^ and $ requires an exact match\n"
"If a test does not match any list entry,\n"
"it is skipped unless some list entry starts with ~");
DEFINE_string(mismatchPath, "", "Write images for tests that failed due to " DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
"pixel mismatches into this directory."); "pixel mismatches into this directory.");
DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which " DEFINE_string(modulo, "", "[--modulo <remainder> <divisor>]: only run tests for which "
@ -1306,17 +1312,35 @@ static int findConfig(const char config[]) {
} }
static bool skip_name(SkCommandLineFlags::StringArray array, const char name[]) { static bool skip_name(SkCommandLineFlags::StringArray array, const char name[]) {
if (0 == array.count()) { // FIXME: this duplicates the logic in test/skia_test.cpp -- consolidate
// no names, so don't skip anything int count = array.count();
return false; size_t testLen = strlen(name);
} bool anyExclude = count == 0;
for (int i = 0; i < array.count(); ++i) { for (int i = 0; i < array.count(); ++i) {
if (strstr(name, array[i])) { const char* matchName = array[i];
// found the name, so don't skip size_t matchLen = strlen(matchName);
return false; bool matchExclude, matchStart, matchEnd;
if ((matchExclude = matchName[0] == '~')) {
anyExclude = true;
matchName++;
matchLen--;
}
if ((matchStart = matchName[0] == '^')) {
matchName++;
matchLen--;
}
if ((matchEnd = matchName[matchLen - 1] == '$')) {
matchLen--;
}
if (matchStart ? (!matchEnd || matchLen == testLen)
&& strncmp(name, matchName, matchLen) == 0
: matchEnd ? matchLen <= testLen
&& strncmp(name + testLen - matchLen, matchName, matchLen) == 0
: strstr(name, matchName) != 0) {
return matchExclude;
} }
} }
return true; return !anyExclude;
} }
namespace skiagm { namespace skiagm {