blob: 7789410c1eca25b2d0430a05995b2d65060f6fd1 [file] [log] [blame]
#!/usr/bin/env dart
import 'dart:async';
import 'dart:io';
import 'dart:io' as io;
import 'package:path/path.dart' as path;
final root = path.relative(Platform.script.resolve('.').toFilePath());
final testDir = path.join(root, 'vipunen/tests');
final vipunen = path.join(root, 'vipunen/bin/compile.dart');
final fasta = path.join(root, 'pkg/front_end/tool/fasta');
final transform = path.join(root, 'pkg/kernel/bin/transform.dart');
main(args) async {
String selector;
if (args.length != 1) {
if (!['debug', 'release'].contains(args[0])) {
print('Usage: ${Platform.executable} ${Platform.script} [debug|release]'
'<selector>');
exit(1);
}
if (args.length == 2) {
selector = args[1];
}
}
final config = args[0] == 'debug' ? 'DebugX64' : 'ReleaseX64';
final buildRoot = Platform.isMacOS ? 'xcodebuild' : 'out';
final buildDir = path.join(root, '${buildRoot}/$config');
final failures = [];
final futures = <Future>[];
for (final String testFile in scanTests()) {
if (selector != null && !testFile.contains(selector)) continue;
final dirname = path.dirname(testFile);
final basename = path.basename(testFile);
final dillFile = '$dirname/$basename.dill';
final shakenDillFile = '$dirname/$basename.shaken.dill';
final closuresDillFile = '$dirname/$basename.vipclosures.dill';
final methodcallDillFile = '$dirname/$basename.vipclosures.methodcall.dill';
final asmFile = '$dirname/$basename.S';
final soFile = '$dirname/$basename.so';
final printedLines = <String>[];
futures.add(runZoned(() async {
print('\nTesting $testFile:\n----------------------------------------');
final ok = await runFasta(buildDir, testFile, dillFile) &&
await transformIt('treeshake', dillFile, shakenDillFile) &&
await transformIt('vipclosures', shakenDillFile, closuresDillFile) &&
await transformIt(
'methodcall', closuresDillFile, methodcallDillFile) &&
await compileIt(buildDir, methodcallDillFile, asmFile) &&
await assembleIt(asmFile, soFile) &&
await runIt(buildDir, soFile);
if (!ok) failures.add(testFile);
return printedLines;
}, zoneSpecification: new ZoneSpecification(print: (_, _1, _2, line) {
printedLines.add(line);
})));
}
for (final lines in await Future.wait(futures)) {
lines.forEach(print);
}
if (failures.isEmpty) {
print('ALL TESTS PASSED');
} else {
for (var test in failures) {
print("FAIL $test");
}
}
}
List<String> scanTests() {
return new Directory(testDir)
.listSync()
.where((fse) => fse is File && fse.path.endsWith('_test.dart'))
.map((file) => file.path)
.toList();
}
Future<bool> runFasta(String buildDir, String testFile, String dillFile) {
final args = [
'compile',
'-o',
dillFile,
'--platform=$buildDir/patched_sdk/platform.dill',
testFile,
];
return run(args, fasta);
}
Future<bool> transformIt(
String transformer, String fromDillFile, String toDillFile) {
return run([
'-c',
transform,
'-f',
'bin',
'-t',
transformer,
'-o',
toDillFile,
fromDillFile,
], Platform.executable);
}
Future<bool> compileIt(String buildDir, String dillFile, String asmFile) {
final environment = new Map<String, String>.from(Platform.environment);
environment['LD_LIBRARY_PATH'] = buildDir;
return run(['--checked', vipunen, '-o', asmFile, dillFile],
Platform.executable, environment);
}
Future assembleIt(String asmFile, String soFile) {
return run(['-shared', '-fPIC', '-o', soFile, asmFile], 'g++');
}
Future runIt(String buildDir, String soFile) async {
return run(
[path.join(root, '.run.dart'), soFile], path.join(buildDir, 'dart'));
}
Future<bool> run(List<String> arguments,
[String executable, Map<String, String> environment]) async {
if (executable == null) executable = Platform.executable;
print('Running "$executable ${arguments.join(' ')}"');
final ProcessResult result =
await Process.run(executable, arguments, environment: environment);
return checkResult(result.exitCode, result.stdout, result.stderr);
}
bool checkResult(int exitCode, String stdout, String stderr) {
if (exitCode != 0) {
print(' -> Failed with ${exitCode}');
print(' stdout: \n ${stdout.split('\n').join('\n ')}');
print(' stderr: \n ${stderr.split('\n').join('\n ')}');
io.exitCode = exitCode;
return false;
}
return true;
}