epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
commit-bot@chromium.org | ba59d64 | 2013-04-11 16:54:09 +0000 | [diff] [blame] | 7 | |
mtklein | 30e6e2a | 2014-06-18 11:44:15 -0700 | [diff] [blame] | 8 | #include "CrashHandler.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 9 | #include "OverwriteLine.h" |
Cary Clark | f394912 | 2018-08-07 16:38:21 -0400 | [diff] [blame] | 10 | #include "PathOpsDebug.h" |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 11 | #include "Resources.h" |
herb | 62a69c2 | 2015-09-29 11:47:45 -0700 | [diff] [blame] | 12 | #include "SkAtomics.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 13 | #include "SkCommonFlags.h" |
reed@android.com | 5e5adfd | 2009-03-07 03:39:23 +0000 | [diff] [blame] | 14 | #include "SkGraphics.h" |
commit-bot@chromium.org | 0506b9d | 2013-04-22 16:43:07 +0000 | [diff] [blame] | 15 | #include "SkOSFile.h" |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 16 | #include "SkPathOpsDebug.h" |
commit-bot@chromium.org | 197845a | 2013-04-19 13:24:28 +0000 | [diff] [blame] | 17 | #include "SkTArray.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 18 | #include "SkTaskGroup.h" |
commit-bot@chromium.org | 197845a | 2013-04-19 13:24:28 +0000 | [diff] [blame] | 19 | #include "SkTemplates.h" |
commit-bot@chromium.org | 0506b9d | 2013-04-22 16:43:07 +0000 | [diff] [blame] | 20 | #include "SkTime.h" |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 21 | #include "Test.h" |
| 22 | |
robertphillips@google.com | bdb1be5 | 2012-09-07 18:24:43 +0000 | [diff] [blame] | 23 | #include "GrContext.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 24 | #include "GrContextFactory.h" |
robertphillips@google.com | bdb1be5 | 2012-09-07 18:24:43 +0000 | [diff] [blame] | 25 | |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 26 | using namespace skiatest; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 27 | using namespace sk_gpu_test; |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 28 | |
caryclark | 1326068 | 2016-10-24 05:10:14 -0700 | [diff] [blame] | 29 | DEFINE_bool2(dumpOp, d, false, "dump the pathOps to a file to recover mid-crash."); |
commit-bot@chromium.org | ba59d64 | 2013-04-11 16:54:09 +0000 | [diff] [blame] | 30 | DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps."); |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 31 | DEFINE_bool2(runFail, f, false, "check for success on tests known to fail."); |
caryclark | 1326068 | 2016-10-24 05:10:14 -0700 | [diff] [blame] | 32 | DEFINE_bool2(verifyOp, y, false, "compare the pathOps result against a region."); |
Cary Clark | f394912 | 2018-08-07 16:38:21 -0400 | [diff] [blame] | 33 | DEFINE_string2(json, J, "", "write json version of tests."); |
caryclark | 1326068 | 2016-10-24 05:10:14 -0700 | [diff] [blame] | 34 | |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 35 | #if DEBUG_COIN |
| 36 | DEFINE_bool2(coinTest, c, false, "detect unused coincidence algorithms."); |
| 37 | #endif |
commit-bot@chromium.org | 197845a | 2013-04-19 13:24:28 +0000 | [diff] [blame] | 38 | |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 39 | // need to explicitly declare this, or we get some weird infinite loop llist |
| 40 | template TestRegistry* TestRegistry::gHead; |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 41 | void (*gVerboseFinalize)() = nullptr; |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 42 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 43 | // The threads report back to this object when they are done. |
| 44 | class Status { |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 45 | public: |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 46 | explicit Status(int total) |
| 47 | : fDone(0), fTestCount(0), fFailCount(0), fTotal(total) {} |
| 48 | // Threadsafe. |
| 49 | void endTest(const char* testName, |
| 50 | bool success, |
| 51 | SkMSec elapsed, |
| 52 | int testCount) { |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 53 | const int done = 1 + sk_atomic_inc(&fDone); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 54 | for (int i = 0; i < testCount; ++i) { |
| 55 | sk_atomic_inc(&fTestCount); |
| 56 | } |
| 57 | if (!success) { |
| 58 | SkDebugf("\n---- %s FAILED", testName); |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | SkString prefix(kSkOverwriteLine); |
| 62 | SkString time; |
| 63 | if (FLAGS_verbose) { |
| 64 | prefix.printf("\n"); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 65 | time.printf("%5dms ", elapsed); |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 66 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 67 | SkDebugf("%s[%3d/%3d] %s%s", prefix.c_str(), done, fTotal, time.c_str(), |
| 68 | testName); |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 69 | } |
| 70 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 71 | void reportFailure() { sk_atomic_inc(&fFailCount); } |
| 72 | |
| 73 | int32_t testCount() { return fTestCount; } |
| 74 | int32_t failCount() { return fFailCount; } |
| 75 | |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 76 | private: |
| 77 | int32_t fDone; // atomic |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 78 | int32_t fTestCount; // atomic |
| 79 | int32_t fFailCount; // atomic |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 80 | const int fTotal; |
| 81 | }; |
| 82 | |
mtklein | 048494c | 2016-02-16 19:06:15 -0800 | [diff] [blame] | 83 | class SkTestRunnable { |
commit-bot@chromium.org | 197845a | 2013-04-19 13:24:28 +0000 | [diff] [blame] | 84 | public: |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 85 | SkTestRunnable(const Test& test, Status* status) : fTest(test), fStatus(status) {} |
commit-bot@chromium.org | 197845a | 2013-04-19 13:24:28 +0000 | [diff] [blame] | 86 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 87 | void operator()() { |
| 88 | struct TestReporter : public skiatest::Reporter { |
| 89 | public: |
| 90 | TestReporter() : fStats(nullptr), fError(false), fTestCount(0) {} |
| 91 | void bumpTestCount() override { ++fTestCount; } |
| 92 | bool allowExtendedTest() const override { return FLAGS_extendedTest; } |
| 93 | bool verbose() const override { return FLAGS_veryVerbose; } |
| 94 | void reportFailed(const skiatest::Failure& failure) override { |
| 95 | SkDebugf("\nFAILED: %s", failure.toString().c_str()); |
| 96 | fError = true; |
| 97 | } |
| 98 | void* stats() const override { return fStats; } |
| 99 | void* fStats; |
| 100 | bool fError; |
| 101 | int fTestCount; |
| 102 | } reporter; |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 103 | |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 104 | const Timer timer; |
| 105 | fTest.proc(&reporter, GrContextOptions()); |
| 106 | SkMSec elapsed = timer.elapsedMsInt(); |
| 107 | if (reporter.fError) { |
| 108 | fStatus->reportFailure(); |
| 109 | } |
| 110 | fStatus->endTest(fTest.name, !reporter.fError, elapsed, reporter.fTestCount); |
commit-bot@chromium.org | 197845a | 2013-04-19 13:24:28 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | private: |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 114 | Test fTest; |
| 115 | Status* fStatus; |
commit-bot@chromium.org | 197845a | 2013-04-19 13:24:28 +0000 | [diff] [blame] | 116 | }; |
commit-bot@chromium.org | ba59d64 | 2013-04-11 16:54:09 +0000 | [diff] [blame] | 117 | |
commit-bot@chromium.org | 5a47b09 | 2014-01-30 15:30:50 +0000 | [diff] [blame] | 118 | static bool should_run(const char* testName, bool isGPUTest) { |
| 119 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, testName)) { |
| 120 | return false; |
| 121 | } |
| 122 | if (!FLAGS_cpu && !isGPUTest) { |
| 123 | return false; |
| 124 | } |
| 125 | if (!FLAGS_gpu && isGPUTest) { |
| 126 | return false; |
| 127 | } |
| 128 | return true; |
| 129 | } |
| 130 | |
Mike Klein | be28ee2 | 2017-02-06 12:46:20 -0500 | [diff] [blame] | 131 | int main(int argc, char** argv) { |
| 132 | SkCommandLineFlags::Parse(argc, argv); |
Cary Clark | 918fb1f | 2016-11-15 13:22:25 -0500 | [diff] [blame] | 133 | #if DEBUG_DUMP_VERIFY |
caryclark | 1326068 | 2016-10-24 05:10:14 -0700 | [diff] [blame] | 134 | SkPathOpsDebug::gDumpOp = FLAGS_dumpOp; |
| 135 | SkPathOpsDebug::gVerifyOp = FLAGS_verifyOp; |
| 136 | #endif |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 137 | SkPathOpsDebug::gRunFail = FLAGS_runFail; |
caryclark | 1326068 | 2016-10-24 05:10:14 -0700 | [diff] [blame] | 138 | SkPathOpsDebug::gVeryVerbose = FLAGS_veryVerbose; |
Cary Clark | f394912 | 2018-08-07 16:38:21 -0400 | [diff] [blame] | 139 | PathOpsDebug::gOutFirst = true; |
Cary Clark | 4533f3d | 2018-08-08 09:48:09 -0400 | [diff] [blame] | 140 | PathOpsDebug::gCheckForDuplicateNames = false; |
Cary Clark | 9c9611f | 2018-08-08 13:17:25 -0400 | [diff] [blame] | 141 | PathOpsDebug::gOutputSVG = false; |
Cary Clark | f394912 | 2018-08-07 16:38:21 -0400 | [diff] [blame] | 142 | if ((PathOpsDebug::gJson = !FLAGS_json.isEmpty())) { |
| 143 | PathOpsDebug::gOut = fopen(FLAGS_json[0], "wb"); |
| 144 | fprintf(PathOpsDebug::gOut, "{\n"); |
| 145 | FLAGS_threads = 0; |
Cary Clark | da6289c | 2018-08-27 16:10:28 -0400 | [diff] [blame] | 146 | PathOpsDebug::gMarkJsonFlaky = false; |
Cary Clark | f394912 | 2018-08-07 16:38:21 -0400 | [diff] [blame] | 147 | } |
mtklein | 30e6e2a | 2014-06-18 11:44:15 -0700 | [diff] [blame] | 148 | SetupCrashHandler(); |
commit-bot@chromium.org | ba59d64 | 2013-04-11 16:54:09 +0000 | [diff] [blame] | 149 | |
tfarina | a71d3af | 2014-11-07 06:12:30 -0800 | [diff] [blame] | 150 | SkAutoGraphics ag; |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 151 | |
reed@google.com | 91d449e | 2011-10-26 15:25:18 +0000 | [diff] [blame] | 152 | { |
| 153 | SkString header("Skia UnitTests:"); |
reed@google.com | 9aff148 | 2013-04-11 18:27:52 +0000 | [diff] [blame] | 154 | if (!FLAGS_match.isEmpty()) { |
caryclark@google.com | b631eec | 2013-05-02 13:14:40 +0000 | [diff] [blame] | 155 | header.appendf(" --match"); |
| 156 | for (int index = 0; index < FLAGS_match.count(); ++index) { |
| 157 | header.appendf(" %s", FLAGS_match[index]); |
| 158 | } |
reed@google.com | 91d449e | 2011-10-26 15:25:18 +0000 | [diff] [blame] | 159 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 160 | SkString tmpDir = skiatest::GetTmpDir(); |
scroggo@google.com | c76218d | 2013-06-06 14:59:56 +0000 | [diff] [blame] | 161 | if (!tmpDir.isEmpty()) { |
| 162 | header.appendf(" --tmpDir %s", tmpDir.c_str()); |
djsollen@google.com | cb62650 | 2013-03-20 13:48:20 +0000 | [diff] [blame] | 163 | } |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 164 | SkString resourcePath = GetResourcePath(); |
scroggo@google.com | c76218d | 2013-06-06 14:59:56 +0000 | [diff] [blame] | 165 | if (!resourcePath.isEmpty()) { |
| 166 | header.appendf(" --resourcePath %s", resourcePath.c_str()); |
reed@google.com | 789c6f2 | 2013-02-25 20:24:24 +0000 | [diff] [blame] | 167 | } |
caryclark | 1326068 | 2016-10-24 05:10:14 -0700 | [diff] [blame] | 168 | #if DEBUG_COIN |
| 169 | if (FLAGS_coinTest) { |
| 170 | header.appendf(" -c"); |
| 171 | } |
| 172 | #endif |
| 173 | if (FLAGS_dumpOp) { |
| 174 | header.appendf(" -d"); |
| 175 | } |
Cary Clark | 59d5a0e | 2017-01-23 14:38:52 +0000 | [diff] [blame] | 176 | #ifdef SK_DEBUG |
| 177 | if (FLAGS_runFail) { |
| 178 | header.appendf(" -f"); |
| 179 | } |
| 180 | #endif |
caryclark | 1326068 | 2016-10-24 05:10:14 -0700 | [diff] [blame] | 181 | if (FLAGS_verbose) { |
| 182 | header.appendf(" -v"); |
| 183 | } |
| 184 | if (FLAGS_veryVerbose) { |
| 185 | header.appendf(" -V"); |
| 186 | } |
| 187 | if (FLAGS_extendedTest) { |
| 188 | header.appendf(" -x"); |
| 189 | } |
| 190 | if (FLAGS_verifyOp) { |
| 191 | header.appendf(" -y"); |
| 192 | } |
reed@google.com | 91d449e | 2011-10-26 15:25:18 +0000 | [diff] [blame] | 193 | #ifdef SK_DEBUG |
| 194 | header.append(" SK_DEBUG"); |
| 195 | #else |
| 196 | header.append(" SK_RELEASE"); |
| 197 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 198 | if (FLAGS_veryVerbose) { |
| 199 | header.appendf("\n"); |
| 200 | } |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 201 | SkDebugf("%s", header.c_str()); |
reed@google.com | 91d449e | 2011-10-26 15:25:18 +0000 | [diff] [blame] | 202 | } |
| 203 | |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 204 | |
commit-bot@chromium.org | 0506b9d | 2013-04-22 16:43:07 +0000 | [diff] [blame] | 205 | // Count tests first. |
| 206 | int total = 0; |
| 207 | int toRun = 0; |
sglez@google.com | 586db93 | 2013-07-24 17:24:23 +0000 | [diff] [blame] | 208 | |
Hal Canary | 972eba3 | 2018-07-30 17:07:07 -0400 | [diff] [blame] | 209 | for (const Test& test : TestRegistry::Range()) { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 210 | if (should_run(test.name, test.needsGpu)) { |
commit-bot@chromium.org | 0506b9d | 2013-04-22 16:43:07 +0000 | [diff] [blame] | 211 | toRun++; |
| 212 | } |
| 213 | total++; |
| 214 | } |
commit-bot@chromium.org | 0506b9d | 2013-04-22 16:43:07 +0000 | [diff] [blame] | 215 | |
| 216 | // Now run them. |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 217 | int skipCount = 0; |
commit-bot@chromium.org | 197845a | 2013-04-19 13:24:28 +0000 | [diff] [blame] | 218 | |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 219 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
| 220 | SkTaskGroup cpuTests; |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 221 | SkTArray<const Test*> gpuTests; |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 222 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 223 | Status status(toRun); |
Hal Canary | 972eba3 | 2018-07-30 17:07:07 -0400 | [diff] [blame] | 224 | |
| 225 | for (const Test& test : TestRegistry::Range()) { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 226 | if (!should_run(test.name, test.needsGpu)) { |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 227 | ++skipCount; |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 228 | } else if (test.needsGpu) { |
| 229 | gpuTests.push_back(&test); |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 230 | } else { |
mtklein | 048494c | 2016-02-16 19:06:15 -0800 | [diff] [blame] | 231 | cpuTests.add(SkTestRunnable(test, &status)); |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 232 | } |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 233 | } |
reed@android.com | 57b799e | 2009-04-01 20:26:42 +0000 | [diff] [blame] | 234 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 235 | // Run GPU tests on this thread. |
| 236 | for (int i = 0; i < gpuTests.count(); i++) { |
Brian Salomon | dcfca43 | 2017-11-15 15:48:03 -0500 | [diff] [blame] | 237 | SkTestRunnable(*gpuTests[i], &status)(); |
commit-bot@chromium.org | 197845a | 2013-04-19 13:24:28 +0000 | [diff] [blame] | 238 | } |
| 239 | |
commit-bot@chromium.org | a7538ba | 2013-10-10 18:49:04 +0000 | [diff] [blame] | 240 | // Block until threaded tests finish. |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 241 | cpuTests.wait(); |
commit-bot@chromium.org | 197845a | 2013-04-19 13:24:28 +0000 | [diff] [blame] | 242 | |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 243 | if (FLAGS_verbose) { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 244 | SkDebugf( |
| 245 | "\nFinished %d tests, %d failures, %d skipped. " |
| 246 | "(%d internal tests)", |
| 247 | toRun, status.failCount(), skipCount, status.testCount()); |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 248 | if (gVerboseFinalize) { |
| 249 | (*gVerboseFinalize)(); |
| 250 | } |
caryclark@google.com | d54e1e9 | 2013-04-10 15:57:31 +0000 | [diff] [blame] | 251 | } |
reed@google.com | a276975 | 2012-07-22 22:33:05 +0000 | [diff] [blame] | 252 | |
commit-bot@chromium.org | 261c666 | 2014-01-02 16:19:53 +0000 | [diff] [blame] | 253 | SkDebugf("\n"); |
Cary Clark | ab87d7a | 2016-10-04 10:01:04 -0400 | [diff] [blame] | 254 | #if DEBUG_COIN |
| 255 | if (FLAGS_coinTest) { |
| 256 | SkPathOpsDebug::DumpCoinDict(); |
| 257 | } |
| 258 | #endif |
Cary Clark | f394912 | 2018-08-07 16:38:21 -0400 | [diff] [blame] | 259 | if (PathOpsDebug::gJson) { |
| 260 | fprintf(PathOpsDebug::gOut, "\n}\n"); |
| 261 | fclose(PathOpsDebug::gOut); |
| 262 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 263 | return (status.failCount() == 0) ? 0 : 1; |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 264 | } |