blob: 232904209d428fa271c0cf931ed9a9f568298921 [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"
Brian Salomondcfca432017-11-15 15:48:03 -050013#else
14struct GrContextOptions {};
Mike Klein4a77cf82017-03-27 22:51:23 -040015#endif
16
Mike Kleind63442d2017-03-27 14:16:04 -040017struct TestStream : Stream {
18 const skiatest::TestRegistry* registry = skiatest::TestRegistry::Head();
Mike Klein6105e4b2017-03-27 17:16:00 -040019 bool extended = false, verbose = false;
Mike Kleind63442d2017-03-27 14:16:04 -040020
Mike Klein6105e4b2017-03-27 17:16:00 -040021 static std::unique_ptr<Stream> Create(Options options) {
Mike Kleind63442d2017-03-27 14:16:04 -040022 TestStream stream;
Mike Klein6105e4b2017-03-27 17:16:00 -040023 if (options("extended") != "") { stream.extended = true; }
24 if (options("verbose" ) != "") { stream.verbose = true; }
25
Mike Kleind63442d2017-03-27 14:16:04 -040026 return move_unique(stream);
27 }
28
29 struct TestSrc : Src {
30 skiatest::Test test {"", false, nullptr};
Mike Klein6105e4b2017-03-27 17:16:00 -040031 bool extended, verbose;
Mike Kleind63442d2017-03-27 14:16:04 -040032
33 std::string name() override { return test.name; }
34 SkISize size() override { return {0,0}; }
35
Mike Kleine15a7b52017-03-29 12:41:13 -040036 Status draw(SkCanvas*) override {
Mike Klein6105e4b2017-03-27 17:16:00 -040037 struct : public skiatest::Reporter {
Mike Kleine15a7b52017-03-29 12:41:13 -040038 Status status = Status::OK;
Mike Klein6105e4b2017-03-27 17:16:00 -040039 bool extended, verbose_;
40
41 void reportFailed(const skiatest::Failure& failure) override {
Mike Klein200f6da2017-03-28 09:30:11 -040042 ok_log(failure.toString().c_str());
Mike Kleine15a7b52017-03-29 12:41:13 -040043 status = Status::Failed;
Mike Klein6105e4b2017-03-27 17:16:00 -040044 }
45 bool allowExtendedTest() const override { return extended; }
46 bool verbose() const override { return verbose_; }
47 } reporter;
Mike Klein6105e4b2017-03-27 17:16:00 -040048 reporter.extended = extended;
49 reporter.verbose_ = verbose;
50
Mike Klein4a77cf82017-03-27 22:51:23 -040051 GrContextOptions options;
Brian Salomondcfca432017-11-15 15:48:03 -050052 test.run(&reporter, options);
Mike Kleine15a7b52017-03-29 12:41:13 -040053 return reporter.status;
Mike Kleind63442d2017-03-27 14:16:04 -040054 }
55 };
56
57 std::unique_ptr<Src> next() override {
58 if (!registry) {
59 return nullptr;
60 }
61 TestSrc src;
62 src.test = registry->factory();
Mike Klein6105e4b2017-03-27 17:16:00 -040063 src.extended = extended;
64 src.verbose = verbose;
Mike Kleind63442d2017-03-27 14:16:04 -040065 registry = registry->next();
66 return move_unique(src);
67 }
68};
Mike Kleine15a7b52017-03-29 12:41:13 -040069static Register test{"test", "run unit tests linked into this binary", TestStream::Create};
Mike Kleind63442d2017-03-27 14:16:04 -040070
71// Hey, now why were these defined in DM.cpp? That's kind of weird.
72namespace skiatest {
73#if SK_SUPPORT_GPU
74 bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
75 return kOpenGL_GrBackend == sk_gpu_test::GrContextFactory::ContextTypeBackend(type);
76 }
77 bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
78 return kVulkan_GrBackend == sk_gpu_test::GrContextFactory::ContextTypeBackend(type);
79 }
80 bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
81 return IsGLContextType(type) && sk_gpu_test::GrContextFactory::IsRenderingContext(type);
82 }
83 bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
84 return type == sk_gpu_test::GrContextFactory::kNullGL_ContextType;
85 }
86#else
87 bool IsGLContextType (int) { return false; }
88 bool IsVulkanContextType (int) { return false; }
89 bool IsRenderingGLContextType(int) { return false; }
90 bool IsNullGLContextType (int) { return false; }
91#endif
92
93 void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
Brian Salomondcfca432017-11-15 15:48:03 -050094 Reporter* reporter, const GrContextOptions& options) {
Mike Kleind63442d2017-03-27 14:16:04 -040095 // TODO(bsalomon)
96 }
97}