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

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

Issue 247223009: Reduce test.dart memory usage (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clear static pointer to closure when finished Created 6 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 | « tools/testing/dart/test_progress.dart ('k') | tools/testing/dart/test_suite.dart » ('j') | 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 executing tests. 6 * Classes and methods for executing tests.
7 * 7 *
8 * This module includes: 8 * This module includes:
9 * - Managing parallel execution of tests, including timeout checks. 9 * - Managing parallel execution of tests, including timeout checks.
10 * - Evaluating the output of each test as pass/fail/crash/timeout. 10 * - Evaluating the output of each test as pass/fail/crash/timeout.
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 * The output information is stored in a [CommandOutput] instance contained 704 * The output information is stored in a [CommandOutput] instance contained
705 * in TestCase.commandOutputs. The last CommandOutput instance is responsible 705 * in TestCase.commandOutputs. The last CommandOutput instance is responsible
706 * for evaluating if the test has passed, failed, crashed, or timed out, and the 706 * for evaluating if the test has passed, failed, crashed, or timed out, and the
707 * TestCase has information about what the expected result of the test should 707 * TestCase has information about what the expected result of the test should
708 * be. 708 * be.
709 * 709 *
710 * The TestCase has a callback function, [completedHandler], that is run when 710 * The TestCase has a callback function, [completedHandler], that is run when
711 * the test is completed. 711 * the test is completed.
712 */ 712 */
713 class TestCase extends UniqueObject { 713 class TestCase extends UniqueObject {
714 // Flags set in _expectations from the optional argument info.
715 static final int IS_NEGATIVE = 1 << 0;
716 static final int HAS_RUNTIME_ERROR = 1 << 1;
717 static final int HAS_STATIC_WARNING = 1 << 2;
718 static final int IS_NEGATIVE_IF_CHECKED = 1 << 3;
719 static final int HAS_COMPILE_ERROR = 1 << 4;
720 static final int HAS_COMPILE_ERROR_IF_CHECKED = 1 << 5;
721 static final int EXPECT_COMPILE_ERROR = 1 << 6;
714 /** 722 /**
715 * A list of commands to execute. Most test cases have a single command. 723 * A list of commands to execute. Most test cases have a single command.
716 * Dart2js tests have two commands, one to compile the source and another 724 * Dart2js tests have two commands, one to compile the source and another
717 * to execute it. Some isolate tests might even have three, if they require 725 * to execute it. Some isolate tests might even have three, if they require
718 * compiling multiple sources that are run in isolation. 726 * compiling multiple sources that are run in isolation.
719 */ 727 */
720 List<Command> commands; 728 List<Command> commands;
721 Map<Command, CommandOutput> commandOutputs = new Map<Command,CommandOutput>(); 729 Map<Command, CommandOutput> commandOutputs = new Map<Command,CommandOutput>();
722 730
723 Map configuration; 731 Map configuration;
724 String displayName; 732 String displayName;
725 bool isNegative; 733 int _expectations = 0;
734 int hash = 0;
726 Set<Expectation> expectedOutcomes; 735 Set<Expectation> expectedOutcomes;
727 TestInformation info;
728 736
729 TestCase(this.displayName, 737 TestCase(this.displayName,
730 this.commands, 738 this.commands,
731 this.configuration, 739 this.configuration,
732 this.expectedOutcomes, 740 this.expectedOutcomes,
733 {this.isNegative: false, 741 {isNegative: false,
734 this.info: null}) { 742 TestInformation info: null}) {
735 if (!isNegative) { 743 if (isNegative || displayName.contains("negative_test")) {
736 this.isNegative = displayName.contains("negative_test"); 744 _expectations |= IS_NEGATIVE;
745 }
746 if (info != null) {
747 _setExpectations(info);
748 hash = info.originTestPath.relativeTo(TestUtils.dartDir)
749 .toString().hashCode;
737 } 750 }
738 } 751 }
739 752
740 /// Returns `true` if this test case should result in a compile-time error, 753 void _setExpectations(TestInformation info) {
741 /// either unconditionally or if the configuration is 'checked'. 754 // We don't want to keep the entire (large) TestInformation structure,
742 bool get expectCompileError { 755 // so we copy the needed bools into flags set in a single integer.
743 if (info == null) return false; 756 if (info.hasRuntimeError) _expectations |= HAS_RUNTIME_ERROR;
744 return info.hasCompileError || 757 if (info.hasStaticWarning) _expectations |= HAS_STATIC_WARNING;
745 (configuration['checked'] && info.hasCompileErrorIfChecked); 758 if (info.isNegativeIfChecked) _expectations |= IS_NEGATIVE_IF_CHECKED;
759 if (info.hasCompileError) _expectations |= HAS_COMPILE_ERROR;
760 if (info.hasCompileErrorIfChecked) {
761 _expectations |= HAS_COMPILE_ERROR_IF_CHECKED;
762 }
763 if (info.hasCompileError ||
764 (configuration['checked'] && info.hasCompileErrorIfChecked)) {
765 _expectations |= EXPECT_COMPILE_ERROR;
766 }
746 } 767 }
747 768
769 bool get isNegative => _expectations & IS_NEGATIVE != 0;
770 bool get hasRuntimeError => _expectations & HAS_RUNTIME_ERROR != 0;
771 bool get hasStaticWarning => _expectations & HAS_STATIC_WARNING != 0;
772 bool get isNegativeIfChecked => _expectations & IS_NEGATIVE_IF_CHECKED != 0;
773 bool get hasCompileError => _expectations & HAS_COMPILE_ERROR != 0;
774 bool get hasCompileErrorIfChecked =>
775 _expectations & HAS_COMPILE_ERROR_IF_CHECKED != 0;
776 bool get expectCompileError => _expectations & EXPECT_COMPILE_ERROR != 0;
777
748 bool get unexpectedOutput { 778 bool get unexpectedOutput {
749 var outcome = lastCommandOutput.result(this); 779 var outcome = lastCommandOutput.result(this);
750 return !expectedOutcomes.any((expectation) { 780 return !expectedOutcomes.any((expectation) {
751 return outcome.canBeOutcomeOf(expectation); 781 return outcome.canBeOutcomeOf(expectation);
752 }); 782 });
753 } 783 }
754 784
755 Expectation get result => lastCommandOutput.result(this); 785 Expectation get result => lastCommandOutput.result(this);
756 786
757 CommandOutput get lastCommandOutput { 787 CommandOutput get lastCommandOutput {
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 } 1043 }
1014 } 1044 }
1015 1045
1016 Expectation result(TestCase testCase) { 1046 Expectation result(TestCase testCase) {
1017 // Handle crashes and timeouts first 1047 // Handle crashes and timeouts first
1018 if (hasCrashed) return Expectation.CRASH; 1048 if (hasCrashed) return Expectation.CRASH;
1019 if (hasTimedOut) return Expectation.TIMEOUT; 1049 if (hasTimedOut) return Expectation.TIMEOUT;
1020 1050
1021 var outcome = _getOutcome(); 1051 var outcome = _getOutcome();
1022 1052
1023 if (testCase.info != null && testCase.info.hasRuntimeError) { 1053 if (testCase.hasRuntimeError) {
1024 if (!outcome.canBeOutcomeOf(Expectation.RUNTIME_ERROR)) { 1054 if (!outcome.canBeOutcomeOf(Expectation.RUNTIME_ERROR)) {
1025 return Expectation.MISSING_RUNTIME_ERROR; 1055 return Expectation.MISSING_RUNTIME_ERROR;
1026 } 1056 }
1027 } 1057 }
1028 if (testCase.isNegative) { 1058 if (testCase.isNegative) {
1029 if (outcome.canBeOutcomeOf(Expectation.FAIL)) return Expectation.PASS; 1059 if (outcome.canBeOutcomeOf(Expectation.FAIL)) return Expectation.PASS;
1030 return Expectation.FAIL; 1060 return Expectation.FAIL;
1031 } 1061 }
1032 return outcome; 1062 return outcome;
1033 } 1063 }
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 : super(command, 0, result.didTimeout, stdout, stderr, result.duration, 1386 : super(command, 0, result.didTimeout, stdout, stderr, result.duration,
1357 false, 0) { 1387 false, 0) {
1358 _result = result; 1388 _result = result;
1359 } 1389 }
1360 1390
1361 Expectation result(TestCase testCase) { 1391 Expectation result(TestCase testCase) {
1362 // Handle timeouts first 1392 // Handle timeouts first
1363 if (_result.didTimeout) return Expectation.TIMEOUT; 1393 if (_result.didTimeout) return Expectation.TIMEOUT;
1364 1394
1365 // Multitests are handled specially 1395 // Multitests are handled specially
1366 if (testCase.info != null) { 1396 if (testCase.hasRuntimeError) {
1367 if (testCase.info.hasRuntimeError) { 1397 if (_rawOutcome == Expectation.RUNTIME_ERROR) return Expectation.PASS;
1368 if (_rawOutcome == Expectation.RUNTIME_ERROR) return Expectation.PASS; 1398 return Expectation.MISSING_RUNTIME_ERROR;
1369 return Expectation.MISSING_RUNTIME_ERROR;
1370 }
1371 } 1399 }
1372 1400
1373 return _negateOutcomeIfNegativeTest(_rawOutcome, testCase.isNegative); 1401 return _negateOutcomeIfNegativeTest(_rawOutcome, testCase.isNegative);
1374 } 1402 }
1375 } 1403 }
1376 1404
1377 1405
1378 class AnalysisCommandOutputImpl extends CommandOutputImpl { 1406 class AnalysisCommandOutputImpl extends CommandOutputImpl {
1379 // An error line has 8 fields that look like: 1407 // An error line has 8 fields that look like:
1380 // ERROR|COMPILER|MISSING_SOURCE|file:/tmp/t.dart|15|1|24|Missing source. 1408 // ERROR|COMPILER|MISSING_SOURCE|file:/tmp/t.dart|15|1|24|Missing source.
(...skipping 26 matching lines...) Expand all
1407 // Handle crashes and timeouts first 1435 // Handle crashes and timeouts first
1408 if (hasCrashed) return Expectation.CRASH; 1436 if (hasCrashed) return Expectation.CRASH;
1409 if (hasTimedOut) return Expectation.TIMEOUT; 1437 if (hasTimedOut) return Expectation.TIMEOUT;
1410 1438
1411 // Get the errors/warnings from the analyzer 1439 // Get the errors/warnings from the analyzer
1412 List<String> errors = []; 1440 List<String> errors = [];
1413 List<String> warnings = []; 1441 List<String> warnings = [];
1414 parseAnalyzerOutput(errors, warnings); 1442 parseAnalyzerOutput(errors, warnings);
1415 1443
1416 // Handle errors / missing errors 1444 // Handle errors / missing errors
1417 if (testCase.info.hasCompileError) { 1445 if (testCase.hasCompileError) {
1418 // Don't use [TestCase.expectCompileError] since the analyzer does not 1446 // Don't use [TestCase.expectCompileError] since the analyzer does not
1419 // (currently) report checked-mode only compile time errors. 1447 // (currently) report checked-mode only compile time errors.
1420 if (errors.length > 0) { 1448 if (errors.length > 0) {
1421 return Expectation.PASS; 1449 return Expectation.PASS;
1422 } 1450 }
1423 return Expectation.MISSING_COMPILETIME_ERROR; 1451 return Expectation.MISSING_COMPILETIME_ERROR;
1424 } 1452 }
1425 if (errors.length > 0) { 1453 if (errors.length > 0) {
1426 return Expectation.COMPILETIME_ERROR; 1454 return Expectation.COMPILETIME_ERROR;
1427 } 1455 }
1428 1456
1429 // Handle static warnings / missing static warnings 1457 // Handle static warnings / missing static warnings
1430 if (testCase.info.hasStaticWarning) { 1458 if (testCase.hasStaticWarning) {
1431 if (warnings.length > 0) { 1459 if (warnings.length > 0) {
1432 return Expectation.PASS; 1460 return Expectation.PASS;
1433 } 1461 }
1434 return Expectation.MISSING_STATIC_WARNING; 1462 return Expectation.MISSING_STATIC_WARNING;
1435 } 1463 }
1436 if (warnings.length > 0) { 1464 if (warnings.length > 0) {
1437 return Expectation.STATIC_WARNING; 1465 return Expectation.STATIC_WARNING;
1438 } 1466 }
1439 1467
1440 assert (errors.length == 0 && warnings.length == 0); 1468 assert (errors.length == 0 && warnings.length == 0);
1441 assert (!testCase.info.hasCompileError && 1469 assert (!testCase.hasCompileError &&
1442 !testCase.info.hasStaticWarning); 1470 !testCase.hasStaticWarning);
1443 return Expectation.PASS; 1471 return Expectation.PASS;
1444 } 1472 }
1445 1473
1446 void parseAnalyzerOutput(List<String> outErrors, List<String> outWarnings) { 1474 void parseAnalyzerOutput(List<String> outErrors, List<String> outWarnings) {
1447 AnalysisCommand analysisCommand = command; 1475 AnalysisCommand analysisCommand = command;
1448 1476
1449 // Parse a line delimited by the | character using \ as an escape charager 1477 // Parse a line delimited by the | character using \ as an escape charager
1450 // like: FOO|BAR|FOO\|BAR|FOO\\BAZ as 4 fields: FOO BAR FOO|BAR FOO\BAZ 1478 // like: FOO|BAR|FOO\|BAR|FOO\\BAZ as 4 fields: FOO BAR FOO|BAR FOO\BAZ
1451 List<String> splitMachineError(String line) { 1479 List<String> splitMachineError(String line) {
1452 StringBuffer field = new StringBuffer(); 1480 StringBuffer field = new StringBuffer();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 List<int> stdout, List<int> stderr, Duration time, 1523 List<int> stdout, List<int> stderr, Duration time,
1496 int pid) 1524 int pid)
1497 : super(command, exitCode, timedOut, stdout, stderr, time, false, pid); 1525 : super(command, exitCode, timedOut, stdout, stderr, time, false, pid);
1498 1526
1499 Expectation result(TestCase testCase) { 1527 Expectation result(TestCase testCase) {
1500 // Handle crashes and timeouts first 1528 // Handle crashes and timeouts first
1501 if (hasCrashed) return Expectation.CRASH; 1529 if (hasCrashed) return Expectation.CRASH;
1502 if (hasTimedOut) return Expectation.TIMEOUT; 1530 if (hasTimedOut) return Expectation.TIMEOUT;
1503 1531
1504 // Multitests are handled specially 1532 // Multitests are handled specially
1505 if (testCase.info != null) { 1533 if (testCase.expectCompileError) {
1506 if (testCase.expectCompileError) { 1534 if (exitCode == DART_VM_EXITCODE_COMPILE_TIME_ERROR) {
1507 if (exitCode == DART_VM_EXITCODE_COMPILE_TIME_ERROR) { 1535 return Expectation.PASS;
1508 return Expectation.PASS;
1509 }
1510
1511 return Expectation.MISSING_COMPILETIME_ERROR;
1512 } 1536 }
1513 if (testCase.info.hasRuntimeError) { 1537 return Expectation.MISSING_COMPILETIME_ERROR;
1514 // TODO(kustermann): Do we consider a "runtimeError" only an uncaught 1538 }
1515 // exception or does any nonzero exit code fullfil this requirement? 1539 if (testCase.hasRuntimeError) {
1516 if (exitCode != 0) { 1540 // TODO(kustermann): Do we consider a "runtimeError" only an uncaught
1517 return Expectation.PASS; 1541 // exception or does any nonzero exit code fullfil this requirement?
1518 } 1542 if (exitCode != 0) {
1519 return Expectation.MISSING_RUNTIME_ERROR; 1543 return Expectation.PASS;
1520 } 1544 }
1545 return Expectation.MISSING_RUNTIME_ERROR;
1521 } 1546 }
1522 1547
1523 // The actual outcome depends on the exitCode 1548 // The actual outcome depends on the exitCode
1524 Expectation outcome; 1549 Expectation outcome;
1525 if (exitCode == DART_VM_EXITCODE_COMPILE_TIME_ERROR) { 1550 if (exitCode == DART_VM_EXITCODE_COMPILE_TIME_ERROR) {
1526 outcome = Expectation.COMPILETIME_ERROR; 1551 outcome = Expectation.COMPILETIME_ERROR;
1527 } else if (exitCode == DART_VM_EXITCODE_UNCAUGHT_EXCEPTION) { 1552 } else if (exitCode == DART_VM_EXITCODE_UNCAUGHT_EXCEPTION) {
1528 outcome = Expectation.RUNTIME_ERROR; 1553 outcome = Expectation.RUNTIME_ERROR;
1529 } else if (exitCode != 0) { 1554 } else if (exitCode != 0) {
1530 // This is a general fail, in case we get an unknown nonzero exitcode. 1555 // This is a general fail, in case we get an unknown nonzero exitcode.
(...skipping 21 matching lines...) Expand all
1552 if (hasTimedOut) return Expectation.TIMEOUT; 1577 if (hasTimedOut) return Expectation.TIMEOUT;
1553 1578
1554 // Handle dart2js/dart2dart specific crash detection 1579 // Handle dart2js/dart2dart specific crash detection
1555 if (exitCode == DART2JS_EXITCODE_CRASH || 1580 if (exitCode == DART2JS_EXITCODE_CRASH ||
1556 exitCode == VmCommandOutputImpl.DART_VM_EXITCODE_COMPILE_TIME_ERROR || 1581 exitCode == VmCommandOutputImpl.DART_VM_EXITCODE_COMPILE_TIME_ERROR ||
1557 exitCode == VmCommandOutputImpl.DART_VM_EXITCODE_UNCAUGHT_EXCEPTION) { 1582 exitCode == VmCommandOutputImpl.DART_VM_EXITCODE_UNCAUGHT_EXCEPTION) {
1558 return Expectation.CRASH; 1583 return Expectation.CRASH;
1559 } 1584 }
1560 1585
1561 // Multitests are handled specially 1586 // Multitests are handled specially
1562 if (testCase.info != null) {
1563 if (testCase.expectCompileError) { 1587 if (testCase.expectCompileError) {
1564 // Nonzero exit code of the compiler means compilation failed 1588 // Nonzero exit code of the compiler means compilation failed
1565 // TODO(kustermann): Do we have a special exit code in that case??? 1589 // TODO(kustermann): Do we have a special exit code in that case???
1566 if (exitCode != 0) { 1590 if (exitCode != 0) {
1567 return Expectation.PASS; 1591 return Expectation.PASS;
1568 }
1569 return Expectation.MISSING_COMPILETIME_ERROR;
1570 } 1592 }
1593 return Expectation.MISSING_COMPILETIME_ERROR;
1594 }
1571 1595
1572 // TODO(kustermann): This is a hack, remove it 1596 // TODO(kustermann): This is a hack, remove it
1573 if (testCase.info.hasRuntimeError && testCase.commands.length > 1) { 1597 if (testCase.hasRuntimeError && testCase.commands.length > 1) {
1574 // We expected to run the test, but we got an compile time error. 1598 // We expected to run the test, but we got an compile time error.
1575 // If the compilation succeeded, we wouldn't be in here! 1599 // If the compilation succeeded, we wouldn't be in here!
1576 assert(exitCode != 0); 1600 assert(exitCode != 0);
1577 return Expectation.COMPILETIME_ERROR; 1601 return Expectation.COMPILETIME_ERROR;
1578 }
1579 } 1602 }
1580 1603
1581 Expectation outcome = 1604 Expectation outcome =
1582 exitCode == 0 ? Expectation.PASS : Expectation.COMPILETIME_ERROR; 1605 exitCode == 0 ? Expectation.PASS : Expectation.COMPILETIME_ERROR;
1583 return _negateOutcomeIfNegativeTest(outcome, testCase.isNegative); 1606 return _negateOutcomeIfNegativeTest(outcome, testCase.isNegative);
1584 } 1607 }
1585 } 1608 }
1586 1609
1587 class JsCommandlineOutputImpl extends CommandOutputImpl 1610 class JsCommandlineOutputImpl extends CommandOutputImpl
1588 with UnittestSuiteMessagesMixin { 1611 with UnittestSuiteMessagesMixin {
1589 JsCommandlineOutputImpl(Command command, int exitCode, bool timedOut, 1612 JsCommandlineOutputImpl(Command command, int exitCode, bool timedOut,
1590 List<int> stdout, List<int> stderr, Duration time) 1613 List<int> stdout, List<int> stderr, Duration time)
1591 : super(command, exitCode, timedOut, stdout, stderr, time, false, 0); 1614 : super(command, exitCode, timedOut, stdout, stderr, time, false, 0);
1592 1615
1593 Expectation result(TestCase testCase) { 1616 Expectation result(TestCase testCase) {
1594 // Handle crashes and timeouts first 1617 // Handle crashes and timeouts first
1595 if (hasCrashed) return Expectation.CRASH; 1618 if (hasCrashed) return Expectation.CRASH;
1596 if (hasTimedOut) return Expectation.TIMEOUT; 1619 if (hasTimedOut) return Expectation.TIMEOUT;
1597 1620
1598 if (testCase.info != null && testCase.info.hasRuntimeError) { 1621 if (testCase.hasRuntimeError) {
1599 if (exitCode != 0) return Expectation.PASS; 1622 if (exitCode != 0) return Expectation.PASS;
1600 return Expectation.MISSING_RUNTIME_ERROR; 1623 return Expectation.MISSING_RUNTIME_ERROR;
1601 } 1624 }
1602 1625
1603 var outcome = exitCode == 0 ? Expectation.PASS : Expectation.RUNTIME_ERROR; 1626 var outcome = exitCode == 0 ? Expectation.PASS : Expectation.RUNTIME_ERROR;
1604 outcome = _negateOutcomeIfIncompleteAsyncTest(outcome, decodeUtf8(stdout)); 1627 outcome = _negateOutcomeIfIncompleteAsyncTest(outcome, decodeUtf8(stdout));
1605 return _negateOutcomeIfNegativeTest(outcome, testCase.isNegative); 1628 return _negateOutcomeIfNegativeTest(outcome, testCase.isNegative);
1606 } 1629 }
1607 } 1630 }
1608 1631
(...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after
2947 } 2970 }
2948 } 2971 }
2949 2972
2950 void eventAllTestsDone() { 2973 void eventAllTestsDone() {
2951 for (var listener in _eventListener) { 2974 for (var listener in _eventListener) {
2952 listener.allDone(); 2975 listener.allDone();
2953 } 2976 }
2954 _allDone(); 2977 _allDone();
2955 } 2978 }
2956 } 2979 }
OLDNEW
« no previous file with comments | « tools/testing/dart/test_progress.dart ('k') | tools/testing/dart/test_suite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698