blob: df16182072e200078466011129bab3b18d4c3cf6 [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"
caryclark17f0b6d2014-07-22 10:15:34 -070016#include "SkCommonFlags.h"
caryclark83ca6282015-06-10 09:31:09 -070017#include "SkFontMgr.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000018#include "SkForceLinking.h"
19#include "SkGraphics.h"
mtklein748ca3b2015-01-15 10:56:12 -080020#include "SkMD5.h"
mtklein1b249332015-07-07 12:21:21 -070021#include "SkMutex.h"
mtklein1d0f1642014-09-08 08:05:18 -070022#include "SkOSFile.h"
mtkleina82f5622015-02-20 12:30:19 -080023#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070024#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070025#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000026#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080027#include "Timer.h"
caryclark83ca6282015-06-10 09:31:09 -070028#include "sk_tool_utils.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000029
djsollen54416de2015-04-03 07:24:48 -070030DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080031DEFINE_bool(nameByHash, false,
32 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070033 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080034DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080035DEFINE_string(matrix, "1 0 0 1",
36 "2x2 scale+skew matrix to apply or upright when using "
37 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080038DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000039
mtkleina2ef6422015-01-15 13:44:22 -080040DEFINE_string(blacklist, "",
djsollen54416de2015-04-03 07:24:48 -070041 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n"
42 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
43 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.");
mtkleina2ef6422015-01-15 13:44:22 -080044
mtklein62bd1a62015-01-27 14:46:26 -080045DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
46
borenet09ed4802015-04-03 14:15:33 -070047DEFINE_string(uninterestingHashesFile, "",
48 "File containing a list of uninteresting hashes. If a result hashes to something in "
49 "this list, no image is written for that result.");
50
mtklein6393c062015-04-27 08:45:01 -070051DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
52DEFINE_int32(shard, 0, "Which shard do I run?");
bsalomon821e10e2015-06-04 14:15:33 -070053DEFINE_bool2(pre_log, p, false, "Log before running each test. May be incomprehensible when threading");
mtklein6393c062015-04-27 08:45:01 -070054
mtklein@google.comd36522d2013-10-16 13:02:15 +000055__SK_FORCE_IMAGE_DECODER_LINKING;
mtklein748ca3b2015-01-15 10:56:12 -080056using namespace DM;
mtklein@google.comd36522d2013-10-16 13:02:15 +000057
mtklein748ca3b2015-01-15 10:56:12 -080058/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
59
60SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
61static SkTArray<SkString> gFailures;
62
63static void fail(ImplicitString err) {
64 SkAutoMutexAcquire lock(gFailuresMutex);
65 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
66 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -080067}
68
mtkleinb37cb412015-03-18 05:27:14 -070069static int32_t gPending = 0; // Atomic. Total number of running and queued tasks.
70
71SK_DECLARE_STATIC_MUTEX(gRunningMutex);
72static SkTArray<SkString> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -080073
mtkleinb9eb4ac2015-02-02 18:26:03 -080074static void done(double ms,
djsollen54416de2015-04-03 07:24:48 -070075 ImplicitString config, ImplicitString src, ImplicitString srcOptions,
76 ImplicitString name, ImplicitString note, ImplicitString log) {
77 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
78 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -070079 {
80 SkAutoMutexAcquire lock(gRunningMutex);
81 for (int i = 0; i < gRunning.count(); i++) {
82 if (gRunning[i] == id) {
83 gRunning.removeShuffle(i);
84 break;
85 }
86 }
87 }
88 if (!FLAGS_verbose) {
89 note = "";
90 }
mtkleinb9eb4ac2015-02-02 18:26:03 -080091 if (!log.isEmpty()) {
92 log.prepend("\n");
93 }
mtklein6dee2ad2015-02-05 09:53:44 -080094 auto pending = sk_atomic_dec(&gPending)-1;
reed50bc0512015-05-19 14:13:31 -070095 if (!FLAGS_quiet) {
mtklein711a2452015-07-08 08:49:20 -070096 SkDebugf("%s(%4d/%-4dMB %6d) %s\t%s%s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine
reed50bc0512015-05-19 14:13:31 -070097 , sk_tools::getCurrResidentSetSizeMB()
98 , sk_tools::getMaxResidentSetSizeMB()
99 , pending
100 , HumanizeMs(ms).c_str()
101 , id.c_str()
102 , note.c_str()
103 , log.c_str());
104 }
mtkleina17241b2015-01-23 05:48:00 -0800105 // We write our dm.json file every once in a while in case we crash.
106 // Notice this also handles the final dm.json when pending == 0.
107 if (pending % 500 == 0) {
108 JsonWriter::DumpJson();
109 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000110}
111
djsollen54416de2015-04-03 07:24:48 -0700112static void start(ImplicitString config, ImplicitString src,
113 ImplicitString srcOptions, ImplicitString name) {
114 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
115 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700116 SkAutoMutexAcquire lock(gRunningMutex);
117 gRunning.push_back(id);
118}
119
mtklein748ca3b2015-01-15 10:56:12 -0800120/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800121
mtklein62bd1a62015-01-27 14:46:26 -0800122struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800123 Gold() : SkString("") {}
djsollen54416de2015-04-03 07:24:48 -0700124 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions,
125 ImplicitString name, ImplicitString md5)
mtklein62bd1a62015-01-27 14:46:26 -0800126 : SkString("") {
127 this->append(sink);
128 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700129 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800130 this->append(name);
131 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800132 }
mtklein02f46cf2015-03-20 13:48:42 -0700133 static uint32_t Hash(const Gold& g) { return SkGoodHash((const SkString&)g); }
mtklein62bd1a62015-01-27 14:46:26 -0800134};
mtkleina82f5622015-02-20 12:30:19 -0800135static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800136
137static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700138 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800139}
140
141static void gather_gold() {
142 if (!FLAGS_readPath.isEmpty()) {
143 SkString path(FLAGS_readPath[0]);
144 path.append("/dm.json");
145 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
146 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
147 }
148 }
149}
150
151/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
152
borenet09ed4802015-04-03 14:15:33 -0700153static SkTHashSet<SkString> gUninterestingHashes;
154
155static void gather_uninteresting_hashes() {
156 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
157 SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0]));
158 SkTArray<SkString> hashes;
159 SkStrSplit((const char*)data->data(), "\n", &hashes);
160 for (const SkString& hash : hashes) {
161 gUninterestingHashes.add(hash);
162 }
163 }
164}
165
166/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
167
mtklein748ca3b2015-01-15 10:56:12 -0800168template <typename T>
djsollen54416de2015-04-03 07:24:48 -0700169struct Tagged : public SkAutoTDelete<T> {
170 const char* tag;
171 const char* options;
172};
mtklein748ca3b2015-01-15 10:56:12 -0800173
174static const bool kMemcpyOK = true;
175
176static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs;
177static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks;
178
mtklein6393c062015-04-27 08:45:01 -0700179static bool in_shard() {
180 static int N = 0;
181 return N++ % FLAGS_shards == FLAGS_shard;
182}
183
djsollen54416de2015-04-03 07:24:48 -0700184static void push_src(const char* tag, const char* options, Src* s) {
mtklein748ca3b2015-01-15 10:56:12 -0800185 SkAutoTDelete<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700186 if (in_shard() &&
187 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800188 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
189 Tagged<Src>& s = gSrcs.push_back();
190 s.reset(src.detach());
191 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700192 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800193 }
mtklein748ca3b2015-01-15 10:56:12 -0800194}
mtklein114c3cd2015-01-15 10:15:02 -0800195
msarett438b2ad2015-04-09 12:43:10 -0700196static void push_codec_srcs(Path path) {
197 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
198 if (!encoded) {
199 SkDebugf("Couldn't read %s.", path.c_str());
200 return;
201 }
202 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
203 if (NULL == codec.get()) {
204 SkDebugf("Couldn't create codec for %s.", path.c_str());
205 return;
206 }
207
msarett0a242972015-06-11 14:27:27 -0700208 // Choose scales for scaling tests.
209 // TODO (msarett): Add more scaling tests as we implement more flexible scaling.
210 // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these
211 // tests. SkImageDecoder supports downscales by integer factors.
msarett1c8a5872015-07-07 08:50:01 -0700212 const float scales[] = { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f, 1.0f };
msarett438b2ad2015-04-09 12:43:10 -0700213
msarett0a242972015-06-11 14:27:27 -0700214 for (float scale : scales) {
215 // Build additional test cases for images that decode natively to non-canvas types
216 switch(codec->getInfo().colorType()) {
217 case kGray_8_SkColorType:
218 push_src("image", "codec_kGray8", new CodecSrc(path, CodecSrc::kNormal_Mode,
219 CodecSrc::kGrayscale_Always_DstColorType, scale));
220 push_src("image", "scanline_kGray8", new CodecSrc(path, CodecSrc::kScanline_Mode,
221 CodecSrc::kGrayscale_Always_DstColorType, scale));
222 push_src("image", "scanline_subset_kGray8", new CodecSrc(path,
223 CodecSrc::kScanline_Subset_Mode, CodecSrc::kGrayscale_Always_DstColorType,
224 scale));
225 push_src("image", "stripe_kGray8", new CodecSrc(path, CodecSrc::kStripe_Mode,
226 CodecSrc::kGrayscale_Always_DstColorType, scale));
227 // Intentional fall through
228 // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8?
229 // Further discussion on this topic is at skbug.com/3683
230 case kIndex_8_SkColorType:
231 push_src("image", "codec_kIndex8", new CodecSrc(path, CodecSrc::kNormal_Mode,
232 CodecSrc::kIndex8_Always_DstColorType, scale));
233 push_src("image", "scanline_kIndex8", new CodecSrc(path, CodecSrc::kScanline_Mode,
234 CodecSrc::kIndex8_Always_DstColorType, scale));
235 push_src("image", "scanline_subset_kIndex8", new CodecSrc(path,
236 CodecSrc::kScanline_Subset_Mode, CodecSrc::kIndex8_Always_DstColorType,
237 scale));
238 push_src("image", "stripe_kIndex8", new CodecSrc(path, CodecSrc::kStripe_Mode,
239 CodecSrc::kIndex8_Always_DstColorType, scale));
240 break;
241 default:
242 // Do nothing
243 break;
244 }
245
246 // Decode all images to the canvas color type
247 push_src("image", "codec", new CodecSrc(path, CodecSrc::kNormal_Mode,
248 CodecSrc::kGetFromCanvas_DstColorType, scale));
249 push_src("image", "scanline", new CodecSrc(path, CodecSrc::kScanline_Mode,
250 CodecSrc::kGetFromCanvas_DstColorType, scale));
251 push_src("image", "scanline_subset", new CodecSrc(path, CodecSrc::kScanline_Subset_Mode,
252 CodecSrc::kGetFromCanvas_DstColorType, scale));
253 push_src("image", "stripe", new CodecSrc(path, CodecSrc::kStripe_Mode,
254 CodecSrc::kGetFromCanvas_DstColorType, scale));
255 }
msarett438b2ad2015-04-09 12:43:10 -0700256}
257
scroggo9b77ddd2015-03-19 06:03:39 -0700258static bool codec_supported(const char* ext) {
259 // FIXME: Once other versions of SkCodec are available, we can add them to this
260 // list (and eventually we can remove this check once they are all supported).
msarett8c8f22a2015-04-01 06:58:48 -0700261 static const char* const exts[] = {
scroggo6f5e6192015-06-18 12:53:43 -0700262 "bmp", "gif", "jpg", "jpeg", "png", "ico", "wbmp", "webp",
263 "BMP", "GIF", "JPG", "JPEG", "PNG", "ICO", "WBMP", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700264 };
265
266 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
267 if (0 == strcmp(exts[i], ext)) {
268 return true;
269 }
270 }
271 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700272}
273
mtklein748ca3b2015-01-15 10:56:12 -0800274static void gather_srcs() {
275 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700276 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800277 }
halcanaryfc37ad12015-01-30 07:31:19 -0800278 for (int i = 0; i < FLAGS_skps.count(); i++) {
279 const char* path = FLAGS_skps[i];
280 if (sk_isdir(path)) {
281 SkOSFile::Iter it(path, "skp");
282 for (SkString file; it.next(&file); ) {
djsollen54416de2015-04-03 07:24:48 -0700283 push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str())));
halcanaryfc37ad12015-01-30 07:31:19 -0800284 }
285 } else {
djsollen54416de2015-04-03 07:24:48 -0700286 push_src("skp", "", new SKPSrc(path));
mtklein114c3cd2015-01-15 10:15:02 -0800287 }
288 }
halcanary23b03c32015-01-30 09:58:58 -0800289 static const char* const exts[] = {
290 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
291 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
292 };
293 for (int i = 0; i < FLAGS_images.count(); i++) {
294 const char* flag = FLAGS_images[i];
295 if (sk_isdir(flag)) {
296 for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) {
297 SkOSFile::Iter it(flag, exts[j]);
298 for (SkString file; it.next(&file); ) {
299 SkString path = SkOSPath::Join(flag, file.c_str());
djsollen54416de2015-04-03 07:24:48 -0700300 push_src("image", "decode", new ImageSrc(path)); // Decode entire image
301 push_src("image", "subset", new ImageSrc(path, 2)); // Decode into 2x2 subsets
scroggo9b77ddd2015-03-19 06:03:39 -0700302 if (codec_supported(exts[j])) {
msarett438b2ad2015-04-09 12:43:10 -0700303 push_codec_srcs(path);
scroggo9b77ddd2015-03-19 06:03:39 -0700304 }
halcanary23b03c32015-01-30 09:58:58 -0800305 }
mtklein114c3cd2015-01-15 10:15:02 -0800306 }
halcanary23b03c32015-01-30 09:58:58 -0800307 } else if (sk_exists(flag)) {
308 // assume that FLAGS_images[i] is a valid image if it is a file.
djsollen54416de2015-04-03 07:24:48 -0700309 push_src("image", "decode", new ImageSrc(flag)); // Decode entire image.
310 push_src("image", "subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subsets
msarett438b2ad2015-04-09 12:43:10 -0700311 push_codec_srcs(flag);
mtklein709d2c32015-01-15 08:30:25 -0800312 }
mtklein709d2c32015-01-15 08:30:25 -0800313 }
314}
315
mtklein748ca3b2015-01-15 10:56:12 -0800316static GrGLStandard get_gpu_api() {
317 if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; }
318 if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; }
319 return kNone_GrGLStandard;
mtklein709d2c32015-01-15 08:30:25 -0800320}
321
mtklein748ca3b2015-01-15 10:56:12 -0800322static void push_sink(const char* tag, Sink* s) {
323 SkAutoTDelete<Sink> sink(s);
324 if (!FLAGS_config.contains(tag)) {
325 return;
mtklein114c3cd2015-01-15 10:15:02 -0800326 }
mtklein748ca3b2015-01-15 10:56:12 -0800327 // Try a noop Src as a canary. If it fails, skip this sink.
328 struct : public Src {
mtklein36352bf2015-03-25 18:17:31 -0700329 Error draw(SkCanvas*) const override { return ""; }
330 SkISize size() const override { return SkISize::Make(16, 16); }
331 Name name() const override { return "noop"; }
mtklein748ca3b2015-01-15 10:56:12 -0800332 } noop;
mtklein114c3cd2015-01-15 10:15:02 -0800333
mtklein748ca3b2015-01-15 10:56:12 -0800334 SkBitmap bitmap;
335 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800336 SkString log;
337 Error err = sink->draw(noop, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800338 if (err.isFatal()) {
mtklein05641a52015-04-21 10:49:13 -0700339 SkDebugf("Could not run %s: %s\n", tag, err.c_str());
340 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800341 }
342
mtklein748ca3b2015-01-15 10:56:12 -0800343 Tagged<Sink>& ts = gSinks.push_back();
344 ts.reset(sink.detach());
345 ts.tag = tag;
346}
347
348static bool gpu_supported() {
349#if SK_SUPPORT_GPU
350 return FLAGS_gpu;
351#else
352 return false;
353#endif
354}
355
356static Sink* create_sink(const char* tag) {
357#define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); }
358 if (gpu_supported()) {
mtklein82d28432015-01-15 12:46:02 -0800359 typedef GrContextFactory Gr;
mtklein748ca3b2015-01-15 10:56:12 -0800360 const GrGLStandard api = get_gpu_api();
mtklein82d28432015-01-15 12:46:02 -0800361 SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading);
362 SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading);
363 SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading);
364 SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading);
365 SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading);
366 SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading);
367 SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading);
368 SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800369 #if SK_ANGLE
mtklein82d28432015-01-15 12:46:02 -0800370 SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800371 #endif
372 #if SK_MESA
mtklein82d28432015-01-15 12:46:02 -0800373 SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800374 #endif
mtklein114c3cd2015-01-15 10:15:02 -0800375 }
mtklein748ca3b2015-01-15 10:56:12 -0800376
tomhudsoneebc39a2015-02-23 12:18:05 -0800377#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
378 SINK("hwui", HWUISink);
379#endif
380
mtklein748ca3b2015-01-15 10:56:12 -0800381 if (FLAGS_cpu) {
382 SINK("565", RasterSink, kRGB_565_SkColorType);
383 SINK("8888", RasterSink, kN32_SkColorType);
mtklein19f30602015-01-20 13:34:39 -0800384 SINK("pdf", PDFSink);
mtklein9c3f17d2015-01-28 11:35:18 -0800385 SINK("skp", SKPSink);
mtklein8a4527e2015-01-31 20:00:58 -0800386 SINK("svg", SVGSink);
387 SINK("null", NullSink);
halcanary47ef4d52015-03-03 09:13:09 -0800388 SINK("xps", XPSSink);
mtklein748ca3b2015-01-15 10:56:12 -0800389 }
390#undef SINK
391 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800392}
393
mtklein748ca3b2015-01-15 10:56:12 -0800394static Sink* create_via(const char* tag, Sink* wrapped) {
395#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); }
mtklein6fbf4b32015-05-06 11:35:40 -0700396 VIA("twice", ViaTwice, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800397 VIA("pipe", ViaPipe, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800398 VIA("serialize", ViaSerialization, wrapped);
reed06a22f62015-05-05 08:11:33 -0700399 VIA("deferred", ViaDeferred, wrapped);
mtkleinb7e8d692015-04-07 08:30:32 -0700400 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700401 VIA("sp", ViaSingletonPictures, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800402 VIA("tiles", ViaTiles, 256, 256, NULL, wrapped);
403 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800404
mtkleind603b222015-02-17 11:13:33 -0800405 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800406 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800407 m.reset();
408 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
409 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
410 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
411 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
412 VIA("matrix", ViaMatrix, m, wrapped);
413 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800414 }
tomhudson64de1e12015-03-05 08:01:07 -0800415
416#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
417 VIA("androidsdk", ViaAndroidSDK, wrapped);
418#endif
419
mtklein748ca3b2015-01-15 10:56:12 -0800420#undef VIA
421 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800422}
423
mtklein748ca3b2015-01-15 10:56:12 -0800424static void gather_sinks() {
425 for (int i = 0; i < FLAGS_config.count(); i++) {
426 const char* config = FLAGS_config[i];
427 SkTArray<SkString> parts;
428 SkStrSplit(config, "-", &parts);
429
430 Sink* sink = NULL;
431 for (int i = parts.count(); i-- > 0;) {
432 const char* part = parts[i].c_str();
433 Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink);
434 if (next == NULL) {
435 SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part);
436 delete sink;
437 sink = NULL;
438 break;
439 }
440 sink = next;
441 }
442 if (sink) {
443 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800444 }
445 }
446}
mtklein709d2c32015-01-15 08:30:25 -0800447
mtkleina2ef6422015-01-15 13:44:22 -0800448static bool match(const char* needle, const char* haystack) {
449 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle);
450}
451
djsollen54416de2015-04-03 07:24:48 -0700452static ImplicitString is_blacklisted(const char* sink, const char* src,
453 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -0700454 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -0800455 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -0700456 match(FLAGS_blacklist[i+1], src) &&
457 match(FLAGS_blacklist[i+2], srcOptions) &&
458 match(FLAGS_blacklist[i+3], name)) {
459 return SkStringPrintf("%s %s %s %s",
460 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1],
461 FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]);
mtkleina2ef6422015-01-15 13:44:22 -0800462 }
463 }
464 return "";
465}
466
mtklein748ca3b2015-01-15 10:56:12 -0800467// The finest-grained unit of work we can run: draw a single Src into a single Sink,
468// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
469struct Task {
470 Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {}
471 const Tagged<Src>& src;
472 const Tagged<Sink>& sink;
473
474 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800475 SkString name = task->src->name();
mtkleinb37cb412015-03-18 05:27:14 -0700476 SkString note;
djsollen54416de2015-04-03 07:24:48 -0700477 SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag,
478 task->src.options, name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700479 if (!whyBlacklisted.isEmpty()) {
480 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
481 }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800482 SkString log;
mtklein748ca3b2015-01-15 10:56:12 -0800483 WallTimer timer;
484 timer.start();
mtkleina2ef6422015-01-15 13:44:22 -0800485 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800486 SkBitmap bitmap;
487 SkDynamicMemoryWStream stream;
bsalomon821e10e2015-06-04 14:15:33 -0700488 if (FLAGS_pre_log) {
489 SkDebugf("\nRunning %s->%s", name.c_str(), task->sink.tag);
490 }
djsollen54416de2015-04-03 07:24:48 -0700491 start(task->sink.tag, task->src.tag, task->src.options, name.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800492 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
mtklein748ca3b2015-01-15 10:56:12 -0800493 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -0800494 timer.end();
495 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -0700496 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein4089ef72015-03-05 08:40:28 -0800497 task->sink.tag,
498 task->src.tag,
djsollen54416de2015-04-03 07:24:48 -0700499 task->src.options,
mtklein4089ef72015-03-05 08:40:28 -0800500 name.c_str(),
501 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -0700502 } else {
503 note.appendf(" (skipped: %s)", err.c_str());
mtklein4089ef72015-03-05 08:40:28 -0800504 }
djsollen54416de2015-04-03 07:24:48 -0700505 done(timer.fWall, task->sink.tag, task->src.tag, task->src.options,
506 name, note, log);
mtklein4089ef72015-03-05 08:40:28 -0800507 return;
mtklein748ca3b2015-01-15 10:56:12 -0800508 }
mtklein62bd1a62015-01-27 14:46:26 -0800509 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
510
511 SkString md5;
512 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
513 SkMD5 hash;
514 if (data->getLength()) {
515 hash.writeStream(data, data->getLength());
516 data->rewind();
517 } else {
mtklein38408462015-07-08 07:25:27 -0700518 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
519 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
520 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
521 // We might consider promoting 565 to RGBA too.
522 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
523 SkBitmap swizzle;
524 SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
525 hash.write(swizzle.getPixels(), swizzle.getSize());
526 } else {
527 hash.write(bitmap.getPixels(), bitmap.getSize());
528 }
mtklein62bd1a62015-01-27 14:46:26 -0800529 }
530 SkMD5::Digest digest;
531 hash.finish(digest);
532 for (int i = 0; i < 16; i++) {
533 md5.appendf("%02x", digest.data[i]);
534 }
535 }
536
537 if (!FLAGS_readPath.isEmpty() &&
djsollen54416de2015-04-03 07:24:48 -0700538 !gGold.contains(Gold(task->sink.tag, task->src.tag,
539 task->src.options, name, md5))) {
540 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
mtklein62bd1a62015-01-27 14:46:26 -0800541 md5.c_str(),
542 task->sink.tag,
543 task->src.tag,
djsollen54416de2015-04-03 07:24:48 -0700544 task->src.options,
mtklein62bd1a62015-01-27 14:46:26 -0800545 name.c_str(),
546 FLAGS_readPath[0]));
547 }
548
mtkleinb0531a72015-04-07 13:38:48 -0700549 if (!FLAGS_writePath.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800550 const char* ext = task->sink->fileExtension();
mtklein62bd1a62015-01-27 14:46:26 -0800551 if (data->getLength()) {
552 WriteToDisk(*task, md5, ext, data, data->getLength(), NULL);
halcanary022afb82015-01-30 11:00:12 -0800553 SkASSERT(bitmap.drawsNothing());
554 } else if (!bitmap.drawsNothing()) {
mtklein62bd1a62015-01-27 14:46:26 -0800555 WriteToDisk(*task, md5, ext, NULL, 0, &bitmap);
mtklein748ca3b2015-01-15 10:56:12 -0800556 }
557 }
558 }
559 timer.end();
djsollen54416de2015-04-03 07:24:48 -0700560 done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, name, note, log);
mtklein748ca3b2015-01-15 10:56:12 -0800561 }
562
563 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -0800564 SkString md5,
565 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -0800566 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -0800567 const SkBitmap* bitmap) {
mtklein748ca3b2015-01-15 10:56:12 -0800568 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -0700569 result.name = task.src->name();
570 result.config = task.sink.tag;
571 result.sourceType = task.src.tag;
572 result.sourceOptions = task.src.options;
573 result.ext = ext;
574 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -0800575 JsonWriter::AddBitmapResult(result);
576
mtkleinb0531a72015-04-07 13:38:48 -0700577 // If an MD5 is uninteresting, we want it noted in the JSON file,
578 // but don't want to dump it out as a .png (or whatever ext is).
579 if (gUninterestingHashes.contains(md5)) {
580 return;
581 }
582
mtklein748ca3b2015-01-15 10:56:12 -0800583 const char* dir = FLAGS_writePath[0];
584 if (0 == strcmp(dir, "@")) { // Needed for iOS.
585 dir = FLAGS_resourcePath[0];
586 }
587 sk_mkdir(dir);
588
589 SkString path;
590 if (FLAGS_nameByHash) {
591 path = SkOSPath::Join(dir, result.md5.c_str());
592 path.append(".");
593 path.append(ext);
594 if (sk_exists(path.c_str())) {
595 return; // Content-addressed. If it exists already, we're done.
596 }
597 } else {
598 path = SkOSPath::Join(dir, task.sink.tag);
599 sk_mkdir(path.c_str());
600 path = SkOSPath::Join(path.c_str(), task.src.tag);
601 sk_mkdir(path.c_str());
djsollen54416de2015-04-03 07:24:48 -0700602 if (strcmp(task.src.options, "") != 0) {
603 path = SkOSPath::Join(path.c_str(), task.src.options);
604 sk_mkdir(path.c_str());
605 }
mtklein748ca3b2015-01-15 10:56:12 -0800606 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
607 path.append(".");
608 path.append(ext);
609 }
610
611 SkFILEWStream file(path.c_str());
612 if (!file.isValid()) {
613 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
614 return;
615 }
616
mtklein748ca3b2015-01-15 10:56:12 -0800617 if (bitmap) {
618 // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first.
619 SkBitmap converted;
620 if (bitmap->info().colorType() == kAlpha_8_SkColorType) {
621 if (!bitmap->copyTo(&converted, kN32_SkColorType)) {
622 fail("Can't convert A8 to 8888.\n");
623 return;
624 }
625 bitmap = &converted;
626 }
627 if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) {
628 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
629 return;
630 }
631 } else {
632 if (!file.writeStream(data, len)) {
633 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
634 return;
635 }
636 }
637 }
638};
639
640// Run all tasks in the same enclave serially on the same thread.
641// They can't possibly run concurrently with each other.
642static void run_enclave(SkTArray<Task>* tasks) {
643 for (int i = 0; i < tasks->count(); i++) {
644 Task::Run(tasks->begin() + i);
645 }
646}
647
648/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
649
650// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
651
mtklein55e88b22015-01-21 15:50:13 -0800652static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800653
654static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -0800655 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -0800656 return;
657 }
mtklein6393c062015-04-27 08:45:01 -0700658 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
659 if (!in_shard()) {
660 continue;
661 }
halcanary87f3ba42015-01-20 09:30:20 -0800662 // Despite its name, factory() is returning a reference to
663 // link-time static const POD data.
664 const skiatest::Test& test = r->factory();
665 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800666 continue;
667 }
halcanary87f3ba42015-01-20 09:30:20 -0800668 if (test.needsGpu && gpu_supported()) {
mtklein55e88b22015-01-21 15:50:13 -0800669 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -0800670 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -0800671 gThreadedTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800672 }
mtklein748ca3b2015-01-15 10:56:12 -0800673 }
674}
675
halcanary87f3ba42015-01-20 09:30:20 -0800676static void run_test(skiatest::Test* test) {
677 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -0700678 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -0800679 fail(failure.toString());
680 JsonWriter::AddTestFailure(failure);
681 }
mtklein36352bf2015-03-25 18:17:31 -0700682 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -0800683 return FLAGS_pathOpsExtended;
684 }
mtklein36352bf2015-03-25 18:17:31 -0700685 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -0800686 } reporter;
djsollen824996a2015-06-12 12:06:22 -0700687
688 SkString note;
689 SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test->name);
690 if (!whyBlacklisted.isEmpty()) {
691 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
692 }
693
mtklein748ca3b2015-01-15 10:56:12 -0800694 WallTimer timer;
695 timer.start();
djsollen824996a2015-06-12 12:06:22 -0700696 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
djsollen54416de2015-04-03 07:24:48 -0700697 start("unit", "test", "", test->name);
mtklein55e88b22015-01-21 15:50:13 -0800698 GrContextFactory factory;
bsalomon821e10e2015-06-04 14:15:33 -0700699 if (FLAGS_pre_log) {
700 SkDebugf("\nRunning test %s", test->name);
701 }
mtklein55e88b22015-01-21 15:50:13 -0800702 test->proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -0800703 }
704 timer.end();
djsollen824996a2015-06-12 12:06:22 -0700705 done(timer.fWall, "unit", "test", "", test->name, note, "");
mtklein748ca3b2015-01-15 10:56:12 -0800706}
707
708/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
709
mtklein55e88b22015-01-21 15:50:13 -0800710// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
711static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
712 run_enclave(tasks);
713 for (int i = 0; i < gGPUTests.count(); i++) {
714 run_test(&gGPUTests[i]);
715 }
716}
717
mtkleinde6fc2b2015-03-12 06:28:54 -0700718// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
719// This prints something every once in a while so that it knows we're still working.
mtklein2e1c47e2015-03-12 07:16:56 -0700720static void start_keepalive() {
721 struct Loop {
722 static void forever(void*) {
723 for (;;) {
724 static const int kSec = 300;
725 #if defined(SK_BUILD_FOR_WIN)
726 Sleep(kSec * 1000);
727 #else
728 sleep(kSec);
729 #endif
mtkleinb37cb412015-03-18 05:27:14 -0700730 SkString running;
731 {
732 SkAutoMutexAcquire lock(gRunningMutex);
733 for (int i = 0; i < gRunning.count(); i++) {
734 running.appendf("\n\t%s", gRunning[i].c_str());
735 }
736 }
737 SkDebugf("\nCurrently running:%s\n", running.c_str());
mtklein2e1c47e2015-03-12 07:16:56 -0700738 }
739 }
740 };
741 static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
742 intentionallyLeaked->start();
mtkleinde6fc2b2015-03-12 06:28:54 -0700743}
744
caryclark83ca6282015-06-10 09:31:09 -0700745#define PORTABLE_FONT_PREFIX "Toy Liberation "
746
747static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
748 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
749 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
750 return sk_tool_utils::create_portable_typeface_always(familyName, style);
751 }
752 return NULL;
753}
754
755#undef PORTABLE_FONT_PREFIX
756
757extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
758
jcgregorio3b27ade2014-11-13 08:06:40 -0800759int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700760int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800761 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000762 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700763 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -0700764 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000765
mtklein2e1c47e2015-03-12 07:16:56 -0700766 start_keepalive();
mtkleinde6fc2b2015-03-12 06:28:54 -0700767
mtklein62bd1a62015-01-27 14:46:26 -0800768 gather_gold();
borenet09ed4802015-04-03 14:15:33 -0700769 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -0800770
mtklein748ca3b2015-01-15 10:56:12 -0800771 gather_srcs();
772 gather_sinks();
773 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000774
mtklein55e88b22015-01-21 15:50:13 -0800775 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -0800776 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -0800777 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -0800778
779 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
780 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -0800781 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -0800782 SkTArray<Task> enclaves[kNumEnclaves];
783 for (int j = 0; j < gSinks.count(); j++) {
784 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
785 for (int i = 0; i < gSrcs.count(); i++) {
786 tasks.push_back(Task(gSrcs[i], gSinks[j]));
787 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000788 }
789
mtklein748ca3b2015-01-15 10:56:12 -0800790 SkTaskGroup tg;
mtklein55e88b22015-01-21 15:50:13 -0800791 tg.batch(run_test, gThreadedTests.begin(), gThreadedTests.count());
792 for (int i = 0; i < kNumEnclaves; i++) {
793 switch(i) {
794 case kAnyThread_Enclave:
795 tg.batch(Task::Run, enclaves[i].begin(), enclaves[i].count());
796 break;
797 case kGPU_Enclave:
798 tg.add(run_enclave_and_gpu_tests, &enclaves[i]);
799 break;
800 default:
801 tg.add(run_enclave, &enclaves[i]);
802 break;
mtklein82d28432015-01-15 12:46:02 -0800803 }
mtklein55e88b22015-01-21 15:50:13 -0800804 }
mtklein748ca3b2015-01-15 10:56:12 -0800805 tg.wait();
mtklein748ca3b2015-01-15 10:56:12 -0800806 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -0700807 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +0000808
mtklein2f64eec2015-01-15 14:20:41 -0800809 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -0800810 if (gFailures.count() > 0) {
811 SkDebugf("Failures:\n");
812 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -0800813 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800814 }
815 SkDebugf("%d failures\n", gFailures.count());
816 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800817 }
mtklein748ca3b2015-01-15 10:56:12 -0800818 if (gPending > 0) {
819 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
820 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800821 }
mtklein748ca3b2015-01-15 10:56:12 -0800822 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000823}
jcgregorio3b27ade2014-11-13 08:06:40 -0800824
borenet48087572015-04-02 12:16:36 -0700825#if !defined(SK_BUILD_FOR_IOS)
jcgregorio3b27ade2014-11-13 08:06:40 -0800826int main(int argc, char** argv) {
827 SkCommandLineFlags::Parse(argc, argv);
828 return dm_main();
829}
830#endif