blob: 8537313cf33e8697e831a219b48c86d93119e49d [file] [log] [blame]
scroggo478652e2015-03-25 07:11:02 -07001/*
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
jcgregorio3b27ade2014-11-13 08:06:40 -08008#include "CrashHandler.h"
mtklein748ca3b2015-01-15 10:56:12 -08009#include "DMJsonWriter.h"
10#include "DMSrcSink.h"
tomhudsoneebc39a2015-02-23 12:18:05 -080011#include "DMSrcSinkAndroid.h"
mtklein748ca3b2015-01-15 10:56:12 -080012#include "OverwriteLine.h"
13#include "ProcStats.h"
14#include "SkBBHFactory.h"
mtklein62bd1a62015-01-27 14:46:26 -080015#include "SkChecksum.h"
scroggocc2feb12015-08-14 08:32:46 -070016#include "SkCodec.h"
caryclark17f0b6d2014-07-22 10:15:34 -070017#include "SkCommonFlags.h"
caryclark83ca6282015-06-10 09:31:09 -070018#include "SkFontMgr.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000019#include "SkForceLinking.h"
20#include "SkGraphics.h"
mtklein748ca3b2015-01-15 10:56:12 -080021#include "SkMD5.h"
mtklein1b249332015-07-07 12:21:21 -070022#include "SkMutex.h"
mtklein1d0f1642014-09-08 08:05:18 -070023#include "SkOSFile.h"
mtkleina82f5622015-02-20 12:30:19 -080024#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070025#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070026#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000027#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080028#include "Timer.h"
caryclark83ca6282015-06-10 09:31:09 -070029#include "sk_tool_utils.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000030
mtkleina5114d72015-08-24 13:27:01 -070031#ifdef SKIA_PNG_PREFIXED
32 // this must proceed png.h
33 #include "pngprefix.h"
34#endif
35#include "png.h"
36
djsollen54416de2015-04-03 07:24:48 -070037DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080038DEFINE_bool(nameByHash, false,
39 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070040 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080041DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080042DEFINE_string(matrix, "1 0 0 1",
43 "2x2 scale+skew matrix to apply or upright when using "
44 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080045DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000046
mtkleina2ef6422015-01-15 13:44:22 -080047DEFINE_string(blacklist, "",
djsollen54416de2015-04-03 07:24:48 -070048 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n"
49 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
50 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.");
mtkleina2ef6422015-01-15 13:44:22 -080051
mtklein62bd1a62015-01-27 14:46:26 -080052DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
53
borenet09ed4802015-04-03 14:15:33 -070054DEFINE_string(uninterestingHashesFile, "",
55 "File containing a list of uninteresting hashes. If a result hashes to something in "
56 "this list, no image is written for that result.");
57
mtklein6393c062015-04-27 08:45:01 -070058DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
59DEFINE_int32(shard, 0, "Which shard do I run?");
bsalomon821e10e2015-06-04 14:15:33 -070060DEFINE_bool2(pre_log, p, false, "Log before running each test. May be incomprehensible when threading");
mtklein6393c062015-04-27 08:45:01 -070061
mtklein@google.comd36522d2013-10-16 13:02:15 +000062__SK_FORCE_IMAGE_DECODER_LINKING;
mtklein748ca3b2015-01-15 10:56:12 -080063using namespace DM;
mtklein@google.comd36522d2013-10-16 13:02:15 +000064
mtklein748ca3b2015-01-15 10:56:12 -080065/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
66
67SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
68static SkTArray<SkString> gFailures;
69
70static void fail(ImplicitString err) {
71 SkAutoMutexAcquire lock(gFailuresMutex);
72 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
73 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -080074}
75
mtkleinb37cb412015-03-18 05:27:14 -070076static int32_t gPending = 0; // Atomic. Total number of running and queued tasks.
77
78SK_DECLARE_STATIC_MUTEX(gRunningMutex);
79static SkTArray<SkString> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -080080
mtkleinb9eb4ac2015-02-02 18:26:03 -080081static void done(double ms,
djsollen54416de2015-04-03 07:24:48 -070082 ImplicitString config, ImplicitString src, ImplicitString srcOptions,
83 ImplicitString name, ImplicitString note, ImplicitString log) {
84 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
85 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -070086 {
87 SkAutoMutexAcquire lock(gRunningMutex);
88 for (int i = 0; i < gRunning.count(); i++) {
89 if (gRunning[i] == id) {
90 gRunning.removeShuffle(i);
91 break;
92 }
93 }
94 }
95 if (!FLAGS_verbose) {
96 note = "";
97 }
mtkleinb9eb4ac2015-02-02 18:26:03 -080098 if (!log.isEmpty()) {
99 log.prepend("\n");
100 }
mtklein6dee2ad2015-02-05 09:53:44 -0800101 auto pending = sk_atomic_dec(&gPending)-1;
reed50bc0512015-05-19 14:13:31 -0700102 if (!FLAGS_quiet) {
mtklein711a2452015-07-08 08:49:20 -0700103 SkDebugf("%s(%4d/%-4dMB %6d) %s\t%s%s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine
reed50bc0512015-05-19 14:13:31 -0700104 , sk_tools::getCurrResidentSetSizeMB()
105 , sk_tools::getMaxResidentSetSizeMB()
106 , pending
107 , HumanizeMs(ms).c_str()
108 , id.c_str()
109 , note.c_str()
110 , log.c_str());
111 }
mtkleina17241b2015-01-23 05:48:00 -0800112 // We write our dm.json file every once in a while in case we crash.
113 // Notice this also handles the final dm.json when pending == 0.
114 if (pending % 500 == 0) {
115 JsonWriter::DumpJson();
116 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000117}
118
djsollen54416de2015-04-03 07:24:48 -0700119static void start(ImplicitString config, ImplicitString src,
120 ImplicitString srcOptions, ImplicitString name) {
121 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
122 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700123 SkAutoMutexAcquire lock(gRunningMutex);
124 gRunning.push_back(id);
125}
126
mtklein748ca3b2015-01-15 10:56:12 -0800127/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800128
mtklein62bd1a62015-01-27 14:46:26 -0800129struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800130 Gold() : SkString("") {}
djsollen54416de2015-04-03 07:24:48 -0700131 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions,
132 ImplicitString name, ImplicitString md5)
mtklein62bd1a62015-01-27 14:46:26 -0800133 : SkString("") {
134 this->append(sink);
135 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700136 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800137 this->append(name);
138 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800139 }
mtklein02f46cf2015-03-20 13:48:42 -0700140 static uint32_t Hash(const Gold& g) { return SkGoodHash((const SkString&)g); }
mtklein62bd1a62015-01-27 14:46:26 -0800141};
mtkleina82f5622015-02-20 12:30:19 -0800142static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800143
144static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700145 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800146}
147
148static void gather_gold() {
149 if (!FLAGS_readPath.isEmpty()) {
150 SkString path(FLAGS_readPath[0]);
151 path.append("/dm.json");
152 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
153 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
154 }
155 }
156}
157
158/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
159
borenet09ed4802015-04-03 14:15:33 -0700160static SkTHashSet<SkString> gUninterestingHashes;
161
162static void gather_uninteresting_hashes() {
163 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
164 SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0]));
165 SkTArray<SkString> hashes;
166 SkStrSplit((const char*)data->data(), "\n", &hashes);
167 for (const SkString& hash : hashes) {
168 gUninterestingHashes.add(hash);
169 }
170 }
171}
172
173/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
174
mtkleine0effd62015-07-29 06:37:28 -0700175struct TaggedSrc : public SkAutoTDelete<Src> {
176 const char* tag;
177 const char* options;
178};
179
180struct TaggedSink : public SkAutoTDelete<Sink> {
181 const char* tag;
djsollen54416de2015-04-03 07:24:48 -0700182};
mtklein748ca3b2015-01-15 10:56:12 -0800183
184static const bool kMemcpyOK = true;
185
mtkleine0effd62015-07-29 06:37:28 -0700186static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
187static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800188
mtklein6393c062015-04-27 08:45:01 -0700189static bool in_shard() {
190 static int N = 0;
191 return N++ % FLAGS_shards == FLAGS_shard;
192}
193
djsollen54416de2015-04-03 07:24:48 -0700194static void push_src(const char* tag, const char* options, Src* s) {
mtklein748ca3b2015-01-15 10:56:12 -0800195 SkAutoTDelete<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700196 if (in_shard() &&
197 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800198 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700199 TaggedSrc& s = gSrcs.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800200 s.reset(src.detach());
201 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700202 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800203 }
mtklein748ca3b2015-01-15 10:56:12 -0800204}
mtklein114c3cd2015-01-15 10:15:02 -0800205
msarett438b2ad2015-04-09 12:43:10 -0700206static void push_codec_srcs(Path path) {
207 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
208 if (!encoded) {
209 SkDebugf("Couldn't read %s.", path.c_str());
210 return;
211 }
212 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
213 if (NULL == codec.get()) {
214 SkDebugf("Couldn't create codec for %s.", path.c_str());
215 return;
216 }
217
msarett0a242972015-06-11 14:27:27 -0700218 // Choose scales for scaling tests.
219 // TODO (msarett): Add more scaling tests as we implement more flexible scaling.
220 // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these
221 // tests. SkImageDecoder supports downscales by integer factors.
emmaleer8f4ba762015-08-14 07:44:46 -0700222 // SkJpegCodec natively supports scaling to: 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875
223 // 0.1, 0.16, 0.2 etc allow us to test SkScaledCodec with sampleSize 10, 6, 5, etc
224 // 0.4, 0.7 etc allow to test what happens when the client requests a scale that
225 // does not exactly match a sampleSize or native scaling capability
226 const float scales[] = { 0.1f, 0.125f, 0.166f, 0.2f, 0.25f, 0.333f, 0.375f, 0.4f, 0.5f, 0.6f,
227 0.625f, 0.750f, 0.8f, 0.875f, 1.0f };
msarett438b2ad2015-04-09 12:43:10 -0700228
msarett0a242972015-06-11 14:27:27 -0700229 for (float scale : scales) {
scroggo0df0e432015-08-07 12:53:25 -0700230 if (scale != 1.0f && (path.endsWith(".webp") || path.endsWith(".WEBP"))) {
231 // FIXME: skbug.com/4038 Scaling webp seems to leave some pixels uninitialized/
232 // compute their colors based on uninitialized values.
233 continue;
234 }
msarett0a242972015-06-11 14:27:27 -0700235 // Build additional test cases for images that decode natively to non-canvas types
236 switch(codec->getInfo().colorType()) {
237 case kGray_8_SkColorType:
238 push_src("image", "codec_kGray8", new CodecSrc(path, CodecSrc::kNormal_Mode,
239 CodecSrc::kGrayscale_Always_DstColorType, scale));
240 push_src("image", "scanline_kGray8", new CodecSrc(path, CodecSrc::kScanline_Mode,
241 CodecSrc::kGrayscale_Always_DstColorType, scale));
242 push_src("image", "scanline_subset_kGray8", new CodecSrc(path,
243 CodecSrc::kScanline_Subset_Mode, CodecSrc::kGrayscale_Always_DstColorType,
244 scale));
245 push_src("image", "stripe_kGray8", new CodecSrc(path, CodecSrc::kStripe_Mode,
246 CodecSrc::kGrayscale_Always_DstColorType, scale));
247 // Intentional fall through
248 // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8?
249 // Further discussion on this topic is at skbug.com/3683
250 case kIndex_8_SkColorType:
251 push_src("image", "codec_kIndex8", new CodecSrc(path, CodecSrc::kNormal_Mode,
252 CodecSrc::kIndex8_Always_DstColorType, scale));
253 push_src("image", "scanline_kIndex8", new CodecSrc(path, CodecSrc::kScanline_Mode,
254 CodecSrc::kIndex8_Always_DstColorType, scale));
255 push_src("image", "scanline_subset_kIndex8", new CodecSrc(path,
256 CodecSrc::kScanline_Subset_Mode, CodecSrc::kIndex8_Always_DstColorType,
257 scale));
258 push_src("image", "stripe_kIndex8", new CodecSrc(path, CodecSrc::kStripe_Mode,
259 CodecSrc::kIndex8_Always_DstColorType, scale));
260 break;
261 default:
262 // Do nothing
263 break;
264 }
265
266 // Decode all images to the canvas color type
267 push_src("image", "codec", new CodecSrc(path, CodecSrc::kNormal_Mode,
268 CodecSrc::kGetFromCanvas_DstColorType, scale));
269 push_src("image", "scanline", new CodecSrc(path, CodecSrc::kScanline_Mode,
270 CodecSrc::kGetFromCanvas_DstColorType, scale));
271 push_src("image", "scanline_subset", new CodecSrc(path, CodecSrc::kScanline_Subset_Mode,
272 CodecSrc::kGetFromCanvas_DstColorType, scale));
273 push_src("image", "stripe", new CodecSrc(path, CodecSrc::kStripe_Mode,
274 CodecSrc::kGetFromCanvas_DstColorType, scale));
scroggob636b452015-07-22 07:16:20 -0700275 // Note: The only codec which supports subsets natively is SkWebpCodec, which will never
276 // report kIndex_8 or kGray_8, so there is no need to test kSubset_mode with those color
277 // types specifically requested.
278 push_src("image", "codec_subset", new CodecSrc(path, CodecSrc::kSubset_Mode,
279 CodecSrc::kGetFromCanvas_DstColorType, scale));
msarett0a242972015-06-11 14:27:27 -0700280 }
msarett438b2ad2015-04-09 12:43:10 -0700281}
282
scroggo9b77ddd2015-03-19 06:03:39 -0700283static bool codec_supported(const char* ext) {
284 // FIXME: Once other versions of SkCodec are available, we can add them to this
285 // list (and eventually we can remove this check once they are all supported).
msarett8c8f22a2015-04-01 06:58:48 -0700286 static const char* const exts[] = {
scroggo6f5e6192015-06-18 12:53:43 -0700287 "bmp", "gif", "jpg", "jpeg", "png", "ico", "wbmp", "webp",
288 "BMP", "GIF", "JPG", "JPEG", "PNG", "ICO", "WBMP", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700289 };
290
291 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
292 if (0 == strcmp(exts[i], ext)) {
293 return true;
294 }
295 }
296 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700297}
298
mtklein748ca3b2015-01-15 10:56:12 -0800299static void gather_srcs() {
300 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700301 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800302 }
halcanaryfc37ad12015-01-30 07:31:19 -0800303 for (int i = 0; i < FLAGS_skps.count(); i++) {
304 const char* path = FLAGS_skps[i];
305 if (sk_isdir(path)) {
306 SkOSFile::Iter it(path, "skp");
307 for (SkString file; it.next(&file); ) {
djsollen54416de2015-04-03 07:24:48 -0700308 push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str())));
halcanaryfc37ad12015-01-30 07:31:19 -0800309 }
310 } else {
djsollen54416de2015-04-03 07:24:48 -0700311 push_src("skp", "", new SKPSrc(path));
mtklein114c3cd2015-01-15 10:15:02 -0800312 }
313 }
halcanary23b03c32015-01-30 09:58:58 -0800314 static const char* const exts[] = {
315 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
316 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
317 };
318 for (int i = 0; i < FLAGS_images.count(); i++) {
319 const char* flag = FLAGS_images[i];
320 if (sk_isdir(flag)) {
321 for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) {
322 SkOSFile::Iter it(flag, exts[j]);
323 for (SkString file; it.next(&file); ) {
324 SkString path = SkOSPath::Join(flag, file.c_str());
djsollen54416de2015-04-03 07:24:48 -0700325 push_src("image", "decode", new ImageSrc(path)); // Decode entire image
326 push_src("image", "subset", new ImageSrc(path, 2)); // Decode into 2x2 subsets
scroggo9b77ddd2015-03-19 06:03:39 -0700327 if (codec_supported(exts[j])) {
msarett438b2ad2015-04-09 12:43:10 -0700328 push_codec_srcs(path);
scroggo9b77ddd2015-03-19 06:03:39 -0700329 }
halcanary23b03c32015-01-30 09:58:58 -0800330 }
mtklein114c3cd2015-01-15 10:15:02 -0800331 }
halcanary23b03c32015-01-30 09:58:58 -0800332 } else if (sk_exists(flag)) {
333 // assume that FLAGS_images[i] is a valid image if it is a file.
djsollen54416de2015-04-03 07:24:48 -0700334 push_src("image", "decode", new ImageSrc(flag)); // Decode entire image.
335 push_src("image", "subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subsets
msarett438b2ad2015-04-09 12:43:10 -0700336 push_codec_srcs(flag);
mtklein709d2c32015-01-15 08:30:25 -0800337 }
mtklein709d2c32015-01-15 08:30:25 -0800338 }
339}
340
mtklein748ca3b2015-01-15 10:56:12 -0800341static GrGLStandard get_gpu_api() {
342 if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; }
343 if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; }
344 return kNone_GrGLStandard;
mtklein709d2c32015-01-15 08:30:25 -0800345}
346
mtklein748ca3b2015-01-15 10:56:12 -0800347static void push_sink(const char* tag, Sink* s) {
348 SkAutoTDelete<Sink> sink(s);
349 if (!FLAGS_config.contains(tag)) {
350 return;
mtklein114c3cd2015-01-15 10:15:02 -0800351 }
mtkleine0effd62015-07-29 06:37:28 -0700352 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800353 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700354 Error draw(SkCanvas* c) const override {
355 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
356 return "";
357 }
mtklein36352bf2015-03-25 18:17:31 -0700358 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700359 Name name() const override { return "justOneRect"; }
360 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800361
mtklein748ca3b2015-01-15 10:56:12 -0800362 SkBitmap bitmap;
363 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800364 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700365 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800366 if (err.isFatal()) {
mtklein05641a52015-04-21 10:49:13 -0700367 SkDebugf("Could not run %s: %s\n", tag, err.c_str());
368 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800369 }
370
mtkleine0effd62015-07-29 06:37:28 -0700371 TaggedSink& ts = gSinks.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800372 ts.reset(sink.detach());
373 ts.tag = tag;
374}
375
376static bool gpu_supported() {
377#if SK_SUPPORT_GPU
378 return FLAGS_gpu;
379#else
380 return false;
381#endif
382}
383
384static Sink* create_sink(const char* tag) {
385#define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); }
386 if (gpu_supported()) {
mtklein82d28432015-01-15 12:46:02 -0800387 typedef GrContextFactory Gr;
mtklein748ca3b2015-01-15 10:56:12 -0800388 const GrGLStandard api = get_gpu_api();
mtklein82d28432015-01-15 12:46:02 -0800389 SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading);
390 SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading);
391 SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading);
392 SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading);
393 SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading);
394 SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading);
395 SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading);
396 SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800397 #if SK_ANGLE
mtklein82d28432015-01-15 12:46:02 -0800398 SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800399 #endif
400 #if SK_MESA
mtklein82d28432015-01-15 12:46:02 -0800401 SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800402 #endif
mtklein114c3cd2015-01-15 10:15:02 -0800403 }
mtklein748ca3b2015-01-15 10:56:12 -0800404
tomhudsoneebc39a2015-02-23 12:18:05 -0800405#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
406 SINK("hwui", HWUISink);
407#endif
408
mtklein748ca3b2015-01-15 10:56:12 -0800409 if (FLAGS_cpu) {
410 SINK("565", RasterSink, kRGB_565_SkColorType);
411 SINK("8888", RasterSink, kN32_SkColorType);
mtklein19f30602015-01-20 13:34:39 -0800412 SINK("pdf", PDFSink);
mtklein9c3f17d2015-01-28 11:35:18 -0800413 SINK("skp", SKPSink);
mtklein8a4527e2015-01-31 20:00:58 -0800414 SINK("svg", SVGSink);
415 SINK("null", NullSink);
halcanary47ef4d52015-03-03 09:13:09 -0800416 SINK("xps", XPSSink);
mtklein748ca3b2015-01-15 10:56:12 -0800417 }
418#undef SINK
419 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800420}
421
mtklein748ca3b2015-01-15 10:56:12 -0800422static Sink* create_via(const char* tag, Sink* wrapped) {
423#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); }
mtklein6fbf4b32015-05-06 11:35:40 -0700424 VIA("twice", ViaTwice, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800425 VIA("pipe", ViaPipe, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800426 VIA("serialize", ViaSerialization, wrapped);
mtkleinb7e8d692015-04-07 08:30:32 -0700427 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700428 VIA("sp", ViaSingletonPictures, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800429 VIA("tiles", ViaTiles, 256, 256, NULL, wrapped);
430 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800431
mtkleind603b222015-02-17 11:13:33 -0800432 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800433 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800434 m.reset();
435 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
436 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
437 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
438 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
439 VIA("matrix", ViaMatrix, m, wrapped);
440 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800441 }
tomhudson64de1e12015-03-05 08:01:07 -0800442
443#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
444 VIA("androidsdk", ViaAndroidSDK, wrapped);
445#endif
446
mtklein748ca3b2015-01-15 10:56:12 -0800447#undef VIA
448 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800449}
450
mtklein748ca3b2015-01-15 10:56:12 -0800451static void gather_sinks() {
452 for (int i = 0; i < FLAGS_config.count(); i++) {
453 const char* config = FLAGS_config[i];
454 SkTArray<SkString> parts;
455 SkStrSplit(config, "-", &parts);
456
457 Sink* sink = NULL;
458 for (int i = parts.count(); i-- > 0;) {
459 const char* part = parts[i].c_str();
460 Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink);
461 if (next == NULL) {
462 SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part);
463 delete sink;
464 sink = NULL;
465 break;
466 }
467 sink = next;
468 }
469 if (sink) {
470 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800471 }
472 }
473}
mtklein709d2c32015-01-15 08:30:25 -0800474
mtkleina5114d72015-08-24 13:27:01 -0700475static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
476 const int w = bitmap.width(),
477 h = bitmap.height();
478
479 // First get the bitmap into N32 color format. The next step will work only there.
480 if (bitmap.colorType() != kN32_SkColorType) {
481 SkBitmap n32;
482 if (!bitmap.copyTo(&n32, kN32_SkColorType)) {
483 return false;
484 }
485 bitmap = n32;
486 }
487
488 // Convert our N32 bitmap into unpremul RGBA for libpng.
489 SkAutoTMalloc<uint32_t> rgba(w*h);
490 if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType),
491 rgba, 4*w, 0,0)) {
492 return false;
493 }
494
495 // We don't need bitmap anymore. Might as well drop our ref.
496 bitmap = SkBitmap();
497
498 FILE* f = fopen(path, "w");
499 if (!f) { return false; }
500
501 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
502 if (!png) {
503 fclose(f);
504 return false;
505 }
506
507 png_infop info = png_create_info_struct(png);
508 if (!info) {
509 png_destroy_write_struct(&png, &info);
510 fclose(f);
511 return false;
512 }
513
514 png_text text[2];
515 text[0].key = (png_charp)"Author";
516 text[0].text = (png_charp)"DM dump_png()";
517 text[0].compression = PNG_TEXT_COMPRESSION_NONE;
518 text[1].key = (png_charp)"Description";
519 text[1].text = (png_charp)md5;
520 text[1].compression = PNG_TEXT_COMPRESSION_NONE;
521 png_set_text(png, info, text, 2);
522
523 png_init_io(png, f);
524 png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8,
525 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
526 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
527 png_write_info(png, info);
528 for (int j = 0; j < h; j++) {
529 png_bytep row = (png_bytep)(rgba.get() + w*j);
530 png_write_rows(png, &row, 1);
531 }
532 png_write_end(png, info);
533
534 png_destroy_write_struct(&png, &info);
535 fclose(f);
536 return true;
537}
538
mtkleina2ef6422015-01-15 13:44:22 -0800539static bool match(const char* needle, const char* haystack) {
540 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle);
541}
542
djsollen54416de2015-04-03 07:24:48 -0700543static ImplicitString is_blacklisted(const char* sink, const char* src,
544 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -0700545 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -0800546 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -0700547 match(FLAGS_blacklist[i+1], src) &&
548 match(FLAGS_blacklist[i+2], srcOptions) &&
549 match(FLAGS_blacklist[i+3], name)) {
550 return SkStringPrintf("%s %s %s %s",
551 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1],
552 FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]);
mtkleina2ef6422015-01-15 13:44:22 -0800553 }
554 }
555 return "";
556}
557
mtklein748ca3b2015-01-15 10:56:12 -0800558// The finest-grained unit of work we can run: draw a single Src into a single Sink,
559// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
560struct Task {
mtkleine0effd62015-07-29 06:37:28 -0700561 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
562 const TaggedSrc& src;
563 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -0800564
565 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800566 SkString name = task->src->name();
mtkleine0effd62015-07-29 06:37:28 -0700567
568 // We'll skip drawing this Src/Sink pair if:
569 // - the Src vetoes the Sink;
570 // - this Src / Sink combination is on the blacklist;
571 // - it's a dry run.
mtklein99cab4e2015-07-31 06:43:04 -0700572 SkString note(task->src->veto(task->sink->flags()) ? " (veto)" : "");
djsollen54416de2015-04-03 07:24:48 -0700573 SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag,
574 task->src.options, name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700575 if (!whyBlacklisted.isEmpty()) {
576 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
577 }
mtkleine0effd62015-07-29 06:37:28 -0700578
mtkleinb9eb4ac2015-02-02 18:26:03 -0800579 SkString log;
mtklein748ca3b2015-01-15 10:56:12 -0800580 WallTimer timer;
581 timer.start();
mtkleine0effd62015-07-29 06:37:28 -0700582 if (!FLAGS_dryRun && note.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800583 SkBitmap bitmap;
584 SkDynamicMemoryWStream stream;
bsalomon821e10e2015-06-04 14:15:33 -0700585 if (FLAGS_pre_log) {
586 SkDebugf("\nRunning %s->%s", name.c_str(), task->sink.tag);
587 }
djsollen54416de2015-04-03 07:24:48 -0700588 start(task->sink.tag, task->src.tag, task->src.options, name.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800589 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
mtklein748ca3b2015-01-15 10:56:12 -0800590 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -0800591 timer.end();
592 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -0700593 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein4089ef72015-03-05 08:40:28 -0800594 task->sink.tag,
595 task->src.tag,
djsollen54416de2015-04-03 07:24:48 -0700596 task->src.options,
mtklein4089ef72015-03-05 08:40:28 -0800597 name.c_str(),
598 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -0700599 } else {
600 note.appendf(" (skipped: %s)", err.c_str());
mtklein4089ef72015-03-05 08:40:28 -0800601 }
djsollen54416de2015-04-03 07:24:48 -0700602 done(timer.fWall, task->sink.tag, task->src.tag, task->src.options,
603 name, note, log);
mtklein4089ef72015-03-05 08:40:28 -0800604 return;
mtklein748ca3b2015-01-15 10:56:12 -0800605 }
mtklein62bd1a62015-01-27 14:46:26 -0800606 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
607
608 SkString md5;
609 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
610 SkMD5 hash;
611 if (data->getLength()) {
612 hash.writeStream(data, data->getLength());
613 data->rewind();
614 } else {
mtklein38408462015-07-08 07:25:27 -0700615 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
616 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
617 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
618 // We might consider promoting 565 to RGBA too.
619 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
620 SkBitmap swizzle;
621 SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
622 hash.write(swizzle.getPixels(), swizzle.getSize());
623 } else {
624 hash.write(bitmap.getPixels(), bitmap.getSize());
625 }
mtklein62bd1a62015-01-27 14:46:26 -0800626 }
627 SkMD5::Digest digest;
628 hash.finish(digest);
629 for (int i = 0; i < 16; i++) {
630 md5.appendf("%02x", digest.data[i]);
631 }
632 }
633
634 if (!FLAGS_readPath.isEmpty() &&
djsollen54416de2015-04-03 07:24:48 -0700635 !gGold.contains(Gold(task->sink.tag, task->src.tag,
636 task->src.options, name, md5))) {
637 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
mtklein62bd1a62015-01-27 14:46:26 -0800638 md5.c_str(),
639 task->sink.tag,
640 task->src.tag,
djsollen54416de2015-04-03 07:24:48 -0700641 task->src.options,
mtklein62bd1a62015-01-27 14:46:26 -0800642 name.c_str(),
643 FLAGS_readPath[0]));
644 }
645
mtkleinb0531a72015-04-07 13:38:48 -0700646 if (!FLAGS_writePath.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800647 const char* ext = task->sink->fileExtension();
mtklein62bd1a62015-01-27 14:46:26 -0800648 if (data->getLength()) {
649 WriteToDisk(*task, md5, ext, data, data->getLength(), NULL);
halcanary022afb82015-01-30 11:00:12 -0800650 SkASSERT(bitmap.drawsNothing());
651 } else if (!bitmap.drawsNothing()) {
mtklein62bd1a62015-01-27 14:46:26 -0800652 WriteToDisk(*task, md5, ext, NULL, 0, &bitmap);
mtklein748ca3b2015-01-15 10:56:12 -0800653 }
654 }
655 }
656 timer.end();
djsollen54416de2015-04-03 07:24:48 -0700657 done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, name, note, log);
mtklein748ca3b2015-01-15 10:56:12 -0800658 }
659
660 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -0800661 SkString md5,
662 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -0800663 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -0800664 const SkBitmap* bitmap) {
mtklein748ca3b2015-01-15 10:56:12 -0800665 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -0700666 result.name = task.src->name();
667 result.config = task.sink.tag;
668 result.sourceType = task.src.tag;
669 result.sourceOptions = task.src.options;
670 result.ext = ext;
671 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -0800672 JsonWriter::AddBitmapResult(result);
673
mtkleinb0531a72015-04-07 13:38:48 -0700674 // If an MD5 is uninteresting, we want it noted in the JSON file,
675 // but don't want to dump it out as a .png (or whatever ext is).
676 if (gUninterestingHashes.contains(md5)) {
677 return;
678 }
679
mtklein748ca3b2015-01-15 10:56:12 -0800680 const char* dir = FLAGS_writePath[0];
681 if (0 == strcmp(dir, "@")) { // Needed for iOS.
682 dir = FLAGS_resourcePath[0];
683 }
684 sk_mkdir(dir);
685
686 SkString path;
687 if (FLAGS_nameByHash) {
688 path = SkOSPath::Join(dir, result.md5.c_str());
689 path.append(".");
690 path.append(ext);
691 if (sk_exists(path.c_str())) {
692 return; // Content-addressed. If it exists already, we're done.
693 }
694 } else {
695 path = SkOSPath::Join(dir, task.sink.tag);
696 sk_mkdir(path.c_str());
697 path = SkOSPath::Join(path.c_str(), task.src.tag);
698 sk_mkdir(path.c_str());
djsollen54416de2015-04-03 07:24:48 -0700699 if (strcmp(task.src.options, "") != 0) {
700 path = SkOSPath::Join(path.c_str(), task.src.options);
701 sk_mkdir(path.c_str());
702 }
mtklein748ca3b2015-01-15 10:56:12 -0800703 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
704 path.append(".");
705 path.append(ext);
706 }
707
mtklein748ca3b2015-01-15 10:56:12 -0800708 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -0700709 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -0800710 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
711 return;
712 }
713 } else {
mtkleina5114d72015-08-24 13:27:01 -0700714 SkFILEWStream file(path.c_str());
715 if (!file.isValid()) {
716 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
717 return;
718 }
mtklein748ca3b2015-01-15 10:56:12 -0800719 if (!file.writeStream(data, len)) {
720 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
721 return;
722 }
723 }
724 }
725};
726
727// Run all tasks in the same enclave serially on the same thread.
728// They can't possibly run concurrently with each other.
729static void run_enclave(SkTArray<Task>* tasks) {
730 for (int i = 0; i < tasks->count(); i++) {
731 Task::Run(tasks->begin() + i);
732 }
733}
734
735/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
736
737// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
738
mtklein55e88b22015-01-21 15:50:13 -0800739static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800740
741static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -0800742 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -0800743 return;
744 }
mtklein6393c062015-04-27 08:45:01 -0700745 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
746 if (!in_shard()) {
747 continue;
748 }
halcanary87f3ba42015-01-20 09:30:20 -0800749 // Despite its name, factory() is returning a reference to
750 // link-time static const POD data.
751 const skiatest::Test& test = r->factory();
752 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800753 continue;
754 }
halcanary87f3ba42015-01-20 09:30:20 -0800755 if (test.needsGpu && gpu_supported()) {
mtklein55e88b22015-01-21 15:50:13 -0800756 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -0800757 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -0800758 gThreadedTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800759 }
mtklein748ca3b2015-01-15 10:56:12 -0800760 }
761}
762
halcanary87f3ba42015-01-20 09:30:20 -0800763static void run_test(skiatest::Test* test) {
764 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -0700765 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -0800766 fail(failure.toString());
767 JsonWriter::AddTestFailure(failure);
768 }
mtklein36352bf2015-03-25 18:17:31 -0700769 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -0800770 return FLAGS_pathOpsExtended;
771 }
mtklein36352bf2015-03-25 18:17:31 -0700772 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -0800773 } reporter;
djsollen824996a2015-06-12 12:06:22 -0700774
775 SkString note;
776 SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test->name);
777 if (!whyBlacklisted.isEmpty()) {
778 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
779 }
780
mtklein748ca3b2015-01-15 10:56:12 -0800781 WallTimer timer;
782 timer.start();
djsollen824996a2015-06-12 12:06:22 -0700783 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
djsollen54416de2015-04-03 07:24:48 -0700784 start("unit", "test", "", test->name);
mtklein55e88b22015-01-21 15:50:13 -0800785 GrContextFactory factory;
bsalomon821e10e2015-06-04 14:15:33 -0700786 if (FLAGS_pre_log) {
787 SkDebugf("\nRunning test %s", test->name);
788 }
mtklein55e88b22015-01-21 15:50:13 -0800789 test->proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -0800790 }
791 timer.end();
djsollen824996a2015-06-12 12:06:22 -0700792 done(timer.fWall, "unit", "test", "", test->name, note, "");
mtklein748ca3b2015-01-15 10:56:12 -0800793}
794
795/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
796
mtklein55e88b22015-01-21 15:50:13 -0800797// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
798static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
799 run_enclave(tasks);
800 for (int i = 0; i < gGPUTests.count(); i++) {
801 run_test(&gGPUTests[i]);
802 }
803}
804
mtkleinde6fc2b2015-03-12 06:28:54 -0700805// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
806// This prints something every once in a while so that it knows we're still working.
mtklein2e1c47e2015-03-12 07:16:56 -0700807static void start_keepalive() {
808 struct Loop {
809 static void forever(void*) {
810 for (;;) {
811 static const int kSec = 300;
812 #if defined(SK_BUILD_FOR_WIN)
813 Sleep(kSec * 1000);
814 #else
815 sleep(kSec);
816 #endif
mtkleinb37cb412015-03-18 05:27:14 -0700817 SkString running;
818 {
819 SkAutoMutexAcquire lock(gRunningMutex);
820 for (int i = 0; i < gRunning.count(); i++) {
821 running.appendf("\n\t%s", gRunning[i].c_str());
822 }
823 }
824 SkDebugf("\nCurrently running:%s\n", running.c_str());
mtklein2e1c47e2015-03-12 07:16:56 -0700825 }
826 }
827 };
828 static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
829 intentionallyLeaked->start();
mtkleinde6fc2b2015-03-12 06:28:54 -0700830}
831
caryclark83ca6282015-06-10 09:31:09 -0700832#define PORTABLE_FONT_PREFIX "Toy Liberation "
833
834static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
835 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
836 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -0700837 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -0700838 }
839 return NULL;
840}
841
842#undef PORTABLE_FONT_PREFIX
843
844extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
845
jcgregorio3b27ade2014-11-13 08:06:40 -0800846int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700847int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800848 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000849 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700850 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -0700851 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000852
mtklein2e1c47e2015-03-12 07:16:56 -0700853 start_keepalive();
mtkleinde6fc2b2015-03-12 06:28:54 -0700854
mtklein62bd1a62015-01-27 14:46:26 -0800855 gather_gold();
borenet09ed4802015-04-03 14:15:33 -0700856 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -0800857
mtklein748ca3b2015-01-15 10:56:12 -0800858 gather_srcs();
859 gather_sinks();
860 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000861
mtklein55e88b22015-01-21 15:50:13 -0800862 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -0800863 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -0800864 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -0800865
866 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
867 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -0800868 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -0800869 SkTArray<Task> enclaves[kNumEnclaves];
870 for (int j = 0; j < gSinks.count(); j++) {
871 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
872 for (int i = 0; i < gSrcs.count(); i++) {
873 tasks.push_back(Task(gSrcs[i], gSinks[j]));
874 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000875 }
876
mtklein748ca3b2015-01-15 10:56:12 -0800877 SkTaskGroup tg;
mtklein55e88b22015-01-21 15:50:13 -0800878 tg.batch(run_test, gThreadedTests.begin(), gThreadedTests.count());
879 for (int i = 0; i < kNumEnclaves; i++) {
880 switch(i) {
881 case kAnyThread_Enclave:
882 tg.batch(Task::Run, enclaves[i].begin(), enclaves[i].count());
883 break;
884 case kGPU_Enclave:
885 tg.add(run_enclave_and_gpu_tests, &enclaves[i]);
886 break;
887 default:
888 tg.add(run_enclave, &enclaves[i]);
889 break;
mtklein82d28432015-01-15 12:46:02 -0800890 }
mtklein55e88b22015-01-21 15:50:13 -0800891 }
mtklein748ca3b2015-01-15 10:56:12 -0800892 tg.wait();
mtklein748ca3b2015-01-15 10:56:12 -0800893 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -0700894 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +0000895
mtklein2f64eec2015-01-15 14:20:41 -0800896 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -0800897 if (gFailures.count() > 0) {
898 SkDebugf("Failures:\n");
899 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -0800900 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800901 }
902 SkDebugf("%d failures\n", gFailures.count());
903 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800904 }
mtklein748ca3b2015-01-15 10:56:12 -0800905 if (gPending > 0) {
906 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
907 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800908 }
mtklein748ca3b2015-01-15 10:56:12 -0800909 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000910}
jcgregorio3b27ade2014-11-13 08:06:40 -0800911
borenet48087572015-04-02 12:16:36 -0700912#if !defined(SK_BUILD_FOR_IOS)
jcgregorio3b27ade2014-11-13 08:06:40 -0800913int main(int argc, char** argv) {
914 SkCommandLineFlags::Parse(argc, argv);
915 return dm_main();
916}
917#endif