blob: f5c4f224894169439a69bdc00c811ea69f29eea1 [file] [log] [blame]
Mike Kleind63442d2017-03-27 14:16:04 -04001/*
2 * Copyright 2017 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
8#include "ok.h"
9#include "Test.h"
10
Mike Klein4a77cf82017-03-27 22:51:23 -040011#if SK_SUPPORT_GPU
12 #include "GrContextFactory.h"
13#endif
14
Mike Kleind63442d2017-03-27 14:16:04 -040015struct TestStream : Stream {
16 const skiatest::TestRegistry* registry = skiatest::TestRegistry::Head();
Mike Klein6105e4b2017-03-27 17:16:00 -040017 bool extended = false, verbose = false;
Mike Kleind63442d2017-03-27 14:16:04 -040018
Mike Klein6105e4b2017-03-27 17:16:00 -040019 static std::unique_ptr<Stream> Create(Options options) {
Mike Kleind63442d2017-03-27 14:16:04 -040020 TestStream stream;
Mike Klein6105e4b2017-03-27 17:16:00 -040021 if (options("extended") != "") { stream.extended = true; }
22 if (options("verbose" ) != "") { stream.verbose = true; }
23
Mike Kleind63442d2017-03-27 14:16:04 -040024 return move_unique(stream);
25 }
26
27 struct TestSrc : Src {
28 skiatest::Test test {"", false, nullptr};
Mike Klein6105e4b2017-03-27 17:16:00 -040029 bool extended, verbose;
Mike Kleind63442d2017-03-27 14:16:04 -040030
31 std::string name() override { return test.name; }
32 SkISize size() override { return {0,0}; }
33
Mike Kleine15a7b52017-03-29 12:41:13 -040034 Status draw(SkCanvas*) override {
Mike Klein6105e4b2017-03-27 17:16:00 -040035
36 struct : public skiatest::Reporter {
Mike Kleine15a7b52017-03-29 12:41:13 -040037 Status status = Status::OK;
Mike Klein6105e4b2017-03-27 17:16:00 -040038 bool extended, verbose_;
39
40 void reportFailed(const skiatest::Failure& failure) override {
Mike Klein200f6da2017-03-28 09:30:11 -040041 ok_log(failure.toString().c_str());
Mike Kleine15a7b52017-03-29 12:41:13 -040042 status = Status::Failed;
Mike Klein6105e4b2017-03-27 17:16:00 -040043 }
44 bool allowExtendedTest() const override { return extended; }
45 bool verbose() const override { return verbose_; }
46 } reporter;
Mike Klein6105e4b2017-03-27 17:16:00 -040047 reporter.extended = extended;
48 reporter.verbose_ = verbose;
49
Mike Klein4a77cf82017-03-27 22:51:23 -040050 sk_gpu_test::GrContextFactory* factory = nullptr;
51 #if SK_SUPPORT_GPU
52 GrContextOptions options;
53 sk_gpu_test::GrContextFactory a_real_factory(options);
54 factory = &a_real_factory;
55 #endif
56
57 test.proc(&reporter, factory);
Mike Kleine15a7b52017-03-29 12:41:13 -040058 return reporter.status;
Mike Kleind63442d2017-03-27 14:16:04 -040059 }
60 };
61
62 std::unique_ptr<Src> next() override {
63 if (!registry) {
64 return nullptr;
65 }
66 TestSrc src;
67 src.test = registry->factory();
Mike Klein6105e4b2017-03-27 17:16:00 -040068 src.extended = extended;
69 src.verbose = verbose;
Mike Kleind63442d2017-03-27 14:16:04 -040070 registry = registry->next();
71 return move_unique(src);
72 }
73};
Mike Kleine15a7b52017-03-29 12:41:13 -040074static Register test{"test", "run unit tests linked into this binary", TestStream::Create};
Mike Kleind63442d2017-03-27 14:16:04 -040075
76// Hey, now why were these defined in DM.cpp? That's kind of weird.
77namespace skiatest {
78#if SK_SUPPORT_GPU
79 bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
80 return kOpenGL_GrBackend == sk_gpu_test::GrContextFactory::ContextTypeBackend(type);
81 }
82 bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
83 return kVulkan_GrBackend == sk_gpu_test::GrContextFactory::ContextTypeBackend(type);
84 }
85 bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
86 return IsGLContextType(type) && sk_gpu_test::GrContextFactory::IsRenderingContext(type);
87 }
88 bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
89 return type == sk_gpu_test::GrContextFactory::kNullGL_ContextType;
90 }
91#else
92 bool IsGLContextType (int) { return false; }
93 bool IsVulkanContextType (int) { return false; }
94 bool IsRenderingGLContextType(int) { return false; }
95 bool IsNullGLContextType (int) { return false; }
96#endif
97
98 void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
99 Reporter* reporter, sk_gpu_test::GrContextFactory* factory) {
100 // TODO(bsalomon)
101 }
102}