Chromium Code Reviews| Index: test/perf/run.dart |
| diff --git a/test/perf/run.dart b/test/perf/run.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..80f1b4662513a2cc1c2cb83a74842c1b593b63ae |
| --- /dev/null |
| +++ b/test/perf/run.dart |
| @@ -0,0 +1,115 @@ |
| +// Copyright (c) 2012, 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. |
| + |
| +/** |
| + * This is a helper for run.sh. We try to run all of the Dart code in one |
|
Jennifer Messerly
2013/01/07 21:07:46
helper for perf.sh?
should this file be called "pe
Siggi Cherem (dart-lang)
2013/01/08 02:26:18
Done.
|
| + * instance of the Dart VM to reduce warm-up time. |
| + */ |
| +library run_impl; |
| + |
| +import 'dart:io'; |
| +import 'dart:json'; |
| +import 'dart:utf' show encodeUtf8; |
| +import 'dart:isolate'; |
| +import 'package:unittest/unittest.dart'; |
| +import 'package:web_ui/dwc.dart' as dwc; |
| + |
| +import '../compact_vm_config.dart'; |
| + |
| +main() { |
| + var args = new Options().arguments; |
| + var pattern = new RegExp(args.length > 0 ? args[0] : '.'); |
| + |
| + useCompactVMConfiguration(); |
| + |
| + var lister = new Directory.fromPath(new Path('input')).list(); |
| + var cwd = new Path(new Directory.current().path); |
| + var inputDir = cwd.append('input'); |
| + var results = {}; |
| + lister.onFile = (path) { |
| + if (!path.endsWith('_test.html') || !pattern.hasMatch(path)) return; |
| + var filename = new Path(path).filename; |
| + var outDir = cwd.append('output'); |
| + var htmlPath = outDir.append(filename).toString(); |
| + var dartPath = outDir.append('${filename}_bootstrap.dart').toString(); |
| + |
| + test('drt-compile $filename', () { |
| + expect(dwc.run(['-o', 'output/', path], printTime: false) |
| + .transform((res) { |
| + expect(res.messages.length, 0, |
| + reason: Strings.join(res.messages, '\n')); |
| + }), completes); |
| + }); |
| + |
| + test('drt-run $filename', () { |
| + results['dart $filename'] = null; |
| + var outputPath = '$htmlPath.txt'; |
| + expect(Process.run('DumpRenderTree', [htmlPath]).transform((res) { |
| + results['dart $filename'] = _extractResult(res.stdout); |
| + expect(res.exitCode, 0, reason: |
| + 'DumpRenderTree exited with a non-zero exit code, when running ' |
| + 'on $filename. Contents of stderr: \n${res.stderr}'); |
| + }), completes); |
| + }); |
| + |
| + test('dart2js-compile $filename', () { |
| + expect(Process.run('dart2js', ["-o$dartPath.js", dartPath]).transform( |
| + (res) { |
| + if (res.stdout != null && res.stdout != '') print(res.stdout); |
| + expect(res.exitCode, 0, reason: |
| + 'dart2js exited with a non-zero exit code, when running ' |
| + 'on $dartPath. Contents of stderr: \n${res.stderr}'); |
| + }), completes); |
| + }); |
| + |
| + test('js-drt-run $filename', () { |
| + results['js $filename'] = null; |
| + var htmlJSPath = '${htmlPath}_js.html'; |
| + // Mutate the .html file to ensure DRT runs the code as Javascript. |
| + expect(Process.run('sed', [ |
|
Jennifer Messerly
2013/01/07 21:07:46
How bad would it be to rewrite this in Dart instea
Siggi Cherem (dart-lang)
2013/01/08 02:26:18
good point - done. I believe the \1 is coming with
|
| + // Load .dart.js directly |
| + '-e', r's/application\/dart\(.*\)\.dart/' |
| + r'application\/javascript\1.dart.js/', |
| + // Remove references to /dart.js and to start_dart.js |
| + '-e', r's/.*script.*\/dart.js.*//', |
| + '-e', r's/.*script.*start_dart.js.*//', |
| + // Save the modified html |
| + '-e', 'w $htmlJSPath', |
| + htmlPath]).transform((res) { |
| + expect(res.exitCode, 0, reason: res.stderr); |
| + expect(Process.run('DumpRenderTree', [htmlJSPath]).transform((res) { |
| + results['js $filename'] = _extractResult(res.stdout); |
| + expect(res.exitCode, 0, reason: |
| + 'DumpRenderTree exited with a non-zero exit code, when running ' |
| + 'on $filename. Contents of stderr: \n${res.stderr}'); |
| + }), completes); |
| + }), completes); |
| + }); |
| + |
| + lister.onDone = (done) { |
| + test('printing-results', () { |
| + print('\nRESULTS'); |
| + results.forEach((k, v) { |
| + print(' $k: $v'); |
| + }); |
| + expect(_writeFile('$cwd/output/results.json', JSON.stringify(results)), |
| + completes); |
| + }); |
| + }; |
| + }; |
| +} |
| + |
| +final _SCORE_REGEX = new RegExp(r'^CONSOLE.*benchmark-score: (.*)$', |
| + multiLine: true); |
| + |
| +_extractResult(String s) { |
| + var match = _SCORE_REGEX.firstMatch(s); |
| + return (match != null) ? double.parse(match.group(1)) : null; |
| +} |
| + |
| +Future _writeFile(String path, String text) { |
| + return new File(path).open(FileMode.WRITE) |
| + .chain((file) => file.writeString(text)) |
| + .chain((file) => file.close()); |
| +} |