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

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: Forced linking is required, shouldn't have removed it Created 7 years, 4 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
« no previous file with comments | « gyp/bench.gyp ('k') | tools/flags/SkCommandLineFlags.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
200 int tool_main(int argc, char** argv); 162 int tool_main(int argc, char** argv);
201 int tool_main(int argc, char** argv) { 163 int tool_main(int argc, char** argv) {
202 SkCommandLineFlags::SetUsage(""); 164 SkCommandLineFlags::SetUsage("");
203 SkCommandLineFlags::Parse(argc, argv); 165 SkCommandLineFlags::Parse(argc, argv);
204 166
205 #if SK_ENABLE_INST_COUNT 167 #if SK_ENABLE_INST_COUNT
206 gPrintInstCount = true; 168 gPrintInstCount = true;
207 #endif 169 #endif
208 170
209 SkGraphics::Init(); 171 SkGraphics::Init();
(...skipping 27 matching lines...) Expand all
237 SkDebugf("%s\n", header.c_str()); 199 SkDebugf("%s\n", header.c_str());
238 } 200 }
239 201
240 DebugfReporter reporter(FLAGS_extendedTest, !FLAGS_single, FLAGS_verbose); 202 DebugfReporter reporter(FLAGS_extendedTest, !FLAGS_single, FLAGS_verbose);
241 Iter iter(&reporter); 203 Iter iter(&reporter);
242 204
243 // Count tests first. 205 // Count tests first.
244 int total = 0; 206 int total = 0;
245 int toRun = 0; 207 int toRun = 0;
246 Test* test; 208 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
247 while ((test = iter.next()) != NULL) { 215 while ((test = iter.next()) != NULL) {
248 SkAutoTDelete<Test> owned(test); 216 SkAutoTDelete<Test> owned(test);
249 if(!shouldSkip(test->getName())) { 217
218 if(!SkCommandLineFlags::ShouldSkip(matchStrs, test->getName())) {
250 toRun++; 219 toRun++;
251 } 220 }
252 total++; 221 total++;
253 } 222 }
254 reporter.setTotal(toRun); 223 reporter.setTotal(toRun);
255 224
256 // Now run them. 225 // Now run them.
257 iter.reset(); 226 iter.reset();
258 int32_t failCount = 0; 227 int32_t failCount = 0;
259 int skipCount = 0; 228 int skipCount = 0;
260 229
261 SkAutoTDelete<SkThreadPool> threadpool(SkNEW_ARGS(SkThreadPool, (FLAGS_threa ds))); 230 SkAutoTDelete<SkThreadPool> threadpool(SkNEW_ARGS(SkThreadPool, (FLAGS_threa ds)));
262 SkTArray<Test*> unsafeTests; // Always passes ownership to an SkTestRunnabl e 231 SkTArray<Test*> unsafeTests; // Always passes ownership to an SkTestRunnabl e
263 for (int i = 0; i < total; i++) { 232 for (int i = 0; i < total; i++) {
264 SkAutoTDelete<Test> test(iter.next()); 233 SkAutoTDelete<Test> test(iter.next());
265 if (shouldSkip(test->getName())) { 234 if (SkCommandLineFlags::ShouldSkip(matchStrs, test->getName())) {
266 ++skipCount; 235 ++skipCount;
267 } else if (!test->isThreadsafe()) { 236 } else if (!test->isThreadsafe()) {
268 unsafeTests.push_back() = test.detach(); 237 unsafeTests.push_back() = test.detach();
269 } else { 238 } else {
270 threadpool->add(SkNEW_ARGS(SkTestRunnable, (test.detach(), &failCoun t))); 239 threadpool->add(SkNEW_ARGS(SkTestRunnable, (test.detach(), &failCoun t)));
271 } 240 }
272 } 241 }
273 242
274 // Run the tests that aren't threadsafe. 243 // Run the tests that aren't threadsafe.
275 for (int i = 0; i < unsafeTests.count(); i++) { 244 for (int i = 0; i < unsafeTests.count(); i++) {
(...skipping 23 matching lines...) Expand all
299 GpuTest::DestroyContexts(); 268 GpuTest::DestroyContexts();
300 269
301 return (failCount == 0) ? 0 : 1; 270 return (failCount == 0) ? 0 : 1;
302 } 271 }
303 272
304 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 273 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
305 int main(int argc, char * const argv[]) { 274 int main(int argc, char * const argv[]) {
306 return tool_main(argc, (char**) argv); 275 return tool_main(argc, (char**) argv);
307 } 276 }
308 #endif 277 #endif
OLDNEW
« no previous file with comments | « gyp/bench.gyp ('k') | tools/flags/SkCommandLineFlags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698