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" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 7 | #include "SkCommonFlags.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 8 | #include "SkForceLinking.h" |
| 9 | #include "SkGraphics.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 10 | #include "SkMD5.h" |
mtklein | 1d0f164 | 2014-09-08 08:05:18 -0700 | [diff] [blame] | 11 | #include "SkOSFile.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 12 | #include "SkTaskGroup.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 13 | #include "Test.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 14 | #include "Timer.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 15 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 16 | DEFINE_bool(tests, true, "Run tests?"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 17 | DEFINE_string(images, "resources", "Images to decode."); |
| 18 | //DEFINE_string(src, "gm skp image subset", "Source types to test."); |
| 19 | DEFINE_string(src, "gm skp", "Source types to test. TEMPORARILY DISABLED"); |
| 20 | DEFINE_bool(nameByHash, false, |
| 21 | "If true, write to FLAGS_writePath[0]/<hash>.png instead of " |
| 22 | "to FLAGS_writePath[0]/<config>/<sourceType>/<name>.png"); |
| 23 | DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); |
| 24 | DEFINE_string(matrix, "1 0 0 0 1 0 0 0 1", |
| 25 | "Matrix to apply when using 'matrix' in config."); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame^] | 26 | 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] | 27 | |
| 28 | __SK_FORCE_IMAGE_DECODER_LINKING; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 29 | using namespace DM; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 30 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 31 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 32 | |
| 33 | SK_DECLARE_STATIC_MUTEX(gFailuresMutex); |
| 34 | static SkTArray<SkString> gFailures; |
| 35 | |
| 36 | static void fail(ImplicitString err) { |
| 37 | SkAutoMutexAcquire lock(gFailuresMutex); |
| 38 | SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); |
| 39 | gFailures.push_back(err); |
halcanary | 9e398f7 | 2015-01-10 11:18:04 -0800 | [diff] [blame] | 40 | } |
| 41 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 42 | static int32_t gPending = 0; // Atomic. |
| 43 | |
| 44 | static void done(double ms, ImplicitString config, ImplicitString src, ImplicitString name) { |
| 45 | SkDebugf("%s(%4dMB %5d) %s\t%s %s %s ", FLAGS_verbose ? "\n" : kSkOverwriteLine |
| 46 | , sk_tools::getMaxResidentSetSizeMB() |
| 47 | , sk_atomic_dec(&gPending)-1 |
| 48 | , HumanizeMs(ms).c_str() |
| 49 | , config.c_str() |
| 50 | , src.c_str() |
| 51 | , name.c_str()); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 52 | } |
| 53 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 54 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 55 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 56 | template <typename T> |
| 57 | struct Tagged : public SkAutoTDelete<T> { const char* tag; }; |
| 58 | |
| 59 | static const bool kMemcpyOK = true; |
| 60 | |
| 61 | static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs; |
| 62 | static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks; |
| 63 | |
| 64 | static void push_src(const char* tag, Src* s) { |
| 65 | SkAutoTDelete<Src> src(s); |
| 66 | if (FLAGS_src.contains(tag) && |
| 67 | !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { |
| 68 | Tagged<Src>& s = gSrcs.push_back(); |
| 69 | s.reset(src.detach()); |
| 70 | s.tag = tag; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 71 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 72 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 73 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 74 | static void gather_srcs() { |
| 75 | for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { |
| 76 | push_src("gm", new GMSrc(r->factory())); |
| 77 | } |
| 78 | if (!FLAGS_skps.isEmpty()) { |
| 79 | SkOSFile::Iter it(FLAGS_skps[0], "skp"); |
| 80 | for (SkString file; it.next(&file); ) { |
| 81 | push_src("skp", new SKPSrc(SkOSPath::Join(FLAGS_skps[0], file.c_str()))); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 82 | } |
| 83 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 84 | if (!FLAGS_images.isEmpty()) { |
| 85 | const char* exts[] = { |
| 86 | "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico", |
| 87 | "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO", |
| 88 | }; |
| 89 | for (size_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { |
| 90 | SkOSFile::Iter it(FLAGS_images[0], exts[i]); |
| 91 | for (SkString file; it.next(&file); ) { |
| 92 | SkString path = SkOSPath::Join(FLAGS_images[0], file.c_str()); |
| 93 | push_src("image", new ImageSrc(path)); // Decode entire image. |
| 94 | push_src("subset", new ImageSrc(path, 5)); // Decode 5 random subsets. |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 95 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 96 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 100 | static GrGLStandard get_gpu_api() { |
| 101 | if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; } |
| 102 | if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; } |
| 103 | return kNone_GrGLStandard; |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 104 | } |
| 105 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 106 | static void push_sink(const char* tag, Sink* s) { |
| 107 | SkAutoTDelete<Sink> sink(s); |
| 108 | if (!FLAGS_config.contains(tag)) { |
| 109 | return; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 110 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 111 | // Try a noop Src as a canary. If it fails, skip this sink. |
| 112 | struct : public Src { |
| 113 | Error draw(SkCanvas*) const SK_OVERRIDE { return ""; } |
| 114 | SkISize size() const SK_OVERRIDE { return SkISize::Make(16, 16); } |
| 115 | Name name() const SK_OVERRIDE { return "noop"; } |
| 116 | } noop; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 117 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 118 | SkBitmap bitmap; |
| 119 | SkDynamicMemoryWStream stream; |
| 120 | Error err = sink->draw(noop, &bitmap, &stream); |
| 121 | if (!err.isEmpty()) { |
| 122 | SkDebugf("Skipping %s: %s\n", tag, err.c_str()); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 123 | return; |
| 124 | } |
| 125 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 126 | Tagged<Sink>& ts = gSinks.push_back(); |
| 127 | ts.reset(sink.detach()); |
| 128 | ts.tag = tag; |
| 129 | } |
| 130 | |
| 131 | static bool gpu_supported() { |
| 132 | #if SK_SUPPORT_GPU |
| 133 | return FLAGS_gpu; |
| 134 | #else |
| 135 | return false; |
| 136 | #endif |
| 137 | } |
| 138 | |
| 139 | static Sink* create_sink(const char* tag) { |
| 140 | #define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); } |
| 141 | if (gpu_supported()) { |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame^] | 142 | typedef GrContextFactory Gr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 143 | const GrGLStandard api = get_gpu_api(); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame^] | 144 | SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 145 | SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 146 | SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 147 | SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading); |
| 148 | SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 149 | SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading); |
| 150 | SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 151 | SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 152 | #if SK_ANGLE |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame^] | 153 | SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 154 | #endif |
| 155 | #if SK_MESA |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame^] | 156 | SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 157 | #endif |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 158 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 159 | |
| 160 | if (FLAGS_cpu) { |
| 161 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 162 | SINK("8888", RasterSink, kN32_SkColorType); |
| 163 | // TODO(mtklein): reenable once skiagold can handle .pdf uploads. |
| 164 | //SINK("pdf", PDFSink); |
| 165 | } |
| 166 | #undef SINK |
| 167 | return NULL; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 168 | } |
| 169 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 170 | static Sink* create_via(const char* tag, Sink* wrapped) { |
| 171 | #define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); } |
| 172 | VIA("serialize", ViaSerialization, wrapped); |
| 173 | |
| 174 | VIA("tiles", ViaTiles, 256, 256, NULL, wrapped); |
| 175 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
| 176 | |
| 177 | const int xp = SkGPipeWriter::kCrossProcess_Flag, |
| 178 | sa = xp | SkGPipeWriter::kSharedAddressSpace_Flag; |
| 179 | VIA("pipe", ViaPipe, 0, wrapped); |
| 180 | VIA("pipe_xp", ViaPipe, xp, wrapped); |
| 181 | VIA("pipe_sa", ViaPipe, sa, wrapped); |
| 182 | |
| 183 | if (FLAGS_matrix.count() == 9) { |
| 184 | SkMatrix m; |
| 185 | for (int i = 0; i < 9; i++) { |
| 186 | m[i] = (SkScalar)atof(FLAGS_matrix[i]); |
| 187 | } |
| 188 | VIA("matrix", ViaMatrix, m, wrapped); |
| 189 | } |
| 190 | #undef VIA |
| 191 | return NULL; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 192 | } |
| 193 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 194 | static void gather_sinks() { |
| 195 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 196 | const char* config = FLAGS_config[i]; |
| 197 | SkTArray<SkString> parts; |
| 198 | SkStrSplit(config, "-", &parts); |
| 199 | |
| 200 | Sink* sink = NULL; |
| 201 | for (int i = parts.count(); i-- > 0;) { |
| 202 | const char* part = parts[i].c_str(); |
| 203 | Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink); |
| 204 | if (next == NULL) { |
| 205 | SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part); |
| 206 | delete sink; |
| 207 | sink = NULL; |
| 208 | break; |
| 209 | } |
| 210 | sink = next; |
| 211 | } |
| 212 | if (sink) { |
| 213 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 217 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 218 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 219 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 220 | struct Task { |
| 221 | Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {} |
| 222 | const Tagged<Src>& src; |
| 223 | const Tagged<Sink>& sink; |
| 224 | |
| 225 | static void Run(Task* task) { |
| 226 | WallTimer timer; |
| 227 | timer.start(); |
| 228 | if (!FLAGS_dryRun) { |
| 229 | SkBitmap bitmap; |
| 230 | SkDynamicMemoryWStream stream; |
| 231 | Error err = task->sink->draw(*task->src, &bitmap, &stream); |
| 232 | if (!err.isEmpty()) { |
| 233 | fail(SkStringPrintf("%s %s %s: %s", |
| 234 | task->sink.tag, |
| 235 | task->src.tag, |
| 236 | task->src->name().c_str(), |
| 237 | err.c_str())); |
| 238 | } |
| 239 | if (!FLAGS_writePath.isEmpty()) { |
| 240 | const char* ext = task->sink->fileExtension(); |
| 241 | if (stream.bytesWritten() == 0) { |
| 242 | SkMemoryStream pixels(bitmap.getPixels(), bitmap.getSize()); |
| 243 | WriteToDisk(*task, &pixels, bitmap.getSize(), &bitmap, ext); |
| 244 | } else { |
| 245 | SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream()); |
| 246 | WriteToDisk(*task, data, data->getLength(), NULL, ext); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | timer.end(); |
| 251 | done(timer.fWall, task->sink.tag, task->src.tag, task->src->name()); |
| 252 | } |
| 253 | |
| 254 | static void WriteToDisk(const Task& task, |
| 255 | SkStream* data, size_t len, |
| 256 | const SkBitmap* bitmap, |
| 257 | const char* ext) { |
| 258 | SkMD5 hash; |
| 259 | hash.writeStream(data, len); |
| 260 | SkMD5::Digest digest; |
| 261 | hash.finish(digest); |
| 262 | |
| 263 | JsonWriter::BitmapResult result; |
| 264 | result.name = task.src->name(); |
| 265 | result.config = task.sink.tag; |
| 266 | result.sourceType = task.src.tag; |
| 267 | result.ext = ext; |
| 268 | for (int i = 0; i < 16; i++) { |
| 269 | result.md5.appendf("%02x", digest.data[i]); |
| 270 | } |
| 271 | JsonWriter::AddBitmapResult(result); |
| 272 | |
| 273 | const char* dir = FLAGS_writePath[0]; |
| 274 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 275 | dir = FLAGS_resourcePath[0]; |
| 276 | } |
| 277 | sk_mkdir(dir); |
| 278 | |
| 279 | SkString path; |
| 280 | if (FLAGS_nameByHash) { |
| 281 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 282 | path.append("."); |
| 283 | path.append(ext); |
| 284 | if (sk_exists(path.c_str())) { |
| 285 | return; // Content-addressed. If it exists already, we're done. |
| 286 | } |
| 287 | } else { |
| 288 | path = SkOSPath::Join(dir, task.sink.tag); |
| 289 | sk_mkdir(path.c_str()); |
| 290 | path = SkOSPath::Join(path.c_str(), task.src.tag); |
| 291 | sk_mkdir(path.c_str()); |
| 292 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 293 | path.append("."); |
| 294 | path.append(ext); |
| 295 | } |
| 296 | |
| 297 | SkFILEWStream file(path.c_str()); |
| 298 | if (!file.isValid()) { |
| 299 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | data->rewind(); |
| 304 | if (bitmap) { |
| 305 | // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first. |
| 306 | SkBitmap converted; |
| 307 | if (bitmap->info().colorType() == kAlpha_8_SkColorType) { |
| 308 | if (!bitmap->copyTo(&converted, kN32_SkColorType)) { |
| 309 | fail("Can't convert A8 to 8888.\n"); |
| 310 | return; |
| 311 | } |
| 312 | bitmap = &converted; |
| 313 | } |
| 314 | if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) { |
| 315 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 316 | return; |
| 317 | } |
| 318 | } else { |
| 319 | if (!file.writeStream(data, len)) { |
| 320 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 321 | return; |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | }; |
| 326 | |
| 327 | // Run all tasks in the same enclave serially on the same thread. |
| 328 | // They can't possibly run concurrently with each other. |
| 329 | static void run_enclave(SkTArray<Task>* tasks) { |
| 330 | for (int i = 0; i < tasks->count(); i++) { |
| 331 | Task::Run(tasks->begin() + i); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 336 | |
| 337 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 338 | |
| 339 | static struct : public skiatest::Reporter { |
| 340 | void onReportFailed(const skiatest::Failure& failure) SK_OVERRIDE { |
| 341 | SkString s; |
| 342 | failure.getFailureString(&s); |
| 343 | fail(s); |
| 344 | JsonWriter::AddTestFailure(failure); |
| 345 | } |
| 346 | bool allowExtendedTest() const SK_OVERRIDE { return FLAGS_pathOpsExtended; } |
| 347 | bool verbose() const SK_OVERRIDE { return FLAGS_veryVerbose; } |
| 348 | } gTestReporter; |
| 349 | |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame^] | 350 | static SkTArray<SkAutoTDelete<skiatest::Test>, kMemcpyOK> gCPUTests, gGPUTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 351 | |
| 352 | static void gather_tests() { |
| 353 | if (!FLAGS_tests) { |
| 354 | return; |
| 355 | } |
| 356 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) { |
| 357 | SkAutoTDelete<skiatest::Test> test(r->factory()(NULL)); |
| 358 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test->getName())) { |
| 359 | continue; |
| 360 | } |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame^] | 361 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 362 | test->setReporter(&gTestReporter); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame^] | 363 | if (test->isGPUTest() && gpu_supported()) { |
| 364 | gGPUTests.push_back().reset(test.detach()); |
| 365 | } else if (!test->isGPUTest() && FLAGS_cpu) { |
| 366 | gCPUTests.push_back().reset(test.detach()); |
| 367 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | |
| 371 | static void run_test(SkAutoTDelete<skiatest::Test>* t) { |
| 372 | WallTimer timer; |
| 373 | timer.start(); |
| 374 | skiatest::Test* test = t->get(); |
| 375 | if (!FLAGS_dryRun) { |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame^] | 376 | test->setGrContextFactory(GetThreadLocalGrContextFactory()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 377 | test->run(); |
| 378 | if (!test->passed()) { |
| 379 | fail(SkStringPrintf("test %s failed", test->getName())); |
| 380 | } |
| 381 | } |
| 382 | timer.end(); |
| 383 | done(timer.fWall, "unit", "test", test->getName()); |
| 384 | } |
| 385 | |
| 386 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 387 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 388 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 389 | int dm_main() { |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 390 | SetupCrashHandler(); |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 391 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 392 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 393 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 394 | gather_srcs(); |
| 395 | gather_sinks(); |
| 396 | gather_tests(); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 397 | |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame^] | 398 | gPending = gSrcs.count() * gSinks.count() + gCPUTests.count() + gGPUTests.count(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 399 | SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n", |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame^] | 400 | gSrcs.count(), gSinks.count(), gCPUTests.count() + gGPUTests.count(), gPending); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 401 | |
| 402 | // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread, |
| 403 | // 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^] | 404 | // CPU tests run on any thread. GPU tests depend on --gpu_threading. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 405 | SkTArray<Task> enclaves[kNumEnclaves]; |
| 406 | for (int j = 0; j < gSinks.count(); j++) { |
| 407 | SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()]; |
| 408 | for (int i = 0; i < gSrcs.count(); i++) { |
| 409 | tasks.push_back(Task(gSrcs[i], gSinks[j])); |
| 410 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 411 | } |
| 412 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 413 | SK_COMPILE_ASSERT(kAnyThread_Enclave == 0, AnyThreadZero); |
| 414 | SkTaskGroup tg; |
| 415 | tg.batch( Task::Run, enclaves[0].begin(), enclaves[0].count()); |
| 416 | tg.batch(run_enclave, enclaves+1, kNumEnclaves-1); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame^] | 417 | tg.batch( run_test, gCPUTests.begin(), gCPUTests.count()); |
| 418 | if (FLAGS_gpu_threading) { |
| 419 | tg.batch(run_test, gGPUTests.begin(), gGPUTests.count()); |
| 420 | } else { |
| 421 | for (int i = 0; i < gGPUTests.count(); i++) { |
| 422 | run_test(&gGPUTests[i]); |
| 423 | } |
| 424 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 425 | tg.wait(); |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 426 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 427 | // At this point we're back in single-threaded land. |
| 428 | |
| 429 | if (!FLAGS_verbose) { |
| 430 | SkDebugf("\n"); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 431 | } |
| 432 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 433 | JsonWriter::DumpJson(); |
| 434 | |
| 435 | if (gFailures.count() > 0) { |
| 436 | SkDebugf("Failures:\n"); |
| 437 | for (int i = 0; i < gFailures.count(); i++) { |
| 438 | SkDebugf("\t%s", gFailures[i].c_str()); |
| 439 | } |
| 440 | SkDebugf("%d failures\n", gFailures.count()); |
| 441 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 442 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 443 | if (gPending > 0) { |
| 444 | SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n"); |
| 445 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 446 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 447 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 448 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 449 | |
| 450 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 451 | int main(int argc, char** argv) { |
| 452 | SkCommandLineFlags::Parse(argc, argv); |
| 453 | return dm_main(); |
| 454 | } |
| 455 | #endif |