Mike Klein | d63442d | 2017-03-27 14:16:04 -0400 | [diff] [blame] | 1 | /* |
| 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 Klein | 4a77cf8 | 2017-03-27 22:51:23 -0400 | [diff] [blame] | 11 | #if SK_SUPPORT_GPU |
| 12 | #include "GrContextFactory.h" |
| 13 | #endif |
| 14 | |
Mike Klein | d63442d | 2017-03-27 14:16:04 -0400 | [diff] [blame] | 15 | struct TestStream : Stream { |
| 16 | const skiatest::TestRegistry* registry = skiatest::TestRegistry::Head(); |
Mike Klein | 6105e4b | 2017-03-27 17:16:00 -0400 | [diff] [blame] | 17 | bool extended = false, verbose = false; |
Mike Klein | d63442d | 2017-03-27 14:16:04 -0400 | [diff] [blame] | 18 | |
Mike Klein | 6105e4b | 2017-03-27 17:16:00 -0400 | [diff] [blame] | 19 | static std::unique_ptr<Stream> Create(Options options) { |
Mike Klein | d63442d | 2017-03-27 14:16:04 -0400 | [diff] [blame] | 20 | TestStream stream; |
Mike Klein | 6105e4b | 2017-03-27 17:16:00 -0400 | [diff] [blame] | 21 | if (options("extended") != "") { stream.extended = true; } |
| 22 | if (options("verbose" ) != "") { stream.verbose = true; } |
| 23 | |
Mike Klein | d63442d | 2017-03-27 14:16:04 -0400 | [diff] [blame] | 24 | return move_unique(stream); |
| 25 | } |
| 26 | |
| 27 | struct TestSrc : Src { |
| 28 | skiatest::Test test {"", false, nullptr}; |
Mike Klein | 6105e4b | 2017-03-27 17:16:00 -0400 | [diff] [blame] | 29 | bool extended, verbose; |
Mike Klein | d63442d | 2017-03-27 14:16:04 -0400 | [diff] [blame] | 30 | |
| 31 | std::string name() override { return test.name; } |
| 32 | SkISize size() override { return {0,0}; } |
| 33 | |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 34 | Status draw(SkCanvas*) override { |
Mike Klein | 6105e4b | 2017-03-27 17:16:00 -0400 | [diff] [blame] | 35 | |
| 36 | struct : public skiatest::Reporter { |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 37 | Status status = Status::OK; |
Mike Klein | 6105e4b | 2017-03-27 17:16:00 -0400 | [diff] [blame] | 38 | bool extended, verbose_; |
| 39 | |
| 40 | void reportFailed(const skiatest::Failure& failure) override { |
Mike Klein | 200f6da | 2017-03-28 09:30:11 -0400 | [diff] [blame] | 41 | ok_log(failure.toString().c_str()); |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 42 | status = Status::Failed; |
Mike Klein | 6105e4b | 2017-03-27 17:16:00 -0400 | [diff] [blame] | 43 | } |
| 44 | bool allowExtendedTest() const override { return extended; } |
| 45 | bool verbose() const override { return verbose_; } |
| 46 | } reporter; |
Mike Klein | 6105e4b | 2017-03-27 17:16:00 -0400 | [diff] [blame] | 47 | reporter.extended = extended; |
| 48 | reporter.verbose_ = verbose; |
| 49 | |
Mike Klein | 4a77cf8 | 2017-03-27 22:51:23 -0400 | [diff] [blame] | 50 | 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 Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 58 | return reporter.status; |
Mike Klein | d63442d | 2017-03-27 14:16:04 -0400 | [diff] [blame] | 59 | } |
| 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 Klein | 6105e4b | 2017-03-27 17:16:00 -0400 | [diff] [blame] | 68 | src.extended = extended; |
| 69 | src.verbose = verbose; |
Mike Klein | d63442d | 2017-03-27 14:16:04 -0400 | [diff] [blame] | 70 | registry = registry->next(); |
| 71 | return move_unique(src); |
| 72 | } |
| 73 | }; |
Mike Klein | e15a7b5 | 2017-03-29 12:41:13 -0400 | [diff] [blame] | 74 | static Register test{"test", "run unit tests linked into this binary", TestStream::Create}; |
Mike Klein | d63442d | 2017-03-27 14:16:04 -0400 | [diff] [blame] | 75 | |
| 76 | // Hey, now why were these defined in DM.cpp? That's kind of weird. |
| 77 | namespace 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 | } |