1 #include "CrashHandler.h"
2 // #include "OverwriteLine.h"
7 #include "SkColorPriv.h"
8 #include "SkCommandLineFlags.h"
10 #include "SkForceLinking.h"
11 #include "SkGraphics.h"
12 #include "SkImageDecoder.h"
13 #include "SkImageEncoder.h"
15 #include "SkPathOpsDebug.h"
16 #include "SkPicture.h"
18 #include "SkRunnable.h"
23 #include "SkTDArray.h"
24 #include "SkTaskGroup.h"
25 #include "SkTemplates.h"
28 __SK_FORCE_IMAGE_DECODER_LINKING;
30 /* add local exceptions here */
31 /* TODO : add command flag interface */
32 const struct SkipOverTest {
37 { 2, "http___www_groupon_sg_.skp", false}, // SkAAClip::Builder::addRun SkASSERT(fBounds.contains(x, y));
38 { 6, "http___www_googleventures_com_.skp", true}, // addTCoincident SkASSERT(test->fT < 1);
39 { 7, "http___www_foxsports_nl_.skp", true}, // (no repro on mac) addT SkASSERT(this != other || fVerb == SkPath::kCubic_Verb)
40 {13, "http___www_modernqigong_com_.skp", false}, // SkAAClip::Builder::addRun SkASSERT(fBounds.contains(x, y));
41 {14, "http___www_devbridge_com_.skp", true}, // checkSmallCoincidence SkASSERT(!next->fSmall || checkMultiple);
42 {16, "http___www_1023world_net_.skp", false}, // bitmap decode assert (corrupt skp?)
43 {19, "http___www_alamdi_com_.skp", true}, // cubic/quad intersection
44 {26, "http___www_liveencounters_net_.skp", true}, // (no repro on mac) checkSmall addT:549 (line, expects cubic)
45 {28, "http___www_encros_fr_.skp", false}, // SkAAClip::Builder::addRun SkASSERT(fBounds.contains(x, y));
46 {37, "http___www_familysurvivalprotocol_wordpress_com_.skp", true}, // bumpSpan SkASSERT(span->fOppValue >= 0);
47 {39, "http___sufeinet_com_.skp", false}, // bitmap decode assert (corrupt skp?)
48 {41, "http___www_rano360_com_.skp", true}, // checkSmallCoincidence SkASSERT(!next->fSmall || checkMultiple);
49 {44, "http___www_firstunitedbank_com_.skp", true}, // addTCancel SkASSERT(oIndex > 0);
50 {46, "http___www_shinydemos_com_.skp", true}, // addSimpleAngle SkASSERT(index == count() - 2);
51 {48, "http___www_familysurvivalprotocol_com_.skp", true}, // bumpSpan SkASSERT "span->fOppValue >= 0"
52 {57, "http___www_lptemp_com_.skp", true}, // addTCoincident oPeek = &other->fTs[++oPeekIndex];
53 {71, "http___www_1milyonkahraman_org_.skp", true}, // addTCoincident SkASSERT(test->fT < 1);
54 {88, "http___www_apuntesdelechuza_wordpress_com_.skp", true}, // bumpSpan SkASSERT "span->fOppValue >= 0"
55 {89, "http___www_mobilizedconsulting_com_.skp", true}, // addTCancel SkASSERT(oIndex > 0);
56 {93, "http___www_simple_living_in_suffolk_co_uk_.skp", true}, // bumpSpan SkASSERT "span->fOppValue >= 0"
59 size_t skipOverCount = sizeof(skipOver) / sizeof(skipOver[0]);
62 /* customize file in/out here */
63 /* TODO : add command flag interface */
64 #define CHROME_VERSION "1e5dfa4-4a995df"
67 #ifdef SK_BUILD_FOR_WIN
68 #define DRIVE_SPEC "D:"
69 #define PATH_SLASH "\\"
72 #define PATH_SLASH "/"
75 #define IN_DIR_PRE DRIVE_SPEC PATH_SLASH "skps" PATH_SLASH "slave"
76 #define OUT_DIR_PRE DRIVE_SPEC PATH_SLASH "skpOut" PATH_SLASH "slave"
77 #define OUT_DIR_SUM DRIVE_SPEC PATH_SLASH "skpOut" PATH_SLASH "summary"
78 #define DIR_POST PATH_SLASH "All" PATH_SLASH CHROME_VERSION
80 static const char outOpDir[] = "opClip";
81 static const char outOldDir[] = "oldClip";
82 static const char outStatusDir[] = "statusTest";
84 static SkString get_in_path(int dirNo, const char* filename) {
87 path.appendf("%s%d%s", IN_DIR_PRE, dirNo, DIR_POST);
88 if (!sk_exists(path.c_str())) {
89 SkDebugf("could not read %s\n", path.c_str());
93 path.appendf("%s%s", PATH_SLASH, filename);
94 if (!sk_exists(path.c_str())) {
95 SkDebugf("could not read %s\n", path.c_str());
102 static void make_recursive_dir(const SkString& path) {
103 if (sk_exists(path.c_str())) {
106 const char* pathStr = path.c_str();
107 int last = (int) path.size();
109 while (last > 0 && pathStr[--last] != PATH_SLASH[0])
112 SkString shorter(pathStr, last);
113 if (sk_mkdir(shorter.c_str())) {
118 while (last < (int) path.size() && pathStr[++last] != PATH_SLASH[0])
120 SkString shorter(pathStr, last);
121 SkAssertResult(sk_mkdir(shorter.c_str()));
122 } while (last < (int) path.size());
125 static SkString get_out_path(int dirNo, const char* dirName) {
129 path.appendf("%s%d%s%s%s", OUT_DIR_PRE, dirNo, DIR_POST, PATH_SLASH, dirName);
130 make_recursive_dir(path);
134 static SkString get_sum_path(const char* dirName) {
137 path.appendf("%s%d%s%s", OUT_DIR_SUM, SUMMARY_RUN, PATH_SLASH, dirName);
138 SkDebugf("%s\n", path.c_str());
139 make_recursive_dir(path);
143 static SkString make_png_name(const char* filename) {
144 SkString pngName = SkString(filename);
145 pngName.remove(pngName.size() - 3, 3);
146 pngName.append("png");
150 ////////////////////////////////////////////////////////
164 void init(int dirNo) {
166 sk_bzero(fFilename, sizeof(fFilename));
167 fTestStep = kCompareBits;
171 void init(int dirNo, const SkString& filename) {
173 strcpy(fFilename, filename.c_str());
174 fTestStep = kCompareBits;
180 outStr.printf("%s %d %d\n", fFilename, fPixelError, fTime);
184 SkString progress() {
186 outStr.printf("dir=%d %s ", fDirNo, fFilename);
188 outStr.appendf(" err=%d", fPixelError);
191 outStr.appendf(" time=%d", fTime);
194 outStr.appendf(" scale=%d", fScale);
196 outStr.appendf("\n");
201 void test(int dirNo, const SkString& filename) {
203 strcpy(fFilename, filename.c_str());
209 char fFilename[kMaxLength];
217 class SortByPixel : public TestResult {
219 bool operator<(const SortByPixel& rh) const {
220 return fPixelError < rh.fPixelError;
224 class SortByTime : public TestResult {
226 bool operator<(const SortByTime& rh) const {
227 return fTime < rh.fTime;
231 class SortByName : public TestResult {
233 bool operator<(const SortByName& rh) const {
234 return strcmp(fFilename, rh.fFilename) < 0;
239 void init(int dirNo) {
243 SkTDArray<SortByPixel> fPixelWorst;
244 SkTDArray<SortByTime> fSlowest;
251 SkTDArray<class TestRunnable*> fRunnables;
254 class TestRunnable : public SkRunnable {
256 void run() SK_OVERRIDE {
257 SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024);
258 (*fTestFun)(&fState);
262 void (*fTestFun)(TestState*);
266 class TestRunnableDir : public TestRunnable {
268 TestRunnableDir(void (*testFun)(TestState*), int dirNo, TestRunner* runner) {
275 class TestRunnableFile : public TestRunnable {
277 TestRunnableFile(void (*testFun)(TestState*), int dirNo, const char* name, TestRunner* runner) {
279 strcpy(fState.fResult.fFilename, name);
284 class TestRunnableEncode : public TestRunnableFile {
286 TestRunnableEncode(void (*testFun)(TestState*), int dirNo, const char* name, TestRunner* runner)
287 : TestRunnableFile(testFun, dirNo, name, runner) {
288 fState.fResult.fTestStep = kEncodeFiles;
292 TestRunner::~TestRunner() {
293 for (int index = 0; index < fRunnables.count(); index++) {
294 SkDELETE(fRunnables[index]);
298 void TestRunner::render() {
300 for (int index = 0; index < fRunnables.count(); ++ index) {
301 tg.add(fRunnables[index]);
305 ////////////////////////////////////////////////
308 static int similarBits(const SkBitmap& gr, const SkBitmap& sk) {
309 const int kRowCount = 3;
310 const int kThreshold = 3;
311 int width = SkTMin(gr.width(), sk.width());
312 if (width < kRowCount) {
315 int height = SkTMin(gr.height(), sk.height());
316 if (height < kRowCount) {
320 SkTArray<int, true> errorRows;
321 errorRows.push_back_n(width * kRowCount);
322 SkAutoLockPixels autoGr(gr);
323 SkAutoLockPixels autoSk(sk);
324 for (int y = 0; y < height; ++y) {
325 SkPMColor* grRow = gr.getAddr32(0, y);
326 SkPMColor* skRow = sk.getAddr32(0, y);
327 int* base = &errorRows[0];
328 int* cOut = &errorRows[y % kRowCount];
329 for (int x = 0; x < width; ++x) {
330 SkPMColor grColor = grRow[x];
331 SkPMColor skColor = skRow[x];
332 int dr = SkGetPackedR32(grColor) - SkGetPackedR32(skColor);
333 int dg = SkGetPackedG32(grColor) - SkGetPackedG32(skColor);
334 int db = SkGetPackedB32(grColor) - SkGetPackedB32(skColor);
335 int error = cOut[x] = SkTMax(SkAbs32(dr), SkTMax(SkAbs32(dg), SkAbs32(db)));
336 if (error < kThreshold || x < 2) {
339 if (base[x - 2] < kThreshold
340 || base[width + x - 2] < kThreshold
341 || base[width * 2 + x - 2] < kThreshold
342 || base[x - 1] < kThreshold
343 || base[width + x - 1] < kThreshold
344 || base[width * 2 + x - 1] < kThreshold
345 || base[x] < kThreshold
346 || base[width + x] < kThreshold
347 || base[width * 2 + x] < kThreshold) {
356 static bool addError(TestState* data, const TestResult& testResult) {
357 if (testResult.fPixelError <= 0 && testResult.fTime <= 0) {
360 int worstCount = data->fPixelWorst.count();
361 int pixelError = testResult.fPixelError;
362 if (pixelError > 0) {
363 for (int index = 0; index < worstCount; ++index) {
364 if (pixelError > data->fPixelWorst[index].fPixelError) {
365 data->fPixelWorst[index] = *(SortByPixel*) &testResult;
370 int slowCount = data->fSlowest.count();
371 int time = testResult.fTime;
373 for (int index = 0; index < slowCount; ++index) {
374 if (time > data->fSlowest[index].fTime) {
375 data->fSlowest[index] = *(SortByTime*) &testResult;
380 if (pixelError > 0 && worstCount < kMaxFiles) {
381 *data->fPixelWorst.append() = *(SortByPixel*) &testResult;
384 if (time > 0 && slowCount < kMaxFiles) {
385 *data->fSlowest.append() = *(SortByTime*) &testResult;
391 static SkMSec timePict(SkPicture* pic, SkCanvas* canvas) {
393 SkScalar pWidth = pic->cullRect().width();
394 SkScalar pHeight = pic->cullRect().height();
395 const SkScalar maxDimension = 1000.0f;
396 const int slices = 3;
397 SkScalar xInterval = SkTMax(pWidth - maxDimension, 0.0f) / (slices - 1);
398 SkScalar yInterval = SkTMax(pHeight - maxDimension, 0.0f) / (slices - 1);
399 SkRect rect = {0, 0, SkTMin(maxDimension, pWidth), SkTMin(maxDimension, pHeight) };
400 canvas->clipRect(rect);
401 SkMSec start = SkTime::GetMSecs();
402 for (int x = 0; x < slices; ++x) {
403 for (int y = 0; y < slices; ++y) {
404 pic->playback(canvas);
405 canvas->translate(0, yInterval);
407 canvas->translate(xInterval, -yInterval * slices);
409 SkMSec end = SkTime::GetMSecs();
414 static void drawPict(SkPicture* pic, SkCanvas* canvas, int scale) {
415 canvas->clear(SK_ColorWHITE);
418 canvas->scale(1.0f / scale, 1.0f / scale);
420 pic->playback(canvas);
426 static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pngName) {
427 SkString outFile = get_sum_path(outDir);
428 outFile.appendf("%s%s", PATH_SLASH, pngName);
429 if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100)) {
430 SkDebugf("unable to encode gr %s (width=%d height=%d)\n", pngName,
431 bitmap.width(), bitmap.height());
435 void TestResult::testOne() {
436 SkPicture* pic = NULL;
438 #if DEBUG_SHOW_TEST_NAME
439 if (fTestStep == kCompareBits) {
440 SkString testName(fFilename);
441 const char http[] = "http";
442 if (testName.startsWith(http)) {
443 testName.remove(0, sizeof(http) - 1);
445 while (testName.startsWith("_")) {
446 testName.remove(0, 1);
448 const char dotSkp[] = ".skp";
449 if (testName.endsWith(dotSkp)) {
450 size_t len = testName.size();
451 testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1);
453 testName.prepend("skp");
454 testName.append("1");
455 strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRING_LENGTH);
456 } else if (fTestStep == kEncodeFiles) {
457 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
460 SkString path = get_in_path(fDirNo, fFilename);
461 SkFILEStream stream(path.c_str());
462 if (!stream.isValid()) {
463 SkDebugf("invalid stream %s\n", path.c_str());
466 pic = SkPicture::CreateFromStream(&stream, &SkImageDecoder::DecodeMemory);
468 SkDebugf("unable to decode %s\n", fFilename);
471 SkScalar width = pic->cullRect().width();
472 SkScalar height = pic->cullRect().height();
473 SkBitmap oldBitmap, opBitmap;
475 while (width / fScale > 32767 || height / fScale > 32767) {
479 int dimX = SkScalarCeilToInt(width / fScale);
480 int dimY = SkScalarCeilToInt(height / fScale);
481 if (oldBitmap.tryAllocN32Pixels(dimX, dimY) && opBitmap.tryAllocN32Pixels(dimX, dimY)) {
484 SkDebugf("-%d-", fScale);
485 } while (++fScale < 256);
487 SkDebugf("unable to allocate bitmap for %s (w=%f h=%f)\n", fFilename,
491 oldBitmap.eraseColor(SK_ColorWHITE);
492 SkCanvas oldCanvas(oldBitmap);
493 oldCanvas.setAllowSimplifyClip(false);
494 opBitmap.eraseColor(SK_ColorWHITE);
495 SkCanvas opCanvas(opBitmap);
496 opCanvas.setAllowSimplifyClip(true);
497 drawPict(pic, &oldCanvas, fScale);
498 drawPict(pic, &opCanvas, fScale);
499 if (fTestStep == kCompareBits) {
500 fPixelError = similarBits(oldBitmap, opBitmap);
501 int oldTime = timePict(pic, &oldCanvas);
502 int opTime = timePict(pic, &opCanvas);
503 fTime = SkTMax(0, oldTime - opTime);
504 } else if (fTestStep == kEncodeFiles) {
505 SkString pngStr = make_png_name(fFilename);
506 const char* pngName = pngStr.c_str();
507 writePict(oldBitmap, outOldDir, pngName);
508 writePict(opBitmap, outOpDir, pngName);
517 DEFINE_string2(match, m, "PathOpsSkpClipThreaded",
518 "[~][^]substring[$] [...] of test name to run.\n"
519 "Multiple matches may be separated by spaces.\n"
520 "~ causes a matching test to always be skipped\n"
521 "^ requires the start of the test to match\n"
522 "$ requires the end of the test to match\n"
523 "^ and $ requires an exact match\n"
524 "If a test does not match any list entry,\n"
525 "it is skipped unless some list entry starts with ~");
526 DEFINE_string2(dir, d, NULL, "range of directories (e.g., 1-100)");
527 DEFINE_string2(skp, s, NULL, "skp to test");
528 DEFINE_bool2(single, z, false, "run tests on a single thread internally.");
529 DEFINE_int32(testIndex, 0, "override local test index (PathOpsSkpClipOneOff only).");
530 DEFINE_bool2(verbose, v, false, "enable verbose output.");
532 static bool verbose() {
533 return FLAGS_verbose;
540 sk_bzero(fRun, sizeof(fRun));
546 while (++index < kMaxDir) {
557 while (--index > 0 && !fRun[index])
563 while (++fIndex < kMaxDir) {
575 void set(int start, int end) {
576 while (start < end) {
604 while (fNames && ++fIndex < fNames->count()) {
605 return (*fNames)[fIndex];
610 void set(const SkCommandLineFlags::StringArray& names) {
616 const SkCommandLineFlags::StringArray* fNames;
619 static bool buildTestDir(int dirNo, int firstDirNo,
620 SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sorted) {
621 SkString dirName = get_out_path(dirNo, outStatusDir);
622 if (!dirName.size()) {
625 SkOSFile::Iter iter(dirName.c_str(), "skp");
627 while (iter.next(&filename)) {
630 SkString spaceFile(filename);
631 char* spaces = spaceFile.writable_str();
632 int spaceSize = (int) spaceFile.size();
633 for (int index = 0; index < spaceSize; ++index) {
634 if (spaces[index] == '.') {
638 int success = sscanf(spaces, "%s %d %d skp", test.fFilename,
639 &test.fPixelError, &test.fTime);
641 SkDebugf("failed to scan %s matched=%d\n", filename.c_str(), success);
644 *tests[dirNo - firstDirNo].append() = test;
649 SkTDArray<TestResult>& testSet = tests[dirNo - firstDirNo];
650 int count = testSet.count();
651 for (int index = 0; index < count; ++index) {
652 *sorted[dirNo - firstDirNo].append() = (SortByName*) &testSet[index];
654 if (sorted[dirNo - firstDirNo].count()) {
655 SkTQSort<SortByName>(sorted[dirNo - firstDirNo].begin(),
656 sorted[dirNo - firstDirNo].end() - 1);
664 static void testSkpClip(TestState* data) {
665 data->fResult.testOne();
666 SkString statName(data->fResult.fFilename);
667 SkASSERT(statName.endsWith(".skp"));
668 statName.remove(statName.size() - 4, 4);
669 statName.appendf(".%d.%d.skp", data->fResult.fPixelError, data->fResult.fTime);
670 SkString statusFile = get_out_path(data->fResult.fDirNo, outStatusDir);
671 if (!statusFile.size()) {
672 SkDebugf("failed to create %s", statusFile.c_str());
675 statusFile.appendf("%s%s", PATH_SLASH, statName.c_str());
676 SkFILE* file = sk_fopen(statusFile.c_str(), kWrite_SkFILE_Flag);
678 SkDebugf("failed to create %s", statusFile.c_str());
683 if (data->fResult.fPixelError || data->fResult.fTime) {
684 SkDebugf("%s", data->fResult.progress().c_str());
691 bool Less(const SortByName& a, const SortByName& b);
692 bool Less(const SortByName& a, const SortByName& b) {
696 static bool doOneDir(TestState* state, bool threaded) {
697 int dirNo = state->fResult.fDirNo;
698 SkString dirName = get_in_path(dirNo, NULL);
699 if (!dirName.size()) {
702 SkTDArray<TestResult> tests[1];
703 SkTDArray<SortByName*> sorted[1];
704 if (!buildTestDir(dirNo, dirNo, tests, sorted)) {
707 SkOSFile::Iter iter(dirName.c_str(), "skp");
709 while (iter.next(&filename)) {
710 for (size_t index = 0; index < skipOverCount; ++index) {
711 if (skipOver[index].directory == dirNo
712 && strcmp(filename.c_str(), skipOver[index].filename) == 0) {
719 strncpy(name.fFilename, filename.c_str(), filename.size() - 4); // drop .skp
720 int count = sorted[0].count();
721 int idx = SkTSearch<SortByName, Less>(sorted[0].begin(), count, &name, sizeof(&name));
723 SortByName* found = sorted[0][idx];
724 (void) addError(state, *found);
728 test.init(dirNo, filename);
729 state->fResult = test;
731 #if 0 // artificially limit to a few while debugging code
732 static int debugLimit = 0;
733 if (++debugLimit == 5) {
744 static void initTest() {
745 #if !defined SK_BUILD_FOR_WIN && !defined SK_BUILD_FOR_MAC
746 SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true);
747 SK_CONF_SET("images.png.suppressDecoderWarnings", true);
751 static void testSkpClipEncode(TestState* data) {
752 data->fResult.testOne();
758 static void encodeFound(TestState& state) {
760 if (state.fPixelWorst.count()) {
761 SkTDArray<SortByPixel*> worst;
762 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
763 *worst.append() = &state.fPixelWorst[index];
765 SkTQSort<SortByPixel>(worst.begin(), worst.end() - 1);
766 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
767 const TestResult& result = *worst[index];
768 SkDebugf("%d %s pixelError=%d\n", result.fDirNo, result.fFilename, result.fPixelError);
771 if (state.fSlowest.count()) {
772 SkTDArray<SortByTime*> slowest;
773 for (int index = 0; index < state.fSlowest.count(); ++index) {
774 *slowest.append() = &state.fSlowest[index];
776 if (slowest.count() > 0) {
777 SkTQSort<SortByTime>(slowest.begin(), slowest.end() - 1);
778 for (int index = 0; index < slowest.count(); ++index) {
779 const TestResult& result = *slowest[index];
780 SkDebugf("%d %s time=%d\n", result.fDirNo, result.fFilename, result.fTime);
785 TestRunner testRunner;
786 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
787 const TestResult& result = state.fPixelWorst[index];
788 SkString filename(result.fFilename);
789 if (!filename.endsWith(".skp")) {
790 filename.append(".skp");
792 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableEncode,
793 (&testSkpClipEncode, result.fDirNo, filename.c_str(), &testRunner));
803 const char* getName() { onGetName(&fName); return fName.c_str(); }
804 void run() { onRun(); }
807 virtual void onGetName(SkString*) = 0;
808 virtual void onRun() = 0;
814 typedef SkTRegistry<Test*(*)(void*)> TestRegistry;
816 #define DEF_TEST(name) \
817 static void test_##name(); \
818 class name##Class : public Test { \
820 static Test* Factory(void*) { return SkNEW(name##Class); } \
822 void onGetName(SkString* name) SK_OVERRIDE { \
825 void onRun() SK_OVERRIDE { test_##name(); } \
827 static TestRegistry gReg_##name##Class(name##Class::Factory); \
828 static void test_##name()
830 DEF_TEST(PathOpsSkpClip) {
833 SkTArray<TestResult, true> errors;
838 while ((dirNo = gDirs.next()) > 0) {
840 SkDebugf("dirNo=%d\n", dirNo);
842 state.fResult.fDirNo = dirNo;
843 if (!doOneDir(&state, false)) {
850 static void testSkpClipMain(TestState* data) {
851 (void) doOneDir(data, true);
854 DEF_TEST(PathOpsSkpClipThreaded) {
857 TestRunner testRunner;
860 while ((dirNo = gDirs.next()) > 0) {
861 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableDir,
862 (&testSkpClipMain, dirNo, &testRunner));
868 while ((dirNo = gDirs.next()) > 0) {
869 TestState& testState = testRunner.fRunnables[dirNo - 1]->fState;
870 SkASSERT(testState.fResult.fDirNo == dirNo);
871 for (int inner = 0; inner < testState.fPixelWorst.count(); ++inner) {
872 addError(&state, testState.fPixelWorst[inner]);
874 for (int inner = 0; inner < testState.fSlowest.count(); ++inner) {
875 addError(&state, testState.fSlowest[inner]);
881 static bool buildTests(SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sorted) {
882 int firstDirNo = gDirs.first();
884 while ((dirNo = gDirs.next()) > 0) {
885 if (!buildTestDir(dirNo, firstDirNo, tests, sorted)) {
892 DEF_TEST(PathOpsSkpClipUberThreaded) {
894 const int firstDirNo = gDirs.next();
895 const int lastDirNo = gDirs.last();
897 int dirCount = lastDirNo - firstDirNo + 1;
898 SkAutoTDeleteArray<SkTDArray<TestResult> > tests(new SkTDArray<TestResult>[dirCount]);
899 SkAutoTDeleteArray<SkTDArray<SortByName*> > sorted(new SkTDArray<SortByName*>[dirCount]);
900 if (!buildTests(tests.get(), sorted.get())) {
903 TestRunner testRunner;
906 while ((dirNo = gDirs.next()) > 0) {
907 SkString dirName = get_in_path(dirNo, NULL);
908 if (!dirName.size()) {
911 SkOSFile::Iter iter(dirName.c_str(), "skp");
913 while (iter.next(&filename)) {
914 for (size_t index = 0; index < skipOverCount; ++index) {
915 if (skipOver[index].directory == dirNo
916 && strcmp(filename.c_str(), skipOver[index].filename) == 0) {
923 strncpy(name.fFilename, filename.c_str(), filename.size() - 4); // drop .skp
924 int count = sorted.get()[dirNo - firstDirNo].count();
925 if (SkTSearch<SortByName, Less>(sorted.get()[dirNo - firstDirNo].begin(),
926 count, &name, sizeof(&name)) < 0) {
927 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableFile,
928 (&testSkpClip, dirNo, filename.c_str(), &testRunner));
937 SkAutoTDeleteArray<SkTDArray<TestResult> > results(new SkTDArray<TestResult>[dirCount]);
938 if (!buildTests(results.get(), NULL)) {
941 SkTDArray<TestResult> allResults;
942 for (int dirNo = firstDirNo; dirNo <= lastDirNo; ++dirNo) {
943 SkTDArray<TestResult>& array = results.get()[dirNo - firstDirNo];
944 allResults.append(array.count(), array.begin());
946 int allCount = allResults.count();
947 SkTDArray<SortByPixel*> pixels;
948 SkTDArray<SortByTime*> times;
949 for (int index = 0; index < allCount; ++index) {
950 *pixels.append() = (SortByPixel*) &allResults[index];
951 *times.append() = (SortByTime*) &allResults[index];
954 if (pixels.count()) {
955 SkTQSort<SortByPixel>(pixels.begin(), pixels.end() - 1);
956 for (int inner = 0; inner < kMaxFiles; ++inner) {
957 *state.fPixelWorst.append() = *pixels[allCount - inner - 1];
961 SkTQSort<SortByTime>(times.begin(), times.end() - 1);
962 for (int inner = 0; inner < kMaxFiles; ++inner) {
963 *state.fSlowest.append() = *times[allCount - inner - 1];
969 DEF_TEST(PathOpsSkpClipOneOff) {
970 const int testIndex = FLAGS_testIndex;
971 int dirNo = gDirs.next();
973 dirNo = skipOver[testIndex].directory;
975 const char* skp = gNames.next();
977 skp = skipOver[testIndex].filename;
980 SkAssertResult(get_in_path(dirNo, skp).size());
981 SkString filename(skp);
983 state.test(dirNo, filename);
985 SkDebugf("%s", state.status().c_str());
987 state.fTestStep = kEncodeFiles;
991 DEF_TEST(PathOpsTestSkipped) {
992 for (size_t index = 0; index < skipOverCount; ++index) {
993 const SkipOverTest& skip = skipOver[index];
994 if (!skip.blamePathOps) {
997 int dirNo = skip.directory;
998 const char* skp = skip.filename;
1000 SkAssertResult(get_in_path(dirNo, skp).size());
1001 SkString filename(skp);
1003 state.test(dirNo, filename);
1005 SkDebugf("%s", state.status().c_str());
1007 state.fTestStep = kEncodeFiles;
1012 DEF_TEST(PathOpsCopyFails) {
1013 FLAGS_verbose = true;
1014 for (size_t index = 0; index < skipOverCount; ++index) {
1015 int dirNo = skipOver[index].directory;
1016 SkDebugf("mkdir -p " IN_DIR_PRE "%d" DIR_POST "\n", dirNo);
1018 for (size_t index = 0; index < skipOverCount; ++index) {
1019 int dirNo = skipOver[index].directory;
1020 const char* filename = skipOver[index].filename;
1021 SkDebugf("rsync -av cary-linux.cnc:/tera" PATH_SLASH "skps" PATH_SLASH "slave"
1022 "%d" DIR_POST "/%s " IN_DIR_PRE "%d" DIR_POST "\n", dirNo, filename, dirNo);
1026 template TestRegistry* TestRegistry::gHead;
1030 Iter() { this->reset(); }
1031 void reset() { fReg = TestRegistry::Head(); }
1035 TestRegistry::Factory fact = fReg->factory();
1036 fReg = fReg->next();
1037 Test* test = fact(NULL);
1044 const TestRegistry* fReg;
1047 int tool_main(int argc, char** argv);
1048 int tool_main(int argc, char** argv) {
1049 SetupCrashHandler();
1050 SkCommandLineFlags::SetUsage("");
1051 SkCommandLineFlags::Parse(argc, argv);
1053 SkString header("PathOps SkpClip:");
1054 if (!FLAGS_match.isEmpty()) {
1055 header.appendf(" --match");
1056 for (int index = 0; index < FLAGS_match.count(); ++index) {
1057 header.appendf(" %s", FLAGS_match[index]);
1060 if (!FLAGS_dir.isEmpty()) {
1061 int count = FLAGS_dir.count();
1062 for (int i = 0; i < count; ++i) {
1063 const char* range = FLAGS_dir[i];
1064 const char* dash = strchr(range, '-');
1066 dash = strchr(range, ',');
1068 int first = atoi(range);
1069 int last = dash ? atoi(dash + 1) : first;
1070 if (!first || !last) {
1071 SkDebugf("couldn't parse --dir %s\n", range);
1074 gDirs.set(first, last);
1077 if (!FLAGS_skp.isEmpty()) {
1078 gNames.set(FLAGS_skp);
1081 header.append(" SK_DEBUG");
1083 header.append(" SK_RELEASE");
1085 header.appendf(" skia_arch_width=%d", (int)sizeof(void*) * 8);
1086 if (FLAGS_verbose) {
1087 header.appendf("\n");
1089 SkDebugf("%s", header.c_str());
1092 while ((test = iter.next()) != NULL) {
1093 SkAutoTDelete<Test> owned(test);
1094 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) {
1102 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
1103 int main(int argc, char * const argv[]) {
1104 return tool_main(argc, (char**) argv);