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

Side by Side Diff: tests/skia_test.cpp

Issue 179403010: Revert of Let DM run unit tests. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 10 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"
21 #endif 20 #endif
22 21
23 using namespace skiatest; 22 using namespace skiatest;
24 23
25 DEFINE_string2(match, m, NULL, "[~][^]substring[$] [...] of test name to run.\n" \ 24 DEFINE_string2(match, m, NULL, "[~][^]substring[$] [...] of test name to run.\n" \
26 "Multiple matches may be separated by spaces.\n" \ 25 "Multiple matches may be separated by spaces.\n" \
27 "~ causes a matching test to always be skipped\n" \ 26 "~ causes a matching test to always be skipped\n" \
28 "^ requires the start of the test to match\n" \ 27 "^ requires the start of the test to match\n" \
29 "$ requires the end of the test to match\n" \ 28 "$ requires the end of the test to match\n" \
30 "^ and $ requires an exact match\n" \ 29 "^ and $ requires an exact match\n" \
31 "If a test does not match any list entry,\n" \ 30 "If a test does not match any list entry,\n" \
32 "it is skipped unless some list entry starts with ~"); 31 "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.");
33 DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps."); 34 DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps.");
34 DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects."); 35 DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects.");
35 DEFINE_bool2(single, z, false, "run tests on a single thread internally."); 36 DEFINE_bool2(single, z, false, "run tests on a single thread internally.");
36 DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver."); 37 DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver.");
37 DEFINE_bool2(veryVerbose, V, false, "tell individual tests to be verbose."); 38 DEFINE_bool2(veryVerbose, V, false, "tell individual tests to be verbose.");
38 DEFINE_bool(cpu, true, "whether or not to run CPU tests."); 39 DEFINE_bool(cpu, true, "whether or not to run CPU tests.");
39 DEFINE_bool(gpu, true, "whether or not to run GPU tests."); 40 DEFINE_bool(gpu, true, "whether or not to run GPU tests.");
40 DEFINE_int32(threads, SkThreadPool::kThreadPerCore, 41 DEFINE_int32(threads, SkThreadPool::kThreadPerCore,
41 "Run threadsafe tests on a threadpool with this many threads."); 42 "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
101 // Deletes self when run. 111 // Deletes self when run.
102 class SkTestRunnable : public SkRunnable { 112 class SkTestRunnable : public SkRunnable {
103 public: 113 public:
104 // Takes ownership of test. 114 // Takes ownership of test.
105 SkTestRunnable(Test* test, int32_t* failCount) : fTest(test), fFailCount(failC ount) {} 115 SkTestRunnable(Test* test, int32_t* failCount) : fTest(test), fFailCount(failC ount) {}
106 116
107 virtual void run() { 117 virtual void run() {
108 fTest->run(); 118 fTest->run();
109 if(!fTest->passed()) { 119 if(!fTest->passed()) {
110 sk_atomic_inc(fFailCount); 120 sk_atomic_inc(fFailCount);
(...skipping 16 matching lines...) Expand all
127 if (!FLAGS_gpu && isGPUTest) { 137 if (!FLAGS_gpu && isGPUTest) {
128 return false; 138 return false;
129 } 139 }
130 return true; 140 return true;
131 } 141 }
132 142
133 int tool_main(int argc, char** argv); 143 int tool_main(int argc, char** argv);
134 int tool_main(int argc, char** argv) { 144 int tool_main(int argc, char** argv) {
135 SkCommandLineFlags::SetUsage(""); 145 SkCommandLineFlags::SetUsage("");
136 SkCommandLineFlags::Parse(argc, argv); 146 SkCommandLineFlags::Parse(argc, argv);
137 Test::SetResourcePath(FLAGS_resourcePath[0]);
138 147
139 #if SK_ENABLE_INST_COUNT 148 #if SK_ENABLE_INST_COUNT
140 if (FLAGS_leaks) { 149 if (FLAGS_leaks) {
141 gPrintInstCount = true; 150 gPrintInstCount = true;
142 } 151 }
143 #endif 152 #endif
144 153
145 SkGraphics::Init(); 154 SkGraphics::Init();
146 155
147 { 156 {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 192 }
184 total++; 193 total++;
185 } 194 }
186 195
187 // Now run them. 196 // Now run them.
188 iter.reset(); 197 iter.reset();
189 int32_t failCount = 0; 198 int32_t failCount = 0;
190 int skipCount = 0; 199 int skipCount = 0;
191 200
192 SkThreadPool threadpool(FLAGS_threads); 201 SkThreadPool threadpool(FLAGS_threads);
193 SkTArray<Test*> gpuTests; // Always passes ownership to an SkTestRunnable 202 SkTArray<Test*> unsafeTests; // Always passes ownership to an SkTestRunnabl e
194 203
195 DebugfReporter reporter(toRun); 204 DebugfReporter reporter(toRun);
196 for (int i = 0; i < total; i++) { 205 for (int i = 0; i < total; i++) {
197 SkAutoTDelete<Test> test(iter.next(&reporter)); 206 SkAutoTDelete<Test> test(iter.next(&reporter));
198 if (!should_run(test->getName(), test->isGPUTest())) { 207 if (!should_run(test->getName(), test->isGPUTest())) {
199 ++skipCount; 208 ++skipCount;
200 } else if (test->isGPUTest()) { 209 } else if (test->isGPUTest()) {
201 gpuTests.push_back() = test.detach(); 210 unsafeTests.push_back() = test.detach();
202 } else { 211 } else {
203 threadpool.add(SkNEW_ARGS(SkTestRunnable, (test.detach(), &failCount ))); 212 threadpool.add(SkNEW_ARGS(SkTestRunnable, (test.detach(), &failCount )));
204 } 213 }
205 } 214 }
206 215
207 #if SK_SUPPORT_GPU 216 // Run the tests that aren't threadsafe.
208 GrContextFactory grContextFactory; 217 for (int i = 0; i < unsafeTests.count(); i++) {
209 // Run GPU tests on this thread. 218 SkNEW_ARGS(SkTestRunnable, (unsafeTests[i], &failCount))->run();
210 for (int i = 0; i < gpuTests.count(); i++) {
211 gpuTests[i]->setGrContextFactory(&grContextFactory);
212 SkNEW_ARGS(SkTestRunnable, (gpuTests[i], &failCount))->run();
213 } 219 }
214 #endif
215 220
216 // Block until threaded tests finish. 221 // Block until threaded tests finish.
217 threadpool.wait(); 222 threadpool.wait();
218 223
219 if (FLAGS_verbose) { 224 if (FLAGS_verbose) {
220 SkDebugf("\nFinished %d tests, %d failures, %d skipped. (%d internal tes ts)", 225 SkDebugf("\nFinished %d tests, %d failures, %d skipped. (%d internal tes ts)",
221 toRun, failCount, skipCount, reporter.countTests()); 226 toRun, failCount, skipCount, reporter.countTests());
222 } 227 }
223 SkGraphics::Term(); 228 SkGraphics::Term();
229 GpuTest::DestroyContexts();
224 230
225 SkDebugf("\n"); 231 SkDebugf("\n");
226 return (failCount == 0) ? 0 : 1; 232 return (failCount == 0) ? 0 : 1;
227 } 233 }
228 234
229 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 235 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
230 int main(int argc, char * const argv[]) { 236 int main(int argc, char * const argv[]) {
231 return tool_main(argc, (char**) argv); 237 return tool_main(argc, (char**) argv);
232 } 238 }
233 #endif 239 #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