blob: 45d20b86f0439889dff61f881f44822b926d47b4 [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.");
mtkleine1315522015-01-15 13:58:56 -080018DEFINE_string(src, "gm skp image subset", "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());
97 push_src("image", new ImageSrc(path)); // Decode entire image.
98 push_src("subset", 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);
167 // TODO(mtklein): reenable once skiagold can handle .pdf uploads.
168 //SINK("pdf", PDFSink);
169 }
170#undef SINK
171 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800172}
173
mtklein748ca3b2015-01-15 10:56:12 -0800174static Sink* create_via(const char* tag, Sink* wrapped) {
175#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); }
176 VIA("serialize", ViaSerialization, wrapped);
177
178 VIA("tiles", ViaTiles, 256, 256, NULL, wrapped);
179 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
180
181 const int xp = SkGPipeWriter::kCrossProcess_Flag,
182 sa = xp | SkGPipeWriter::kSharedAddressSpace_Flag;
183 VIA("pipe", ViaPipe, 0, wrapped);
184 VIA("pipe_xp", ViaPipe, xp, wrapped);
185 VIA("pipe_sa", ViaPipe, sa, wrapped);
186
187 if (FLAGS_matrix.count() == 9) {
188 SkMatrix m;
189 for (int i = 0; i < 9; i++) {
190 m[i] = (SkScalar)atof(FLAGS_matrix[i]);
191 }
192 VIA("matrix", ViaMatrix, m, wrapped);
193 }
194#undef VIA
195 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800196}
197
mtklein748ca3b2015-01-15 10:56:12 -0800198static void gather_sinks() {
199 for (int i = 0; i < FLAGS_config.count(); i++) {
200 const char* config = FLAGS_config[i];
201 SkTArray<SkString> parts;
202 SkStrSplit(config, "-", &parts);
203
204 Sink* sink = NULL;
205 for (int i = parts.count(); i-- > 0;) {
206 const char* part = parts[i].c_str();
207 Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink);
208 if (next == NULL) {
209 SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part);
210 delete sink;
211 sink = NULL;
212 break;
213 }
214 sink = next;
215 }
216 if (sink) {
217 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800218 }
219 }
220}
mtklein709d2c32015-01-15 08:30:25 -0800221
mtkleina2ef6422015-01-15 13:44:22 -0800222static bool match(const char* needle, const char* haystack) {
223 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle);
224}
225
226static ImplicitString is_blacklisted(const char* sink, const char* src, const char* name) {
227 for (int i = 0; i < FLAGS_blacklist.count() - 2; i += 3) {
228 if (match(FLAGS_blacklist[i+0], sink) &&
229 match(FLAGS_blacklist[i+1], src) &&
230 match(FLAGS_blacklist[i+2], name)) {
231 return SkStringPrintf("%s %s %s",
232 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], FLAGS_blacklist[i+2]);
233 }
234 }
235 return "";
236}
237
mtklein748ca3b2015-01-15 10:56:12 -0800238// The finest-grained unit of work we can run: draw a single Src into a single Sink,
239// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
240struct Task {
241 Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {}
242 const Tagged<Src>& src;
243 const Tagged<Sink>& sink;
244
245 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800246 SkString name = task->src->name();
247 SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag, name.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800248 WallTimer timer;
249 timer.start();
mtkleina2ef6422015-01-15 13:44:22 -0800250 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800251 SkBitmap bitmap;
252 SkDynamicMemoryWStream stream;
253 Error err = task->sink->draw(*task->src, &bitmap, &stream);
254 if (!err.isEmpty()) {
255 fail(SkStringPrintf("%s %s %s: %s",
256 task->sink.tag,
257 task->src.tag,
mtkleina2ef6422015-01-15 13:44:22 -0800258 name.c_str(),
mtklein748ca3b2015-01-15 10:56:12 -0800259 err.c_str()));
260 }
261 if (!FLAGS_writePath.isEmpty()) {
262 const char* ext = task->sink->fileExtension();
263 if (stream.bytesWritten() == 0) {
264 SkMemoryStream pixels(bitmap.getPixels(), bitmap.getSize());
265 WriteToDisk(*task, &pixels, bitmap.getSize(), &bitmap, ext);
266 } else {
267 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
268 WriteToDisk(*task, data, data->getLength(), NULL, ext);
269 }
270 }
271 }
272 timer.end();
mtkleina2ef6422015-01-15 13:44:22 -0800273 if (!whyBlacklisted.isEmpty()) {
274 name.appendf(" (--blacklist, %s)", whyBlacklisted.c_str());
275 }
276 done(timer.fWall, task->sink.tag, task->src.tag, name);
mtklein748ca3b2015-01-15 10:56:12 -0800277 }
278
279 static void WriteToDisk(const Task& task,
280 SkStream* data, size_t len,
281 const SkBitmap* bitmap,
282 const char* ext) {
283 SkMD5 hash;
284 hash.writeStream(data, len);
285 SkMD5::Digest digest;
286 hash.finish(digest);
287
288 JsonWriter::BitmapResult result;
289 result.name = task.src->name();
290 result.config = task.sink.tag;
291 result.sourceType = task.src.tag;
292 result.ext = ext;
293 for (int i = 0; i < 16; i++) {
294 result.md5.appendf("%02x", digest.data[i]);
295 }
296 JsonWriter::AddBitmapResult(result);
297
298 const char* dir = FLAGS_writePath[0];
299 if (0 == strcmp(dir, "@")) { // Needed for iOS.
300 dir = FLAGS_resourcePath[0];
301 }
302 sk_mkdir(dir);
303
304 SkString path;
305 if (FLAGS_nameByHash) {
306 path = SkOSPath::Join(dir, result.md5.c_str());
307 path.append(".");
308 path.append(ext);
309 if (sk_exists(path.c_str())) {
310 return; // Content-addressed. If it exists already, we're done.
311 }
312 } else {
313 path = SkOSPath::Join(dir, task.sink.tag);
314 sk_mkdir(path.c_str());
315 path = SkOSPath::Join(path.c_str(), task.src.tag);
316 sk_mkdir(path.c_str());
317 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
318 path.append(".");
319 path.append(ext);
320 }
321
322 SkFILEWStream file(path.c_str());
323 if (!file.isValid()) {
324 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
325 return;
326 }
327
328 data->rewind();
329 if (bitmap) {
330 // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first.
331 SkBitmap converted;
332 if (bitmap->info().colorType() == kAlpha_8_SkColorType) {
333 if (!bitmap->copyTo(&converted, kN32_SkColorType)) {
334 fail("Can't convert A8 to 8888.\n");
335 return;
336 }
337 bitmap = &converted;
338 }
339 if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) {
340 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
341 return;
342 }
343 } else {
344 if (!file.writeStream(data, len)) {
345 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
346 return;
347 }
348 }
349 }
350};
351
352// Run all tasks in the same enclave serially on the same thread.
353// They can't possibly run concurrently with each other.
354static void run_enclave(SkTArray<Task>* tasks) {
355 for (int i = 0; i < tasks->count(); i++) {
356 Task::Run(tasks->begin() + i);
357 }
358}
359
360/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
361
362// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
363
halcanary87f3ba42015-01-20 09:30:20 -0800364static SkTDArray<skiatest::Test> gCPUTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800365
366static void gather_tests() {
367 if (!FLAGS_tests) {
368 return;
369 }
halcanary87f3ba42015-01-20 09:30:20 -0800370 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r;
371 r = r->next()) {
372 // Despite its name, factory() is returning a reference to
373 // link-time static const POD data.
374 const skiatest::Test& test = r->factory();
375 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800376 continue;
377 }
halcanary87f3ba42015-01-20 09:30:20 -0800378 if (test.needsGpu && gpu_supported()) {
379 gGPUTests.push(test);
380 } else if (!test.needsGpu && FLAGS_cpu) {
381 gCPUTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800382 }
mtklein748ca3b2015-01-15 10:56:12 -0800383 }
384}
385
halcanary87f3ba42015-01-20 09:30:20 -0800386static void run_test(skiatest::Test* test) {
387 struct : public skiatest::Reporter {
388 void reportFailed(const skiatest::Failure& failure) SK_OVERRIDE {
389 fail(failure.toString());
390 JsonWriter::AddTestFailure(failure);
391 }
392 bool allowExtendedTest() const SK_OVERRIDE {
393 return FLAGS_pathOpsExtended;
394 }
395 bool verbose() const SK_OVERRIDE { return FLAGS_veryVerbose; }
396 } reporter;
mtklein748ca3b2015-01-15 10:56:12 -0800397 WallTimer timer;
398 timer.start();
mtklein748ca3b2015-01-15 10:56:12 -0800399 if (!FLAGS_dryRun) {
halcanary87f3ba42015-01-20 09:30:20 -0800400 test->proc(&reporter, GetThreadLocalGrContextFactory());
mtklein748ca3b2015-01-15 10:56:12 -0800401 }
402 timer.end();
halcanary87f3ba42015-01-20 09:30:20 -0800403 done(timer.fWall, "unit", "test", test->name);
mtklein748ca3b2015-01-15 10:56:12 -0800404}
405
406/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
407
jcgregorio3b27ade2014-11-13 08:06:40 -0800408int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700409int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800410 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000411 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700412 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000413
mtklein748ca3b2015-01-15 10:56:12 -0800414 gather_srcs();
415 gather_sinks();
416 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000417
mtklein82d28432015-01-15 12:46:02 -0800418 gPending = gSrcs.count() * gSinks.count() + gCPUTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -0800419 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein82d28432015-01-15 12:46:02 -0800420 gSrcs.count(), gSinks.count(), gCPUTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -0800421
422 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
423 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -0800424 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -0800425 SkTArray<Task> enclaves[kNumEnclaves];
426 for (int j = 0; j < gSinks.count(); j++) {
427 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
428 for (int i = 0; i < gSrcs.count(); i++) {
429 tasks.push_back(Task(gSrcs[i], gSinks[j]));
430 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000431 }
432
mtklein748ca3b2015-01-15 10:56:12 -0800433 SK_COMPILE_ASSERT(kAnyThread_Enclave == 0, AnyThreadZero);
434 SkTaskGroup tg;
435 tg.batch( Task::Run, enclaves[0].begin(), enclaves[0].count());
436 tg.batch(run_enclave, enclaves+1, kNumEnclaves-1);
mtklein82d28432015-01-15 12:46:02 -0800437 tg.batch( run_test, gCPUTests.begin(), gCPUTests.count());
438 if (FLAGS_gpu_threading) {
439 tg.batch(run_test, gGPUTests.begin(), gGPUTests.count());
mtklein2f64eec2015-01-15 14:20:41 -0800440 #if !defined(SK_BUILD_FOR_WIN32)
mtklein82d28432015-01-15 12:46:02 -0800441 } else {
442 for (int i = 0; i < gGPUTests.count(); i++) {
443 run_test(&gGPUTests[i]);
444 }
mtklein2f64eec2015-01-15 14:20:41 -0800445 #endif
mtklein82d28432015-01-15 12:46:02 -0800446 }
mtklein748ca3b2015-01-15 10:56:12 -0800447 tg.wait();
mtklein748ca3b2015-01-15 10:56:12 -0800448 // At this point we're back in single-threaded land.
mtklein@google.comd36522d2013-10-16 13:02:15 +0000449
mtklein2f64eec2015-01-15 14:20:41 -0800450 // This is not ideal for parallelism, but Windows seems crash-prone if we run
451 // these GPU tests in parallel with any GPU Src/Sink work. Everyone else seems fine.
452#if defined(SK_BUILD_FOR_WIN32)
453 for (int i = 0; i < gGPUTests.count(); i++) {
454 run_test(&gGPUTests[i]);
455 }
456#endif
457
458 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -0800459 JsonWriter::DumpJson();
460
461 if (gFailures.count() > 0) {
462 SkDebugf("Failures:\n");
463 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -0800464 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800465 }
466 SkDebugf("%d failures\n", gFailures.count());
467 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800468 }
mtklein748ca3b2015-01-15 10:56:12 -0800469 if (gPending > 0) {
470 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
471 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800472 }
mtklein748ca3b2015-01-15 10:56:12 -0800473 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000474}
jcgregorio3b27ade2014-11-13 08:06:40 -0800475
476#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
477int main(int argc, char** argv) {
478 SkCommandLineFlags::Parse(argc, argv);
479 return dm_main();
480}
481#endif