blob: 7c020d88e1dfabf03dd644b4768771449f4c210c [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 struct : public skiatest::Reporter {
Mike Kleine15a7b52017-03-29 12:41:13 -040036 Status status = Status::OK;
Mike Klein6105e4b2017-03-27 17:16:00 -040037 bool extended, verbose_;
38
39 void reportFailed(const skiatest::Failure& failure) override {
Mike Klein200f6da2017-03-28 09:30:11 -040040 ok_log(failure.toString().c_str());
Mike Kleine15a7b52017-03-29 12:41:13 -040041 status = Status::Failed;
Mike Klein6105e4b2017-03-27 17:16:00 -040042 }
43 bool allowExtendedTest() const override { return extended; }
44 bool verbose() const override { return verbose_; }
45 } reporter;
Mike Klein6105e4b2017-03-27 17:16:00 -040046 reporter.extended = extended;
47 reporter.verbose_ = verbose;
48
Mike Klein4a77cf82017-03-27 22:51:23 -040049 sk_gpu_test::GrContextFactory* factory = nullptr;
50 #if SK_SUPPORT_GPU
51 GrContextOptions options;
52 sk_gpu_test::GrContextFactory a_real_factory(options);
53 factory = &a_real_factory;
54 #endif
55
Mike Kleinb323a5e2017-07-24 15:21:31 -040056 test.run(&reporter, factory);
Mike Kleine15a7b52017-03-29 12:41:13 -040057 return reporter.status;
Mike Kleind63442d2017-03-27 14:16:04 -040058 }
59 };
60
61 std::unique_ptr<Src> next() override {
62 if (!registry) {
63 return nullptr;
64 }
65 TestSrc src;
66 src.test = registry->factory();
Mike Klein6105e4b2017-03-27 17:16:00 -040067 src.extended = extended;
68 src.verbose = verbose;
Mike Kleind63442d2017-03-27 14:16:04 -040069 registry = registry->next();
70 return move_unique(src);
71 }
72};
Mike Kleine15a7b52017-03-29 12:41:13 -040073static Register test{"test", "run unit tests linked into this binary", TestStream::Create};
Mike Kleind63442d2017-03-27 14:16:04 -040074
75// Hey, now why were these defined in DM.cpp? That's kind of weird.
76namespace skiatest {
77#if SK_SUPPORT_GPU
78 bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
79 return kOpenGL_GrBackend == sk_gpu_test::GrContextFactory::ContextTypeBackend(type);
80 }
81 bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
82 return kVulkan_GrBackend == sk_gpu_test::GrContextFactory::ContextTypeBackend(type);
83 }
84 bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
85 return IsGLContextType(type) && sk_gpu_test::GrContextFactory::IsRenderingContext(type);
86 }
87 bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
88 return type == sk_gpu_test::GrContextFactory::kNullGL_ContextType;
89 }
90#else
91 bool IsGLContextType (int) { return false; }
92 bool IsVulkanContextType (int) { return false; }
93 bool IsRenderingGLContextType(int) { return false; }
94 bool IsNullGLContextType (int) { return false; }
95#endif
96
97 void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
98 Reporter* reporter, sk_gpu_test::GrContextFactory* factory) {
99 // TODO(bsalomon)
100 }
101}