blob: 1f69ff05e1832563be36ac69ca507d653c98e3b5 [file] [log] [blame]
borenet48087572015-04-02 12:16:36 -07001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
caryclark19eb3b22014-07-18 05:08:14 -07008#include "CrashHandler.h"
9// #include "OverwriteLine.h"
10#include "Resources.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000011#include "SkBitmap.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000012#include "SkCanvas.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000013#include "SkColor.h"
14#include "SkColorPriv.h"
caryclark19eb3b22014-07-18 05:08:14 -070015#include "SkCommandLineFlags.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000016#include "SkDevice.h"
caryclark19eb3b22014-07-18 05:08:14 -070017#include "SkForceLinking.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000018#include "SkGraphics.h"
caryclark@google.comcffbcc32013-06-04 17:59:42 +000019#include "SkImageDecoder.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000020#include "SkImageEncoder.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000021#include "SkOSFile.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000022#include "SkPathOpsDebug.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000023#include "SkPicture.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000024#include "SkRTConf.h"
reed89889b62014-10-29 12:36:45 -070025#include "SkRunnable.h"
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000026#include "SkTSort.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000027#include "SkStream.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000028#include "SkString.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000029#include "SkTArray.h"
30#include "SkTDArray.h"
mtklein406654b2014-09-03 15:34:37 -070031#include "SkTaskGroup.h"
caryclark19eb3b22014-07-18 05:08:14 -070032#include "SkTemplates.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000033#include "SkTime.h"
caryclark@google.com07e97fc2013-07-08 17:17:02 +000034
caryclark19eb3b22014-07-18 05:08:14 -070035__SK_FORCE_IMAGE_DECODER_LINKING;
caryclark@google.com07e97fc2013-07-08 17:17:02 +000036
caryclark19eb3b22014-07-18 05:08:14 -070037/* add local exceptions here */
38/* TODO : add command flag interface */
39const struct SkipOverTest {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000040 int directory;
41 const char* filename;
caryclark19eb3b22014-07-18 05:08:14 -070042 bool blamePathOps;
43} skipOver[] = {
44 { 2, "http___www_groupon_sg_.skp", false}, // SkAAClip::Builder::addRun SkASSERT(fBounds.contains(x, y));
45 { 6, "http___www_googleventures_com_.skp", true}, // addTCoincident SkASSERT(test->fT < 1);
46 { 7, "http___www_foxsports_nl_.skp", true}, // (no repro on mac) addT SkASSERT(this != other || fVerb == SkPath::kCubic_Verb)
47 {13, "http___www_modernqigong_com_.skp", false}, // SkAAClip::Builder::addRun SkASSERT(fBounds.contains(x, y));
48 {14, "http___www_devbridge_com_.skp", true}, // checkSmallCoincidence SkASSERT(!next->fSmall || checkMultiple);
caryclark5e27e0e2014-08-12 07:46:33 -070049 {16, "http___www_1023world_net_.skp", false}, // bitmap decode assert (corrupt skp?)
caryclark19eb3b22014-07-18 05:08:14 -070050 {19, "http___www_alamdi_com_.skp", true}, // cubic/quad intersection
51 {26, "http___www_liveencounters_net_.skp", true}, // (no repro on mac) checkSmall addT:549 (line, expects cubic)
52 {28, "http___www_encros_fr_.skp", false}, // SkAAClip::Builder::addRun SkASSERT(fBounds.contains(x, y));
53 {37, "http___www_familysurvivalprotocol_wordpress_com_.skp", true}, // bumpSpan SkASSERT(span->fOppValue >= 0);
54 {39, "http___sufeinet_com_.skp", false}, // bitmap decode assert (corrupt skp?)
55 {41, "http___www_rano360_com_.skp", true}, // checkSmallCoincidence SkASSERT(!next->fSmall || checkMultiple);
56 {44, "http___www_firstunitedbank_com_.skp", true}, // addTCancel SkASSERT(oIndex > 0);
57 {46, "http___www_shinydemos_com_.skp", true}, // addSimpleAngle SkASSERT(index == count() - 2);
58 {48, "http___www_familysurvivalprotocol_com_.skp", true}, // bumpSpan SkASSERT "span->fOppValue >= 0"
59 {57, "http___www_lptemp_com_.skp", true}, // addTCoincident oPeek = &other->fTs[++oPeekIndex];
60 {71, "http___www_1milyonkahraman_org_.skp", true}, // addTCoincident SkASSERT(test->fT < 1);
61 {88, "http___www_apuntesdelechuza_wordpress_com_.skp", true}, // bumpSpan SkASSERT "span->fOppValue >= 0"
62 {89, "http___www_mobilizedconsulting_com_.skp", true}, // addTCancel SkASSERT(oIndex > 0);
63 {93, "http___www_simple_living_in_suffolk_co_uk_.skp", true}, // bumpSpan SkASSERT "span->fOppValue >= 0"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000064};
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000065
caryclark19eb3b22014-07-18 05:08:14 -070066size_t skipOverCount = sizeof(skipOver) / sizeof(skipOver[0]);
caryclarkdac1d172014-06-17 05:15:38 -070067
caryclark19eb3b22014-07-18 05:08:14 -070068
69/* customize file in/out here */
70/* TODO : add command flag interface */
71#define CHROME_VERSION "1e5dfa4-4a995df"
72#define SUMMARY_RUN 1
73
74#ifdef SK_BUILD_FOR_WIN
75 #define DRIVE_SPEC "D:"
76 #define PATH_SLASH "\\"
77#else
78 #define DRIVE_SPEC ""
79 #define PATH_SLASH "/"
80#endif
81
82#define IN_DIR_PRE DRIVE_SPEC PATH_SLASH "skps" PATH_SLASH "slave"
83#define OUT_DIR_PRE DRIVE_SPEC PATH_SLASH "skpOut" PATH_SLASH "slave"
84#define OUT_DIR_SUM DRIVE_SPEC PATH_SLASH "skpOut" PATH_SLASH "summary"
85#define DIR_POST PATH_SLASH "All" PATH_SLASH CHROME_VERSION
86
87static const char outOpDir[] = "opClip";
88static const char outOldDir[] = "oldClip";
89static const char outStatusDir[] = "statusTest";
90
91static SkString get_in_path(int dirNo, const char* filename) {
92 SkString path;
93 SkASSERT(dirNo);
94 path.appendf("%s%d%s", IN_DIR_PRE, dirNo, DIR_POST);
95 if (!sk_exists(path.c_str())) {
96 SkDebugf("could not read %s\n", path.c_str());
97 return SkString();
98 }
99 if (filename) {
100 path.appendf("%s%s", PATH_SLASH, filename);
mtklein406654b2014-09-03 15:34:37 -0700101 if (!sk_exists(path.c_str())) {
caryclark19eb3b22014-07-18 05:08:14 -0700102 SkDebugf("could not read %s\n", path.c_str());
103 return SkString();
104 }
105 }
106 return path;
107}
mtklein406654b2014-09-03 15:34:37 -0700108
caryclark19eb3b22014-07-18 05:08:14 -0700109static void make_recursive_dir(const SkString& path) {
110 if (sk_exists(path.c_str())) {
111 return;
112 }
113 const char* pathStr = path.c_str();
114 int last = (int) path.size();
115 do {
116 while (last > 0 && pathStr[--last] != PATH_SLASH[0])
117 ;
118 SkASSERT(last > 0);
119 SkString shorter(pathStr, last);
120 if (sk_mkdir(shorter.c_str())) {
121 break;
122 }
123 } while (true);
124 do {
125 while (last < (int) path.size() && pathStr[++last] != PATH_SLASH[0])
126 ;
127 SkString shorter(pathStr, last);
128 SkAssertResult(sk_mkdir(shorter.c_str()));
129 } while (last < (int) path.size());
130}
131
132static SkString get_out_path(int dirNo, const char* dirName) {
133 SkString path;
134 SkASSERT(dirNo);
135 SkASSERT(dirName);
136 path.appendf("%s%d%s%s%s", OUT_DIR_PRE, dirNo, DIR_POST, PATH_SLASH, dirName);
137 make_recursive_dir(path);
138 return path;
139}
mtklein406654b2014-09-03 15:34:37 -0700140
caryclark19eb3b22014-07-18 05:08:14 -0700141static SkString get_sum_path(const char* dirName) {
142 SkString path;
143 SkASSERT(dirName);
144 path.appendf("%s%d%s%s", OUT_DIR_SUM, SUMMARY_RUN, PATH_SLASH, dirName);
145 SkDebugf("%s\n", path.c_str());
146 make_recursive_dir(path);
147 return path;
148}
149
150static SkString make_png_name(const char* filename) {
151 SkString pngName = SkString(filename);
152 pngName.remove(pngName.size() - 3, 3);
153 pngName.append("png");
154 return pngName;
155}
156
157////////////////////////////////////////////////////////
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000158
159enum TestStep {
160 kCompareBits,
161 kEncodeFiles,
162};
163
164enum {
caryclarkdac1d172014-06-17 05:15:38 -0700165 kMaxLength = 256,
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000166 kMaxFiles = 128,
167 kSmallLimit = 1000,
168};
169
170struct TestResult {
171 void init(int dirNo) {
172 fDirNo = dirNo;
173 sk_bzero(fFilename, sizeof(fFilename));
174 fTestStep = kCompareBits;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000175 fScale = 1;
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000176 }
mtklein406654b2014-09-03 15:34:37 -0700177
caryclark19eb3b22014-07-18 05:08:14 -0700178 void init(int dirNo, const SkString& filename) {
179 fDirNo = dirNo;
180 strcpy(fFilename, filename.c_str());
181 fTestStep = kCompareBits;
mtklein406654b2014-09-03 15:34:37 -0700182 fScale = 1;
caryclark19eb3b22014-07-18 05:08:14 -0700183 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000184
185 SkString status() {
186 SkString outStr;
187 outStr.printf("%s %d %d\n", fFilename, fPixelError, fTime);
188 return outStr;
189 }
190
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000191 SkString progress() {
192 SkString outStr;
193 outStr.printf("dir=%d %s ", fDirNo, fFilename);
194 if (fPixelError) {
195 outStr.appendf(" err=%d", fPixelError);
196 }
197 if (fTime) {
198 outStr.appendf(" time=%d", fTime);
199 }
200 if (fScale != 1) {
201 outStr.appendf(" scale=%d", fScale);
202 }
203 outStr.appendf("\n");
204 return outStr;
205
206 }
207
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000208 void test(int dirNo, const SkString& filename) {
209 init(dirNo);
210 strcpy(fFilename, filename.c_str());
211 testOne();
212 }
213
214 void testOne();
mtklein406654b2014-09-03 15:34:37 -0700215
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000216 char fFilename[kMaxLength];
217 TestStep fTestStep;
218 int fDirNo;
219 int fPixelError;
220 int fTime;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000221 int fScale;
222};
223
224class SortByPixel : public TestResult {
225public:
226 bool operator<(const SortByPixel& rh) const {
227 return fPixelError < rh.fPixelError;
228 }
229};
230
231class SortByTime : public TestResult {
232public:
233 bool operator<(const SortByTime& rh) const {
234 return fTime < rh.fTime;
235 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000236};
237
caryclarkdac1d172014-06-17 05:15:38 -0700238class SortByName : public TestResult {
239public:
240 bool operator<(const SortByName& rh) const {
241 return strcmp(fFilename, rh.fFilename) < 0;
242 }
243};
244
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000245struct TestState {
caryclark19eb3b22014-07-18 05:08:14 -0700246 void init(int dirNo) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000247 fResult.init(dirNo);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000248 }
249
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000250 SkTDArray<SortByPixel> fPixelWorst;
251 SkTDArray<SortByTime> fSlowest;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000252 TestResult fResult;
253};
254
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000255struct TestRunner {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000256 ~TestRunner();
257 void render();
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000258 SkTDArray<class TestRunnable*> fRunnables;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000259};
260
261class TestRunnable : public SkRunnable {
262public:
mtklein36352bf2015-03-25 18:17:31 -0700263 void run() override {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000264 SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024);
265 (*fTestFun)(&fState);
266 }
267
268 TestState fState;
269 void (*fTestFun)(TestState*);
270};
271
caryclarkdac1d172014-06-17 05:15:38 -0700272
273class TestRunnableDir : public TestRunnable {
274public:
275 TestRunnableDir(void (*testFun)(TestState*), int dirNo, TestRunner* runner) {
caryclark19eb3b22014-07-18 05:08:14 -0700276 fState.init(dirNo);
caryclarkdac1d172014-06-17 05:15:38 -0700277 fTestFun = testFun;
278 }
279
280};
281
282class TestRunnableFile : public TestRunnable {
283public:
284 TestRunnableFile(void (*testFun)(TestState*), int dirNo, const char* name, TestRunner* runner) {
caryclark19eb3b22014-07-18 05:08:14 -0700285 fState.init(dirNo);
caryclarkdac1d172014-06-17 05:15:38 -0700286 strcpy(fState.fResult.fFilename, name);
287 fTestFun = testFun;
288 }
289};
290
291class TestRunnableEncode : public TestRunnableFile {
292public:
293 TestRunnableEncode(void (*testFun)(TestState*), int dirNo, const char* name, TestRunner* runner)
294 : TestRunnableFile(testFun, dirNo, name, runner) {
295 fState.fResult.fTestStep = kEncodeFiles;
296 }
297};
298
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000299TestRunner::~TestRunner() {
300 for (int index = 0; index < fRunnables.count(); index++) {
301 SkDELETE(fRunnables[index]);
302 }
303}
304
305void TestRunner::render() {
mtklein406654b2014-09-03 15:34:37 -0700306 SkTaskGroup tg;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000307 for (int index = 0; index < fRunnables.count(); ++ index) {
mtklein406654b2014-09-03 15:34:37 -0700308 tg.add(fRunnables[index]);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000309 }
310}
311
312////////////////////////////////////////////////
313
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000314
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000315static int similarBits(const SkBitmap& gr, const SkBitmap& sk) {
316 const int kRowCount = 3;
317 const int kThreshold = 3;
318 int width = SkTMin(gr.width(), sk.width());
319 if (width < kRowCount) {
320 return true;
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000321 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000322 int height = SkTMin(gr.height(), sk.height());
323 if (height < kRowCount) {
324 return true;
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000325 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000326 int errorTotal = 0;
327 SkTArray<int, true> errorRows;
328 errorRows.push_back_n(width * kRowCount);
329 SkAutoLockPixels autoGr(gr);
330 SkAutoLockPixels autoSk(sk);
331 for (int y = 0; y < height; ++y) {
332 SkPMColor* grRow = gr.getAddr32(0, y);
333 SkPMColor* skRow = sk.getAddr32(0, y);
334 int* base = &errorRows[0];
335 int* cOut = &errorRows[y % kRowCount];
336 for (int x = 0; x < width; ++x) {
337 SkPMColor grColor = grRow[x];
338 SkPMColor skColor = skRow[x];
339 int dr = SkGetPackedR32(grColor) - SkGetPackedR32(skColor);
340 int dg = SkGetPackedG32(grColor) - SkGetPackedG32(skColor);
341 int db = SkGetPackedB32(grColor) - SkGetPackedB32(skColor);
342 int error = cOut[x] = SkTMax(SkAbs32(dr), SkTMax(SkAbs32(dg), SkAbs32(db)));
343 if (error < kThreshold || x < 2) {
344 continue;
345 }
346 if (base[x - 2] < kThreshold
347 || base[width + x - 2] < kThreshold
348 || base[width * 2 + x - 2] < kThreshold
349 || base[x - 1] < kThreshold
350 || base[width + x - 1] < kThreshold
351 || base[width * 2 + x - 1] < kThreshold
352 || base[x] < kThreshold
353 || base[width + x] < kThreshold
354 || base[width * 2 + x] < kThreshold) {
355 continue;
356 }
357 errorTotal += error;
358 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000359 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000360 return errorTotal;
361}
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000362
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000363static bool addError(TestState* data, const TestResult& testResult) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000364 if (testResult.fPixelError <= 0 && testResult.fTime <= 0) {
365 return false;
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000366 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000367 int worstCount = data->fPixelWorst.count();
368 int pixelError = testResult.fPixelError;
369 if (pixelError > 0) {
370 for (int index = 0; index < worstCount; ++index) {
371 if (pixelError > data->fPixelWorst[index].fPixelError) {
372 data->fPixelWorst[index] = *(SortByPixel*) &testResult;
373 return true;
374 }
375 }
376 }
377 int slowCount = data->fSlowest.count();
378 int time = testResult.fTime;
379 if (time > 0) {
380 for (int index = 0; index < slowCount; ++index) {
381 if (time > data->fSlowest[index].fTime) {
382 data->fSlowest[index] = *(SortByTime*) &testResult;
383 return true;
384 }
385 }
386 }
387 if (pixelError > 0 && worstCount < kMaxFiles) {
388 *data->fPixelWorst.append() = *(SortByPixel*) &testResult;
389 return true;
390 }
391 if (time > 0 && slowCount < kMaxFiles) {
392 *data->fSlowest.append() = *(SortByTime*) &testResult;
393 return true;
394 }
395 return false;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000396}
397
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000398static SkMSec timePict(SkPicture* pic, SkCanvas* canvas) {
399 canvas->save();
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700400 SkScalar pWidth = pic->cullRect().width();
401 SkScalar pHeight = pic->cullRect().height();
402 const SkScalar maxDimension = 1000.0f;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000403 const int slices = 3;
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700404 SkScalar xInterval = SkTMax(pWidth - maxDimension, 0.0f) / (slices - 1);
405 SkScalar yInterval = SkTMax(pHeight - maxDimension, 0.0f) / (slices - 1);
406 SkRect rect = {0, 0, SkTMin(maxDimension, pWidth), SkTMin(maxDimension, pHeight) };
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000407 canvas->clipRect(rect);
408 SkMSec start = SkTime::GetMSecs();
409 for (int x = 0; x < slices; ++x) {
410 for (int y = 0; y < slices; ++y) {
robertphillipsc5ba71d2014-09-04 08:42:50 -0700411 pic->playback(canvas);
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700412 canvas->translate(0, yInterval);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000413 }
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700414 canvas->translate(xInterval, -yInterval * slices);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000415 }
416 SkMSec end = SkTime::GetMSecs();
417 canvas->restore();
418 return end - start;
419}
420
421static void drawPict(SkPicture* pic, SkCanvas* canvas, int scale) {
422 canvas->clear(SK_ColorWHITE);
423 if (scale != 1) {
424 canvas->save();
425 canvas->scale(1.0f / scale, 1.0f / scale);
426 }
robertphillipsc5ba71d2014-09-04 08:42:50 -0700427 pic->playback(canvas);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000428 if (scale != 1) {
429 canvas->restore();
430 }
431}
432
433static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pngName) {
caryclark19eb3b22014-07-18 05:08:14 -0700434 SkString outFile = get_sum_path(outDir);
435 outFile.appendf("%s%s", PATH_SLASH, pngName);
436 if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100)) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000437 SkDebugf("unable to encode gr %s (width=%d height=%d)\n", pngName,
438 bitmap.width(), bitmap.height());
439 }
440}
441
442void TestResult::testOne() {
443 SkPicture* pic = NULL;
444 {
445 #if DEBUG_SHOW_TEST_NAME
446 if (fTestStep == kCompareBits) {
447 SkString testName(fFilename);
448 const char http[] = "http";
449 if (testName.startsWith(http)) {
450 testName.remove(0, sizeof(http) - 1);
451 }
452 while (testName.startsWith("_")) {
453 testName.remove(0, 1);
454 }
455 const char dotSkp[] = ".skp";
456 if (testName.endsWith(dotSkp)) {
457 size_t len = testName.size();
458 testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1);
459 }
460 testName.prepend("skp");
461 testName.append("1");
462 strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRING_LENGTH);
463 } else if (fTestStep == kEncodeFiles) {
464 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
465 }
466 #endif
caryclark19eb3b22014-07-18 05:08:14 -0700467 SkString path = get_in_path(fDirNo, fFilename);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000468 SkFILEStream stream(path.c_str());
469 if (!stream.isValid()) {
470 SkDebugf("invalid stream %s\n", path.c_str());
471 goto finish;
472 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000473 pic = SkPicture::CreateFromStream(&stream, &SkImageDecoder::DecodeMemory);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000474 if (!pic) {
475 SkDebugf("unable to decode %s\n", fFilename);
476 goto finish;
477 }
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700478 SkScalar width = pic->cullRect().width();
479 SkScalar height = pic->cullRect().height();
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000480 SkBitmap oldBitmap, opBitmap;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000481 fScale = 1;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000482 while (width / fScale > 32767 || height / fScale > 32767) {
483 ++fScale;
484 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000485 do {
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700486 int dimX = SkScalarCeilToInt(width / fScale);
487 int dimY = SkScalarCeilToInt(height / fScale);
reed84825042014-09-02 12:50:45 -0700488 if (oldBitmap.tryAllocN32Pixels(dimX, dimY) && opBitmap.tryAllocN32Pixels(dimX, dimY)) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000489 break;
490 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000491 SkDebugf("-%d-", fScale);
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000492 } while (++fScale < 256);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000493 if (fScale >= 256) {
robertphillipsa8d7f0b2014-08-29 08:03:56 -0700494 SkDebugf("unable to allocate bitmap for %s (w=%f h=%f)\n", fFilename,
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000495 width, height);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000496 goto finish;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000497 }
498 oldBitmap.eraseColor(SK_ColorWHITE);
499 SkCanvas oldCanvas(oldBitmap);
500 oldCanvas.setAllowSimplifyClip(false);
501 opBitmap.eraseColor(SK_ColorWHITE);
502 SkCanvas opCanvas(opBitmap);
503 opCanvas.setAllowSimplifyClip(true);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000504 drawPict(pic, &oldCanvas, fScale);
505 drawPict(pic, &opCanvas, fScale);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000506 if (fTestStep == kCompareBits) {
507 fPixelError = similarBits(oldBitmap, opBitmap);
508 int oldTime = timePict(pic, &oldCanvas);
509 int opTime = timePict(pic, &opCanvas);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000510 fTime = SkTMax(0, oldTime - opTime);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000511 } else if (fTestStep == kEncodeFiles) {
512 SkString pngStr = make_png_name(fFilename);
513 const char* pngName = pngStr.c_str();
514 writePict(oldBitmap, outOldDir, pngName);
515 writePict(opBitmap, outOpDir, pngName);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000516 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000517 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000518finish:
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000519 if (pic) {
520 pic->unref();
521 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000522}
523
caryclark19eb3b22014-07-18 05:08:14 -0700524DEFINE_string2(match, m, "PathOpsSkpClipThreaded",
525 "[~][^]substring[$] [...] of test name to run.\n"
526 "Multiple matches may be separated by spaces.\n"
527 "~ causes a matching test to always be skipped\n"
528 "^ requires the start of the test to match\n"
529 "$ requires the end of the test to match\n"
530 "^ and $ requires an exact match\n"
531 "If a test does not match any list entry,\n"
532 "it is skipped unless some list entry starts with ~");
533DEFINE_string2(dir, d, NULL, "range of directories (e.g., 1-100)");
534DEFINE_string2(skp, s, NULL, "skp to test");
535DEFINE_bool2(single, z, false, "run tests on a single thread internally.");
536DEFINE_int32(testIndex, 0, "override local test index (PathOpsSkpClipOneOff only).");
caryclark19eb3b22014-07-18 05:08:14 -0700537DEFINE_bool2(verbose, v, false, "enable verbose output.");
538
539static bool verbose() {
540 return FLAGS_verbose;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000541}
542
caryclark19eb3b22014-07-18 05:08:14 -0700543class Dirs {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000544public:
caryclark19eb3b22014-07-18 05:08:14 -0700545 Dirs() {
546 reset();
547 sk_bzero(fRun, sizeof(fRun));
548 fSet = false;
549 }
550
551 int first() const {
552 int index = 0;
553 while (++index < kMaxDir) {
554 if (fRun[index]) {
555 return index;
556 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000557 }
caryclark19eb3b22014-07-18 05:08:14 -0700558 SkASSERT(0);
559 return -1;
560 }
561
562 int last() const {
563 int index = kMaxDir;
564 while (--index > 0 && !fRun[index])
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000565 ;
caryclark19eb3b22014-07-18 05:08:14 -0700566 return index;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000567 }
568
caryclark19eb3b22014-07-18 05:08:14 -0700569 int next() {
570 while (++fIndex < kMaxDir) {
571 if (fRun[fIndex]) {
572 return fIndex;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000573 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000574 }
caryclark19eb3b22014-07-18 05:08:14 -0700575 return -1;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000576 }
577
caryclark19eb3b22014-07-18 05:08:14 -0700578 void reset() {
579 fIndex = -1;
580 }
581
582 void set(int start, int end) {
583 while (start < end) {
584 fRun[start++] = 1;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000585 }
caryclark19eb3b22014-07-18 05:08:14 -0700586 fSet = true;
587 }
588
589 void setDefault() {
590 if (!fSet) {
591 set(1, 100);
592 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000593 }
594
595private:
caryclark19eb3b22014-07-18 05:08:14 -0700596 enum {
597 kMaxDir = 101
598 };
599 char fRun[kMaxDir];
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000600 int fIndex;
caryclark19eb3b22014-07-18 05:08:14 -0700601 bool fSet;
602} gDirs;
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000603
caryclark19eb3b22014-07-18 05:08:14 -0700604class Filenames {
605public:
606 Filenames()
607 : fIndex(-1) {
608 }
609
610 const char* next() {
611 while (fNames && ++fIndex < fNames->count()) {
612 return (*fNames)[fIndex];
613 }
614 return NULL;
615 }
mtklein406654b2014-09-03 15:34:37 -0700616
caryclark19eb3b22014-07-18 05:08:14 -0700617 void set(const SkCommandLineFlags::StringArray& names) {
618 fNames = &names;
619 }
620
621private:
622 int fIndex;
623 const SkCommandLineFlags::StringArray* fNames;
624} gNames;
625
mtklein406654b2014-09-03 15:34:37 -0700626static bool buildTestDir(int dirNo, int firstDirNo,
caryclark19eb3b22014-07-18 05:08:14 -0700627 SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sorted) {
628 SkString dirName = get_out_path(dirNo, outStatusDir);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000629 if (!dirName.size()) {
630 return false;
631 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000632 SkOSFile::Iter iter(dirName.c_str(), "skp");
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000633 SkString filename;
634 while (iter.next(&filename)) {
caryclark19eb3b22014-07-18 05:08:14 -0700635 TestResult test;
636 test.init(dirNo);
637 SkString spaceFile(filename);
638 char* spaces = spaceFile.writable_str();
639 int spaceSize = (int) spaceFile.size();
640 for (int index = 0; index < spaceSize; ++index) {
641 if (spaces[index] == '.') {
642 spaces[index] = ' ';
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000643 }
644 }
caryclark19eb3b22014-07-18 05:08:14 -0700645 int success = sscanf(spaces, "%s %d %d skp", test.fFilename,
646 &test.fPixelError, &test.fTime);
647 if (success < 3) {
648 SkDebugf("failed to scan %s matched=%d\n", filename.c_str(), success);
649 return false;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000650 }
caryclark19eb3b22014-07-18 05:08:14 -0700651 *tests[dirNo - firstDirNo].append() = test;
652 }
653 if (!sorted) {
654 return true;
655 }
656 SkTDArray<TestResult>& testSet = tests[dirNo - firstDirNo];
657 int count = testSet.count();
658 for (int index = 0; index < count; ++index) {
659 *sorted[dirNo - firstDirNo].append() = (SortByName*) &testSet[index];
660 }
661 if (sorted[dirNo - firstDirNo].count()) {
662 SkTQSort<SortByName>(sorted[dirNo - firstDirNo].begin(),
663 sorted[dirNo - firstDirNo].end() - 1);
664 if (verbose()) {
665 SkDebugf("+");
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000666 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000667 }
668 return true;
669}
670
caryclark19eb3b22014-07-18 05:08:14 -0700671static void testSkpClip(TestState* data) {
672 data->fResult.testOne();
673 SkString statName(data->fResult.fFilename);
674 SkASSERT(statName.endsWith(".skp"));
675 statName.remove(statName.size() - 4, 4);
676 statName.appendf(".%d.%d.skp", data->fResult.fPixelError, data->fResult.fTime);
677 SkString statusFile = get_out_path(data->fResult.fDirNo, outStatusDir);
678 if (!statusFile.size()) {
679 SkDebugf("failed to create %s", statusFile.c_str());
680 return;
681 }
682 statusFile.appendf("%s%s", PATH_SLASH, statName.c_str());
683 SkFILE* file = sk_fopen(statusFile.c_str(), kWrite_SkFILE_Flag);
684 if (!file) {
685 SkDebugf("failed to create %s", statusFile.c_str());
686 return;
687 }
688 sk_fclose(file);
689 if (verbose()) {
690 if (data->fResult.fPixelError || data->fResult.fTime) {
691 SkDebugf("%s", data->fResult.progress().c_str());
692 } else {
693 SkDebugf(".");
694 }
695 }
696}
697
698bool Less(const SortByName& a, const SortByName& b);
699bool Less(const SortByName& a, const SortByName& b) {
700 return a < b;
701}
702
703static bool doOneDir(TestState* state, bool threaded) {
704 int dirNo = state->fResult.fDirNo;
705 SkString dirName = get_in_path(dirNo, NULL);
706 if (!dirName.size()) {
707 return false;
708 }
709 SkTDArray<TestResult> tests[1];
710 SkTDArray<SortByName*> sorted[1];
711 if (!buildTestDir(dirNo, dirNo, tests, sorted)) {
712 return false;
713 }
714 SkOSFile::Iter iter(dirName.c_str(), "skp");
715 SkString filename;
716 while (iter.next(&filename)) {
717 for (size_t index = 0; index < skipOverCount; ++index) {
718 if (skipOver[index].directory == dirNo
719 && strcmp(filename.c_str(), skipOver[index].filename) == 0) {
720 goto checkEarlyExit;
721 }
722 }
723 {
724 SortByName name;
725 name.init(dirNo);
726 strncpy(name.fFilename, filename.c_str(), filename.size() - 4); // drop .skp
727 int count = sorted[0].count();
728 int idx = SkTSearch<SortByName, Less>(sorted[0].begin(), count, &name, sizeof(&name));
729 if (idx >= 0) {
730 SortByName* found = sorted[0][idx];
731 (void) addError(state, *found);
732 continue;
733 }
734 TestResult test;
735 test.init(dirNo, filename);
736 state->fResult = test;
737 testSkpClip(state);
738#if 0 // artificially limit to a few while debugging code
739 static int debugLimit = 0;
740 if (++debugLimit == 5) {
741 return true;
742 }
743#endif
744 }
745checkEarlyExit:
746 ;
747 }
748 return true;
749}
750
751static void initTest() {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000752#if !defined SK_BUILD_FOR_WIN && !defined SK_BUILD_FOR_MAC
753 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true);
754 SK_CONF_SET("images.png.suppressDecoderWarnings", true);
755#endif
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000756}
757
caryclarkdac1d172014-06-17 05:15:38 -0700758static void testSkpClipEncode(TestState* data) {
759 data->fResult.testOne();
caryclark19eb3b22014-07-18 05:08:14 -0700760 if (verbose()) {
761 SkDebugf("+");
caryclarkdac1d172014-06-17 05:15:38 -0700762 }
763}
764
caryclark19eb3b22014-07-18 05:08:14 -0700765static void encodeFound(TestState& state) {
766 if (verbose()) {
caryclarkdac1d172014-06-17 05:15:38 -0700767 if (state.fPixelWorst.count()) {
768 SkTDArray<SortByPixel*> worst;
769 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
770 *worst.append() = &state.fPixelWorst[index];
771 }
772 SkTQSort<SortByPixel>(worst.begin(), worst.end() - 1);
773 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
774 const TestResult& result = *worst[index];
775 SkDebugf("%d %s pixelError=%d\n", result.fDirNo, result.fFilename, result.fPixelError);
776 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000777 }
caryclarkdac1d172014-06-17 05:15:38 -0700778 if (state.fSlowest.count()) {
779 SkTDArray<SortByTime*> slowest;
780 for (int index = 0; index < state.fSlowest.count(); ++index) {
781 *slowest.append() = &state.fSlowest[index];
782 }
783 if (slowest.count() > 0) {
784 SkTQSort<SortByTime>(slowest.begin(), slowest.end() - 1);
785 for (int index = 0; index < slowest.count(); ++index) {
786 const TestResult& result = *slowest[index];
787 SkDebugf("%d %s time=%d\n", result.fDirNo, result.fFilename, result.fTime);
788 }
789 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000790 }
791 }
mtklein406654b2014-09-03 15:34:37 -0700792 TestRunner testRunner;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000793 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
794 const TestResult& result = state.fPixelWorst[index];
caryclarkdac1d172014-06-17 05:15:38 -0700795 SkString filename(result.fFilename);
796 if (!filename.endsWith(".skp")) {
797 filename.append(".skp");
798 }
799 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableEncode,
800 (&testSkpClipEncode, result.fDirNo, filename.c_str(), &testRunner));
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000801 }
caryclarkdac1d172014-06-17 05:15:38 -0700802 testRunner.render();
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000803}
804
caryclark19eb3b22014-07-18 05:08:14 -0700805class Test {
806public:
807 Test() {}
808 virtual ~Test() {}
809
810 const char* getName() { onGetName(&fName); return fName.c_str(); }
811 void run() { onRun(); }
812
813protected:
814 virtual void onGetName(SkString*) = 0;
815 virtual void onRun() = 0;
816
817private:
818 SkString fName;
819};
820
821typedef SkTRegistry<Test*(*)(void*)> TestRegistry;
822
823#define DEF_TEST(name) \
824 static void test_##name(); \
825 class name##Class : public Test { \
826 public: \
827 static Test* Factory(void*) { return SkNEW(name##Class); } \
828 protected: \
mtklein36352bf2015-03-25 18:17:31 -0700829 void onGetName(SkString* name) override { \
caryclark19eb3b22014-07-18 05:08:14 -0700830 name->set(#name); \
831 } \
mtklein36352bf2015-03-25 18:17:31 -0700832 void onRun() override { test_##name(); } \
caryclark19eb3b22014-07-18 05:08:14 -0700833 }; \
834 static TestRegistry gReg_##name##Class(name##Class::Factory); \
835 static void test_##name()
836
837DEF_TEST(PathOpsSkpClip) {
838 gDirs.setDefault();
839 initTest();
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000840 SkTArray<TestResult, true> errors;
841 TestState state;
caryclark19eb3b22014-07-18 05:08:14 -0700842 state.init(0);
843 int dirNo;
844 gDirs.reset();
845 while ((dirNo = gDirs.next()) > 0) {
846 if (verbose()) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000847 SkDebugf("dirNo=%d\n", dirNo);
848 }
849 state.fResult.fDirNo = dirNo;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000850 if (!doOneDir(&state, false)) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000851 break;
852 }
853 }
caryclark19eb3b22014-07-18 05:08:14 -0700854 encodeFound(state);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000855}
856
857static void testSkpClipMain(TestState* data) {
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000858 (void) doOneDir(data, true);
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000859}
860
caryclark19eb3b22014-07-18 05:08:14 -0700861DEF_TEST(PathOpsSkpClipThreaded) {
862 gDirs.setDefault();
863 initTest();
mtklein406654b2014-09-03 15:34:37 -0700864 TestRunner testRunner;
caryclark19eb3b22014-07-18 05:08:14 -0700865 int dirNo;
866 gDirs.reset();
867 while ((dirNo = gDirs.next()) > 0) {
caryclarkdac1d172014-06-17 05:15:38 -0700868 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableDir,
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000869 (&testSkpClipMain, dirNo, &testRunner));
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000870 }
871 testRunner.render();
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000872 TestState state;
caryclark19eb3b22014-07-18 05:08:14 -0700873 state.init(0);
874 gDirs.reset();
875 while ((dirNo = gDirs.next()) > 0) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000876 TestState& testState = testRunner.fRunnables[dirNo - 1]->fState;
caryclarkdac1d172014-06-17 05:15:38 -0700877 SkASSERT(testState.fResult.fDirNo == dirNo);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000878 for (int inner = 0; inner < testState.fPixelWorst.count(); ++inner) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000879 addError(&state, testState.fPixelWorst[inner]);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000880 }
caryclarkdac1d172014-06-17 05:15:38 -0700881 for (int inner = 0; inner < testState.fSlowest.count(); ++inner) {
882 addError(&state, testState.fSlowest[inner]);
883 }
884 }
caryclark19eb3b22014-07-18 05:08:14 -0700885 encodeFound(state);
caryclarkdac1d172014-06-17 05:15:38 -0700886}
mtklein406654b2014-09-03 15:34:37 -0700887
caryclark19eb3b22014-07-18 05:08:14 -0700888static bool buildTests(SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sorted) {
889 int firstDirNo = gDirs.first();
890 int dirNo;
891 while ((dirNo = gDirs.next()) > 0) {
892 if (!buildTestDir(dirNo, firstDirNo, tests, sorted)) {
caryclarkdac1d172014-06-17 05:15:38 -0700893 return false;
894 }
caryclarkdac1d172014-06-17 05:15:38 -0700895 }
896 return true;
897}
898
caryclark19eb3b22014-07-18 05:08:14 -0700899DEF_TEST(PathOpsSkpClipUberThreaded) {
900 gDirs.setDefault();
901 const int firstDirNo = gDirs.next();
902 const int lastDirNo = gDirs.last();
903 initTest();
904 int dirCount = lastDirNo - firstDirNo + 1;
905 SkAutoTDeleteArray<SkTDArray<TestResult> > tests(new SkTDArray<TestResult>[dirCount]);
906 SkAutoTDeleteArray<SkTDArray<SortByName*> > sorted(new SkTDArray<SortByName*>[dirCount]);
907 if (!buildTests(tests.get(), sorted.get())) {
caryclarkdac1d172014-06-17 05:15:38 -0700908 return;
909 }
mtklein406654b2014-09-03 15:34:37 -0700910 TestRunner testRunner;
caryclark19eb3b22014-07-18 05:08:14 -0700911 int dirNo;
912 gDirs.reset();
913 while ((dirNo = gDirs.next()) > 0) {
914 SkString dirName = get_in_path(dirNo, NULL);
caryclarkdac1d172014-06-17 05:15:38 -0700915 if (!dirName.size()) {
916 continue;
917 }
918 SkOSFile::Iter iter(dirName.c_str(), "skp");
919 SkString filename;
920 while (iter.next(&filename)) {
caryclark19eb3b22014-07-18 05:08:14 -0700921 for (size_t index = 0; index < skipOverCount; ++index) {
922 if (skipOver[index].directory == dirNo
923 && strcmp(filename.c_str(), skipOver[index].filename) == 0) {
caryclarkdac1d172014-06-17 05:15:38 -0700924 goto checkEarlyExit;
925 }
926 }
caryclark19eb3b22014-07-18 05:08:14 -0700927 {
928 SortByName name;
929 name.init(dirNo);
930 strncpy(name.fFilename, filename.c_str(), filename.size() - 4); // drop .skp
931 int count = sorted.get()[dirNo - firstDirNo].count();
932 if (SkTSearch<SortByName, Less>(sorted.get()[dirNo - firstDirNo].begin(),
933 count, &name, sizeof(&name)) < 0) {
934 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableFile,
935 (&testSkpClip, dirNo, filename.c_str(), &testRunner));
936 }
caryclarkdac1d172014-06-17 05:15:38 -0700937 }
938 checkEarlyExit:
939 ;
940 }
941
942 }
943 testRunner.render();
caryclark19eb3b22014-07-18 05:08:14 -0700944 SkAutoTDeleteArray<SkTDArray<TestResult> > results(new SkTDArray<TestResult>[dirCount]);
945 if (!buildTests(results.get(), NULL)) {
caryclarkdac1d172014-06-17 05:15:38 -0700946 return;
947 }
948 SkTDArray<TestResult> allResults;
949 for (int dirNo = firstDirNo; dirNo <= lastDirNo; ++dirNo) {
caryclark19eb3b22014-07-18 05:08:14 -0700950 SkTDArray<TestResult>& array = results.get()[dirNo - firstDirNo];
caryclarkdac1d172014-06-17 05:15:38 -0700951 allResults.append(array.count(), array.begin());
952 }
953 int allCount = allResults.count();
954 SkTDArray<SortByPixel*> pixels;
955 SkTDArray<SortByTime*> times;
956 for (int index = 0; index < allCount; ++index) {
957 *pixels.append() = (SortByPixel*) &allResults[index];
958 *times.append() = (SortByTime*) &allResults[index];
959 }
960 TestState state;
961 if (pixels.count()) {
962 SkTQSort<SortByPixel>(pixels.begin(), pixels.end() - 1);
963 for (int inner = 0; inner < kMaxFiles; ++inner) {
964 *state.fPixelWorst.append() = *pixels[allCount - inner - 1];
965 }
966 }
967 if (times.count()) {
968 SkTQSort<SortByTime>(times.begin(), times.end() - 1);
969 for (int inner = 0; inner < kMaxFiles; ++inner) {
970 *state.fSlowest.append() = *times[allCount - inner - 1];
971 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000972 }
caryclark19eb3b22014-07-18 05:08:14 -0700973 encodeFound(state);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000974}
975
caryclark19eb3b22014-07-18 05:08:14 -0700976DEF_TEST(PathOpsSkpClipOneOff) {
977 const int testIndex = FLAGS_testIndex;
978 int dirNo = gDirs.next();
979 if (dirNo < 0) {
980 dirNo = skipOver[testIndex].directory;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000981 }
caryclark19eb3b22014-07-18 05:08:14 -0700982 const char* skp = gNames.next();
983 if (!skp) {
984 skp = skipOver[testIndex].filename;
985 }
986 initTest();
987 SkAssertResult(get_in_path(dirNo, skp).size());
988 SkString filename(skp);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000989 TestResult state;
990 state.test(dirNo, filename);
caryclark19eb3b22014-07-18 05:08:14 -0700991 if (verbose()) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000992 SkDebugf("%s", state.status().c_str());
993 }
994 state.fTestStep = kEncodeFiles;
995 state.testOne();
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000996}
caryclark19eb3b22014-07-18 05:08:14 -0700997
998DEF_TEST(PathOpsTestSkipped) {
999 for (size_t index = 0; index < skipOverCount; ++index) {
1000 const SkipOverTest& skip = skipOver[index];
1001 if (!skip.blamePathOps) {
1002 continue;
1003 }
1004 int dirNo = skip.directory;
1005 const char* skp = skip.filename;
1006 initTest();
1007 SkAssertResult(get_in_path(dirNo, skp).size());
1008 SkString filename(skp);
1009 TestResult state;
1010 state.test(dirNo, filename);
1011 if (verbose()) {
1012 SkDebugf("%s", state.status().c_str());
1013 }
1014 state.fTestStep = kEncodeFiles;
1015 state.testOne();
1016 }
1017}
1018
1019DEF_TEST(PathOpsCopyFails) {
1020 FLAGS_verbose = true;
1021 for (size_t index = 0; index < skipOverCount; ++index) {
1022 int dirNo = skipOver[index].directory;
1023 SkDebugf("mkdir -p " IN_DIR_PRE "%d" DIR_POST "\n", dirNo);
1024 }
1025 for (size_t index = 0; index < skipOverCount; ++index) {
1026 int dirNo = skipOver[index].directory;
1027 const char* filename = skipOver[index].filename;
1028 SkDebugf("rsync -av cary-linux.cnc:/tera" PATH_SLASH "skps" PATH_SLASH "slave"
1029 "%d" DIR_POST "/%s " IN_DIR_PRE "%d" DIR_POST "\n", dirNo, filename, dirNo);
1030 }
1031}
1032
1033template TestRegistry* TestRegistry::gHead;
1034
1035class Iter {
1036public:
1037 Iter() { this->reset(); }
1038 void reset() { fReg = TestRegistry::Head(); }
1039
1040 Test* next() {
1041 if (fReg) {
1042 TestRegistry::Factory fact = fReg->factory();
1043 fReg = fReg->next();
1044 Test* test = fact(NULL);
1045 return test;
1046 }
1047 return NULL;
1048 }
1049
1050private:
1051 const TestRegistry* fReg;
1052};
1053
1054int tool_main(int argc, char** argv);
1055int tool_main(int argc, char** argv) {
1056 SetupCrashHandler();
1057 SkCommandLineFlags::SetUsage("");
1058 SkCommandLineFlags::Parse(argc, argv);
1059 SkGraphics::Init();
1060 SkString header("PathOps SkpClip:");
1061 if (!FLAGS_match.isEmpty()) {
1062 header.appendf(" --match");
1063 for (int index = 0; index < FLAGS_match.count(); ++index) {
1064 header.appendf(" %s", FLAGS_match[index]);
1065 }
1066 }
1067 if (!FLAGS_dir.isEmpty()) {
1068 int count = FLAGS_dir.count();
1069 for (int i = 0; i < count; ++i) {
1070 const char* range = FLAGS_dir[i];
1071 const char* dash = strchr(range, '-');
1072 if (!dash) {
1073 dash = strchr(range, ',');
1074 }
1075 int first = atoi(range);
1076 int last = dash ? atoi(dash + 1) : first;
1077 if (!first || !last) {
1078 SkDebugf("couldn't parse --dir %s\n", range);
1079 return 1;
1080 }
1081 gDirs.set(first, last);
1082 }
1083 }
1084 if (!FLAGS_skp.isEmpty()) {
1085 gNames.set(FLAGS_skp);
1086 }
1087#ifdef SK_DEBUG
1088 header.append(" SK_DEBUG");
1089#else
1090 header.append(" SK_RELEASE");
1091#endif
1092 header.appendf(" skia_arch_width=%d", (int)sizeof(void*) * 8);
1093 if (FLAGS_verbose) {
1094 header.appendf("\n");
1095 }
kkinnunen297aaf92015-02-19 06:32:12 -08001096 SkDebugf("%s", header.c_str());
caryclark19eb3b22014-07-18 05:08:14 -07001097 Iter iter;
1098 Test* test;
1099 while ((test = iter.next()) != NULL) {
1100 SkAutoTDelete<Test> owned(test);
1101 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) {
1102 test->run();
1103 }
1104 }
1105 SkGraphics::Term();
1106 return 0;
1107}
1108
borenet48087572015-04-02 12:16:36 -07001109#if !defined(SK_BUILD_FOR_IOS)
caryclark19eb3b22014-07-18 05:08:14 -07001110int main(int argc, char * const argv[]) {
1111 return tool_main(argc, (char**) argv);
1112}
1113#endif