| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkGraphics.h" | 8 #include "SkGraphics.h" |
| 9 #include "Test.h" | 9 #include "Test.h" |
| 10 #include "SkOSFile.h" | 10 #include "SkOSFile.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 Reporter* fReporter; | 54 Reporter* fReporter; |
| 55 const TestRegistry* fReg; | 55 const TestRegistry* fReg; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 static const char* result2string(Reporter::Result result) { | 58 static const char* result2string(Reporter::Result result) { |
| 59 return result == Reporter::kPassed ? "passed" : "FAILED"; | 59 return result == Reporter::kPassed ? "passed" : "FAILED"; |
| 60 } | 60 } |
| 61 | 61 |
| 62 class DebugfReporter : public Reporter { | 62 class DebugfReporter : public Reporter { |
| 63 public: | 63 public: |
| 64 DebugfReporter() : fIndex(0), fTotal(0) {} | 64 DebugfReporter(bool allowExtendedTest) |
| 65 : fIndex(0) |
| 66 , fTotal(0) |
| 67 , fAllowExtendedTest(allowExtendedTest) { |
| 68 } |
| 65 | 69 |
| 66 void setIndexOfTotal(int index, int total) { | 70 void setIndexOfTotal(int index, int total) { |
| 67 fIndex = index; | 71 fIndex = index; |
| 68 fTotal = total; | 72 fTotal = total; |
| 69 } | 73 } |
| 74 |
| 75 virtual bool allowExtendedTest() const { |
| 76 return fAllowExtendedTest; |
| 77 } |
| 78 |
| 70 protected: | 79 protected: |
| 71 virtual void onStart(Test* test) { | 80 virtual void onStart(Test* test) { |
| 72 SkDebugf("[%d/%d] %s...\n", fIndex+1, fTotal, test->getName()); | 81 SkDebugf("[%d/%d] %s...\n", fIndex+1, fTotal, test->getName()); |
| 73 } | 82 } |
| 74 virtual void onReport(const char desc[], Reporter::Result result) { | 83 virtual void onReport(const char desc[], Reporter::Result result) { |
| 75 SkDebugf("\t%s: %s\n", result2string(result), desc); | 84 SkDebugf("\t%s: %s\n", result2string(result), desc); |
| 76 } | 85 } |
| 77 virtual void onEnd(Test*) { | 86 virtual void onEnd(Test*) { |
| 78 if (!this->getCurrSuccess()) { | 87 if (!this->getCurrSuccess()) { |
| 79 SkDebugf("---- FAILED\n"); | 88 SkDebugf("---- FAILED\n"); |
| 80 } | 89 } |
| 81 } | 90 } |
| 82 private: | 91 private: |
| 83 int fIndex, fTotal; | 92 int fIndex, fTotal; |
| 93 bool fAllowExtendedTest; |
| 84 }; | 94 }; |
| 85 | 95 |
| 86 static const char* make_canonical_dir_path(const char* path, SkString* storage)
{ | 96 static const char* make_canonical_dir_path(const char* path, SkString* storage)
{ |
| 87 if (path) { | 97 if (path) { |
| 88 // clean it up so it always has a trailing searator | 98 // clean it up so it always has a trailing searator |
| 89 size_t len = strlen(path); | 99 size_t len = strlen(path); |
| 90 if (0 == len) { | 100 if (0 == len) { |
| 91 path = NULL; | 101 path = NULL; |
| 92 } else if (SkPATH_SEPARATOR != path[len - 1]) { | 102 } else if (SkPATH_SEPARATOR != path[len - 1]) { |
| 93 // resize to len + 1, to make room for searator | 103 // resize to len + 1, to make room for searator |
| (...skipping 15 matching lines...) Expand all Loading... |
| 109 | 119 |
| 110 const SkString& Test::GetResourcePath() { | 120 const SkString& Test::GetResourcePath() { |
| 111 return gResourcePath; | 121 return gResourcePath; |
| 112 } | 122 } |
| 113 | 123 |
| 114 int tool_main(int argc, char** argv); | 124 int tool_main(int argc, char** argv); |
| 115 int tool_main(int argc, char** argv) { | 125 int tool_main(int argc, char** argv) { |
| 116 #if SK_ENABLE_INST_COUNT | 126 #if SK_ENABLE_INST_COUNT |
| 117 gPrintInstCount = true; | 127 gPrintInstCount = true; |
| 118 #endif | 128 #endif |
| 129 bool allowExtendedTest = false; |
| 130 bool verboseOutput = false; |
| 131 |
| 119 SkGraphics::Init(); | 132 SkGraphics::Init(); |
| 120 | 133 |
| 121 const char* matchStr = NULL; | 134 const char* matchStr = NULL; |
| 122 | 135 |
| 123 char* const* stop = argv + argc; | 136 char* const* stop = argv + argc; |
| 124 for (++argv; argv < stop; ++argv) { | 137 for (++argv; argv < stop; ++argv) { |
| 125 if (strcmp(*argv, "--match") == 0) { | 138 if (0 == strcmp(*argv, "--match") || 0 == strcmp(*argv, "-m")) { |
| 126 ++argv; | 139 ++argv; |
| 127 if (argv < stop && **argv) { | 140 if (argv < stop && **argv) { |
| 128 matchStr = *argv; | 141 matchStr = *argv; |
| 129 } else { | 142 } else { |
| 130 SkDebugf("no following argument to --match\n"); | 143 SkDebugf("no following argument to --match\n"); |
| 131 return -1; | 144 return -1; |
| 132 } | 145 } |
| 133 } else if (0 == strcmp(*argv, "--tmpDir")) { | 146 } else if (0 == strcmp(*argv, "--tmpDir") || 0 == strcmp(*argv, "-t")) { |
| 134 ++argv; | 147 ++argv; |
| 135 if (argv < stop && **argv) { | 148 if (argv < stop && **argv) { |
| 136 make_canonical_dir_path(*argv, &gTmpDir); | 149 make_canonical_dir_path(*argv, &gTmpDir); |
| 137 } else { | 150 } else { |
| 138 SkDebugf("no following argument to --tmpDir\n"); | 151 SkDebugf("no following argument to --tmpDir\n"); |
| 139 return -1; | 152 return -1; |
| 140 } | 153 } |
| 141 } else if ((0 == strcmp(*argv, "--resourcePath")) || | 154 } else if (0 == strcmp(*argv, "--resourcePath") || 0 == strcmp(*argv, "-
i")) { |
| 142 (0 == strcmp(*argv, "-i"))) { | |
| 143 argv++; | 155 argv++; |
| 144 if (argv < stop && **argv) { | 156 if (argv < stop && **argv) { |
| 145 make_canonical_dir_path(*argv, &gResourcePath); | 157 make_canonical_dir_path(*argv, &gResourcePath); |
| 146 } | 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; |
| 147 } | 175 } |
| 148 } | 176 } |
| 149 | 177 |
| 150 { | 178 { |
| 151 SkString header("Skia UnitTests:"); | 179 SkString header("Skia UnitTests:"); |
| 152 if (matchStr) { | 180 if (matchStr) { |
| 153 header.appendf(" --match %s", matchStr); | 181 header.appendf(" --match %s", matchStr); |
| 154 } | 182 } |
| 155 if (!gTmpDir.isEmpty()) { | 183 if (!gTmpDir.isEmpty()) { |
| 156 header.appendf(" --tmpDir %s", gTmpDir.c_str()); | 184 header.appendf(" --tmpDir %s", gTmpDir.c_str()); |
| 157 } | 185 } |
| 158 if (!gResourcePath.isEmpty()) { | 186 if (!gResourcePath.isEmpty()) { |
| 159 header.appendf(" --resourcePath %s", gResourcePath.c_str()); | 187 header.appendf(" --resourcePath %s", gResourcePath.c_str()); |
| 160 } | 188 } |
| 161 #ifdef SK_DEBUG | 189 #ifdef SK_DEBUG |
| 162 header.append(" SK_DEBUG"); | 190 header.append(" SK_DEBUG"); |
| 163 #else | 191 #else |
| 164 header.append(" SK_RELEASE"); | 192 header.append(" SK_RELEASE"); |
| 165 #endif | 193 #endif |
| 166 #ifdef SK_SCALAR_IS_FIXED | 194 #ifdef SK_SCALAR_IS_FIXED |
| 167 header.append(" SK_SCALAR_IS_FIXED"); | 195 header.append(" SK_SCALAR_IS_FIXED"); |
| 168 #else | 196 #else |
| 169 header.append(" SK_SCALAR_IS_FLOAT"); | 197 header.append(" SK_SCALAR_IS_FLOAT"); |
| 170 #endif | 198 #endif |
| 171 SkDebugf("%s\n", header.c_str()); | 199 SkDebugf("%s\n", header.c_str()); |
| 172 } | 200 } |
| 173 | 201 |
| 174 DebugfReporter reporter; | 202 DebugfReporter reporter(allowExtendedTest); |
| 175 Iter iter(&reporter); | 203 Iter iter(&reporter); |
| 176 Test* test; | 204 Test* test; |
| 177 | 205 |
| 178 const int count = Iter::Count(); | 206 const int count = Iter::Count(); |
| 179 int index = 0; | 207 int index = 0; |
| 180 int failCount = 0; | 208 int failCount = 0; |
| 181 int skipCount = 0; | 209 int skipCount = 0; |
| 182 while ((test = iter.next()) != NULL) { | 210 while ((test = iter.next()) != NULL) { |
| 183 reporter.setIndexOfTotal(index, count); | 211 reporter.setIndexOfTotal(index, count); |
| 184 if (NULL != matchStr && !strstr(test->getName(), matchStr)) { | 212 if (NULL != matchStr && !strstr(test->getName(), matchStr)) { |
| 185 ++skipCount; | 213 ++skipCount; |
| 186 } else { | 214 } else { |
| 187 if (!test->run()) { | 215 if (!test->run()) { |
| 188 ++failCount; | 216 ++failCount; |
| 189 } | 217 } |
| 190 } | 218 } |
| 191 SkDELETE(test); | 219 SkDELETE(test); |
| 192 index += 1; | 220 index += 1; |
| 193 } | 221 } |
| 194 | 222 |
| 195 SkDebugf("Finished %d tests, %d failures, %d skipped.\n", | 223 SkDebugf("Finished %d tests, %d failures, %d skipped.\n", |
| 196 count, failCount, skipCount); | 224 count, failCount, skipCount); |
| 197 | 225 int testCount = reporter.countTests(); |
| 226 if (verboseOutput && testCount > 0) { |
| 227 SkDebugf("Ran %d Internal tests.\n", testCount); |
| 228 } |
| 198 #if SK_SUPPORT_GPU | 229 #if SK_SUPPORT_GPU |
| 199 | 230 |
| 200 #if GR_CACHE_STATS | 231 #if GR_CACHE_STATS |
| 201 GrContext *gr = GpuTest::GetContext(); | 232 GrContext *gr = GpuTest::GetContext(); |
| 202 | 233 |
| 203 gr->printCacheStats(); | 234 gr->printCacheStats(); |
| 204 #endif | 235 #endif |
| 205 | 236 |
| 206 #endif | 237 #endif |
| 207 | 238 |
| 208 SkGraphics::Term(); | 239 SkGraphics::Term(); |
| 209 GpuTest::DestroyContexts(); | 240 GpuTest::DestroyContexts(); |
| 210 | 241 |
| 211 return (failCount == 0) ? 0 : 1; | 242 return (failCount == 0) ? 0 : 1; |
| 212 } | 243 } |
| 213 | 244 |
| 214 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 245 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 215 int main(int argc, char * const argv[]) { | 246 int main(int argc, char * const argv[]) { |
| 216 return tool_main(argc, (char**) argv); | 247 return tool_main(argc, (char**) argv); |
| 217 } | 248 } |
| 218 #endif | 249 #endif |
| OLD | NEW |