blob: d4991ef312d0999d77ecbf12edc3675c78944081 [file] [log] [blame]
jcgregorio3b27ade2014-11-13 08:06:40 -08001#include "CrashHandler.h"
mtklein748ca3b2015-01-15 10:56:12 -08002#include "DMJsonWriter.h"
3#include "DMSrcSink.h"
4#include "OverwriteLine.h"
5#include "ProcStats.h"
6#include "SkBBHFactory.h"
caryclark17f0b6d2014-07-22 10:15:34 -07007#include "SkCommonFlags.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00008#include "SkForceLinking.h"
9#include "SkGraphics.h"
mtklein748ca3b2015-01-15 10:56:12 -080010#include "SkMD5.h"
mtklein1d0f1642014-09-08 08:05:18 -070011#include "SkOSFile.h"
mtklein406654b2014-09-03 15:34:37 -070012#include "SkTaskGroup.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000013#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080014#include "Timer.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000015
mtklein748ca3b2015-01-15 10:56:12 -080016DEFINE_string(images, "resources", "Images to decode.");
mtklein6c5fed22015-01-20 13:47:23 -080017DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080018DEFINE_bool(nameByHash, false,
19 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
20 "to FLAGS_writePath[0]/<config>/<sourceType>/<name>.png");
21DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
22DEFINE_string(matrix, "1 0 0 0 1 0 0 0 1",
23 "Matrix to apply when using 'matrix' in config.");
mtklein82d28432015-01-15 12:46:02 -080024DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000025
mtkleina2ef6422015-01-15 13:44:22 -080026DEFINE_string(blacklist, "",
27 "Space-separated config/src/name triples to blacklist. '_' matches anything. E.g. \n"
28 "'--blacklist gpu skp _' will blacklist all SKPs drawn into the gpu config.\n"
29 "'--blacklist gpu skp _ 8888 gm aarects' will also blacklist the aarects GM on 8888.");
30
mtklein@google.comd36522d2013-10-16 13:02:15 +000031__SK_FORCE_IMAGE_DECODER_LINKING;
mtklein748ca3b2015-01-15 10:56:12 -080032using namespace DM;
mtklein@google.comd36522d2013-10-16 13:02:15 +000033
mtklein748ca3b2015-01-15 10:56:12 -080034/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
35
36SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
37static SkTArray<SkString> gFailures;
38
39static void fail(ImplicitString err) {
40 SkAutoMutexAcquire lock(gFailuresMutex);
41 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
42 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -080043}
44
mtklein748ca3b2015-01-15 10:56:12 -080045static int32_t gPending = 0; // Atomic.
46
47static void done(double ms, ImplicitString config, ImplicitString src, ImplicitString name) {
48 SkDebugf("%s(%4dMB %5d) %s\t%s %s %s ", FLAGS_verbose ? "\n" : kSkOverwriteLine
49 , sk_tools::getMaxResidentSetSizeMB()
50 , sk_atomic_dec(&gPending)-1
51 , HumanizeMs(ms).c_str()
52 , config.c_str()
53 , src.c_str()
54 , name.c_str());
mtklein@google.comd36522d2013-10-16 13:02:15 +000055}
56
mtklein748ca3b2015-01-15 10:56:12 -080057/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -080058
mtklein748ca3b2015-01-15 10:56:12 -080059template <typename T>
60struct Tagged : public SkAutoTDelete<T> { const char* tag; };
61
62static const bool kMemcpyOK = true;
63
64static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs;
65static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks;
66
67static void push_src(const char* tag, Src* s) {
68 SkAutoTDelete<Src> src(s);
69 if (FLAGS_src.contains(tag) &&
70 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
71 Tagged<Src>& s = gSrcs.push_back();
72 s.reset(src.detach());
73 s.tag = tag;
mtklein114c3cd2015-01-15 10:15:02 -080074 }
mtklein748ca3b2015-01-15 10:56:12 -080075}
mtklein114c3cd2015-01-15 10:15:02 -080076
mtklein748ca3b2015-01-15 10:56:12 -080077static void gather_srcs() {
78 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
79 push_src("gm", new GMSrc(r->factory()));
80 }
81 if (!FLAGS_skps.isEmpty()) {
82 SkOSFile::Iter it(FLAGS_skps[0], "skp");
83 for (SkString file; it.next(&file); ) {
84 push_src("skp", new SKPSrc(SkOSPath::Join(FLAGS_skps[0], file.c_str())));
mtklein114c3cd2015-01-15 10:15:02 -080085 }
86 }
mtklein748ca3b2015-01-15 10:56:12 -080087 if (!FLAGS_images.isEmpty()) {
88 const char* exts[] = {
89 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
90 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
91 };
92 for (size_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
93 SkOSFile::Iter it(FLAGS_images[0], exts[i]);
94 for (SkString file; it.next(&file); ) {
95 SkString path = SkOSPath::Join(FLAGS_images[0], file.c_str());
mtklein9264a952015-01-20 10:11:53 -080096 push_src("image", new ImageSrc(path)); // Decode entire image.
97 push_src("image", new ImageSrc(path, 5)); // Decode 5 random subsets.
mtklein114c3cd2015-01-15 10:15:02 -080098 }
mtklein709d2c32015-01-15 08:30:25 -080099 }
mtklein709d2c32015-01-15 08:30:25 -0800100 }
101}
102
mtklein748ca3b2015-01-15 10:56:12 -0800103static GrGLStandard get_gpu_api() {
104 if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; }
105 if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; }
106 return kNone_GrGLStandard;
mtklein709d2c32015-01-15 08:30:25 -0800107}
108
mtklein748ca3b2015-01-15 10:56:12 -0800109static void push_sink(const char* tag, Sink* s) {
110 SkAutoTDelete<Sink> sink(s);
111 if (!FLAGS_config.contains(tag)) {
112 return;
mtklein114c3cd2015-01-15 10:15:02 -0800113 }
mtklein748ca3b2015-01-15 10:56:12 -0800114 // Try a noop Src as a canary. If it fails, skip this sink.
115 struct : public Src {
116 Error draw(SkCanvas*) const SK_OVERRIDE { return ""; }
117 SkISize size() const SK_OVERRIDE { return SkISize::Make(16, 16); }
118 Name name() const SK_OVERRIDE { return "noop"; }
119 } noop;
mtklein114c3cd2015-01-15 10:15:02 -0800120
mtklein748ca3b2015-01-15 10:56:12 -0800121 SkBitmap bitmap;
122 SkDynamicMemoryWStream stream;
123 Error err = sink->draw(noop, &bitmap, &stream);
124 if (!err.isEmpty()) {
125 SkDebugf("Skipping %s: %s\n", tag, err.c_str());
mtklein114c3cd2015-01-15 10:15:02 -0800126 return;
127 }
128
mtklein748ca3b2015-01-15 10:56:12 -0800129 Tagged<Sink>& ts = gSinks.push_back();
130 ts.reset(sink.detach());
131 ts.tag = tag;
132}
133
134static bool gpu_supported() {
135#if SK_SUPPORT_GPU
136 return FLAGS_gpu;
137#else
138 return false;
139#endif
140}
141
142static Sink* create_sink(const char* tag) {
143#define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); }
144 if (gpu_supported()) {
mtklein82d28432015-01-15 12:46:02 -0800145 typedef GrContextFactory Gr;
mtklein748ca3b2015-01-15 10:56:12 -0800146 const GrGLStandard api = get_gpu_api();
mtklein82d28432015-01-15 12:46:02 -0800147 SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading);
148 SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading);
149 SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading);
150 SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading);
151 SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading);
152 SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading);
153 SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading);
154 SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800155 #if SK_ANGLE
mtklein82d28432015-01-15 12:46:02 -0800156 SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800157 #endif
158 #if SK_MESA
mtklein82d28432015-01-15 12:46:02 -0800159 SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800160 #endif
mtklein114c3cd2015-01-15 10:15:02 -0800161 }
mtklein748ca3b2015-01-15 10:56:12 -0800162
163 if (FLAGS_cpu) {
164 SINK("565", RasterSink, kRGB_565_SkColorType);
165 SINK("8888", RasterSink, kN32_SkColorType);
mtklein19f30602015-01-20 13:34:39 -0800166 SINK("pdf", PDFSink);
mtklein748ca3b2015-01-15 10:56:12 -0800167 }
168#undef SINK
169 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800170}
171
mtklein748ca3b2015-01-15 10:56:12 -0800172static Sink* create_via(const char* tag, Sink* wrapped) {
173#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); }
mtklein7edca212015-01-21 13:18:51 -0800174 VIA("pipe", ViaPipe, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800175 VIA("serialize", ViaSerialization, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800176 VIA("tiles", ViaTiles, 256, 256, NULL, wrapped);
177 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800178
179 if (FLAGS_matrix.count() == 9) {
180 SkMatrix m;
181 for (int i = 0; i < 9; i++) {
182 m[i] = (SkScalar)atof(FLAGS_matrix[i]);
183 }
184 VIA("matrix", ViaMatrix, m, wrapped);
185 }
186#undef VIA
187 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800188}
189
mtklein748ca3b2015-01-15 10:56:12 -0800190static void gather_sinks() {
191 for (int i = 0; i < FLAGS_config.count(); i++) {
192 const char* config = FLAGS_config[i];
193 SkTArray<SkString> parts;
194 SkStrSplit(config, "-", &parts);
195
196 Sink* sink = NULL;
197 for (int i = parts.count(); i-- > 0;) {
198 const char* part = parts[i].c_str();
199 Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink);
200 if (next == NULL) {
201 SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part);
202 delete sink;
203 sink = NULL;
204 break;
205 }
206 sink = next;
207 }
208 if (sink) {
209 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800210 }
211 }
212}
mtklein709d2c32015-01-15 08:30:25 -0800213
mtkleina2ef6422015-01-15 13:44:22 -0800214static bool match(const char* needle, const char* haystack) {
215 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle);
216}
217
218static ImplicitString is_blacklisted(const char* sink, const char* src, const char* name) {
219 for (int i = 0; i < FLAGS_blacklist.count() - 2; i += 3) {
220 if (match(FLAGS_blacklist[i+0], sink) &&
221 match(FLAGS_blacklist[i+1], src) &&
222 match(FLAGS_blacklist[i+2], name)) {
223 return SkStringPrintf("%s %s %s",
224 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], FLAGS_blacklist[i+2]);
225 }
226 }
227 return "";
228}
229
mtklein748ca3b2015-01-15 10:56:12 -0800230// The finest-grained unit of work we can run: draw a single Src into a single Sink,
231// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
232struct Task {
233 Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {}
234 const Tagged<Src>& src;
235 const Tagged<Sink>& sink;
236
237 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800238 SkString name = task->src->name();
239 SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag, name.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800240 WallTimer timer;
241 timer.start();
mtkleina2ef6422015-01-15 13:44:22 -0800242 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800243 SkBitmap bitmap;
244 SkDynamicMemoryWStream stream;
245 Error err = task->sink->draw(*task->src, &bitmap, &stream);
246 if (!err.isEmpty()) {
247 fail(SkStringPrintf("%s %s %s: %s",
248 task->sink.tag,
249 task->src.tag,
mtkleina2ef6422015-01-15 13:44:22 -0800250 name.c_str(),
mtklein748ca3b2015-01-15 10:56:12 -0800251 err.c_str()));
252 }
253 if (!FLAGS_writePath.isEmpty()) {
254 const char* ext = task->sink->fileExtension();
255 if (stream.bytesWritten() == 0) {
256 SkMemoryStream pixels(bitmap.getPixels(), bitmap.getSize());
257 WriteToDisk(*task, &pixels, bitmap.getSize(), &bitmap, ext);
258 } else {
259 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
260 WriteToDisk(*task, data, data->getLength(), NULL, ext);
261 }
262 }
263 }
264 timer.end();
mtkleina2ef6422015-01-15 13:44:22 -0800265 if (!whyBlacklisted.isEmpty()) {
266 name.appendf(" (--blacklist, %s)", whyBlacklisted.c_str());
267 }
268 done(timer.fWall, task->sink.tag, task->src.tag, name);
mtklein748ca3b2015-01-15 10:56:12 -0800269 }
270
271 static void WriteToDisk(const Task& task,
272 SkStream* data, size_t len,
273 const SkBitmap* bitmap,
274 const char* ext) {
275 SkMD5 hash;
276 hash.writeStream(data, len);
277 SkMD5::Digest digest;
278 hash.finish(digest);
279
280 JsonWriter::BitmapResult result;
281 result.name = task.src->name();
282 result.config = task.sink.tag;
283 result.sourceType = task.src.tag;
284 result.ext = ext;
285 for (int i = 0; i < 16; i++) {
286 result.md5.appendf("%02x", digest.data[i]);
287 }
288 JsonWriter::AddBitmapResult(result);
289
290 const char* dir = FLAGS_writePath[0];
291 if (0 == strcmp(dir, "@")) { // Needed for iOS.
292 dir = FLAGS_resourcePath[0];
293 }
294 sk_mkdir(dir);
295
296 SkString path;
297 if (FLAGS_nameByHash) {
298 path = SkOSPath::Join(dir, result.md5.c_str());
299 path.append(".");
300 path.append(ext);
301 if (sk_exists(path.c_str())) {
302 return; // Content-addressed. If it exists already, we're done.
303 }
304 } else {
305 path = SkOSPath::Join(dir, task.sink.tag);
306 sk_mkdir(path.c_str());
307 path = SkOSPath::Join(path.c_str(), task.src.tag);
308 sk_mkdir(path.c_str());
309 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
310 path.append(".");
311 path.append(ext);
312 }
313
314 SkFILEWStream file(path.c_str());
315 if (!file.isValid()) {
316 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
317 return;
318 }
319
320 data->rewind();
321 if (bitmap) {
322 // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first.
323 SkBitmap converted;
324 if (bitmap->info().colorType() == kAlpha_8_SkColorType) {
325 if (!bitmap->copyTo(&converted, kN32_SkColorType)) {
326 fail("Can't convert A8 to 8888.\n");
327 return;
328 }
329 bitmap = &converted;
330 }
331 if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) {
332 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
333 return;
334 }
335 } else {
336 if (!file.writeStream(data, len)) {
337 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
338 return;
339 }
340 }
341 }
342};
343
344// Run all tasks in the same enclave serially on the same thread.
345// They can't possibly run concurrently with each other.
346static void run_enclave(SkTArray<Task>* tasks) {
347 for (int i = 0; i < tasks->count(); i++) {
348 Task::Run(tasks->begin() + i);
349 }
350}
351
352/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
353
354// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
355
mtklein55e88b22015-01-21 15:50:13 -0800356static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800357
358static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -0800359 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -0800360 return;
361 }
halcanary87f3ba42015-01-20 09:30:20 -0800362 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r;
363 r = r->next()) {
364 // Despite its name, factory() is returning a reference to
365 // link-time static const POD data.
366 const skiatest::Test& test = r->factory();
367 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800368 continue;
369 }
halcanary87f3ba42015-01-20 09:30:20 -0800370 if (test.needsGpu && gpu_supported()) {
mtklein55e88b22015-01-21 15:50:13 -0800371 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -0800372 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -0800373 gThreadedTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800374 }
mtklein748ca3b2015-01-15 10:56:12 -0800375 }
376}
377
halcanary87f3ba42015-01-20 09:30:20 -0800378static void run_test(skiatest::Test* test) {
379 struct : public skiatest::Reporter {
380 void reportFailed(const skiatest::Failure& failure) SK_OVERRIDE {
381 fail(failure.toString());
382 JsonWriter::AddTestFailure(failure);
383 }
384 bool allowExtendedTest() const SK_OVERRIDE {
385 return FLAGS_pathOpsExtended;
386 }
387 bool verbose() const SK_OVERRIDE { return FLAGS_veryVerbose; }
388 } reporter;
mtklein748ca3b2015-01-15 10:56:12 -0800389 WallTimer timer;
390 timer.start();
mtklein748ca3b2015-01-15 10:56:12 -0800391 if (!FLAGS_dryRun) {
mtklein55e88b22015-01-21 15:50:13 -0800392 GrContextFactory factory;
393 test->proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -0800394 }
395 timer.end();
halcanary87f3ba42015-01-20 09:30:20 -0800396 done(timer.fWall, "unit", "test", test->name);
mtklein748ca3b2015-01-15 10:56:12 -0800397}
398
399/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
400
mtklein55e88b22015-01-21 15:50:13 -0800401// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
402static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
403 run_enclave(tasks);
404 for (int i = 0; i < gGPUTests.count(); i++) {
405 run_test(&gGPUTests[i]);
406 }
407}
408
jcgregorio3b27ade2014-11-13 08:06:40 -0800409int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700410int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800411 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000412 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700413 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000414
mtklein748ca3b2015-01-15 10:56:12 -0800415 gather_srcs();
416 gather_sinks();
417 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000418
mtklein55e88b22015-01-21 15:50:13 -0800419 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -0800420 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -0800421 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -0800422
423 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
424 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -0800425 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -0800426 SkTArray<Task> enclaves[kNumEnclaves];
427 for (int j = 0; j < gSinks.count(); j++) {
428 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
429 for (int i = 0; i < gSrcs.count(); i++) {
430 tasks.push_back(Task(gSrcs[i], gSinks[j]));
431 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000432 }
433
mtklein748ca3b2015-01-15 10:56:12 -0800434 SkTaskGroup tg;
mtklein55e88b22015-01-21 15:50:13 -0800435 tg.batch(run_test, gThreadedTests.begin(), gThreadedTests.count());
436 for (int i = 0; i < kNumEnclaves; i++) {
437 switch(i) {
438 case kAnyThread_Enclave:
439 tg.batch(Task::Run, enclaves[i].begin(), enclaves[i].count());
440 break;
441 case kGPU_Enclave:
442 tg.add(run_enclave_and_gpu_tests, &enclaves[i]);
443 break;
444 default:
445 tg.add(run_enclave, &enclaves[i]);
446 break;
mtklein82d28432015-01-15 12:46:02 -0800447 }
mtklein55e88b22015-01-21 15:50:13 -0800448 }
mtklein748ca3b2015-01-15 10:56:12 -0800449 tg.wait();
mtklein748ca3b2015-01-15 10:56:12 -0800450 // At this point we're back in single-threaded land.
mtklein@google.comd36522d2013-10-16 13:02:15 +0000451
mtklein2f64eec2015-01-15 14:20:41 -0800452 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -0800453 JsonWriter::DumpJson();
454
455 if (gFailures.count() > 0) {
456 SkDebugf("Failures:\n");
457 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -0800458 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800459 }
460 SkDebugf("%d failures\n", gFailures.count());
461 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800462 }
mtklein748ca3b2015-01-15 10:56:12 -0800463 if (gPending > 0) {
464 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
465 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800466 }
mtklein748ca3b2015-01-15 10:56:12 -0800467 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000468}
jcgregorio3b27ade2014-11-13 08:06:40 -0800469
470#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
471int main(int argc, char** argv) {
472 SkCommandLineFlags::Parse(argc, argv);
473 return dm_main();
474}
475#endif