blob: a94412e98973af615dd62409844ce4beb36dc9f6 [file] [log] [blame]
caryclark19eb3b22014-07-18 05:08:14 -07001#include "CrashHandler.h"
2// #include "OverwriteLine.h"
3#include "Resources.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +00004#include "SkBitmap.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +00005#include "SkCanvas.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +00006#include "SkColor.h"
7#include "SkColorPriv.h"
caryclark19eb3b22014-07-18 05:08:14 -07008#include "SkCommandLineFlags.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +00009#include "SkDevice.h"
caryclark19eb3b22014-07-18 05:08:14 -070010#include "SkForceLinking.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000011#include "SkGraphics.h"
caryclark@google.comcffbcc32013-06-04 17:59:42 +000012#include "SkImageDecoder.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000013#include "SkImageEncoder.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000014#include "SkOSFile.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000015#include "SkPathOpsDebug.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000016#include "SkPicture.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000017#include "SkRTConf.h"
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000018#include "SkTSort.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000019#include "SkStream.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000020#include "SkString.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000021#include "SkTArray.h"
22#include "SkTDArray.h"
caryclark19eb3b22014-07-18 05:08:14 -070023#include "SkTemplates.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000024#include "SkThreadPool.h"
25#include "SkTime.h"
caryclark@google.com07e97fc2013-07-08 17:17:02 +000026
caryclark19eb3b22014-07-18 05:08:14 -070027__SK_FORCE_IMAGE_DECODER_LINKING;
caryclark@google.com07e97fc2013-07-08 17:17:02 +000028
caryclark19eb3b22014-07-18 05:08:14 -070029/* add local exceptions here */
30/* TODO : add command flag interface */
31const struct SkipOverTest {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000032 int directory;
33 const char* filename;
caryclark19eb3b22014-07-18 05:08:14 -070034 bool blamePathOps;
35} skipOver[] = {
36 { 2, "http___www_groupon_sg_.skp", false}, // SkAAClip::Builder::addRun SkASSERT(fBounds.contains(x, y));
37 { 6, "http___www_googleventures_com_.skp", true}, // addTCoincident SkASSERT(test->fT < 1);
38 { 7, "http___www_foxsports_nl_.skp", true}, // (no repro on mac) addT SkASSERT(this != other || fVerb == SkPath::kCubic_Verb)
39 {13, "http___www_modernqigong_com_.skp", false}, // SkAAClip::Builder::addRun SkASSERT(fBounds.contains(x, y));
40 {14, "http___www_devbridge_com_.skp", true}, // checkSmallCoincidence SkASSERT(!next->fSmall || checkMultiple);
caryclark5e27e0e2014-08-12 07:46:33 -070041 {16, "http___www_1023world_net_.skp", false}, // bitmap decode assert (corrupt skp?)
caryclark19eb3b22014-07-18 05:08:14 -070042 {19, "http___www_alamdi_com_.skp", true}, // cubic/quad intersection
43 {26, "http___www_liveencounters_net_.skp", true}, // (no repro on mac) checkSmall addT:549 (line, expects cubic)
44 {28, "http___www_encros_fr_.skp", false}, // SkAAClip::Builder::addRun SkASSERT(fBounds.contains(x, y));
45 {37, "http___www_familysurvivalprotocol_wordpress_com_.skp", true}, // bumpSpan SkASSERT(span->fOppValue >= 0);
46 {39, "http___sufeinet_com_.skp", false}, // bitmap decode assert (corrupt skp?)
47 {41, "http___www_rano360_com_.skp", true}, // checkSmallCoincidence SkASSERT(!next->fSmall || checkMultiple);
48 {44, "http___www_firstunitedbank_com_.skp", true}, // addTCancel SkASSERT(oIndex > 0);
49 {46, "http___www_shinydemos_com_.skp", true}, // addSimpleAngle SkASSERT(index == count() - 2);
50 {48, "http___www_familysurvivalprotocol_com_.skp", true}, // bumpSpan SkASSERT "span->fOppValue >= 0"
51 {57, "http___www_lptemp_com_.skp", true}, // addTCoincident oPeek = &other->fTs[++oPeekIndex];
52 {71, "http___www_1milyonkahraman_org_.skp", true}, // addTCoincident SkASSERT(test->fT < 1);
53 {88, "http___www_apuntesdelechuza_wordpress_com_.skp", true}, // bumpSpan SkASSERT "span->fOppValue >= 0"
54 {89, "http___www_mobilizedconsulting_com_.skp", true}, // addTCancel SkASSERT(oIndex > 0);
55 {93, "http___www_simple_living_in_suffolk_co_uk_.skp", true}, // bumpSpan SkASSERT "span->fOppValue >= 0"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000056};
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000057
caryclark19eb3b22014-07-18 05:08:14 -070058size_t skipOverCount = sizeof(skipOver) / sizeof(skipOver[0]);
caryclarkdac1d172014-06-17 05:15:38 -070059
caryclark19eb3b22014-07-18 05:08:14 -070060
61/* customize file in/out here */
62/* TODO : add command flag interface */
63#define CHROME_VERSION "1e5dfa4-4a995df"
64#define SUMMARY_RUN 1
65
66#ifdef SK_BUILD_FOR_WIN
67 #define DRIVE_SPEC "D:"
68 #define PATH_SLASH "\\"
69#else
70 #define DRIVE_SPEC ""
71 #define PATH_SLASH "/"
72#endif
73
74#define IN_DIR_PRE DRIVE_SPEC PATH_SLASH "skps" PATH_SLASH "slave"
75#define OUT_DIR_PRE DRIVE_SPEC PATH_SLASH "skpOut" PATH_SLASH "slave"
76#define OUT_DIR_SUM DRIVE_SPEC PATH_SLASH "skpOut" PATH_SLASH "summary"
77#define DIR_POST PATH_SLASH "All" PATH_SLASH CHROME_VERSION
78
79static const char outOpDir[] = "opClip";
80static const char outOldDir[] = "oldClip";
81static const char outStatusDir[] = "statusTest";
82
83static SkString get_in_path(int dirNo, const char* filename) {
84 SkString path;
85 SkASSERT(dirNo);
86 path.appendf("%s%d%s", IN_DIR_PRE, dirNo, DIR_POST);
87 if (!sk_exists(path.c_str())) {
88 SkDebugf("could not read %s\n", path.c_str());
89 return SkString();
90 }
91 if (filename) {
92 path.appendf("%s%s", PATH_SLASH, filename);
93 if (!sk_exists(path.c_str())) {
94 SkDebugf("could not read %s\n", path.c_str());
95 return SkString();
96 }
97 }
98 return path;
99}
100
101static void make_recursive_dir(const SkString& path) {
102 if (sk_exists(path.c_str())) {
103 return;
104 }
105 const char* pathStr = path.c_str();
106 int last = (int) path.size();
107 do {
108 while (last > 0 && pathStr[--last] != PATH_SLASH[0])
109 ;
110 SkASSERT(last > 0);
111 SkString shorter(pathStr, last);
112 if (sk_mkdir(shorter.c_str())) {
113 break;
114 }
115 } while (true);
116 do {
117 while (last < (int) path.size() && pathStr[++last] != PATH_SLASH[0])
118 ;
119 SkString shorter(pathStr, last);
120 SkAssertResult(sk_mkdir(shorter.c_str()));
121 } while (last < (int) path.size());
122}
123
124static SkString get_out_path(int dirNo, const char* dirName) {
125 SkString path;
126 SkASSERT(dirNo);
127 SkASSERT(dirName);
128 path.appendf("%s%d%s%s%s", OUT_DIR_PRE, dirNo, DIR_POST, PATH_SLASH, dirName);
129 make_recursive_dir(path);
130 return path;
131}
132
133static SkString get_sum_path(const char* dirName) {
134 SkString path;
135 SkASSERT(dirName);
136 path.appendf("%s%d%s%s", OUT_DIR_SUM, SUMMARY_RUN, PATH_SLASH, dirName);
137 SkDebugf("%s\n", path.c_str());
138 make_recursive_dir(path);
139 return path;
140}
141
142static SkString make_png_name(const char* filename) {
143 SkString pngName = SkString(filename);
144 pngName.remove(pngName.size() - 3, 3);
145 pngName.append("png");
146 return pngName;
147}
148
149////////////////////////////////////////////////////////
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000150
151enum TestStep {
152 kCompareBits,
153 kEncodeFiles,
154};
155
156enum {
caryclarkdac1d172014-06-17 05:15:38 -0700157 kMaxLength = 256,
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000158 kMaxFiles = 128,
159 kSmallLimit = 1000,
160};
161
162struct TestResult {
163 void init(int dirNo) {
164 fDirNo = dirNo;
165 sk_bzero(fFilename, sizeof(fFilename));
166 fTestStep = kCompareBits;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000167 fScale = 1;
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000168 }
caryclark19eb3b22014-07-18 05:08:14 -0700169
170 void init(int dirNo, const SkString& filename) {
171 fDirNo = dirNo;
172 strcpy(fFilename, filename.c_str());
173 fTestStep = kCompareBits;
174 fScale = 1;
175 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000176
177 SkString status() {
178 SkString outStr;
179 outStr.printf("%s %d %d\n", fFilename, fPixelError, fTime);
180 return outStr;
181 }
182
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000183 SkString progress() {
184 SkString outStr;
185 outStr.printf("dir=%d %s ", fDirNo, fFilename);
186 if (fPixelError) {
187 outStr.appendf(" err=%d", fPixelError);
188 }
189 if (fTime) {
190 outStr.appendf(" time=%d", fTime);
191 }
192 if (fScale != 1) {
193 outStr.appendf(" scale=%d", fScale);
194 }
195 outStr.appendf("\n");
196 return outStr;
197
198 }
199
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000200 void test(int dirNo, const SkString& filename) {
201 init(dirNo);
202 strcpy(fFilename, filename.c_str());
203 testOne();
204 }
205
206 void testOne();
caryclark19eb3b22014-07-18 05:08:14 -0700207
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000208 char fFilename[kMaxLength];
209 TestStep fTestStep;
210 int fDirNo;
211 int fPixelError;
212 int fTime;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000213 int fScale;
214};
215
216class SortByPixel : public TestResult {
217public:
218 bool operator<(const SortByPixel& rh) const {
219 return fPixelError < rh.fPixelError;
220 }
221};
222
223class SortByTime : public TestResult {
224public:
225 bool operator<(const SortByTime& rh) const {
226 return fTime < rh.fTime;
227 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000228};
229
caryclarkdac1d172014-06-17 05:15:38 -0700230class SortByName : public TestResult {
231public:
232 bool operator<(const SortByName& rh) const {
233 return strcmp(fFilename, rh.fFilename) < 0;
234 }
235};
236
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000237struct TestState {
caryclark19eb3b22014-07-18 05:08:14 -0700238 void init(int dirNo) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000239 fResult.init(dirNo);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000240 }
241
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000242 SkTDArray<SortByPixel> fPixelWorst;
243 SkTDArray<SortByTime> fSlowest;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000244 TestResult fResult;
245};
246
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000247struct TestRunner {
caryclark19eb3b22014-07-18 05:08:14 -0700248 TestRunner(int threadCount)
249 : fNumThreads(threadCount) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000250 }
251
252 ~TestRunner();
253 void render();
254 int fNumThreads;
255 SkTDArray<class TestRunnable*> fRunnables;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000256};
257
258class TestRunnable : public SkRunnable {
259public:
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000260 virtual void run() SK_OVERRIDE {
261 SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024);
262 (*fTestFun)(&fState);
263 }
264
265 TestState fState;
266 void (*fTestFun)(TestState*);
267};
268
caryclarkdac1d172014-06-17 05:15:38 -0700269
270class TestRunnableDir : public TestRunnable {
271public:
272 TestRunnableDir(void (*testFun)(TestState*), int dirNo, TestRunner* runner) {
caryclark19eb3b22014-07-18 05:08:14 -0700273 fState.init(dirNo);
caryclarkdac1d172014-06-17 05:15:38 -0700274 fTestFun = testFun;
275 }
276
277};
278
279class TestRunnableFile : public TestRunnable {
280public:
281 TestRunnableFile(void (*testFun)(TestState*), int dirNo, const char* name, TestRunner* runner) {
caryclark19eb3b22014-07-18 05:08:14 -0700282 fState.init(dirNo);
caryclarkdac1d172014-06-17 05:15:38 -0700283 strcpy(fState.fResult.fFilename, name);
284 fTestFun = testFun;
285 }
286};
287
288class TestRunnableEncode : public TestRunnableFile {
289public:
290 TestRunnableEncode(void (*testFun)(TestState*), int dirNo, const char* name, TestRunner* runner)
291 : TestRunnableFile(testFun, dirNo, name, runner) {
292 fState.fResult.fTestStep = kEncodeFiles;
293 }
294};
295
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000296TestRunner::~TestRunner() {
297 for (int index = 0; index < fRunnables.count(); index++) {
298 SkDELETE(fRunnables[index]);
299 }
300}
301
302void TestRunner::render() {
303 SkThreadPool pool(fNumThreads);
304 for (int index = 0; index < fRunnables.count(); ++ index) {
305 pool.add(fRunnables[index]);
306 }
307}
308
309////////////////////////////////////////////////
310
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000311
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000312static int similarBits(const SkBitmap& gr, const SkBitmap& sk) {
313 const int kRowCount = 3;
314 const int kThreshold = 3;
315 int width = SkTMin(gr.width(), sk.width());
316 if (width < kRowCount) {
317 return true;
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000318 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000319 int height = SkTMin(gr.height(), sk.height());
320 if (height < kRowCount) {
321 return true;
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000322 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000323 int errorTotal = 0;
324 SkTArray<int, true> errorRows;
325 errorRows.push_back_n(width * kRowCount);
326 SkAutoLockPixels autoGr(gr);
327 SkAutoLockPixels autoSk(sk);
328 for (int y = 0; y < height; ++y) {
329 SkPMColor* grRow = gr.getAddr32(0, y);
330 SkPMColor* skRow = sk.getAddr32(0, y);
331 int* base = &errorRows[0];
332 int* cOut = &errorRows[y % kRowCount];
333 for (int x = 0; x < width; ++x) {
334 SkPMColor grColor = grRow[x];
335 SkPMColor skColor = skRow[x];
336 int dr = SkGetPackedR32(grColor) - SkGetPackedR32(skColor);
337 int dg = SkGetPackedG32(grColor) - SkGetPackedG32(skColor);
338 int db = SkGetPackedB32(grColor) - SkGetPackedB32(skColor);
339 int error = cOut[x] = SkTMax(SkAbs32(dr), SkTMax(SkAbs32(dg), SkAbs32(db)));
340 if (error < kThreshold || x < 2) {
341 continue;
342 }
343 if (base[x - 2] < kThreshold
344 || base[width + x - 2] < kThreshold
345 || base[width * 2 + x - 2] < kThreshold
346 || base[x - 1] < kThreshold
347 || base[width + x - 1] < kThreshold
348 || base[width * 2 + x - 1] < kThreshold
349 || base[x] < kThreshold
350 || base[width + x] < kThreshold
351 || base[width * 2 + x] < kThreshold) {
352 continue;
353 }
354 errorTotal += error;
355 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000356 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000357 return errorTotal;
358}
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000359
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000360static bool addError(TestState* data, const TestResult& testResult) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000361 if (testResult.fPixelError <= 0 && testResult.fTime <= 0) {
362 return false;
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000363 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000364 int worstCount = data->fPixelWorst.count();
365 int pixelError = testResult.fPixelError;
366 if (pixelError > 0) {
367 for (int index = 0; index < worstCount; ++index) {
368 if (pixelError > data->fPixelWorst[index].fPixelError) {
369 data->fPixelWorst[index] = *(SortByPixel*) &testResult;
370 return true;
371 }
372 }
373 }
374 int slowCount = data->fSlowest.count();
375 int time = testResult.fTime;
376 if (time > 0) {
377 for (int index = 0; index < slowCount; ++index) {
378 if (time > data->fSlowest[index].fTime) {
379 data->fSlowest[index] = *(SortByTime*) &testResult;
380 return true;
381 }
382 }
383 }
384 if (pixelError > 0 && worstCount < kMaxFiles) {
385 *data->fPixelWorst.append() = *(SortByPixel*) &testResult;
386 return true;
387 }
388 if (time > 0 && slowCount < kMaxFiles) {
389 *data->fSlowest.append() = *(SortByTime*) &testResult;
390 return true;
391 }
392 return false;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000393}
394
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000395static SkMSec timePict(SkPicture* pic, SkCanvas* canvas) {
396 canvas->save();
397 int pWidth = pic->width();
398 int pHeight = pic->height();
399 const int maxDimension = 1000;
400 const int slices = 3;
401 int xInterval = SkTMax(pWidth - maxDimension, 0) / (slices - 1);
402 int yInterval = SkTMax(pHeight - maxDimension, 0) / (slices - 1);
skia.committer@gmail.comf54ad6f2013-11-02 07:02:02 +0000403 SkRect rect = {0, 0, SkIntToScalar(SkTMin(maxDimension, pWidth)),
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000404 SkIntToScalar(SkTMin(maxDimension, pHeight))};
405 canvas->clipRect(rect);
406 SkMSec start = SkTime::GetMSecs();
407 for (int x = 0; x < slices; ++x) {
408 for (int y = 0; y < slices; ++y) {
409 pic->draw(canvas);
410 canvas->translate(0, SkIntToScalar(yInterval));
411 }
412 canvas->translate(SkIntToScalar(xInterval), SkIntToScalar(-yInterval * slices));
413 }
414 SkMSec end = SkTime::GetMSecs();
415 canvas->restore();
416 return end - start;
417}
418
419static void drawPict(SkPicture* pic, SkCanvas* canvas, int scale) {
420 canvas->clear(SK_ColorWHITE);
421 if (scale != 1) {
422 canvas->save();
423 canvas->scale(1.0f / scale, 1.0f / scale);
424 }
425 pic->draw(canvas);
426 if (scale != 1) {
427 canvas->restore();
428 }
429}
430
431static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pngName) {
caryclark19eb3b22014-07-18 05:08:14 -0700432 SkString outFile = get_sum_path(outDir);
433 outFile.appendf("%s%s", PATH_SLASH, pngName);
434 if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100)) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000435 SkDebugf("unable to encode gr %s (width=%d height=%d)\n", pngName,
436 bitmap.width(), bitmap.height());
437 }
438}
439
440void TestResult::testOne() {
441 SkPicture* pic = NULL;
442 {
443 #if DEBUG_SHOW_TEST_NAME
444 if (fTestStep == kCompareBits) {
445 SkString testName(fFilename);
446 const char http[] = "http";
447 if (testName.startsWith(http)) {
448 testName.remove(0, sizeof(http) - 1);
449 }
450 while (testName.startsWith("_")) {
451 testName.remove(0, 1);
452 }
453 const char dotSkp[] = ".skp";
454 if (testName.endsWith(dotSkp)) {
455 size_t len = testName.size();
456 testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1);
457 }
458 testName.prepend("skp");
459 testName.append("1");
460 strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRING_LENGTH);
461 } else if (fTestStep == kEncodeFiles) {
462 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
463 }
464 #endif
caryclark19eb3b22014-07-18 05:08:14 -0700465 SkString path = get_in_path(fDirNo, fFilename);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000466 SkFILEStream stream(path.c_str());
467 if (!stream.isValid()) {
468 SkDebugf("invalid stream %s\n", path.c_str());
469 goto finish;
470 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000471 pic = SkPicture::CreateFromStream(&stream, &SkImageDecoder::DecodeMemory);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000472 if (!pic) {
473 SkDebugf("unable to decode %s\n", fFilename);
474 goto finish;
475 }
476 int width = pic->width();
477 int height = pic->height();
478 SkBitmap oldBitmap, opBitmap;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000479 fScale = 1;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000480 while (width / fScale > 32767 || height / fScale > 32767) {
481 ++fScale;
482 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000483 do {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000484 int dimX = (width + fScale - 1) / fScale;
485 int dimY = (height + fScale - 1) / fScale;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +0000486 if (oldBitmap.allocN32Pixels(dimX, dimY) &&
487 opBitmap.allocN32Pixels(dimX, dimY)) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000488 break;
489 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000490 SkDebugf("-%d-", fScale);
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000491 } while (++fScale < 256);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000492 if (fScale >= 256) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000493 SkDebugf("unable to allocate bitmap for %s (w=%d h=%d)\n", fFilename,
494 width, height);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000495 goto finish;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000496 }
497 oldBitmap.eraseColor(SK_ColorWHITE);
498 SkCanvas oldCanvas(oldBitmap);
499 oldCanvas.setAllowSimplifyClip(false);
500 opBitmap.eraseColor(SK_ColorWHITE);
501 SkCanvas opCanvas(opBitmap);
502 opCanvas.setAllowSimplifyClip(true);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000503 drawPict(pic, &oldCanvas, fScale);
504 drawPict(pic, &opCanvas, fScale);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000505 if (fTestStep == kCompareBits) {
506 fPixelError = similarBits(oldBitmap, opBitmap);
507 int oldTime = timePict(pic, &oldCanvas);
508 int opTime = timePict(pic, &opCanvas);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000509 fTime = SkTMax(0, oldTime - opTime);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000510 } else if (fTestStep == kEncodeFiles) {
511 SkString pngStr = make_png_name(fFilename);
512 const char* pngName = pngStr.c_str();
513 writePict(oldBitmap, outOldDir, pngName);
514 writePict(opBitmap, outOpDir, pngName);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000515 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000516 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000517finish:
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000518 if (pic) {
519 pic->unref();
520 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000521}
522
caryclark19eb3b22014-07-18 05:08:14 -0700523DEFINE_string2(match, m, "PathOpsSkpClipThreaded",
524 "[~][^]substring[$] [...] of test name to run.\n"
525 "Multiple matches may be separated by spaces.\n"
526 "~ causes a matching test to always be skipped\n"
527 "^ requires the start of the test to match\n"
528 "$ requires the end of the test to match\n"
529 "^ and $ requires an exact match\n"
530 "If a test does not match any list entry,\n"
531 "it is skipped unless some list entry starts with ~");
532DEFINE_string2(dir, d, NULL, "range of directories (e.g., 1-100)");
533DEFINE_string2(skp, s, NULL, "skp to test");
534DEFINE_bool2(single, z, false, "run tests on a single thread internally.");
535DEFINE_int32(testIndex, 0, "override local test index (PathOpsSkpClipOneOff only).");
536DEFINE_int32(threads, SkThreadPool::kThreadPerCore,
537 "Run threadsafe tests on a threadpool with this many threads.");
538DEFINE_bool2(verbose, v, false, "enable verbose output.");
539
540static bool verbose() {
541 return FLAGS_verbose;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000542}
543
caryclark19eb3b22014-07-18 05:08:14 -0700544static int getThreadCount() {
545 return FLAGS_single ? 1 : FLAGS_threads;
546}
547
548class Dirs {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000549public:
caryclark19eb3b22014-07-18 05:08:14 -0700550 Dirs() {
551 reset();
552 sk_bzero(fRun, sizeof(fRun));
553 fSet = false;
554 }
555
556 int first() const {
557 int index = 0;
558 while (++index < kMaxDir) {
559 if (fRun[index]) {
560 return index;
561 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000562 }
caryclark19eb3b22014-07-18 05:08:14 -0700563 SkASSERT(0);
564 return -1;
565 }
566
567 int last() const {
568 int index = kMaxDir;
569 while (--index > 0 && !fRun[index])
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000570 ;
caryclark19eb3b22014-07-18 05:08:14 -0700571 return index;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000572 }
573
caryclark19eb3b22014-07-18 05:08:14 -0700574 int next() {
575 while (++fIndex < kMaxDir) {
576 if (fRun[fIndex]) {
577 return fIndex;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000578 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000579 }
caryclark19eb3b22014-07-18 05:08:14 -0700580 return -1;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000581 }
582
caryclark19eb3b22014-07-18 05:08:14 -0700583 void reset() {
584 fIndex = -1;
585 }
586
587 void set(int start, int end) {
588 while (start < end) {
589 fRun[start++] = 1;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000590 }
caryclark19eb3b22014-07-18 05:08:14 -0700591 fSet = true;
592 }
593
594 void setDefault() {
595 if (!fSet) {
596 set(1, 100);
597 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000598 }
599
600private:
caryclark19eb3b22014-07-18 05:08:14 -0700601 enum {
602 kMaxDir = 101
603 };
604 char fRun[kMaxDir];
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000605 int fIndex;
caryclark19eb3b22014-07-18 05:08:14 -0700606 bool fSet;
607} gDirs;
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000608
caryclark19eb3b22014-07-18 05:08:14 -0700609class Filenames {
610public:
611 Filenames()
612 : fIndex(-1) {
613 }
614
615 const char* next() {
616 while (fNames && ++fIndex < fNames->count()) {
617 return (*fNames)[fIndex];
618 }
619 return NULL;
620 }
621
622 void set(const SkCommandLineFlags::StringArray& names) {
623 fNames = &names;
624 }
625
626private:
627 int fIndex;
628 const SkCommandLineFlags::StringArray* fNames;
629} gNames;
630
631static bool buildTestDir(int dirNo, int firstDirNo,
632 SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sorted) {
633 SkString dirName = get_out_path(dirNo, outStatusDir);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000634 if (!dirName.size()) {
635 return false;
636 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000637 SkOSFile::Iter iter(dirName.c_str(), "skp");
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000638 SkString filename;
639 while (iter.next(&filename)) {
caryclark19eb3b22014-07-18 05:08:14 -0700640 TestResult test;
641 test.init(dirNo);
642 SkString spaceFile(filename);
643 char* spaces = spaceFile.writable_str();
644 int spaceSize = (int) spaceFile.size();
645 for (int index = 0; index < spaceSize; ++index) {
646 if (spaces[index] == '.') {
647 spaces[index] = ' ';
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000648 }
649 }
caryclark19eb3b22014-07-18 05:08:14 -0700650 int success = sscanf(spaces, "%s %d %d skp", test.fFilename,
651 &test.fPixelError, &test.fTime);
652 if (success < 3) {
653 SkDebugf("failed to scan %s matched=%d\n", filename.c_str(), success);
654 return false;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000655 }
caryclark19eb3b22014-07-18 05:08:14 -0700656 *tests[dirNo - firstDirNo].append() = test;
657 }
658 if (!sorted) {
659 return true;
660 }
661 SkTDArray<TestResult>& testSet = tests[dirNo - firstDirNo];
662 int count = testSet.count();
663 for (int index = 0; index < count; ++index) {
664 *sorted[dirNo - firstDirNo].append() = (SortByName*) &testSet[index];
665 }
666 if (sorted[dirNo - firstDirNo].count()) {
667 SkTQSort<SortByName>(sorted[dirNo - firstDirNo].begin(),
668 sorted[dirNo - firstDirNo].end() - 1);
669 if (verbose()) {
670 SkDebugf("+");
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000671 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000672 }
673 return true;
674}
675
caryclark19eb3b22014-07-18 05:08:14 -0700676static void testSkpClip(TestState* data) {
677 data->fResult.testOne();
678 SkString statName(data->fResult.fFilename);
679 SkASSERT(statName.endsWith(".skp"));
680 statName.remove(statName.size() - 4, 4);
681 statName.appendf(".%d.%d.skp", data->fResult.fPixelError, data->fResult.fTime);
682 SkString statusFile = get_out_path(data->fResult.fDirNo, outStatusDir);
683 if (!statusFile.size()) {
684 SkDebugf("failed to create %s", statusFile.c_str());
685 return;
686 }
687 statusFile.appendf("%s%s", PATH_SLASH, statName.c_str());
688 SkFILE* file = sk_fopen(statusFile.c_str(), kWrite_SkFILE_Flag);
689 if (!file) {
690 SkDebugf("failed to create %s", statusFile.c_str());
691 return;
692 }
693 sk_fclose(file);
694 if (verbose()) {
695 if (data->fResult.fPixelError || data->fResult.fTime) {
696 SkDebugf("%s", data->fResult.progress().c_str());
697 } else {
698 SkDebugf(".");
699 }
700 }
701}
702
703bool Less(const SortByName& a, const SortByName& b);
704bool Less(const SortByName& a, const SortByName& b) {
705 return a < b;
706}
707
708static bool doOneDir(TestState* state, bool threaded) {
709 int dirNo = state->fResult.fDirNo;
710 SkString dirName = get_in_path(dirNo, NULL);
711 if (!dirName.size()) {
712 return false;
713 }
714 SkTDArray<TestResult> tests[1];
715 SkTDArray<SortByName*> sorted[1];
716 if (!buildTestDir(dirNo, dirNo, tests, sorted)) {
717 return false;
718 }
719 SkOSFile::Iter iter(dirName.c_str(), "skp");
720 SkString filename;
721 while (iter.next(&filename)) {
722 for (size_t index = 0; index < skipOverCount; ++index) {
723 if (skipOver[index].directory == dirNo
724 && strcmp(filename.c_str(), skipOver[index].filename) == 0) {
725 goto checkEarlyExit;
726 }
727 }
728 {
729 SortByName name;
730 name.init(dirNo);
731 strncpy(name.fFilename, filename.c_str(), filename.size() - 4); // drop .skp
732 int count = sorted[0].count();
733 int idx = SkTSearch<SortByName, Less>(sorted[0].begin(), count, &name, sizeof(&name));
734 if (idx >= 0) {
735 SortByName* found = sorted[0][idx];
736 (void) addError(state, *found);
737 continue;
738 }
739 TestResult test;
740 test.init(dirNo, filename);
741 state->fResult = test;
742 testSkpClip(state);
743#if 0 // artificially limit to a few while debugging code
744 static int debugLimit = 0;
745 if (++debugLimit == 5) {
746 return true;
747 }
748#endif
749 }
750checkEarlyExit:
751 ;
752 }
753 return true;
754}
755
756static void initTest() {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000757#if !defined SK_BUILD_FOR_WIN && !defined SK_BUILD_FOR_MAC
758 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true);
759 SK_CONF_SET("images.png.suppressDecoderWarnings", true);
760#endif
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000761}
762
caryclarkdac1d172014-06-17 05:15:38 -0700763static void testSkpClipEncode(TestState* data) {
764 data->fResult.testOne();
caryclark19eb3b22014-07-18 05:08:14 -0700765 if (verbose()) {
766 SkDebugf("+");
caryclarkdac1d172014-06-17 05:15:38 -0700767 }
768}
769
caryclark19eb3b22014-07-18 05:08:14 -0700770static void encodeFound(TestState& state) {
771 if (verbose()) {
caryclarkdac1d172014-06-17 05:15:38 -0700772 if (state.fPixelWorst.count()) {
773 SkTDArray<SortByPixel*> worst;
774 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
775 *worst.append() = &state.fPixelWorst[index];
776 }
777 SkTQSort<SortByPixel>(worst.begin(), worst.end() - 1);
778 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
779 const TestResult& result = *worst[index];
780 SkDebugf("%d %s pixelError=%d\n", result.fDirNo, result.fFilename, result.fPixelError);
781 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000782 }
caryclarkdac1d172014-06-17 05:15:38 -0700783 if (state.fSlowest.count()) {
784 SkTDArray<SortByTime*> slowest;
785 for (int index = 0; index < state.fSlowest.count(); ++index) {
786 *slowest.append() = &state.fSlowest[index];
787 }
788 if (slowest.count() > 0) {
789 SkTQSort<SortByTime>(slowest.begin(), slowest.end() - 1);
790 for (int index = 0; index < slowest.count(); ++index) {
791 const TestResult& result = *slowest[index];
792 SkDebugf("%d %s time=%d\n", result.fDirNo, result.fFilename, result.fTime);
793 }
794 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000795 }
796 }
caryclark19eb3b22014-07-18 05:08:14 -0700797 int threadCount = getThreadCount();
798 TestRunner testRunner(threadCount);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000799 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
800 const TestResult& result = state.fPixelWorst[index];
caryclarkdac1d172014-06-17 05:15:38 -0700801 SkString filename(result.fFilename);
802 if (!filename.endsWith(".skp")) {
803 filename.append(".skp");
804 }
805 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableEncode,
806 (&testSkpClipEncode, result.fDirNo, filename.c_str(), &testRunner));
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000807 }
caryclarkdac1d172014-06-17 05:15:38 -0700808 testRunner.render();
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000809}
810
caryclark19eb3b22014-07-18 05:08:14 -0700811class Test {
812public:
813 Test() {}
814 virtual ~Test() {}
815
816 const char* getName() { onGetName(&fName); return fName.c_str(); }
817 void run() { onRun(); }
818
819protected:
820 virtual void onGetName(SkString*) = 0;
821 virtual void onRun() = 0;
822
823private:
824 SkString fName;
825};
826
827typedef SkTRegistry<Test*(*)(void*)> TestRegistry;
828
829#define DEF_TEST(name) \
830 static void test_##name(); \
831 class name##Class : public Test { \
832 public: \
833 static Test* Factory(void*) { return SkNEW(name##Class); } \
834 protected: \
835 virtual void onGetName(SkString* name) SK_OVERRIDE { \
836 name->set(#name); \
837 } \
838 virtual void onRun() SK_OVERRIDE { test_##name(); } \
839 }; \
840 static TestRegistry gReg_##name##Class(name##Class::Factory); \
841 static void test_##name()
842
843DEF_TEST(PathOpsSkpClip) {
844 gDirs.setDefault();
845 initTest();
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000846 SkTArray<TestResult, true> errors;
847 TestState state;
caryclark19eb3b22014-07-18 05:08:14 -0700848 state.init(0);
849 int dirNo;
850 gDirs.reset();
851 while ((dirNo = gDirs.next()) > 0) {
852 if (verbose()) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000853 SkDebugf("dirNo=%d\n", dirNo);
854 }
855 state.fResult.fDirNo = dirNo;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000856 if (!doOneDir(&state, false)) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000857 break;
858 }
859 }
caryclark19eb3b22014-07-18 05:08:14 -0700860 encodeFound(state);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000861}
862
863static void testSkpClipMain(TestState* data) {
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000864 (void) doOneDir(data, true);
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000865}
866
caryclark19eb3b22014-07-18 05:08:14 -0700867DEF_TEST(PathOpsSkpClipThreaded) {
868 gDirs.setDefault();
869 initTest();
870 int threadCount = getThreadCount();
871 TestRunner testRunner(threadCount);
872 int dirNo;
873 gDirs.reset();
874 while ((dirNo = gDirs.next()) > 0) {
caryclarkdac1d172014-06-17 05:15:38 -0700875 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableDir,
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000876 (&testSkpClipMain, dirNo, &testRunner));
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000877 }
878 testRunner.render();
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000879 TestState state;
caryclark19eb3b22014-07-18 05:08:14 -0700880 state.init(0);
881 gDirs.reset();
882 while ((dirNo = gDirs.next()) > 0) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000883 TestState& testState = testRunner.fRunnables[dirNo - 1]->fState;
caryclarkdac1d172014-06-17 05:15:38 -0700884 SkASSERT(testState.fResult.fDirNo == dirNo);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000885 for (int inner = 0; inner < testState.fPixelWorst.count(); ++inner) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000886 addError(&state, testState.fPixelWorst[inner]);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000887 }
caryclarkdac1d172014-06-17 05:15:38 -0700888 for (int inner = 0; inner < testState.fSlowest.count(); ++inner) {
889 addError(&state, testState.fSlowest[inner]);
890 }
891 }
caryclark19eb3b22014-07-18 05:08:14 -0700892 encodeFound(state);
caryclarkdac1d172014-06-17 05:15:38 -0700893}
caryclark19eb3b22014-07-18 05:08:14 -0700894
895static bool buildTests(SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sorted) {
896 int firstDirNo = gDirs.first();
897 int dirNo;
898 while ((dirNo = gDirs.next()) > 0) {
899 if (!buildTestDir(dirNo, firstDirNo, tests, sorted)) {
caryclarkdac1d172014-06-17 05:15:38 -0700900 return false;
901 }
caryclarkdac1d172014-06-17 05:15:38 -0700902 }
903 return true;
904}
905
caryclark19eb3b22014-07-18 05:08:14 -0700906DEF_TEST(PathOpsSkpClipUberThreaded) {
907 gDirs.setDefault();
908 const int firstDirNo = gDirs.next();
909 const int lastDirNo = gDirs.last();
910 initTest();
911 int dirCount = lastDirNo - firstDirNo + 1;
912 SkAutoTDeleteArray<SkTDArray<TestResult> > tests(new SkTDArray<TestResult>[dirCount]);
913 SkAutoTDeleteArray<SkTDArray<SortByName*> > sorted(new SkTDArray<SortByName*>[dirCount]);
914 if (!buildTests(tests.get(), sorted.get())) {
caryclarkdac1d172014-06-17 05:15:38 -0700915 return;
916 }
caryclark19eb3b22014-07-18 05:08:14 -0700917 int threadCount = getThreadCount();
918 TestRunner testRunner(threadCount);
919 int dirNo;
920 gDirs.reset();
921 while ((dirNo = gDirs.next()) > 0) {
922 SkString dirName = get_in_path(dirNo, NULL);
caryclarkdac1d172014-06-17 05:15:38 -0700923 if (!dirName.size()) {
924 continue;
925 }
926 SkOSFile::Iter iter(dirName.c_str(), "skp");
927 SkString filename;
928 while (iter.next(&filename)) {
caryclark19eb3b22014-07-18 05:08:14 -0700929 for (size_t index = 0; index < skipOverCount; ++index) {
930 if (skipOver[index].directory == dirNo
931 && strcmp(filename.c_str(), skipOver[index].filename) == 0) {
caryclarkdac1d172014-06-17 05:15:38 -0700932 goto checkEarlyExit;
933 }
934 }
caryclark19eb3b22014-07-18 05:08:14 -0700935 {
936 SortByName name;
937 name.init(dirNo);
938 strncpy(name.fFilename, filename.c_str(), filename.size() - 4); // drop .skp
939 int count = sorted.get()[dirNo - firstDirNo].count();
940 if (SkTSearch<SortByName, Less>(sorted.get()[dirNo - firstDirNo].begin(),
941 count, &name, sizeof(&name)) < 0) {
942 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableFile,
943 (&testSkpClip, dirNo, filename.c_str(), &testRunner));
944 }
caryclarkdac1d172014-06-17 05:15:38 -0700945 }
946 checkEarlyExit:
947 ;
948 }
949
950 }
951 testRunner.render();
caryclark19eb3b22014-07-18 05:08:14 -0700952 SkAutoTDeleteArray<SkTDArray<TestResult> > results(new SkTDArray<TestResult>[dirCount]);
953 if (!buildTests(results.get(), NULL)) {
caryclarkdac1d172014-06-17 05:15:38 -0700954 return;
955 }
956 SkTDArray<TestResult> allResults;
957 for (int dirNo = firstDirNo; dirNo <= lastDirNo; ++dirNo) {
caryclark19eb3b22014-07-18 05:08:14 -0700958 SkTDArray<TestResult>& array = results.get()[dirNo - firstDirNo];
caryclarkdac1d172014-06-17 05:15:38 -0700959 allResults.append(array.count(), array.begin());
960 }
961 int allCount = allResults.count();
962 SkTDArray<SortByPixel*> pixels;
963 SkTDArray<SortByTime*> times;
964 for (int index = 0; index < allCount; ++index) {
965 *pixels.append() = (SortByPixel*) &allResults[index];
966 *times.append() = (SortByTime*) &allResults[index];
967 }
968 TestState state;
969 if (pixels.count()) {
970 SkTQSort<SortByPixel>(pixels.begin(), pixels.end() - 1);
971 for (int inner = 0; inner < kMaxFiles; ++inner) {
972 *state.fPixelWorst.append() = *pixels[allCount - inner - 1];
973 }
974 }
975 if (times.count()) {
976 SkTQSort<SortByTime>(times.begin(), times.end() - 1);
977 for (int inner = 0; inner < kMaxFiles; ++inner) {
978 *state.fSlowest.append() = *times[allCount - inner - 1];
979 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000980 }
caryclark19eb3b22014-07-18 05:08:14 -0700981 encodeFound(state);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000982}
983
caryclark19eb3b22014-07-18 05:08:14 -0700984DEF_TEST(PathOpsSkpClipOneOff) {
985 const int testIndex = FLAGS_testIndex;
986 int dirNo = gDirs.next();
987 if (dirNo < 0) {
988 dirNo = skipOver[testIndex].directory;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000989 }
caryclark19eb3b22014-07-18 05:08:14 -0700990 const char* skp = gNames.next();
991 if (!skp) {
992 skp = skipOver[testIndex].filename;
993 }
994 initTest();
995 SkAssertResult(get_in_path(dirNo, skp).size());
996 SkString filename(skp);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000997 TestResult state;
998 state.test(dirNo, filename);
caryclark19eb3b22014-07-18 05:08:14 -0700999 if (verbose()) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +00001000 SkDebugf("%s", state.status().c_str());
1001 }
1002 state.fTestStep = kEncodeFiles;
1003 state.testOne();
caryclark@google.com07e97fc2013-07-08 17:17:02 +00001004}
caryclark19eb3b22014-07-18 05:08:14 -07001005
1006DEF_TEST(PathOpsTestSkipped) {
1007 for (size_t index = 0; index < skipOverCount; ++index) {
1008 const SkipOverTest& skip = skipOver[index];
1009 if (!skip.blamePathOps) {
1010 continue;
1011 }
1012 int dirNo = skip.directory;
1013 const char* skp = skip.filename;
1014 initTest();
1015 SkAssertResult(get_in_path(dirNo, skp).size());
1016 SkString filename(skp);
1017 TestResult state;
1018 state.test(dirNo, filename);
1019 if (verbose()) {
1020 SkDebugf("%s", state.status().c_str());
1021 }
1022 state.fTestStep = kEncodeFiles;
1023 state.testOne();
1024 }
1025}
1026
1027DEF_TEST(PathOpsCopyFails) {
1028 FLAGS_verbose = true;
1029 for (size_t index = 0; index < skipOverCount; ++index) {
1030 int dirNo = skipOver[index].directory;
1031 SkDebugf("mkdir -p " IN_DIR_PRE "%d" DIR_POST "\n", dirNo);
1032 }
1033 for (size_t index = 0; index < skipOverCount; ++index) {
1034 int dirNo = skipOver[index].directory;
1035 const char* filename = skipOver[index].filename;
1036 SkDebugf("rsync -av cary-linux.cnc:/tera" PATH_SLASH "skps" PATH_SLASH "slave"
1037 "%d" DIR_POST "/%s " IN_DIR_PRE "%d" DIR_POST "\n", dirNo, filename, dirNo);
1038 }
1039}
1040
1041template TestRegistry* TestRegistry::gHead;
1042
1043class Iter {
1044public:
1045 Iter() { this->reset(); }
1046 void reset() { fReg = TestRegistry::Head(); }
1047
1048 Test* next() {
1049 if (fReg) {
1050 TestRegistry::Factory fact = fReg->factory();
1051 fReg = fReg->next();
1052 Test* test = fact(NULL);
1053 return test;
1054 }
1055 return NULL;
1056 }
1057
1058private:
1059 const TestRegistry* fReg;
1060};
1061
1062int tool_main(int argc, char** argv);
1063int tool_main(int argc, char** argv) {
1064 SetupCrashHandler();
1065 SkCommandLineFlags::SetUsage("");
1066 SkCommandLineFlags::Parse(argc, argv);
1067 SkGraphics::Init();
1068 SkString header("PathOps SkpClip:");
1069 if (!FLAGS_match.isEmpty()) {
1070 header.appendf(" --match");
1071 for (int index = 0; index < FLAGS_match.count(); ++index) {
1072 header.appendf(" %s", FLAGS_match[index]);
1073 }
1074 }
1075 if (!FLAGS_dir.isEmpty()) {
1076 int count = FLAGS_dir.count();
1077 for (int i = 0; i < count; ++i) {
1078 const char* range = FLAGS_dir[i];
1079 const char* dash = strchr(range, '-');
1080 if (!dash) {
1081 dash = strchr(range, ',');
1082 }
1083 int first = atoi(range);
1084 int last = dash ? atoi(dash + 1) : first;
1085 if (!first || !last) {
1086 SkDebugf("couldn't parse --dir %s\n", range);
1087 return 1;
1088 }
1089 gDirs.set(first, last);
1090 }
1091 }
1092 if (!FLAGS_skp.isEmpty()) {
1093 gNames.set(FLAGS_skp);
1094 }
1095#ifdef SK_DEBUG
1096 header.append(" SK_DEBUG");
1097#else
1098 header.append(" SK_RELEASE");
1099#endif
1100 header.appendf(" skia_arch_width=%d", (int)sizeof(void*) * 8);
1101 if (FLAGS_verbose) {
1102 header.appendf("\n");
1103 }
1104 SkDebugf(header.c_str());
1105 Iter iter;
1106 Test* test;
1107 while ((test = iter.next()) != NULL) {
1108 SkAutoTDelete<Test> owned(test);
1109 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) {
1110 test->run();
1111 }
1112 }
1113 SkGraphics::Term();
1114 return 0;
1115}
1116
1117#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
1118int main(int argc, char * const argv[]) {
1119 return tool_main(argc, (char**) argv);
1120}
1121#endif