Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
skqp_main.cpp
Go to the documentation of this file.
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 <iostream>
9#include <sys/stat.h>
10
11#include "tools/skqp/src/skqp.h"
12
13#include "include/core/SkData.h"
14#include "src/core/SkOSFile.h"
15#include "src/utils/SkOSPath.h"
16#include "tools/Resources.h"
17
18////////////////////////////////////////////////////////////////////////////////
19
20namespace {
21class StdAssetManager : public SkQPAssetManager {
22public:
23 StdAssetManager(const char* p) : fPrefix(p) {
24 SkASSERT(!fPrefix.empty());
25 }
26
27 sk_sp<SkData> open(const char* subpath) override {
28 SkString path = SkOSPath::Join(fPrefix.c_str(), subpath);
29 return SkData::MakeFromFileName(path.c_str());
30 }
31
32 std::vector<std::string> iterateDir(const char* directory, const char* extension) override {
33 std::vector<std::string> paths;
34 SkString resourceDirectory = GetResourcePath(directory);
35 SkOSFile::Iter iter(resourceDirectory.c_str(), extension);
37
38 while (iter.next(&name, /*getDir=*/false)) {
39 SkString path(SkOSPath::Join(directory, name.c_str()));
40 paths.push_back(path.c_str());
41 }
42
43 return paths;
44 }
45
46private:
47 std::string fPrefix;
48};
49
50struct Args {
51 char* assetDir;
52 char* outputDir;
53};
54} // namespace
55
56static constexpr char kSkipUsage[] =
57 " TEST_MATCH_RULES:"
58 " [~][^]substring[$] [...] of name to run.\n"
59 " Multiple matches may be separated by spaces.\n"
60 " ~ causes a matching name to always be skipped\n"
61 " ^ requires the start of the name to match\n"
62 " $ requires the end of the name to match\n"
63 " ^ and $ requires an exact match\n"
64 " If a name does not match any list entry,\n"
65 " it is skipped unless some list entry starts with ~\n";
66
67static bool should_skip(const char* const* rules, size_t count, const char* name) {
68 size_t testLen = strlen(name);
69 bool anyExclude = count == 0;
70 for (size_t i = 0; i < count; ++i) {
71 const char* matchName = rules[i];
72 size_t matchLen = strlen(matchName);
73 bool matchExclude, matchStart, matchEnd;
74 if ((matchExclude = matchName[0] == '~')) {
75 anyExclude = true;
76 matchName++;
77 matchLen--;
78 }
79 if ((matchStart = matchName[0] == '^')) {
80 matchName++;
81 matchLen--;
82 }
83 if ((matchEnd = matchName[matchLen - 1] == '$')) {
84 matchLen--;
85 }
86 if (matchStart ? (!matchEnd || matchLen == testLen)
87 && strncmp(name, matchName, matchLen) == 0
88 : matchEnd ? matchLen <= testLen
89 && strncmp(name + testLen - matchLen, matchName, matchLen) == 0
90 : strstr(name, matchName) != nullptr) {
91 return matchExclude;
92 }
93 }
94 return !anyExclude;
95}
96
97static void parse_args(int argc, char *argv[], Args *args) {
98 if (argc < 3) {
99 std::cerr << "Usage:\n " << argv[0] << " ASSET_DIR OUTPUT_DIR [TEST_MATCH_RULES]\n"
100 << kSkipUsage << '\n';
101 exit(1);
102 }
103 args->assetDir = argv[1];
104 args->outputDir = argv[2];
105}
106
107int main(int argc, char *argv[]) {
108 Args args;
109 parse_args(argc, argv, &args);
110
111 SetResourcePath(std::string(args.assetDir + std::string("/resources")).c_str());
112 if (!sk_mkdir(args.outputDir)) {
113 std::cerr << "sk_mkdir(" << args.outputDir << ") failed.\n";
114 return 2;
115 }
116
117 StdAssetManager mgr(args.assetDir);
118 SkQP skqp;
119 skqp.init(&mgr, args.outputDir);
120 int ret = 0;
121
122 const char* const* matchRules = &argv[3];
123 size_t matchRulesCount = (size_t)(argc - 3);
124
125 // Unit Tests
126 for (SkQP::UnitTest test : skqp.getUnitTests()) {
127 auto testName = std::string("unitTest_") + SkQP::GetUnitTestName(test);
128 if (should_skip(matchRules, matchRulesCount, testName.c_str())) {
129 continue;
130 }
131 std::cout << "Starting: " << testName << " ";
132 std::vector<std::string> errors = skqp.executeTest(test);
133 if (!errors.empty()) {
134 std::cout << "[FAILED: " << errors.size() << " error(s)]" << std::endl;
135 for (const std::string& error : errors) {
136 std::cout << " " << error << std::endl;
137 }
138 ret = 1;
139 } else {
140 std::cout << "[PASSED]" << std::endl;
141 }
142 std::cout.flush();
143 }
144 skqp.makeReport();
145
146 return ret;
147}
int count
void SetResourcePath(const char *resource)
Definition Resources.cpp:27
SkString GetResourcePath(const char *resource)
Definition Resources.cpp:23
#define SkASSERT(cond)
Definition SkAssert.h:116
bool sk_mkdir(const char *path)
static sk_sp< SkData > MakeFromFileName(const char path[])
Definition SkData.cpp:148
static SkString Join(const char *rootPath, const char *relativePath)
Definition SkOSPath.cpp:14
virtual sk_sp< SkData > open(const char *path)=0
virtual std::vector< std::string > iterateDir(const char *directory, const char *extension)=0
Definition skqp.h:42
void makeReport()
Definition skqp.cpp:192
const std::vector< UnitTest > & getUnitTests() const
Definition skqp.h:74
std::vector< std::string > executeTest(UnitTest)
Definition skqp.cpp:147
void init(SkQPAssetManager *assetManager, const char *reportDirectory)
Definition skqp.cpp:120
static const char * GetUnitTestName(UnitTest)
Definition skqp.cpp:114
const char * c_str() const
Definition SkString.h:133
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
const char * name
Definition fuchsia.cc:50
char ** argv
Definition library.h:9
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
Definition main.py:1
static bool should_skip(const char *const *rules, size_t count, const char *name)
Definition skqp_main.cpp:67
static constexpr char kSkipUsage[]
Definition skqp_main.cpp:56
static void parse_args(int argc, char *argv[], Args *args)
Definition skqp_main.cpp:97