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