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

Side by Side Diff: tools/testing/dart/test_suite.dart

Issue 9927001: Use string hash for sharding tests instead of using an index in a sorted list. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | « no previous file | 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 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Classes and methods for enumerating and preparing tests. 6 * Classes and methods for enumerating and preparing tests.
7 * 7 *
8 * This library includes: 8 * This library includes:
9 * 9 *
10 * - Creating tests by listing all the Dart files in certain directories, 10 * - Creating tests by listing all the Dart files in certain directories,
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 globalTemporaryDirectory = globalTempDir; 238 globalTemporaryDirectory = globalTempDir;
239 239
240 var filesRead = 0; 240 var filesRead = 0;
241 void statusFileRead() { 241 void statusFileRead() {
242 filesRead++; 242 filesRead++;
243 if (filesRead == statusFilePaths.length) { 243 if (filesRead == statusFilePaths.length) {
244 // Checked if we have already found and generated the tests for 244 // Checked if we have already found and generated the tests for
245 // this suite. 245 // this suite.
246 if (!testCache.containsKey(suiteName)) { 246 if (!testCache.containsKey(suiteName)) {
247 cachedTests = testCache[suiteName] = []; 247 cachedTests = testCache[suiteName] = [];
248 if (configuration['shards'] > 1) {
249 // If we are sharding tests, we do not enqueue them as they are
250 // found in the directory listing. We add all the tests to the
251 // testCache, then delete all but this shard's tests from the
252 // cache. The doDone function then enqueues the tests from the
253 // cache, and other configurations also use the shard from the
254 // cache.
255 Function oldDone = doDone;
256 doDone = () {
257 testCache[suiteName] = shardTests();
258 for (var info in testCache[suiteName]) {
259 enqueueTestCaseFromTestInformation(info);
260 }
261 oldDone();
262 };
263 }
264 processDirectory(); 248 processDirectory();
265 } else { 249 } else {
266 // We rely on enqueueing completing asynchronously so use a 250 // We rely on enqueueing completing asynchronously so use a
267 // timer to make it so. 251 // timer to make it so.
268 void enqueueCachedTests(Timer ignore) { 252 void enqueueCachedTests(Timer ignore) {
269 for (var info in testCache[suiteName]) { 253 for (var info in testCache[suiteName]) {
270 enqueueTestCaseFromTestInformation(info); 254 enqueueTestCaseFromTestInformation(info);
271 } 255 }
272 doDone(); 256 doDone();
273 } 257 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 } 373 }
390 } 374 }
391 375
392 Function makeTestCaseCreator(Map optionsFromFile) { 376 Function makeTestCaseCreator(Map optionsFromFile) {
393 return (String filename, 377 return (String filename,
394 bool isNegative, 378 bool isNegative,
395 [bool isNegativeIfChecked = false, 379 [bool isNegativeIfChecked = false,
396 bool hasFatalTypeErrors = false, 380 bool hasFatalTypeErrors = false,
397 bool hasRuntimeErrors = false, 381 bool hasRuntimeErrors = false,
398 Set<String> multitestOutcome = null]) { 382 Set<String> multitestOutcome = null]) {
383 int shards = configuration['shards'];
384 if (shards > 1) {
385 int shard = configuration['shard'];
386 if (filename.hashCode() % shards != shard -1) {
387 return;
388 }
389 }
390
399 // Cache the test information for each test case. 391 // Cache the test information for each test case.
400 var info = new TestInformation(filename, 392 var info = new TestInformation(filename,
401 optionsFromFile, 393 optionsFromFile,
402 isNegative, 394 isNegative,
403 isNegativeIfChecked, 395 isNegativeIfChecked,
404 hasFatalTypeErrors, 396 hasFatalTypeErrors,
405 hasRuntimeErrors, 397 hasRuntimeErrors,
406 multitestOutcome); 398 multitestOutcome);
407 cachedTests.add(info); 399 cachedTests.add(info);
408 if (configuration['shards'] == 1) { 400 enqueueTestCaseFromTestInformation(info);
409 // If we are not sharding, we queue the tests as we find them.
410 enqueueTestCaseFromTestInformation(info);
411 }
412 }; 401 };
413 } 402 }
414 403
415 void processFile(String filename) { 404 void processFile(String filename) {
416 if (!isTestFile(filename)) return; 405 if (!isTestFile(filename)) return;
417 406
418 // Only run the tests that match the pattern. 407 // Only run the tests that match the pattern.
419 RegExp pattern = configuration['selectors'][suiteName]; 408 RegExp pattern = configuration['selectors'][suiteName];
420 if (!pattern.hasMatch(filename)) return; 409 if (!pattern.hasMatch(filename)) return;
421 if (filename.endsWith('test_config.dart')) return; 410 if (filename.endsWith('test_config.dart')) return;
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 "otherScripts": otherScripts, 873 "otherScripts": otherScripts,
885 "isMultitest": isMultitest, 874 "isMultitest": isMultitest,
886 "containsLeadingHash": containsLeadingHash, 875 "containsLeadingHash": containsLeadingHash,
887 "isolateStubs": isolateStubs, 876 "isolateStubs": isolateStubs,
888 "containsDomImport": containsDomImport, 877 "containsDomImport": containsDomImport,
889 "isLibraryDefinition": isLibraryDefinition, 878 "isLibraryDefinition": isLibraryDefinition,
890 "containsSourceOrImport": containsSourceOrImport, 879 "containsSourceOrImport": containsSourceOrImport,
891 "numStaticTypeAnnotations": numStaticTypeAnnotations, 880 "numStaticTypeAnnotations": numStaticTypeAnnotations,
892 "numCompileTimeAnnotations": numCompileTimeAnnotations}; 881 "numCompileTimeAnnotations": numCompileTimeAnnotations};
893 } 882 }
894
895 /**
896 * shardTests takes the list of tests, stored as the List<TestInformation>
897 * cachedTests, and selects only the tests belonging to this shard.
898 * The tests are sorted by filename, and if there are n shards and we are
899 * shard number i, only the tests at indices equal to i-1 modulo n are kept.
900 */
901 List<TestInformation> shardTests() {
902 cachedTests.sort((TestInformation a, TestInformation b) => a.filename.compar eTo(b.filename));
903 int n = configuration['shards'];
904 int i = configuration['shard'];
905 if (n >= 2) {
906 int current = 0;
907 // The test function given to cachedTests.filter uses the entry's index.
908 cachedTests = cachedTests.filter((t) => ((++current % n) == i - 1));
909 }
910 return cachedTests;
911 }
912 } 883 }
913 884
914 885
915 class DartcCompilationTestSuite extends StandardTestSuite { 886 class DartcCompilationTestSuite extends StandardTestSuite {
916 List<String> _testDirs; 887 List<String> _testDirs;
917 int activityCount = 0; 888 int activityCount = 0;
918 889
919 DartcCompilationTestSuite(Map configuration, 890 DartcCompilationTestSuite(Map configuration,
920 String suiteName, 891 String suiteName,
921 String directoryPath, 892 String directoryPath,
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 * $noCrash tests are expected to be flaky but not crash 1239 * $noCrash tests are expected to be flaky but not crash
1269 * $pass tests are expected to pass 1240 * $pass tests are expected to pass
1270 * $failOk tests are expected to fail that we won't fix 1241 * $failOk tests are expected to fail that we won't fix
1271 * $fail tests are expected to fail that we should fix 1242 * $fail tests are expected to fail that we should fix
1272 * $crash tests are expected to crash that we should fix 1243 * $crash tests are expected to crash that we should fix
1273 * $timeout tests are allowed to timeout 1244 * $timeout tests are allowed to timeout
1274 """; 1245 """;
1275 print(report); 1246 print(report);
1276 } 1247 }
1277 } 1248 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698