Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Side by Side Diff: tests/skia_test.cpp

Issue 19807005: refactor duplication (shouldSkip and skip_name) into a utility function (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Forgot to add new files.. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "SkRunnable.h" 11 #include "SkRunnable.h"
12 #include "SkTArray.h" 12 #include "SkTArray.h"
13 #include "SkTemplates.h" 13 #include "SkTemplates.h"
14 #include "SkThreadPool.h" 14 #include "SkThreadPool.h"
15 #include "SkTime.h" 15 #include "SkTime.h"
16 #include "Test.h" 16 #include "Test.h"
17 #include "ToolUtils.h"
17 18
18 #if SK_SUPPORT_GPU 19 #if SK_SUPPORT_GPU
19 #include "GrContext.h" 20 #include "GrContext.h"
20 #endif 21 #endif
21 22
22 using namespace skiatest; 23 using namespace skiatest;
23 24
24 // need to explicitly declare this, or we get some weird infinite loop llist 25 // need to explicitly declare this, or we get some weird infinite loop llist
25 template TestRegistry* TestRegistry::gHead; 26 template TestRegistry* TestRegistry::gHead;
26 27
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 sk_atomic_inc(fFailCount); 153 sk_atomic_inc(fFailCount);
153 } 154 }
154 SkDELETE(this); 155 SkDELETE(this);
155 } 156 }
156 157
157 private: 158 private:
158 SkAutoTDelete<Test> fTest; 159 SkAutoTDelete<Test> fTest;
159 int32_t* fFailCount; 160 int32_t* fFailCount;
160 }; 161 };
161 162
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
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 int tool_main(int argc, char** argv) {
202 SkCommandLineFlags::SetUsage(""); 165 SkCommandLineFlags::SetUsage("");
203 SkCommandLineFlags::Parse(argc, argv); 166 SkCommandLineFlags::Parse(argc, argv);
204 167
205 #if SK_ENABLE_INST_COUNT 168 #if SK_ENABLE_INST_COUNT
206 gPrintInstCount = true; 169 gPrintInstCount = true;
207 #endif 170 #endif
208 171
209 SkGraphics::Init(); 172 SkGraphics::Init();
(...skipping 27 matching lines...) Expand all
237 SkDebugf("%s\n", header.c_str()); 200 SkDebugf("%s\n", header.c_str());
238 } 201 }
239 202
240 DebugfReporter reporter(FLAGS_extendedTest, !FLAGS_single, FLAGS_verbose); 203 DebugfReporter reporter(FLAGS_extendedTest, !FLAGS_single, FLAGS_verbose);
241 Iter iter(&reporter); 204 Iter iter(&reporter);
242 205
243 // Count tests first. 206 // Count tests first.
244 int total = 0; 207 int total = 0;
245 int toRun = 0; 208 int toRun = 0;
246 Test* test; 209 Test* test;
210
211 SkTDArray<const char*> matchStrs;
212 for(int i = 0; i < FLAGS_match.count(); ++i) {
213 matchStrs.push(FLAGS_match[i]);
214 }
215
247 while ((test = iter.next()) != NULL) { 216 while ((test = iter.next()) != NULL) {
248 SkAutoTDelete<Test> owned(test); 217 SkAutoTDelete<Test> owned(test);
249 if(!shouldSkip(test->getName())) { 218
219 if(!shouldSkip(matchStrs, test->getName())) {
250 toRun++; 220 toRun++;
251 } 221 }
252 total++; 222 total++;
253 } 223 }
254 reporter.setTotal(toRun); 224 reporter.setTotal(toRun);
255 225
256 // Now run them. 226 // Now run them.
257 iter.reset(); 227 iter.reset();
258 int32_t failCount = 0; 228 int32_t failCount = 0;
259 int skipCount = 0; 229 int skipCount = 0;
260 230
261 SkAutoTDelete<SkThreadPool> threadpool(SkNEW_ARGS(SkThreadPool, (FLAGS_threa ds))); 231 SkAutoTDelete<SkThreadPool> threadpool(SkNEW_ARGS(SkThreadPool, (FLAGS_threa ds)));
262 SkTArray<Test*> unsafeTests; // Always passes ownership to an SkTestRunnabl e 232 SkTArray<Test*> unsafeTests; // Always passes ownership to an SkTestRunnabl e
263 for (int i = 0; i < total; i++) { 233 for (int i = 0; i < total; i++) {
264 SkAutoTDelete<Test> test(iter.next()); 234 SkAutoTDelete<Test> test(iter.next());
265 if (shouldSkip(test->getName())) { 235 if (shouldSkip(matchStrs, test->getName())) {
266 ++skipCount; 236 ++skipCount;
267 } else if (!test->isThreadsafe()) { 237 } else if (!test->isThreadsafe()) {
268 unsafeTests.push_back() = test.detach(); 238 unsafeTests.push_back() = test.detach();
269 } else { 239 } else {
270 threadpool->add(SkNEW_ARGS(SkTestRunnable, (test.detach(), &failCoun t))); 240 threadpool->add(SkNEW_ARGS(SkTestRunnable, (test.detach(), &failCoun t)));
271 } 241 }
272 } 242 }
273 243
274 // Run the tests that aren't threadsafe. 244 // Run the tests that aren't threadsafe.
275 for (int i = 0; i < unsafeTests.count(); i++) { 245 for (int i = 0; i < unsafeTests.count(); i++) {
(...skipping 23 matching lines...) Expand all
299 GpuTest::DestroyContexts(); 269 GpuTest::DestroyContexts();
300 270
301 return (failCount == 0) ? 0 : 1; 271 return (failCount == 0) ? 0 : 1;
302 } 272 }
303 273
304 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 274 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
305 int main(int argc, char * const argv[]) { 275 int main(int argc, char * const argv[]) {
306 return tool_main(argc, (char**) argv); 276 return tool_main(argc, (char**) argv);
307 } 277 }
308 #endif 278 #endif
OLDNEW
« no previous file with comments | « gyp/tests.gyp ('k') | tools/ToolUtils.h » ('j') | tools/ToolUtils.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698