| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * 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 |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCommandLineFlags.h" | 8 #include "SkCommandLineFlags.h" |
| 9 #include "SkGraphics.h" | 9 #include "SkGraphics.h" |
| 10 #include "SkOSFile.h" | 10 #include "SkOSFile.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 sk_atomic_inc(fFailCount); | 152 sk_atomic_inc(fFailCount); |
| 153 } | 153 } |
| 154 SkDELETE(this); | 154 SkDELETE(this); |
| 155 } | 155 } |
| 156 | 156 |
| 157 private: | 157 private: |
| 158 SkAutoTDelete<Test> fTest; | 158 SkAutoTDelete<Test> fTest; |
| 159 int32_t* fFailCount; | 159 int32_t* fFailCount; |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 /* Takes a list of the form [~][^]match[$] |
| 163 ~ causes a matching test to always be skipped |
| 164 ^ requires the start of the test to match |
| 165 $ requires the end of the test to match |
| 166 ^ and $ requires an exact match |
| 167 If a test does not match any list entry, it is skipped unless some list entry
starts with ~ |
| 168 */ |
| 169 static bool shouldSkip(const char* testName) { |
| 170 int count = FLAGS_match.count(); |
| 171 size_t testLen = strlen(testName); |
| 172 bool anyExclude = count == 0; |
| 173 for (int index = 0; index < count; ++index) { |
| 174 const char* matchName = FLAGS_match[index]; |
| 175 size_t matchLen = strlen(matchName); |
| 176 bool matchExclude, matchStart, matchEnd; |
| 177 if ((matchExclude = matchName[0] == '~')) { |
| 178 anyExclude = true; |
| 179 matchName++; |
| 180 matchLen--; |
| 181 } |
| 182 if ((matchStart = matchName[0] == '^')) { |
| 183 matchName++; |
| 184 matchLen--; |
| 185 } |
| 186 if ((matchEnd = matchName[matchLen - 1] == '$')) { |
| 187 matchLen--; |
| 188 } |
| 189 if (matchStart ? (!matchEnd || matchLen == testLen) |
| 190 && strncmp(testName, matchName, matchLen) == 0 |
| 191 : matchEnd ? matchLen <= testLen |
| 192 && strncmp(testName + testLen - matchLen, matchName, matchLen) =
= 0 |
| 193 : strstr(testName, matchName) != 0) { |
| 194 return matchExclude; |
| 195 } |
| 196 } |
| 197 return !anyExclude; |
| 198 } |
| 199 |
| 162 int tool_main(int argc, char** argv); | 200 int tool_main(int argc, char** argv); |
| 163 int tool_main(int argc, char** argv) { | 201 int tool_main(int argc, char** argv) { |
| 164 SkCommandLineFlags::SetUsage(""); | 202 SkCommandLineFlags::SetUsage(""); |
| 165 SkCommandLineFlags::Parse(argc, argv); | 203 SkCommandLineFlags::Parse(argc, argv); |
| 166 | 204 |
| 167 #if SK_ENABLE_INST_COUNT | 205 #if SK_ENABLE_INST_COUNT |
| 168 gPrintInstCount = true; | 206 gPrintInstCount = true; |
| 169 #endif | 207 #endif |
| 170 | 208 |
| 171 SkGraphics::Init(); | 209 SkGraphics::Init(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 199 SkDebugf("%s\n", header.c_str()); | 237 SkDebugf("%s\n", header.c_str()); |
| 200 } | 238 } |
| 201 | 239 |
| 202 DebugfReporter reporter(FLAGS_extendedTest, !FLAGS_single, FLAGS_verbose); | 240 DebugfReporter reporter(FLAGS_extendedTest, !FLAGS_single, FLAGS_verbose); |
| 203 Iter iter(&reporter); | 241 Iter iter(&reporter); |
| 204 | 242 |
| 205 // Count tests first. | 243 // Count tests first. |
| 206 int total = 0; | 244 int total = 0; |
| 207 int toRun = 0; | 245 int toRun = 0; |
| 208 Test* test; | 246 Test* test; |
| 209 | |
| 210 SkTDArray<const char*> matchStrs; | |
| 211 for(int i = 0; i < FLAGS_match.count(); ++i) { | |
| 212 matchStrs.push(FLAGS_match[i]); | |
| 213 } | |
| 214 | |
| 215 while ((test = iter.next()) != NULL) { | 247 while ((test = iter.next()) != NULL) { |
| 216 SkAutoTDelete<Test> owned(test); | 248 SkAutoTDelete<Test> owned(test); |
| 217 | 249 if(!shouldSkip(test->getName())) { |
| 218 if(!SkCommandLineFlags::ShouldSkip(matchStrs, test->getName())) { | |
| 219 toRun++; | 250 toRun++; |
| 220 } | 251 } |
| 221 total++; | 252 total++; |
| 222 } | 253 } |
| 223 reporter.setTotal(toRun); | 254 reporter.setTotal(toRun); |
| 224 | 255 |
| 225 // Now run them. | 256 // Now run them. |
| 226 iter.reset(); | 257 iter.reset(); |
| 227 int32_t failCount = 0; | 258 int32_t failCount = 0; |
| 228 int skipCount = 0; | 259 int skipCount = 0; |
| 229 | 260 |
| 230 SkAutoTDelete<SkThreadPool> threadpool(SkNEW_ARGS(SkThreadPool, (FLAGS_threa
ds))); | 261 SkAutoTDelete<SkThreadPool> threadpool(SkNEW_ARGS(SkThreadPool, (FLAGS_threa
ds))); |
| 231 SkTArray<Test*> unsafeTests; // Always passes ownership to an SkTestRunnabl
e | 262 SkTArray<Test*> unsafeTests; // Always passes ownership to an SkTestRunnabl
e |
| 232 for (int i = 0; i < total; i++) { | 263 for (int i = 0; i < total; i++) { |
| 233 SkAutoTDelete<Test> test(iter.next()); | 264 SkAutoTDelete<Test> test(iter.next()); |
| 234 if (SkCommandLineFlags::ShouldSkip(matchStrs, test->getName())) { | 265 if (shouldSkip(test->getName())) { |
| 235 ++skipCount; | 266 ++skipCount; |
| 236 } else if (!test->isThreadsafe()) { | 267 } else if (!test->isThreadsafe()) { |
| 237 unsafeTests.push_back() = test.detach(); | 268 unsafeTests.push_back() = test.detach(); |
| 238 } else { | 269 } else { |
| 239 threadpool->add(SkNEW_ARGS(SkTestRunnable, (test.detach(), &failCoun
t))); | 270 threadpool->add(SkNEW_ARGS(SkTestRunnable, (test.detach(), &failCoun
t))); |
| 240 } | 271 } |
| 241 } | 272 } |
| 242 | 273 |
| 243 // Run the tests that aren't threadsafe. | 274 // Run the tests that aren't threadsafe. |
| 244 for (int i = 0; i < unsafeTests.count(); i++) { | 275 for (int i = 0; i < unsafeTests.count(); i++) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 268 GpuTest::DestroyContexts(); | 299 GpuTest::DestroyContexts(); |
| 269 | 300 |
| 270 return (failCount == 0) ? 0 : 1; | 301 return (failCount == 0) ? 0 : 1; |
| 271 } | 302 } |
| 272 | 303 |
| 273 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 304 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 274 int main(int argc, char * const argv[]) { | 305 int main(int argc, char * const argv[]) { |
| 275 return tool_main(argc, (char**) argv); | 306 return tool_main(argc, (char**) argv); |
| 276 } | 307 } |
| 277 #endif | 308 #endif |
| OLD | NEW |