Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * 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.
| |
| 7 * instance of the Dart VM to reduce warm-up time. | |
| 8 */ | |
| 9 library run_impl; | |
| 10 | |
| 11 import 'dart:io'; | |
| 12 import 'dart:json'; | |
| 13 import 'dart:utf' show encodeUtf8; | |
| 14 import 'dart:isolate'; | |
| 15 import 'package:unittest/unittest.dart'; | |
| 16 import 'package:web_ui/dwc.dart' as dwc; | |
| 17 | |
| 18 import '../compact_vm_config.dart'; | |
| 19 | |
| 20 main() { | |
| 21 var args = new Options().arguments; | |
| 22 var pattern = new RegExp(args.length > 0 ? args[0] : '.'); | |
| 23 | |
| 24 useCompactVMConfiguration(); | |
| 25 | |
| 26 var lister = new Directory.fromPath(new Path('input')).list(); | |
| 27 var cwd = new Path(new Directory.current().path); | |
| 28 var inputDir = cwd.append('input'); | |
| 29 var results = {}; | |
| 30 lister.onFile = (path) { | |
| 31 if (!path.endsWith('_test.html') || !pattern.hasMatch(path)) return; | |
| 32 var filename = new Path(path).filename; | |
| 33 var outDir = cwd.append('output'); | |
| 34 var htmlPath = outDir.append(filename).toString(); | |
| 35 var dartPath = outDir.append('${filename}_bootstrap.dart').toString(); | |
| 36 | |
| 37 test('drt-compile $filename', () { | |
| 38 expect(dwc.run(['-o', 'output/', path], printTime: false) | |
| 39 .transform((res) { | |
| 40 expect(res.messages.length, 0, | |
| 41 reason: Strings.join(res.messages, '\n')); | |
| 42 }), completes); | |
| 43 }); | |
| 44 | |
| 45 test('drt-run $filename', () { | |
| 46 results['dart $filename'] = null; | |
| 47 var outputPath = '$htmlPath.txt'; | |
| 48 expect(Process.run('DumpRenderTree', [htmlPath]).transform((res) { | |
| 49 results['dart $filename'] = _extractResult(res.stdout); | |
| 50 expect(res.exitCode, 0, reason: | |
| 51 'DumpRenderTree exited with a non-zero exit code, when running ' | |
| 52 'on $filename. Contents of stderr: \n${res.stderr}'); | |
| 53 }), completes); | |
| 54 }); | |
| 55 | |
| 56 test('dart2js-compile $filename', () { | |
| 57 expect(Process.run('dart2js', ["-o$dartPath.js", dartPath]).transform( | |
| 58 (res) { | |
| 59 if (res.stdout != null && res.stdout != '') print(res.stdout); | |
| 60 expect(res.exitCode, 0, reason: | |
| 61 'dart2js exited with a non-zero exit code, when running ' | |
| 62 'on $dartPath. Contents of stderr: \n${res.stderr}'); | |
| 63 }), completes); | |
| 64 }); | |
| 65 | |
| 66 test('js-drt-run $filename', () { | |
| 67 results['js $filename'] = null; | |
| 68 var htmlJSPath = '${htmlPath}_js.html'; | |
| 69 // Mutate the .html file to ensure DRT runs the code as Javascript. | |
| 70 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
| |
| 71 // Load .dart.js directly | |
| 72 '-e', r's/application\/dart\(.*\)\.dart/' | |
| 73 r'application\/javascript\1.dart.js/', | |
| 74 // Remove references to /dart.js and to start_dart.js | |
| 75 '-e', r's/.*script.*\/dart.js.*//', | |
| 76 '-e', r's/.*script.*start_dart.js.*//', | |
| 77 // Save the modified html | |
| 78 '-e', 'w $htmlJSPath', | |
| 79 htmlPath]).transform((res) { | |
| 80 expect(res.exitCode, 0, reason: res.stderr); | |
| 81 expect(Process.run('DumpRenderTree', [htmlJSPath]).transform((res) { | |
| 82 results['js $filename'] = _extractResult(res.stdout); | |
| 83 expect(res.exitCode, 0, reason: | |
| 84 'DumpRenderTree exited with a non-zero exit code, when running ' | |
| 85 'on $filename. Contents of stderr: \n${res.stderr}'); | |
| 86 }), completes); | |
| 87 }), completes); | |
| 88 }); | |
| 89 | |
| 90 lister.onDone = (done) { | |
| 91 test('printing-results', () { | |
| 92 print('\nRESULTS'); | |
| 93 results.forEach((k, v) { | |
| 94 print(' $k: $v'); | |
| 95 }); | |
| 96 expect(_writeFile('$cwd/output/results.json', JSON.stringify(results)), | |
| 97 completes); | |
| 98 }); | |
| 99 }; | |
| 100 }; | |
| 101 } | |
| 102 | |
| 103 final _SCORE_REGEX = new RegExp(r'^CONSOLE.*benchmark-score: (.*)$', | |
| 104 multiLine: true); | |
| 105 | |
| 106 _extractResult(String s) { | |
| 107 var match = _SCORE_REGEX.firstMatch(s); | |
| 108 return (match != null) ? double.parse(match.group(1)) : null; | |
| 109 } | |
| 110 | |
| 111 Future _writeFile(String path, String text) { | |
| 112 return new File(path).open(FileMode.WRITE) | |
| 113 .chain((file) => file.writeString(text)) | |
| 114 .chain((file) => file.close()); | |
| 115 } | |
| OLD | NEW |