blob: 40823c4945f4c411d304eaf070eda18c1801562e [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"
mtklein1d0f1642014-09-08 08:05:18 -070021#include "SkOSFile.h"
mtkleina82f5622015-02-20 12:30:19 -080022#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070023#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070024#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000025#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080026#include "Timer.h"
caryclark83ca6282015-06-10 09:31:09 -070027#include "sk_tool_utils.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000028
djsollen54416de2015-04-03 07:24:48 -070029DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080030DEFINE_bool(nameByHash, false,
31 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070032 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080033DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080034DEFINE_string(matrix, "1 0 0 1",
35 "2x2 scale+skew matrix to apply or upright when using "
36 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080037DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000038
mtkleina2ef6422015-01-15 13:44:22 -080039DEFINE_string(blacklist, "",
djsollen54416de2015-04-03 07:24:48 -070040 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n"
41 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
42 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.");
mtkleina2ef6422015-01-15 13:44:22 -080043
mtklein62bd1a62015-01-27 14:46:26 -080044DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
45
borenet09ed4802015-04-03 14:15:33 -070046DEFINE_string(uninterestingHashesFile, "",
47 "File containing a list of uninteresting hashes. If a result hashes to something in "
48 "this list, no image is written for that result.");
49
mtklein6393c062015-04-27 08:45:01 -070050DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
51DEFINE_int32(shard, 0, "Which shard do I run?");
bsalomon821e10e2015-06-04 14:15:33 -070052DEFINE_bool2(pre_log, p, false, "Log before running each test. May be incomprehensible when threading");
mtklein6393c062015-04-27 08:45:01 -070053
mtklein@google.comd36522d2013-10-16 13:02:15 +000054__SK_FORCE_IMAGE_DECODER_LINKING;
mtklein748ca3b2015-01-15 10:56:12 -080055using namespace DM;
mtklein@google.comd36522d2013-10-16 13:02:15 +000056
mtklein748ca3b2015-01-15 10:56:12 -080057/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
58
59SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
60static SkTArray<SkString> gFailures;
61
62static void fail(ImplicitString err) {
63 SkAutoMutexAcquire lock(gFailuresMutex);
64 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
65 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -080066}
67
mtkleinb37cb412015-03-18 05:27:14 -070068static int32_t gPending = 0; // Atomic. Total number of running and queued tasks.
69
70SK_DECLARE_STATIC_MUTEX(gRunningMutex);
71static SkTArray<SkString> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -080072
mtkleinb9eb4ac2015-02-02 18:26:03 -080073static void done(double ms,
djsollen54416de2015-04-03 07:24:48 -070074 ImplicitString config, ImplicitString src, ImplicitString srcOptions,
75 ImplicitString name, ImplicitString note, ImplicitString log) {
76 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
77 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -070078 {
79 SkAutoMutexAcquire lock(gRunningMutex);
80 for (int i = 0; i < gRunning.count(); i++) {
81 if (gRunning[i] == id) {
82 gRunning.removeShuffle(i);
83 break;
84 }
85 }
86 }
87 if (!FLAGS_verbose) {
88 note = "";
89 }
mtkleinb9eb4ac2015-02-02 18:26:03 -080090 if (!log.isEmpty()) {
91 log.prepend("\n");
92 }
mtklein6dee2ad2015-02-05 09:53:44 -080093 auto pending = sk_atomic_dec(&gPending)-1;
reed50bc0512015-05-19 14:13:31 -070094 if (!FLAGS_quiet) {
95 SkDebugf("%s(%4d/%-4dMB %5d) %s\t%s%s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine
96 , sk_tools::getCurrResidentSetSizeMB()
97 , sk_tools::getMaxResidentSetSizeMB()
98 , pending
99 , HumanizeMs(ms).c_str()
100 , id.c_str()
101 , note.c_str()
102 , log.c_str());
103 }
mtkleina17241b2015-01-23 05:48:00 -0800104 // We write our dm.json file every once in a while in case we crash.
105 // Notice this also handles the final dm.json when pending == 0.
106 if (pending % 500 == 0) {
107 JsonWriter::DumpJson();
108 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000109}
110
djsollen54416de2015-04-03 07:24:48 -0700111static void start(ImplicitString config, ImplicitString src,
112 ImplicitString srcOptions, ImplicitString name) {
113 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
114 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700115 SkAutoMutexAcquire lock(gRunningMutex);
116 gRunning.push_back(id);
117}
118
mtklein748ca3b2015-01-15 10:56:12 -0800119/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800120
mtklein62bd1a62015-01-27 14:46:26 -0800121struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800122 Gold() : SkString("") {}
djsollen54416de2015-04-03 07:24:48 -0700123 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions,
124 ImplicitString name, ImplicitString md5)
mtklein62bd1a62015-01-27 14:46:26 -0800125 : SkString("") {
126 this->append(sink);
127 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700128 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800129 this->append(name);
130 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800131 }
mtklein02f46cf2015-03-20 13:48:42 -0700132 static uint32_t Hash(const Gold& g) { return SkGoodHash((const SkString&)g); }
mtklein62bd1a62015-01-27 14:46:26 -0800133};
mtkleina82f5622015-02-20 12:30:19 -0800134static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800135
136static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700137 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800138}
139
140static void gather_gold() {
141 if (!FLAGS_readPath.isEmpty()) {
142 SkString path(FLAGS_readPath[0]);
143 path.append("/dm.json");
144 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
145 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
146 }
147 }
148}
149
150/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
151
borenet09ed4802015-04-03 14:15:33 -0700152static SkTHashSet<SkString> gUninterestingHashes;
153
154static void gather_uninteresting_hashes() {
155 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
156 SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0]));
157 SkTArray<SkString> hashes;
158 SkStrSplit((const char*)data->data(), "\n", &hashes);
159 for (const SkString& hash : hashes) {
160 gUninterestingHashes.add(hash);
161 }
162 }
163}
164
165/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
166
mtklein748ca3b2015-01-15 10:56:12 -0800167template <typename T>
djsollen54416de2015-04-03 07:24:48 -0700168struct Tagged : public SkAutoTDelete<T> {
169 const char* tag;
170 const char* options;
171};
mtklein748ca3b2015-01-15 10:56:12 -0800172
173static const bool kMemcpyOK = true;
174
175static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs;
176static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks;
177
mtklein6393c062015-04-27 08:45:01 -0700178static bool in_shard() {
179 static int N = 0;
180 return N++ % FLAGS_shards == FLAGS_shard;
181}
182
djsollen54416de2015-04-03 07:24:48 -0700183static void push_src(const char* tag, const char* options, Src* s) {
mtklein748ca3b2015-01-15 10:56:12 -0800184 SkAutoTDelete<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700185 if (in_shard() &&
186 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800187 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
188 Tagged<Src>& s = gSrcs.push_back();
189 s.reset(src.detach());
190 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700191 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800192 }
mtklein748ca3b2015-01-15 10:56:12 -0800193}
mtklein114c3cd2015-01-15 10:15:02 -0800194
msarett438b2ad2015-04-09 12:43:10 -0700195static void push_codec_srcs(Path path) {
196 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
197 if (!encoded) {
198 SkDebugf("Couldn't read %s.", path.c_str());
199 return;
200 }
201 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
202 if (NULL == codec.get()) {
203 SkDebugf("Couldn't create codec for %s.", path.c_str());
204 return;
205 }
206
msarett0a242972015-06-11 14:27:27 -0700207 // Choose scales for scaling tests.
208 // TODO (msarett): Add more scaling tests as we implement more flexible scaling.
209 // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these
210 // tests. SkImageDecoder supports downscales by integer factors.
jvanverth94a2fbc2015-07-02 10:40:24 -0700211 const float scales[] = { 0.125f, 0.25f, 0.5f, 1.0f };
msarett438b2ad2015-04-09 12:43:10 -0700212
msarett0a242972015-06-11 14:27:27 -0700213 for (float scale : scales) {
214 // Build additional test cases for images that decode natively to non-canvas types
215 switch(codec->getInfo().colorType()) {
216 case kGray_8_SkColorType:
217 push_src("image", "codec_kGray8", new CodecSrc(path, CodecSrc::kNormal_Mode,
218 CodecSrc::kGrayscale_Always_DstColorType, scale));
219 push_src("image", "scanline_kGray8", new CodecSrc(path, CodecSrc::kScanline_Mode,
220 CodecSrc::kGrayscale_Always_DstColorType, scale));
221 push_src("image", "scanline_subset_kGray8", new CodecSrc(path,
222 CodecSrc::kScanline_Subset_Mode, CodecSrc::kGrayscale_Always_DstColorType,
223 scale));
224 push_src("image", "stripe_kGray8", new CodecSrc(path, CodecSrc::kStripe_Mode,
225 CodecSrc::kGrayscale_Always_DstColorType, scale));
226 // Intentional fall through
227 // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8?
228 // Further discussion on this topic is at skbug.com/3683
229 case kIndex_8_SkColorType:
230 push_src("image", "codec_kIndex8", new CodecSrc(path, CodecSrc::kNormal_Mode,
231 CodecSrc::kIndex8_Always_DstColorType, scale));
232 push_src("image", "scanline_kIndex8", new CodecSrc(path, CodecSrc::kScanline_Mode,
233 CodecSrc::kIndex8_Always_DstColorType, scale));
234 push_src("image", "scanline_subset_kIndex8", new CodecSrc(path,
235 CodecSrc::kScanline_Subset_Mode, CodecSrc::kIndex8_Always_DstColorType,
236 scale));
237 push_src("image", "stripe_kIndex8", new CodecSrc(path, CodecSrc::kStripe_Mode,
238 CodecSrc::kIndex8_Always_DstColorType, scale));
239 break;
240 default:
241 // Do nothing
242 break;
243 }
244
245 // Decode all images to the canvas color type
246 push_src("image", "codec", new CodecSrc(path, CodecSrc::kNormal_Mode,
247 CodecSrc::kGetFromCanvas_DstColorType, scale));
248 push_src("image", "scanline", new CodecSrc(path, CodecSrc::kScanline_Mode,
249 CodecSrc::kGetFromCanvas_DstColorType, scale));
250 push_src("image", "scanline_subset", new CodecSrc(path, CodecSrc::kScanline_Subset_Mode,
251 CodecSrc::kGetFromCanvas_DstColorType, scale));
252 push_src("image", "stripe", new CodecSrc(path, CodecSrc::kStripe_Mode,
253 CodecSrc::kGetFromCanvas_DstColorType, scale));
254 }
msarett438b2ad2015-04-09 12:43:10 -0700255}
256
scroggo9b77ddd2015-03-19 06:03:39 -0700257static bool codec_supported(const char* ext) {
258 // FIXME: Once other versions of SkCodec are available, we can add them to this
259 // list (and eventually we can remove this check once they are all supported).
msarett8c8f22a2015-04-01 06:58:48 -0700260 static const char* const exts[] = {
scroggo6f5e6192015-06-18 12:53:43 -0700261 "bmp", "gif", "jpg", "jpeg", "png", "ico", "wbmp", "webp",
262 "BMP", "GIF", "JPG", "JPEG", "PNG", "ICO", "WBMP", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700263 };
264
265 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
266 if (0 == strcmp(exts[i], ext)) {
267 return true;
268 }
269 }
270 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700271}
272
mtklein748ca3b2015-01-15 10:56:12 -0800273static void gather_srcs() {
274 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700275 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800276 }
halcanaryfc37ad12015-01-30 07:31:19 -0800277 for (int i = 0; i < FLAGS_skps.count(); i++) {
278 const char* path = FLAGS_skps[i];
279 if (sk_isdir(path)) {
280 SkOSFile::Iter it(path, "skp");
281 for (SkString file; it.next(&file); ) {
djsollen54416de2015-04-03 07:24:48 -0700282 push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str())));
halcanaryfc37ad12015-01-30 07:31:19 -0800283 }
284 } else {
djsollen54416de2015-04-03 07:24:48 -0700285 push_src("skp", "", new SKPSrc(path));
mtklein114c3cd2015-01-15 10:15:02 -0800286 }
287 }
halcanary23b03c32015-01-30 09:58:58 -0800288 static const char* const exts[] = {
289 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
290 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
291 };
292 for (int i = 0; i < FLAGS_images.count(); i++) {
293 const char* flag = FLAGS_images[i];
294 if (sk_isdir(flag)) {
295 for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) {
296 SkOSFile::Iter it(flag, exts[j]);
297 for (SkString file; it.next(&file); ) {
298 SkString path = SkOSPath::Join(flag, file.c_str());
djsollen54416de2015-04-03 07:24:48 -0700299 push_src("image", "decode", new ImageSrc(path)); // Decode entire image
300 push_src("image", "subset", new ImageSrc(path, 2)); // Decode into 2x2 subsets
scroggo9b77ddd2015-03-19 06:03:39 -0700301 if (codec_supported(exts[j])) {
msarett438b2ad2015-04-09 12:43:10 -0700302 push_codec_srcs(path);
scroggo9b77ddd2015-03-19 06:03:39 -0700303 }
halcanary23b03c32015-01-30 09:58:58 -0800304 }
mtklein114c3cd2015-01-15 10:15:02 -0800305 }
halcanary23b03c32015-01-30 09:58:58 -0800306 } else if (sk_exists(flag)) {
307 // assume that FLAGS_images[i] is a valid image if it is a file.
djsollen54416de2015-04-03 07:24:48 -0700308 push_src("image", "decode", new ImageSrc(flag)); // Decode entire image.
309 push_src("image", "subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subsets
msarett438b2ad2015-04-09 12:43:10 -0700310 push_codec_srcs(flag);
mtklein709d2c32015-01-15 08:30:25 -0800311 }
mtklein709d2c32015-01-15 08:30:25 -0800312 }
313}
314
mtklein748ca3b2015-01-15 10:56:12 -0800315static GrGLStandard get_gpu_api() {
316 if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; }
317 if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; }
318 return kNone_GrGLStandard;
mtklein709d2c32015-01-15 08:30:25 -0800319}
320
mtklein748ca3b2015-01-15 10:56:12 -0800321static void push_sink(const char* tag, Sink* s) {
322 SkAutoTDelete<Sink> sink(s);
323 if (!FLAGS_config.contains(tag)) {
324 return;
mtklein114c3cd2015-01-15 10:15:02 -0800325 }
mtklein748ca3b2015-01-15 10:56:12 -0800326 // Try a noop Src as a canary. If it fails, skip this sink.
327 struct : public Src {
mtklein36352bf2015-03-25 18:17:31 -0700328 Error draw(SkCanvas*) const override { return ""; }
329 SkISize size() const override { return SkISize::Make(16, 16); }
330 Name name() const override { return "noop"; }
mtklein748ca3b2015-01-15 10:56:12 -0800331 } noop;
mtklein114c3cd2015-01-15 10:15:02 -0800332
mtklein748ca3b2015-01-15 10:56:12 -0800333 SkBitmap bitmap;
334 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800335 SkString log;
336 Error err = sink->draw(noop, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800337 if (err.isFatal()) {
mtklein05641a52015-04-21 10:49:13 -0700338 SkDebugf("Could not run %s: %s\n", tag, err.c_str());
339 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800340 }
341
mtklein748ca3b2015-01-15 10:56:12 -0800342 Tagged<Sink>& ts = gSinks.push_back();
343 ts.reset(sink.detach());
344 ts.tag = tag;
345}
346
347static bool gpu_supported() {
348#if SK_SUPPORT_GPU
349 return FLAGS_gpu;
350#else
351 return false;
352#endif
353}
354
355static Sink* create_sink(const char* tag) {
356#define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); }
357 if (gpu_supported()) {
mtklein82d28432015-01-15 12:46:02 -0800358 typedef GrContextFactory Gr;
mtklein748ca3b2015-01-15 10:56:12 -0800359 const GrGLStandard api = get_gpu_api();
mtklein82d28432015-01-15 12:46:02 -0800360 SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading);
361 SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading);
362 SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading);
363 SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading);
364 SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading);
365 SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading);
366 SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading);
367 SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800368 #if SK_ANGLE
mtklein82d28432015-01-15 12:46:02 -0800369 SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800370 #endif
371 #if SK_MESA
mtklein82d28432015-01-15 12:46:02 -0800372 SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800373 #endif
mtklein114c3cd2015-01-15 10:15:02 -0800374 }
mtklein748ca3b2015-01-15 10:56:12 -0800375
tomhudsoneebc39a2015-02-23 12:18:05 -0800376#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
377 SINK("hwui", HWUISink);
378#endif
379
mtklein748ca3b2015-01-15 10:56:12 -0800380 if (FLAGS_cpu) {
381 SINK("565", RasterSink, kRGB_565_SkColorType);
382 SINK("8888", RasterSink, kN32_SkColorType);
mtklein19f30602015-01-20 13:34:39 -0800383 SINK("pdf", PDFSink);
mtklein9c3f17d2015-01-28 11:35:18 -0800384 SINK("skp", SKPSink);
mtklein8a4527e2015-01-31 20:00:58 -0800385 SINK("svg", SVGSink);
386 SINK("null", NullSink);
halcanary47ef4d52015-03-03 09:13:09 -0800387 SINK("xps", XPSSink);
mtklein748ca3b2015-01-15 10:56:12 -0800388 }
389#undef SINK
390 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800391}
392
mtklein748ca3b2015-01-15 10:56:12 -0800393static Sink* create_via(const char* tag, Sink* wrapped) {
394#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); }
mtklein6fbf4b32015-05-06 11:35:40 -0700395 VIA("twice", ViaTwice, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800396 VIA("pipe", ViaPipe, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800397 VIA("serialize", ViaSerialization, wrapped);
reed06a22f62015-05-05 08:11:33 -0700398 VIA("deferred", ViaDeferred, wrapped);
mtkleinb7e8d692015-04-07 08:30:32 -0700399 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700400 VIA("sp", ViaSingletonPictures, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800401 VIA("tiles", ViaTiles, 256, 256, NULL, wrapped);
402 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800403
mtkleind603b222015-02-17 11:13:33 -0800404 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800405 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800406 m.reset();
407 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
408 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
409 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
410 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
411 VIA("matrix", ViaMatrix, m, wrapped);
412 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800413 }
tomhudson64de1e12015-03-05 08:01:07 -0800414
415#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
416 VIA("androidsdk", ViaAndroidSDK, wrapped);
417#endif
418
mtklein748ca3b2015-01-15 10:56:12 -0800419#undef VIA
420 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800421}
422
mtklein748ca3b2015-01-15 10:56:12 -0800423static void gather_sinks() {
424 for (int i = 0; i < FLAGS_config.count(); i++) {
425 const char* config = FLAGS_config[i];
426 SkTArray<SkString> parts;
427 SkStrSplit(config, "-", &parts);
428
429 Sink* sink = NULL;
430 for (int i = parts.count(); i-- > 0;) {
431 const char* part = parts[i].c_str();
432 Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink);
433 if (next == NULL) {
434 SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part);
435 delete sink;
436 sink = NULL;
437 break;
438 }
439 sink = next;
440 }
441 if (sink) {
442 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800443 }
444 }
445}
mtklein709d2c32015-01-15 08:30:25 -0800446
mtkleina2ef6422015-01-15 13:44:22 -0800447static bool match(const char* needle, const char* haystack) {
448 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle);
449}
450
djsollen54416de2015-04-03 07:24:48 -0700451static ImplicitString is_blacklisted(const char* sink, const char* src,
452 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -0700453 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -0800454 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -0700455 match(FLAGS_blacklist[i+1], src) &&
456 match(FLAGS_blacklist[i+2], srcOptions) &&
457 match(FLAGS_blacklist[i+3], name)) {
458 return SkStringPrintf("%s %s %s %s",
459 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1],
460 FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]);
mtkleina2ef6422015-01-15 13:44:22 -0800461 }
462 }
463 return "";
464}
465
mtklein748ca3b2015-01-15 10:56:12 -0800466// The finest-grained unit of work we can run: draw a single Src into a single Sink,
467// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
468struct Task {
469 Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {}
470 const Tagged<Src>& src;
471 const Tagged<Sink>& sink;
472
473 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800474 SkString name = task->src->name();
mtkleinb37cb412015-03-18 05:27:14 -0700475 SkString note;
djsollen54416de2015-04-03 07:24:48 -0700476 SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag,
477 task->src.options, name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700478 if (!whyBlacklisted.isEmpty()) {
479 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
480 }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800481 SkString log;
mtklein748ca3b2015-01-15 10:56:12 -0800482 WallTimer timer;
483 timer.start();
mtkleina2ef6422015-01-15 13:44:22 -0800484 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800485 SkBitmap bitmap;
486 SkDynamicMemoryWStream stream;
bsalomon821e10e2015-06-04 14:15:33 -0700487 if (FLAGS_pre_log) {
488 SkDebugf("\nRunning %s->%s", name.c_str(), task->sink.tag);
489 }
djsollen54416de2015-04-03 07:24:48 -0700490 start(task->sink.tag, task->src.tag, task->src.options, name.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800491 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
mtklein748ca3b2015-01-15 10:56:12 -0800492 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -0800493 timer.end();
494 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -0700495 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein4089ef72015-03-05 08:40:28 -0800496 task->sink.tag,
497 task->src.tag,
djsollen54416de2015-04-03 07:24:48 -0700498 task->src.options,
mtklein4089ef72015-03-05 08:40:28 -0800499 name.c_str(),
500 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -0700501 } else {
502 note.appendf(" (skipped: %s)", err.c_str());
mtklein4089ef72015-03-05 08:40:28 -0800503 }
djsollen54416de2015-04-03 07:24:48 -0700504 done(timer.fWall, task->sink.tag, task->src.tag, task->src.options,
505 name, note, log);
mtklein4089ef72015-03-05 08:40:28 -0800506 return;
mtklein748ca3b2015-01-15 10:56:12 -0800507 }
mtklein62bd1a62015-01-27 14:46:26 -0800508 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
509
510 SkString md5;
511 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
512 SkMD5 hash;
513 if (data->getLength()) {
514 hash.writeStream(data, data->getLength());
515 data->rewind();
516 } else {
517 hash.write(bitmap.getPixels(), bitmap.getSize());
518 }
519 SkMD5::Digest digest;
520 hash.finish(digest);
521 for (int i = 0; i < 16; i++) {
522 md5.appendf("%02x", digest.data[i]);
523 }
524 }
525
526 if (!FLAGS_readPath.isEmpty() &&
djsollen54416de2015-04-03 07:24:48 -0700527 !gGold.contains(Gold(task->sink.tag, task->src.tag,
528 task->src.options, name, md5))) {
529 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
mtklein62bd1a62015-01-27 14:46:26 -0800530 md5.c_str(),
531 task->sink.tag,
532 task->src.tag,
djsollen54416de2015-04-03 07:24:48 -0700533 task->src.options,
mtklein62bd1a62015-01-27 14:46:26 -0800534 name.c_str(),
535 FLAGS_readPath[0]));
536 }
537
mtkleinb0531a72015-04-07 13:38:48 -0700538 if (!FLAGS_writePath.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800539 const char* ext = task->sink->fileExtension();
mtklein62bd1a62015-01-27 14:46:26 -0800540 if (data->getLength()) {
541 WriteToDisk(*task, md5, ext, data, data->getLength(), NULL);
halcanary022afb82015-01-30 11:00:12 -0800542 SkASSERT(bitmap.drawsNothing());
543 } else if (!bitmap.drawsNothing()) {
mtklein62bd1a62015-01-27 14:46:26 -0800544 WriteToDisk(*task, md5, ext, NULL, 0, &bitmap);
mtklein748ca3b2015-01-15 10:56:12 -0800545 }
546 }
547 }
548 timer.end();
djsollen54416de2015-04-03 07:24:48 -0700549 done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, name, note, log);
mtklein748ca3b2015-01-15 10:56:12 -0800550 }
551
552 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -0800553 SkString md5,
554 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -0800555 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -0800556 const SkBitmap* bitmap) {
mtklein748ca3b2015-01-15 10:56:12 -0800557 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -0700558 result.name = task.src->name();
559 result.config = task.sink.tag;
560 result.sourceType = task.src.tag;
561 result.sourceOptions = task.src.options;
562 result.ext = ext;
563 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -0800564 JsonWriter::AddBitmapResult(result);
565
mtkleinb0531a72015-04-07 13:38:48 -0700566 // If an MD5 is uninteresting, we want it noted in the JSON file,
567 // but don't want to dump it out as a .png (or whatever ext is).
568 if (gUninterestingHashes.contains(md5)) {
569 return;
570 }
571
mtklein748ca3b2015-01-15 10:56:12 -0800572 const char* dir = FLAGS_writePath[0];
573 if (0 == strcmp(dir, "@")) { // Needed for iOS.
574 dir = FLAGS_resourcePath[0];
575 }
576 sk_mkdir(dir);
577
578 SkString path;
579 if (FLAGS_nameByHash) {
580 path = SkOSPath::Join(dir, result.md5.c_str());
581 path.append(".");
582 path.append(ext);
583 if (sk_exists(path.c_str())) {
584 return; // Content-addressed. If it exists already, we're done.
585 }
586 } else {
587 path = SkOSPath::Join(dir, task.sink.tag);
588 sk_mkdir(path.c_str());
589 path = SkOSPath::Join(path.c_str(), task.src.tag);
590 sk_mkdir(path.c_str());
djsollen54416de2015-04-03 07:24:48 -0700591 if (strcmp(task.src.options, "") != 0) {
592 path = SkOSPath::Join(path.c_str(), task.src.options);
593 sk_mkdir(path.c_str());
594 }
mtklein748ca3b2015-01-15 10:56:12 -0800595 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
596 path.append(".");
597 path.append(ext);
598 }
599
600 SkFILEWStream file(path.c_str());
601 if (!file.isValid()) {
602 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
603 return;
604 }
605
mtklein748ca3b2015-01-15 10:56:12 -0800606 if (bitmap) {
607 // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first.
608 SkBitmap converted;
609 if (bitmap->info().colorType() == kAlpha_8_SkColorType) {
610 if (!bitmap->copyTo(&converted, kN32_SkColorType)) {
611 fail("Can't convert A8 to 8888.\n");
612 return;
613 }
614 bitmap = &converted;
615 }
616 if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) {
617 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
618 return;
619 }
620 } else {
621 if (!file.writeStream(data, len)) {
622 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
623 return;
624 }
625 }
626 }
627};
628
629// Run all tasks in the same enclave serially on the same thread.
630// They can't possibly run concurrently with each other.
631static void run_enclave(SkTArray<Task>* tasks) {
632 for (int i = 0; i < tasks->count(); i++) {
633 Task::Run(tasks->begin() + i);
634 }
635}
636
637/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
638
639// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
640
mtklein55e88b22015-01-21 15:50:13 -0800641static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800642
643static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -0800644 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -0800645 return;
646 }
mtklein6393c062015-04-27 08:45:01 -0700647 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
648 if (!in_shard()) {
649 continue;
650 }
halcanary87f3ba42015-01-20 09:30:20 -0800651 // Despite its name, factory() is returning a reference to
652 // link-time static const POD data.
653 const skiatest::Test& test = r->factory();
654 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800655 continue;
656 }
halcanary87f3ba42015-01-20 09:30:20 -0800657 if (test.needsGpu && gpu_supported()) {
mtklein55e88b22015-01-21 15:50:13 -0800658 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -0800659 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -0800660 gThreadedTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800661 }
mtklein748ca3b2015-01-15 10:56:12 -0800662 }
663}
664
halcanary87f3ba42015-01-20 09:30:20 -0800665static void run_test(skiatest::Test* test) {
666 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -0700667 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -0800668 fail(failure.toString());
669 JsonWriter::AddTestFailure(failure);
670 }
mtklein36352bf2015-03-25 18:17:31 -0700671 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -0800672 return FLAGS_pathOpsExtended;
673 }
mtklein36352bf2015-03-25 18:17:31 -0700674 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -0800675 } reporter;
djsollen824996a2015-06-12 12:06:22 -0700676
677 SkString note;
678 SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test->name);
679 if (!whyBlacklisted.isEmpty()) {
680 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
681 }
682
mtklein748ca3b2015-01-15 10:56:12 -0800683 WallTimer timer;
684 timer.start();
djsollen824996a2015-06-12 12:06:22 -0700685 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
djsollen54416de2015-04-03 07:24:48 -0700686 start("unit", "test", "", test->name);
mtklein55e88b22015-01-21 15:50:13 -0800687 GrContextFactory factory;
bsalomon821e10e2015-06-04 14:15:33 -0700688 if (FLAGS_pre_log) {
689 SkDebugf("\nRunning test %s", test->name);
690 }
mtklein55e88b22015-01-21 15:50:13 -0800691 test->proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -0800692 }
693 timer.end();
djsollen824996a2015-06-12 12:06:22 -0700694 done(timer.fWall, "unit", "test", "", test->name, note, "");
mtklein748ca3b2015-01-15 10:56:12 -0800695}
696
697/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
698
mtklein55e88b22015-01-21 15:50:13 -0800699// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
700static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
701 run_enclave(tasks);
702 for (int i = 0; i < gGPUTests.count(); i++) {
703 run_test(&gGPUTests[i]);
704 }
705}
706
mtkleinde6fc2b2015-03-12 06:28:54 -0700707// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
708// This prints something every once in a while so that it knows we're still working.
mtklein2e1c47e2015-03-12 07:16:56 -0700709static void start_keepalive() {
710 struct Loop {
711 static void forever(void*) {
712 for (;;) {
713 static const int kSec = 300;
714 #if defined(SK_BUILD_FOR_WIN)
715 Sleep(kSec * 1000);
716 #else
717 sleep(kSec);
718 #endif
mtkleinb37cb412015-03-18 05:27:14 -0700719 SkString running;
720 {
721 SkAutoMutexAcquire lock(gRunningMutex);
722 for (int i = 0; i < gRunning.count(); i++) {
723 running.appendf("\n\t%s", gRunning[i].c_str());
724 }
725 }
726 SkDebugf("\nCurrently running:%s\n", running.c_str());
mtklein2e1c47e2015-03-12 07:16:56 -0700727 }
728 }
729 };
730 static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
731 intentionallyLeaked->start();
mtkleinde6fc2b2015-03-12 06:28:54 -0700732}
733
caryclark83ca6282015-06-10 09:31:09 -0700734#define PORTABLE_FONT_PREFIX "Toy Liberation "
735
736static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
737 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
738 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
739 return sk_tool_utils::create_portable_typeface_always(familyName, style);
740 }
741 return NULL;
742}
743
744#undef PORTABLE_FONT_PREFIX
745
746extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
747
jcgregorio3b27ade2014-11-13 08:06:40 -0800748int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700749int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800750 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000751 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700752 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -0700753 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000754
mtklein2e1c47e2015-03-12 07:16:56 -0700755 start_keepalive();
mtkleinde6fc2b2015-03-12 06:28:54 -0700756
mtklein62bd1a62015-01-27 14:46:26 -0800757 gather_gold();
borenet09ed4802015-04-03 14:15:33 -0700758 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -0800759
mtklein748ca3b2015-01-15 10:56:12 -0800760 gather_srcs();
761 gather_sinks();
762 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000763
mtklein55e88b22015-01-21 15:50:13 -0800764 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -0800765 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -0800766 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -0800767
768 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
769 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -0800770 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -0800771 SkTArray<Task> enclaves[kNumEnclaves];
772 for (int j = 0; j < gSinks.count(); j++) {
773 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
774 for (int i = 0; i < gSrcs.count(); i++) {
775 tasks.push_back(Task(gSrcs[i], gSinks[j]));
776 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000777 }
778
mtklein748ca3b2015-01-15 10:56:12 -0800779 SkTaskGroup tg;
mtklein55e88b22015-01-21 15:50:13 -0800780 tg.batch(run_test, gThreadedTests.begin(), gThreadedTests.count());
781 for (int i = 0; i < kNumEnclaves; i++) {
782 switch(i) {
783 case kAnyThread_Enclave:
784 tg.batch(Task::Run, enclaves[i].begin(), enclaves[i].count());
785 break;
786 case kGPU_Enclave:
787 tg.add(run_enclave_and_gpu_tests, &enclaves[i]);
788 break;
789 default:
790 tg.add(run_enclave, &enclaves[i]);
791 break;
mtklein82d28432015-01-15 12:46:02 -0800792 }
mtklein55e88b22015-01-21 15:50:13 -0800793 }
mtklein748ca3b2015-01-15 10:56:12 -0800794 tg.wait();
mtklein748ca3b2015-01-15 10:56:12 -0800795 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -0700796 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +0000797
mtklein2f64eec2015-01-15 14:20:41 -0800798 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -0800799 if (gFailures.count() > 0) {
800 SkDebugf("Failures:\n");
801 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -0800802 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800803 }
804 SkDebugf("%d failures\n", gFailures.count());
805 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800806 }
mtklein748ca3b2015-01-15 10:56:12 -0800807 if (gPending > 0) {
808 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
809 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800810 }
mtklein748ca3b2015-01-15 10:56:12 -0800811 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000812}
jcgregorio3b27ade2014-11-13 08:06:40 -0800813
borenet48087572015-04-02 12:16:36 -0700814#if !defined(SK_BUILD_FOR_IOS)
jcgregorio3b27ade2014-11-13 08:06:40 -0800815int main(int argc, char** argv) {
816 SkCommandLineFlags::Parse(argc, argv);
817 return dm_main();
818}
819#endif