blob: 708d8558f33fb28c63c1e76a3776b0861200ab9f [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) {
mtkleina17241b2015-01-23 05:48:00 -080048 int32_t pending = sk_atomic_dec(&gPending)-1;
mtklein748ca3b2015-01-15 10:56:12 -080049 SkDebugf("%s(%4dMB %5d) %s\t%s %s %s ", FLAGS_verbose ? "\n" : kSkOverwriteLine
50 , sk_tools::getMaxResidentSetSizeMB()
mtkleina17241b2015-01-23 05:48:00 -080051 , pending
mtklein748ca3b2015-01-15 10:56:12 -080052 , HumanizeMs(ms).c_str()
53 , config.c_str()
54 , src.c_str()
55 , name.c_str());
mtkleina17241b2015-01-23 05:48:00 -080056 // We write our dm.json file every once in a while in case we crash.
57 // Notice this also handles the final dm.json when pending == 0.
58 if (pending % 500 == 0) {
59 JsonWriter::DumpJson();
60 }
mtklein@google.comd36522d2013-10-16 13:02:15 +000061}
62
mtklein748ca3b2015-01-15 10:56:12 -080063/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -080064
mtklein748ca3b2015-01-15 10:56:12 -080065template <typename T>
66struct Tagged : public SkAutoTDelete<T> { const char* tag; };
67
68static const bool kMemcpyOK = true;
69
70static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs;
71static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks;
72
73static void push_src(const char* tag, Src* s) {
74 SkAutoTDelete<Src> src(s);
75 if (FLAGS_src.contains(tag) &&
76 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
77 Tagged<Src>& s = gSrcs.push_back();
78 s.reset(src.detach());
79 s.tag = tag;
mtklein114c3cd2015-01-15 10:15:02 -080080 }
mtklein748ca3b2015-01-15 10:56:12 -080081}
mtklein114c3cd2015-01-15 10:15:02 -080082
mtklein748ca3b2015-01-15 10:56:12 -080083static void gather_srcs() {
84 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
85 push_src("gm", new GMSrc(r->factory()));
86 }
87 if (!FLAGS_skps.isEmpty()) {
88 SkOSFile::Iter it(FLAGS_skps[0], "skp");
89 for (SkString file; it.next(&file); ) {
90 push_src("skp", new SKPSrc(SkOSPath::Join(FLAGS_skps[0], file.c_str())));
mtklein114c3cd2015-01-15 10:15:02 -080091 }
92 }
mtklein748ca3b2015-01-15 10:56:12 -080093 if (!FLAGS_images.isEmpty()) {
94 const char* exts[] = {
95 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
96 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
97 };
98 for (size_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
99 SkOSFile::Iter it(FLAGS_images[0], exts[i]);
100 for (SkString file; it.next(&file); ) {
101 SkString path = SkOSPath::Join(FLAGS_images[0], file.c_str());
mtklein9264a952015-01-20 10:11:53 -0800102 push_src("image", new ImageSrc(path)); // Decode entire image.
103 push_src("image", new ImageSrc(path, 5)); // Decode 5 random subsets.
mtklein114c3cd2015-01-15 10:15:02 -0800104 }
mtklein709d2c32015-01-15 08:30:25 -0800105 }
mtklein709d2c32015-01-15 08:30:25 -0800106 }
107}
108
mtklein748ca3b2015-01-15 10:56:12 -0800109static GrGLStandard get_gpu_api() {
110 if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; }
111 if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; }
112 return kNone_GrGLStandard;
mtklein709d2c32015-01-15 08:30:25 -0800113}
114
mtklein748ca3b2015-01-15 10:56:12 -0800115static void push_sink(const char* tag, Sink* s) {
116 SkAutoTDelete<Sink> sink(s);
117 if (!FLAGS_config.contains(tag)) {
118 return;
mtklein114c3cd2015-01-15 10:15:02 -0800119 }
mtklein748ca3b2015-01-15 10:56:12 -0800120 // Try a noop Src as a canary. If it fails, skip this sink.
121 struct : public Src {
122 Error draw(SkCanvas*) const SK_OVERRIDE { return ""; }
123 SkISize size() const SK_OVERRIDE { return SkISize::Make(16, 16); }
124 Name name() const SK_OVERRIDE { return "noop"; }
125 } noop;
mtklein114c3cd2015-01-15 10:15:02 -0800126
mtklein748ca3b2015-01-15 10:56:12 -0800127 SkBitmap bitmap;
128 SkDynamicMemoryWStream stream;
129 Error err = sink->draw(noop, &bitmap, &stream);
130 if (!err.isEmpty()) {
131 SkDebugf("Skipping %s: %s\n", tag, err.c_str());
mtklein114c3cd2015-01-15 10:15:02 -0800132 return;
133 }
134
mtklein748ca3b2015-01-15 10:56:12 -0800135 Tagged<Sink>& ts = gSinks.push_back();
136 ts.reset(sink.detach());
137 ts.tag = tag;
138}
139
140static bool gpu_supported() {
141#if SK_SUPPORT_GPU
142 return FLAGS_gpu;
143#else
144 return false;
145#endif
146}
147
148static Sink* create_sink(const char* tag) {
149#define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); }
150 if (gpu_supported()) {
mtklein82d28432015-01-15 12:46:02 -0800151 typedef GrContextFactory Gr;
mtklein748ca3b2015-01-15 10:56:12 -0800152 const GrGLStandard api = get_gpu_api();
mtklein82d28432015-01-15 12:46:02 -0800153 SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading);
154 SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading);
155 SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading);
156 SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading);
157 SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading);
158 SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading);
159 SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading);
160 SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800161 #if SK_ANGLE
mtklein82d28432015-01-15 12:46:02 -0800162 SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800163 #endif
164 #if SK_MESA
mtklein82d28432015-01-15 12:46:02 -0800165 SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800166 #endif
mtklein114c3cd2015-01-15 10:15:02 -0800167 }
mtklein748ca3b2015-01-15 10:56:12 -0800168
169 if (FLAGS_cpu) {
170 SINK("565", RasterSink, kRGB_565_SkColorType);
171 SINK("8888", RasterSink, kN32_SkColorType);
mtklein19f30602015-01-20 13:34:39 -0800172 SINK("pdf", PDFSink);
mtklein748ca3b2015-01-15 10:56:12 -0800173 }
174#undef SINK
175 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800176}
177
mtklein748ca3b2015-01-15 10:56:12 -0800178static Sink* create_via(const char* tag, Sink* wrapped) {
179#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); }
mtklein7edca212015-01-21 13:18:51 -0800180 VIA("pipe", ViaPipe, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800181 VIA("serialize", ViaSerialization, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800182 VIA("tiles", ViaTiles, 256, 256, NULL, wrapped);
183 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800184
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
mtklein55e88b22015-01-21 15:50:13 -0800362static SkTDArray<skiatest::Test> gThreadedTests, 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()) {
mtklein55e88b22015-01-21 15:50:13 -0800377 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -0800378 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -0800379 gThreadedTests.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) {
mtklein55e88b22015-01-21 15:50:13 -0800398 GrContextFactory factory;
399 test->proc(&reporter, &factory);
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
mtklein55e88b22015-01-21 15:50:13 -0800407// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
408static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
409 run_enclave(tasks);
410 for (int i = 0; i < gGPUTests.count(); i++) {
411 run_test(&gGPUTests[i]);
412 }
413}
414
jcgregorio3b27ade2014-11-13 08:06:40 -0800415int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700416int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800417 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000418 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700419 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000420
mtklein748ca3b2015-01-15 10:56:12 -0800421 gather_srcs();
422 gather_sinks();
423 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000424
mtklein55e88b22015-01-21 15:50:13 -0800425 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -0800426 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -0800427 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -0800428
429 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
430 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -0800431 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -0800432 SkTArray<Task> enclaves[kNumEnclaves];
433 for (int j = 0; j < gSinks.count(); j++) {
434 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
435 for (int i = 0; i < gSrcs.count(); i++) {
436 tasks.push_back(Task(gSrcs[i], gSinks[j]));
437 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000438 }
439
mtklein748ca3b2015-01-15 10:56:12 -0800440 SkTaskGroup tg;
mtklein55e88b22015-01-21 15:50:13 -0800441 tg.batch(run_test, gThreadedTests.begin(), gThreadedTests.count());
442 for (int i = 0; i < kNumEnclaves; i++) {
443 switch(i) {
444 case kAnyThread_Enclave:
445 tg.batch(Task::Run, enclaves[i].begin(), enclaves[i].count());
446 break;
447 case kGPU_Enclave:
448 tg.add(run_enclave_and_gpu_tests, &enclaves[i]);
449 break;
450 default:
451 tg.add(run_enclave, &enclaves[i]);
452 break;
mtklein82d28432015-01-15 12:46:02 -0800453 }
mtklein55e88b22015-01-21 15:50:13 -0800454 }
mtklein748ca3b2015-01-15 10:56:12 -0800455 tg.wait();
mtklein748ca3b2015-01-15 10:56:12 -0800456 // At this point we're back in single-threaded land.
mtklein@google.comd36522d2013-10-16 13:02:15 +0000457
mtklein2f64eec2015-01-15 14:20:41 -0800458 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -0800459 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