OLD | NEW |
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 "CrashHandler.h" | 8 #include "CrashHandler.h" |
9 #include "OverwriteLine.h" | 9 #include "OverwriteLine.h" |
10 #include "Resources.h" | 10 #include "Resources.h" |
11 #include "SkAtomics.h" | 11 #include "SkAtomics.h" |
12 #include "SkCommonFlags.h" | 12 #include "SkCommonFlags.h" |
13 #include "SkGraphics.h" | 13 #include "SkGraphics.h" |
14 #include "SkOSFile.h" | 14 #include "SkOSFile.h" |
15 #include "SkRunnable.h" | |
16 #include "SkTArray.h" | 15 #include "SkTArray.h" |
17 #include "SkTaskGroup.h" | 16 #include "SkTaskGroup.h" |
18 #include "SkTemplates.h" | 17 #include "SkTemplates.h" |
19 #include "SkTime.h" | 18 #include "SkTime.h" |
20 #include "Test.h" | 19 #include "Test.h" |
21 | 20 |
22 #if SK_SUPPORT_GPU | 21 #if SK_SUPPORT_GPU |
23 #include "GrContext.h" | 22 #include "GrContext.h" |
24 #include "GrContextFactory.h" | 23 #include "GrContextFactory.h" |
25 #endif | 24 #endif |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 int32_t testCount() { return fTestCount; } | 64 int32_t testCount() { return fTestCount; } |
66 int32_t failCount() { return fFailCount; } | 65 int32_t failCount() { return fFailCount; } |
67 | 66 |
68 private: | 67 private: |
69 int32_t fDone; // atomic | 68 int32_t fDone; // atomic |
70 int32_t fTestCount; // atomic | 69 int32_t fTestCount; // atomic |
71 int32_t fFailCount; // atomic | 70 int32_t fFailCount; // atomic |
72 const int fTotal; | 71 const int fTotal; |
73 }; | 72 }; |
74 | 73 |
75 // Deletes self when run. | 74 class SkTestRunnable { |
76 class SkTestRunnable : public SkRunnable { | |
77 public: | 75 public: |
78 SkTestRunnable(const Test& test, | 76 SkTestRunnable(const Test& test, |
79 Status* status, | 77 Status* status, |
80 GrContextFactory* grContextFactory = nullptr) | 78 GrContextFactory* grContextFactory = nullptr) |
81 : fTest(test), fStatus(status), fGrContextFactory(grContextFactory) {} | 79 : fTest(test), fStatus(status), fGrContextFactory(grContextFactory) {} |
82 | 80 |
83 virtual void run() { | 81 void operator()() { |
84 struct TestReporter : public skiatest::Reporter { | 82 struct TestReporter : public skiatest::Reporter { |
85 public: | 83 public: |
86 TestReporter() : fError(false), fTestCount(0) {} | 84 TestReporter() : fError(false), fTestCount(0) {} |
87 void bumpTestCount() override { ++fTestCount; } | 85 void bumpTestCount() override { ++fTestCount; } |
88 bool allowExtendedTest() const override { | 86 bool allowExtendedTest() const override { |
89 return FLAGS_extendedTest; | 87 return FLAGS_extendedTest; |
90 } | 88 } |
91 bool verbose() const override { return FLAGS_veryVerbose; } | 89 bool verbose() const override { return FLAGS_veryVerbose; } |
92 void reportFailed(const skiatest::Failure& failure) override { | 90 void reportFailed(const skiatest::Failure& failure) override { |
93 SkDebugf("\nFAILED: %s", failure.toString().c_str()); | 91 SkDebugf("\nFAILED: %s", failure.toString().c_str()); |
94 fError = true; | 92 fError = true; |
95 } | 93 } |
96 bool fError; | 94 bool fError; |
97 int fTestCount; | 95 int fTestCount; |
98 } reporter; | 96 } reporter; |
99 | 97 |
100 const SkMSec start = SkTime::GetMSecs(); | 98 const SkMSec start = SkTime::GetMSecs(); |
101 fTest.proc(&reporter, fGrContextFactory); | 99 fTest.proc(&reporter, fGrContextFactory); |
102 SkMSec elapsed = SkTime::GetMSecs() - start; | 100 SkMSec elapsed = SkTime::GetMSecs() - start; |
103 if (reporter.fError) { | 101 if (reporter.fError) { |
104 fStatus->reportFailure(); | 102 fStatus->reportFailure(); |
105 } | 103 } |
106 fStatus->endTest(fTest.name, !reporter.fError, elapsed, | 104 fStatus->endTest(fTest.name, !reporter.fError, elapsed, |
107 reporter.fTestCount); | 105 reporter.fTestCount); |
108 delete this; | |
109 } | 106 } |
110 | 107 |
111 private: | 108 private: |
112 Test fTest; | 109 Test fTest; |
113 Status* fStatus; | 110 Status* fStatus; |
114 GrContextFactory* fGrContextFactory; | 111 GrContextFactory* fGrContextFactory; |
115 }; | 112 }; |
116 | 113 |
117 static bool should_run(const char* testName, bool isGPUTest) { | 114 static bool should_run(const char* testName, bool isGPUTest) { |
118 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, testName)) { | 115 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, testName)) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 180 |
184 Status status(toRun); | 181 Status status(toRun); |
185 for (const TestRegistry* iter = TestRegistry::Head(); iter; | 182 for (const TestRegistry* iter = TestRegistry::Head(); iter; |
186 iter = iter->next()) { | 183 iter = iter->next()) { |
187 const Test& test = iter->factory(); | 184 const Test& test = iter->factory(); |
188 if (!should_run(test.name, test.needsGpu)) { | 185 if (!should_run(test.name, test.needsGpu)) { |
189 ++skipCount; | 186 ++skipCount; |
190 } else if (test.needsGpu) { | 187 } else if (test.needsGpu) { |
191 gpuTests.push_back(&test); | 188 gpuTests.push_back(&test); |
192 } else { | 189 } else { |
193 cpuTests.add(new SkTestRunnable(test, &status)); | 190 cpuTests.add(SkTestRunnable(test, &status)); |
194 } | 191 } |
195 } | 192 } |
196 | 193 |
197 GrContextFactory* grContextFactoryPtr = nullptr; | 194 GrContextFactory* grContextFactoryPtr = nullptr; |
198 #if SK_SUPPORT_GPU | 195 #if SK_SUPPORT_GPU |
199 // Give GPU tests a context factory if that makes sense on this machine. | 196 // Give GPU tests a context factory if that makes sense on this machine. |
200 GrContextFactory grContextFactory; | 197 GrContextFactory grContextFactory; |
201 grContextFactoryPtr = &grContextFactory; | 198 grContextFactoryPtr = &grContextFactory; |
202 | 199 |
203 #endif | 200 #endif |
204 | 201 |
205 // Run GPU tests on this thread. | 202 // Run GPU tests on this thread. |
206 for (int i = 0; i < gpuTests.count(); i++) { | 203 for (int i = 0; i < gpuTests.count(); i++) { |
207 (new SkTestRunnable(*gpuTests[i], &status, grContextFactoryPtr))->run(); | 204 SkTestRunnable(*gpuTests[i], &status, grContextFactoryPtr)(); |
208 } | 205 } |
209 | 206 |
210 // Block until threaded tests finish. | 207 // Block until threaded tests finish. |
211 cpuTests.wait(); | 208 cpuTests.wait(); |
212 | 209 |
213 if (FLAGS_verbose) { | 210 if (FLAGS_verbose) { |
214 SkDebugf( | 211 SkDebugf( |
215 "\nFinished %d tests, %d failures, %d skipped. " | 212 "\nFinished %d tests, %d failures, %d skipped. " |
216 "(%d internal tests)", | 213 "(%d internal tests)", |
217 toRun, status.failCount(), skipCount, status.testCount()); | 214 toRun, status.failCount(), skipCount, status.testCount()); |
218 if (gVerboseFinalize) { | 215 if (gVerboseFinalize) { |
219 (*gVerboseFinalize)(); | 216 (*gVerboseFinalize)(); |
220 } | 217 } |
221 } | 218 } |
222 | 219 |
223 SkDebugf("\n"); | 220 SkDebugf("\n"); |
224 return (status.failCount() == 0) ? 0 : 1; | 221 return (status.failCount() == 0) ? 0 : 1; |
225 } | 222 } |
226 | 223 |
227 #if !defined(SK_BUILD_FOR_IOS) | 224 #if !defined(SK_BUILD_FOR_IOS) |
228 int main(int argc, char** argv) { | 225 int main(int argc, char** argv) { |
229 SkCommandLineFlags::Parse(argc, argv); | 226 SkCommandLineFlags::Parse(argc, argv); |
230 return test_main(); | 227 return test_main(); |
231 } | 228 } |
232 #endif | 229 #endif |
OLD | NEW |