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

Side by Side Diff: tests/skia_test.cpp

Issue 16098011: Fix bug in setting directories for tests. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Respond to comments Created 7 years, 6 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 "SkOSFile.h" 10 #include "SkOSFile.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 private: 107 private:
108 int32_t fNextIndex; 108 int32_t fNextIndex;
109 int32_t fPending; 109 int32_t fPending;
110 int fTotal; 110 int fTotal;
111 bool fAllowExtendedTest; 111 bool fAllowExtendedTest;
112 bool fAllowThreaded; 112 bool fAllowThreaded;
113 }; 113 };
114 114
115 static const char* make_canonical_dir_path(const char* path, SkString* storage) {
116 if (path) {
117 // clean it up so it always has a trailing searator
118 size_t len = strlen(path);
119 if (0 == len) {
120 path = NULL;
121 } else if (SkPATH_SEPARATOR != path[len - 1]) {
122 // resize to len + 1, to make room for searator
123 storage->set(path, len + 1);
124 storage->writable_str()[len] = SkPATH_SEPARATOR;
125 path = storage->c_str();
126 }
127 }
128 return path;
129 }
130
131 static SkString gTmpDir;
132
133 const SkString& Test::GetTmpDir() {
134 return gTmpDir;
135 }
136
137 static SkString gResourcePath;
138
139 const SkString& Test::GetResourcePath() {
140 return gResourcePath;
141 }
142
143 DEFINE_string2(match, m, NULL, "[~][^]substring[$] [...] of test name to run.\n" \ 115 DEFINE_string2(match, m, NULL, "[~][^]substring[$] [...] of test name to run.\n" \
144 "Multiple matches may be separated by spaces.\n" \ 116 "Multiple matches may be separated by spaces.\n" \
145 "~ causes a matching test to always be skipped\n" \ 117 "~ causes a matching test to always be skipped\n" \
146 "^ requires the start of the test to match\n" \ 118 "^ requires the start of the test to match\n" \
147 "$ requires the end of the test to match\n" \ 119 "$ requires the end of the test to match\n" \
148 "^ and $ requires an exact match\n" \ 120 "^ and $ requires an exact match\n" \
149 "If a test does not match any list entry,\n" \ 121 "If a test does not match any list entry,\n" \
150 "it is skipped unless some list entry starts with ~"); 122 "it is skipped unless some list entry starts with ~");
151 DEFINE_string2(tmpDir, t, NULL, "tmp directory for tests to use."); 123 DEFINE_string2(tmpDir, t, NULL, "tmp directory for tests to use.");
152 DEFINE_string2(resourcePath, i, NULL, "directory for test resources."); 124 DEFINE_string2(resourcePath, i, NULL, "directory for test resources.");
153 DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps."); 125 DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps.");
154 DEFINE_bool2(threaded, z, false, "allow tests to use multiple threads internally ."); 126 DEFINE_bool2(threaded, z, false, "allow tests to use multiple threads internally .");
155 DEFINE_bool2(verbose, v, false, "enable verbose output."); 127 DEFINE_bool2(verbose, v, false, "enable verbose output.");
156 DEFINE_int32(threads, SkThreadPool::kThreadPerCore, 128 DEFINE_int32(threads, SkThreadPool::kThreadPerCore,
157 "Run threadsafe tests on a threadpool with this many threads."); 129 "Run threadsafe tests on a threadpool with this many threads.");
158 130
131 SkString Test::GetTmpDir() {
132 const char* tmpDir = FLAGS_tmpDir.isEmpty() ? NULL : FLAGS_tmpDir[0];
133 return SkString(tmpDir);
134 }
135
136 SkString Test::GetResourcePath() {
137 const char* resourcePath = FLAGS_resourcePath.isEmpty() ? NULL : FLAGS_resou rcePath[0];
138 return SkString(resourcePath);
139 }
140
159 // Deletes self when run. 141 // Deletes self when run.
160 class SkTestRunnable : public SkRunnable { 142 class SkTestRunnable : public SkRunnable {
161 public: 143 public:
162 // Takes ownership of test. 144 // Takes ownership of test.
163 SkTestRunnable(Test* test, int32_t* failCount) : fTest(test), fFailCount(failC ount) {} 145 SkTestRunnable(Test* test, int32_t* failCount) : fTest(test), fFailCount(failC ount) {}
164 146
165 virtual void run() { 147 virtual void run() {
166 fTest->run(); 148 fTest->run();
167 if(!fTest->passed()) { 149 if(!fTest->passed()) {
168 sk_atomic_inc(fFailCount); 150 sk_atomic_inc(fFailCount);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 193 }
212 } 194 }
213 return !anyExclude; 195 return !anyExclude;
214 } 196 }
215 197
216 int tool_main(int argc, char** argv); 198 int tool_main(int argc, char** argv);
217 int tool_main(int argc, char** argv) { 199 int tool_main(int argc, char** argv) {
218 SkCommandLineFlags::SetUsage(""); 200 SkCommandLineFlags::SetUsage("");
219 SkCommandLineFlags::Parse(argc, argv); 201 SkCommandLineFlags::Parse(argc, argv);
220 202
221 if (!FLAGS_tmpDir.isEmpty()) {
222 make_canonical_dir_path(FLAGS_tmpDir[0], &gTmpDir);
223 }
224 if (!FLAGS_resourcePath.isEmpty()) {
225 make_canonical_dir_path(FLAGS_resourcePath[0], &gResourcePath);
226 }
227
228 #if SK_ENABLE_INST_COUNT 203 #if SK_ENABLE_INST_COUNT
229 gPrintInstCount = true; 204 gPrintInstCount = true;
230 #endif 205 #endif
231 206
232 SkGraphics::Init(); 207 SkGraphics::Init();
233 208
234 { 209 {
235 SkString header("Skia UnitTests:"); 210 SkString header("Skia UnitTests:");
236 if (!FLAGS_match.isEmpty()) { 211 if (!FLAGS_match.isEmpty()) {
237 header.appendf(" --match"); 212 header.appendf(" --match");
238 for (int index = 0; index < FLAGS_match.count(); ++index) { 213 for (int index = 0; index < FLAGS_match.count(); ++index) {
239 header.appendf(" %s", FLAGS_match[index]); 214 header.appendf(" %s", FLAGS_match[index]);
240 } 215 }
241 } 216 }
242 if (!gTmpDir.isEmpty()) { 217 SkString tmpDir = Test::GetTmpDir();
243 header.appendf(" --tmpDir %s", gTmpDir.c_str()); 218 if (!tmpDir.isEmpty()) {
219 header.appendf(" --tmpDir %s", tmpDir.c_str());
244 } 220 }
245 if (!gResourcePath.isEmpty()) { 221 SkString resourcePath = Test::GetResourcePath();
246 header.appendf(" --resourcePath %s", gResourcePath.c_str()); 222 if (!resourcePath.isEmpty()) {
223 header.appendf(" --resourcePath %s", resourcePath.c_str());
247 } 224 }
248 #ifdef SK_DEBUG 225 #ifdef SK_DEBUG
249 header.append(" SK_DEBUG"); 226 header.append(" SK_DEBUG");
250 #else 227 #else
251 header.append(" SK_RELEASE"); 228 header.append(" SK_RELEASE");
252 #endif 229 #endif
253 #ifdef SK_SCALAR_IS_FIXED 230 #ifdef SK_SCALAR_IS_FIXED
254 header.append(" SK_SCALAR_IS_FIXED"); 231 header.append(" SK_SCALAR_IS_FIXED");
255 #else 232 #else
256 header.append(" SK_SCALAR_IS_FLOAT"); 233 header.append(" SK_SCALAR_IS_FLOAT");
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 GpuTest::DestroyContexts(); 297 GpuTest::DestroyContexts();
321 298
322 return (failCount == 0) ? 0 : 1; 299 return (failCount == 0) ? 0 : 1;
323 } 300 }
324 301
325 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 302 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
326 int main(int argc, char * const argv[]) { 303 int main(int argc, char * const argv[]) {
327 return tool_main(argc, (char**) argv); 304 return tool_main(argc, (char**) argv);
328 } 305 }
329 #endif 306 #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