Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 4 * | 3 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 7 | |
| 8 #include "../tools/flags/SkCommandLineFlags.h" | |
|
scroggo
2013/04/11 16:28:01
You should be able to remove the full path if you
| |
| 8 #include "SkGraphics.h" | 9 #include "SkGraphics.h" |
| 9 #include "Test.h" | 10 #include "Test.h" |
| 10 #include "SkOSFile.h" | 11 #include "SkOSFile.h" |
| 11 | 12 |
| 12 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
| 13 #include "GrContext.h" | 14 #include "GrContext.h" |
| 14 #endif | 15 #endif |
| 15 | 16 |
| 16 using namespace skiatest; | 17 using namespace skiatest; |
| 17 | 18 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 const SkString& Test::GetTmpDir() { | 115 const SkString& Test::GetTmpDir() { |
| 115 return gTmpDir; | 116 return gTmpDir; |
| 116 } | 117 } |
| 117 | 118 |
| 118 static SkString gResourcePath; | 119 static SkString gResourcePath; |
| 119 | 120 |
| 120 const SkString& Test::GetResourcePath() { | 121 const SkString& Test::GetResourcePath() { |
| 121 return gResourcePath; | 122 return gResourcePath; |
| 122 } | 123 } |
| 123 | 124 |
| 125 DEFINE_string2(matchStr, m, NULL, "substring of test name to run."); | |
| 126 DEFINE_string2(tmpDir, t, NULL, "tmp directory for tests to use."); | |
| 127 DEFINE_string2(resourcePath, i, NULL, "directory for test resources."); | |
| 128 DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps."); | |
| 129 DEFINE_bool2(verbose, v, false, "enable verbose output."); | |
| 130 | |
| 124 int tool_main(int argc, char** argv); | 131 int tool_main(int argc, char** argv); |
| 125 int tool_main(int argc, char** argv) { | 132 int tool_main(int argc, char** argv) { |
| 133 SkCommandLineFlags::SetUsage(""); | |
| 134 SkCommandLineFlags::Parse(argc, argv); | |
| 135 | |
| 136 if (!FLAGS_tmpDir.isEmpty()) { | |
| 137 make_canonical_dir_path(FLAGS_tmpDir[0], &gTmpDir); | |
| 138 } | |
| 139 if (!FLAGS_resourcePath.isEmpty()) { | |
| 140 make_canonical_dir_path(FLAGS_resourcePath[0], &gResourcePath); | |
| 141 } | |
| 142 | |
| 126 #if SK_ENABLE_INST_COUNT | 143 #if SK_ENABLE_INST_COUNT |
| 127 gPrintInstCount = true; | 144 gPrintInstCount = true; |
| 128 #endif | 145 #endif |
| 129 bool allowExtendedTest = false; | |
| 130 bool verboseOutput = false; | |
| 131 | 146 |
| 132 SkGraphics::Init(); | 147 SkGraphics::Init(); |
| 133 | 148 |
| 134 const char* matchStr = NULL; | |
| 135 | |
| 136 char* const* stop = argv + argc; | |
| 137 for (++argv; argv < stop; ++argv) { | |
| 138 if (0 == strcmp(*argv, "--match") || 0 == strcmp(*argv, "-m")) { | |
| 139 ++argv; | |
| 140 if (argv < stop && **argv) { | |
| 141 matchStr = *argv; | |
| 142 } else { | |
| 143 SkDebugf("no following argument to --match\n"); | |
| 144 return -1; | |
| 145 } | |
| 146 } else if (0 == strcmp(*argv, "--tmpDir") || 0 == strcmp(*argv, "-t")) { | |
| 147 ++argv; | |
| 148 if (argv < stop && **argv) { | |
| 149 make_canonical_dir_path(*argv, &gTmpDir); | |
| 150 } else { | |
| 151 SkDebugf("no following argument to --tmpDir\n"); | |
| 152 return -1; | |
| 153 } | |
| 154 } else if (0 == strcmp(*argv, "--resourcePath") || 0 == strcmp(*argv, "- i")) { | |
| 155 argv++; | |
| 156 if (argv < stop && **argv) { | |
| 157 make_canonical_dir_path(*argv, &gResourcePath); | |
| 158 } | |
| 159 } else if (0 == strcmp(*argv, "--extendedTest") || 0 == strcmp(*argv, "- x")) { | |
| 160 allowExtendedTest = true; | |
| 161 } else if (0 == strcmp(*argv, "--verbose") || 0 == strcmp(*argv, "-v")) { | |
| 162 verboseOutput = true; | |
| 163 } else { | |
| 164 if (0 != strcmp(*argv, "--help") && 0 != strcmp(*argv, "-h") | |
| 165 && 0 != strcmp(*argv, "-?")) { | |
| 166 SkDebugf("Unknown option %s. ", *argv); | |
| 167 } | |
| 168 SkDebugf("Skia UnitTests options are:\n"); | |
| 169 SkDebugf(" -m --match [test-name-substring]\n"); | |
| 170 SkDebugf(" -t --tmpDir [dir]\n"); | |
| 171 SkDebugf(" -i --resourcePath [dir]\n"); | |
| 172 SkDebugf(" -x --extendedTest\n"); | |
| 173 SkDebugf(" -v --verbose\n"); | |
| 174 return 1; | |
| 175 } | |
| 176 } | |
| 177 | |
| 178 { | 149 { |
| 179 SkString header("Skia UnitTests:"); | 150 SkString header("Skia UnitTests:"); |
| 180 if (matchStr) { | 151 if (!FLAGS_matchStr.isEmpty()) { |
| 181 header.appendf(" --match %s", matchStr); | 152 header.appendf(" --match %s", FLAGS_matchStr[0]); |
| 182 } | 153 } |
| 183 if (!gTmpDir.isEmpty()) { | 154 if (!gTmpDir.isEmpty()) { |
| 184 header.appendf(" --tmpDir %s", gTmpDir.c_str()); | 155 header.appendf(" --tmpDir %s", gTmpDir.c_str()); |
| 185 } | 156 } |
| 186 if (!gResourcePath.isEmpty()) { | 157 if (!gResourcePath.isEmpty()) { |
| 187 header.appendf(" --resourcePath %s", gResourcePath.c_str()); | 158 header.appendf(" --resourcePath %s", gResourcePath.c_str()); |
| 188 } | 159 } |
| 189 #ifdef SK_DEBUG | 160 #ifdef SK_DEBUG |
| 190 header.append(" SK_DEBUG"); | 161 header.append(" SK_DEBUG"); |
| 191 #else | 162 #else |
| 192 header.append(" SK_RELEASE"); | 163 header.append(" SK_RELEASE"); |
| 193 #endif | 164 #endif |
| 194 #ifdef SK_SCALAR_IS_FIXED | 165 #ifdef SK_SCALAR_IS_FIXED |
| 195 header.append(" SK_SCALAR_IS_FIXED"); | 166 header.append(" SK_SCALAR_IS_FIXED"); |
| 196 #else | 167 #else |
| 197 header.append(" SK_SCALAR_IS_FLOAT"); | 168 header.append(" SK_SCALAR_IS_FLOAT"); |
| 198 #endif | 169 #endif |
| 199 SkDebugf("%s\n", header.c_str()); | 170 SkDebugf("%s\n", header.c_str()); |
| 200 } | 171 } |
| 201 | 172 |
| 202 DebugfReporter reporter(allowExtendedTest); | 173 DebugfReporter reporter(FLAGS_extendedTest); |
| 203 Iter iter(&reporter); | 174 Iter iter(&reporter); |
| 204 Test* test; | 175 Test* test; |
| 205 | 176 |
| 206 const int count = Iter::Count(); | 177 const int count = Iter::Count(); |
| 207 int index = 0; | 178 int index = 0; |
| 208 int failCount = 0; | 179 int failCount = 0; |
| 209 int skipCount = 0; | 180 int skipCount = 0; |
| 210 while ((test = iter.next()) != NULL) { | 181 while ((test = iter.next()) != NULL) { |
| 211 reporter.setIndexOfTotal(index, count); | 182 reporter.setIndexOfTotal(index, count); |
| 212 if (NULL != matchStr && !strstr(test->getName(), matchStr)) { | 183 if (!FLAGS_matchStr.isEmpty() && !strstr(test->getName(), FLAGS_matchStr [0])) { |
| 213 ++skipCount; | 184 ++skipCount; |
| 214 } else { | 185 } else { |
| 215 if (!test->run()) { | 186 if (!test->run()) { |
| 216 ++failCount; | 187 ++failCount; |
| 217 } | 188 } |
| 218 } | 189 } |
| 219 SkDELETE(test); | 190 SkDELETE(test); |
| 220 index += 1; | 191 index += 1; |
| 221 } | 192 } |
| 222 | 193 |
| 223 SkDebugf("Finished %d tests, %d failures, %d skipped.\n", | 194 SkDebugf("Finished %d tests, %d failures, %d skipped.\n", |
| 224 count, failCount, skipCount); | 195 count, failCount, skipCount); |
| 225 int testCount = reporter.countTests(); | 196 int testCount = reporter.countTests(); |
| 226 if (verboseOutput && testCount > 0) { | 197 if (FLAGS_verbose && testCount > 0) { |
| 227 SkDebugf("Ran %d Internal tests.\n", testCount); | 198 SkDebugf("Ran %d Internal tests.\n", testCount); |
| 228 } | 199 } |
| 229 #if SK_SUPPORT_GPU | 200 #if SK_SUPPORT_GPU |
| 230 | 201 |
| 231 #if GR_CACHE_STATS | 202 #if GR_CACHE_STATS |
| 232 GrContext *gr = GpuTest::GetContext(); | 203 GrContext *gr = GpuTest::GetContext(); |
| 233 | 204 |
| 234 gr->printCacheStats(); | 205 gr->printCacheStats(); |
| 235 #endif | 206 #endif |
| 236 | 207 |
| 237 #endif | 208 #endif |
| 238 | 209 |
| 239 SkGraphics::Term(); | 210 SkGraphics::Term(); |
| 240 GpuTest::DestroyContexts(); | 211 GpuTest::DestroyContexts(); |
| 241 | 212 |
| 242 return (failCount == 0) ? 0 : 1; | 213 return (failCount == 0) ? 0 : 1; |
| 243 } | 214 } |
| 244 | 215 |
| 245 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 216 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 246 int main(int argc, char * const argv[]) { | 217 int main(int argc, char * const argv[]) { |
| 247 return tool_main(argc, (char**) argv); | 218 return tool_main(argc, (char**) argv); |
| 248 } | 219 } |
| 249 #endif | 220 #endif |
| OLD | NEW |