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

Side by Side Diff: tests/skia_test.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 | « tests/Test.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "OverwriteLine.h" 8 #include "OverwriteLine.h"
9 #include "SkCommandLineFlags.h" 9 #include "SkCommandLineFlags.h"
10 #include "SkGraphics.h" 10 #include "SkGraphics.h"
11 #include "SkOSFile.h" 11 #include "SkOSFile.h"
12 #include "SkTArray.h" 12 #include "SkTArray.h"
13 #include "SkTemplates.h" 13 #include "SkTemplates.h"
14 #include "SkThreadPool.h" 14 #include "SkThreadPool.h"
15 #include "SkTime.h" 15 #include "SkTime.h"
16 #include "Test.h" 16 #include "Test.h"
17 17
18 #if SK_SUPPORT_GPU 18 #if SK_SUPPORT_GPU
19 #include "GrContext.h" 19 #include "GrContext.h"
20 #include "GrContextFactory.h"
20 #endif 21 #endif
21 22
22 using namespace skiatest; 23 using namespace skiatest;
23 24
24 DEFINE_string2(match, m, NULL, "[~][^]substring[$] [...] of test name to run.\n" \ 25 DEFINE_string2(match, m, NULL, "[~][^]substring[$] [...] of test name to run.\n" \
25 "Multiple matches may be separated by spaces.\n" \ 26 "Multiple matches may be separated by spaces.\n" \
26 "~ causes a matching test to always be skipped\n" \ 27 "~ causes a matching test to always be skipped\n" \
27 "^ requires the start of the test to match\n" \ 28 "^ requires the start of the test to match\n" \
28 "$ requires the end of the test to match\n" \ 29 "$ requires the end of the test to match\n" \
29 "^ and $ requires an exact match\n" \ 30 "^ and $ requires an exact match\n" \
30 "If a test does not match any list entry,\n" \ 31 "If a test does not match any list entry,\n" \
31 "it is skipped unless some list entry starts with ~"); 32 "it is skipped unless some list entry starts with ~");
32 DEFINE_string2(tmpDir, t, NULL, "tmp directory for tests to use.");
33 DEFINE_string2(resourcePath, i, "resources", "directory for test resources.");
34 DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps."); 33 DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps.");
35 DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects."); 34 DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects.");
36 DEFINE_bool2(single, z, false, "run tests on a single thread internally."); 35 DEFINE_bool2(single, z, false, "run tests on a single thread internally.");
37 DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver."); 36 DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
38 DEFINE_bool2(veryVerbose, V, false, "tell individual tests to be verbose."); 37 DEFINE_bool2(veryVerbose, V, false, "tell individual tests to be verbose.");
39 DEFINE_bool(cpu, true, "whether or not to run CPU tests."); 38 DEFINE_bool(cpu, true, "whether or not to run CPU tests.");
40 DEFINE_bool(gpu, true, "whether or not to run GPU tests."); 39 DEFINE_bool(gpu, true, "whether or not to run GPU tests.");
41 DEFINE_int32(threads, SkThreadPool::kThreadPerCore, 40 DEFINE_int32(threads, SkThreadPool::kThreadPerCore,
42 "Run threadsafe tests on a threadpool with this many threads."); 41 "Run threadsafe tests on a threadpool with this many threads.");
42 DEFINE_string2(resourcePath, i, "resources", "directory for test resources.");
43 43
44 // need to explicitly declare this, or we get some weird infinite loop llist 44 // need to explicitly declare this, or we get some weird infinite loop llist
45 template TestRegistry* TestRegistry::gHead; 45 template TestRegistry* TestRegistry::gHead;
46 46
47 class Iter { 47 class Iter {
48 public: 48 public:
49 Iter() { this->reset(); } 49 Iter() { this->reset(); }
50 void reset() { fReg = TestRegistry::Head(); } 50 void reset() { fReg = TestRegistry::Head(); }
51 51
52 Test* next(Reporter* r) { 52 Test* next(Reporter* r) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 time.printf("%5dms ", test->elapsedMs()); 91 time.printf("%5dms ", test->elapsedMs());
92 } 92 }
93 SkDebugf("%s[%3d/%3d] %s%s", prefix.c_str(), done, fTotal, time.c_str(), test->getName()); 93 SkDebugf("%s[%3d/%3d] %s%s", prefix.c_str(), done, fTotal, time.c_str(), test->getName());
94 } 94 }
95 95
96 private: 96 private:
97 int32_t fDone; // atomic 97 int32_t fDone; // atomic
98 const int fTotal; 98 const int fTotal;
99 }; 99 };
100 100
101 SkString Test::GetTmpDir() {
102 const char* tmpDir = FLAGS_tmpDir.isEmpty() ? NULL : FLAGS_tmpDir[0];
103 return SkString(tmpDir);
104 }
105
106 SkString Test::GetResourcePath() {
107 const char* resourcePath = FLAGS_resourcePath.isEmpty() ? NULL : FLAGS_resou rcePath[0];
108 return SkString(resourcePath);
109 }
110
111 // Deletes self when run. 101 // Deletes self when run.
112 class SkTestRunnable : public SkRunnable { 102 class SkTestRunnable : public SkRunnable {
113 public: 103 public:
114 // Takes ownership of test. 104 // Takes ownership of test.
115 SkTestRunnable(Test* test, int32_t* failCount) : fTest(test), fFailCount(failC ount) {} 105 SkTestRunnable(Test* test, int32_t* failCount) : fTest(test), fFailCount(failC ount) {}
116 106
117 virtual void run() { 107 virtual void run() {
118 fTest->run(); 108 fTest->run();
119 if(!fTest->passed()) { 109 if(!fTest->passed()) {
120 sk_atomic_inc(fFailCount); 110 sk_atomic_inc(fFailCount);
(...skipping 16 matching lines...) Expand all
137 if (!FLAGS_gpu && isGPUTest) { 127 if (!FLAGS_gpu && isGPUTest) {
138 return false; 128 return false;
139 } 129 }
140 return true; 130 return true;
141 } 131 }
142 132
143 int tool_main(int argc, char** argv); 133 int tool_main(int argc, char** argv);
144 int tool_main(int argc, char** argv) { 134 int tool_main(int argc, char** argv) {
145 SkCommandLineFlags::SetUsage(""); 135 SkCommandLineFlags::SetUsage("");
146 SkCommandLineFlags::Parse(argc, argv); 136 SkCommandLineFlags::Parse(argc, argv);
137 Test::SetResourcePath(FLAGS_resourcePath[0]);
147 138
148 #if SK_ENABLE_INST_COUNT 139 #if SK_ENABLE_INST_COUNT
149 if (FLAGS_leaks) { 140 if (FLAGS_leaks) {
150 gPrintInstCount = true; 141 gPrintInstCount = true;
151 } 142 }
152 #endif 143 #endif
153 144
154 SkGraphics::Init(); 145 SkGraphics::Init();
155 146
156 { 147 {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 183 }
193 total++; 184 total++;
194 } 185 }
195 186
196 // Now run them. 187 // Now run them.
197 iter.reset(); 188 iter.reset();
198 int32_t failCount = 0; 189 int32_t failCount = 0;
199 int skipCount = 0; 190 int skipCount = 0;
200 191
201 SkThreadPool threadpool(FLAGS_threads); 192 SkThreadPool threadpool(FLAGS_threads);
202 SkTArray<Test*> unsafeTests; // Always passes ownership to an SkTestRunnabl e 193 SkTArray<Test*> gpuTests; // Always passes ownership to an SkTestRunnable
203 194
204 DebugfReporter reporter(toRun); 195 DebugfReporter reporter(toRun);
205 for (int i = 0; i < total; i++) { 196 for (int i = 0; i < total; i++) {
206 SkAutoTDelete<Test> test(iter.next(&reporter)); 197 SkAutoTDelete<Test> test(iter.next(&reporter));
207 if (!should_run(test->getName(), test->isGPUTest())) { 198 if (!should_run(test->getName(), test->isGPUTest())) {
208 ++skipCount; 199 ++skipCount;
209 } else if (test->isGPUTest()) { 200 } else if (test->isGPUTest()) {
210 unsafeTests.push_back() = test.detach(); 201 gpuTests.push_back() = test.detach();
211 } else { 202 } else {
212 threadpool.add(SkNEW_ARGS(SkTestRunnable, (test.detach(), &failCount ))); 203 threadpool.add(SkNEW_ARGS(SkTestRunnable, (test.detach(), &failCount )));
213 } 204 }
214 } 205 }
215 206
216 // Run the tests that aren't threadsafe. 207 #if SK_SUPPORT_GPU
217 for (int i = 0; i < unsafeTests.count(); i++) { 208 // Give GPU tests a context factory if that makes sense on this machine.
218 SkNEW_ARGS(SkTestRunnable, (unsafeTests[i], &failCount))->run(); 209 GrContextFactory grContextFactory;
210 for (int i = 0; i < gpuTests.count(); i++) {
211 gpuTests[i]->setGrContextFactory(&grContextFactory);
212 }
213 #endif
214
215 // Run GPU tests on this thread.
216 for (int i = 0; i < gpuTests.count(); i++) {
217 SkNEW_ARGS(SkTestRunnable, (gpuTests[i], &failCount))->run();
219 } 218 }
220 219
221 // Block until threaded tests finish. 220 // Block until threaded tests finish.
222 threadpool.wait(); 221 threadpool.wait();
223 222
224 if (FLAGS_verbose) { 223 if (FLAGS_verbose) {
225 SkDebugf("\nFinished %d tests, %d failures, %d skipped. (%d internal tes ts)", 224 SkDebugf("\nFinished %d tests, %d failures, %d skipped. (%d internal tes ts)",
226 toRun, failCount, skipCount, reporter.countTests()); 225 toRun, failCount, skipCount, reporter.countTests());
227 } 226 }
228 SkGraphics::Term(); 227 SkGraphics::Term();
229 GpuTest::DestroyContexts();
230 228
231 SkDebugf("\n"); 229 SkDebugf("\n");
232 return (failCount == 0) ? 0 : 1; 230 return (failCount == 0) ? 0 : 1;
233 } 231 }
234 232
235 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 233 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
236 int main(int argc, char * const argv[]) { 234 int main(int argc, char * const argv[]) {
237 return tool_main(argc, (char**) argv); 235 return tool_main(argc, (char**) argv);
238 } 236 }
239 #endif 237 #endif
OLDNEW
« no previous file with comments | « tests/Test.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698