blob: da9dc2c55562fa3eedc7b5425868a9df2938111c [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
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000016DEFINE_bool(tests, true, "Run tests?");
mtklein748ca3b2015-01-15 10:56:12 -080017DEFINE_string(images, "resources", "Images to decode.");
mtklein9264a952015-01-20 10:11:53 -080018DEFINE_string(src, "gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080019DEFINE_bool(nameByHash, false,
20 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
21 "to FLAGS_writePath[0]/<config>/<sourceType>/<name>.png");
22DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
23DEFINE_string(matrix, "1 0 0 0 1 0 0 0 1",
24 "Matrix to apply when using 'matrix' in config.");
mtklein82d28432015-01-15 12:46:02 -080025DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000026
mtkleina2ef6422015-01-15 13:44:22 -080027DEFINE_string(blacklist, "",
28 "Space-separated config/src/name triples to blacklist. '_' matches anything. E.g. \n"
29 "'--blacklist gpu skp _' will blacklist all SKPs drawn into the gpu config.\n"
30 "'--blacklist gpu skp _ 8888 gm aarects' will also blacklist the aarects GM on 8888.");
31
mtklein@google.comd36522d2013-10-16 13:02:15 +000032__SK_FORCE_IMAGE_DECODER_LINKING;
mtklein748ca3b2015-01-15 10:56:12 -080033using namespace DM;
mtklein@google.comd36522d2013-10-16 13:02:15 +000034
mtklein748ca3b2015-01-15 10:56:12 -080035/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
36
37SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
38static SkTArray<SkString> gFailures;
39
40static void fail(ImplicitString err) {
41 SkAutoMutexAcquire lock(gFailuresMutex);
42 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
43 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -080044}
45
mtklein748ca3b2015-01-15 10:56:12 -080046static int32_t gPending = 0; // Atomic.
47
48static void done(double ms, ImplicitString config, ImplicitString src, ImplicitString name) {
49 SkDebugf("%s(%4dMB %5d) %s\t%s %s %s ", FLAGS_verbose ? "\n" : kSkOverwriteLine
50 , sk_tools::getMaxResidentSetSizeMB()
51 , sk_atomic_dec(&gPending)-1
52 , HumanizeMs(ms).c_str()
53 , config.c_str()
54 , src.c_str()
55 , name.c_str());
mtklein@google.comd36522d2013-10-16 13:02:15 +000056}
57
mtklein748ca3b2015-01-15 10:56:12 -080058/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -080059
mtklein748ca3b2015-01-15 10:56:12 -080060template <typename T>
61struct Tagged : public SkAutoTDelete<T> { const char* tag; };
62
63static const bool kMemcpyOK = true;
64
65static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs;
66static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks;
67
68static void push_src(const char* tag, Src* s) {
69 SkAutoTDelete<Src> src(s);
70 if (FLAGS_src.contains(tag) &&
71 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
72 Tagged<Src>& s = gSrcs.push_back();
73 s.reset(src.detach());
74 s.tag = tag;
mtklein114c3cd2015-01-15 10:15:02 -080075 }
mtklein748ca3b2015-01-15 10:56:12 -080076}
mtklein114c3cd2015-01-15 10:15:02 -080077
mtklein748ca3b2015-01-15 10:56:12 -080078static void gather_srcs() {
79 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
80 push_src("gm", new GMSrc(r->factory()));
81 }
82 if (!FLAGS_skps.isEmpty()) {
83 SkOSFile::Iter it(FLAGS_skps[0], "skp");
84 for (SkString file; it.next(&file); ) {
85 push_src("skp", new SKPSrc(SkOSPath::Join(FLAGS_skps[0], file.c_str())));
mtklein114c3cd2015-01-15 10:15:02 -080086 }
87 }
mtklein748ca3b2015-01-15 10:56:12 -080088 if (!FLAGS_images.isEmpty()) {
89 const char* exts[] = {
90 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
91 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
92 };
93 for (size_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
94 SkOSFile::Iter it(FLAGS_images[0], exts[i]);
95 for (SkString file; it.next(&file); ) {
96 SkString path = SkOSPath::Join(FLAGS_images[0], file.c_str());
mtklein9264a952015-01-20 10:11:53 -080097 push_src("image", new ImageSrc(path)); // Decode entire image.
98 push_src("image", new ImageSrc(path, 5)); // Decode 5 random subsets.
mtklein114c3cd2015-01-15 10:15:02 -080099 }
mtklein709d2c32015-01-15 08:30:25 -0800100 }
mtklein709d2c32015-01-15 08:30:25 -0800101 }
102}
103
mtklein748ca3b2015-01-15 10:56:12 -0800104static GrGLStandard get_gpu_api() {
105 if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; }
106 if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; }
107 return kNone_GrGLStandard;
mtklein709d2c32015-01-15 08:30:25 -0800108}
109
mtklein748ca3b2015-01-15 10:56:12 -0800110static void push_sink(const char* tag, Sink* s) {
111 SkAutoTDelete<Sink> sink(s);
112 if (!FLAGS_config.contains(tag)) {
113 return;
mtklein114c3cd2015-01-15 10:15:02 -0800114 }
mtklein748ca3b2015-01-15 10:56:12 -0800115 // Try a noop Src as a canary. If it fails, skip this sink.
116 struct : public Src {
117 Error draw(SkCanvas*) const SK_OVERRIDE { return ""; }
118 SkISize size() const SK_OVERRIDE { return SkISize::Make(16, 16); }
119 Name name() const SK_OVERRIDE { return "noop"; }
120 } noop;
mtklein114c3cd2015-01-15 10:15:02 -0800121
mtklein748ca3b2015-01-15 10:56:12 -0800122 SkBitmap bitmap;
123 SkDynamicMemoryWStream stream;
124 Error err = sink->draw(noop, &bitmap, &stream);
125 if (!err.isEmpty()) {
126 SkDebugf("Skipping %s: %s\n", tag, err.c_str());
mtklein114c3cd2015-01-15 10:15:02 -0800127 return;
128 }
129
mtklein748ca3b2015-01-15 10:56:12 -0800130 Tagged<Sink>& ts = gSinks.push_back();
131 ts.reset(sink.detach());
132 ts.tag = tag;
133}
134
135static bool gpu_supported() {
136#if SK_SUPPORT_GPU
137 return FLAGS_gpu;
138#else
139 return false;
140#endif
141}
142
143static Sink* create_sink(const char* tag) {
144#define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); }
145 if (gpu_supported()) {
mtklein82d28432015-01-15 12:46:02 -0800146 typedef GrContextFactory Gr;
mtklein748ca3b2015-01-15 10:56:12 -0800147 const GrGLStandard api = get_gpu_api();
mtklein82d28432015-01-15 12:46:02 -0800148 SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading);
149 SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading);
150 SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading);
151 SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading);
152 SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading);
153 SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading);
154 SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading);
155 SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800156 #if SK_ANGLE
mtklein82d28432015-01-15 12:46:02 -0800157 SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800158 #endif
159 #if SK_MESA
mtklein82d28432015-01-15 12:46:02 -0800160 SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800161 #endif
mtklein114c3cd2015-01-15 10:15:02 -0800162 }
mtklein748ca3b2015-01-15 10:56:12 -0800163
164 if (FLAGS_cpu) {
165 SINK("565", RasterSink, kRGB_565_SkColorType);
166 SINK("8888", RasterSink, kN32_SkColorType);
mtklein19f30602015-01-20 13:34:39 -0800167 SINK("pdf", PDFSink);
mtklein748ca3b2015-01-15 10:56:12 -0800168 }
169#undef SINK
170 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800171}
172
mtklein748ca3b2015-01-15 10:56:12 -0800173static Sink* create_via(const char* tag, Sink* wrapped) {
174#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); }
175 VIA("serialize", ViaSerialization, wrapped);
176
177 VIA("tiles", ViaTiles, 256, 256, NULL, wrapped);
178 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
179
180 const int xp = SkGPipeWriter::kCrossProcess_Flag,
181 sa = xp | SkGPipeWriter::kSharedAddressSpace_Flag;
182 VIA("pipe", ViaPipe, 0, wrapped);
183 VIA("pipe_xp", ViaPipe, xp, wrapped);
184 VIA("pipe_sa", ViaPipe, sa, wrapped);
185
186 if (FLAGS_matrix.count() == 9) {
187 SkMatrix m;
188 for (int i = 0; i < 9; i++) {
189 m[i] = (SkScalar)atof(FLAGS_matrix[i]);
190 }
191 VIA("matrix", ViaMatrix, m, wrapped);
192 }
193#undef VIA
194 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800195}
196
mtklein748ca3b2015-01-15 10:56:12 -0800197static void gather_sinks() {
198 for (int i = 0; i < FLAGS_config.count(); i++) {
199 const char* config = FLAGS_config[i];
200 SkTArray<SkString> parts;
201 SkStrSplit(config, "-", &parts);
202
203 Sink* sink = NULL;
204 for (int i = parts.count(); i-- > 0;) {
205 const char* part = parts[i].c_str();
206 Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink);
207 if (next == NULL) {
208 SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part);
209 delete sink;
210 sink = NULL;
211 break;
212 }
213 sink = next;
214 }
215 if (sink) {
216 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800217 }
218 }
219}
mtklein709d2c32015-01-15 08:30:25 -0800220
mtkleina2ef6422015-01-15 13:44:22 -0800221static bool match(const char* needle, const char* haystack) {
222 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle);
223}
224
225static ImplicitString is_blacklisted(const char* sink, const char* src, const char* name) {
226 for (int i = 0; i < FLAGS_blacklist.count() - 2; i += 3) {
227 if (match(FLAGS_blacklist[i+0], sink) &&
228 match(FLAGS_blacklist[i+1], src) &&
229 match(FLAGS_blacklist[i+2], name)) {
230 return SkStringPrintf("%s %s %s",
231 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], FLAGS_blacklist[i+2]);
232 }
233 }
234 return "";
235}
236
mtklein748ca3b2015-01-15 10:56:12 -0800237// The finest-grained unit of work we can run: draw a single Src into a single Sink,
238// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
239struct Task {
240 Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {}
241 const Tagged<Src>& src;
242 const Tagged<Sink>& sink;
243
244 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800245 SkString name = task->src->name();
246 SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag, name.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800247 WallTimer timer;
248 timer.start();
mtkleina2ef6422015-01-15 13:44:22 -0800249 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800250 SkBitmap bitmap;
251 SkDynamicMemoryWStream stream;
252 Error err = task->sink->draw(*task->src, &bitmap, &stream);
253 if (!err.isEmpty()) {
254 fail(SkStringPrintf("%s %s %s: %s",
255 task->sink.tag,
256 task->src.tag,
mtkleina2ef6422015-01-15 13:44:22 -0800257 name.c_str(),
mtklein748ca3b2015-01-15 10:56:12 -0800258 err.c_str()));
259 }
260 if (!FLAGS_writePath.isEmpty()) {
261 const char* ext = task->sink->fileExtension();
262 if (stream.bytesWritten() == 0) {
263 SkMemoryStream pixels(bitmap.getPixels(), bitmap.getSize());
264 WriteToDisk(*task, &pixels, bitmap.getSize(), &bitmap, ext);
265 } else {
266 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
267 WriteToDisk(*task, data, data->getLength(), NULL, ext);
268 }
269 }
270 }
271 timer.end();
mtkleina2ef6422015-01-15 13:44:22 -0800272 if (!whyBlacklisted.isEmpty()) {
273 name.appendf(" (--blacklist, %s)", whyBlacklisted.c_str());
274 }
275 done(timer.fWall, task->sink.tag, task->src.tag, name);
mtklein748ca3b2015-01-15 10:56:12 -0800276 }
277
278 static void WriteToDisk(const Task& task,
279 SkStream* data, size_t len,
280 const SkBitmap* bitmap,
281 const char* ext) {
282 SkMD5 hash;
283 hash.writeStream(data, len);
284 SkMD5::Digest digest;
285 hash.finish(digest);
286
287 JsonWriter::BitmapResult result;
288 result.name = task.src->name();
289 result.config = task.sink.tag;
290 result.sourceType = task.src.tag;
291 result.ext = ext;
292 for (int i = 0; i < 16; i++) {
293 result.md5.appendf("%02x", digest.data[i]);
294 }
295 JsonWriter::AddBitmapResult(result);
296
297 const char* dir = FLAGS_writePath[0];
298 if (0 == strcmp(dir, "@")) { // Needed for iOS.
299 dir = FLAGS_resourcePath[0];
300 }
301 sk_mkdir(dir);
302
303 SkString path;
304 if (FLAGS_nameByHash) {
305 path = SkOSPath::Join(dir, result.md5.c_str());
306 path.append(".");
307 path.append(ext);
308 if (sk_exists(path.c_str())) {
309 return; // Content-addressed. If it exists already, we're done.
310 }
311 } else {
312 path = SkOSPath::Join(dir, task.sink.tag);
313 sk_mkdir(path.c_str());
314 path = SkOSPath::Join(path.c_str(), task.src.tag);
315 sk_mkdir(path.c_str());
316 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
317 path.append(".");
318 path.append(ext);
319 }
320
321 SkFILEWStream file(path.c_str());
322 if (!file.isValid()) {
323 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
324 return;
325 }
326
327 data->rewind();
328 if (bitmap) {
329 // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first.
330 SkBitmap converted;
331 if (bitmap->info().colorType() == kAlpha_8_SkColorType) {
332 if (!bitmap->copyTo(&converted, kN32_SkColorType)) {
333 fail("Can't convert A8 to 8888.\n");
334 return;
335 }
336 bitmap = &converted;
337 }
338 if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) {
339 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
340 return;
341 }
342 } else {
343 if (!file.writeStream(data, len)) {
344 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
345 return;
346 }
347 }
348 }
349};
350
351// Run all tasks in the same enclave serially on the same thread.
352// They can't possibly run concurrently with each other.
353static void run_enclave(SkTArray<Task>* tasks) {
354 for (int i = 0; i < tasks->count(); i++) {
355 Task::Run(tasks->begin() + i);
356 }
357}
358
359/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
360
361// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
362
halcanary87f3ba42015-01-20 09:30:20 -0800363static SkTDArray<skiatest::Test> gCPUTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800364
365static void gather_tests() {
366 if (!FLAGS_tests) {
367 return;
368 }
halcanary87f3ba42015-01-20 09:30:20 -0800369 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r;
370 r = r->next()) {
371 // Despite its name, factory() is returning a reference to
372 // link-time static const POD data.
373 const skiatest::Test& test = r->factory();
374 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800375 continue;
376 }
halcanary87f3ba42015-01-20 09:30:20 -0800377 if (test.needsGpu && gpu_supported()) {
378 gGPUTests.push(test);
379 } else if (!test.needsGpu && FLAGS_cpu) {
380 gCPUTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800381 }
mtklein748ca3b2015-01-15 10:56:12 -0800382 }
383}
384
halcanary87f3ba42015-01-20 09:30:20 -0800385static void run_test(skiatest::Test* test) {
386 struct : public skiatest::Reporter {
387 void reportFailed(const skiatest::Failure& failure) SK_OVERRIDE {
388 fail(failure.toString());
389 JsonWriter::AddTestFailure(failure);
390 }
391 bool allowExtendedTest() const SK_OVERRIDE {
392 return FLAGS_pathOpsExtended;
393 }
394 bool verbose() const SK_OVERRIDE { return FLAGS_veryVerbose; }
395 } reporter;
mtklein748ca3b2015-01-15 10:56:12 -0800396 WallTimer timer;
397 timer.start();
mtklein748ca3b2015-01-15 10:56:12 -0800398 if (!FLAGS_dryRun) {
halcanary87f3ba42015-01-20 09:30:20 -0800399 test->proc(&reporter, GetThreadLocalGrContextFactory());
mtklein748ca3b2015-01-15 10:56:12 -0800400 }
401 timer.end();
halcanary87f3ba42015-01-20 09:30:20 -0800402 done(timer.fWall, "unit", "test", test->name);
mtklein748ca3b2015-01-15 10:56:12 -0800403}
404
405/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
406
jcgregorio3b27ade2014-11-13 08:06:40 -0800407int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700408int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800409 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000410 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700411 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000412
mtklein748ca3b2015-01-15 10:56:12 -0800413 gather_srcs();
414 gather_sinks();
415 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000416
mtklein82d28432015-01-15 12:46:02 -0800417 gPending = gSrcs.count() * gSinks.count() + gCPUTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -0800418 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein82d28432015-01-15 12:46:02 -0800419 gSrcs.count(), gSinks.count(), gCPUTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -0800420
421 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
422 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -0800423 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -0800424 SkTArray<Task> enclaves[kNumEnclaves];
425 for (int j = 0; j < gSinks.count(); j++) {
426 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
427 for (int i = 0; i < gSrcs.count(); i++) {
428 tasks.push_back(Task(gSrcs[i], gSinks[j]));
429 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000430 }
431
mtklein748ca3b2015-01-15 10:56:12 -0800432 SK_COMPILE_ASSERT(kAnyThread_Enclave == 0, AnyThreadZero);
433 SkTaskGroup tg;
434 tg.batch( Task::Run, enclaves[0].begin(), enclaves[0].count());
435 tg.batch(run_enclave, enclaves+1, kNumEnclaves-1);
mtklein82d28432015-01-15 12:46:02 -0800436 tg.batch( run_test, gCPUTests.begin(), gCPUTests.count());
437 if (FLAGS_gpu_threading) {
438 tg.batch(run_test, gGPUTests.begin(), gGPUTests.count());
mtklein2f64eec2015-01-15 14:20:41 -0800439 #if !defined(SK_BUILD_FOR_WIN32)
mtklein82d28432015-01-15 12:46:02 -0800440 } else {
441 for (int i = 0; i < gGPUTests.count(); i++) {
442 run_test(&gGPUTests[i]);
443 }
mtklein2f64eec2015-01-15 14:20:41 -0800444 #endif
mtklein82d28432015-01-15 12:46:02 -0800445 }
mtklein748ca3b2015-01-15 10:56:12 -0800446 tg.wait();
mtklein748ca3b2015-01-15 10:56:12 -0800447 // At this point we're back in single-threaded land.
mtklein@google.comd36522d2013-10-16 13:02:15 +0000448
mtklein2f64eec2015-01-15 14:20:41 -0800449 // This is not ideal for parallelism, but Windows seems crash-prone if we run
450 // these GPU tests in parallel with any GPU Src/Sink work. Everyone else seems fine.
451#if defined(SK_BUILD_FOR_WIN32)
452 for (int i = 0; i < gGPUTests.count(); i++) {
453 run_test(&gGPUTests[i]);
454 }
455#endif
456
457 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -0800458 JsonWriter::DumpJson();
459
460 if (gFailures.count() > 0) {
461 SkDebugf("Failures:\n");
462 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -0800463 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800464 }
465 SkDebugf("%d failures\n", gFailures.count());
466 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800467 }
mtklein748ca3b2015-01-15 10:56:12 -0800468 if (gPending > 0) {
469 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
470 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800471 }
mtklein748ca3b2015-01-15 10:56:12 -0800472 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000473}
jcgregorio3b27ade2014-11-13 08:06:40 -0800474
475#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
476int main(int argc, char** argv) {
477 SkCommandLineFlags::Parse(argc, argv);
478 return dm_main();
479}
480#endif