blob: c0fccaaa2c7bfcee54624fb32f02af5f4771161a [file] [log] [blame]
scroggo478652e2015-03-25 07:11:02 -07001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
jcgregorio3b27ade2014-11-13 08:06:40 -08008#include "CrashHandler.h"
mtklein748ca3b2015-01-15 10:56:12 -08009#include "DMJsonWriter.h"
10#include "DMSrcSink.h"
tomhudsoneebc39a2015-02-23 12:18:05 -080011#include "DMSrcSinkAndroid.h"
mtklein748ca3b2015-01-15 10:56:12 -080012#include "OverwriteLine.h"
13#include "ProcStats.h"
14#include "SkBBHFactory.h"
mtklein62bd1a62015-01-27 14:46:26 -080015#include "SkChecksum.h"
caryclark17f0b6d2014-07-22 10:15:34 -070016#include "SkCommonFlags.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000017#include "SkForceLinking.h"
18#include "SkGraphics.h"
mtkleine67164d2015-02-02 13:24:37 -080019#include "SkInstCnt.h"
mtklein748ca3b2015-01-15 10:56:12 -080020#include "SkMD5.h"
mtklein1d0f1642014-09-08 08:05:18 -070021#include "SkOSFile.h"
mtkleina82f5622015-02-20 12:30:19 -080022#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070023#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070024#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000025#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080026#include "Timer.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000027
djsollen54416de2015-04-03 07:24:48 -070028DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080029DEFINE_bool(nameByHash, false,
30 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070031 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080032DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080033DEFINE_string(matrix, "1 0 0 1",
34 "2x2 scale+skew matrix to apply or upright when using "
35 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080036DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000037
mtkleina2ef6422015-01-15 13:44:22 -080038DEFINE_string(blacklist, "",
djsollen54416de2015-04-03 07:24:48 -070039 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n"
40 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
41 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.");
mtkleina2ef6422015-01-15 13:44:22 -080042
mtklein62bd1a62015-01-27 14:46:26 -080043DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
44
borenet09ed4802015-04-03 14:15:33 -070045DEFINE_string(uninterestingHashesFile, "",
46 "File containing a list of uninteresting hashes. If a result hashes to something in "
47 "this list, no image is written for that result.");
48
mtklein@google.comd36522d2013-10-16 13:02:15 +000049__SK_FORCE_IMAGE_DECODER_LINKING;
mtklein748ca3b2015-01-15 10:56:12 -080050using namespace DM;
mtklein@google.comd36522d2013-10-16 13:02:15 +000051
mtklein748ca3b2015-01-15 10:56:12 -080052/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
53
54SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
55static SkTArray<SkString> gFailures;
56
57static void fail(ImplicitString err) {
58 SkAutoMutexAcquire lock(gFailuresMutex);
59 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
60 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -080061}
62
mtkleinb37cb412015-03-18 05:27:14 -070063static int32_t gPending = 0; // Atomic. Total number of running and queued tasks.
64
65SK_DECLARE_STATIC_MUTEX(gRunningMutex);
66static SkTArray<SkString> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -080067
mtkleinb9eb4ac2015-02-02 18:26:03 -080068static void done(double ms,
djsollen54416de2015-04-03 07:24:48 -070069 ImplicitString config, ImplicitString src, ImplicitString srcOptions,
70 ImplicitString name, ImplicitString note, ImplicitString log) {
71 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
72 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -070073 {
74 SkAutoMutexAcquire lock(gRunningMutex);
75 for (int i = 0; i < gRunning.count(); i++) {
76 if (gRunning[i] == id) {
77 gRunning.removeShuffle(i);
78 break;
79 }
80 }
81 }
82 if (!FLAGS_verbose) {
83 note = "";
84 }
mtkleinb9eb4ac2015-02-02 18:26:03 -080085 if (!log.isEmpty()) {
86 log.prepend("\n");
87 }
mtklein6dee2ad2015-02-05 09:53:44 -080088 auto pending = sk_atomic_dec(&gPending)-1;
mtkleinb37cb412015-03-18 05:27:14 -070089 SkDebugf("%s(%4dMB %5d) %s\t%s%s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine
90 , sk_tools::getBestResidentSetSizeMB()
91 , pending
92 , HumanizeMs(ms).c_str()
93 , id.c_str()
94 , note.c_str()
95 , log.c_str());
mtkleina17241b2015-01-23 05:48:00 -080096 // We write our dm.json file every once in a while in case we crash.
97 // Notice this also handles the final dm.json when pending == 0.
98 if (pending % 500 == 0) {
99 JsonWriter::DumpJson();
100 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000101}
102
djsollen54416de2015-04-03 07:24:48 -0700103static void start(ImplicitString config, ImplicitString src,
104 ImplicitString srcOptions, ImplicitString name) {
105 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
106 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700107 SkAutoMutexAcquire lock(gRunningMutex);
108 gRunning.push_back(id);
109}
110
mtklein748ca3b2015-01-15 10:56:12 -0800111/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800112
mtklein62bd1a62015-01-27 14:46:26 -0800113struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800114 Gold() : SkString("") {}
djsollen54416de2015-04-03 07:24:48 -0700115 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions,
116 ImplicitString name, ImplicitString md5)
mtklein62bd1a62015-01-27 14:46:26 -0800117 : SkString("") {
118 this->append(sink);
119 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700120 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800121 this->append(name);
122 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800123 }
mtklein02f46cf2015-03-20 13:48:42 -0700124 static uint32_t Hash(const Gold& g) { return SkGoodHash((const SkString&)g); }
mtklein62bd1a62015-01-27 14:46:26 -0800125};
mtkleina82f5622015-02-20 12:30:19 -0800126static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800127
128static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700129 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800130}
131
132static void gather_gold() {
133 if (!FLAGS_readPath.isEmpty()) {
134 SkString path(FLAGS_readPath[0]);
135 path.append("/dm.json");
136 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
137 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
138 }
139 }
140}
141
142/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
143
borenet09ed4802015-04-03 14:15:33 -0700144static SkTHashSet<SkString> gUninterestingHashes;
145
146static void gather_uninteresting_hashes() {
147 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
148 SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0]));
149 SkTArray<SkString> hashes;
150 SkStrSplit((const char*)data->data(), "\n", &hashes);
151 for (const SkString& hash : hashes) {
152 gUninterestingHashes.add(hash);
153 }
154 }
155}
156
157/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
158
mtklein748ca3b2015-01-15 10:56:12 -0800159template <typename T>
djsollen54416de2015-04-03 07:24:48 -0700160struct Tagged : public SkAutoTDelete<T> {
161 const char* tag;
162 const char* options;
163};
mtklein748ca3b2015-01-15 10:56:12 -0800164
165static const bool kMemcpyOK = true;
166
167static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs;
168static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks;
169
djsollen54416de2015-04-03 07:24:48 -0700170static void push_src(const char* tag, const char* options, Src* s) {
mtklein748ca3b2015-01-15 10:56:12 -0800171 SkAutoTDelete<Src> src(s);
172 if (FLAGS_src.contains(tag) &&
173 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
174 Tagged<Src>& s = gSrcs.push_back();
175 s.reset(src.detach());
176 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700177 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800178 }
mtklein748ca3b2015-01-15 10:56:12 -0800179}
mtklein114c3cd2015-01-15 10:15:02 -0800180
msarett438b2ad2015-04-09 12:43:10 -0700181static void push_codec_srcs(Path path) {
182 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
183 if (!encoded) {
184 SkDebugf("Couldn't read %s.", path.c_str());
185 return;
186 }
187 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
188 if (NULL == codec.get()) {
189 SkDebugf("Couldn't create codec for %s.", path.c_str());
190 return;
191 }
192
193 // Build additional test cases for images that decode natively to non-canvas types
194 switch(codec->getInfo().colorType()) {
195 case kGray_8_SkColorType:
djsollena669bc32015-04-14 13:47:51 -0700196 push_src("image", "codec_kGray8", new CodecSrc(path, CodecSrc::kNormal_Mode,
msarett438b2ad2015-04-09 12:43:10 -0700197 CodecSrc::kGrayscale_Always_DstColorType));
djsollena669bc32015-04-14 13:47:51 -0700198 push_src("image", "scanline_kGray8", new CodecSrc(path, CodecSrc::kScanline_Mode,
msarett438b2ad2015-04-09 12:43:10 -0700199 CodecSrc::kGrayscale_Always_DstColorType));
200 // Intentional fall through
201 // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8?
202 // Further discussion on this topic is at skbug.com/3683
203 case kIndex_8_SkColorType:
djsollena669bc32015-04-14 13:47:51 -0700204 push_src("image", "codec_kIndex8", new CodecSrc(path, CodecSrc::kNormal_Mode,
msarett438b2ad2015-04-09 12:43:10 -0700205 CodecSrc::kIndex8_Always_DstColorType));
msarett164d5b02015-04-14 05:37:36 -0700206 // FIXME: Need to implement scanline decoding for kIndex8.
207 //push_src("image", "scanline kIndex8", new CodecSrc(path, CodecSrc::kScanline_Mode,
208 // CodecSrc::kIndex8_Always_DstColorType));
msarett438b2ad2015-04-09 12:43:10 -0700209 break;
210 default:
211 // Do nothing
212 break;
213 }
214
215 // Decode all images to the canvas color type
216 push_src("image", "codec", new CodecSrc(path, CodecSrc::kNormal_Mode,
217 CodecSrc::kGetFromCanvas_DstColorType));
218 push_src("image", "scanline", new CodecSrc(path, CodecSrc::kScanline_Mode,
219 CodecSrc::kGetFromCanvas_DstColorType));
220}
221
scroggo9b77ddd2015-03-19 06:03:39 -0700222static bool codec_supported(const char* ext) {
223 // FIXME: Once other versions of SkCodec are available, we can add them to this
224 // list (and eventually we can remove this check once they are all supported).
msarett8c8f22a2015-04-01 06:58:48 -0700225 static const char* const exts[] = {
msarette16b04a2015-04-15 07:32:19 -0700226 "bmp", "gif", "jpg", "jpeg", "png", "ico", "wbmp",
227 "BMP", "GIF", "JPG", "JPEG", "PNG", "ICO", "WBMP"
msarett8c8f22a2015-04-01 06:58:48 -0700228 };
229
230 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
231 if (0 == strcmp(exts[i], ext)) {
232 return true;
233 }
234 }
235 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700236}
237
mtklein748ca3b2015-01-15 10:56:12 -0800238static void gather_srcs() {
239 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700240 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800241 }
halcanaryfc37ad12015-01-30 07:31:19 -0800242 for (int i = 0; i < FLAGS_skps.count(); i++) {
243 const char* path = FLAGS_skps[i];
244 if (sk_isdir(path)) {
245 SkOSFile::Iter it(path, "skp");
246 for (SkString file; it.next(&file); ) {
djsollen54416de2015-04-03 07:24:48 -0700247 push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str())));
halcanaryfc37ad12015-01-30 07:31:19 -0800248 }
249 } else {
djsollen54416de2015-04-03 07:24:48 -0700250 push_src("skp", "", new SKPSrc(path));
mtklein114c3cd2015-01-15 10:15:02 -0800251 }
252 }
halcanary23b03c32015-01-30 09:58:58 -0800253 static const char* const exts[] = {
254 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
255 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
256 };
257 for (int i = 0; i < FLAGS_images.count(); i++) {
258 const char* flag = FLAGS_images[i];
259 if (sk_isdir(flag)) {
260 for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) {
261 SkOSFile::Iter it(flag, exts[j]);
262 for (SkString file; it.next(&file); ) {
263 SkString path = SkOSPath::Join(flag, file.c_str());
djsollen54416de2015-04-03 07:24:48 -0700264 push_src("image", "decode", new ImageSrc(path)); // Decode entire image
265 push_src("image", "subset", new ImageSrc(path, 2)); // Decode into 2x2 subsets
scroggo9b77ddd2015-03-19 06:03:39 -0700266 if (codec_supported(exts[j])) {
msarett438b2ad2015-04-09 12:43:10 -0700267 push_codec_srcs(path);
scroggo9b77ddd2015-03-19 06:03:39 -0700268 }
halcanary23b03c32015-01-30 09:58:58 -0800269 }
mtklein114c3cd2015-01-15 10:15:02 -0800270 }
halcanary23b03c32015-01-30 09:58:58 -0800271 } else if (sk_exists(flag)) {
272 // assume that FLAGS_images[i] is a valid image if it is a file.
djsollen54416de2015-04-03 07:24:48 -0700273 push_src("image", "decode", new ImageSrc(flag)); // Decode entire image.
274 push_src("image", "subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subsets
msarett438b2ad2015-04-09 12:43:10 -0700275 push_codec_srcs(flag);
mtklein709d2c32015-01-15 08:30:25 -0800276 }
mtklein709d2c32015-01-15 08:30:25 -0800277 }
278}
279
mtklein748ca3b2015-01-15 10:56:12 -0800280static GrGLStandard get_gpu_api() {
281 if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; }
282 if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; }
283 return kNone_GrGLStandard;
mtklein709d2c32015-01-15 08:30:25 -0800284}
285
mtklein748ca3b2015-01-15 10:56:12 -0800286static void push_sink(const char* tag, Sink* s) {
287 SkAutoTDelete<Sink> sink(s);
288 if (!FLAGS_config.contains(tag)) {
289 return;
mtklein114c3cd2015-01-15 10:15:02 -0800290 }
mtklein748ca3b2015-01-15 10:56:12 -0800291 // Try a noop Src as a canary. If it fails, skip this sink.
292 struct : public Src {
mtklein36352bf2015-03-25 18:17:31 -0700293 Error draw(SkCanvas*) const override { return ""; }
294 SkISize size() const override { return SkISize::Make(16, 16); }
295 Name name() const override { return "noop"; }
mtklein748ca3b2015-01-15 10:56:12 -0800296 } noop;
mtklein114c3cd2015-01-15 10:15:02 -0800297
mtklein748ca3b2015-01-15 10:56:12 -0800298 SkBitmap bitmap;
299 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800300 SkString log;
301 Error err = sink->draw(noop, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800302 if (err.isFatal()) {
mtklein05641a52015-04-21 10:49:13 -0700303 SkDebugf("Could not run %s: %s\n", tag, err.c_str());
304 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800305 }
306
mtklein748ca3b2015-01-15 10:56:12 -0800307 Tagged<Sink>& ts = gSinks.push_back();
308 ts.reset(sink.detach());
309 ts.tag = tag;
310}
311
312static bool gpu_supported() {
313#if SK_SUPPORT_GPU
314 return FLAGS_gpu;
315#else
316 return false;
317#endif
318}
319
320static Sink* create_sink(const char* tag) {
321#define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); }
322 if (gpu_supported()) {
mtklein82d28432015-01-15 12:46:02 -0800323 typedef GrContextFactory Gr;
mtklein748ca3b2015-01-15 10:56:12 -0800324 const GrGLStandard api = get_gpu_api();
mtklein82d28432015-01-15 12:46:02 -0800325 SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading);
326 SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading);
327 SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading);
328 SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading);
329 SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading);
330 SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading);
331 SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading);
332 SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800333 #if SK_ANGLE
mtklein82d28432015-01-15 12:46:02 -0800334 SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800335 #endif
336 #if SK_MESA
mtklein82d28432015-01-15 12:46:02 -0800337 SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800338 #endif
mtklein114c3cd2015-01-15 10:15:02 -0800339 }
mtklein748ca3b2015-01-15 10:56:12 -0800340
tomhudsoneebc39a2015-02-23 12:18:05 -0800341#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
342 SINK("hwui", HWUISink);
343#endif
344
mtklein748ca3b2015-01-15 10:56:12 -0800345 if (FLAGS_cpu) {
346 SINK("565", RasterSink, kRGB_565_SkColorType);
347 SINK("8888", RasterSink, kN32_SkColorType);
mtklein19f30602015-01-20 13:34:39 -0800348 SINK("pdf", PDFSink);
mtklein9c3f17d2015-01-28 11:35:18 -0800349 SINK("skp", SKPSink);
mtklein8a4527e2015-01-31 20:00:58 -0800350 SINK("svg", SVGSink);
351 SINK("null", NullSink);
halcanary47ef4d52015-03-03 09:13:09 -0800352 SINK("xps", XPSSink);
mtklein748ca3b2015-01-15 10:56:12 -0800353 }
354#undef SINK
355 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800356}
357
mtklein748ca3b2015-01-15 10:56:12 -0800358static Sink* create_via(const char* tag, Sink* wrapped) {
359#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); }
mtklein7edca212015-01-21 13:18:51 -0800360 VIA("pipe", ViaPipe, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800361 VIA("serialize", ViaSerialization, wrapped);
mtkleinb7e8d692015-04-07 08:30:32 -0700362 VIA("2ndpic", ViaSecondPicture, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800363 VIA("tiles", ViaTiles, 256, 256, NULL, wrapped);
364 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800365
mtkleind603b222015-02-17 11:13:33 -0800366 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800367 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800368 m.reset();
369 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
370 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
371 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
372 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
373 VIA("matrix", ViaMatrix, m, wrapped);
374 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800375 }
tomhudson64de1e12015-03-05 08:01:07 -0800376
377#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
378 VIA("androidsdk", ViaAndroidSDK, wrapped);
379#endif
380
mtklein748ca3b2015-01-15 10:56:12 -0800381#undef VIA
382 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800383}
384
mtklein748ca3b2015-01-15 10:56:12 -0800385static void gather_sinks() {
386 for (int i = 0; i < FLAGS_config.count(); i++) {
387 const char* config = FLAGS_config[i];
388 SkTArray<SkString> parts;
389 SkStrSplit(config, "-", &parts);
390
391 Sink* sink = NULL;
392 for (int i = parts.count(); i-- > 0;) {
393 const char* part = parts[i].c_str();
394 Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink);
395 if (next == NULL) {
396 SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part);
397 delete sink;
398 sink = NULL;
399 break;
400 }
401 sink = next;
402 }
403 if (sink) {
404 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800405 }
406 }
407}
mtklein709d2c32015-01-15 08:30:25 -0800408
mtkleina2ef6422015-01-15 13:44:22 -0800409static bool match(const char* needle, const char* haystack) {
410 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle);
411}
412
djsollen54416de2015-04-03 07:24:48 -0700413static ImplicitString is_blacklisted(const char* sink, const char* src,
414 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -0700415 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -0800416 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -0700417 match(FLAGS_blacklist[i+1], src) &&
418 match(FLAGS_blacklist[i+2], srcOptions) &&
419 match(FLAGS_blacklist[i+3], name)) {
420 return SkStringPrintf("%s %s %s %s",
421 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1],
422 FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]);
mtkleina2ef6422015-01-15 13:44:22 -0800423 }
424 }
425 return "";
426}
427
mtklein748ca3b2015-01-15 10:56:12 -0800428// The finest-grained unit of work we can run: draw a single Src into a single Sink,
429// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
430struct Task {
431 Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {}
432 const Tagged<Src>& src;
433 const Tagged<Sink>& sink;
434
435 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800436 SkString name = task->src->name();
mtkleinb37cb412015-03-18 05:27:14 -0700437 SkString note;
djsollen54416de2015-04-03 07:24:48 -0700438 SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag,
439 task->src.options, name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700440 if (!whyBlacklisted.isEmpty()) {
441 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
442 }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800443 SkString log;
mtklein748ca3b2015-01-15 10:56:12 -0800444 WallTimer timer;
445 timer.start();
mtkleina2ef6422015-01-15 13:44:22 -0800446 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800447 SkBitmap bitmap;
448 SkDynamicMemoryWStream stream;
djsollen54416de2015-04-03 07:24:48 -0700449 start(task->sink.tag, task->src.tag, task->src.options, name.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800450 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
mtklein748ca3b2015-01-15 10:56:12 -0800451 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -0800452 timer.end();
453 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -0700454 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein4089ef72015-03-05 08:40:28 -0800455 task->sink.tag,
456 task->src.tag,
djsollen54416de2015-04-03 07:24:48 -0700457 task->src.options,
mtklein4089ef72015-03-05 08:40:28 -0800458 name.c_str(),
459 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -0700460 } else {
461 note.appendf(" (skipped: %s)", err.c_str());
mtklein4089ef72015-03-05 08:40:28 -0800462 }
djsollen54416de2015-04-03 07:24:48 -0700463 done(timer.fWall, task->sink.tag, task->src.tag, task->src.options,
464 name, note, log);
mtklein4089ef72015-03-05 08:40:28 -0800465 return;
mtklein748ca3b2015-01-15 10:56:12 -0800466 }
mtklein62bd1a62015-01-27 14:46:26 -0800467 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
468
469 SkString md5;
470 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
471 SkMD5 hash;
472 if (data->getLength()) {
473 hash.writeStream(data, data->getLength());
474 data->rewind();
475 } else {
476 hash.write(bitmap.getPixels(), bitmap.getSize());
477 }
478 SkMD5::Digest digest;
479 hash.finish(digest);
480 for (int i = 0; i < 16; i++) {
481 md5.appendf("%02x", digest.data[i]);
482 }
483 }
484
485 if (!FLAGS_readPath.isEmpty() &&
djsollen54416de2015-04-03 07:24:48 -0700486 !gGold.contains(Gold(task->sink.tag, task->src.tag,
487 task->src.options, name, md5))) {
488 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
mtklein62bd1a62015-01-27 14:46:26 -0800489 md5.c_str(),
490 task->sink.tag,
491 task->src.tag,
djsollen54416de2015-04-03 07:24:48 -0700492 task->src.options,
mtklein62bd1a62015-01-27 14:46:26 -0800493 name.c_str(),
494 FLAGS_readPath[0]));
495 }
496
mtkleinb0531a72015-04-07 13:38:48 -0700497 if (!FLAGS_writePath.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800498 const char* ext = task->sink->fileExtension();
mtklein62bd1a62015-01-27 14:46:26 -0800499 if (data->getLength()) {
500 WriteToDisk(*task, md5, ext, data, data->getLength(), NULL);
halcanary022afb82015-01-30 11:00:12 -0800501 SkASSERT(bitmap.drawsNothing());
502 } else if (!bitmap.drawsNothing()) {
mtklein62bd1a62015-01-27 14:46:26 -0800503 WriteToDisk(*task, md5, ext, NULL, 0, &bitmap);
mtklein748ca3b2015-01-15 10:56:12 -0800504 }
505 }
506 }
507 timer.end();
djsollen54416de2015-04-03 07:24:48 -0700508 done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, name, note, log);
mtklein748ca3b2015-01-15 10:56:12 -0800509 }
510
511 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -0800512 SkString md5,
513 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -0800514 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -0800515 const SkBitmap* bitmap) {
mtklein748ca3b2015-01-15 10:56:12 -0800516 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -0700517 result.name = task.src->name();
518 result.config = task.sink.tag;
519 result.sourceType = task.src.tag;
520 result.sourceOptions = task.src.options;
521 result.ext = ext;
522 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -0800523 JsonWriter::AddBitmapResult(result);
524
mtkleinb0531a72015-04-07 13:38:48 -0700525 // If an MD5 is uninteresting, we want it noted in the JSON file,
526 // but don't want to dump it out as a .png (or whatever ext is).
527 if (gUninterestingHashes.contains(md5)) {
528 return;
529 }
530
mtklein748ca3b2015-01-15 10:56:12 -0800531 const char* dir = FLAGS_writePath[0];
532 if (0 == strcmp(dir, "@")) { // Needed for iOS.
533 dir = FLAGS_resourcePath[0];
534 }
535 sk_mkdir(dir);
536
537 SkString path;
538 if (FLAGS_nameByHash) {
539 path = SkOSPath::Join(dir, result.md5.c_str());
540 path.append(".");
541 path.append(ext);
542 if (sk_exists(path.c_str())) {
543 return; // Content-addressed. If it exists already, we're done.
544 }
545 } else {
546 path = SkOSPath::Join(dir, task.sink.tag);
547 sk_mkdir(path.c_str());
548 path = SkOSPath::Join(path.c_str(), task.src.tag);
549 sk_mkdir(path.c_str());
djsollen54416de2015-04-03 07:24:48 -0700550 if (strcmp(task.src.options, "") != 0) {
551 path = SkOSPath::Join(path.c_str(), task.src.options);
552 sk_mkdir(path.c_str());
553 }
mtklein748ca3b2015-01-15 10:56:12 -0800554 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
555 path.append(".");
556 path.append(ext);
557 }
558
559 SkFILEWStream file(path.c_str());
560 if (!file.isValid()) {
561 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
562 return;
563 }
564
mtklein748ca3b2015-01-15 10:56:12 -0800565 if (bitmap) {
566 // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first.
567 SkBitmap converted;
568 if (bitmap->info().colorType() == kAlpha_8_SkColorType) {
569 if (!bitmap->copyTo(&converted, kN32_SkColorType)) {
570 fail("Can't convert A8 to 8888.\n");
571 return;
572 }
573 bitmap = &converted;
574 }
575 if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) {
576 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
577 return;
578 }
579 } else {
580 if (!file.writeStream(data, len)) {
581 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
582 return;
583 }
584 }
585 }
586};
587
588// Run all tasks in the same enclave serially on the same thread.
589// They can't possibly run concurrently with each other.
590static void run_enclave(SkTArray<Task>* tasks) {
591 for (int i = 0; i < tasks->count(); i++) {
592 Task::Run(tasks->begin() + i);
593 }
594}
595
596/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
597
598// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
599
mtklein55e88b22015-01-21 15:50:13 -0800600static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800601
602static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -0800603 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -0800604 return;
605 }
halcanary87f3ba42015-01-20 09:30:20 -0800606 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r;
607 r = r->next()) {
608 // Despite its name, factory() is returning a reference to
609 // link-time static const POD data.
610 const skiatest::Test& test = r->factory();
611 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800612 continue;
613 }
halcanary87f3ba42015-01-20 09:30:20 -0800614 if (test.needsGpu && gpu_supported()) {
mtklein55e88b22015-01-21 15:50:13 -0800615 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -0800616 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -0800617 gThreadedTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800618 }
mtklein748ca3b2015-01-15 10:56:12 -0800619 }
620}
621
halcanary87f3ba42015-01-20 09:30:20 -0800622static void run_test(skiatest::Test* test) {
623 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -0700624 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -0800625 fail(failure.toString());
626 JsonWriter::AddTestFailure(failure);
627 }
mtklein36352bf2015-03-25 18:17:31 -0700628 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -0800629 return FLAGS_pathOpsExtended;
630 }
mtklein36352bf2015-03-25 18:17:31 -0700631 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -0800632 } reporter;
mtklein748ca3b2015-01-15 10:56:12 -0800633 WallTimer timer;
634 timer.start();
mtklein748ca3b2015-01-15 10:56:12 -0800635 if (!FLAGS_dryRun) {
djsollen54416de2015-04-03 07:24:48 -0700636 start("unit", "test", "", test->name);
mtklein55e88b22015-01-21 15:50:13 -0800637 GrContextFactory factory;
638 test->proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -0800639 }
640 timer.end();
djsollen54416de2015-04-03 07:24:48 -0700641 done(timer.fWall, "unit", "test", "", test->name, "", "");
mtklein748ca3b2015-01-15 10:56:12 -0800642}
643
644/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
645
mtklein55e88b22015-01-21 15:50:13 -0800646// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
647static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
648 run_enclave(tasks);
649 for (int i = 0; i < gGPUTests.count(); i++) {
650 run_test(&gGPUTests[i]);
651 }
652}
653
mtkleinde6fc2b2015-03-12 06:28:54 -0700654// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
655// This prints something every once in a while so that it knows we're still working.
mtklein2e1c47e2015-03-12 07:16:56 -0700656static void start_keepalive() {
657 struct Loop {
658 static void forever(void*) {
659 for (;;) {
660 static const int kSec = 300;
661 #if defined(SK_BUILD_FOR_WIN)
662 Sleep(kSec * 1000);
663 #else
664 sleep(kSec);
665 #endif
mtkleinb37cb412015-03-18 05:27:14 -0700666 SkString running;
667 {
668 SkAutoMutexAcquire lock(gRunningMutex);
669 for (int i = 0; i < gRunning.count(); i++) {
670 running.appendf("\n\t%s", gRunning[i].c_str());
671 }
672 }
673 SkDebugf("\nCurrently running:%s\n", running.c_str());
mtklein2e1c47e2015-03-12 07:16:56 -0700674 }
675 }
676 };
677 static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
678 intentionallyLeaked->start();
mtkleinde6fc2b2015-03-12 06:28:54 -0700679}
680
jcgregorio3b27ade2014-11-13 08:06:40 -0800681int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700682int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800683 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000684 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700685 SkTaskGroup::Enabler enabled(FLAGS_threads);
mtkleine67164d2015-02-02 13:24:37 -0800686 if (FLAGS_leaks) {
687 SkInstCountPrintLeaksOnExit();
688 }
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000689
mtklein2e1c47e2015-03-12 07:16:56 -0700690 start_keepalive();
mtkleinde6fc2b2015-03-12 06:28:54 -0700691
mtklein62bd1a62015-01-27 14:46:26 -0800692 gather_gold();
borenet09ed4802015-04-03 14:15:33 -0700693 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -0800694
mtklein748ca3b2015-01-15 10:56:12 -0800695 gather_srcs();
696 gather_sinks();
697 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000698
mtklein55e88b22015-01-21 15:50:13 -0800699 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -0800700 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -0800701 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -0800702
703 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
704 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -0800705 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -0800706 SkTArray<Task> enclaves[kNumEnclaves];
707 for (int j = 0; j < gSinks.count(); j++) {
708 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
709 for (int i = 0; i < gSrcs.count(); i++) {
710 tasks.push_back(Task(gSrcs[i], gSinks[j]));
711 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000712 }
713
mtklein748ca3b2015-01-15 10:56:12 -0800714 SkTaskGroup tg;
mtklein55e88b22015-01-21 15:50:13 -0800715 tg.batch(run_test, gThreadedTests.begin(), gThreadedTests.count());
716 for (int i = 0; i < kNumEnclaves; i++) {
717 switch(i) {
718 case kAnyThread_Enclave:
719 tg.batch(Task::Run, enclaves[i].begin(), enclaves[i].count());
720 break;
721 case kGPU_Enclave:
722 tg.add(run_enclave_and_gpu_tests, &enclaves[i]);
723 break;
724 default:
725 tg.add(run_enclave, &enclaves[i]);
726 break;
mtklein82d28432015-01-15 12:46:02 -0800727 }
mtklein55e88b22015-01-21 15:50:13 -0800728 }
mtklein748ca3b2015-01-15 10:56:12 -0800729 tg.wait();
mtklein748ca3b2015-01-15 10:56:12 -0800730 // At this point we're back in single-threaded land.
mtklein@google.comd36522d2013-10-16 13:02:15 +0000731
mtklein2f64eec2015-01-15 14:20:41 -0800732 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -0800733 if (gFailures.count() > 0) {
734 SkDebugf("Failures:\n");
735 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -0800736 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800737 }
738 SkDebugf("%d failures\n", gFailures.count());
739 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800740 }
mtklein748ca3b2015-01-15 10:56:12 -0800741 if (gPending > 0) {
742 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
743 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800744 }
mtklein748ca3b2015-01-15 10:56:12 -0800745 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000746}
jcgregorio3b27ade2014-11-13 08:06:40 -0800747
borenet48087572015-04-02 12:16:36 -0700748#if !defined(SK_BUILD_FOR_IOS)
jcgregorio3b27ade2014-11-13 08:06:40 -0800749int main(int argc, char** argv) {
750 SkCommandLineFlags::Parse(argc, argv);
751 return dm_main();
752}
753#endif