2017-03-27 18:16:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ok.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
2017-03-28 02:51:23 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContextFactory.h"
|
|
|
|
#endif
|
|
|
|
|
2017-03-27 18:16:04 +00:00
|
|
|
struct TestStream : Stream {
|
|
|
|
const skiatest::TestRegistry* registry = skiatest::TestRegistry::Head();
|
2017-03-27 21:16:00 +00:00
|
|
|
bool extended = false, verbose = false;
|
2017-03-27 18:16:04 +00:00
|
|
|
|
2017-03-27 21:16:00 +00:00
|
|
|
static std::unique_ptr<Stream> Create(Options options) {
|
2017-03-27 18:16:04 +00:00
|
|
|
TestStream stream;
|
2017-03-27 21:16:00 +00:00
|
|
|
if (options("extended") != "") { stream.extended = true; }
|
|
|
|
if (options("verbose" ) != "") { stream.verbose = true; }
|
|
|
|
|
2017-03-27 18:16:04 +00:00
|
|
|
return move_unique(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TestSrc : Src {
|
|
|
|
skiatest::Test test {"", false, nullptr};
|
2017-03-27 21:16:00 +00:00
|
|
|
bool extended, verbose;
|
2017-03-27 18:16:04 +00:00
|
|
|
|
|
|
|
std::string name() override { return test.name; }
|
|
|
|
SkISize size() override { return {0,0}; }
|
|
|
|
|
2017-03-29 16:41:13 +00:00
|
|
|
Status draw(SkCanvas*) override {
|
2017-03-27 21:16:00 +00:00
|
|
|
|
|
|
|
struct : public skiatest::Reporter {
|
2017-03-29 16:41:13 +00:00
|
|
|
Status status = Status::OK;
|
2017-03-27 21:16:00 +00:00
|
|
|
bool extended, verbose_;
|
|
|
|
|
|
|
|
void reportFailed(const skiatest::Failure& failure) override {
|
2017-03-28 13:30:11 +00:00
|
|
|
ok_log(failure.toString().c_str());
|
2017-03-29 16:41:13 +00:00
|
|
|
status = Status::Failed;
|
2017-03-27 21:16:00 +00:00
|
|
|
}
|
|
|
|
bool allowExtendedTest() const override { return extended; }
|
|
|
|
bool verbose() const override { return verbose_; }
|
|
|
|
} reporter;
|
|
|
|
reporter.extended = extended;
|
|
|
|
reporter.verbose_ = verbose;
|
|
|
|
|
2017-03-28 02:51:23 +00:00
|
|
|
sk_gpu_test::GrContextFactory* factory = nullptr;
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
GrContextOptions options;
|
|
|
|
sk_gpu_test::GrContextFactory a_real_factory(options);
|
|
|
|
factory = &a_real_factory;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
test.proc(&reporter, factory);
|
2017-03-29 16:41:13 +00:00
|
|
|
return reporter.status;
|
2017-03-27 18:16:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<Src> next() override {
|
|
|
|
if (!registry) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
TestSrc src;
|
|
|
|
src.test = registry->factory();
|
2017-03-27 21:16:00 +00:00
|
|
|
src.extended = extended;
|
|
|
|
src.verbose = verbose;
|
2017-03-27 18:16:04 +00:00
|
|
|
registry = registry->next();
|
|
|
|
return move_unique(src);
|
|
|
|
}
|
|
|
|
};
|
2017-03-29 16:41:13 +00:00
|
|
|
static Register test{"test", "run unit tests linked into this binary", TestStream::Create};
|
2017-03-27 18:16:04 +00:00
|
|
|
|
|
|
|
// Hey, now why were these defined in DM.cpp? That's kind of weird.
|
|
|
|
namespace skiatest {
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
bool IsGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
|
|
return kOpenGL_GrBackend == sk_gpu_test::GrContextFactory::ContextTypeBackend(type);
|
|
|
|
}
|
|
|
|
bool IsVulkanContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
|
|
return kVulkan_GrBackend == sk_gpu_test::GrContextFactory::ContextTypeBackend(type);
|
|
|
|
}
|
|
|
|
bool IsRenderingGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
|
|
return IsGLContextType(type) && sk_gpu_test::GrContextFactory::IsRenderingContext(type);
|
|
|
|
}
|
|
|
|
bool IsNullGLContextType(sk_gpu_test::GrContextFactory::ContextType type) {
|
|
|
|
return type == sk_gpu_test::GrContextFactory::kNullGL_ContextType;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
bool IsGLContextType (int) { return false; }
|
|
|
|
bool IsVulkanContextType (int) { return false; }
|
|
|
|
bool IsRenderingGLContextType(int) { return false; }
|
|
|
|
bool IsNullGLContextType (int) { return false; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void RunWithGPUTestContexts(GrContextTestFn* test, GrContextTypeFilterFn* contextTypeFilter,
|
|
|
|
Reporter* reporter, sk_gpu_test::GrContextFactory* factory) {
|
|
|
|
// TODO(bsalomon)
|
|
|
|
}
|
|
|
|
}
|