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

Side by Side Diff: tests/PathOpsSkpClipTest.cpp

Issue 531653002: SkThreadPool ~~> SkTaskGroup (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cleanup allowThreaded() Created 6 years, 3 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
OLDNEW
1 #include "CrashHandler.h" 1 #include "CrashHandler.h"
2 // #include "OverwriteLine.h" 2 // #include "OverwriteLine.h"
3 #include "Resources.h" 3 #include "Resources.h"
4 #include "SkBitmap.h" 4 #include "SkBitmap.h"
5 #include "SkCanvas.h" 5 #include "SkCanvas.h"
6 #include "SkColor.h" 6 #include "SkColor.h"
7 #include "SkColorPriv.h" 7 #include "SkColorPriv.h"
8 #include "SkCommandLineFlags.h" 8 #include "SkCommandLineFlags.h"
9 #include "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkForceLinking.h" 10 #include "SkForceLinking.h"
11 #include "SkGraphics.h" 11 #include "SkGraphics.h"
12 #include "SkImageDecoder.h" 12 #include "SkImageDecoder.h"
13 #include "SkImageEncoder.h" 13 #include "SkImageEncoder.h"
14 #include "SkOSFile.h" 14 #include "SkOSFile.h"
15 #include "SkPathOpsDebug.h" 15 #include "SkPathOpsDebug.h"
16 #include "SkPicture.h" 16 #include "SkPicture.h"
17 #include "SkRTConf.h" 17 #include "SkRTConf.h"
18 #include "SkTSort.h" 18 #include "SkTSort.h"
19 #include "SkStream.h" 19 #include "SkStream.h"
20 #include "SkString.h" 20 #include "SkString.h"
21 #include "SkTArray.h" 21 #include "SkTArray.h"
22 #include "SkTDArray.h" 22 #include "SkTDArray.h"
23 #include "SkTaskGroup.h"
23 #include "SkTemplates.h" 24 #include "SkTemplates.h"
24 #include "SkThreadPool.h"
25 #include "SkTime.h" 25 #include "SkTime.h"
26 26
27 __SK_FORCE_IMAGE_DECODER_LINKING; 27 __SK_FORCE_IMAGE_DECODER_LINKING;
28 28
29 /* add local exceptions here */ 29 /* add local exceptions here */
30 /* TODO : add command flag interface */ 30 /* TODO : add command flag interface */
31 const struct SkipOverTest { 31 const struct SkipOverTest {
32 int directory; 32 int directory;
33 const char* filename; 33 const char* filename;
34 bool blamePathOps; 34 bool blamePathOps;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 static SkString get_in_path(int dirNo, const char* filename) { 83 static SkString get_in_path(int dirNo, const char* filename) {
84 SkString path; 84 SkString path;
85 SkASSERT(dirNo); 85 SkASSERT(dirNo);
86 path.appendf("%s%d%s", IN_DIR_PRE, dirNo, DIR_POST); 86 path.appendf("%s%d%s", IN_DIR_PRE, dirNo, DIR_POST);
87 if (!sk_exists(path.c_str())) { 87 if (!sk_exists(path.c_str())) {
88 SkDebugf("could not read %s\n", path.c_str()); 88 SkDebugf("could not read %s\n", path.c_str());
89 return SkString(); 89 return SkString();
90 } 90 }
91 if (filename) { 91 if (filename) {
92 path.appendf("%s%s", PATH_SLASH, filename); 92 path.appendf("%s%s", PATH_SLASH, filename);
93 if (!sk_exists(path.c_str())) { 93 if (!sk_exists(path.c_str())) {
94 SkDebugf("could not read %s\n", path.c_str()); 94 SkDebugf("could not read %s\n", path.c_str());
95 return SkString(); 95 return SkString();
96 } 96 }
97 } 97 }
98 return path; 98 return path;
99 } 99 }
100 100
101 static void make_recursive_dir(const SkString& path) { 101 static void make_recursive_dir(const SkString& path) {
102 if (sk_exists(path.c_str())) { 102 if (sk_exists(path.c_str())) {
103 return; 103 return;
104 } 104 }
105 const char* pathStr = path.c_str(); 105 const char* pathStr = path.c_str();
106 int last = (int) path.size(); 106 int last = (int) path.size();
107 do { 107 do {
108 while (last > 0 && pathStr[--last] != PATH_SLASH[0]) 108 while (last > 0 && pathStr[--last] != PATH_SLASH[0])
109 ; 109 ;
110 SkASSERT(last > 0); 110 SkASSERT(last > 0);
(...skipping 11 matching lines...) Expand all
122 } 122 }
123 123
124 static SkString get_out_path(int dirNo, const char* dirName) { 124 static SkString get_out_path(int dirNo, const char* dirName) {
125 SkString path; 125 SkString path;
126 SkASSERT(dirNo); 126 SkASSERT(dirNo);
127 SkASSERT(dirName); 127 SkASSERT(dirName);
128 path.appendf("%s%d%s%s%s", OUT_DIR_PRE, dirNo, DIR_POST, PATH_SLASH, dirName ); 128 path.appendf("%s%d%s%s%s", OUT_DIR_PRE, dirNo, DIR_POST, PATH_SLASH, dirName );
129 make_recursive_dir(path); 129 make_recursive_dir(path);
130 return path; 130 return path;
131 } 131 }
132 132
133 static SkString get_sum_path(const char* dirName) { 133 static SkString get_sum_path(const char* dirName) {
134 SkString path; 134 SkString path;
135 SkASSERT(dirName); 135 SkASSERT(dirName);
136 path.appendf("%s%d%s%s", OUT_DIR_SUM, SUMMARY_RUN, PATH_SLASH, dirName); 136 path.appendf("%s%d%s%s", OUT_DIR_SUM, SUMMARY_RUN, PATH_SLASH, dirName);
137 SkDebugf("%s\n", path.c_str()); 137 SkDebugf("%s\n", path.c_str());
138 make_recursive_dir(path); 138 make_recursive_dir(path);
139 return path; 139 return path;
140 } 140 }
141 141
142 static SkString make_png_name(const char* filename) { 142 static SkString make_png_name(const char* filename) {
(...skipping 16 matching lines...) Expand all
159 kSmallLimit = 1000, 159 kSmallLimit = 1000,
160 }; 160 };
161 161
162 struct TestResult { 162 struct TestResult {
163 void init(int dirNo) { 163 void init(int dirNo) {
164 fDirNo = dirNo; 164 fDirNo = dirNo;
165 sk_bzero(fFilename, sizeof(fFilename)); 165 sk_bzero(fFilename, sizeof(fFilename));
166 fTestStep = kCompareBits; 166 fTestStep = kCompareBits;
167 fScale = 1; 167 fScale = 1;
168 } 168 }
169 169
170 void init(int dirNo, const SkString& filename) { 170 void init(int dirNo, const SkString& filename) {
171 fDirNo = dirNo; 171 fDirNo = dirNo;
172 strcpy(fFilename, filename.c_str()); 172 strcpy(fFilename, filename.c_str());
173 fTestStep = kCompareBits; 173 fTestStep = kCompareBits;
174 fScale = 1; 174 fScale = 1;
175 } 175 }
176 176
177 SkString status() { 177 SkString status() {
178 SkString outStr; 178 SkString outStr;
179 outStr.printf("%s %d %d\n", fFilename, fPixelError, fTime); 179 outStr.printf("%s %d %d\n", fFilename, fPixelError, fTime);
180 return outStr; 180 return outStr;
181 } 181 }
182 182
183 SkString progress() { 183 SkString progress() {
184 SkString outStr; 184 SkString outStr;
(...skipping 12 matching lines...) Expand all
197 197
198 } 198 }
199 199
200 void test(int dirNo, const SkString& filename) { 200 void test(int dirNo, const SkString& filename) {
201 init(dirNo); 201 init(dirNo);
202 strcpy(fFilename, filename.c_str()); 202 strcpy(fFilename, filename.c_str());
203 testOne(); 203 testOne();
204 } 204 }
205 205
206 void testOne(); 206 void testOne();
207 207
208 char fFilename[kMaxLength]; 208 char fFilename[kMaxLength];
209 TestStep fTestStep; 209 TestStep fTestStep;
210 int fDirNo; 210 int fDirNo;
211 int fPixelError; 211 int fPixelError;
212 int fTime; 212 int fTime;
213 int fScale; 213 int fScale;
214 }; 214 };
215 215
216 class SortByPixel : public TestResult { 216 class SortByPixel : public TestResult {
217 public: 217 public:
(...skipping 20 matching lines...) Expand all
238 void init(int dirNo) { 238 void init(int dirNo) {
239 fResult.init(dirNo); 239 fResult.init(dirNo);
240 } 240 }
241 241
242 SkTDArray<SortByPixel> fPixelWorst; 242 SkTDArray<SortByPixel> fPixelWorst;
243 SkTDArray<SortByTime> fSlowest; 243 SkTDArray<SortByTime> fSlowest;
244 TestResult fResult; 244 TestResult fResult;
245 }; 245 };
246 246
247 struct TestRunner { 247 struct TestRunner {
248 TestRunner(int threadCount)
249 : fNumThreads(threadCount) {
250 }
251
252 ~TestRunner(); 248 ~TestRunner();
253 void render(); 249 void render();
254 int fNumThreads;
255 SkTDArray<class TestRunnable*> fRunnables; 250 SkTDArray<class TestRunnable*> fRunnables;
256 }; 251 };
257 252
258 class TestRunnable : public SkRunnable { 253 class TestRunnable : public SkRunnable {
259 public: 254 public:
260 virtual void run() SK_OVERRIDE { 255 virtual void run() SK_OVERRIDE {
261 SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024); 256 SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024);
262 (*fTestFun)(&fState); 257 (*fTestFun)(&fState);
263 } 258 }
264 259
(...skipping 28 matching lines...) Expand all
293 } 288 }
294 }; 289 };
295 290
296 TestRunner::~TestRunner() { 291 TestRunner::~TestRunner() {
297 for (int index = 0; index < fRunnables.count(); index++) { 292 for (int index = 0; index < fRunnables.count(); index++) {
298 SkDELETE(fRunnables[index]); 293 SkDELETE(fRunnables[index]);
299 } 294 }
300 } 295 }
301 296
302 void TestRunner::render() { 297 void TestRunner::render() {
303 SkThreadPool pool(fNumThreads); 298 SkTaskGroup tg;
304 for (int index = 0; index < fRunnables.count(); ++ index) { 299 for (int index = 0; index < fRunnables.count(); ++ index) {
305 pool.add(fRunnables[index]); 300 tg.add(fRunnables[index]);
306 } 301 }
307 } 302 }
308 303
309 //////////////////////////////////////////////// 304 ////////////////////////////////////////////////
310 305
311 306
312 static int similarBits(const SkBitmap& gr, const SkBitmap& sk) { 307 static int similarBits(const SkBitmap& gr, const SkBitmap& sk) {
313 const int kRowCount = 3; 308 const int kRowCount = 3;
314 const int kThreshold = 3; 309 const int kThreshold = 3;
315 int width = SkTMin(gr.width(), sk.width()); 310 int width = SkTMin(gr.width(), sk.width());
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 "~ causes a matching test to always be skipped\n" 520 "~ causes a matching test to always be skipped\n"
526 "^ requires the start of the test to match\n" 521 "^ requires the start of the test to match\n"
527 "$ requires the end of the test to match\n" 522 "$ requires the end of the test to match\n"
528 "^ and $ requires an exact match\n" 523 "^ and $ requires an exact match\n"
529 "If a test does not match any list entry,\n" 524 "If a test does not match any list entry,\n"
530 "it is skipped unless some list entry starts with ~"); 525 "it is skipped unless some list entry starts with ~");
531 DEFINE_string2(dir, d, NULL, "range of directories (e.g., 1-100)"); 526 DEFINE_string2(dir, d, NULL, "range of directories (e.g., 1-100)");
532 DEFINE_string2(skp, s, NULL, "skp to test"); 527 DEFINE_string2(skp, s, NULL, "skp to test");
533 DEFINE_bool2(single, z, false, "run tests on a single thread internally."); 528 DEFINE_bool2(single, z, false, "run tests on a single thread internally.");
534 DEFINE_int32(testIndex, 0, "override local test index (PathOpsSkpClipOneOff only )."); 529 DEFINE_int32(testIndex, 0, "override local test index (PathOpsSkpClipOneOff only ).");
535 DEFINE_int32(threads, SkThreadPool::kThreadPerCore,
536 "Run threadsafe tests on a threadpool with this many threads.");
537 DEFINE_bool2(verbose, v, false, "enable verbose output."); 530 DEFINE_bool2(verbose, v, false, "enable verbose output.");
538 531
539 static bool verbose() { 532 static bool verbose() {
540 return FLAGS_verbose; 533 return FLAGS_verbose;
541 } 534 }
542 535
543 static int getThreadCount() {
544 return FLAGS_single ? 1 : FLAGS_threads;
545 }
546
547 class Dirs { 536 class Dirs {
548 public: 537 public:
549 Dirs() { 538 Dirs() {
550 reset(); 539 reset();
551 sk_bzero(fRun, sizeof(fRun)); 540 sk_bzero(fRun, sizeof(fRun));
552 fSet = false; 541 fSet = false;
553 } 542 }
554 543
555 int first() const { 544 int first() const {
556 int index = 0; 545 int index = 0;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 Filenames() 599 Filenames()
611 : fIndex(-1) { 600 : fIndex(-1) {
612 } 601 }
613 602
614 const char* next() { 603 const char* next() {
615 while (fNames && ++fIndex < fNames->count()) { 604 while (fNames && ++fIndex < fNames->count()) {
616 return (*fNames)[fIndex]; 605 return (*fNames)[fIndex];
617 } 606 }
618 return NULL; 607 return NULL;
619 } 608 }
620 609
621 void set(const SkCommandLineFlags::StringArray& names) { 610 void set(const SkCommandLineFlags::StringArray& names) {
622 fNames = &names; 611 fNames = &names;
623 } 612 }
624 613
625 private: 614 private:
626 int fIndex; 615 int fIndex;
627 const SkCommandLineFlags::StringArray* fNames; 616 const SkCommandLineFlags::StringArray* fNames;
628 } gNames; 617 } gNames;
629 618
630 static bool buildTestDir(int dirNo, int firstDirNo, 619 static bool buildTestDir(int dirNo, int firstDirNo,
631 SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sorted) { 620 SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sorted) {
632 SkString dirName = get_out_path(dirNo, outStatusDir); 621 SkString dirName = get_out_path(dirNo, outStatusDir);
633 if (!dirName.size()) { 622 if (!dirName.size()) {
634 return false; 623 return false;
635 } 624 }
636 SkOSFile::Iter iter(dirName.c_str(), "skp"); 625 SkOSFile::Iter iter(dirName.c_str(), "skp");
637 SkString filename; 626 SkString filename;
638 while (iter.next(&filename)) { 627 while (iter.next(&filename)) {
639 TestResult test; 628 TestResult test;
640 test.init(dirNo); 629 test.init(dirNo);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 } 775 }
787 if (slowest.count() > 0) { 776 if (slowest.count() > 0) {
788 SkTQSort<SortByTime>(slowest.begin(), slowest.end() - 1); 777 SkTQSort<SortByTime>(slowest.begin(), slowest.end() - 1);
789 for (int index = 0; index < slowest.count(); ++index) { 778 for (int index = 0; index < slowest.count(); ++index) {
790 const TestResult& result = *slowest[index]; 779 const TestResult& result = *slowest[index];
791 SkDebugf("%d %s time=%d\n", result.fDirNo, result.fFilename, result.fTime); 780 SkDebugf("%d %s time=%d\n", result.fDirNo, result.fFilename, result.fTime);
792 } 781 }
793 } 782 }
794 } 783 }
795 } 784 }
796 int threadCount = getThreadCount(); 785 TestRunner testRunner;
797 TestRunner testRunner(threadCount);
798 for (int index = 0; index < state.fPixelWorst.count(); ++index) { 786 for (int index = 0; index < state.fPixelWorst.count(); ++index) {
799 const TestResult& result = state.fPixelWorst[index]; 787 const TestResult& result = state.fPixelWorst[index];
800 SkString filename(result.fFilename); 788 SkString filename(result.fFilename);
801 if (!filename.endsWith(".skp")) { 789 if (!filename.endsWith(".skp")) {
802 filename.append(".skp"); 790 filename.append(".skp");
803 } 791 }
804 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableEncode, 792 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableEncode,
805 (&testSkpClipEncode, result.fDirNo, filename.c_str(), &testRunne r)); 793 (&testSkpClipEncode, result.fDirNo, filename.c_str(), &testRunne r));
806 } 794 }
807 testRunner.render(); 795 testRunner.render();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 encodeFound(state); 847 encodeFound(state);
860 } 848 }
861 849
862 static void testSkpClipMain(TestState* data) { 850 static void testSkpClipMain(TestState* data) {
863 (void) doOneDir(data, true); 851 (void) doOneDir(data, true);
864 } 852 }
865 853
866 DEF_TEST(PathOpsSkpClipThreaded) { 854 DEF_TEST(PathOpsSkpClipThreaded) {
867 gDirs.setDefault(); 855 gDirs.setDefault();
868 initTest(); 856 initTest();
869 int threadCount = getThreadCount(); 857 TestRunner testRunner;
870 TestRunner testRunner(threadCount);
871 int dirNo; 858 int dirNo;
872 gDirs.reset(); 859 gDirs.reset();
873 while ((dirNo = gDirs.next()) > 0) { 860 while ((dirNo = gDirs.next()) > 0) {
874 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableDir, 861 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableDir,
875 (&testSkpClipMain, dirNo, &testRunner)); 862 (&testSkpClipMain, dirNo, &testRunner));
876 } 863 }
877 testRunner.render(); 864 testRunner.render();
878 TestState state; 865 TestState state;
879 state.init(0); 866 state.init(0);
880 gDirs.reset(); 867 gDirs.reset();
881 while ((dirNo = gDirs.next()) > 0) { 868 while ((dirNo = gDirs.next()) > 0) {
882 TestState& testState = testRunner.fRunnables[dirNo - 1]->fState; 869 TestState& testState = testRunner.fRunnables[dirNo - 1]->fState;
883 SkASSERT(testState.fResult.fDirNo == dirNo); 870 SkASSERT(testState.fResult.fDirNo == dirNo);
884 for (int inner = 0; inner < testState.fPixelWorst.count(); ++inner) { 871 for (int inner = 0; inner < testState.fPixelWorst.count(); ++inner) {
885 addError(&state, testState.fPixelWorst[inner]); 872 addError(&state, testState.fPixelWorst[inner]);
886 } 873 }
887 for (int inner = 0; inner < testState.fSlowest.count(); ++inner) { 874 for (int inner = 0; inner < testState.fSlowest.count(); ++inner) {
888 addError(&state, testState.fSlowest[inner]); 875 addError(&state, testState.fSlowest[inner]);
889 } 876 }
890 } 877 }
891 encodeFound(state); 878 encodeFound(state);
892 } 879 }
893 880
894 static bool buildTests(SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sor ted) { 881 static bool buildTests(SkTDArray<TestResult>* tests, SkTDArray<SortByName*>* sor ted) {
895 int firstDirNo = gDirs.first(); 882 int firstDirNo = gDirs.first();
896 int dirNo; 883 int dirNo;
897 while ((dirNo = gDirs.next()) > 0) { 884 while ((dirNo = gDirs.next()) > 0) {
898 if (!buildTestDir(dirNo, firstDirNo, tests, sorted)) { 885 if (!buildTestDir(dirNo, firstDirNo, tests, sorted)) {
899 return false; 886 return false;
900 } 887 }
901 } 888 }
902 return true; 889 return true;
903 } 890 }
904 891
905 DEF_TEST(PathOpsSkpClipUberThreaded) { 892 DEF_TEST(PathOpsSkpClipUberThreaded) {
906 gDirs.setDefault(); 893 gDirs.setDefault();
907 const int firstDirNo = gDirs.next(); 894 const int firstDirNo = gDirs.next();
908 const int lastDirNo = gDirs.last(); 895 const int lastDirNo = gDirs.last();
909 initTest(); 896 initTest();
910 int dirCount = lastDirNo - firstDirNo + 1; 897 int dirCount = lastDirNo - firstDirNo + 1;
911 SkAutoTDeleteArray<SkTDArray<TestResult> > tests(new SkTDArray<TestResult>[d irCount]); 898 SkAutoTDeleteArray<SkTDArray<TestResult> > tests(new SkTDArray<TestResult>[d irCount]);
912 SkAutoTDeleteArray<SkTDArray<SortByName*> > sorted(new SkTDArray<SortByName* >[dirCount]); 899 SkAutoTDeleteArray<SkTDArray<SortByName*> > sorted(new SkTDArray<SortByName* >[dirCount]);
913 if (!buildTests(tests.get(), sorted.get())) { 900 if (!buildTests(tests.get(), sorted.get())) {
914 return; 901 return;
915 } 902 }
916 int threadCount = getThreadCount(); 903 TestRunner testRunner;
917 TestRunner testRunner(threadCount);
918 int dirNo; 904 int dirNo;
919 gDirs.reset(); 905 gDirs.reset();
920 while ((dirNo = gDirs.next()) > 0) { 906 while ((dirNo = gDirs.next()) > 0) {
921 SkString dirName = get_in_path(dirNo, NULL); 907 SkString dirName = get_in_path(dirNo, NULL);
922 if (!dirName.size()) { 908 if (!dirName.size()) {
923 continue; 909 continue;
924 } 910 }
925 SkOSFile::Iter iter(dirName.c_str(), "skp"); 911 SkOSFile::Iter iter(dirName.c_str(), "skp");
926 SkString filename; 912 SkString filename;
927 while (iter.next(&filename)) { 913 while (iter.next(&filename)) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 } 1097 }
1112 SkGraphics::Term(); 1098 SkGraphics::Term();
1113 return 0; 1099 return 0;
1114 } 1100 }
1115 1101
1116 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 1102 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
1117 int main(int argc, char * const argv[]) { 1103 int main(int argc, char * const argv[]) {
1118 return tool_main(argc, (char**) argv); 1104 return tool_main(argc, (char**) argv);
1119 } 1105 }
1120 #endif 1106 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698