blob: 3959fc7e797f8fce77bf507e9e05b9a97647202c [file] [log] [blame]
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +00001
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +00002#include "SkBitmap.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +00003#include "SkCanvas.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +00004#include "SkColor.h"
5#include "SkColorPriv.h"
6#include "SkDevice.h"
7#include "SkGraphics.h"
caryclark@google.comcffbcc32013-06-04 17:59:42 +00008#include "SkImageDecoder.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +00009#include "SkImageEncoder.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000010#include "SkOSFile.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000011#include "SkPathOpsDebug.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000012#include "SkPicture.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000013#include "SkRTConf.h"
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000014#include "SkTSort.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000015#include "SkStream.h"
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000016#include "SkString.h"
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000017#include "SkTArray.h"
18#include "SkTDArray.h"
19#include "SkThreadPool.h"
20#include "SkTime.h"
21#include "Test.h"
caryclark@google.com07e97fc2013-07-08 17:17:02 +000022
23#ifdef SK_BUILD_FOR_WIN
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000024 #define PATH_SLASH "\\"
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000025 #define IN_DIR "D:\\skp\\slave"
26 #define OUT_DIR "D:\\skpOut\\1\\"
caryclark@google.com07e97fc2013-07-08 17:17:02 +000027#else
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000028 #define PATH_SLASH "/"
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000029 #define IN_DIR "/skp/slave"
30 #define OUT_DIR "/skpOut/1/"
caryclark@google.com07e97fc2013-07-08 17:17:02 +000031#endif
32
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000033const struct {
34 int directory;
35 const char* filename;
36} skipOverSept[] = {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000037 {1, "http___elpais_com_.skp"},
38 {1, "http___namecheap_com_.skp"},
39 {1, "http___www_alrakoba_net_.skp"},
40 {1, "http___www_briian_com_.skp"}, // triggers assert at line 467 of SkRRect.cpp
41 {1, "http___www_cityads_ru_.skp"},
42 {3, "http___www_abeautifulmess_com_.skp"}, // asserts in IntToFixed from SkScan::AntiFilllXRect
43 {1, "http___www_dealnews_com_.skp"},
44 {1, "http___www_inmotionhosting_com.skp"},
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000045};
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000046
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000047size_t skipOverSeptCount = sizeof(skipOverSept) / sizeof(skipOverSept[0]);
48
49enum TestStep {
50 kCompareBits,
51 kEncodeFiles,
52};
53
54enum {
55 kMaxLength = 128,
56 kMaxFiles = 128,
57 kSmallLimit = 1000,
58};
59
60struct TestResult {
61 void init(int dirNo) {
62 fDirNo = dirNo;
63 sk_bzero(fFilename, sizeof(fFilename));
64 fTestStep = kCompareBits;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000065 fScale = 1;
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +000066 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000067
68 SkString status() {
69 SkString outStr;
70 outStr.printf("%s %d %d\n", fFilename, fPixelError, fTime);
71 return outStr;
72 }
73
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000074 SkString progress() {
75 SkString outStr;
76 outStr.printf("dir=%d %s ", fDirNo, fFilename);
77 if (fPixelError) {
78 outStr.appendf(" err=%d", fPixelError);
79 }
80 if (fTime) {
81 outStr.appendf(" time=%d", fTime);
82 }
83 if (fScale != 1) {
84 outStr.appendf(" scale=%d", fScale);
85 }
86 outStr.appendf("\n");
87 return outStr;
88
89 }
90
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000091 static void Test(int dirNo, const char* filename, TestStep testStep) {
92 TestResult test;
93 test.init(dirNo);
94 test.fTestStep = testStep;
95 strcpy(test.fFilename, filename);
96 test.testOne();
97 }
98
99 void test(int dirNo, const SkString& filename) {
100 init(dirNo);
101 strcpy(fFilename, filename.c_str());
102 testOne();
103 }
104
105 void testOne();
106
107 char fFilename[kMaxLength];
108 TestStep fTestStep;
109 int fDirNo;
110 int fPixelError;
111 int fTime;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000112 int fScale;
113};
114
115class SortByPixel : public TestResult {
116public:
117 bool operator<(const SortByPixel& rh) const {
118 return fPixelError < rh.fPixelError;
119 }
120};
121
122class SortByTime : public TestResult {
123public:
124 bool operator<(const SortByTime& rh) const {
125 return fTime < rh.fTime;
126 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000127};
128
129struct TestState {
130 void init(int dirNo, skiatest::Reporter* reporter) {
131 fReporter = reporter;
132 fResult.init(dirNo);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000133 }
134
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000135 SkTDArray<SortByPixel> fPixelWorst;
136 SkTDArray<SortByTime> fSlowest;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000137 skiatest::Reporter* fReporter;
138 TestResult fResult;
139};
140
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000141struct TestRunner {
142 TestRunner(skiatest::Reporter* reporter, int threadCount)
143 : fNumThreads(threadCount)
144 , fReporter(reporter) {
145 }
146
147 ~TestRunner();
148 void render();
149 int fNumThreads;
150 SkTDArray<class TestRunnable*> fRunnables;
151 skiatest::Reporter* fReporter;
152};
153
154class TestRunnable : public SkRunnable {
155public:
156 TestRunnable(void (*testFun)(TestState*), int dirNo, TestRunner* runner) {
157 fState.init(dirNo, runner->fReporter);
158 fTestFun = testFun;
159 }
160
161 virtual void run() SK_OVERRIDE {
162 SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024);
163 (*fTestFun)(&fState);
164 }
165
166 TestState fState;
167 void (*fTestFun)(TestState*);
168};
169
170TestRunner::~TestRunner() {
171 for (int index = 0; index < fRunnables.count(); index++) {
172 SkDELETE(fRunnables[index]);
173 }
174}
175
176void TestRunner::render() {
177 SkThreadPool pool(fNumThreads);
178 for (int index = 0; index < fRunnables.count(); ++ index) {
179 pool.add(fRunnables[index]);
180 }
181}
182
183////////////////////////////////////////////////
184
185static const char outOpDir[] = OUT_DIR "opClip";
186static const char outOldDir[] = OUT_DIR "oldClip";
187static const char outSkpDir[] = OUT_DIR "skpTest";
188static const char outDiffDir[] = OUT_DIR "outTest";
189static const char outStatusDir[] = OUT_DIR "statusTest";
190
191static SkString make_filepath(int dirNo, const char* dir, const char* name) {
192 SkString path(dir);
193 if (dirNo) {
194 path.appendf("%d", dirNo);
195 }
196 path.append(PATH_SLASH);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000197 path.append(name);
198 return path;
199}
200
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000201static SkString make_in_dir_name(int dirNo) {
202 SkString dirName(IN_DIR);
203 dirName.appendf("%d", dirNo);
204 if (!sk_exists(dirName.c_str())) {
205 SkDebugf("could not read dir %s\n", dirName.c_str());
206 return SkString();
207 }
208 return dirName;
209}
210
211static bool make_one_out_dir(const char* outDirStr) {
212 SkString outDir = make_filepath(0, outDirStr, "");
213 if (!sk_exists(outDir.c_str())) {
214 if (!sk_mkdir(outDir.c_str())) {
215 SkDebugf("could not create dir %s\n", outDir.c_str());
216 return false;
217 }
218 }
219 return true;
220}
221
222static bool make_out_dirs() {
223 SkString outDir = make_filepath(0, OUT_DIR, "");
224 if (!sk_exists(outDir.c_str())) {
225 if (!sk_mkdir(outDir.c_str())) {
226 SkDebugf("could not create dir %s\n", outDir.c_str());
227 return false;
228 }
229 }
230 return make_one_out_dir(outOldDir)
231 && make_one_out_dir(outOpDir)
232 && make_one_out_dir(outSkpDir)
233 && make_one_out_dir(outDiffDir)
234 && make_one_out_dir(outStatusDir);
235}
236
237static SkString make_png_name(const char* filename) {
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000238 SkString pngName = SkString(filename);
239 pngName.remove(pngName.size() - 3, 3);
240 pngName.append("png");
241 return pngName;
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000242}
243
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000244static int similarBits(const SkBitmap& gr, const SkBitmap& sk) {
245 const int kRowCount = 3;
246 const int kThreshold = 3;
247 int width = SkTMin(gr.width(), sk.width());
248 if (width < kRowCount) {
249 return true;
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000250 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000251 int height = SkTMin(gr.height(), sk.height());
252 if (height < kRowCount) {
253 return true;
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000254 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000255 int errorTotal = 0;
256 SkTArray<int, true> errorRows;
257 errorRows.push_back_n(width * kRowCount);
258 SkAutoLockPixels autoGr(gr);
259 SkAutoLockPixels autoSk(sk);
260 for (int y = 0; y < height; ++y) {
261 SkPMColor* grRow = gr.getAddr32(0, y);
262 SkPMColor* skRow = sk.getAddr32(0, y);
263 int* base = &errorRows[0];
264 int* cOut = &errorRows[y % kRowCount];
265 for (int x = 0; x < width; ++x) {
266 SkPMColor grColor = grRow[x];
267 SkPMColor skColor = skRow[x];
268 int dr = SkGetPackedR32(grColor) - SkGetPackedR32(skColor);
269 int dg = SkGetPackedG32(grColor) - SkGetPackedG32(skColor);
270 int db = SkGetPackedB32(grColor) - SkGetPackedB32(skColor);
271 int error = cOut[x] = SkTMax(SkAbs32(dr), SkTMax(SkAbs32(dg), SkAbs32(db)));
272 if (error < kThreshold || x < 2) {
273 continue;
274 }
275 if (base[x - 2] < kThreshold
276 || base[width + x - 2] < kThreshold
277 || base[width * 2 + x - 2] < kThreshold
278 || base[x - 1] < kThreshold
279 || base[width + x - 1] < kThreshold
280 || base[width * 2 + x - 1] < kThreshold
281 || base[x] < kThreshold
282 || base[width + x] < kThreshold
283 || base[width * 2 + x] < kThreshold) {
284 continue;
285 }
286 errorTotal += error;
287 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000288 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000289 return errorTotal;
290}
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000291
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000292static bool addError(TestState* data, const TestResult& testResult) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000293 if (testResult.fPixelError <= 0 && testResult.fTime <= 0) {
294 return false;
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000295 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000296 int worstCount = data->fPixelWorst.count();
297 int pixelError = testResult.fPixelError;
298 if (pixelError > 0) {
299 for (int index = 0; index < worstCount; ++index) {
300 if (pixelError > data->fPixelWorst[index].fPixelError) {
301 data->fPixelWorst[index] = *(SortByPixel*) &testResult;
302 return true;
303 }
304 }
305 }
306 int slowCount = data->fSlowest.count();
307 int time = testResult.fTime;
308 if (time > 0) {
309 for (int index = 0; index < slowCount; ++index) {
310 if (time > data->fSlowest[index].fTime) {
311 data->fSlowest[index] = *(SortByTime*) &testResult;
312 return true;
313 }
314 }
315 }
316 if (pixelError > 0 && worstCount < kMaxFiles) {
317 *data->fPixelWorst.append() = *(SortByPixel*) &testResult;
318 return true;
319 }
320 if (time > 0 && slowCount < kMaxFiles) {
321 *data->fSlowest.append() = *(SortByTime*) &testResult;
322 return true;
323 }
324 return false;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000325}
326
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000327static SkMSec timePict(SkPicture* pic, SkCanvas* canvas) {
328 canvas->save();
329 int pWidth = pic->width();
330 int pHeight = pic->height();
331 const int maxDimension = 1000;
332 const int slices = 3;
333 int xInterval = SkTMax(pWidth - maxDimension, 0) / (slices - 1);
334 int yInterval = SkTMax(pHeight - maxDimension, 0) / (slices - 1);
skia.committer@gmail.comf54ad6f2013-11-02 07:02:02 +0000335 SkRect rect = {0, 0, SkIntToScalar(SkTMin(maxDimension, pWidth)),
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000336 SkIntToScalar(SkTMin(maxDimension, pHeight))};
337 canvas->clipRect(rect);
338 SkMSec start = SkTime::GetMSecs();
339 for (int x = 0; x < slices; ++x) {
340 for (int y = 0; y < slices; ++y) {
341 pic->draw(canvas);
342 canvas->translate(0, SkIntToScalar(yInterval));
343 }
344 canvas->translate(SkIntToScalar(xInterval), SkIntToScalar(-yInterval * slices));
345 }
346 SkMSec end = SkTime::GetMSecs();
347 canvas->restore();
348 return end - start;
349}
350
351static void drawPict(SkPicture* pic, SkCanvas* canvas, int scale) {
352 canvas->clear(SK_ColorWHITE);
353 if (scale != 1) {
354 canvas->save();
355 canvas->scale(1.0f / scale, 1.0f / scale);
356 }
357 pic->draw(canvas);
358 if (scale != 1) {
359 canvas->restore();
360 }
361}
362
363static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pngName) {
364 SkString outFile = make_filepath(0, outDir, pngName);
365 if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap,
366 SkImageEncoder::kPNG_Type, 100)) {
367 SkDebugf("unable to encode gr %s (width=%d height=%d)\n", pngName,
368 bitmap.width(), bitmap.height());
369 }
370}
371
372void TestResult::testOne() {
373 SkPicture* pic = NULL;
374 {
375 #if DEBUG_SHOW_TEST_NAME
376 if (fTestStep == kCompareBits) {
377 SkString testName(fFilename);
378 const char http[] = "http";
379 if (testName.startsWith(http)) {
380 testName.remove(0, sizeof(http) - 1);
381 }
382 while (testName.startsWith("_")) {
383 testName.remove(0, 1);
384 }
385 const char dotSkp[] = ".skp";
386 if (testName.endsWith(dotSkp)) {
387 size_t len = testName.size();
388 testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1);
389 }
390 testName.prepend("skp");
391 testName.append("1");
392 strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRING_LENGTH);
393 } else if (fTestStep == kEncodeFiles) {
394 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
395 }
396 #endif
397 SkString path = make_filepath(fDirNo, IN_DIR, fFilename);
398 SkFILEStream stream(path.c_str());
399 if (!stream.isValid()) {
400 SkDebugf("invalid stream %s\n", path.c_str());
401 goto finish;
402 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000403 pic = SkPicture::CreateFromStream(&stream, &SkImageDecoder::DecodeMemory);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000404 if (!pic) {
405 SkDebugf("unable to decode %s\n", fFilename);
406 goto finish;
407 }
408 int width = pic->width();
409 int height = pic->height();
410 SkBitmap oldBitmap, opBitmap;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000411 fScale = 1;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000412 do {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000413 int dimX = (width + fScale - 1) / fScale;
414 int dimY = (height + fScale - 1) / fScale;
mike@reedtribe.orgdeee4962014-02-13 14:41:43 +0000415 if (oldBitmap.allocN32Pixels(dimX, dimY) &&
416 opBitmap.allocN32Pixels(dimX, dimY)) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000417 break;
418 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000419 SkDebugf("-%d-", fScale);
420 } while ((fScale *= 2) < 256);
421 if (fScale >= 256) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000422 SkDebugf("unable to allocate bitmap for %s (w=%d h=%d)\n", fFilename,
423 width, height);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000424 goto finish;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000425 }
426 oldBitmap.eraseColor(SK_ColorWHITE);
427 SkCanvas oldCanvas(oldBitmap);
428 oldCanvas.setAllowSimplifyClip(false);
429 opBitmap.eraseColor(SK_ColorWHITE);
430 SkCanvas opCanvas(opBitmap);
431 opCanvas.setAllowSimplifyClip(true);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000432 drawPict(pic, &oldCanvas, fScale);
433 drawPict(pic, &opCanvas, fScale);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000434 if (fTestStep == kCompareBits) {
435 fPixelError = similarBits(oldBitmap, opBitmap);
436 int oldTime = timePict(pic, &oldCanvas);
437 int opTime = timePict(pic, &opCanvas);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000438 fTime = SkTMax(0, oldTime - opTime);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000439 } else if (fTestStep == kEncodeFiles) {
440 SkString pngStr = make_png_name(fFilename);
441 const char* pngName = pngStr.c_str();
442 writePict(oldBitmap, outOldDir, pngName);
443 writePict(opBitmap, outOpDir, pngName);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000444 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000445 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000446finish:
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000447 if (pic) {
448 pic->unref();
449 }
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000450}
451
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000452static SkString makeStatusString(int dirNo) {
453 SkString statName;
454 statName.printf("stats%d.txt", dirNo);
455 SkString statusFile = make_filepath(0, outStatusDir, statName.c_str());
456 return statusFile;
457}
458
459class PreParser {
460public:
461 PreParser(int dirNo)
462 : fDirNo(dirNo)
463 , fIndex(0) {
464 SkString statusPath = makeStatusString(dirNo);
465 if (!sk_exists(statusPath.c_str())) {
466 return;
467 }
468 SkFILEStream reader;
469 reader.setPath(statusPath.c_str());
470 while (fetch(reader, &fResults.push_back()))
471 ;
472 fResults.pop_back();
473 }
474
475 bool fetch(SkFILEStream& reader, TestResult* result) {
476 char c;
477 int i = 0;
478 result->init(fDirNo);
479 result->fPixelError = 0;
480 result->fTime = 0;
481 do {
482 bool readOne = reader.read(&c, 1) != 0;
483 if (!readOne) {
484 SkASSERT(i == 0);
485 return false;
486 }
487 if (c == ' ') {
488 result->fFilename[i++] = '\0';
489 break;
490 }
491 result->fFilename[i++] = c;
492 SkASSERT(i < kMaxLength);
493 } while (true);
494 do {
495 SkAssertResult(reader.read(&c, 1));
496 if (c == ' ') {
497 break;
498 }
499 SkASSERT(c >= '0' && c <= '9');
500 result->fPixelError = result->fPixelError * 10 + (c - '0');
501 } while (true);
502 bool minus = false;
503 do {
504 SkAssertResult(reader.read(&c, 1));
505 if (c == '\n') {
506 break;
507 }
508 if (c == '-') {
509 minus = true;
510 continue;
511 }
512 SkASSERT(c >= '0' && c <= '9');
513 result->fTime = result->fTime * 10 + (c - '0');
514 } while (true);
515 if (minus) {
516 result->fTime = -result->fTime;
517 }
518 return true;
519 }
520
521 bool match(const SkString& filename, SkFILEWStream* stream, TestResult* result) {
522 if (fIndex < fResults.count()) {
523 *result = fResults[fIndex++];
524 SkASSERT(filename.equals(result->fFilename));
525 SkString outStr(result->status());
526 stream->write(outStr.c_str(), outStr.size());
527 return true;
528 }
529 return false;
530 }
531
532private:
533 int fDirNo;
534 int fIndex;
535 SkTArray<TestResult, true> fResults;
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000536};
537
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000538static bool doOneDir(TestState* state) {
539 int dirNo = state->fResult.fDirNo;
540 skiatest::Reporter* reporter = state->fReporter;
541 SkString dirName = make_in_dir_name(dirNo);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000542 if (!dirName.size()) {
543 return false;
544 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000545 SkOSFile::Iter iter(dirName.c_str(), "skp");
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000546 SkString filename;
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000547 int testCount = 0;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000548 PreParser preParser(dirNo);
549 SkFILEWStream statusStream(makeStatusString(dirNo).c_str());
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000550 while (iter.next(&filename)) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000551 for (size_t index = 0; index < skipOverSeptCount; ++index) {
552 if (skipOverSept[index].directory == dirNo
553 && strcmp(filename.c_str(), skipOverSept[index].filename) == 0) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000554 goto checkEarlyExit;
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000555 }
556 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000557 if (preParser.match(filename, &statusStream, &state->fResult)) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000558 (void) addError(state, state->fResult);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000559 ++testCount;
560 goto checkEarlyExit;
561 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000562 {
563 TestResult& result = state->fResult;
564 result.test(dirNo, filename);
565 SkString outStr(result.status());
566 statusStream.write(outStr.c_str(), outStr.size());
567 statusStream.flush();
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000568 if (addError(state, result)) {
569 SkDebugf("%s", result.progress().c_str());
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000570 }
571 }
572 ++testCount;
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000573 if (reporter->verbose()) {
574 SkDebugf(".");
575 if (++testCount % 100 == 0) {
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000576 SkDebugf("%d\n", testCount);
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000577 }
skia.committer@gmail.com2b34fe02013-05-08 07:01:40 +0000578 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000579checkEarlyExit:
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000580 if (0 && testCount >= 1) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000581 return true;
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000582 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000583 }
584 return true;
585}
586
587static bool initTest() {
588#if !defined SK_BUILD_FOR_WIN && !defined SK_BUILD_FOR_MAC
589 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true);
590 SK_CONF_SET("images.png.suppressDecoderWarnings", true);
591#endif
592 return make_out_dirs();
593}
594
595static void encodeFound(skiatest::Reporter* reporter, TestState& state) {
596 if (reporter->verbose()) {
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000597 SkTDArray<SortByPixel*> worst;
598 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
599 *worst.append() = &state.fPixelWorst[index];
600 }
601 SkTQSort<SortByPixel>(worst.begin(), worst.end() - 1);
602 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
603 const TestResult& result = *worst[index];
604 SkDebugf("%d %s pixelError=%d\n", result.fDirNo, result.fFilename, result.fPixelError);
605 }
606 SkTDArray<SortByTime*> slowest;
607 for (int index = 0; index < state.fSlowest.count(); ++index) {
608 *slowest.append() = &state.fSlowest[index];
609 }
610 SkTQSort<SortByTime>(slowest.begin(), slowest.end() - 1);
611 for (int index = 0; index < slowest.count(); ++index) {
612 const TestResult& result = *slowest[index];
613 SkDebugf("%d %s time=%d\n", result.fDirNo, result.fFilename, result.fTime);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000614 }
615 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000616 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
617 const TestResult& result = state.fPixelWorst[index];
618 TestResult::Test(result.fDirNo, result.fFilename, kEncodeFiles);
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000619 if (state.fReporter->verbose()) SkDebugf("+");
620 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000621}
622
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000623DEF_TEST(PathOpsSkpClip, reporter) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000624 if (!initTest()) {
625 return;
626 }
627 SkTArray<TestResult, true> errors;
628 TestState state;
629 state.init(0, reporter);
630 for (int dirNo = 1; dirNo <= 100; ++dirNo) {
631 if (reporter->verbose()) {
632 SkDebugf("dirNo=%d\n", dirNo);
633 }
634 state.fResult.fDirNo = dirNo;
635 if (!doOneDir(&state)) {
636 break;
637 }
638 }
639 encodeFound(reporter, state);
640}
641
642static void testSkpClipMain(TestState* data) {
643 (void) doOneDir(data);
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000644}
645
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000646DEF_TEST(PathOpsSkpClipThreaded, reporter) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000647 if (!initTest()) {
648 return;
649 }
650 int threadCount = reporter->allowThreaded() ? SkThreadPool::kThreadPerCore : 1;
651 TestRunner testRunner(reporter, threadCount);
652 for (int dirNo = 1; dirNo <= 100; ++dirNo) {
653 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnable,
654 (&testSkpClipMain, dirNo, &testRunner));
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000655 }
656 testRunner.render();
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000657 TestState state;
658 state.init(0, reporter);
659 for (int dirNo = 1; dirNo <= 100; ++dirNo) {
660 TestState& testState = testRunner.fRunnables[dirNo - 1]->fState;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000661 for (int inner = 0; inner < testState.fPixelWorst.count(); ++inner) {
662 SkASSERT(testState.fResult.fDirNo == dirNo);
663 addError(&state, testState.fPixelWorst[inner]);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000664 }
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000665 }
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000666 encodeFound(reporter, state);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +0000667}
668
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +0000669DEF_TEST(PathOpsSkpClipOneOff, reporter) {
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000670 if (!initTest()) {
671 return;
672 }
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000673 const int testIndex = 43 - 37;
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +0000674 int dirNo = skipOverSept[testIndex].directory;
675 SkAssertResult(make_in_dir_name(dirNo).size());
676 SkString filename(skipOverSept[testIndex].filename);
677 TestResult state;
678 state.test(dirNo, filename);
679 if (reporter->verbose()) {
680 SkDebugf("%s", state.status().c_str());
681 }
682 state.fTestStep = kEncodeFiles;
683 state.testOne();
caryclark@google.com07e97fc2013-07-08 17:17:02 +0000684}