jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1 | #include "CrashHandler.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 2 | #include "DMJsonWriter.h" |
| 3 | #include "DMSrcSink.h" |
| 4 | #include "OverwriteLine.h" |
| 5 | #include "ProcStats.h" |
| 6 | #include "SkBBHFactory.h" |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 7 | #include "SkChecksum.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 8 | #include "SkCommonFlags.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 9 | #include "SkForceLinking.h" |
| 10 | #include "SkGraphics.h" |
mtklein | e67164d | 2015-02-02 13:24:37 -0800 | [diff] [blame] | 11 | #include "SkInstCnt.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 12 | #include "SkMD5.h" |
mtklein | 1d0f164 | 2014-09-08 08:05:18 -0700 | [diff] [blame] | 13 | #include "SkOSFile.h" |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 14 | #include "SkTDynamicHash.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 15 | #include "SkTaskGroup.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 16 | #include "Test.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 17 | #include "Timer.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 18 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 19 | DEFINE_string(images, "resources", "Images to decode."); |
mtklein | edc93bc | 2015-01-30 13:22:23 -0800 | [diff] [blame] | 20 | DEFINE_string(src, "tests gm skp image subset", "Source types to test."); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 21 | DEFINE_bool(nameByHash, false, |
| 22 | "If true, write to FLAGS_writePath[0]/<hash>.png instead of " |
| 23 | "to FLAGS_writePath[0]/<config>/<sourceType>/<name>.png"); |
| 24 | DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); |
| 25 | DEFINE_string(matrix, "1 0 0 0 1 0 0 0 1", |
| 26 | "Matrix to apply when using 'matrix' in config."); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 27 | DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?"); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 28 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 29 | DEFINE_string(blacklist, "", |
| 30 | "Space-separated config/src/name triples to blacklist. '_' matches anything. E.g. \n" |
| 31 | "'--blacklist gpu skp _' will blacklist all SKPs drawn into the gpu config.\n" |
| 32 | "'--blacklist gpu skp _ 8888 gm aarects' will also blacklist the aarects GM on 8888."); |
| 33 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 34 | DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory."); |
| 35 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 36 | __SK_FORCE_IMAGE_DECODER_LINKING; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 37 | using namespace DM; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 38 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 39 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 40 | |
| 41 | SK_DECLARE_STATIC_MUTEX(gFailuresMutex); |
| 42 | static SkTArray<SkString> gFailures; |
| 43 | |
| 44 | static void fail(ImplicitString err) { |
| 45 | SkAutoMutexAcquire lock(gFailuresMutex); |
| 46 | SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); |
| 47 | gFailures.push_back(err); |
halcanary | 9e398f7 | 2015-01-10 11:18:04 -0800 | [diff] [blame] | 48 | } |
| 49 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 50 | static int32_t gPending = 0; // Atomic. |
| 51 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame^] | 52 | static void done(double ms, |
| 53 | ImplicitString config, ImplicitString src, ImplicitString name, |
| 54 | ImplicitString log) { |
| 55 | if (!log.isEmpty()) { |
| 56 | log.prepend("\n"); |
| 57 | } |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 58 | int32_t pending = sk_atomic_dec(&gPending)-1; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame^] | 59 | SkDebugf("%s(%4dMB %5d) %s\t%s %s %s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 60 | , sk_tools::getMaxResidentSetSizeMB() |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 61 | , pending |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 62 | , HumanizeMs(ms).c_str() |
| 63 | , config.c_str() |
| 64 | , src.c_str() |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame^] | 65 | , name.c_str() |
| 66 | , log.c_str()); |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 67 | // We write our dm.json file every once in a while in case we crash. |
| 68 | // Notice this also handles the final dm.json when pending == 0. |
| 69 | if (pending % 500 == 0) { |
| 70 | JsonWriter::DumpJson(); |
| 71 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 72 | } |
| 73 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 74 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 75 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 76 | struct Gold : public SkString { |
| 77 | Gold(ImplicitString sink, ImplicitString src, ImplicitString name, ImplicitString md5) |
| 78 | : SkString("") { |
| 79 | this->append(sink); |
| 80 | this->append(src); |
| 81 | this->append(name); |
| 82 | this->append(md5); |
| 83 | while (this->size() % 4) { |
| 84 | this->append("!"); // Pad out if needed so we can pass this to Murmur3. |
| 85 | } |
| 86 | } |
| 87 | static const Gold& GetKey(const Gold& g) { return g; } |
| 88 | static uint32_t Hash(const Gold& g) { |
| 89 | return SkChecksum::Murmur3((const uint32_t*)g.c_str(), g.size()); |
| 90 | } |
| 91 | }; |
| 92 | static SkTDynamicHash<Gold, Gold> gGold; |
| 93 | |
| 94 | static void add_gold(JsonWriter::BitmapResult r) { |
| 95 | gGold.add(new Gold(r.config, r.sourceType, r.name, r.md5)); // We'll let these leak. Lazybones. |
| 96 | } |
| 97 | |
| 98 | static void gather_gold() { |
| 99 | if (!FLAGS_readPath.isEmpty()) { |
| 100 | SkString path(FLAGS_readPath[0]); |
| 101 | path.append("/dm.json"); |
| 102 | if (!JsonWriter::ReadJson(path.c_str(), add_gold)) { |
| 103 | fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str())); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 109 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 110 | template <typename T> |
| 111 | struct Tagged : public SkAutoTDelete<T> { const char* tag; }; |
| 112 | |
| 113 | static const bool kMemcpyOK = true; |
| 114 | |
| 115 | static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs; |
| 116 | static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks; |
| 117 | |
| 118 | static void push_src(const char* tag, Src* s) { |
| 119 | SkAutoTDelete<Src> src(s); |
| 120 | if (FLAGS_src.contains(tag) && |
| 121 | !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { |
| 122 | Tagged<Src>& s = gSrcs.push_back(); |
| 123 | s.reset(src.detach()); |
| 124 | s.tag = tag; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 125 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 126 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 127 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 128 | static void gather_srcs() { |
| 129 | for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { |
| 130 | push_src("gm", new GMSrc(r->factory())); |
| 131 | } |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 132 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 133 | const char* path = FLAGS_skps[i]; |
| 134 | if (sk_isdir(path)) { |
| 135 | SkOSFile::Iter it(path, "skp"); |
| 136 | for (SkString file; it.next(&file); ) { |
| 137 | push_src("skp", new SKPSrc(SkOSPath::Join(path, file.c_str()))); |
| 138 | } |
| 139 | } else { |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 140 | push_src("skp", new SKPSrc(path)); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 141 | } |
| 142 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 143 | static const char* const exts[] = { |
| 144 | "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico", |
| 145 | "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO", |
| 146 | }; |
| 147 | for (int i = 0; i < FLAGS_images.count(); i++) { |
| 148 | const char* flag = FLAGS_images[i]; |
| 149 | if (sk_isdir(flag)) { |
| 150 | for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) { |
| 151 | SkOSFile::Iter it(flag, exts[j]); |
| 152 | for (SkString file; it.next(&file); ) { |
| 153 | SkString path = SkOSPath::Join(flag, file.c_str()); |
| 154 | push_src("image", new ImageSrc(path)); // Decode entire image. |
mtklein | edc93bc | 2015-01-30 13:22:23 -0800 | [diff] [blame] | 155 | push_src("subset", new ImageSrc(path, 2)); // Decode into 2 x 2 subsets |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 156 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 157 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 158 | } else if (sk_exists(flag)) { |
| 159 | // assume that FLAGS_images[i] is a valid image if it is a file. |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 160 | push_src("image", new ImageSrc(flag)); // Decode entire image. |
mtklein | edc93bc | 2015-01-30 13:22:23 -0800 | [diff] [blame] | 161 | push_src("subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subsets |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 162 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 166 | static GrGLStandard get_gpu_api() { |
| 167 | if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; } |
| 168 | if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; } |
| 169 | return kNone_GrGLStandard; |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 170 | } |
| 171 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 172 | static void push_sink(const char* tag, Sink* s) { |
| 173 | SkAutoTDelete<Sink> sink(s); |
| 174 | if (!FLAGS_config.contains(tag)) { |
| 175 | return; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 176 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 177 | // Try a noop Src as a canary. If it fails, skip this sink. |
| 178 | struct : public Src { |
| 179 | Error draw(SkCanvas*) const SK_OVERRIDE { return ""; } |
| 180 | SkISize size() const SK_OVERRIDE { return SkISize::Make(16, 16); } |
| 181 | Name name() const SK_OVERRIDE { return "noop"; } |
| 182 | } noop; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 183 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 184 | SkBitmap bitmap; |
| 185 | SkDynamicMemoryWStream stream; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame^] | 186 | SkString log; |
| 187 | Error err = sink->draw(noop, &bitmap, &stream, &log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 188 | if (!err.isEmpty()) { |
| 189 | SkDebugf("Skipping %s: %s\n", tag, err.c_str()); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 190 | return; |
| 191 | } |
| 192 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 193 | Tagged<Sink>& ts = gSinks.push_back(); |
| 194 | ts.reset(sink.detach()); |
| 195 | ts.tag = tag; |
| 196 | } |
| 197 | |
| 198 | static bool gpu_supported() { |
| 199 | #if SK_SUPPORT_GPU |
| 200 | return FLAGS_gpu; |
| 201 | #else |
| 202 | return false; |
| 203 | #endif |
| 204 | } |
| 205 | |
| 206 | static Sink* create_sink(const char* tag) { |
| 207 | #define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); } |
| 208 | if (gpu_supported()) { |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 209 | typedef GrContextFactory Gr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 210 | const GrGLStandard api = get_gpu_api(); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 211 | SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 212 | SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 213 | SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 214 | SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading); |
| 215 | SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 216 | SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading); |
| 217 | SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 218 | SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 219 | #if SK_ANGLE |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 220 | SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 221 | #endif |
| 222 | #if SK_MESA |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 223 | SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 224 | #endif |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 225 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 226 | |
| 227 | if (FLAGS_cpu) { |
| 228 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 229 | SINK("8888", RasterSink, kN32_SkColorType); |
mtklein | 19f3060 | 2015-01-20 13:34:39 -0800 | [diff] [blame] | 230 | SINK("pdf", PDFSink); |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 231 | SINK("skp", SKPSink); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 232 | SINK("svg", SVGSink); |
| 233 | SINK("null", NullSink); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 234 | } |
| 235 | #undef SINK |
| 236 | return NULL; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 237 | } |
| 238 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 239 | static Sink* create_via(const char* tag, Sink* wrapped) { |
| 240 | #define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); } |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 241 | VIA("pipe", ViaPipe, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 242 | VIA("serialize", ViaSerialization, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 243 | VIA("tiles", ViaTiles, 256, 256, NULL, wrapped); |
| 244 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 245 | |
| 246 | if (FLAGS_matrix.count() == 9) { |
| 247 | SkMatrix m; |
| 248 | for (int i = 0; i < 9; i++) { |
| 249 | m[i] = (SkScalar)atof(FLAGS_matrix[i]); |
| 250 | } |
| 251 | VIA("matrix", ViaMatrix, m, wrapped); |
| 252 | } |
| 253 | #undef VIA |
| 254 | return NULL; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 255 | } |
| 256 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 257 | static void gather_sinks() { |
| 258 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 259 | const char* config = FLAGS_config[i]; |
| 260 | SkTArray<SkString> parts; |
| 261 | SkStrSplit(config, "-", &parts); |
| 262 | |
| 263 | Sink* sink = NULL; |
| 264 | for (int i = parts.count(); i-- > 0;) { |
| 265 | const char* part = parts[i].c_str(); |
| 266 | Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink); |
| 267 | if (next == NULL) { |
| 268 | SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part); |
| 269 | delete sink; |
| 270 | sink = NULL; |
| 271 | break; |
| 272 | } |
| 273 | sink = next; |
| 274 | } |
| 275 | if (sink) { |
| 276 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 280 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 281 | static bool match(const char* needle, const char* haystack) { |
| 282 | return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle); |
| 283 | } |
| 284 | |
| 285 | static ImplicitString is_blacklisted(const char* sink, const char* src, const char* name) { |
| 286 | for (int i = 0; i < FLAGS_blacklist.count() - 2; i += 3) { |
| 287 | if (match(FLAGS_blacklist[i+0], sink) && |
| 288 | match(FLAGS_blacklist[i+1], src) && |
| 289 | match(FLAGS_blacklist[i+2], name)) { |
| 290 | return SkStringPrintf("%s %s %s", |
| 291 | FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], FLAGS_blacklist[i+2]); |
| 292 | } |
| 293 | } |
| 294 | return ""; |
| 295 | } |
| 296 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 297 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 298 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 299 | struct Task { |
| 300 | Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {} |
| 301 | const Tagged<Src>& src; |
| 302 | const Tagged<Sink>& sink; |
| 303 | |
| 304 | static void Run(Task* task) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 305 | SkString name = task->src->name(); |
| 306 | SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag, name.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame^] | 307 | SkString log; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 308 | WallTimer timer; |
| 309 | timer.start(); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 310 | if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 311 | SkBitmap bitmap; |
| 312 | SkDynamicMemoryWStream stream; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame^] | 313 | Error err = task->sink->draw(*task->src, &bitmap, &stream, &log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 314 | if (!err.isEmpty()) { |
| 315 | fail(SkStringPrintf("%s %s %s: %s", |
| 316 | task->sink.tag, |
| 317 | task->src.tag, |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 318 | name.c_str(), |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 319 | err.c_str())); |
| 320 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 321 | SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream()); |
| 322 | |
| 323 | SkString md5; |
| 324 | if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { |
| 325 | SkMD5 hash; |
| 326 | if (data->getLength()) { |
| 327 | hash.writeStream(data, data->getLength()); |
| 328 | data->rewind(); |
| 329 | } else { |
| 330 | hash.write(bitmap.getPixels(), bitmap.getSize()); |
| 331 | } |
| 332 | SkMD5::Digest digest; |
| 333 | hash.finish(digest); |
| 334 | for (int i = 0; i < 16; i++) { |
| 335 | md5.appendf("%02x", digest.data[i]); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | if (!FLAGS_readPath.isEmpty() && |
| 340 | !gGold.find(Gold(task->sink.tag, task->src.tag, name, md5))) { |
| 341 | fail(SkStringPrintf("%s not found for %s %s %s in %s", |
| 342 | md5.c_str(), |
| 343 | task->sink.tag, |
| 344 | task->src.tag, |
| 345 | name.c_str(), |
| 346 | FLAGS_readPath[0])); |
| 347 | } |
| 348 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 349 | if (!FLAGS_writePath.isEmpty()) { |
| 350 | const char* ext = task->sink->fileExtension(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 351 | if (data->getLength()) { |
| 352 | WriteToDisk(*task, md5, ext, data, data->getLength(), NULL); |
halcanary | 022afb8 | 2015-01-30 11:00:12 -0800 | [diff] [blame] | 353 | SkASSERT(bitmap.drawsNothing()); |
| 354 | } else if (!bitmap.drawsNothing()) { |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 355 | WriteToDisk(*task, md5, ext, NULL, 0, &bitmap); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | } |
| 359 | timer.end(); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 360 | if (!whyBlacklisted.isEmpty()) { |
| 361 | name.appendf(" (--blacklist, %s)", whyBlacklisted.c_str()); |
| 362 | } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame^] | 363 | done(timer.fWall, task->sink.tag, task->src.tag, name, log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | static void WriteToDisk(const Task& task, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 367 | SkString md5, |
| 368 | const char* ext, |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 369 | SkStream* data, size_t len, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 370 | const SkBitmap* bitmap) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 371 | JsonWriter::BitmapResult result; |
| 372 | result.name = task.src->name(); |
| 373 | result.config = task.sink.tag; |
| 374 | result.sourceType = task.src.tag; |
| 375 | result.ext = ext; |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 376 | result.md5 = md5; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 377 | JsonWriter::AddBitmapResult(result); |
| 378 | |
| 379 | const char* dir = FLAGS_writePath[0]; |
| 380 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 381 | dir = FLAGS_resourcePath[0]; |
| 382 | } |
| 383 | sk_mkdir(dir); |
| 384 | |
| 385 | SkString path; |
| 386 | if (FLAGS_nameByHash) { |
| 387 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 388 | path.append("."); |
| 389 | path.append(ext); |
| 390 | if (sk_exists(path.c_str())) { |
| 391 | return; // Content-addressed. If it exists already, we're done. |
| 392 | } |
| 393 | } else { |
| 394 | path = SkOSPath::Join(dir, task.sink.tag); |
| 395 | sk_mkdir(path.c_str()); |
| 396 | path = SkOSPath::Join(path.c_str(), task.src.tag); |
| 397 | sk_mkdir(path.c_str()); |
| 398 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 399 | path.append("."); |
| 400 | path.append(ext); |
| 401 | } |
| 402 | |
| 403 | SkFILEWStream file(path.c_str()); |
| 404 | if (!file.isValid()) { |
| 405 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 406 | return; |
| 407 | } |
| 408 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 409 | if (bitmap) { |
| 410 | // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first. |
| 411 | SkBitmap converted; |
| 412 | if (bitmap->info().colorType() == kAlpha_8_SkColorType) { |
| 413 | if (!bitmap->copyTo(&converted, kN32_SkColorType)) { |
| 414 | fail("Can't convert A8 to 8888.\n"); |
| 415 | return; |
| 416 | } |
| 417 | bitmap = &converted; |
| 418 | } |
| 419 | if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) { |
| 420 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 421 | return; |
| 422 | } |
| 423 | } else { |
| 424 | if (!file.writeStream(data, len)) { |
| 425 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 426 | return; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | }; |
| 431 | |
| 432 | // Run all tasks in the same enclave serially on the same thread. |
| 433 | // They can't possibly run concurrently with each other. |
| 434 | static void run_enclave(SkTArray<Task>* tasks) { |
| 435 | for (int i = 0; i < tasks->count(); i++) { |
| 436 | Task::Run(tasks->begin() + i); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 441 | |
| 442 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 443 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 444 | static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 445 | |
| 446 | static void gather_tests() { |
mtklein | 6c5fed2 | 2015-01-20 13:47:23 -0800 | [diff] [blame] | 447 | if (!FLAGS_src.contains("tests")) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 448 | return; |
| 449 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 450 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; |
| 451 | r = r->next()) { |
| 452 | // Despite its name, factory() is returning a reference to |
| 453 | // link-time static const POD data. |
| 454 | const skiatest::Test& test = r->factory(); |
| 455 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 456 | continue; |
| 457 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 458 | if (test.needsGpu && gpu_supported()) { |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 459 | (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 460 | } else if (!test.needsGpu && FLAGS_cpu) { |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 461 | gThreadedTests.push(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 462 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 466 | static void run_test(skiatest::Test* test) { |
| 467 | struct : public skiatest::Reporter { |
| 468 | void reportFailed(const skiatest::Failure& failure) SK_OVERRIDE { |
| 469 | fail(failure.toString()); |
| 470 | JsonWriter::AddTestFailure(failure); |
| 471 | } |
| 472 | bool allowExtendedTest() const SK_OVERRIDE { |
| 473 | return FLAGS_pathOpsExtended; |
| 474 | } |
| 475 | bool verbose() const SK_OVERRIDE { return FLAGS_veryVerbose; } |
| 476 | } reporter; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 477 | WallTimer timer; |
| 478 | timer.start(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 479 | if (!FLAGS_dryRun) { |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 480 | GrContextFactory factory; |
| 481 | test->proc(&reporter, &factory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 482 | } |
| 483 | timer.end(); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame^] | 484 | done(timer.fWall, "unit", "test", test->name, ""); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 488 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 489 | // If we're isolating all GPU-bound work to one thread (the default), this function runs all that. |
| 490 | static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) { |
| 491 | run_enclave(tasks); |
| 492 | for (int i = 0; i < gGPUTests.count(); i++) { |
| 493 | run_test(&gGPUTests[i]); |
| 494 | } |
| 495 | } |
| 496 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 497 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 498 | int dm_main() { |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 499 | SetupCrashHandler(); |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 500 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 501 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
mtklein | e67164d | 2015-02-02 13:24:37 -0800 | [diff] [blame] | 502 | if (FLAGS_leaks) { |
| 503 | SkInstCountPrintLeaksOnExit(); |
| 504 | } |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 505 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 506 | gather_gold(); |
| 507 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 508 | gather_srcs(); |
| 509 | gather_sinks(); |
| 510 | gather_tests(); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 511 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 512 | gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 513 | SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n", |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 514 | gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 515 | |
| 516 | // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread, |
| 517 | // but Sinks that identify as part of a particular enclave run serially on a single thread. |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 518 | // CPU tests run on any thread. GPU tests depend on --gpu_threading. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 519 | SkTArray<Task> enclaves[kNumEnclaves]; |
| 520 | for (int j = 0; j < gSinks.count(); j++) { |
| 521 | SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()]; |
| 522 | for (int i = 0; i < gSrcs.count(); i++) { |
| 523 | tasks.push_back(Task(gSrcs[i], gSinks[j])); |
| 524 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 525 | } |
| 526 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 527 | SkTaskGroup tg; |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 528 | tg.batch(run_test, gThreadedTests.begin(), gThreadedTests.count()); |
| 529 | for (int i = 0; i < kNumEnclaves; i++) { |
| 530 | switch(i) { |
| 531 | case kAnyThread_Enclave: |
| 532 | tg.batch(Task::Run, enclaves[i].begin(), enclaves[i].count()); |
| 533 | break; |
| 534 | case kGPU_Enclave: |
| 535 | tg.add(run_enclave_and_gpu_tests, &enclaves[i]); |
| 536 | break; |
| 537 | default: |
| 538 | tg.add(run_enclave, &enclaves[i]); |
| 539 | break; |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 540 | } |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 541 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 542 | tg.wait(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 543 | // At this point we're back in single-threaded land. |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 544 | |
mtklein | 2f64eec | 2015-01-15 14:20:41 -0800 | [diff] [blame] | 545 | SkDebugf("\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 546 | if (gFailures.count() > 0) { |
| 547 | SkDebugf("Failures:\n"); |
| 548 | for (int i = 0; i < gFailures.count(); i++) { |
mtklein | 9dc0910 | 2015-01-15 15:47:33 -0800 | [diff] [blame] | 549 | SkDebugf("\t%s\n", gFailures[i].c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 550 | } |
| 551 | SkDebugf("%d failures\n", gFailures.count()); |
| 552 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 553 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 554 | if (gPending > 0) { |
| 555 | SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n"); |
| 556 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 557 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 558 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 559 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 560 | |
| 561 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 562 | int main(int argc, char** argv) { |
| 563 | SkCommandLineFlags::Parse(argc, argv); |
| 564 | return dm_main(); |
| 565 | } |
| 566 | #endif |