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" |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 22 | #include "SkTSort.h" |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 23 | #include "SkStream.h" |
skia.committer@gmail.com | 2b34fe0 | 2013-05-08 07:01:40 +0000 | [diff] [blame] | 24 | #include "SkString.h" |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 25 | #include "SkTArray.h" |
| 26 | #include "SkTDArray.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 27 | #include "SkTaskGroup.h" |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 28 | #include "SkTemplates.h" |
halcanary | 4e44efe | 2016-08-04 10:47:16 -0700 | [diff] [blame] | 29 | #include "SkTSearch.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 | |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 743 | static void testSkpClipEncode(TestState* data) { |
| 744 | data->fResult.testOne(); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 745 | if (verbose()) { |
| 746 | SkDebugf("+"); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 750 | static void encodeFound(TestState& state) { |
| 751 | if (verbose()) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 752 | if (state.fPixelWorst.count()) { |
| 753 | SkTDArray<SortByPixel*> worst; |
| 754 | for (int index = 0; index < state.fPixelWorst.count(); ++index) { |
| 755 | *worst.append() = &state.fPixelWorst[index]; |
| 756 | } |
| 757 | SkTQSort<SortByPixel>(worst.begin(), worst.end() - 1); |
| 758 | for (int index = 0; index < state.fPixelWorst.count(); ++index) { |
| 759 | const TestResult& result = *worst[index]; |
| 760 | SkDebugf("%d %s pixelError=%d\n", result.fDirNo, result.fFilename, result.fPixelError); |
| 761 | } |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 762 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 763 | if (state.fSlowest.count()) { |
| 764 | SkTDArray<SortByTime*> slowest; |
| 765 | for (int index = 0; index < state.fSlowest.count(); ++index) { |
| 766 | *slowest.append() = &state.fSlowest[index]; |
| 767 | } |
| 768 | if (slowest.count() > 0) { |
| 769 | SkTQSort<SortByTime>(slowest.begin(), slowest.end() - 1); |
| 770 | for (int index = 0; index < slowest.count(); ++index) { |
| 771 | const TestResult& result = *slowest[index]; |
| 772 | SkDebugf("%d %s time=%d\n", result.fDirNo, result.fFilename, result.fTime); |
| 773 | } |
| 774 | } |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 775 | } |
| 776 | } |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 777 | TestRunner testRunner; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 778 | for (int index = 0; index < state.fPixelWorst.count(); ++index) { |
| 779 | const TestResult& result = state.fPixelWorst[index]; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 780 | SkString filename(result.fFilename); |
| 781 | if (!filename.endsWith(".skp")) { |
| 782 | filename.append(".skp"); |
| 783 | } |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 784 | *testRunner.fRunnables.append() = new TestRunnableEncode(&testSkpClipEncode, result.fDirNo, |
| 785 | filename.c_str(), &testRunner); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 786 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 787 | testRunner.render(); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 788 | } |
| 789 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 790 | class Test { |
| 791 | public: |
| 792 | Test() {} |
| 793 | virtual ~Test() {} |
| 794 | |
| 795 | const char* getName() { onGetName(&fName); return fName.c_str(); } |
| 796 | void run() { onRun(); } |
| 797 | |
| 798 | protected: |
| 799 | virtual void onGetName(SkString*) = 0; |
| 800 | virtual void onRun() = 0; |
| 801 | |
| 802 | private: |
| 803 | SkString fName; |
| 804 | }; |
| 805 | |
| 806 | typedef SkTRegistry<Test*(*)(void*)> TestRegistry; |
| 807 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 808 | #define DEF_TEST(name) \ |
| 809 | static void test_##name(); \ |
| 810 | class name##Class : public Test { \ |
| 811 | public: \ |
| 812 | static Test* Factory(void*) { return new name##Class; } \ |
| 813 | \ |
| 814 | protected: \ |
| 815 | void onGetName(SkString* name) override { name->set(#name); } \ |
| 816 | void onRun() override { test_##name(); } \ |
| 817 | }; \ |
| 818 | static TestRegistry gReg_##name##Class(name##Class::Factory); \ |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 819 | static void test_##name() |
| 820 | |
| 821 | DEF_TEST(PathOpsSkpClip) { |
| 822 | gDirs.setDefault(); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 823 | SkTArray<TestResult, true> errors; |
| 824 | TestState state; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 825 | state.init(0); |
| 826 | int dirNo; |
| 827 | gDirs.reset(); |
| 828 | while ((dirNo = gDirs.next()) > 0) { |
| 829 | if (verbose()) { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 830 | SkDebugf("dirNo=%d\n", dirNo); |
| 831 | } |
| 832 | state.fResult.fDirNo = dirNo; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 833 | if (!doOneDir(&state, false)) { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 834 | break; |
| 835 | } |
| 836 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 837 | encodeFound(state); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | static void testSkpClipMain(TestState* data) { |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 841 | (void) doOneDir(data, true); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 842 | } |
| 843 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 844 | DEF_TEST(PathOpsSkpClipThreaded) { |
| 845 | gDirs.setDefault(); |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 846 | TestRunner testRunner; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 847 | int dirNo; |
| 848 | gDirs.reset(); |
| 849 | while ((dirNo = gDirs.next()) > 0) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 850 | *testRunner.fRunnables.append() = new TestRunnableDir(&testSkpClipMain, dirNo, &testRunner); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 851 | } |
| 852 | testRunner.render(); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 853 | TestState state; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 854 | state.init(0); |
| 855 | gDirs.reset(); |
| 856 | while ((dirNo = gDirs.next()) > 0) { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 857 | TestState& testState = testRunner.fRunnables[dirNo - 1]->fState; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 858 | SkASSERT(testState.fResult.fDirNo == dirNo); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 859 | for (int inner = 0; inner < testState.fPixelWorst.count(); ++inner) { |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 860 | addError(&state, testState.fPixelWorst[inner]); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 861 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 862 | for (int inner = 0; inner < testState.fSlowest.count(); ++inner) { |
| 863 | addError(&state, testState.fSlowest[inner]); |
| 864 | } |
| 865 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 866 | encodeFound(state); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 867 | } |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 868 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 869 | static bool buildTests(SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sorted) { |
| 870 | int firstDirNo = gDirs.first(); |
| 871 | int dirNo; |
| 872 | while ((dirNo = gDirs.next()) > 0) { |
| 873 | if (!buildTestDir(dirNo, firstDirNo, tests, sorted)) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 874 | return false; |
| 875 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 876 | } |
| 877 | return true; |
| 878 | } |
| 879 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 880 | DEF_TEST(PathOpsSkpClipUberThreaded) { |
| 881 | gDirs.setDefault(); |
| 882 | const int firstDirNo = gDirs.next(); |
| 883 | const int lastDirNo = gDirs.last(); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 884 | int dirCount = lastDirNo - firstDirNo + 1; |
| 885 | SkAutoTDeleteArray<SkTDArray<TestResult> > tests(new SkTDArray<TestResult>[dirCount]); |
| 886 | SkAutoTDeleteArray<SkTDArray<SortByName*> > sorted(new SkTDArray<SortByName*>[dirCount]); |
| 887 | if (!buildTests(tests.get(), sorted.get())) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 888 | return; |
| 889 | } |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 890 | TestRunner testRunner; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 891 | int dirNo; |
| 892 | gDirs.reset(); |
| 893 | while ((dirNo = gDirs.next()) > 0) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 894 | SkString dirName = get_in_path(dirNo, nullptr); |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 895 | if (!dirName.size()) { |
| 896 | continue; |
| 897 | } |
| 898 | SkOSFile::Iter iter(dirName.c_str(), "skp"); |
| 899 | SkString filename; |
| 900 | while (iter.next(&filename)) { |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 901 | for (size_t index = 0; index < skipOverCount; ++index) { |
| 902 | if (skipOver[index].directory == dirNo |
| 903 | && strcmp(filename.c_str(), skipOver[index].filename) == 0) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 904 | goto checkEarlyExit; |
| 905 | } |
| 906 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 907 | { |
| 908 | SortByName name; |
| 909 | name.init(dirNo); |
| 910 | strncpy(name.fFilename, filename.c_str(), filename.size() - 4); // drop .skp |
| 911 | int count = sorted.get()[dirNo - firstDirNo].count(); |
| 912 | if (SkTSearch<SortByName, Less>(sorted.get()[dirNo - firstDirNo].begin(), |
| 913 | count, &name, sizeof(&name)) < 0) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 914 | *testRunner.fRunnables.append() = new TestRunnableFile( |
| 915 | &testSkpClip, dirNo, filename.c_str(), &testRunner); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 916 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 917 | } |
| 918 | checkEarlyExit: |
| 919 | ; |
| 920 | } |
| 921 | |
| 922 | } |
| 923 | testRunner.render(); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 924 | SkAutoTDeleteArray<SkTDArray<TestResult> > results(new SkTDArray<TestResult>[dirCount]); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 925 | if (!buildTests(results.get(), nullptr)) { |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 926 | return; |
| 927 | } |
| 928 | SkTDArray<TestResult> allResults; |
| 929 | for (int dirNo = firstDirNo; dirNo <= lastDirNo; ++dirNo) { |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 930 | SkTDArray<TestResult>& array = results.get()[dirNo - firstDirNo]; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 931 | allResults.append(array.count(), array.begin()); |
| 932 | } |
| 933 | int allCount = allResults.count(); |
| 934 | SkTDArray<SortByPixel*> pixels; |
| 935 | SkTDArray<SortByTime*> times; |
| 936 | for (int index = 0; index < allCount; ++index) { |
| 937 | *pixels.append() = (SortByPixel*) &allResults[index]; |
| 938 | *times.append() = (SortByTime*) &allResults[index]; |
| 939 | } |
| 940 | TestState state; |
| 941 | if (pixels.count()) { |
| 942 | SkTQSort<SortByPixel>(pixels.begin(), pixels.end() - 1); |
| 943 | for (int inner = 0; inner < kMaxFiles; ++inner) { |
| 944 | *state.fPixelWorst.append() = *pixels[allCount - inner - 1]; |
| 945 | } |
| 946 | } |
| 947 | if (times.count()) { |
| 948 | SkTQSort<SortByTime>(times.begin(), times.end() - 1); |
| 949 | for (int inner = 0; inner < kMaxFiles; ++inner) { |
| 950 | *state.fSlowest.append() = *times[allCount - inner - 1]; |
| 951 | } |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 952 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 953 | encodeFound(state); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 954 | } |
| 955 | |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 956 | DEF_TEST(PathOpsSkpClipOneOff) { |
| 957 | const int testIndex = FLAGS_testIndex; |
| 958 | int dirNo = gDirs.next(); |
| 959 | if (dirNo < 0) { |
| 960 | dirNo = skipOver[testIndex].directory; |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 961 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 962 | const char* skp = gNames.next(); |
| 963 | if (!skp) { |
| 964 | skp = skipOver[testIndex].filename; |
| 965 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 966 | SkAssertResult(get_in_path(dirNo, skp).size()); |
| 967 | SkString filename(skp); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 968 | TestResult state; |
| 969 | state.test(dirNo, filename); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 970 | if (verbose()) { |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 971 | SkDebugf("%s", state.status().c_str()); |
| 972 | } |
| 973 | state.fTestStep = kEncodeFiles; |
| 974 | state.testOne(); |
caryclark@google.com | 07e97fc | 2013-07-08 17:17:02 +0000 | [diff] [blame] | 975 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 976 | |
| 977 | DEF_TEST(PathOpsTestSkipped) { |
| 978 | for (size_t index = 0; index < skipOverCount; ++index) { |
| 979 | const SkipOverTest& skip = skipOver[index]; |
| 980 | if (!skip.blamePathOps) { |
| 981 | continue; |
| 982 | } |
| 983 | int dirNo = skip.directory; |
| 984 | const char* skp = skip.filename; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 985 | SkAssertResult(get_in_path(dirNo, skp).size()); |
| 986 | SkString filename(skp); |
| 987 | TestResult state; |
| 988 | state.test(dirNo, filename); |
| 989 | if (verbose()) { |
| 990 | SkDebugf("%s", state.status().c_str()); |
| 991 | } |
| 992 | state.fTestStep = kEncodeFiles; |
| 993 | state.testOne(); |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | DEF_TEST(PathOpsCopyFails) { |
| 998 | FLAGS_verbose = true; |
| 999 | for (size_t index = 0; index < skipOverCount; ++index) { |
| 1000 | int dirNo = skipOver[index].directory; |
| 1001 | SkDebugf("mkdir -p " IN_DIR_PRE "%d" DIR_POST "\n", dirNo); |
| 1002 | } |
| 1003 | for (size_t index = 0; index < skipOverCount; ++index) { |
| 1004 | int dirNo = skipOver[index].directory; |
| 1005 | const char* filename = skipOver[index].filename; |
| 1006 | SkDebugf("rsync -av cary-linux.cnc:/tera" PATH_SLASH "skps" PATH_SLASH "slave" |
| 1007 | "%d" DIR_POST "/%s " IN_DIR_PRE "%d" DIR_POST "\n", dirNo, filename, dirNo); |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | template TestRegistry* TestRegistry::gHead; |
| 1012 | |
| 1013 | class Iter { |
| 1014 | public: |
| 1015 | Iter() { this->reset(); } |
| 1016 | void reset() { fReg = TestRegistry::Head(); } |
| 1017 | |
| 1018 | Test* next() { |
| 1019 | if (fReg) { |
| 1020 | TestRegistry::Factory fact = fReg->factory(); |
| 1021 | fReg = fReg->next(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1022 | Test* test = fact(nullptr); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1023 | return test; |
| 1024 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1025 | return nullptr; |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | private: |
| 1029 | const TestRegistry* fReg; |
| 1030 | }; |
| 1031 | |
| 1032 | int tool_main(int argc, char** argv); |
| 1033 | int tool_main(int argc, char** argv) { |
| 1034 | SetupCrashHandler(); |
| 1035 | SkCommandLineFlags::SetUsage(""); |
| 1036 | SkCommandLineFlags::Parse(argc, argv); |
| 1037 | SkGraphics::Init(); |
| 1038 | SkString header("PathOps SkpClip:"); |
| 1039 | if (!FLAGS_match.isEmpty()) { |
| 1040 | header.appendf(" --match"); |
| 1041 | for (int index = 0; index < FLAGS_match.count(); ++index) { |
| 1042 | header.appendf(" %s", FLAGS_match[index]); |
| 1043 | } |
| 1044 | } |
| 1045 | if (!FLAGS_dir.isEmpty()) { |
| 1046 | int count = FLAGS_dir.count(); |
| 1047 | for (int i = 0; i < count; ++i) { |
| 1048 | const char* range = FLAGS_dir[i]; |
| 1049 | const char* dash = strchr(range, '-'); |
| 1050 | if (!dash) { |
| 1051 | dash = strchr(range, ','); |
| 1052 | } |
| 1053 | int first = atoi(range); |
| 1054 | int last = dash ? atoi(dash + 1) : first; |
| 1055 | if (!first || !last) { |
| 1056 | SkDebugf("couldn't parse --dir %s\n", range); |
| 1057 | return 1; |
| 1058 | } |
| 1059 | gDirs.set(first, last); |
| 1060 | } |
| 1061 | } |
| 1062 | if (!FLAGS_skp.isEmpty()) { |
| 1063 | gNames.set(FLAGS_skp); |
| 1064 | } |
| 1065 | #ifdef SK_DEBUG |
| 1066 | header.append(" SK_DEBUG"); |
| 1067 | #else |
| 1068 | header.append(" SK_RELEASE"); |
| 1069 | #endif |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1070 | if (FLAGS_verbose) { |
| 1071 | header.appendf("\n"); |
| 1072 | } |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 1073 | SkDebugf("%s", header.c_str()); |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1074 | Iter iter; |
| 1075 | Test* test; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1076 | while ((test = iter.next()) != nullptr) { |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1077 | SkAutoTDelete<Test> owned(test); |
| 1078 | if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) { |
| 1079 | test->run(); |
| 1080 | } |
| 1081 | } |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1082 | return 0; |
| 1083 | } |
| 1084 | |
borenet | 4808757 | 2015-04-02 12:16:36 -0700 | [diff] [blame] | 1085 | #if !defined(SK_BUILD_FOR_IOS) |
caryclark | 19eb3b2 | 2014-07-18 05:08:14 -0700 | [diff] [blame] | 1086 | int main(int argc, char * const argv[]) { |
| 1087 | return tool_main(argc, (char**) argv); |
| 1088 | } |
| 1089 | #endif |