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

Side by Side Diff: tests/skia_test.cpp

Issue 14002007: allow tests to optionally use multiple threads (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « tests/Test.h ('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 "SkCommandLineFlags.h" 8 #include "SkCommandLineFlags.h"
9 #include "SkGraphics.h" 9 #include "SkGraphics.h"
10 #include "Test.h" 10 #include "Test.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 Reporter* fReporter; 55 Reporter* fReporter;
56 const TestRegistry* fReg; 56 const TestRegistry* fReg;
57 }; 57 };
58 58
59 static const char* result2string(Reporter::Result result) { 59 static const char* result2string(Reporter::Result result) {
60 return result == Reporter::kPassed ? "passed" : "FAILED"; 60 return result == Reporter::kPassed ? "passed" : "FAILED";
61 } 61 }
62 62
63 class DebugfReporter : public Reporter { 63 class DebugfReporter : public Reporter {
64 public: 64 public:
65 DebugfReporter(bool allowExtendedTest) 65 DebugfReporter(bool allowExtendedTest, bool allowThreaded)
66 : fIndex(0) 66 : fIndex(0)
67 , fTotal(0) 67 , fTotal(0)
68 , fAllowExtendedTest(allowExtendedTest) { 68 , fAllowExtendedTest(allowExtendedTest)
69 , fAllowThreaded(allowThreaded) {
69 } 70 }
70 71
71 void setIndexOfTotal(int index, int total) { 72 void setIndexOfTotal(int index, int total) {
72 fIndex = index; 73 fIndex = index;
73 fTotal = total; 74 fTotal = total;
74 } 75 }
75 76
76 virtual bool allowExtendedTest() const { 77 virtual bool allowExtendedTest() const {
77 return fAllowExtendedTest; 78 return fAllowExtendedTest;
78 } 79 }
79 80
81 virtual bool allowThreaded() const {
82 return fAllowThreaded;
83 }
84
80 protected: 85 protected:
81 virtual void onStart(Test* test) { 86 virtual void onStart(Test* test) {
82 SkDebugf("[%d/%d] %s...\n", fIndex+1, fTotal, test->getName()); 87 SkDebugf("[%d/%d] %s...\n", fIndex+1, fTotal, test->getName());
83 } 88 }
84 virtual void onReport(const char desc[], Reporter::Result result) { 89 virtual void onReport(const char desc[], Reporter::Result result) {
85 SkDebugf("\t%s: %s\n", result2string(result), desc); 90 SkDebugf("\t%s: %s\n", result2string(result), desc);
86 } 91 }
87 virtual void onEnd(Test*) { 92 virtual void onEnd(Test*) {
88 if (!this->getCurrSuccess()) { 93 if (!this->getCurrSuccess()) {
89 SkDebugf("---- FAILED\n"); 94 SkDebugf("---- FAILED\n");
90 } 95 }
91 } 96 }
92 private: 97 private:
93 int fIndex, fTotal; 98 int fIndex, fTotal;
94 bool fAllowExtendedTest; 99 bool fAllowExtendedTest;
100 bool fAllowThreaded;
95 }; 101 };
96 102
97 static const char* make_canonical_dir_path(const char* path, SkString* storage) { 103 static const char* make_canonical_dir_path(const char* path, SkString* storage) {
98 if (path) { 104 if (path) {
99 // clean it up so it always has a trailing searator 105 // clean it up so it always has a trailing searator
100 size_t len = strlen(path); 106 size_t len = strlen(path);
101 if (0 == len) { 107 if (0 == len) {
102 path = NULL; 108 path = NULL;
103 } else if (SkPATH_SEPARATOR != path[len - 1]) { 109 } else if (SkPATH_SEPARATOR != path[len - 1]) {
104 // resize to len + 1, to make room for searator 110 // resize to len + 1, to make room for searator
(...skipping 14 matching lines...) Expand all
119 static SkString gResourcePath; 125 static SkString gResourcePath;
120 126
121 const SkString& Test::GetResourcePath() { 127 const SkString& Test::GetResourcePath() {
122 return gResourcePath; 128 return gResourcePath;
123 } 129 }
124 130
125 DEFINE_string2(match, m, NULL, "substring of test name to run."); 131 DEFINE_string2(match, m, NULL, "substring of test name to run.");
126 DEFINE_string2(tmpDir, t, NULL, "tmp directory for tests to use."); 132 DEFINE_string2(tmpDir, t, NULL, "tmp directory for tests to use.");
127 DEFINE_string2(resourcePath, i, NULL, "directory for test resources."); 133 DEFINE_string2(resourcePath, i, NULL, "directory for test resources.");
128 DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps."); 134 DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps.");
135 DEFINE_bool2(threaded, z, false, "allow tests to use multiple threads.");
129 DEFINE_bool2(verbose, v, false, "enable verbose output."); 136 DEFINE_bool2(verbose, v, false, "enable verbose output.");
130 137
131 int tool_main(int argc, char** argv); 138 int tool_main(int argc, char** argv);
132 int tool_main(int argc, char** argv) { 139 int tool_main(int argc, char** argv) {
133 SkCommandLineFlags::SetUsage(""); 140 SkCommandLineFlags::SetUsage("");
134 SkCommandLineFlags::Parse(argc, argv); 141 SkCommandLineFlags::Parse(argc, argv);
135 142
136 if (!FLAGS_tmpDir.isEmpty()) { 143 if (!FLAGS_tmpDir.isEmpty()) {
137 make_canonical_dir_path(FLAGS_tmpDir[0], &gTmpDir); 144 make_canonical_dir_path(FLAGS_tmpDir[0], &gTmpDir);
138 } 145 }
(...skipping 24 matching lines...) Expand all
163 header.append(" SK_RELEASE"); 170 header.append(" SK_RELEASE");
164 #endif 171 #endif
165 #ifdef SK_SCALAR_IS_FIXED 172 #ifdef SK_SCALAR_IS_FIXED
166 header.append(" SK_SCALAR_IS_FIXED"); 173 header.append(" SK_SCALAR_IS_FIXED");
167 #else 174 #else
168 header.append(" SK_SCALAR_IS_FLOAT"); 175 header.append(" SK_SCALAR_IS_FLOAT");
169 #endif 176 #endif
170 SkDebugf("%s\n", header.c_str()); 177 SkDebugf("%s\n", header.c_str());
171 } 178 }
172 179
173 DebugfReporter reporter(FLAGS_extendedTest); 180 DebugfReporter reporter(FLAGS_extendedTest, FLAGS_threaded);
174 Iter iter(&reporter); 181 Iter iter(&reporter);
175 Test* test; 182 Test* test;
176 183
177 const int count = Iter::Count(); 184 const int count = Iter::Count();
178 int index = 0; 185 int index = 0;
179 int failCount = 0; 186 int failCount = 0;
180 int skipCount = 0; 187 int skipCount = 0;
181 while ((test = iter.next()) != NULL) { 188 while ((test = iter.next()) != NULL) {
182 reporter.setIndexOfTotal(index, count); 189 reporter.setIndexOfTotal(index, count);
183 if (!FLAGS_match.isEmpty() && !strstr(test->getName(), FLAGS_match[0])) { 190 if (!FLAGS_match.isEmpty() && !strstr(test->getName(), FLAGS_match[0])) {
(...skipping 27 matching lines...) Expand all
211 GpuTest::DestroyContexts(); 218 GpuTest::DestroyContexts();
212 219
213 return (failCount == 0) ? 0 : 1; 220 return (failCount == 0) ? 0 : 1;
214 } 221 }
215 222
216 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 223 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
217 int main(int argc, char * const argv[]) { 224 int main(int argc, char * const argv[]) {
218 return tool_main(argc, (char**) argv); 225 return tool_main(argc, (char**) argv);
219 } 226 }
220 #endif 227 #endif
OLDNEW
« no previous file with comments | « tests/Test.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698