scroggo | 478652e | 2015-03-25 07:11:02 -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 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 8 | #include "CrashHandler.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 9 | #include "DMJsonWriter.h" |
| 10 | #include "DMSrcSink.h" |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 11 | #include "DMSrcSinkAndroid.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 12 | #include "OverwriteLine.h" |
| 13 | #include "ProcStats.h" |
| 14 | #include "SkBBHFactory.h" |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 15 | #include "SkChecksum.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 16 | #include "SkCommonFlags.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 17 | #include "SkForceLinking.h" |
| 18 | #include "SkGraphics.h" |
mtklein | e67164d | 2015-02-02 13:24:37 -0800 | [diff] [blame] | 19 | #include "SkInstCnt.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 20 | #include "SkMD5.h" |
mtklein | 1d0f164 | 2014-09-08 08:05:18 -0700 | [diff] [blame] | 21 | #include "SkOSFile.h" |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 22 | #include "SkTHash.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 23 | #include "SkTaskGroup.h" |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 24 | #include "SkThreadUtils.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 25 | #include "Test.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 26 | #include "Timer.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 27 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 28 | DEFINE_string(src, "tests gm skp image", "Source types to test."); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 29 | DEFINE_bool(nameByHash, false, |
| 30 | "If true, write to FLAGS_writePath[0]/<hash>.png instead of " |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 31 | "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 32 | DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 33 | DEFINE_string(matrix, "1 0 0 1", |
| 34 | "2x2 scale+skew matrix to apply or upright when using " |
| 35 | "'matrix' or 'upright' in config."); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 36 | DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?"); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 37 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 38 | DEFINE_string(blacklist, "", |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 39 | "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n" |
| 40 | "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n" |
| 41 | "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888."); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 42 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 43 | DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory."); |
| 44 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 45 | __SK_FORCE_IMAGE_DECODER_LINKING; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 46 | using namespace DM; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 47 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 48 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 49 | |
| 50 | SK_DECLARE_STATIC_MUTEX(gFailuresMutex); |
| 51 | static SkTArray<SkString> gFailures; |
| 52 | |
| 53 | static void fail(ImplicitString err) { |
| 54 | SkAutoMutexAcquire lock(gFailuresMutex); |
| 55 | SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); |
| 56 | gFailures.push_back(err); |
halcanary | 9e398f7 | 2015-01-10 11:18:04 -0800 | [diff] [blame] | 57 | } |
| 58 | |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 59 | static int32_t gPending = 0; // Atomic. Total number of running and queued tasks. |
| 60 | |
| 61 | SK_DECLARE_STATIC_MUTEX(gRunningMutex); |
| 62 | static SkTArray<SkString> gRunning; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 63 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 64 | static void done(double ms, |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 65 | ImplicitString config, ImplicitString src, ImplicitString srcOptions, |
| 66 | ImplicitString name, ImplicitString note, ImplicitString log) { |
| 67 | SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(), |
| 68 | srcOptions.c_str(), name.c_str()); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 69 | { |
| 70 | SkAutoMutexAcquire lock(gRunningMutex); |
| 71 | for (int i = 0; i < gRunning.count(); i++) { |
| 72 | if (gRunning[i] == id) { |
| 73 | gRunning.removeShuffle(i); |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | if (!FLAGS_verbose) { |
| 79 | note = ""; |
| 80 | } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 81 | if (!log.isEmpty()) { |
| 82 | log.prepend("\n"); |
| 83 | } |
mtklein | 6dee2ad | 2015-02-05 09:53:44 -0800 | [diff] [blame] | 84 | auto pending = sk_atomic_dec(&gPending)-1; |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 85 | SkDebugf("%s(%4dMB %5d) %s\t%s%s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine |
| 86 | , sk_tools::getBestResidentSetSizeMB() |
| 87 | , pending |
| 88 | , HumanizeMs(ms).c_str() |
| 89 | , id.c_str() |
| 90 | , note.c_str() |
| 91 | , log.c_str()); |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 92 | // We write our dm.json file every once in a while in case we crash. |
| 93 | // Notice this also handles the final dm.json when pending == 0. |
| 94 | if (pending % 500 == 0) { |
| 95 | JsonWriter::DumpJson(); |
| 96 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 97 | } |
| 98 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 99 | static void start(ImplicitString config, ImplicitString src, |
| 100 | ImplicitString srcOptions, ImplicitString name) { |
| 101 | SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(), |
| 102 | srcOptions.c_str(), name.c_str()); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 103 | SkAutoMutexAcquire lock(gRunningMutex); |
| 104 | gRunning.push_back(id); |
| 105 | } |
| 106 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 107 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 108 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 109 | struct Gold : public SkString { |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 110 | Gold() : SkString("") {} |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 111 | Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions, |
| 112 | ImplicitString name, ImplicitString md5) |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 113 | : SkString("") { |
| 114 | this->append(sink); |
| 115 | this->append(src); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 116 | this->append(srcOptions); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 117 | this->append(name); |
| 118 | this->append(md5); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 119 | } |
mtklein | 02f46cf | 2015-03-20 13:48:42 -0700 | [diff] [blame] | 120 | static uint32_t Hash(const Gold& g) { return SkGoodHash((const SkString&)g); } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 121 | }; |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 122 | static SkTHashSet<Gold, Gold::Hash> gGold; |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 123 | |
| 124 | static void add_gold(JsonWriter::BitmapResult r) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 125 | gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5)); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static void gather_gold() { |
| 129 | if (!FLAGS_readPath.isEmpty()) { |
| 130 | SkString path(FLAGS_readPath[0]); |
| 131 | path.append("/dm.json"); |
| 132 | if (!JsonWriter::ReadJson(path.c_str(), add_gold)) { |
| 133 | fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str())); |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 139 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 140 | template <typename T> |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 141 | struct Tagged : public SkAutoTDelete<T> { |
| 142 | const char* tag; |
| 143 | const char* options; |
| 144 | }; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 145 | |
| 146 | static const bool kMemcpyOK = true; |
| 147 | |
| 148 | static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs; |
| 149 | static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks; |
| 150 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 151 | static void push_src(const char* tag, const char* options, Src* s) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 152 | SkAutoTDelete<Src> src(s); |
| 153 | if (FLAGS_src.contains(tag) && |
| 154 | !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { |
| 155 | Tagged<Src>& s = gSrcs.push_back(); |
| 156 | s.reset(src.detach()); |
| 157 | s.tag = tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 158 | s.options = options; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 159 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 160 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 161 | |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 162 | static bool codec_supported(const char* ext) { |
| 163 | // FIXME: Once other versions of SkCodec are available, we can add them to this |
| 164 | // list (and eventually we can remove this check once they are all supported). |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 165 | static const char* const exts[] = { |
| 166 | "bmp", "gif", "png", "ico", "wbmp", |
| 167 | "BMP", "GIF", "PNG", "ICO", "WBMP" |
| 168 | }; |
| 169 | |
| 170 | for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { |
| 171 | if (0 == strcmp(exts[i], ext)) { |
| 172 | return true; |
| 173 | } |
| 174 | } |
| 175 | return false; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 176 | } |
| 177 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 178 | static void gather_srcs() { |
| 179 | for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 180 | push_src("gm", "", new GMSrc(r->factory())); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 181 | } |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 182 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 183 | const char* path = FLAGS_skps[i]; |
| 184 | if (sk_isdir(path)) { |
| 185 | SkOSFile::Iter it(path, "skp"); |
| 186 | for (SkString file; it.next(&file); ) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 187 | push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str()))); |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 188 | } |
| 189 | } else { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 190 | push_src("skp", "", new SKPSrc(path)); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 191 | } |
| 192 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 193 | static const char* const exts[] = { |
| 194 | "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico", |
| 195 | "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO", |
| 196 | }; |
| 197 | for (int i = 0; i < FLAGS_images.count(); i++) { |
| 198 | const char* flag = FLAGS_images[i]; |
| 199 | if (sk_isdir(flag)) { |
| 200 | for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) { |
| 201 | SkOSFile::Iter it(flag, exts[j]); |
| 202 | for (SkString file; it.next(&file); ) { |
| 203 | SkString path = SkOSPath::Join(flag, file.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 204 | push_src("image", "decode", new ImageSrc(path)); // Decode entire image |
| 205 | push_src("image", "subset", new ImageSrc(path, 2)); // Decode into 2x2 subsets |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 206 | if (codec_supported(exts[j])) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 207 | push_src("image", "codec", new CodecSrc(path, CodecSrc::kNormal_Mode)); |
| 208 | push_src("image", "scanline", new CodecSrc(path, CodecSrc::kScanline_Mode)); |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 209 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 210 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 211 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 212 | } else if (sk_exists(flag)) { |
| 213 | // assume that FLAGS_images[i] is a valid image if it is a file. |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 214 | push_src("image", "decode", new ImageSrc(flag)); // Decode entire image. |
| 215 | push_src("image", "subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subsets |
| 216 | push_src("image", "codec", new CodecSrc(flag, CodecSrc::kNormal_Mode)); |
| 217 | push_src("image", "scanline", new CodecSrc(flag, CodecSrc::kScanline_Mode)); |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 218 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 222 | static GrGLStandard get_gpu_api() { |
| 223 | if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; } |
| 224 | if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; } |
| 225 | return kNone_GrGLStandard; |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 226 | } |
| 227 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 228 | static void push_sink(const char* tag, Sink* s) { |
| 229 | SkAutoTDelete<Sink> sink(s); |
| 230 | if (!FLAGS_config.contains(tag)) { |
| 231 | return; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 232 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 233 | // Try a noop Src as a canary. If it fails, skip this sink. |
| 234 | struct : public Src { |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 235 | Error draw(SkCanvas*) const override { return ""; } |
| 236 | SkISize size() const override { return SkISize::Make(16, 16); } |
| 237 | Name name() const override { return "noop"; } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 238 | } noop; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 239 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 240 | SkBitmap bitmap; |
| 241 | SkDynamicMemoryWStream stream; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 242 | SkString log; |
| 243 | Error err = sink->draw(noop, &bitmap, &stream, &log); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 244 | if (err.isFatal()) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 245 | SkDebugf("Skipping %s: %s\n", tag, err.c_str()); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 246 | return; |
| 247 | } |
| 248 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 249 | Tagged<Sink>& ts = gSinks.push_back(); |
| 250 | ts.reset(sink.detach()); |
| 251 | ts.tag = tag; |
| 252 | } |
| 253 | |
| 254 | static bool gpu_supported() { |
| 255 | #if SK_SUPPORT_GPU |
| 256 | return FLAGS_gpu; |
| 257 | #else |
| 258 | return false; |
| 259 | #endif |
| 260 | } |
| 261 | |
| 262 | static Sink* create_sink(const char* tag) { |
| 263 | #define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); } |
| 264 | if (gpu_supported()) { |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 265 | typedef GrContextFactory Gr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 266 | const GrGLStandard api = get_gpu_api(); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 267 | SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 268 | SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 269 | SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 270 | SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading); |
| 271 | SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 272 | SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading); |
| 273 | SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 274 | SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 275 | #if SK_ANGLE |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 276 | SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 277 | #endif |
| 278 | #if SK_MESA |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 279 | SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 280 | #endif |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 281 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 282 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 283 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 284 | SINK("hwui", HWUISink); |
| 285 | #endif |
| 286 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 287 | if (FLAGS_cpu) { |
| 288 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 289 | SINK("8888", RasterSink, kN32_SkColorType); |
mtklein | 19f3060 | 2015-01-20 13:34:39 -0800 | [diff] [blame] | 290 | SINK("pdf", PDFSink); |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 291 | SINK("skp", SKPSink); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 292 | SINK("svg", SVGSink); |
| 293 | SINK("null", NullSink); |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 294 | SINK("xps", XPSSink); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 295 | } |
| 296 | #undef SINK |
| 297 | return NULL; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 298 | } |
| 299 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 300 | static Sink* create_via(const char* tag, Sink* wrapped) { |
| 301 | #define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); } |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 302 | VIA("pipe", ViaPipe, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 303 | VIA("serialize", ViaSerialization, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 304 | VIA("tiles", ViaTiles, 256, 256, NULL, wrapped); |
| 305 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 306 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 307 | if (FLAGS_matrix.count() == 4) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 308 | SkMatrix m; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 309 | m.reset(); |
| 310 | m.setScaleX((SkScalar)atof(FLAGS_matrix[0])); |
| 311 | m.setSkewX ((SkScalar)atof(FLAGS_matrix[1])); |
| 312 | m.setSkewY ((SkScalar)atof(FLAGS_matrix[2])); |
| 313 | m.setScaleY((SkScalar)atof(FLAGS_matrix[3])); |
| 314 | VIA("matrix", ViaMatrix, m, wrapped); |
| 315 | VIA("upright", ViaUpright, m, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 316 | } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 317 | |
| 318 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 319 | VIA("androidsdk", ViaAndroidSDK, wrapped); |
| 320 | #endif |
| 321 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 322 | #undef VIA |
| 323 | return NULL; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 324 | } |
| 325 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 326 | static void gather_sinks() { |
| 327 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 328 | const char* config = FLAGS_config[i]; |
| 329 | SkTArray<SkString> parts; |
| 330 | SkStrSplit(config, "-", &parts); |
| 331 | |
| 332 | Sink* sink = NULL; |
| 333 | for (int i = parts.count(); i-- > 0;) { |
| 334 | const char* part = parts[i].c_str(); |
| 335 | Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink); |
| 336 | if (next == NULL) { |
| 337 | SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part); |
| 338 | delete sink; |
| 339 | sink = NULL; |
| 340 | break; |
| 341 | } |
| 342 | sink = next; |
| 343 | } |
| 344 | if (sink) { |
| 345 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 349 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 350 | static bool match(const char* needle, const char* haystack) { |
| 351 | return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle); |
| 352 | } |
| 353 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 354 | static ImplicitString is_blacklisted(const char* sink, const char* src, |
| 355 | const char* srcOptions, const char* name) { |
| 356 | for (int i = 0; i < FLAGS_blacklist.count() - 2; i += 4) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 357 | if (match(FLAGS_blacklist[i+0], sink) && |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 358 | match(FLAGS_blacklist[i+1], src) && |
| 359 | match(FLAGS_blacklist[i+2], srcOptions) && |
| 360 | match(FLAGS_blacklist[i+3], name)) { |
| 361 | return SkStringPrintf("%s %s %s %s", |
| 362 | FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], |
| 363 | FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | return ""; |
| 367 | } |
| 368 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 369 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 370 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 371 | struct Task { |
| 372 | Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {} |
| 373 | const Tagged<Src>& src; |
| 374 | const Tagged<Sink>& sink; |
| 375 | |
| 376 | static void Run(Task* task) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 377 | SkString name = task->src->name(); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 378 | SkString note; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 379 | SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag, |
| 380 | task->src.options, name.c_str()); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 381 | if (!whyBlacklisted.isEmpty()) { |
| 382 | note.appendf(" (--blacklist %s)", whyBlacklisted.c_str()); |
| 383 | } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 384 | SkString log; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 385 | WallTimer timer; |
| 386 | timer.start(); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 387 | if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 388 | SkBitmap bitmap; |
| 389 | SkDynamicMemoryWStream stream; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 390 | start(task->sink.tag, task->src.tag, task->src.options, name.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 391 | Error err = task->sink->draw(*task->src, &bitmap, &stream, &log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 392 | if (!err.isEmpty()) { |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 393 | timer.end(); |
| 394 | if (err.isFatal()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 395 | fail(SkStringPrintf("%s %s %s %s: %s", |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 396 | task->sink.tag, |
| 397 | task->src.tag, |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 398 | task->src.options, |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 399 | name.c_str(), |
| 400 | err.c_str())); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 401 | } else { |
| 402 | note.appendf(" (skipped: %s)", err.c_str()); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 403 | } |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 404 | done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, |
| 405 | name, note, log); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 406 | return; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 407 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 408 | SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream()); |
| 409 | |
| 410 | SkString md5; |
| 411 | if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { |
| 412 | SkMD5 hash; |
| 413 | if (data->getLength()) { |
| 414 | hash.writeStream(data, data->getLength()); |
| 415 | data->rewind(); |
| 416 | } else { |
| 417 | hash.write(bitmap.getPixels(), bitmap.getSize()); |
| 418 | } |
| 419 | SkMD5::Digest digest; |
| 420 | hash.finish(digest); |
| 421 | for (int i = 0; i < 16; i++) { |
| 422 | md5.appendf("%02x", digest.data[i]); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | if (!FLAGS_readPath.isEmpty() && |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 427 | !gGold.contains(Gold(task->sink.tag, task->src.tag, |
| 428 | task->src.options, name, md5))) { |
| 429 | fail(SkStringPrintf("%s not found for %s %s %s %s in %s", |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 430 | md5.c_str(), |
| 431 | task->sink.tag, |
| 432 | task->src.tag, |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 433 | task->src.options, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 434 | name.c_str(), |
| 435 | FLAGS_readPath[0])); |
| 436 | } |
| 437 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 438 | if (!FLAGS_writePath.isEmpty()) { |
| 439 | const char* ext = task->sink->fileExtension(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 440 | if (data->getLength()) { |
| 441 | WriteToDisk(*task, md5, ext, data, data->getLength(), NULL); |
halcanary | 022afb8 | 2015-01-30 11:00:12 -0800 | [diff] [blame] | 442 | SkASSERT(bitmap.drawsNothing()); |
| 443 | } else if (!bitmap.drawsNothing()) { |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 444 | WriteToDisk(*task, md5, ext, NULL, 0, &bitmap); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | } |
| 448 | timer.end(); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 449 | done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, name, note, log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static void WriteToDisk(const Task& task, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 453 | SkString md5, |
| 454 | const char* ext, |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 455 | SkStream* data, size_t len, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 456 | const SkBitmap* bitmap) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 457 | JsonWriter::BitmapResult result; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 458 | result.name = task.src->name(); |
| 459 | result.config = task.sink.tag; |
| 460 | result.sourceType = task.src.tag; |
| 461 | result.sourceOptions = task.src.options; |
| 462 | result.ext = ext; |
| 463 | result.md5 = md5; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 464 | JsonWriter::AddBitmapResult(result); |
| 465 | |
| 466 | const char* dir = FLAGS_writePath[0]; |
| 467 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 468 | dir = FLAGS_resourcePath[0]; |
| 469 | } |
| 470 | sk_mkdir(dir); |
| 471 | |
| 472 | SkString path; |
| 473 | if (FLAGS_nameByHash) { |
| 474 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 475 | path.append("."); |
| 476 | path.append(ext); |
| 477 | if (sk_exists(path.c_str())) { |
| 478 | return; // Content-addressed. If it exists already, we're done. |
| 479 | } |
| 480 | } else { |
| 481 | path = SkOSPath::Join(dir, task.sink.tag); |
| 482 | sk_mkdir(path.c_str()); |
| 483 | path = SkOSPath::Join(path.c_str(), task.src.tag); |
| 484 | sk_mkdir(path.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 485 | if (strcmp(task.src.options, "") != 0) { |
| 486 | path = SkOSPath::Join(path.c_str(), task.src.options); |
| 487 | sk_mkdir(path.c_str()); |
| 488 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 489 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 490 | path.append("."); |
| 491 | path.append(ext); |
| 492 | } |
| 493 | |
| 494 | SkFILEWStream file(path.c_str()); |
| 495 | if (!file.isValid()) { |
| 496 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 497 | return; |
| 498 | } |
| 499 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 500 | if (bitmap) { |
| 501 | // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first. |
| 502 | SkBitmap converted; |
| 503 | if (bitmap->info().colorType() == kAlpha_8_SkColorType) { |
| 504 | if (!bitmap->copyTo(&converted, kN32_SkColorType)) { |
| 505 | fail("Can't convert A8 to 8888.\n"); |
| 506 | return; |
| 507 | } |
| 508 | bitmap = &converted; |
| 509 | } |
| 510 | if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) { |
| 511 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 512 | return; |
| 513 | } |
| 514 | } else { |
| 515 | if (!file.writeStream(data, len)) { |
| 516 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 517 | return; |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | }; |
| 522 | |
| 523 | // Run all tasks in the same enclave serially on the same thread. |
| 524 | // They can't possibly run concurrently with each other. |
| 525 | static void run_enclave(SkTArray<Task>* tasks) { |
| 526 | for (int i = 0; i < tasks->count(); i++) { |
| 527 | Task::Run(tasks->begin() + i); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 532 | |
| 533 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 534 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 535 | static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 536 | |
| 537 | static void gather_tests() { |
mtklein | 6c5fed2 | 2015-01-20 13:47:23 -0800 | [diff] [blame] | 538 | if (!FLAGS_src.contains("tests")) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 539 | return; |
| 540 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 541 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; |
| 542 | r = r->next()) { |
| 543 | // Despite its name, factory() is returning a reference to |
| 544 | // link-time static const POD data. |
| 545 | const skiatest::Test& test = r->factory(); |
| 546 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 547 | continue; |
| 548 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 549 | if (test.needsGpu && gpu_supported()) { |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 550 | (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 551 | } else if (!test.needsGpu && FLAGS_cpu) { |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 552 | gThreadedTests.push(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 553 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 557 | static void run_test(skiatest::Test* test) { |
| 558 | struct : public skiatest::Reporter { |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 559 | void reportFailed(const skiatest::Failure& failure) override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 560 | fail(failure.toString()); |
| 561 | JsonWriter::AddTestFailure(failure); |
| 562 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 563 | bool allowExtendedTest() const override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 564 | return FLAGS_pathOpsExtended; |
| 565 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 566 | bool verbose() const override { return FLAGS_veryVerbose; } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 567 | } reporter; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 568 | WallTimer timer; |
| 569 | timer.start(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 570 | if (!FLAGS_dryRun) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 571 | start("unit", "test", "", test->name); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 572 | GrContextFactory factory; |
| 573 | test->proc(&reporter, &factory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 574 | } |
| 575 | timer.end(); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame^] | 576 | done(timer.fWall, "unit", "test", "", test->name, "", ""); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 580 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 581 | // If we're isolating all GPU-bound work to one thread (the default), this function runs all that. |
| 582 | static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) { |
| 583 | run_enclave(tasks); |
| 584 | for (int i = 0; i < gGPUTests.count(); i++) { |
| 585 | run_test(&gGPUTests[i]); |
| 586 | } |
| 587 | } |
| 588 | |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 589 | // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung. |
| 590 | // This prints something every once in a while so that it knows we're still working. |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 591 | static void start_keepalive() { |
| 592 | struct Loop { |
| 593 | static void forever(void*) { |
| 594 | for (;;) { |
| 595 | static const int kSec = 300; |
| 596 | #if defined(SK_BUILD_FOR_WIN) |
| 597 | Sleep(kSec * 1000); |
| 598 | #else |
| 599 | sleep(kSec); |
| 600 | #endif |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 601 | SkString running; |
| 602 | { |
| 603 | SkAutoMutexAcquire lock(gRunningMutex); |
| 604 | for (int i = 0; i < gRunning.count(); i++) { |
| 605 | running.appendf("\n\t%s", gRunning[i].c_str()); |
| 606 | } |
| 607 | } |
| 608 | SkDebugf("\nCurrently running:%s\n", running.c_str()); |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | }; |
| 612 | static SkThread* intentionallyLeaked = new SkThread(Loop::forever); |
| 613 | intentionallyLeaked->start(); |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 614 | } |
| 615 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 616 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 617 | int dm_main() { |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 618 | SetupCrashHandler(); |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 619 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 620 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
mtklein | e67164d | 2015-02-02 13:24:37 -0800 | [diff] [blame] | 621 | if (FLAGS_leaks) { |
| 622 | SkInstCountPrintLeaksOnExit(); |
| 623 | } |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 624 | |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 625 | start_keepalive(); |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 626 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 627 | gather_gold(); |
| 628 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 629 | gather_srcs(); |
| 630 | gather_sinks(); |
| 631 | gather_tests(); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 632 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 633 | gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 634 | SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n", |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 635 | gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 636 | |
| 637 | // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread, |
| 638 | // but Sinks that identify as part of a particular enclave run serially on a single thread. |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 639 | // CPU tests run on any thread. GPU tests depend on --gpu_threading. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 640 | SkTArray<Task> enclaves[kNumEnclaves]; |
| 641 | for (int j = 0; j < gSinks.count(); j++) { |
| 642 | SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()]; |
| 643 | for (int i = 0; i < gSrcs.count(); i++) { |
| 644 | tasks.push_back(Task(gSrcs[i], gSinks[j])); |
| 645 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 646 | } |
| 647 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 648 | SkTaskGroup tg; |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 649 | tg.batch(run_test, gThreadedTests.begin(), gThreadedTests.count()); |
| 650 | for (int i = 0; i < kNumEnclaves; i++) { |
| 651 | switch(i) { |
| 652 | case kAnyThread_Enclave: |
| 653 | tg.batch(Task::Run, enclaves[i].begin(), enclaves[i].count()); |
| 654 | break; |
| 655 | case kGPU_Enclave: |
| 656 | tg.add(run_enclave_and_gpu_tests, &enclaves[i]); |
| 657 | break; |
| 658 | default: |
| 659 | tg.add(run_enclave, &enclaves[i]); |
| 660 | break; |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 661 | } |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 662 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 663 | tg.wait(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 664 | // At this point we're back in single-threaded land. |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 665 | |
mtklein | 2f64eec | 2015-01-15 14:20:41 -0800 | [diff] [blame] | 666 | SkDebugf("\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 667 | if (gFailures.count() > 0) { |
| 668 | SkDebugf("Failures:\n"); |
| 669 | for (int i = 0; i < gFailures.count(); i++) { |
mtklein | 9dc0910 | 2015-01-15 15:47:33 -0800 | [diff] [blame] | 670 | SkDebugf("\t%s\n", gFailures[i].c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 671 | } |
| 672 | SkDebugf("%d failures\n", gFailures.count()); |
| 673 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 674 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 675 | if (gPending > 0) { |
| 676 | SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n"); |
| 677 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 678 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 679 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 680 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 681 | |
borenet | 4808757 | 2015-04-02 12:16:36 -0700 | [diff] [blame] | 682 | #if !defined(SK_BUILD_FOR_IOS) |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 683 | int main(int argc, char** argv) { |
| 684 | SkCommandLineFlags::Parse(argc, argv); |
| 685 | return dm_main(); |
| 686 | } |
| 687 | #endif |