borenet | 4808757 | 2015-04-02 12:16:36 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 8 | #include "CrashHandler.h" |
| 9 | // #include "OverwriteLine.h" |
| 10 | #include "Resources.h" |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 11 | #include "SkBitmap.h" |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 12 | #include "SkCanvas.h" |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 13 | #include "SkColor.h" |
| 14 | #include "SkColorPriv.h" |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 15 | #include "SkCommandLineFlags.h" |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 16 | #include "SkForceLinking.h" |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 17 | #include "SkGraphics.h" |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 18 | #include "SkImageEncoder.h" |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 19 | #include "SkOSFile.h" |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 20 | #include "SkPathOpsDebug.h" |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 21 | #include "SkPicture.h" |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 22 | #include "SkRTConf.h" |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 23 | #include "SkTSort.h" |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 24 | #include "SkStream.h" |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 25 | #include "SkString.h" |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 26 | #include "SkTArray.h" |
| 27 | #include "SkTDArray.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 28 | #include "SkTaskGroup.h" |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 29 | #include "SkTemplates.h" |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 30 | #include "SkTime.h" |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 31 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 32 | #include <stdlib.h> |
| 33 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 34 | /* add local exceptions here */ |
| 35 | /* TODO : add command flag interface */ |
| 36 | const struct SkipOverTest { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 37 | int directory; |
| 38 | const char* filename; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 39 | bool blamePathOps; |
| 40 | } skipOver[] = { |
| 41 | { 2, "http___www_groupon_sg_.skp", false}, // SkAAClip::Builder::addRun SkASSERT(fBounds.contains(x, y)); |
| 42 | { 6, "http___www_googleventures_com_.skp", true}, // addTCoincident SkASSERT(test->fT < 1); |
| 43 | { 7, "http___www_foxsports_nl_.skp", true}, // (no repro on mac) addT SkASSERT(this != other || fVerb == SkPath::kCubic_Verb) |
| 44 | {13, "http___www_modernqigong_com_.skp", false}, // SkAAClip::Builder::addRun SkASSERT(fBounds.contains(x, y)); |
| 45 | {14, "http___www_devbridge_com_.skp", true}, // checkSmallCoincidence SkASSERT(!next->fSmall || checkMultiple); |
caryclark | 5e27e0e | 2014-08-12 07:46:33 -0700 | [diff] [blame] | 46 | {16, "http___www_1023world_net_.skp", false}, // bitmap decode assert (corrupt skp?) |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 47 | {19, "http___www_alamdi_com_.skp", true}, // cubic/quad intersection |
| 48 | {26, "http___www_liveencounters_net_.skp", true}, // (no repro on mac) checkSmall addT:549 (line, expects cubic) |
| 49 | {28, "http___www_encros_fr_.skp", false}, // SkAAClip::Builder::addRun SkASSERT(fBounds.contains(x, y)); |
| 50 | {37, "http___www_familysurvivalprotocol_wordpress_com_.skp", true}, // bumpSpan SkASSERT(span->fOppValue >= 0); |
| 51 | {39, "http___sufeinet_com_.skp", false}, // bitmap decode assert (corrupt skp?) |
| 52 | {41, "http___www_rano360_com_.skp", true}, // checkSmallCoincidence SkASSERT(!next->fSmall || checkMultiple); |
| 53 | {44, "http___www_firstunitedbank_com_.skp", true}, // addTCancel SkASSERT(oIndex > 0); |
| 54 | {46, "http___www_shinydemos_com_.skp", true}, // addSimpleAngle SkASSERT(index == count() - 2); |
| 55 | {48, "http___www_familysurvivalprotocol_com_.skp", true}, // bumpSpan SkASSERT "span->fOppValue >= 0" |
| 56 | {57, "http___www_lptemp_com_.skp", true}, // addTCoincident oPeek = &other->fTs[++oPeekIndex]; |
| 57 | {71, "http___www_1milyonkahraman_org_.skp", true}, // addTCoincident SkASSERT(test->fT < 1); |
| 58 | {88, "http___www_apuntesdelechuza_wordpress_com_.skp", true}, // bumpSpan SkASSERT "span->fOppValue >= 0" |
| 59 | {89, "http___www_mobilizedconsulting_com_.skp", true}, // addTCancel SkASSERT(oIndex > 0); |
| 60 | {93, "http___www_simple_living_in_suffolk_co_uk_.skp", true}, // bumpSpan SkASSERT "span->fOppValue >= 0" |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 61 | }; |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 62 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 63 | size_t skipOverCount = sizeof(skipOver) / sizeof(skipOver[0]); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 64 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 65 | |
| 66 | /* customize file in/out here */ |
| 67 | /* TODO : add command flag interface */ |
| 68 | #define CHROME_VERSION "1e5dfa4-4a995df" |
| 69 | #define SUMMARY_RUN 1 |
| 70 | |
| 71 | #ifdef SK_BUILD_FOR_WIN |
| 72 | #define DRIVE_SPEC "D:" |
| 73 | #define PATH_SLASH "\\" |
| 74 | #else |
| 75 | #define DRIVE_SPEC "" |
| 76 | #define PATH_SLASH "/" |
| 77 | #endif |
| 78 | |
| 79 | #define IN_DIR_PRE DRIVE_SPEC PATH_SLASH "skps" PATH_SLASH "slave" |
| 80 | #define OUT_DIR_PRE DRIVE_SPEC PATH_SLASH "skpOut" PATH_SLASH "slave" |
| 81 | #define OUT_DIR_SUM DRIVE_SPEC PATH_SLASH "skpOut" PATH_SLASH "summary" |
| 82 | #define DIR_POST PATH_SLASH "All" PATH_SLASH CHROME_VERSION |
| 83 | |
| 84 | static const char outOpDir[] = "opClip"; |
| 85 | static const char outOldDir[] = "oldClip"; |
| 86 | static const char outStatusDir[] = "statusTest"; |
| 87 | |
| 88 | static SkString get_in_path(int dirNo, const char* filename) { |
| 89 | SkString path; |
| 90 | SkASSERT(dirNo); |
| 91 | path.appendf("%s%d%s", IN_DIR_PRE, dirNo, DIR_POST); |
| 92 | if (!sk_exists(path.c_str())) { |
| 93 | SkDebugf("could not read %s\n", path.c_str()); |
| 94 | return SkString(); |
| 95 | } |
| 96 | if (filename) { |
| 97 | path.appendf("%s%s", PATH_SLASH, filename); |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 98 | if (!sk_exists(path.c_str())) { |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 99 | SkDebugf("could not read %s\n", path.c_str()); |
| 100 | return SkString(); |
| 101 | } |
| 102 | } |
| 103 | return path; |
| 104 | } |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 105 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 106 | static void make_recursive_dir(const SkString& path) { |
| 107 | if (sk_exists(path.c_str())) { |
| 108 | return; |
| 109 | } |
| 110 | const char* pathStr = path.c_str(); |
| 111 | int last = (int) path.size(); |
| 112 | do { |
| 113 | while (last > 0 && pathStr[--last] != PATH_SLASH[0]) |
| 114 | ; |
| 115 | SkASSERT(last > 0); |
| 116 | SkString shorter(pathStr, last); |
| 117 | if (sk_mkdir(shorter.c_str())) { |
| 118 | break; |
| 119 | } |
| 120 | } while (true); |
| 121 | do { |
| 122 | while (last < (int) path.size() && pathStr[++last] != PATH_SLASH[0]) |
| 123 | ; |
| 124 | SkString shorter(pathStr, last); |
| 125 | SkAssertResult(sk_mkdir(shorter.c_str())); |
| 126 | } while (last < (int) path.size()); |
| 127 | } |
| 128 | |
| 129 | static SkString get_out_path(int dirNo, const char* dirName) { |
| 130 | SkString path; |
| 131 | SkASSERT(dirNo); |
| 132 | SkASSERT(dirName); |
| 133 | path.appendf("%s%d%s%s%s", OUT_DIR_PRE, dirNo, DIR_POST, PATH_SLASH, dirName); |
| 134 | make_recursive_dir(path); |
| 135 | return path; |
| 136 | } |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 137 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 138 | static SkString get_sum_path(const char* dirName) { |
| 139 | SkString path; |
| 140 | SkASSERT(dirName); |
| 141 | path.appendf("%s%d%s%s", OUT_DIR_SUM, SUMMARY_RUN, PATH_SLASH, dirName); |
| 142 | SkDebugf("%s\n", path.c_str()); |
| 143 | make_recursive_dir(path); |
| 144 | return path; |
| 145 | } |
| 146 | |
| 147 | static SkString make_png_name(const char* filename) { |
| 148 | SkString pngName = SkString(filename); |
| 149 | pngName.remove(pngName.size() - 3, 3); |
| 150 | pngName.append("png"); |
| 151 | return pngName; |
| 152 | } |
| 153 | |
| 154 | //////////////////////////////////////////////////////// |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 155 | |
| 156 | enum TestStep { |
| 157 | kCompareBits, |
| 158 | kEncodeFiles, |
| 159 | }; |
| 160 | |
| 161 | enum { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 162 | kMaxLength = 256, |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 163 | kMaxFiles = 128, |
| 164 | kSmallLimit = 1000, |
| 165 | }; |
| 166 | |
| 167 | struct TestResult { |
| 168 | void init(int dirNo) { |
| 169 | fDirNo = dirNo; |
| 170 | sk_bzero(fFilename, sizeof(fFilename)); |
| 171 | fTestStep = kCompareBits; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 172 | fScale = 1; |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 173 | } |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 174 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 175 | void init(int dirNo, const SkString& filename) { |
| 176 | fDirNo = dirNo; |
| 177 | strcpy(fFilename, filename.c_str()); |
| 178 | fTestStep = kCompareBits; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 179 | fScale = 1; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 180 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 181 | |
| 182 | SkString status() { |
| 183 | SkString outStr; |
| 184 | outStr.printf("%s %d %d\n", fFilename, fPixelError, fTime); |
| 185 | return outStr; |
| 186 | } |
| 187 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 188 | SkString progress() { |
| 189 | SkString outStr; |
| 190 | outStr.printf("dir=%d %s ", fDirNo, fFilename); |
| 191 | if (fPixelError) { |
| 192 | outStr.appendf(" err=%d", fPixelError); |
| 193 | } |
| 194 | if (fTime) { |
| 195 | outStr.appendf(" time=%d", fTime); |
| 196 | } |
| 197 | if (fScale != 1) { |
| 198 | outStr.appendf(" scale=%d", fScale); |
| 199 | } |
| 200 | outStr.appendf("\n"); |
| 201 | return outStr; |
| 202 | |
| 203 | } |
| 204 | |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 205 | void test(int dirNo, const SkString& filename) { |
| 206 | init(dirNo); |
| 207 | strcpy(fFilename, filename.c_str()); |
| 208 | testOne(); |
| 209 | } |
| 210 | |
| 211 | void testOne(); |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 212 | |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 213 | char fFilename[kMaxLength]; |
| 214 | TestStep fTestStep; |
| 215 | int fDirNo; |
| 216 | int fPixelError; |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 217 | SkMSec fTime; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 218 | int fScale; |
| 219 | }; |
| 220 | |
| 221 | class SortByPixel : public TestResult { |
| 222 | public: |
| 223 | bool operator<(const SortByPixel& rh) const { |
| 224 | return fPixelError < rh.fPixelError; |
| 225 | } |
| 226 | }; |
| 227 | |
| 228 | class SortByTime : public TestResult { |
| 229 | public: |
| 230 | bool operator<(const SortByTime& rh) const { |
| 231 | return fTime < rh.fTime; |
| 232 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 233 | }; |
| 234 | |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 235 | class SortByName : public TestResult { |
| 236 | public: |
| 237 | bool operator<(const SortByName& rh) const { |
| 238 | return strcmp(fFilename, rh.fFilename) < 0; |
| 239 | } |
| 240 | }; |
| 241 | |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 242 | struct TestState { |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 243 | void init(int dirNo) { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 244 | fResult.init(dirNo); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 245 | } |
| 246 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 247 | SkTDArray<SortByPixel> fPixelWorst; |
| 248 | SkTDArray<SortByTime> fSlowest; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 249 | TestResult fResult; |
| 250 | }; |
| 251 | |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 252 | struct TestRunner { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 253 | ~TestRunner(); |
| 254 | void render(); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 255 | SkTDArray<class TestRunnable*> fRunnables; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 256 | }; |
| 257 | |
mtklein | 048494c | 2016-02-16 19:06:15 -0800 | [diff] [blame] | 258 | class TestRunnable { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 259 | public: |
mtklein | 048494c | 2016-02-16 19:06:15 -0800 | [diff] [blame] | 260 | void operator()() { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 261 | SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024); |
| 262 | (*fTestFun)(&fState); |
| 263 | } |
| 264 | |
| 265 | TestState fState; |
| 266 | void (*fTestFun)(TestState*); |
| 267 | }; |
| 268 | |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 269 | |
| 270 | class TestRunnableDir : public TestRunnable { |
| 271 | public: |
| 272 | TestRunnableDir(void (*testFun)(TestState*), int dirNo, TestRunner* runner) { |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 273 | fState.init(dirNo); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 274 | fTestFun = testFun; |
| 275 | } |
| 276 | |
| 277 | }; |
| 278 | |
| 279 | class TestRunnableFile : public TestRunnable { |
| 280 | public: |
| 281 | TestRunnableFile(void (*testFun)(TestState*), int dirNo, const char* name, TestRunner* runner) { |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 282 | fState.init(dirNo); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 283 | strcpy(fState.fResult.fFilename, name); |
| 284 | fTestFun = testFun; |
| 285 | } |
| 286 | }; |
| 287 | |
| 288 | class TestRunnableEncode : public TestRunnableFile { |
| 289 | public: |
| 290 | TestRunnableEncode(void (*testFun)(TestState*), int dirNo, const char* name, TestRunner* runner) |
| 291 | : TestRunnableFile(testFun, dirNo, name, runner) { |
| 292 | fState.fResult.fTestStep = kEncodeFiles; |
| 293 | } |
| 294 | }; |
| 295 | |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 296 | TestRunner::~TestRunner() { |
| 297 | for (int index = 0; index < fRunnables.count(); index++) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 298 | delete fRunnables[index]; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
| 302 | void TestRunner::render() { |
mtklein | 279c786 | 2016-01-04 19:13:19 -0800 | [diff] [blame] | 303 | SkTaskGroup().batch(fRunnables.count(), [&](int i) { |
mtklein | 048494c | 2016-02-16 19:06:15 -0800 | [diff] [blame] | 304 | (*fRunnables[i])(); |
mtklein | 00b621c | 2015-06-17 15:26:15 -0700 | [diff] [blame] | 305 | }); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | //////////////////////////////////////////////// |
| 309 | |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 310 | |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 311 | static int similarBits(const SkBitmap& gr, const SkBitmap& sk) { |
| 312 | const int kRowCount = 3; |
| 313 | const int kThreshold = 3; |
| 314 | int width = SkTMin(gr.width(), sk.width()); |
| 315 | if (width < kRowCount) { |
| 316 | return true; |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 317 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 318 | int height = SkTMin(gr.height(), sk.height()); |
| 319 | if (height < kRowCount) { |
| 320 | return true; |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 321 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 322 | int errorTotal = 0; |
| 323 | SkTArray<int, true> errorRows; |
| 324 | errorRows.push_back_n(width * kRowCount); |
| 325 | SkAutoLockPixels autoGr(gr); |
| 326 | SkAutoLockPixels autoSk(sk); |
| 327 | for (int y = 0; y < height; ++y) { |
| 328 | SkPMColor* grRow = gr.getAddr32(0, y); |
| 329 | SkPMColor* skRow = sk.getAddr32(0, y); |
| 330 | int* base = &errorRows[0]; |
| 331 | int* cOut = &errorRows[y % kRowCount]; |
| 332 | for (int x = 0; x < width; ++x) { |
| 333 | SkPMColor grColor = grRow[x]; |
| 334 | SkPMColor skColor = skRow[x]; |
| 335 | int dr = SkGetPackedR32(grColor) - SkGetPackedR32(skColor); |
| 336 | int dg = SkGetPackedG32(grColor) - SkGetPackedG32(skColor); |
| 337 | int db = SkGetPackedB32(grColor) - SkGetPackedB32(skColor); |
| 338 | int error = cOut[x] = SkTMax(SkAbs32(dr), SkTMax(SkAbs32(dg), SkAbs32(db))); |
| 339 | if (error < kThreshold || x < 2) { |
| 340 | continue; |
| 341 | } |
| 342 | if (base[x - 2] < kThreshold |
| 343 | || base[width + x - 2] < kThreshold |
| 344 | || base[width * 2 + x - 2] < kThreshold |
| 345 | || base[x - 1] < kThreshold |
| 346 | || base[width + x - 1] < kThreshold |
| 347 | || base[width * 2 + x - 1] < kThreshold |
| 348 | || base[x] < kThreshold |
| 349 | || base[width + x] < kThreshold |
| 350 | || base[width * 2 + x] < kThreshold) { |
| 351 | continue; |
| 352 | } |
| 353 | errorTotal += error; |
| 354 | } |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 355 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 356 | return errorTotal; |
| 357 | } |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 358 | |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 359 | static bool addError(TestState* data, const TestResult& testResult) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 360 | if (testResult.fPixelError <= 0 && testResult.fTime <= 0) { |
| 361 | return false; |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 362 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 363 | int worstCount = data->fPixelWorst.count(); |
| 364 | int pixelError = testResult.fPixelError; |
| 365 | if (pixelError > 0) { |
| 366 | for (int index = 0; index < worstCount; ++index) { |
| 367 | if (pixelError > data->fPixelWorst[index].fPixelError) { |
| 368 | data->fPixelWorst[index] = *(SortByPixel*) &testResult; |
| 369 | return true; |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | int slowCount = data->fSlowest.count(); |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 374 | SkMSec time = testResult.fTime; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 375 | if (time > 0) { |
| 376 | for (int index = 0; index < slowCount; ++index) { |
| 377 | if (time > data->fSlowest[index].fTime) { |
| 378 | data->fSlowest[index] = *(SortByTime*) &testResult; |
| 379 | return true; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | if (pixelError > 0 && worstCount < kMaxFiles) { |
| 384 | *data->fPixelWorst.append() = *(SortByPixel*) &testResult; |
| 385 | return true; |
| 386 | } |
| 387 | if (time > 0 && slowCount < kMaxFiles) { |
| 388 | *data->fSlowest.append() = *(SortByTime*) &testResult; |
| 389 | return true; |
| 390 | } |
| 391 | return false; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 392 | } |
| 393 | |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 394 | static SkMSec timePict(SkPicture* pic, SkCanvas* canvas) { |
| 395 | canvas->save(); |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 396 | SkScalar pWidth = pic->cullRect().width(); |
| 397 | SkScalar pHeight = pic->cullRect().height(); |
| 398 | const SkScalar maxDimension = 1000.0f; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 399 | const int slices = 3; |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 400 | SkScalar xInterval = SkTMax(pWidth - maxDimension, 0.0f) / (slices - 1); |
| 401 | SkScalar yInterval = SkTMax(pHeight - maxDimension, 0.0f) / (slices - 1); |
| 402 | SkRect rect = {0, 0, SkTMin(maxDimension, pWidth), SkTMin(maxDimension, pHeight) }; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 403 | canvas->clipRect(rect); |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 404 | double start = SkTime::GetMSecs(); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 405 | for (int x = 0; x < slices; ++x) { |
| 406 | for (int y = 0; y < slices; ++y) { |
robertphillips | c5ba71d | 2014-09-04 08:42:50 -0700 | [diff] [blame] | 407 | pic->playback(canvas); |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 408 | canvas->translate(0, yInterval); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 409 | } |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 410 | canvas->translate(xInterval, -yInterval * slices); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 411 | } |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 412 | double end = SkTime::GetMSecs(); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 413 | canvas->restore(); |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 414 | return static_cast<SkMSec>(end - start); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | static void drawPict(SkPicture* pic, SkCanvas* canvas, int scale) { |
| 418 | canvas->clear(SK_ColorWHITE); |
| 419 | if (scale != 1) { |
| 420 | canvas->save(); |
| 421 | canvas->scale(1.0f / scale, 1.0f / scale); |
| 422 | } |
robertphillips | c5ba71d | 2014-09-04 08:42:50 -0700 | [diff] [blame] | 423 | pic->playback(canvas); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 424 | if (scale != 1) { |
| 425 | canvas->restore(); |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pngName) { |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 430 | SkString outFile = get_sum_path(outDir); |
| 431 | outFile.appendf("%s%s", PATH_SLASH, pngName); |
| 432 | if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100)) { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 433 | SkDebugf("unable to encode gr %s (width=%d height=%d)\n", pngName, |
| 434 | bitmap.width(), bitmap.height()); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | void TestResult::testOne() { |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 439 | sk_sp<SkPicture> pic; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 440 | { |
| 441 | #if DEBUG_SHOW_TEST_NAME |
| 442 | if (fTestStep == kCompareBits) { |
| 443 | SkString testName(fFilename); |
| 444 | const char http[] = "http"; |
| 445 | if (testName.startsWith(http)) { |
| 446 | testName.remove(0, sizeof(http) - 1); |
| 447 | } |
| 448 | while (testName.startsWith("_")) { |
| 449 | testName.remove(0, 1); |
| 450 | } |
| 451 | const char dotSkp[] = ".skp"; |
| 452 | if (testName.endsWith(dotSkp)) { |
| 453 | size_t len = testName.size(); |
| 454 | testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1); |
| 455 | } |
| 456 | testName.prepend("skp"); |
| 457 | testName.append("1"); |
| 458 | strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRING_LENGTH); |
| 459 | } else if (fTestStep == kEncodeFiles) { |
| 460 | strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH); |
| 461 | } |
| 462 | #endif |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 463 | SkString path = get_in_path(fDirNo, fFilename); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 464 | SkFILEStream stream(path.c_str()); |
| 465 | if (!stream.isValid()) { |
| 466 | SkDebugf("invalid stream %s\n", path.c_str()); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 467 | return; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 468 | } |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 469 | pic = SkPicture::MakeFromStream(&stream); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 470 | if (!pic) { |
| 471 | SkDebugf("unable to decode %s\n", fFilename); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 472 | return; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 473 | } |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 474 | SkScalar width = pic->cullRect().width(); |
| 475 | SkScalar height = pic->cullRect().height(); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 476 | SkBitmap oldBitmap, opBitmap; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 477 | fScale = 1; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 478 | while (width / fScale > 32767 || height / fScale > 32767) { |
| 479 | ++fScale; |
| 480 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 481 | do { |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 482 | int dimX = SkScalarCeilToInt(width / fScale); |
| 483 | int dimY = SkScalarCeilToInt(height / fScale); |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 484 | if (oldBitmap.tryAllocN32Pixels(dimX, dimY) && opBitmap.tryAllocN32Pixels(dimX, dimY)) { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 485 | break; |
| 486 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 487 | SkDebugf("-%d-", fScale); |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 488 | } while (++fScale < 256); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 489 | if (fScale >= 256) { |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 490 | SkDebugf("unable to allocate bitmap for %s (w=%f h=%f)\n", fFilename, |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 491 | width, height); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 492 | return; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 493 | } |
| 494 | oldBitmap.eraseColor(SK_ColorWHITE); |
| 495 | SkCanvas oldCanvas(oldBitmap); |
| 496 | oldCanvas.setAllowSimplifyClip(false); |
| 497 | opBitmap.eraseColor(SK_ColorWHITE); |
| 498 | SkCanvas opCanvas(opBitmap); |
| 499 | opCanvas.setAllowSimplifyClip(true); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 500 | drawPict(pic.get(), &oldCanvas, fScale); |
| 501 | drawPict(pic.get(), &opCanvas, fScale); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 502 | if (fTestStep == kCompareBits) { |
| 503 | fPixelError = similarBits(oldBitmap, opBitmap); |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 504 | SkMSec oldTime = timePict(pic.get(), &oldCanvas); |
| 505 | SkMSec opTime = timePict(pic.get(), &opCanvas); |
| 506 | fTime = SkTMax(static_cast<SkMSec>(0), oldTime - opTime); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 507 | } else if (fTestStep == kEncodeFiles) { |
| 508 | SkString pngStr = make_png_name(fFilename); |
| 509 | const char* pngName = pngStr.c_str(); |
| 510 | writePict(oldBitmap, outOldDir, pngName); |
| 511 | writePict(opBitmap, outOpDir, pngName); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 512 | } |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 513 | } |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 514 | } |
| 515 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 516 | DEFINE_string2(match, m, "PathOpsSkpClipThreaded", |
| 517 | "[~][^]substring[$] [...] of test name to run.\n" |
| 518 | "Multiple matches may be separated by spaces.\n" |
| 519 | "~ causes a matching test to always be skipped\n" |
| 520 | "^ requires the start of the test to match\n" |
| 521 | "$ requires the end of the test to match\n" |
| 522 | "^ and $ requires an exact match\n" |
| 523 | "If a test does not match any list entry,\n" |
| 524 | "it is skipped unless some list entry starts with ~"); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 525 | DEFINE_string2(dir, d, nullptr, "range of directories (e.g., 1-100)"); |
| 526 | DEFINE_string2(skp, s, nullptr, "skp to test"); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 527 | DEFINE_bool2(single, z, false, "run tests on a single thread internally."); |
| 528 | DEFINE_int32(testIndex, 0, "override local test index (PathOpsSkpClipOneOff only)."); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 529 | DEFINE_bool2(verbose, v, false, "enable verbose output."); |
| 530 | |
| 531 | static bool verbose() { |
| 532 | return FLAGS_verbose; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 533 | } |
| 534 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 535 | class Dirs { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 536 | public: |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 537 | Dirs() { |
| 538 | reset(); |
| 539 | sk_bzero(fRun, sizeof(fRun)); |
| 540 | fSet = false; |
| 541 | } |
| 542 | |
| 543 | int first() const { |
| 544 | int index = 0; |
| 545 | while (++index < kMaxDir) { |
| 546 | if (fRun[index]) { |
| 547 | return index; |
| 548 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 549 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 550 | SkASSERT(0); |
| 551 | return -1; |
| 552 | } |
| 553 | |
| 554 | int last() const { |
| 555 | int index = kMaxDir; |
| 556 | while (--index > 0 && !fRun[index]) |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 557 | ; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 558 | return index; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 559 | } |
| 560 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 561 | int next() { |
| 562 | while (++fIndex < kMaxDir) { |
| 563 | if (fRun[fIndex]) { |
| 564 | return fIndex; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 565 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 566 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 567 | return -1; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 568 | } |
| 569 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 570 | void reset() { |
| 571 | fIndex = -1; |
| 572 | } |
| 573 | |
| 574 | void set(int start, int end) { |
| 575 | while (start < end) { |
| 576 | fRun[start++] = 1; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 577 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 578 | fSet = true; |
| 579 | } |
| 580 | |
| 581 | void setDefault() { |
| 582 | if (!fSet) { |
| 583 | set(1, 100); |
| 584 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | private: |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 588 | enum { |
| 589 | kMaxDir = 101 |
| 590 | }; |
| 591 | char fRun[kMaxDir]; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 592 | int fIndex; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 593 | bool fSet; |
| 594 | } gDirs; |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 595 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 596 | class Filenames { |
| 597 | public: |
| 598 | Filenames() |
| 599 | : fIndex(-1) { |
| 600 | } |
| 601 | |
| 602 | const char* next() { |
| 603 | while (fNames && ++fIndex < fNames->count()) { |
| 604 | return (*fNames)[fIndex]; |
| 605 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 606 | return nullptr; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 607 | } |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 608 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 609 | void set(const SkCommandLineFlags::StringArray& names) { |
| 610 | fNames = &names; |
| 611 | } |
| 612 | |
| 613 | private: |
| 614 | int fIndex; |
| 615 | const SkCommandLineFlags::StringArray* fNames; |
| 616 | } gNames; |
| 617 | |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 618 | static bool buildTestDir(int dirNo, int firstDirNo, |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 619 | SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sorted) { |
| 620 | SkString dirName = get_out_path(dirNo, outStatusDir); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 621 | if (!dirName.size()) { |
| 622 | return false; |
| 623 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 624 | SkOSFile::Iter iter(dirName.c_str(), "skp"); |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 625 | SkString filename; |
| 626 | while (iter.next(&filename)) { |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 627 | TestResult test; |
| 628 | test.init(dirNo); |
| 629 | SkString spaceFile(filename); |
| 630 | char* spaces = spaceFile.writable_str(); |
| 631 | int spaceSize = (int) spaceFile.size(); |
| 632 | for (int index = 0; index < spaceSize; ++index) { |
| 633 | if (spaces[index] == '.') { |
| 634 | spaces[index] = ' '; |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 635 | } |
| 636 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 637 | int success = sscanf(spaces, "%s %d %d skp", test.fFilename, |
| 638 | &test.fPixelError, &test.fTime); |
| 639 | if (success < 3) { |
| 640 | SkDebugf("failed to scan %s matched=%d\n", filename.c_str(), success); |
| 641 | return false; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 642 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 643 | *tests[dirNo - firstDirNo].append() = test; |
| 644 | } |
| 645 | if (!sorted) { |
| 646 | return true; |
| 647 | } |
| 648 | SkTDArray<TestResult>& testSet = tests[dirNo - firstDirNo]; |
| 649 | int count = testSet.count(); |
| 650 | for (int index = 0; index < count; ++index) { |
| 651 | *sorted[dirNo - firstDirNo].append() = (SortByName*) &testSet[index]; |
| 652 | } |
| 653 | if (sorted[dirNo - firstDirNo].count()) { |
| 654 | SkTQSort<SortByName>(sorted[dirNo - firstDirNo].begin(), |
| 655 | sorted[dirNo - firstDirNo].end() - 1); |
| 656 | if (verbose()) { |
| 657 | SkDebugf("+"); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 658 | } |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 659 | } |
| 660 | return true; |
| 661 | } |
| 662 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 663 | static void testSkpClip(TestState* data) { |
| 664 | data->fResult.testOne(); |
| 665 | SkString statName(data->fResult.fFilename); |
| 666 | SkASSERT(statName.endsWith(".skp")); |
| 667 | statName.remove(statName.size() - 4, 4); |
| 668 | statName.appendf(".%d.%d.skp", data->fResult.fPixelError, data->fResult.fTime); |
| 669 | SkString statusFile = get_out_path(data->fResult.fDirNo, outStatusDir); |
| 670 | if (!statusFile.size()) { |
| 671 | SkDebugf("failed to create %s", statusFile.c_str()); |
| 672 | return; |
| 673 | } |
| 674 | statusFile.appendf("%s%s", PATH_SLASH, statName.c_str()); |
halcanary | d76be9c | 2015-11-20 13:47:49 -0800 | [diff] [blame] | 675 | FILE* file = sk_fopen(statusFile.c_str(), kWrite_SkFILE_Flag); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 676 | if (!file) { |
| 677 | SkDebugf("failed to create %s", statusFile.c_str()); |
| 678 | return; |
| 679 | } |
| 680 | sk_fclose(file); |
| 681 | if (verbose()) { |
| 682 | if (data->fResult.fPixelError || data->fResult.fTime) { |
| 683 | SkDebugf("%s", data->fResult.progress().c_str()); |
| 684 | } else { |
| 685 | SkDebugf("."); |
| 686 | } |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | bool Less(const SortByName& a, const SortByName& b); |
| 691 | bool Less(const SortByName& a, const SortByName& b) { |
| 692 | return a < b; |
| 693 | } |
| 694 | |
| 695 | static bool doOneDir(TestState* state, bool threaded) { |
| 696 | int dirNo = state->fResult.fDirNo; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 697 | SkString dirName = get_in_path(dirNo, nullptr); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 698 | if (!dirName.size()) { |
| 699 | return false; |
| 700 | } |
| 701 | SkTDArray<TestResult> tests[1]; |
| 702 | SkTDArray<SortByName*> sorted[1]; |
| 703 | if (!buildTestDir(dirNo, dirNo, tests, sorted)) { |
| 704 | return false; |
| 705 | } |
| 706 | SkOSFile::Iter iter(dirName.c_str(), "skp"); |
| 707 | SkString filename; |
| 708 | while (iter.next(&filename)) { |
| 709 | for (size_t index = 0; index < skipOverCount; ++index) { |
| 710 | if (skipOver[index].directory == dirNo |
| 711 | && strcmp(filename.c_str(), skipOver[index].filename) == 0) { |
| 712 | goto checkEarlyExit; |
| 713 | } |
| 714 | } |
| 715 | { |
| 716 | SortByName name; |
| 717 | name.init(dirNo); |
| 718 | strncpy(name.fFilename, filename.c_str(), filename.size() - 4); // drop .skp |
| 719 | int count = sorted[0].count(); |
| 720 | int idx = SkTSearch<SortByName, Less>(sorted[0].begin(), count, &name, sizeof(&name)); |
| 721 | if (idx >= 0) { |
| 722 | SortByName* found = sorted[0][idx]; |
| 723 | (void) addError(state, *found); |
| 724 | continue; |
| 725 | } |
| 726 | TestResult test; |
| 727 | test.init(dirNo, filename); |
| 728 | state->fResult = test; |
| 729 | testSkpClip(state); |
| 730 | #if 0 // artificially limit to a few while debugging code |
| 731 | static int debugLimit = 0; |
| 732 | if (++debugLimit == 5) { |
| 733 | return true; |
| 734 | } |
| 735 | #endif |
| 736 | } |
| 737 | checkEarlyExit: |
| 738 | ; |
| 739 | } |
| 740 | return true; |
| 741 | } |
| 742 | |
| 743 | static void initTest() { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 744 | #if !defined SK_BUILD_FOR_WIN && !defined SK_BUILD_FOR_MAC |
| 745 | SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); |
| 746 | SK_CONF_SET("images.png.suppressDecoderWarnings", true); |
| 747 | #endif |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 748 | } |
| 749 | |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 750 | static void testSkpClipEncode(TestState* data) { |
| 751 | data->fResult.testOne(); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 752 | if (verbose()) { |
| 753 | SkDebugf("+"); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 757 | static void encodeFound(TestState& state) { |
| 758 | if (verbose()) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 759 | if (state.fPixelWorst.count()) { |
| 760 | SkTDArray<SortByPixel*> worst; |
| 761 | for (int index = 0; index < state.fPixelWorst.count(); ++index) { |
| 762 | *worst.append() = &state.fPixelWorst[index]; |
| 763 | } |
| 764 | SkTQSort<SortByPixel>(worst.begin(), worst.end() - 1); |
| 765 | for (int index = 0; index < state.fPixelWorst.count(); ++index) { |
| 766 | const TestResult& result = *worst[index]; |
| 767 | SkDebugf("%d %s pixelError=%d\n", result.fDirNo, result.fFilename, result.fPixelError); |
| 768 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 769 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 770 | if (state.fSlowest.count()) { |
| 771 | SkTDArray<SortByTime*> slowest; |
| 772 | for (int index = 0; index < state.fSlowest.count(); ++index) { |
| 773 | *slowest.append() = &state.fSlowest[index]; |
| 774 | } |
| 775 | if (slowest.count() > 0) { |
| 776 | SkTQSort<SortByTime>(slowest.begin(), slowest.end() - 1); |
| 777 | for (int index = 0; index < slowest.count(); ++index) { |
| 778 | const TestResult& result = *slowest[index]; |
| 779 | SkDebugf("%d %s time=%d\n", result.fDirNo, result.fFilename, result.fTime); |
| 780 | } |
| 781 | } |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 782 | } |
| 783 | } |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 784 | TestRunner testRunner; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 785 | for (int index = 0; index < state.fPixelWorst.count(); ++index) { |
| 786 | const TestResult& result = state.fPixelWorst[index]; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 787 | SkString filename(result.fFilename); |
| 788 | if (!filename.endsWith(".skp")) { |
| 789 | filename.append(".skp"); |
| 790 | } |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 791 | *testRunner.fRunnables.append() = new TestRunnableEncode(&testSkpClipEncode, result.fDirNo, |
| 792 | filename.c_str(), &testRunner); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 793 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 794 | testRunner.render(); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 795 | } |
| 796 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 797 | class Test { |
| 798 | public: |
| 799 | Test() {} |
| 800 | virtual ~Test() {} |
| 801 | |
| 802 | const char* getName() { onGetName(&fName); return fName.c_str(); } |
| 803 | void run() { onRun(); } |
| 804 | |
| 805 | protected: |
| 806 | virtual void onGetName(SkString*) = 0; |
| 807 | virtual void onRun() = 0; |
| 808 | |
| 809 | private: |
| 810 | SkString fName; |
| 811 | }; |
| 812 | |
| 813 | typedef SkTRegistry<Test*(*)(void*)> TestRegistry; |
| 814 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 815 | #define DEF_TEST(name) \ |
| 816 | static void test_##name(); \ |
| 817 | class name##Class : public Test { \ |
| 818 | public: \ |
| 819 | static Test* Factory(void*) { return new name##Class; } \ |
| 820 | \ |
| 821 | protected: \ |
| 822 | void onGetName(SkString* name) override { name->set(#name); } \ |
| 823 | void onRun() override { test_##name(); } \ |
| 824 | }; \ |
| 825 | static TestRegistry gReg_##name##Class(name##Class::Factory); \ |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 826 | static void test_##name() |
| 827 | |
| 828 | DEF_TEST(PathOpsSkpClip) { |
| 829 | gDirs.setDefault(); |
| 830 | initTest(); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 831 | SkTArray<TestResult, true> errors; |
| 832 | TestState state; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 833 | state.init(0); |
| 834 | int dirNo; |
| 835 | gDirs.reset(); |
| 836 | while ((dirNo = gDirs.next()) > 0) { |
| 837 | if (verbose()) { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 838 | SkDebugf("dirNo=%d\n", dirNo); |
| 839 | } |
| 840 | state.fResult.fDirNo = dirNo; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 841 | if (!doOneDir(&state, false)) { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 842 | break; |
| 843 | } |
| 844 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 845 | encodeFound(state); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | static void testSkpClipMain(TestState* data) { |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 849 | (void) doOneDir(data, true); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 850 | } |
| 851 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 852 | DEF_TEST(PathOpsSkpClipThreaded) { |
| 853 | gDirs.setDefault(); |
| 854 | initTest(); |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 855 | TestRunner testRunner; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 856 | int dirNo; |
| 857 | gDirs.reset(); |
| 858 | while ((dirNo = gDirs.next()) > 0) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 859 | *testRunner.fRunnables.append() = new TestRunnableDir(&testSkpClipMain, dirNo, &testRunner); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 860 | } |
| 861 | testRunner.render(); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 862 | TestState state; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 863 | state.init(0); |
| 864 | gDirs.reset(); |
| 865 | while ((dirNo = gDirs.next()) > 0) { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 866 | TestState& testState = testRunner.fRunnables[dirNo - 1]->fState; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 867 | SkASSERT(testState.fResult.fDirNo == dirNo); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 868 | for (int inner = 0; inner < testState.fPixelWorst.count(); ++inner) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 869 | addError(&state, testState.fPixelWorst[inner]); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 870 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 871 | for (int inner = 0; inner < testState.fSlowest.count(); ++inner) { |
| 872 | addError(&state, testState.fSlowest[inner]); |
| 873 | } |
| 874 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 875 | encodeFound(state); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 876 | } |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 877 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 878 | static bool buildTests(SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sorted) { |
| 879 | int firstDirNo = gDirs.first(); |
| 880 | int dirNo; |
| 881 | while ((dirNo = gDirs.next()) > 0) { |
| 882 | if (!buildTestDir(dirNo, firstDirNo, tests, sorted)) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 883 | return false; |
| 884 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 885 | } |
| 886 | return true; |
| 887 | } |
| 888 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 889 | DEF_TEST(PathOpsSkpClipUberThreaded) { |
| 890 | gDirs.setDefault(); |
| 891 | const int firstDirNo = gDirs.next(); |
| 892 | const int lastDirNo = gDirs.last(); |
| 893 | initTest(); |
| 894 | int dirCount = lastDirNo - firstDirNo + 1; |
| 895 | SkAutoTDeleteArray<SkTDArray<TestResult> > tests(new SkTDArray<TestResult>[dirCount]); |
| 896 | SkAutoTDeleteArray<SkTDArray<SortByName*> > sorted(new SkTDArray<SortByName*>[dirCount]); |
| 897 | if (!buildTests(tests.get(), sorted.get())) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 898 | return; |
| 899 | } |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 900 | TestRunner testRunner; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 901 | int dirNo; |
| 902 | gDirs.reset(); |
| 903 | while ((dirNo = gDirs.next()) > 0) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 904 | SkString dirName = get_in_path(dirNo, nullptr); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 905 | if (!dirName.size()) { |
| 906 | continue; |
| 907 | } |
| 908 | SkOSFile::Iter iter(dirName.c_str(), "skp"); |
| 909 | SkString filename; |
| 910 | while (iter.next(&filename)) { |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 911 | for (size_t index = 0; index < skipOverCount; ++index) { |
| 912 | if (skipOver[index].directory == dirNo |
| 913 | && strcmp(filename.c_str(), skipOver[index].filename) == 0) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 914 | goto checkEarlyExit; |
| 915 | } |
| 916 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 917 | { |
| 918 | SortByName name; |
| 919 | name.init(dirNo); |
| 920 | strncpy(name.fFilename, filename.c_str(), filename.size() - 4); // drop .skp |
| 921 | int count = sorted.get()[dirNo - firstDirNo].count(); |
| 922 | if (SkTSearch<SortByName, Less>(sorted.get()[dirNo - firstDirNo].begin(), |
| 923 | count, &name, sizeof(&name)) < 0) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 924 | *testRunner.fRunnables.append() = new TestRunnableFile( |
| 925 | &testSkpClip, dirNo, filename.c_str(), &testRunner); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 926 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 927 | } |
| 928 | checkEarlyExit: |
| 929 | ; |
| 930 | } |
| 931 | |
| 932 | } |
| 933 | testRunner.render(); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 934 | SkAutoTDeleteArray<SkTDArray<TestResult> > results(new SkTDArray<TestResult>[dirCount]); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 935 | if (!buildTests(results.get(), nullptr)) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 936 | return; |
| 937 | } |
| 938 | SkTDArray<TestResult> allResults; |
| 939 | for (int dirNo = firstDirNo; dirNo <= lastDirNo; ++dirNo) { |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 940 | SkTDArray<TestResult>& array = results.get()[dirNo - firstDirNo]; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 941 | allResults.append(array.count(), array.begin()); |
| 942 | } |
| 943 | int allCount = allResults.count(); |
| 944 | SkTDArray<SortByPixel*> pixels; |
| 945 | SkTDArray<SortByTime*> times; |
| 946 | for (int index = 0; index < allCount; ++index) { |
| 947 | *pixels.append() = (SortByPixel*) &allResults[index]; |
| 948 | *times.append() = (SortByTime*) &allResults[index]; |
| 949 | } |
| 950 | TestState state; |
| 951 | if (pixels.count()) { |
| 952 | SkTQSort<SortByPixel>(pixels.begin(), pixels.end() - 1); |
| 953 | for (int inner = 0; inner < kMaxFiles; ++inner) { |
| 954 | *state.fPixelWorst.append() = *pixels[allCount - inner - 1]; |
| 955 | } |
| 956 | } |
| 957 | if (times.count()) { |
| 958 | SkTQSort<SortByTime>(times.begin(), times.end() - 1); |
| 959 | for (int inner = 0; inner < kMaxFiles; ++inner) { |
| 960 | *state.fSlowest.append() = *times[allCount - inner - 1]; |
| 961 | } |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 962 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 963 | encodeFound(state); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 964 | } |
| 965 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 966 | DEF_TEST(PathOpsSkpClipOneOff) { |
| 967 | const int testIndex = FLAGS_testIndex; |
| 968 | int dirNo = gDirs.next(); |
| 969 | if (dirNo < 0) { |
| 970 | dirNo = skipOver[testIndex].directory; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 971 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 972 | const char* skp = gNames.next(); |
| 973 | if (!skp) { |
| 974 | skp = skipOver[testIndex].filename; |
| 975 | } |
| 976 | initTest(); |
| 977 | SkAssertResult(get_in_path(dirNo, skp).size()); |
| 978 | SkString filename(skp); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 979 | TestResult state; |
| 980 | state.test(dirNo, filename); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 981 | if (verbose()) { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 982 | SkDebugf("%s", state.status().c_str()); |
| 983 | } |
| 984 | state.fTestStep = kEncodeFiles; |
| 985 | state.testOne(); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 986 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 987 | |
| 988 | DEF_TEST(PathOpsTestSkipped) { |
| 989 | for (size_t index = 0; index < skipOverCount; ++index) { |
| 990 | const SkipOverTest& skip = skipOver[index]; |
| 991 | if (!skip.blamePathOps) { |
| 992 | continue; |
| 993 | } |
| 994 | int dirNo = skip.directory; |
| 995 | const char* skp = skip.filename; |
| 996 | initTest(); |
| 997 | SkAssertResult(get_in_path(dirNo, skp).size()); |
| 998 | SkString filename(skp); |
| 999 | TestResult state; |
| 1000 | state.test(dirNo, filename); |
| 1001 | if (verbose()) { |
| 1002 | SkDebugf("%s", state.status().c_str()); |
| 1003 | } |
| 1004 | state.fTestStep = kEncodeFiles; |
| 1005 | state.testOne(); |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | DEF_TEST(PathOpsCopyFails) { |
| 1010 | FLAGS_verbose = true; |
| 1011 | for (size_t index = 0; index < skipOverCount; ++index) { |
| 1012 | int dirNo = skipOver[index].directory; |
| 1013 | SkDebugf("mkdir -p " IN_DIR_PRE "%d" DIR_POST "\n", dirNo); |
| 1014 | } |
| 1015 | for (size_t index = 0; index < skipOverCount; ++index) { |
| 1016 | int dirNo = skipOver[index].directory; |
| 1017 | const char* filename = skipOver[index].filename; |
| 1018 | SkDebugf("rsync -av cary-linux.cnc:/tera" PATH_SLASH "skps" PATH_SLASH "slave" |
| 1019 | "%d" DIR_POST "/%s " IN_DIR_PRE "%d" DIR_POST "\n", dirNo, filename, dirNo); |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | template TestRegistry* TestRegistry::gHead; |
| 1024 | |
| 1025 | class Iter { |
| 1026 | public: |
| 1027 | Iter() { this->reset(); } |
| 1028 | void reset() { fReg = TestRegistry::Head(); } |
| 1029 | |
| 1030 | Test* next() { |
| 1031 | if (fReg) { |
| 1032 | TestRegistry::Factory fact = fReg->factory(); |
| 1033 | fReg = fReg->next(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1034 | Test* test = fact(nullptr); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1035 | return test; |
| 1036 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1037 | return nullptr; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | private: |
| 1041 | const TestRegistry* fReg; |
| 1042 | }; |
| 1043 | |
| 1044 | int tool_main(int argc, char** argv); |
| 1045 | int tool_main(int argc, char** argv) { |
| 1046 | SetupCrashHandler(); |
| 1047 | SkCommandLineFlags::SetUsage(""); |
| 1048 | SkCommandLineFlags::Parse(argc, argv); |
| 1049 | SkGraphics::Init(); |
| 1050 | SkString header("PathOps SkpClip:"); |
| 1051 | if (!FLAGS_match.isEmpty()) { |
| 1052 | header.appendf(" --match"); |
| 1053 | for (int index = 0; index < FLAGS_match.count(); ++index) { |
| 1054 | header.appendf(" %s", FLAGS_match[index]); |
| 1055 | } |
| 1056 | } |
| 1057 | if (!FLAGS_dir.isEmpty()) { |
| 1058 | int count = FLAGS_dir.count(); |
| 1059 | for (int i = 0; i < count; ++i) { |
| 1060 | const char* range = FLAGS_dir[i]; |
| 1061 | const char* dash = strchr(range, '-'); |
| 1062 | if (!dash) { |
| 1063 | dash = strchr(range, ','); |
| 1064 | } |
| 1065 | int first = atoi(range); |
| 1066 | int last = dash ? atoi(dash + 1) : first; |
| 1067 | if (!first || !last) { |
| 1068 | SkDebugf("couldn't parse --dir %s\n", range); |
| 1069 | return 1; |
| 1070 | } |
| 1071 | gDirs.set(first, last); |
| 1072 | } |
| 1073 | } |
| 1074 | if (!FLAGS_skp.isEmpty()) { |
| 1075 | gNames.set(FLAGS_skp); |
| 1076 | } |
| 1077 | #ifdef SK_DEBUG |
| 1078 | header.append(" SK_DEBUG"); |
| 1079 | #else |
| 1080 | header.append(" SK_RELEASE"); |
| 1081 | #endif |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1082 | if (FLAGS_verbose) { |
| 1083 | header.appendf("\n"); |
| 1084 | } |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 1085 | SkDebugf("%s", header.c_str()); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1086 | Iter iter; |
| 1087 | Test* test; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1088 | while ((test = iter.next()) != nullptr) { |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1089 | SkAutoTDelete<Test> owned(test); |
| 1090 | if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) { |
| 1091 | test->run(); |
| 1092 | } |
| 1093 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1094 | return 0; |
| 1095 | } |
| 1096 | |
borenet | 4808757 | 2015-04-02 12:16:36 -0700 | [diff] [blame] | 1097 | #if !defined(SK_BUILD_FOR_IOS) |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1098 | int main(int argc, char * const argv[]) { |
| 1099 | return tool_main(argc, (char**) argv); |
| 1100 | } |
| 1101 | #endif |