Skip to content

Commit

Permalink
Update fuchsia-tester so it takes map of kernel test files (flutter#2…
Browse files Browse the repository at this point in the history
…1573)

* Update fuchsia-tester so it takes map of kernel test files

* Set mainDart correctly. Cleanup nits.
  • Loading branch information
aam authored Sep 9, 2018
1 parent e8fa45c commit e2e2413
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
26 changes: 15 additions & 11 deletions packages/flutter_tools/bin/fuchsia_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:convert' show json;
import 'dart:math' as math;

import 'package:args/args.dart';
Expand All @@ -27,17 +28,15 @@ const String _kOptionPackages = 'packages';
const String _kOptionShell = 'shell';
const String _kOptionTestDirectory = 'test-directory';
const String _kOptionSdkRoot = 'sdk-root';
const String _kOptionTestFile = 'test-file';
const String _kOptionDillFile = 'dill-file';
const String _kOptionIcudtl = 'icudtl';
const String _kOptionTests = 'tests';
const List<String> _kRequiredOptions = <String>[
_kOptionPackages,
_kOptionShell,
_kOptionTestDirectory,
_kOptionSdkRoot,
_kOptionTestFile,
_kOptionDillFile,
_kOptionIcudtl
_kOptionIcudtl,
_kOptionTests,
];
const String _kOptionCoverage = 'coverage';
const String _kOptionCoveragePath = 'coverage-path';
Expand All @@ -54,9 +53,8 @@ Future<Null> run(List<String> args) async {
..addOption(_kOptionShell, help: 'The Flutter shell binary')
..addOption(_kOptionTestDirectory, help: 'Directory containing the tests')
..addOption(_kOptionSdkRoot, help: 'Path to the SDK platform files')
..addOption(_kOptionTestFile, help: 'Test file to execute')
..addOption(_kOptionDillFile, help: 'Precompiled dill file for test')
..addOption(_kOptionIcudtl, help: 'Path to the ICU data file')
..addOption(_kOptionTests, help: 'Path to json file that maps Dart test files to precompiled dill files')
..addFlag(_kOptionCoverage,
defaultsTo: false,
negatable: false,
Expand All @@ -77,8 +75,6 @@ Future<Null> run(List<String> args) async {
Cache.flutterRoot = tempDir.path;
final Directory testDirectory =
fs.directory(argResults[_kOptionTestDirectory]);
final File testFile = fs.file(argResults[_kOptionTestFile]);
final File dillFile = fs.file(argResults[_kOptionDillFile]);

final String shellPath = argResults[_kOptionShell];
if (!fs.isFileSync(shellPath)) {
Expand Down Expand Up @@ -115,13 +111,21 @@ Future<Null> run(List<String> args) async {
collector = new CoverageCollector();
}


final Map<String, String> tests = <String, String>{};
final List<Map<String, dynamic>> jsonList = List<Map<String, dynamic>>.from(
json.decode(fs.file(argResults[_kOptionTests]).readAsStringSync()));
for (Map<String, dynamic> map in jsonList) {
tests[map['source']] = map['dill'];
}

exitCode = await runTests(
<String>[testFile.path],
tests.keys.toList(),
workDir: testDirectory,
watcher: collector,
ipv6: false,
enableObservatory: collector != null,
precompiledDillPath: dillFile.path,
precompiledDillFiles: tests,
concurrency: math.max(1, platform.numberOfProcessors - 2),
);

Expand Down
19 changes: 14 additions & 5 deletions packages/flutter_tools/lib/src/test/flutter_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void installHook({
bool startPaused = false,
int port = 0,
String precompiledDillPath,
Map<String, String> precompiledDillFiles,
bool trackWidgetCreation = false,
bool updateGoldens = false,
int observatoryPort,
Expand All @@ -89,6 +90,7 @@ void installHook({
host: _kHosts[serverType],
port: port,
precompiledDillPath: precompiledDillPath,
precompiledDillFiles: precompiledDillFiles,
trackWidgetCreation: trackWidgetCreation,
updateGoldens: updateGoldens,
projectRootDirectory: projectRootDirectory,
Expand Down Expand Up @@ -339,6 +341,7 @@ class _FlutterPlatform extends PlatformPlugin {
this.host,
this.port,
this.precompiledDillPath,
this.precompiledDillFiles,
this.trackWidgetCreation,
this.updateGoldens,
this.projectRootDirectory,
Expand All @@ -353,6 +356,7 @@ class _FlutterPlatform extends PlatformPlugin {
final InternetAddress host;
final int port;
final String precompiledDillPath;
final Map<String, String> precompiledDillFiles;
final bool trackWidgetCreation;
final bool updateGoldens;
final Uri projectRootDirectory;
Expand Down Expand Up @@ -444,12 +448,17 @@ class _FlutterPlatform extends PlatformPlugin {
printTrace('test $ourTestCount: starting shell process');

// If a kernel file is given, then use that to launch the test.
// Otherwise create a "listener" dart that invokes actual test.
String mainDart = precompiledDillPath != null
? precompiledDillPath
: _createListenerDart(finalizers, ourTestCount, testPath, server);
// If mapping is provided, look kernel file from mapping.
// If all fails, create a "listener" dart that invokes actual test.
String mainDart;
if (precompiledDillPath != null) {
mainDart = precompiledDillPath;
} else if (precompiledDillFiles != null) {
mainDart = precompiledDillFiles[testPath];
}
mainDart ??= _createListenerDart(finalizers, ourTestCount, testPath, server);

if (precompiledDillPath == null) {
if (precompiledDillPath == null && precompiledDillFiles == null) {
// Lazily instantiate compiler so it is built only if it is actually used.
compiler ??= new _Compiler(trackWidgetCreation, projectRootDirectory);
mainDart = await compiler.compile(mainDart);
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter_tools/lib/src/test/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Future<int> runTests(
bool ipv6 = false,
bool machine = false,
String precompiledDillPath,
Map<String, String> precompiledDillFiles,
bool trackWidgetCreation = false,
bool updateGoldens = false,
TestWatcher watcher,
Expand Down Expand Up @@ -75,6 +76,7 @@ Future<int> runTests(
startPaused: startPaused,
serverType: serverType,
precompiledDillPath: precompiledDillPath,
precompiledDillFiles: precompiledDillFiles,
trackWidgetCreation: trackWidgetCreation,
updateGoldens: updateGoldens,
projectRootDirectory: fs.currentDirectory.uri,
Expand Down

0 comments on commit e2e2413

Please sign in to comment.