diff --git a/tests/corelib/test_config.dart b/tests/corelib/test_config.dart new file mode 100644 index 00000000000..5d303b1a74f --- /dev/null +++ b/tests/corelib/test_config.dart @@ -0,0 +1,59 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +#library("corelib_test_config"); + +#import("../../tools/testing/dart/test_runner.dart"); + +class CorelibTestSuite { + final String directoryPath = "tests/corelib/src"; + Function doTest; + Function doDone; + String shellPath; + String pathSeparator; + + CorelibTestSuite() { + shellPath = getDartShellFileName() ; + pathSeparator = new Platform().pathSeparator(); + } + + void forEachTest(Function onTest, [Function onDone = null]) { + doTest = onTest; + doDone = onDone; + processDirectory(); + } + + void processDirectory() { + Directory dir = new Directory(directoryPath); + if (!dir.existsSync()) { + dir = new Directory(".." + pathSeparator + directoryPath); + Expect.isTrue(dir.existsSync(), + "Cannot find tests/corelib/src or ../tests/corelib/src"); + // TODO(ager): Use dir.errorHandler instead when it is implemented. + } + dir.fileHandler = processFile; + dir.doneHandler = doDone; + dir.list(false); + } + + void processFile(String filename) { + if (filename.endsWith("Test.dart")) { + int start = filename.lastIndexOf(pathSeparator); + String displayName = filename.substring(start + 1, filename.length - 5); + // TODO(whesse): Gather test case info from status file and test file. + doTest(new TestCase(displayName, + shellPath, + ["--enable_type_checks", + "--ignore-unrecognized-flags", + filename ], + completeHandler, + new Set.from([PASS, FAIL, CRASH, TIMEOUT]))); + } + } + + void completeHandler(TestCase testCase) { + TestOutput output = testCase.output; + print("Exit code: ${output.exitCode} Time: ${output.time}"); + } +} diff --git a/tests/standalone/src/TestRunnerTest.dart b/tests/standalone/src/TestRunnerTest.dart index 5892bda005d..264e7344c31 100644 --- a/tests/standalone/src/TestRunnerTest.dart +++ b/tests/standalone/src/TestRunnerTest.dart @@ -44,7 +44,8 @@ TestCase MakeTestCase(String testName, List expectations) { test_path = "../tests/standalone/src/${testName}.dart"; } - return new TestCase(getDartShellFileName(), + return new TestCase(testName, + getDartShellFileName(), ["--ignore-unrecognized-flags", "--enable_type_checks", test_path], @@ -73,7 +74,8 @@ void main() { new RunningProcess(MakeTestCase("FailTest", [FAIL]), timeout).start(); new RunningProcess(MakeTestCase("TimeoutTest", [TIMEOUT]), timeout).start(); - new RunningProcess(new TestCase(getProcessTestFileName(), + new RunningProcess(new TestCase("CrashTest", + getProcessTestFileName(), const ["0", "0", "1", "1"], TestController.processCompletedTest, new Set.from([CRASH])), diff --git a/tests/standalone/test_config.dart b/tests/standalone/test_config.dart new file mode 100644 index 00000000000..170de26c172 --- /dev/null +++ b/tests/standalone/test_config.dart @@ -0,0 +1,59 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +#library("standalone_test_config"); + +#import("../../tools/testing/dart/test_runner.dart"); + +class StandaloneTestSuite { + final String directoryPath = "tests/standalone/src"; + Function doTest; + Function doDone; + String shellPath; + String pathSeparator; + + StandaloneTestSuite() { + shellPath = getDartShellFileName() ; + pathSeparator = new Platform().pathSeparator(); + } + + void forEachTest(Function onTest, [Function onDone = null]) { + doTest = onTest; + doDone = onDone; + processDirectory(); + } + + void processDirectory() { + Directory dir = new Directory(directoryPath); + if (!dir.existsSync()) { + dir = new Directory(".." + pathSeparator + directoryPath); + Expect.isTrue(dir.existsSync(), + "Cannot find tests/corelib/src or ../tests/corelib/src"); + // TODO(ager): Use dir.errorHandler instead when it is implemented. + } + dir.fileHandler = processFile; + dir.doneHandler = doDone; + dir.list(false); + } + + void processFile(String filename) { + if (filename.endsWith("Test.dart")) { + int start = filename.lastIndexOf(pathSeparator); + String displayName = filename.substring(start + 1, filename.length - 5); + // TODO(whesse): Gather test case info from status file and test file. + doTest(new TestCase(displayName, + shellPath, + ["--enable_type_checks", + "--ignore-unrecognized-flags", + filename ], + completeHandler, + new Set.from([PASS, FAIL, CRASH, TIMEOUT]))); + } + } + + void completeHandler(TestCase testCase) { + TestOutput output = testCase.output; + print("Exit code: ${output.exitCode} Time: ${output.time}"); + } +} diff --git a/tools/test.dart b/tools/test.dart new file mode 100755 index 00000000000..a9baeff79e6 --- /dev/null +++ b/tools/test.dart @@ -0,0 +1,17 @@ +#!/usr/bin/env dart_bin +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +#library("test"); + +#import("testing/dart/test_runner.dart"); +#import("../tests/standalone/test_config.dart"); +#import("../tests/corelib/test_config.dart"); + +main() { + int numProcessors = new Platform().numberOfProcessors(); + var queue = new ProcessQueue(numProcessors); + new StandaloneTestSuite().forEachTest(queue.runTest); + new CorelibTestSuite().forEachTest(queue.runTest); +} diff --git a/tools/testing/dart/test_runner.dart b/tools/testing/dart/test_runner.dart index 8a720d6faf3..0e22e119e32 100644 --- a/tools/testing/dart/test_runner.dart +++ b/tools/testing/dart/test_runner.dart @@ -23,6 +23,8 @@ final PASS = "Pass"; // An indication to skip the test. The caller is responsible for skipping it. final SKIP = "Skip"; +final int NO_TIMEOUT = 0; + String getDartShellFileName() { var names = ["out/Debug_ia32/dart_bin", "out/Release_ia32/dart_bin", @@ -43,11 +45,12 @@ class TestCase { String executablePath; List arguments; String commandLine; + String displayName; TestOutput output; Set expectedOutcomes; Function completedHandler; - TestCase(this.executablePath, this.arguments, + TestCase(this.displayName, this.executablePath, this.arguments, this.completedHandler, this.expectedOutcomes) { commandLine = executablePath; for (var arg in arguments) { @@ -103,7 +106,6 @@ class RunningProcess { List stderr; List handlers; - static final int NO_TIMEOUT = 0; RunningProcess(this.testCase, [this.timeout = NO_TIMEOUT]); @@ -154,3 +156,36 @@ class RunningProcess { } } + +class ProcessQueue { + int numProcesses = 0; + final int maxProcesses; + Queue tests; + + ProcessQueue(this.maxProcesses) : tests = new Queue(); + + tryRunTest() { + if (numProcesses < maxProcesses && !tests.isEmpty()) { + TestCase test = tests.removeFirst(); + print("running ${test.displayName}"); + // TODO(whesse): Refactor into various test output methods. + Function old_callback = test.completedHandler; + Function wrapper = (TestCase test_arg) { + numProcesses--; + print("finished ${test_arg.displayName}"); + tryRunTest(); + old_callback(test_arg); + }; + test.completedHandler = wrapper; + + // TODO(whesse): Add timeout information to TestCase, use it here. + new RunningProcess(test, 60).start(); + numProcesses++; + } + } + + runTest(TestCase test) { + tests.add(test); + tryRunTest(); + } +}