Flutter Engine
The Flutter Engine
BazelUnitTestRunner.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
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 * This runs *all* the tests registered via the Test registry in series. If one or more fail, those
8 * error messages will be printed out and a non-zero exit code will be returned. Otherwise, the
9 * exit code will be 0.
10 */
11
15#include "tests/Test.h"
16#include "tests/TestHarness.h"
19
20#if defined(SK_GANESH)
23#include "include/gpu/GrTypes.h"
27#endif
28
29#include <ctime>
30#include <cwchar>
31#include <functional>
32#include <iomanip>
33#include <sstream>
34#include <string>
35
36struct tm;
37
38static DEFINE_string(skip, "", "Space-separated list of test cases (regexps) to skip.");
40 match,
41 "",
42 "Space-separated list of test cases (regexps) to run. Will run all tests if omitted.");
43
44// Set in //bazel/devicesrc but consumed by other C++ test runners.
45static DEFINE_string(key, "", "Ignored by this test runner.");
46static DEFINE_string(cpuName, "", "Ignored by this test runner.");
47static DEFINE_string(gpuName, "", "Ignored by this test runner.");
48
49// Set in //bazel/devicesrc but only consumed by adb_test_runner.go. We cannot use the
50// DEFINE_string macro because the flag name includes dashes.
51[[maybe_unused]] static bool unused =
52 SkFlagInfo::CreateStringFlag("device-specific-bazel-config",
53 nullptr,
55 nullptr,
56 "Ignored by this test runner.",
57 nullptr);
58
60public:
61 void reportFailed(const skiatest::Failure& failure) override {
62 TestRunner::Log("FAIL: %s", failure.toString().c_str());
63 fFailed = true;
64 }
65 bool allowExtendedTest() const override { return false; }
66 bool verbose() const override { return false; }
67 bool ok() { return !fFailed; }
68
69private:
70 bool fFailed = false;
71};
72
73#if defined(SK_GANESH)
74namespace skiatest {
77}
80}
83}
86}
88
89skgpu::ContextType compiledInContextTypes[] = {
90#if defined(SK_GL)
91// Use "native" instead of explicitly trying both OpenGL and OpenGL ES. Do not use GLES on
92// desktop since tests do not account for not fixing http://skbug.com/2809
93#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_WIN) || defined(SK_BUILD_FOR_MAC)
95#else
97#endif
98#endif // defined(SK_GL)
99#if defined(SK_VULKAN)
101#endif
102#if defined(SK_DAWN)
103 skgpu::ContextType::kDawn,
104#endif
105 // TODO(kjlubick) Other Ganesh backends
107};
108
109// The macros defined in Test.h eventually call into this function. For each GPU backend that is
110// compiled in, we run the testFn with a freshly created
112 ContextTypeFilterFn* filter,
113 Reporter* reporter,
114 const GrContextOptions& options) {
116
117 for (skgpu::ContextType ctxType : compiledInContextTypes) {
118 if (filter && !(*filter)(ctxType)) {
119 continue;
120 }
121
122 sk_gpu_test::ContextInfo ctxInfo = factory.getContextInfo(ctxType);
123 if (ctxInfo.directContext()) {
124 (*testFn)(reporter, ctxInfo);
125 // In case the test changed the current context make sure we move it back before
126 // calling flush.
127 ctxInfo.testContext()->makeCurrent();
128 // Sync so any release/finished procs get called.
130 } else {
131 TestRunner::Log("Unable to make direct context for Ganesh test.");
132 SkASSERT(false);
133 return;
134 }
135 }
136}
137
138} // namespace skiatest
139#endif // #if defined(SK_GANESH)
140
142
143void maybeRunTest(const char* name, std::function<void()> testFn) {
144 if (!TestRunner::ShouldRunTestCase(name, FLAGS_match, FLAGS_skip)) {
145 TestRunner::Log("Skipping %s", name);
146 return;
147 }
148
149 TestRunner::Log("Running %s", name);
150 testFn();
151 TestRunner::Log("\tDone");
152}
153
154int main(int argc, char** argv) {
156
158
161 if (test.fTestType == skiatest::TestType::kCPU) {
162 maybeRunTest(test.fName, [&]() { test.cpu(&reporter); });
163 }
164 }
165
166#if defined(SK_GANESH)
167 GrContextOptions grCtxOptions;
168 // TODO(kjlubick) DM has grContextOptions set via flags. Should this runner have that too?
169 grCtxOptions.fExecutor = nullptr;
170 grCtxOptions.fAllowPathMaskCaching = true;
171 grCtxOptions.fFailFlushTimeCallbacks = false;
172 grCtxOptions.fAllPathsVolatile = false;
173 grCtxOptions.fGpuPathRenderers = GpuPathRenderers::kDefault;
174 grCtxOptions.fDisableDriverCorrectnessWorkarounds = false;
175 grCtxOptions.fResourceCacheLimitOverride = -1;
178 if (test.fTestType == skiatest::TestType::kGanesh) {
179 maybeRunTest(test.fName, [&]() { test.ganesh(&reporter, grCtxOptions); });
180 }
181 }
182#endif
183
184 // TODO(kjlubick) Graphite support
185
186 if (reporter.ok()) {
187 TestRunner::Log("PASS");
188 return 0;
189 }
190 TestRunner::Log("FAIL");
191 return 1;
192}
int main(int argc, char **argv)
static bool unused
TestHarness CurrentTestHarness()
void maybeRunTest(const char *name, std::function< void()> testFn)
static DEFINE_string(skip, "", "Space-separated list of test cases (regexps) to skip.")
const char * options
reporter
Definition: FontMgrTest.cpp:39
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool skip(SkStream *stream, size_t amount)
TestHarness
Definition: TestHarness.h:14
@ kBazelUnitTestRunner
GLenum type
bool verbose() const override
void reportFailed(const skiatest::Failure &failure) override
bool allowExtendedTest() const override
static void Parse(int argc, const char *const *argv)
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
static bool CreateStringFlag(const char *name, const char *shortName, CommandLineFlags::StringArray *pStrings, const char *defaultValue, const char *helpString, const char *extendedHelpString)
const char * c_str() const
Definition: SkString.h:133
GrDirectContext * directContext() const
TestContext * testContext() const
Dart_NativeFunction function
Definition: fuchsia.cc:51
char ** argv
Definition: library.h:9
bool ShouldRunTestCase(const char *name, CommandLineFlags::StringArray &matchFlag, CommandLineFlags::StringArray &skipFlag)
Definition: TestRunner.cpp:113
void Log(const char *format,...) SK_PRINTF_LIKE(1
Definition: TestRunner.cpp:137
void InitAndLogCmdlineArgs(int argc, char **argv)
Definition: TestRunner.cpp:88
def match(bench, filt)
Definition: benchmark.py:23
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
GrBackendApi ContextTypeBackend(skgpu::ContextType type)
Definition: ContextType.cpp:92
ContextType
Definition: ContextType.h:19
@ kGLES
OpenGL context.
@ kVulkan
ANGLE on Metal ES 3 context.
@ kMock
Dawn on OpenGL ES.
void RunWithGaneshTestContexts(GrContextTestFn *testFn, ContextTypeFilterFn *filter, Reporter *reporter, const GrContextOptions &options)
bool IsMetalContextType(skgpu::ContextType type)
bool IsGLContextType(skgpu::ContextType type)
bool ContextTypeFilterFn(GpuContextType)
Definition: Test.h:214
bool IsMockContextType(skgpu::ContextType type)
bool IsDirect3DContextType(skgpu::ContextType type)
void GrContextTestFn(Reporter *, const sk_gpu_test::ContextInfo &)
Definition: Test.h:213
bool IsVulkanContextType(skgpu::ContextType type)
SkExecutor * fExecutor
Enable fReduceOpsTaskSplitting
bool fDisableDriverCorrectnessWorkarounds
SkString toString() const
Definition: Test.cpp:41