blob: ae544058d3effe071d6603197f0665f1646b72b2 [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__); }
174 VIA("serialize", ViaSerialization, wrapped);
175
176 VIA("tiles", ViaTiles, 256, 256, NULL, wrapped);
177 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
178
179 const int xp = SkGPipeWriter::kCrossProcess_Flag,
180 sa = xp | SkGPipeWriter::kSharedAddressSpace_Flag;
181 VIA("pipe", ViaPipe, 0, wrapped);
182 VIA("pipe_xp", ViaPipe, xp, wrapped);
183 VIA("pipe_sa", ViaPipe, sa, wrapped);
184
185 if (FLAGS_matrix.count() == 9) {
186 SkMatrix m;
187 for (int i = 0; i < 9; i++) {
188 m[i] = (SkScalar)atof(FLAGS_matrix[i]);
189 }
190 VIA("matrix", ViaMatrix, m, wrapped);
191 }
192#undef VIA
193 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800194}
195
mtklein748ca3b2015-01-15 10:56:12 -0800196static void gather_sinks() {
197 for (int i = 0; i < FLAGS_config.count(); i++) {
198 const char* config = FLAGS_config[i];
199 SkTArray<SkString> parts;
200 SkStrSplit(config, "-", &parts);
201
202 Sink* sink = NULL;
203 for (int i = parts.count(); i-- > 0;) {
204 const char* part = parts[i].c_str();
205 Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink);
206 if (next == NULL) {
207 SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part);
208 delete sink;
209 sink = NULL;
210 break;
211 }
212 sink = next;
213 }
214 if (sink) {
215 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800216 }
217 }
218}
mtklein709d2c32015-01-15 08:30:25 -0800219
mtkleina2ef6422015-01-15 13:44:22 -0800220static bool match(const char* needle, const char* haystack) {
221 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle);
222}
223
224static ImplicitString is_blacklisted(const char* sink, const char* src, const char* name) {
225 for (int i = 0; i < FLAGS_blacklist.count() - 2; i += 3) {
226 if (match(FLAGS_blacklist[i+0], sink) &&
227 match(FLAGS_blacklist[i+1], src) &&
228 match(FLAGS_blacklist[i+2], name)) {
229 return SkStringPrintf("%s %s %s",
230 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], FLAGS_blacklist[i+2]);
231 }
232 }
233 return "";
234}
235
mtklein748ca3b2015-01-15 10:56:12 -0800236// The finest-grained unit of work we can run: draw a single Src into a single Sink,
237// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
238struct Task {
239 Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {}
240 const Tagged<Src>& src;
241 const Tagged<Sink>& sink;
242
243 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800244 SkString name = task->src->name();
245 SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag, name.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800246 WallTimer timer;
247 timer.start();
mtkleina2ef6422015-01-15 13:44:22 -0800248 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800249 SkBitmap bitmap;
250 SkDynamicMemoryWStream stream;
251 Error err = task->sink->draw(*task->src, &bitmap, &stream);
252 if (!err.isEmpty()) {
253 fail(SkStringPrintf("%s %s %s: %s",
254 task->sink.tag,
255 task->src.tag,
mtkleina2ef6422015-01-15 13:44:22 -0800256 name.c_str(),
mtklein748ca3b2015-01-15 10:56:12 -0800257 err.c_str()));
258 }
259 if (!FLAGS_writePath.isEmpty()) {
260 const char* ext = task->sink->fileExtension();
261 if (stream.bytesWritten() == 0) {
262 SkMemoryStream pixels(bitmap.getPixels(), bitmap.getSize());
263 WriteToDisk(*task, &pixels, bitmap.getSize(), &bitmap, ext);
264 } else {
265 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
266 WriteToDisk(*task, data, data->getLength(), NULL, ext);
267 }
268 }
269 }
270 timer.end();
mtkleina2ef6422015-01-15 13:44:22 -0800271 if (!whyBlacklisted.isEmpty()) {
272 name.appendf(" (--blacklist, %s)", whyBlacklisted.c_str());
273 }
274 done(timer.fWall, task->sink.tag, task->src.tag, name);
mtklein748ca3b2015-01-15 10:56:12 -0800275 }
276
277 static void WriteToDisk(const Task& task,
278 SkStream* data, size_t len,
279 const SkBitmap* bitmap,
280 const char* ext) {
281 SkMD5 hash;
282 hash.writeStream(data, len);
283 SkMD5::Digest digest;
284 hash.finish(digest);
285
286 JsonWriter::BitmapResult result;
287 result.name = task.src->name();
288 result.config = task.sink.tag;
289 result.sourceType = task.src.tag;
290 result.ext = ext;
291 for (int i = 0; i < 16; i++) {
292 result.md5.appendf("%02x", digest.data[i]);
293 }
294 JsonWriter::AddBitmapResult(result);
295
296 const char* dir = FLAGS_writePath[0];
297 if (0 == strcmp(dir, "@")) { // Needed for iOS.
298 dir = FLAGS_resourcePath[0];
299 }
300 sk_mkdir(dir);
301
302 SkString path;
303 if (FLAGS_nameByHash) {
304 path = SkOSPath::Join(dir, result.md5.c_str());
305 path.append(".");
306 path.append(ext);
307 if (sk_exists(path.c_str())) {
308 return; // Content-addressed. If it exists already, we're done.
309 }
310 } else {
311 path = SkOSPath::Join(dir, task.sink.tag);
312 sk_mkdir(path.c_str());
313 path = SkOSPath::Join(path.c_str(), task.src.tag);
314 sk_mkdir(path.c_str());
315 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
316 path.append(".");
317 path.append(ext);
318 }
319
320 SkFILEWStream file(path.c_str());
321 if (!file.isValid()) {
322 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
323 return;
324 }
325
326 data->rewind();
327 if (bitmap) {
328 // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first.
329 SkBitmap converted;
330 if (bitmap->info().colorType() == kAlpha_8_SkColorType) {
331 if (!bitmap->copyTo(&converted, kN32_SkColorType)) {
332 fail("Can't convert A8 to 8888.\n");
333 return;
334 }
335 bitmap = &converted;
336 }
337 if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) {
338 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
339 return;
340 }
341 } else {
342 if (!file.writeStream(data, len)) {
343 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
344 return;
345 }
346 }
347 }
348};
349
350// Run all tasks in the same enclave serially on the same thread.
351// They can't possibly run concurrently with each other.
352static void run_enclave(SkTArray<Task>* tasks) {
353 for (int i = 0; i < tasks->count(); i++) {
354 Task::Run(tasks->begin() + i);
355 }
356}
357
358/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
359
360// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
361
halcanary87f3ba42015-01-20 09:30:20 -0800362static SkTDArray<skiatest::Test> gCPUTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800363
364static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -0800365 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -0800366 return;
367 }
halcanary87f3ba42015-01-20 09:30:20 -0800368 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r;
369 r = r->next()) {
370 // Despite its name, factory() is returning a reference to
371 // link-time static const POD data.
372 const skiatest::Test& test = r->factory();
373 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800374 continue;
375 }
halcanary87f3ba42015-01-20 09:30:20 -0800376 if (test.needsGpu && gpu_supported()) {
377 gGPUTests.push(test);
378 } else if (!test.needsGpu && FLAGS_cpu) {
379 gCPUTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800380 }
mtklein748ca3b2015-01-15 10:56:12 -0800381 }
382}
383
halcanary87f3ba42015-01-20 09:30:20 -0800384static void run_test(skiatest::Test* test) {
385 struct : public skiatest::Reporter {
386 void reportFailed(const skiatest::Failure& failure) SK_OVERRIDE {
387 fail(failure.toString());
388 JsonWriter::AddTestFailure(failure);
389 }
390 bool allowExtendedTest() const SK_OVERRIDE {
391 return FLAGS_pathOpsExtended;
392 }
393 bool verbose() const SK_OVERRIDE { return FLAGS_veryVerbose; }
394 } reporter;
mtklein748ca3b2015-01-15 10:56:12 -0800395 WallTimer timer;
396 timer.start();
mtklein748ca3b2015-01-15 10:56:12 -0800397 if (!FLAGS_dryRun) {
halcanary87f3ba42015-01-20 09:30:20 -0800398 test->proc(&reporter, GetThreadLocalGrContextFactory());
mtklein748ca3b2015-01-15 10:56:12 -0800399 }
400 timer.end();
halcanary87f3ba42015-01-20 09:30:20 -0800401 done(timer.fWall, "unit", "test", test->name);
mtklein748ca3b2015-01-15 10:56:12 -0800402}
403
404/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
405
jcgregorio3b27ade2014-11-13 08:06:40 -0800406int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700407int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800408 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000409 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700410 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000411
mtklein748ca3b2015-01-15 10:56:12 -0800412 gather_srcs();
413 gather_sinks();
414 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000415
mtklein82d28432015-01-15 12:46:02 -0800416 gPending = gSrcs.count() * gSinks.count() + gCPUTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -0800417 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein82d28432015-01-15 12:46:02 -0800418 gSrcs.count(), gSinks.count(), gCPUTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -0800419
420 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
421 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -0800422 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -0800423 SkTArray<Task> enclaves[kNumEnclaves];
424 for (int j = 0; j < gSinks.count(); j++) {
425 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
426 for (int i = 0; i < gSrcs.count(); i++) {
427 tasks.push_back(Task(gSrcs[i], gSinks[j]));
428 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000429 }
430
mtklein748ca3b2015-01-15 10:56:12 -0800431 SK_COMPILE_ASSERT(kAnyThread_Enclave == 0, AnyThreadZero);
432 SkTaskGroup tg;
433 tg.batch( Task::Run, enclaves[0].begin(), enclaves[0].count());
434 tg.batch(run_enclave, enclaves+1, kNumEnclaves-1);
mtklein82d28432015-01-15 12:46:02 -0800435 tg.batch( run_test, gCPUTests.begin(), gCPUTests.count());
436 if (FLAGS_gpu_threading) {
437 tg.batch(run_test, gGPUTests.begin(), gGPUTests.count());
mtklein2f64eec2015-01-15 14:20:41 -0800438 #if !defined(SK_BUILD_FOR_WIN32)
mtklein82d28432015-01-15 12:46:02 -0800439 } else {
440 for (int i = 0; i < gGPUTests.count(); i++) {
441 run_test(&gGPUTests[i]);
442 }
mtklein2f64eec2015-01-15 14:20:41 -0800443 #endif
mtklein82d28432015-01-15 12:46:02 -0800444 }
mtklein748ca3b2015-01-15 10:56:12 -0800445 tg.wait();
mtklein748ca3b2015-01-15 10:56:12 -0800446 // At this point we're back in single-threaded land.
mtklein@google.comd36522d2013-10-16 13:02:15 +0000447
mtklein2f64eec2015-01-15 14:20:41 -0800448 // This is not ideal for parallelism, but Windows seems crash-prone if we run
449 // these GPU tests in parallel with any GPU Src/Sink work. Everyone else seems fine.
450#if defined(SK_BUILD_FOR_WIN32)
451 for (int i = 0; i < gGPUTests.count(); i++) {
452 run_test(&gGPUTests[i]);
453 }
454#endif
455
456 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -0800457 JsonWriter::DumpJson();
458
459 if (gFailures.count() > 0) {
460 SkDebugf("Failures:\n");
461 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -0800462 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800463 }
464 SkDebugf("%d failures\n", gFailures.count());
465 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800466 }
mtklein748ca3b2015-01-15 10:56:12 -0800467 if (gPending > 0) {
468 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
469 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800470 }
mtklein748ca3b2015-01-15 10:56:12 -0800471 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000472}
jcgregorio3b27ade2014-11-13 08:06:40 -0800473
474#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
475int main(int argc, char** argv) {
476 SkCommandLineFlags::Parse(argc, argv);
477 return dm_main();
478}
479#endif