Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: dm/DM.cpp

Issue 178273002: Let DM run unit tests. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | dm/DMGpuTask.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Main binary for DM. 1 // Main binary for DM.
2 // For a high-level overview, please see dm/README. 2 // For a high-level overview, please see dm/README.
3 3
4 #include "GrContext.h" 4 #include "GrContext.h"
5 #include "GrContextFactory.h" 5 #include "GrContextFactory.h"
6 #include "SkCommandLineFlags.h" 6 #include "SkCommandLineFlags.h"
7 #include "SkForceLinking.h" 7 #include "SkForceLinking.h"
8 #include "SkGraphics.h" 8 #include "SkGraphics.h"
9 #include "SkString.h" 9 #include "SkString.h"
10 #include "Test.h"
10 #include "gm.h" 11 #include "gm.h"
11 12
13 #include "DMCpuTask.h"
14 #include "DMGpuTask.h"
12 #include "DMReporter.h" 15 #include "DMReporter.h"
13 #include "DMTask.h" 16 #include "DMTask.h"
14 #include "DMTaskRunner.h" 17 #include "DMTaskRunner.h"
15 #include "DMCpuTask.h" 18 #include "DMTestTask.h"
16 #include "DMGpuTask.h"
17 #include "DMWriteTask.h" 19 #include "DMWriteTask.h"
18 20
19 #include <string.h> 21 #include <string.h>
20 22
21 using skiagm::GM; 23 using skiagm::GM;
22 using skiagm::GMRegistry; 24 using skiagm::GMRegistry;
25 using skiatest::Test;
26 using skiatest::TestRegistry;
23 27
24 DEFINE_int32(cpuThreads, -1, "Threads for CPU work. Default NUM_CPUS."); 28 DEFINE_int32(threads, -1, "Threads for CPU work. Default NUM_CPUS.");
25 DEFINE_int32(gpuThreads, 1, "Threads for GPU work.");
26 DEFINE_string2(expectations, r, "", 29 DEFINE_string2(expectations, r, "",
27 "If a directory, compare generated images against images under th is path. " 30 "If a directory, compare generated images against images under th is path. "
28 "If a file, compare generated images against JSON expectations at this path."); 31 "If a file, compare generated images against JSON expectations at this path.");
29 DEFINE_string(resources, "resources", "Path to resources directory."); 32 DEFINE_string2(resources, i, "resources", "Path to resources directory.");
30 DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n" 33 DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n"
31 "Multiple matches may be separated by spaces.\n" 34 "Multiple matches may be separated by spaces.\n"
32 "~ causes a matching GM to always be skipped\n" 35 "~ causes a matching GM to always be skipped\n"
33 "^ requires the start of the GM to match\n" 36 "^ requires the start of the GM to match\n"
34 "$ requires the end of the GM to match\n" 37 "$ requires the end of the GM to match\n"
35 "^ and $ requires an exact match\n" 38 "^ and $ requires an exact match\n"
36 "If a GM does not match any list entry,\n" 39 "If a GM does not match any list entry,\n"
37 "it is skipped unless some list entry starts with ~"); 40 "it is skipped unless some list entry starts with ~");
38 DEFINE_string(config, "565 8888 gpu", 41 DEFINE_string(config, "565 8888 gpu",
39 "Options: 565 8888 gpu msaa4 msaa16 gpunull gpudebug angle mesa"); // TO DO(mtklein): pdf 42 "Options: 565 8888 gpu msaa4 msaa16 gpunull gpudebug angle mesa"); // TO DO(mtklein): pdf
43 DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?");
44
45 DEFINE_bool(gms, true, "Run GMs?");
46 DEFINE_bool(tests, true, "Run tests?");
40 47
41 __SK_FORCE_IMAGE_DECODER_LINKING; 48 __SK_FORCE_IMAGE_DECODER_LINKING;
42 49
43 // "FooBar" -> "foobar". Obviously, ASCII only. 50 // "FooBar" -> "foobar". Obviously, ASCII only.
44 static SkString lowercase(SkString s) { 51 static SkString lowercase(SkString s) {
45 for (size_t i = 0; i < s.size(); i++) { 52 for (size_t i = 0; i < s.size(); i++) {
46 s[i] = tolower(s[i]); 53 s[i] = tolower(s[i]);
47 } 54 }
48 return s; 55 return s;
49 } 56 }
50 57
51 static void kick_off_tasks(const SkTDArray<GMRegistry::Factory>& gms, 58 static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
52 const SkTArray<SkString>& configs, 59 const SkTArray<SkString>& configs,
53 const DM::Expectations& expectations, 60 const DM::Expectations& expectations,
54 DM::Reporter* reporter, 61 DM::Reporter* reporter,
55 DM::TaskRunner* tasks) { 62 DM::TaskRunner* tasks) {
56 const SkColorType _565 = kRGB_565_SkColorType; 63 const SkColorType _565 = kRGB_565_SkColorType;
57 const SkColorType _8888 = kPMColor_SkColorType; 64 const SkColorType _8888 = kPMColor_SkColorType;
58 const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLC ontextType; 65 const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLC ontextType;
59 const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLCon textType; 66 const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLCon textType;
60 const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLCo ntextType; 67 const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLCo ntextType;
61 const GrContextFactory::GLContextType angle = 68 const GrContextFactory::GLContextType angle =
62 #if SK_ANGLE 69 #if SK_ANGLE
63 GrContextFactory::kANGLE_GLContextType; 70 GrContextFactory::kANGLE_GLContextType;
64 #else 71 #else
65 native; 72 native;
(...skipping 20 matching lines...) Expand all
86 START("gpunull", GpuTask, _8888, null, 0); 93 START("gpunull", GpuTask, _8888, null, 0);
87 START("gpudebug", GpuTask, _8888, debug, 0); 94 START("gpudebug", GpuTask, _8888, debug, 0);
88 START("angle", GpuTask, _8888, angle, 0); 95 START("angle", GpuTask, _8888, angle, 0);
89 START("mesa", GpuTask, _8888, mesa, 0); 96 START("mesa", GpuTask, _8888, mesa, 0);
90 //START("pdf", PdfTask, _8888); 97 //START("pdf", PdfTask, _8888);
91 } 98 }
92 } 99 }
93 #undef START 100 #undef START
94 } 101 }
95 102
103 static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
104 DM::Reporter* reporter,
105 DM::TaskRunner* tasks) {
106 for (int i = 0; i < tests.count(); i++) {
107 tasks->add(SkNEW_ARGS(DM::TestTask, (reporter, tasks, tests[i])));
108 }
109 }
110
96 static void report_failures(const DM::Reporter& reporter) { 111 static void report_failures(const DM::Reporter& reporter) {
97 SkTArray<SkString> failures; 112 SkTArray<SkString> failures;
98 reporter.getFailures(&failures); 113 reporter.getFailures(&failures);
99 114
100 if (failures.count() == 0) { 115 if (failures.count() == 0) {
101 return; 116 return;
102 } 117 }
103 118
104 SkDebugf("Failures:\n"); 119 SkDebugf("Failures:\n");
105 for (int i = 0; i < failures.count(); i++) { 120 for (int i = 0; i < failures.count(); i++) {
106 SkDebugf(" %s\n", failures[i].c_str()); 121 SkDebugf(" %s\n", failures[i].c_str());
107 } 122 }
108 } 123 }
109 124
110 int tool_main(int argc, char** argv); 125 int tool_main(int argc, char** argv);
111 int tool_main(int argc, char** argv) { 126 int tool_main(int argc, char** argv) {
127 #if SK_ENABLE_INST_COUNT
128 gPrintInstCount = FLAGS_leaks;
129 #endif
112 SkGraphics::Init(); 130 SkGraphics::Init();
113
114 SkCommandLineFlags::Parse(argc, argv); 131 SkCommandLineFlags::Parse(argc, argv);
115 GM::SetResourcePath(FLAGS_resources[0]); 132 GM::SetResourcePath(FLAGS_resources[0]);
133 Test::SetResourcePath(FLAGS_resources[0]);
134
116 SkTArray<SkString> configs; 135 SkTArray<SkString> configs;
117 for (int i = 0; i < FLAGS_config.count(); i++) { 136 SkTDArray<GMRegistry::Factory> gms;
118 SkStrSplit(FLAGS_config[i], ", ", &configs); 137 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
119 }
120 138
121 SkTDArray<GMRegistry::Factory> gms; 139 if (FLAGS_gms) {
122 for (const GMRegistry* reg = GMRegistry::Head(); reg != NULL; reg = reg->nex t()) { 140 for (int i = 0; i < FLAGS_config.count(); i++) {
123 SkAutoTDelete<GM> gmForName(reg->factory()(NULL)); 141 SkStrSplit(FLAGS_config[i], ", ", &configs);
124 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gmForName->shortName()) ) {
125 *gms.append() = reg->factory();
126 } 142 }
127 }
128 SkDebugf("%d GMs x %d configs\n", gms.count(), configs.count());
129 143
130 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations)); 144 for (const GMRegistry* reg = GMRegistry::Head(); reg != NULL; reg = reg- >next()) {
131 if (FLAGS_expectations.count() > 0) { 145 SkAutoTDelete<GM> gmForName(reg->factory()(NULL));
132 const char* path = FLAGS_expectations[0]; 146 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gmForName->shortNam e())) {
133 if (sk_isdir(path)) { 147 *gms.append() = reg->factory();
134 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path))); 148 }
135 } else { 149 }
136 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path))); 150
151 if (FLAGS_expectations.count() > 0) {
152 const char* path = FLAGS_expectations[0];
153 if (sk_isdir(path)) {
154 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path )));
155 } else {
156 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
157 }
137 } 158 }
138 } 159 }
139 160
161 SkTDArray<TestRegistry::Factory> tests;
162 if (FLAGS_tests) {
163 for (const TestRegistry* reg = TestRegistry::Head(); reg != NULL; reg = reg->next()) {
164 SkAutoTDelete<Test> testForName(reg->factory()(NULL));
165 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, testForName->getNam e())) {
166 *tests.append() = reg->factory();
167 }
168 }
169 }
170
171 SkDebugf("%d GMs x %d configs, %d tests\n", gms.count(), configs.count(), te sts.count());
140 DM::Reporter reporter; 172 DM::Reporter reporter;
141 DM::TaskRunner tasks(FLAGS_cpuThreads, FLAGS_gpuThreads); 173 DM::TaskRunner tasks(FLAGS_threads);
142 kick_off_tasks(gms, configs, *expectations, &reporter, &tasks); 174 kick_off_gms(gms, configs, *expectations, &reporter, &tasks);
175 kick_off_tests(tests, &reporter, &tasks);
143 tasks.wait(); 176 tasks.wait();
144 177
145 reporter.updateStatusLine();
146 SkDebugf("\n"); 178 SkDebugf("\n");
147 report_failures(reporter); 179 report_failures(reporter);
148 180
149 SkGraphics::Term(); 181 SkGraphics::Term();
150 182
151 return reporter.failed() > 0; 183 return reporter.failed() > 0;
152 } 184 }
153 185
154 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 186 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
155 int main(int argc, char** argv) { 187 int main(int argc, char** argv) {
156 return tool_main(argc, argv); 188 return tool_main(argc, argv);
157 } 189 }
158 #endif 190 #endif
OLDNEW
« no previous file with comments | « no previous file | dm/DMGpuTask.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698