Remove outdated Fuchsia concepts (#107335)

Fuchsia will soon remove all support for Component Framework version 1
components (recognized by component manifests ending in `.cmx`).
Notably, some of the `flutter` tool commands for Fuchsia devices--
notably, but not limited to, those related to CFv1--are outdated, and
either do not work today or soon won't work.

This PR removes the outdated components and commands, replacing some
with the newer version, or simply removing the non-working features,
in some cases.
This commit is contained in:
Rich Kadel
2022-07-22 16:42:48 -07:00
committed by GitHub
parent a3b531ddc9
commit 549f70c914
22 changed files with 647 additions and 1361 deletions

View File

@@ -1,239 +0,0 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:args/command_runner.dart';
import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build.dart';
import 'package:flutter_tools/src/commands/build_fuchsia.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/fuchsia/fuchsia_kernel_compiler.dart';
import 'package:flutter_tools/src/fuchsia/fuchsia_pm.dart';
import 'package:flutter_tools/src/fuchsia/fuchsia_sdk.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:meta/meta.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/test_flutter_command_runner.dart';
// Defined globally for fakes to use.
FileSystem fileSystem;
void main() {
Cache.disableLocking();
final Platform linuxPlatform = FakePlatform(
environment: const <String, String>{
'FLUTTER_ROOT': '/',
},
);
final Platform windowsPlatform = FakePlatform(
operatingSystem: 'windows',
environment: const <String, String>{
'FLUTTER_ROOT': '/',
},
);
FakeFuchsiaSdk fuchsiaSdk;
setUp(() {
fuchsiaSdk = FakeFuchsiaSdk();
fileSystem = MemoryFileSystem.test();
});
group('Fuchsia build fails gracefully when', () {
testUsingContext('The feature is disabled', () async {
final BuildCommand command = BuildCommand();
fileSystem.directory('fuchsia').createSync(recursive: true);
fileSystem.file('.packages').createSync();
fileSystem.file('pubspec.yaml').createSync();
fileSystem.file('lib/main.dart').createSync(recursive: true);
expect(
createTestCommandRunner(command).run(const <String>['build', 'fuchsia']),
throwsToolExit(message: '"build fuchsia" is currently disabled'),
);
}, overrides: <Type, Generator>{
Platform: () => linuxPlatform,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(),
});
testUsingContext('there is no Fuchsia project', () async {
final BuildCommand command = BuildCommand();
expect(
createTestCommandRunner(command).run(const <String>['build', 'fuchsia']),
throwsToolExit(),
);
}, overrides: <Type, Generator>{
Platform: () => linuxPlatform,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isFuchsiaEnabled: true),
});
testUsingContext('there is no cmx file', () async {
final BuildCommand command = BuildCommand();
fileSystem.directory('fuchsia').createSync(recursive: true);
fileSystem.file('.packages').createSync();
fileSystem.file('pubspec.yaml').createSync();
expect(
createTestCommandRunner(command).run(const <String>['build', 'fuchsia']),
throwsToolExit(),
);
}, overrides: <Type, Generator>{
Platform: () => linuxPlatform,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isFuchsiaEnabled: true),
});
testUsingContext('on Windows platform', () async {
final BuildCommand command = BuildCommand();
const String appName = 'app_name';
fileSystem
.file(fileSystem.path.join('fuchsia', 'meta', '$appName.cmx'))
..createSync(recursive: true)
..writeAsStringSync('{}');
fileSystem.file('.packages').createSync();
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
pubspecFile.writeAsStringSync('name: $appName');
final bool supported = BuildFuchsiaCommand(verboseHelp: false).supported;
expect(
createTestCommandRunner(command).run(const <String>['build', 'fuchsia']),
supported ? throwsToolExit() : throwsA(isA<UsageException>()),
);
}, overrides: <Type, Generator>{
Platform: () => windowsPlatform,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isFuchsiaEnabled: true),
});
testUsingContext('there is no Fuchsia kernel compiler', () async {
final BuildCommand command = BuildCommand();
const String appName = 'app_name';
fileSystem
.file(fileSystem.path.join('fuchsia', 'meta', '$appName.cmx'))
..createSync(recursive: true)
..writeAsStringSync('{}');
fileSystem.file('.packages').createSync();
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
pubspecFile.writeAsStringSync('name: $appName');
expect(
createTestCommandRunner(command).run(const <String>['build', 'fuchsia']),
throwsToolExit(),
);
}, overrides: <Type, Generator>{
Platform: () => linuxPlatform,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isFuchsiaEnabled: true),
});
});
testUsingContext('Fuchsia build parts fit together right', () async {
final BuildCommand command = BuildCommand();
const String appName = 'app_name';
fileSystem
.file(fileSystem.path.join('fuchsia', 'meta', '$appName.cmx'))
..createSync(recursive: true)
..writeAsStringSync('{}');
fileSystem.file('.packages').createSync();
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
pubspecFile.writeAsStringSync('name: $appName');
await createTestCommandRunner(command)
.run(const <String>['build', 'fuchsia']);
final String farPath = fileSystem.path.join(
getFuchsiaBuildDirectory(), 'pkg', 'app_name-0.far',
);
expect(fileSystem.file(farPath), exists);
}, overrides: <Type, Generator>{
Platform: () => linuxPlatform,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
FuchsiaSdk: () => fuchsiaSdk,
FeatureFlags: () => TestFeatureFlags(isFuchsiaEnabled: true),
});
}
class FakeFuchsiaPM extends Fake implements FuchsiaPM {
String _appName;
@override
Future<bool> init(String buildPath, String appName) async {
if (!fileSystem.directory(buildPath).existsSync()) {
return false;
}
fileSystem
.file(fileSystem.path.join(buildPath, 'meta', 'package'))
.createSync(recursive: true);
_appName = appName;
return true;
}
@override
Future<bool> build(String buildPath, String manifestPath) async {
if (!fileSystem.file(fileSystem.path.join(buildPath, 'meta', 'package')).existsSync() ||
!fileSystem.file(manifestPath).existsSync()) {
return false;
}
fileSystem.file(fileSystem.path.join(buildPath, 'meta.far')).createSync(recursive: true);
return true;
}
@override
Future<bool> archive(String buildPath, String manifestPath) async {
if (!fileSystem.file(fileSystem.path.join(buildPath, 'meta', 'package')).existsSync() ||
!fileSystem.file(manifestPath).existsSync()) {
return false;
}
if (_appName == null) {
return false;
}
fileSystem
.file(fileSystem.path.join(buildPath, '$_appName-0.far'))
.createSync(recursive: true);
return true;
}
}
class FakeFuchsiaKernelCompiler extends Fake implements FuchsiaKernelCompiler {
@override
Future<void> build({
@required FuchsiaProject fuchsiaProject,
@required String target, // E.g., lib/main.dart
BuildInfo buildInfo = BuildInfo.debug,
}) async {
final String outDir = getFuchsiaBuildDirectory();
final String appName = fuchsiaProject.project.manifest.appName;
final String manifestPath = fileSystem.path.join(outDir, '$appName.dilpmanifest');
fileSystem.file(manifestPath).createSync(recursive: true);
}
}
class FakeFuchsiaSdk extends Fake implements FuchsiaSdk {
@override
final FuchsiaPM fuchsiaPM = FakeFuchsiaPM();
@override
final FuchsiaKernelCompiler fuchsiaKernelCompiler =
FakeFuchsiaKernelCompiler();
}

View File

@@ -12,7 +12,6 @@ import 'package:flutter_tools/src/commands/build.dart';
import 'package:flutter_tools/src/commands/build_aar.dart';
import 'package:flutter_tools/src/commands/build_apk.dart';
import 'package:flutter_tools/src/commands/build_appbundle.dart';
import 'package:flutter_tools/src/commands/build_fuchsia.dart';
import 'package:flutter_tools/src/commands/build_ios.dart';
import 'package:flutter_tools/src/commands/build_ios_framework.dart';
import 'package:flutter_tools/src/commands/build_linux.dart';
@@ -36,9 +35,11 @@ void main() {
BuildIOSCommand(verboseHelp: false),
BuildIOSArchiveCommand(verboseHelp: false),
BuildAppBundleCommand(),
BuildFuchsiaCommand(verboseHelp: false),
BuildAarCommand(verboseHelp: false),
BuildIOSFrameworkCommand(verboseHelp: false, buildSystem: globals.buildSystem),
BuildIOSFrameworkCommand(
verboseHelp: false,
buildSystem: globals.buildSystem,
),
AttachCommand(),
];
@@ -53,7 +54,8 @@ void main() {
}
});
testUsingContext('BuildSubCommand displays current null safety mode', () async {
testUsingContext('BuildSubCommand displays current null safety mode',
() async {
const BuildInfo unsound = BuildInfo(
BuildMode.debug,
'',
@@ -67,11 +69,13 @@ void main() {
);
FakeBuildSubCommand().test(unsound);
expect(testLogger.statusText, contains('Building without sound null safety'));
expect(
testLogger.statusText, contains('Building without sound null safety'));
testLogger.clear();
FakeBuildSubCommand().test(sound);
expect(testLogger.statusText, contains('💪 Building with sound null safety 💪'));
expect(testLogger.statusText,
contains('💪 Building with sound null safety 💪'));
});
testUsingContext('Include only supported sub commands', () {

View File

@@ -22,8 +22,6 @@ import 'package:flutter_tools/src/fuchsia/fuchsia_kernel_compiler.dart';
import 'package:flutter_tools/src/fuchsia/fuchsia_pm.dart';
import 'package:flutter_tools/src/fuchsia/fuchsia_sdk.dart';
import 'package:flutter_tools/src/fuchsia/pkgctl.dart';
import 'package:flutter_tools/src/fuchsia/session_control.dart';
import 'package:flutter_tools/src/fuchsia/tiles_ctl.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/project.dart';
import 'package:meta/meta.dart';
@@ -42,7 +40,6 @@ void main() {
Artifacts artifacts;
FakeProcessManager fakeSuccessfulProcessManager;
FakeProcessManager fakeFailedProcessManagerForHostAddress;
FakeProcessManager fakeSuccessfulProcessManagerWithSession;
File sshConfig;
setUp(() {
@@ -50,56 +47,69 @@ void main() {
osUtils = FakeOperatingSystemUtils();
fuchsiaDeviceTools = FakeFuchsiaDeviceTools();
fuchsiaSdk = FakeFuchsiaSdk();
sshConfig = MemoryFileSystem.test().file('ssh_config')..writeAsStringSync('\n');
sshConfig = MemoryFileSystem.test().file('ssh_config')
..writeAsStringSync('\n');
artifacts = Artifacts.test();
for (final BuildMode mode in <BuildMode>[BuildMode.debug, BuildMode.release]) {
memoryFileSystem.file(
artifacts.getArtifactPath(Artifact.fuchsiaKernelCompiler,
platform: TargetPlatform.fuchsia_arm64, mode: mode),
).createSync();
for (final BuildMode mode in <BuildMode>[
BuildMode.debug,
BuildMode.release
]) {
memoryFileSystem
.file(
artifacts.getArtifactPath(Artifact.fuchsiaKernelCompiler,
platform: TargetPlatform.fuchsia_arm64, mode: mode),
)
.createSync();
memoryFileSystem.file(
artifacts.getArtifactPath(Artifact.platformKernelDill,
platform: TargetPlatform.fuchsia_arm64, mode: mode),
).createSync();
memoryFileSystem
.file(
artifacts.getArtifactPath(Artifact.platformKernelDill,
platform: TargetPlatform.fuchsia_arm64, mode: mode),
)
.createSync();
memoryFileSystem.file(
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath,
platform: TargetPlatform.fuchsia_arm64, mode: mode),
).createSync();
memoryFileSystem
.file(
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath,
platform: TargetPlatform.fuchsia_arm64, mode: mode),
)
.createSync();
memoryFileSystem.file(
artifacts.getArtifactPath(Artifact.fuchsiaFlutterRunner,
platform: TargetPlatform.fuchsia_arm64, mode: mode),
).createSync();
memoryFileSystem
.file(
artifacts.getArtifactPath(Artifact.fuchsiaFlutterRunner,
platform: TargetPlatform.fuchsia_arm64, mode: mode),
)
.createSync();
}
fakeSuccessfulProcessManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['ssh', '-F', '/ssh_config', '123', 'which session_control'],
exitCode: 1,
),
FakeCommand(
command: <String>['ssh', '-F', sshConfig.absolute.path, '123', r'echo $SSH_CONNECTION'],
stdout: 'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
command: <String>[
'ssh',
'-F',
sshConfig.absolute.path,
'123',
r'echo $SSH_CONNECTION'
],
stdout:
'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
),
]);
fakeFailedProcessManagerForHostAddress = FakeProcessManager.list(<FakeCommand>[
fakeFailedProcessManagerForHostAddress =
FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>['ssh', '-F', sshConfig.absolute.path, '123', r'echo $SSH_CONNECTION'],
stdout: 'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
command: <String>[
'ssh',
'-F',
sshConfig.absolute.path,
'123',
r'echo $SSH_CONNECTION'
],
stdout:
'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
exitCode: 1,
),
]);
fakeSuccessfulProcessManagerWithSession = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['ssh', '-F', '/ssh_config', '123', 'which session_control'],
stdout: '/bin/session_control',
),
FakeCommand(
command: <String>['ssh', '-F', sshConfig.absolute.path, '123', r'echo $SSH_CONNECTION'],
stdout: 'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
),
]);
});
Future<LaunchResult> setupAndStartApp({
@@ -117,15 +127,21 @@ void main() {
final File far = globals.fs.file('app_name-0.far')..createSync();
app = FuchsiaApp.fromPrebuiltApp(far);
} else {
globals.fs.file(globals.fs.path.join('fuchsia', 'meta', '$appName.cmx'))
globals.fs.file(globals.fs.path.join('fuchsia', 'meta', '$appName.cm'))
..createSync(recursive: true)
..writeAsStringSync('{}');
globals.fs.file('.packages').createSync();
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
app = BuildableFuchsiaApp(project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory).fuchsia);
globals.fs
.file(globals.fs.path.join('lib', 'main.dart'))
.createSync(recursive: true);
app = BuildableFuchsiaApp(
project:
FlutterProject.fromDirectoryTest(globals.fs.currentDirectory)
.fuchsia);
}
final DebuggingOptions debuggingOptions = DebuggingOptions.disabled(BuildInfo(mode, null, treeShakeIcons: false));
final DebuggingOptions debuggingOptions = DebuggingOptions.disabled(
BuildInfo(mode, null, treeShakeIcons: false));
return device.startApp(
app,
prebuiltApplication: prebuilt,
@@ -133,10 +149,12 @@ void main() {
);
}
testUsingContext('start prebuilt in release mode', () async {
testUsingContext(
'start prebuilt in release mode fails without session',
() async {
final LaunchResult launchResult =
await setupAndStartApp(prebuilt: true, mode: BuildMode.release);
expect(launchResult.started, isTrue);
expect(launchResult.started, isFalse);
expect(launchResult.hasObservatory, isFalse);
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
@@ -150,20 +168,22 @@ void main() {
testUsingContext('start prebuilt in release mode with session', () async {
final LaunchResult launchResult =
await setupAndStartApp(prebuilt: true, mode: BuildMode.release);
await setupAndStartApp(prebuilt: true, mode: BuildMode.release);
expect(launchResult.started, isTrue);
expect(launchResult.hasObservatory, isFalse);
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => fakeSuccessfulProcessManagerWithSession,
ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
FuchsiaSdk: () => FakeFuchsiaSdk(ffx: FakeFuchsiaFfxWithSession()),
OperatingSystemUtils: () => osUtils,
});
testUsingContext('start and stop prebuilt in release mode', () async {
testUsingContext(
'start and stop prebuilt in release mode fails without session',
() async {
const String appName = 'app_name';
final FuchsiaDevice device = FuchsiaDeviceWithFakeDiscovery('123');
globals.fs.directory('fuchsia').createSync(recursive: true);
@@ -172,14 +192,12 @@ void main() {
final File far = globals.fs.file('app_name-0.far')..createSync();
final FuchsiaApp app = FuchsiaApp.fromPrebuiltApp(far);
final DebuggingOptions debuggingOptions =
DebuggingOptions.disabled(const BuildInfo(BuildMode.release, null, treeShakeIcons: false));
final DebuggingOptions debuggingOptions = DebuggingOptions.disabled(
const BuildInfo(BuildMode.release, null, treeShakeIcons: false));
final LaunchResult launchResult = await device.startApp(app,
prebuiltApplication: true,
debuggingOptions: debuggingOptions);
expect(launchResult.started, isTrue);
prebuiltApplication: true, debuggingOptions: debuggingOptions);
expect(launchResult.started, isFalse);
expect(launchResult.hasObservatory, isFalse);
expect(await device.stopApp(app), isTrue);
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
@@ -190,7 +208,8 @@ void main() {
OperatingSystemUtils: () => osUtils,
});
testUsingContext('start and stop prebuilt in release mode with session', () async {
testUsingContext('start and stop prebuilt in release mode with session',
() async {
const String appName = 'app_name';
final FuchsiaDevice device = FuchsiaDeviceWithFakeDiscovery('123');
globals.fs.directory('fuchsia').createSync(recursive: true);
@@ -199,29 +218,29 @@ void main() {
final File far = globals.fs.file('app_name-0.far')..createSync();
final FuchsiaApp app = FuchsiaApp.fromPrebuiltApp(far);
final DebuggingOptions debuggingOptions =
DebuggingOptions.disabled(const BuildInfo(BuildMode.release, null, treeShakeIcons: false));
final DebuggingOptions debuggingOptions = DebuggingOptions.disabled(
const BuildInfo(BuildMode.release, null, treeShakeIcons: false));
final LaunchResult launchResult = await device.startApp(app,
prebuiltApplication: true,
debuggingOptions: debuggingOptions);
prebuiltApplication: true, debuggingOptions: debuggingOptions);
expect(launchResult.started, isTrue);
expect(launchResult.hasObservatory, isFalse);
expect(await device.stopApp(app), isTrue);
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => fakeSuccessfulProcessManagerWithSession,
ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
FuchsiaSdk: () => FakeFuchsiaSdk(ffx: FakeFuchsiaFfxWithSession()),
OperatingSystemUtils: () => osUtils,
});
testUsingContext('start prebuilt in debug mode', () async {
testUsingContext(
'start prebuilt in debug mode fails without session',
() async {
final LaunchResult launchResult =
await setupAndStartApp(prebuilt: true, mode: BuildMode.debug);
expect(launchResult.started, isTrue);
expect(launchResult.hasObservatory, isTrue);
expect(launchResult.started, isFalse);
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
@@ -234,32 +253,32 @@ void main() {
testUsingContext('start prebuilt in debug mode with session', () async {
final LaunchResult launchResult =
await setupAndStartApp(prebuilt: true, mode: BuildMode.debug);
await setupAndStartApp(prebuilt: true, mode: BuildMode.debug);
expect(launchResult.started, isTrue);
expect(launchResult.hasObservatory, isTrue);
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => fakeSuccessfulProcessManagerWithSession,
ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
FuchsiaSdk: () => FakeFuchsiaSdk(ffx: FakeFuchsiaFfxWithSession()),
OperatingSystemUtils: () => osUtils,
});
testUsingContext('start buildable in release mode', () async {
final LaunchResult launchResult =
await setupAndStartApp(prebuilt: false, mode: BuildMode.release);
expect(launchResult.started, isTrue);
expect(launchResult.hasObservatory, isFalse);
testUsingContext(
'start buildable in release mode fails without session',
() async {
expect(
() async => setupAndStartApp(prebuilt: false, mode: BuildMode.release),
throwsToolExit(
message: 'This tool does not currently build apps for fuchsia.\n'
'Build the app using a supported Fuchsia workflow.\n'
'Then use the --use-application-binary flag.'));
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['ssh', '-F', '/ssh_config', '123', 'which session_control'],
exitCode: 1,
),
const FakeCommand(
command: <String>[
'Artifact.genSnapshot.TargetPlatform.fuchsia_arm64.release',
@@ -270,8 +289,15 @@ void main() {
],
),
FakeCommand(
command: <String>['ssh', '-F', sshConfig.absolute.path, '123', r'echo $SSH_CONNECTION'],
stdout: 'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
command: <String>[
'ssh',
'-F',
sshConfig.absolute.path,
'123',
r'echo $SSH_CONNECTION'
],
stdout:
'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
),
]),
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
@@ -280,44 +306,55 @@ void main() {
OperatingSystemUtils: () => osUtils,
});
testUsingContext('start buildable in release mode with session', () async {
final LaunchResult launchResult =
await setupAndStartApp(prebuilt: false, mode: BuildMode.release);
expect(launchResult.started, isTrue);
expect(launchResult.hasObservatory, isFalse);
testUsingContext(
'start buildable in release mode with session fails, does not build apps yet',
() async {
expect(
() async => setupAndStartApp(prebuilt: false, mode: BuildMode.release),
throwsToolExit(
message: 'This tool does not currently build apps for fuchsia.\n'
'Build the app using a supported Fuchsia workflow.\n'
'Then use the --use-application-binary flag.'));
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['ssh', '-F', '/ssh_config', '123', 'which session_control'],
stdout: '/bin/session_control',
),
const FakeCommand(
command: <String>[
'Artifact.genSnapshot.TargetPlatform.fuchsia_arm64.release',
'--deterministic',
'--snapshot_kind=app-aot-elf',
'--elf=build/fuchsia/elf.aotsnapshot',
'build/fuchsia/app_name.dil',
],
),
FakeCommand(
command: <String>['ssh', '-F', sshConfig.absolute.path, '123', r'echo $SSH_CONNECTION'],
stdout: 'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
),
]),
const FakeCommand(
command: <String>[
'Artifact.genSnapshot.TargetPlatform.fuchsia_arm64.release',
'--deterministic',
'--snapshot_kind=app-aot-elf',
'--elf=build/fuchsia/elf.aotsnapshot',
'build/fuchsia/app_name.dil',
],
),
FakeCommand(
command: <String>[
'ssh',
'-F',
sshConfig.absolute.path,
'123',
r'echo $SSH_CONNECTION'
],
stdout:
'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
),
]),
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
FuchsiaSdk: () => FakeFuchsiaSdk(ffx: FakeFuchsiaFfxWithSession()),
OperatingSystemUtils: () => osUtils,
});
testUsingContext('start buildable in debug mode', () async {
final LaunchResult launchResult =
await setupAndStartApp(prebuilt: false, mode: BuildMode.debug);
expect(launchResult.started, isTrue);
expect(launchResult.hasObservatory, isTrue);
testUsingContext(
'start buildable in debug mode fails without session',
() async {
expect(
() async => setupAndStartApp(prebuilt: false, mode: BuildMode.debug),
throwsToolExit(
message: 'This tool does not currently build apps for fuchsia.\n'
'Build the app using a supported Fuchsia workflow.\n'
'Then use the --use-application-binary flag.'));
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
@@ -328,37 +365,42 @@ void main() {
OperatingSystemUtils: () => osUtils,
});
testUsingContext('start buildable in debug mode with session', () async {
final LaunchResult launchResult =
await setupAndStartApp(prebuilt: false, mode: BuildMode.debug);
expect(launchResult.started, isTrue);
expect(launchResult.hasObservatory, isTrue);
testUsingContext(
'start buildable in debug mode with session fails, does not build apps yet',
() async {
expect(
() async => setupAndStartApp(prebuilt: false, mode: BuildMode.debug),
throwsToolExit(
message: 'This tool does not currently build apps for fuchsia.\n'
'Build the app using a supported Fuchsia workflow.\n'
'Then use the --use-application-binary flag.'));
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => fakeSuccessfulProcessManagerWithSession,
ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
FuchsiaSdk: () => FakeFuchsiaSdk(ffx: FakeFuchsiaFfxWithSession()),
OperatingSystemUtils: () => osUtils,
});
testUsingContext('fail when cant get ssh config', () async {
expect(() async =>
setupAndStartApp(prebuilt: true, mode: BuildMode.release),
throwsToolExit(message: 'Cannot interact with device. No ssh config.\n'
'Try setting FUCHSIA_SSH_CONFIG or FUCHSIA_BUILD_DIR.'));
expect(
() async => setupAndStartApp(prebuilt: true, mode: BuildMode.release),
throwsToolExit(
message: 'Cannot interact with device. No ssh config.\n'
'Try setting FUCHSIA_SSH_CONFIG or FUCHSIA_BUILD_DIR.'));
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
FuchsiaArtifacts: () => FuchsiaArtifacts(),
FuchsiaSdk: () => FakeFuchsiaSdk(ffx: FakeFuchsiaFfxWithSession()),
OperatingSystemUtils: () => osUtils,
});
testUsingContext('fail when cant get host address', () async {
expect(() async =>
FuchsiaDeviceWithFakeDiscovery('123').hostAddress,
expect(() async => FuchsiaDeviceWithFakeDiscovery('123').hostAddress,
throwsToolExit(message: 'Failed to get local address, aborting.'));
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
@@ -400,37 +442,6 @@ void main() {
FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils,
});
testUsingContext('fail with correct LaunchResult when tiles fails', () async {
final LaunchResult launchResult =
await setupAndStartApp(prebuilt: true, mode: BuildMode.release);
expect(launchResult.started, isFalse);
expect(launchResult.hasObservatory, isFalse);
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => FakeFuchsiaDeviceTools(tiles: FailingTilesCtl()),
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils,
});
testUsingContext('fail with correct LaunchResult when tiles fails with session', () async {
final LaunchResult launchResult =
await setupAndStartApp(prebuilt: true, mode: BuildMode.release);
expect(launchResult.started, isFalse);
expect(launchResult.hasObservatory, isFalse);
}, overrides: <Type, Generator>{
Artifacts: () => artifacts,
FileSystem: () => memoryFileSystem,
ProcessManager: () => fakeSuccessfulProcessManagerWithSession,
FuchsiaDeviceTools: () => FakeFuchsiaDeviceTools(sessionControl: FailingFuchsiaSessionControl()),
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => fuchsiaSdk,
OperatingSystemUtils: () => osUtils,
});
});
}
@@ -440,34 +451,41 @@ Process _createFakeProcess({
String stderr = '',
bool persistent = false,
}) {
final Stream<List<int>> stdoutStream = Stream<List<int>>.fromIterable(<List<int>>[
final Stream<List<int>> stdoutStream =
Stream<List<int>>.fromIterable(<List<int>>[
utf8.encode(stdout),
]);
final Stream<List<int>> stderrStream = Stream<List<int>>.fromIterable(<List<int>>[
final Stream<List<int>> stderrStream =
Stream<List<int>>.fromIterable(<List<int>>[
utf8.encode(stderr),
]);
final Completer<int> exitCodeCompleter = Completer<int>();
final Process process = FakeProcess(
stdout: stdoutStream,
stderr: stderrStream,
exitCode: persistent ? exitCodeCompleter.future : Future<int>.value(exitCode),
exitCode:
persistent ? exitCodeCompleter.future : Future<int>.value(exitCode),
);
return process;
}
class FuchsiaDeviceWithFakeDiscovery extends FuchsiaDevice {
FuchsiaDeviceWithFakeDiscovery(String id, {String name}) : super(id, name: name);
FuchsiaDeviceWithFakeDiscovery(String id, {String name})
: super(id, name: name);
@override
FuchsiaIsolateDiscoveryProtocol getIsolateDiscoveryProtocol(String isolateName) {
FuchsiaIsolateDiscoveryProtocol getIsolateDiscoveryProtocol(
String isolateName) {
return FakeFuchsiaIsolateDiscoveryProtocol();
}
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.fuchsia_arm64;
Future<TargetPlatform> get targetPlatform async =>
TargetPlatform.fuchsia_arm64;
}
class FakeFuchsiaIsolateDiscoveryProtocol implements FuchsiaIsolateDiscoveryProtocol {
class FakeFuchsiaIsolateDiscoveryProtocol
implements FuchsiaIsolateDiscoveryProtocol {
@override
FutureOr<Uri> get uri => Uri.parse('http://[::1]:37');
@@ -513,112 +531,18 @@ class FailingPkgctl implements FuchsiaPkgctl {
}
}
class FakeFuchsiaTilesCtl implements FuchsiaTilesCtl {
final Map<int, String> _runningApps = <int, String>{};
bool _started = false;
int _nextAppId = 1;
@override
Future<bool> start(FuchsiaDevice device) async {
_started = true;
return true;
}
@override
Future<Map<int, String>> list(FuchsiaDevice device) async {
if (!_started) {
return null;
}
return _runningApps;
}
@override
Future<bool> add(FuchsiaDevice device, String url, List<String> args) async {
if (!_started) {
return false;
}
_runningApps[_nextAppId] = url;
_nextAppId++;
return true;
}
@override
Future<bool> remove(FuchsiaDevice device, int key) async {
if (!_started) {
return false;
}
_runningApps.remove(key);
return true;
}
@override
Future<bool> quit(FuchsiaDevice device) async {
if (!_started) {
return false;
}
_started = false;
return true;
}
}
class FailingTilesCtl implements FuchsiaTilesCtl {
@override
Future<bool> start(FuchsiaDevice device) async {
return false;
}
@override
Future<Map<int, String>> list(FuchsiaDevice device) async {
return null;
}
@override
Future<bool> add(FuchsiaDevice device, String url, List<String> args) async {
return false;
}
@override
Future<bool> remove(FuchsiaDevice device, int key) async {
return false;
}
@override
Future<bool> quit(FuchsiaDevice device) async {
return false;
}
}
class FakeFuchsiaSessionControl implements FuchsiaSessionControl {
@override
Future<bool> add(FuchsiaDevice device, String url) async {
return true;
}
}
class FailingFuchsiaSessionControl implements FuchsiaSessionControl {
@override
Future<bool> add(FuchsiaDevice device, String url) async {
return false;
}
}
class FakeFuchsiaDeviceTools implements FuchsiaDeviceTools {
FakeFuchsiaDeviceTools({
FuchsiaPkgctl pkgctl,
FuchsiaTilesCtl tiles,
FuchsiaSessionControl sessionControl,
FuchsiaFfx ffx,
}) : pkgctl = pkgctl ?? FakeFuchsiaPkgctl(),
tilesCtl = tiles ?? FakeFuchsiaTilesCtl(),
sessionControl = sessionControl ?? FakeFuchsiaSessionControl();
ffx = ffx ?? FakeFuchsiaFfx();
@override
final FuchsiaPkgctl pkgctl;
@override
final FuchsiaTilesCtl tilesCtl;
@override
final FuchsiaSessionControl sessionControl;
final FuchsiaFfx ffx;
}
class FakeFuchsiaPM implements FuchsiaPM {
@@ -638,17 +562,23 @@ class FakeFuchsiaPM implements FuchsiaPM {
@override
Future<bool> build(String buildPath, String manifestPath) async {
if (!globals.fs.file(globals.fs.path.join(buildPath, 'meta', 'package')).existsSync() ||
if (!globals.fs
.file(globals.fs.path.join(buildPath, 'meta', 'package'))
.existsSync() ||
!globals.fs.file(manifestPath).existsSync()) {
return false;
}
globals.fs.file(globals.fs.path.join(buildPath, 'meta.far')).createSync(recursive: true);
globals.fs
.file(globals.fs.path.join(buildPath, 'meta.far'))
.createSync(recursive: true);
return true;
}
@override
Future<bool> archive(String buildPath, String manifestPath) async {
if (!globals.fs.file(globals.fs.path.join(buildPath, 'meta', 'package')).existsSync() ||
if (!globals.fs
.file(globals.fs.path.join(buildPath, 'meta', 'package'))
.existsSync() ||
!globals.fs.file(manifestPath).existsSync()) {
return false;
}
@@ -692,7 +622,6 @@ class FailingPM implements FuchsiaPM {
return false;
}
@override
Future<bool> build(String buildPath, String manifestPath) async {
return false;
@@ -728,7 +657,8 @@ class FakeFuchsiaKernelCompiler implements FuchsiaKernelCompiler {
}) async {
final String outDir = getFuchsiaBuildDirectory();
final String appName = fuchsiaProject.project.manifest.appName;
final String manifestPath = globals.fs.path.join(outDir, '$appName.dilpmanifest');
final String manifestPath =
globals.fs.path.join(outDir, '$appName.dilpmanifest');
globals.fs.file(manifestPath).createSync(recursive: true);
}
}
@@ -743,6 +673,38 @@ class FakeFuchsiaFfx implements FuchsiaFfx {
Future<String> resolve(String deviceName) async {
return '192.168.42.10';
}
@override
Future<String> sessionShow() async {
return null;
}
@override
Future<bool> sessionAdd(String url) async {
return false;
}
}
class FakeFuchsiaFfxWithSession implements FuchsiaFfx {
@override
Future<List<String>> list({Duration timeout}) async {
return <String>['192.168.42.172 scare-cable-skip-ffx'];
}
@override
Future<String> resolve(String deviceName) async {
return '192.168.42.10';
}
@override
Future<String> sessionShow() async {
return 'session info';
}
@override
Future<bool> sessionAdd(String url) async {
return true;
}
}
class FakeFuchsiaSdk extends Fake implements FuchsiaSdk {
@@ -750,9 +712,9 @@ class FakeFuchsiaSdk extends Fake implements FuchsiaSdk {
FuchsiaPM pm,
FuchsiaKernelCompiler compiler,
FuchsiaFfx ffx,
}) : fuchsiaPM = pm ?? FakeFuchsiaPM(),
fuchsiaKernelCompiler = compiler ?? FakeFuchsiaKernelCompiler(),
fuchsiaFfx = ffx ?? FakeFuchsiaFfx();
}) : fuchsiaPM = pm ?? FakeFuchsiaPM(),
fuchsiaKernelCompiler = compiler ?? FakeFuchsiaKernelCompiler(),
fuchsiaFfx = ffx ?? FakeFuchsiaFfx();
@override
final FuchsiaPM fuchsiaPM;

View File

@@ -40,7 +40,7 @@ final vm_service.Isolate fakeIsolate = vm_service.Isolate(
id: '1',
pauseEvent: vm_service.Event(
kind: vm_service.EventKind.kResume,
timestamp: 0
timestamp: 0,
),
breakpoints: <vm_service.Breakpoint>[],
exceptionPauseMode: null,
@@ -87,8 +87,10 @@ void main() {
expect(device.supportsRuntimeMode(BuildMode.jitRelease), false);
});
testWithoutContext('lists nothing when workflow cannot list devices', () async {
final FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow(canListDevices: false);
testWithoutContext('lists nothing when workflow cannot list devices',
() async {
final FakeFuchsiaWorkflow fuchsiaWorkflow =
FakeFuchsiaWorkflow(canListDevices: false);
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
platform: FakePlatform(),
fuchsiaSdk: FakeFuchsiaSdk(devices: 'ignored'),
@@ -102,7 +104,9 @@ void main() {
testWithoutContext('can parse ffx output for single device', () async {
final FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow();
final FakeFuchsiaSdk fuchsiaSdk = FakeFuchsiaSdk(devices: '2001:0db8:85a3:0000:0000:8a2e:0370:7334 paper-pulp-bush-angel');
final FakeFuchsiaSdk fuchsiaSdk = FakeFuchsiaSdk(
devices:
'2001:0db8:85a3:0000:0000:8a2e:0370:7334 paper-pulp-bush-angel');
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
platform: FakePlatform(environment: <String, String>{}),
fuchsiaSdk: fuchsiaSdk,
@@ -118,10 +122,10 @@ void main() {
testWithoutContext('can parse ffx output for multiple devices', () async {
final FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow();
final FakeFuchsiaSdk fuchsiaSdk = FakeFuchsiaSdk(devices:
'2001:0db8:85a3:0000:0000:8a2e:0370:7334 paper-pulp-bush-angel\n'
'2001:0db8:85a3:0000:0000:8a2e:0370:7335 foo-bar-fiz-buzz'
);
final FakeFuchsiaSdk fuchsiaSdk = FakeFuchsiaSdk(
devices:
'2001:0db8:85a3:0000:0000:8a2e:0370:7334 paper-pulp-bush-angel\n'
'2001:0db8:85a3:0000:0000:8a2e:0370:7335 foo-bar-fiz-buzz');
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
platform: FakePlatform(),
fuchsiaSdk: fuchsiaSdk,
@@ -138,7 +142,8 @@ void main() {
});
testWithoutContext('can parse junk output from ffx', () async {
final FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow(canListDevices: false);
final FakeFuchsiaWorkflow fuchsiaWorkflow =
FakeFuchsiaWorkflow(canListDevices: false);
final FakeFuchsiaSdk fuchsiaSdk = FakeFuchsiaSdk(devices: 'junk');
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
platform: FakePlatform(),
@@ -163,7 +168,8 @@ void main() {
testWithoutContext('default capabilities', () async {
final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
final FlutterProject project = FlutterProject.fromDirectoryTest(memoryFileSystem.currentDirectory);
final FlutterProject project =
FlutterProject.fromDirectoryTest(memoryFileSystem.currentDirectory);
memoryFileSystem.directory('fuchsia').createSync(recursive: true);
memoryFileSystem.file('pubspec.yaml').createSync();
@@ -181,7 +187,8 @@ void main() {
testWithoutContext('supported for project', () async {
final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
final FlutterProject project = FlutterProject.fromDirectoryTest(memoryFileSystem.currentDirectory);
final FlutterProject project =
FlutterProject.fromDirectoryTest(memoryFileSystem.currentDirectory);
memoryFileSystem.directory('fuchsia').createSync(recursive: true);
memoryFileSystem.file('pubspec.yaml').createSync();
@@ -190,13 +197,15 @@ void main() {
testWithoutContext('not supported for project', () async {
final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
final FlutterProject project = FlutterProject.fromDirectoryTest(memoryFileSystem.currentDirectory);
final FlutterProject project =
FlutterProject.fromDirectoryTest(memoryFileSystem.currentDirectory);
memoryFileSystem.file('pubspec.yaml').createSync();
expect(device.isSupportedForProject(project), false);
});
testUsingContext('targetPlatform does not throw when sshConfig is missing', () async {
testUsingContext('targetPlatform does not throw when sshConfig is missing',
() async {
final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
expect(await device.targetPlatform, TargetPlatform.fuchsia_arm64);
@@ -236,8 +245,15 @@ void main() {
testUsingContext('hostAddress parsing works', () async {
processManager.addCommand(const FakeCommand(
command: <String>['ssh', '-F', '/ssh_config', 'id', r'echo $SSH_CONNECTION'],
stdout: 'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
command: <String>[
'ssh',
'-F',
'/ssh_config',
'id',
r'echo $SSH_CONNECTION'
],
stdout:
'fe80::8c6c:2fff:fe3d:c5e1%ethp0003 50666 fe80::5054:ff:fe63:5e7a%ethp0003 22',
));
final FuchsiaDevice device = FuchsiaDevice('id', name: 'device');
@@ -248,9 +264,16 @@ void main() {
ProcessManager: () => processManager,
});
testUsingContext('hostAddress parsing throws tool error on failure', () async {
testUsingContext('hostAddress parsing throws tool error on failure',
() async {
processManager.addCommand(const FakeCommand(
command: <String>['ssh', '-F', '/ssh_config', 'id', r'echo $SSH_CONNECTION'],
command: <String>[
'ssh',
'-F',
'/ssh_config',
'id',
r'echo $SSH_CONNECTION'
],
exitCode: 1,
));
@@ -262,9 +285,16 @@ void main() {
ProcessManager: () => processManager,
});
testUsingContext('hostAddress parsing throws tool error on empty response', () async {
testUsingContext('hostAddress parsing throws tool error on empty response',
() async {
processManager.addCommand(const FakeCommand(
command: <String>['ssh', '-F', '/ssh_config', 'id', r'echo $SSH_CONNECTION'],
command: <String>[
'ssh',
'-F',
'/ssh_config',
'id',
r'echo $SSH_CONNECTION'
],
));
final FuchsiaDevice device = FuchsiaDevice('id', name: 'device');
@@ -287,28 +317,38 @@ void main() {
testUsingContext('No vmservices found', () async {
processManager.addCommand(const FakeCommand(
command: <String>['ssh', '-F', '/artifact', 'id', 'find /hub -name vmservice-port'],
command: <String>[
'ssh',
'-F',
'/artifact',
'id',
'find /hub -name vmservice-port'
],
));
final FuchsiaDevice device = FuchsiaDevice('id', name: 'device');
await expectLater(device.servicePorts, throwsToolExit(message: 'No Dart Observatories found. Are you running a debug build?'));
await expectLater(
device.servicePorts,
throwsToolExit(
message:
'No Dart Observatories found. Are you running a debug build?'));
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
FuchsiaArtifacts: () => FuchsiaArtifacts(
sshConfig: artifactFile,
ffx: artifactFile,
),
sshConfig: artifactFile,
ffx: artifactFile,
),
FuchsiaSdk: () => FakeFuchsiaSdk(),
});
group('device logs', () {
const String exampleUtcLogs = '''
[2018-11-09 01:27:45][3][297950920][log] INFO: example_app.cmx(flutter): Error doing thing
[2018-11-09 01:27:45][3][297950920][log] INFO: example_app.cm(flutter): Error doing thing
[2018-11-09 01:27:58][46257][46269][foo] INFO: Using a thing
[2018-11-09 01:29:58][46257][46269][foo] INFO: Blah blah blah
[2018-11-09 01:29:58][46257][46269][foo] INFO: other_app.cmx(flutter): Do thing
[2018-11-09 01:29:58][46257][46269][foo] INFO: other_app.cm(flutter): Do thing
[2018-11-09 01:30:02][41175][41187][bar] INFO: Invoking a bar
[2018-11-09 01:30:12][52580][52983][log] INFO: example_app.cmx(flutter): Did thing this time
[2018-11-09 01:30:12][52580][52983][log] INFO: example_app.cm(flutter): Did thing this time
''';
FakeProcessManager processManager;
@@ -316,21 +356,29 @@ void main() {
File sshConfig;
setUp(() {
processManager = FakeProcessManager.empty();
processManager = FakeProcessManager.empty();
final FileSystem memoryFileSystem = MemoryFileSystem.test();
ffx = memoryFileSystem.file('ffx')..writeAsStringSync('\n');
sshConfig = memoryFileSystem.file('ssh_config')..writeAsStringSync('\n');
sshConfig = memoryFileSystem.file('ssh_config')
..writeAsStringSync('\n');
});
testUsingContext('can be parsed for an app', () async {
final Completer<void> lock = Completer<void>();
processManager.addCommand(FakeCommand(
command: const <String>['ssh', '-F', '/ssh_config', 'id', 'log_listener --clock Local'],
command: const <String>[
'ssh',
'-F',
'/ssh_config',
'id',
'log_listener --clock Local'
],
stdout: exampleUtcLogs,
completer: lock,
));
final FuchsiaDevice device = FuchsiaDevice('id', name: 'tester');
final DeviceLogReader reader = device.getLogReader(app: FuchsiaModulePackage(name: 'example_app'));
final DeviceLogReader reader =
device.getLogReader(app: FuchsiaModulePackage(name: 'example_app'));
final List<String> logLines = <String>[];
reader.logLines.listen((String line) {
logLines.add(line);
@@ -355,12 +403,19 @@ void main() {
testUsingContext('cuts off prior logs', () async {
final Completer<void> lock = Completer<void>();
processManager.addCommand(FakeCommand(
command: const <String>['ssh', '-F', '/ssh_config', 'id', 'log_listener --clock Local'],
command: const <String>[
'ssh',
'-F',
'/ssh_config',
'id',
'log_listener --clock Local'
],
stdout: exampleUtcLogs,
completer: lock,
));
final FuchsiaDevice device = FuchsiaDevice('id', name: 'tester');
final DeviceLogReader reader = device.getLogReader(app: FuchsiaModulePackage(name: 'example_app'));
final DeviceLogReader reader =
device.getLogReader(app: FuchsiaModulePackage(name: 'example_app'));
final List<String> logLines = <String>[];
reader.logLines.listen((String line) {
logLines.add(line);
@@ -376,13 +431,20 @@ void main() {
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
SystemClock: () => SystemClock.fixed(DateTime(2018, 11, 9, 1, 29, 45)),
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig, ffx: ffx),
FuchsiaArtifacts: () =>
FuchsiaArtifacts(sshConfig: sshConfig, ffx: ffx),
});
testUsingContext('can be parsed for all apps', () async {
final Completer<void> lock = Completer<void>();
processManager.addCommand(FakeCommand(
command: const <String>['ssh', '-F', '/ssh_config', 'id', 'log_listener --clock Local'],
command: const <String>[
'ssh',
'-F',
'/ssh_config',
'id',
'log_listener --clock Local'
],
stdout: exampleUtcLogs,
completer: lock,
));
@@ -407,7 +469,8 @@ void main() {
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
SystemClock: () => SystemClock.fixed(DateTime(2018, 11, 9, 1, 25, 45)),
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig, ffx: ffx),
FuchsiaArtifacts: () =>
FuchsiaArtifacts(sshConfig: sshConfig, ffx: ffx),
});
});
});
@@ -432,8 +495,8 @@ void main() {
expect(device.supportsScreenshot, false);
}, overrides: <Type, Generator>{
Platform: () => FakePlatform(
operatingSystem: 'windows',
),
operatingSystem: 'windows',
),
});
test("takeScreenshot throws if file isn't .ppm", () async {
@@ -441,43 +504,38 @@ void main() {
await expectLater(
() => device.takeScreenshot(globals.fs.file('file.invalid')),
throwsA(isA<Exception>().having(
(Exception exception) => exception.toString(),
'message',
contains('file.invalid must be a .ppm file')
)),
(Exception exception) => exception.toString(),
'message',
contains('file.invalid must be a .ppm file'))),
);
});
testUsingContext('takeScreenshot throws if screencap failed', () async {
processManager.addCommand(const FakeCommand(
command: <String>[
'ssh',
'-F',
'/fuchsia/out/default/.ssh',
'0.0.0.0',
'screencap > /tmp/screenshot.ppm',
],
exitCode: 1,
stderr: '<error-message>'
));
processManager.addCommand(const FakeCommand(command: <String>[
'ssh',
'-F',
'/fuchsia/out/default/.ssh',
'0.0.0.0',
'screencap > /tmp/screenshot.ppm',
], exitCode: 1, stderr: '<error-message>'));
final FuchsiaDevice device = FuchsiaDevice('0.0.0.0', name: 'tester');
await expectLater(
() => device.takeScreenshot(globals.fs.file('file.ppm')),
throwsA(isA<Exception>().having(
(Exception exception) => exception.toString(),
'message',
contains('Could not take a screenshot on device tester:\n<error-message>')
)),
(Exception exception) => exception.toString(),
'message',
contains(
'Could not take a screenshot on device tester:\n<error-message>'))),
);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
FileSystem: () => MemoryFileSystem.test(),
Platform: () => FakePlatform(
environment: <String, String>{
'FUCHSIA_SSH_CONFIG': '/fuchsia/out/default/.ssh',
},
),
environment: <String, String>{
'FUCHSIA_SSH_CONFIG': '/fuchsia/out/default/.ssh',
},
),
});
testUsingContext('takeScreenshot throws if scp failed', () async {
@@ -515,22 +573,24 @@ void main() {
await expectLater(
() => device.takeScreenshot(globals.fs.file('file.ppm')),
throwsA(isA<Exception>().having(
(Exception exception) => exception.toString(),
'message',
contains('Failed to copy screenshot from device:\n<error-message>')
)),
(Exception exception) => exception.toString(),
'message',
contains(
'Failed to copy screenshot from device:\n<error-message>'))),
);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
FileSystem: () => MemoryFileSystem.test(),
Platform: () => FakePlatform(
environment: <String, String>{
'FUCHSIA_SSH_CONFIG': '/fuchsia/out/default/.ssh',
},
),
environment: <String, String>{
'FUCHSIA_SSH_CONFIG': '/fuchsia/out/default/.ssh',
},
),
});
testUsingContext("takeScreenshot prints error if can't delete file from device", () async {
testUsingContext(
"takeScreenshot prints error if can't delete file from device",
() async {
final FuchsiaDevice device = FuchsiaDevice('0.0.0.0', name: 'tester');
processManager.addCommand(const FakeCommand(
command: <String>[
@@ -565,16 +625,17 @@ void main() {
await device.takeScreenshot(globals.fs.file('file.ppm'));
expect(
testLogger.errorText,
contains('Failed to delete screenshot.ppm from the device:\n<error-message>'),
contains(
'Failed to delete screenshot.ppm from the device:\n<error-message>'),
);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
FileSystem: () => MemoryFileSystem.test(),
Platform: () => FakePlatform(
environment: <String, String>{
'FUCHSIA_SSH_CONFIG': '/fuchsia/out/default/.ssh',
},
),
environment: <String, String>{
'FUCHSIA_SSH_CONFIG': '/fuchsia/out/default/.ssh',
},
),
}, testOn: 'posix');
testUsingContext('takeScreenshot returns', () async {
@@ -607,15 +668,16 @@ void main() {
],
));
expect(() => device.takeScreenshot(globals.fs.file('file.ppm')), returnsNormally);
expect(() => device.takeScreenshot(globals.fs.file('file.ppm')),
returnsNormally);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
FileSystem: () => MemoryFileSystem.test(),
Platform: () => FakePlatform(
environment: <String, String>{
'FUCHSIA_SSH_CONFIG': '/fuchsia/out/default/.ssh',
},
),
environment: <String, String>{
'FUCHSIA_SSH_CONFIG': '/fuchsia/out/default/.ssh',
},
),
});
});
@@ -625,21 +687,36 @@ void main() {
setUp(() {
processManager = FakeProcessManager.empty();
sshConfig = MemoryFileSystem.test().file('irrelevant')..writeAsStringSync('\n');
sshConfig = MemoryFileSystem.test().file('irrelevant')
..writeAsStringSync('\n');
});
testUsingContext('`unforward` prints stdout and stderr if ssh command failed', () async {
testUsingContext(
'`unforward` prints stdout and stderr if ssh command failed', () async {
final FuchsiaDevice device = FuchsiaDevice('id', name: 'tester');
processManager.addCommand(const FakeCommand(
command: <String>['ssh', '-F', '/irrelevant', '-O', 'cancel', '-vvv', '-L', '0:127.0.0.1:1', 'id'],
command: <String>[
'ssh',
'-F',
'/irrelevant',
'-O',
'cancel',
'-vvv',
'-L',
'0:127.0.0.1:1',
'id'
],
exitCode: 1,
stdout: '<stdout>',
stderr: '<stderr>',
));
await expectLater(
() => device.portForwarder.unforward(ForwardedPort(/*hostPort=*/ 0, /*devicePort=*/ 1)),
throwsToolExit(message: 'Unforward command failed:\nstdout: <stdout>\nstderr: <stderr>'),
() => device.portForwarder
.unforward(ForwardedPort(/*hostPort=*/ 0, /*devicePort=*/ 1)),
throwsToolExit(
message:
'Unforward command failed:\nstdout: <stdout>\nstderr: <stderr>'),
);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
@@ -647,26 +724,26 @@ void main() {
});
});
group('FuchsiaIsolateDiscoveryProtocol', () {
Future<Uri> findUri(List<FlutterView> views, String expectedIsolateName) async {
Future<Uri> findUri(
List<FlutterView> views, String expectedIsolateName) async {
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
requests: <VmServiceExpectation>[
FakeVmServiceRequest(
method: kListViewsMethod,
jsonResponse: <String, Object>{
'views': <Object>[
for (FlutterView view in views)
view.toJson(),
for (FlutterView view in views) view.toJson(),
],
},
),
],
httpAddress: Uri.parse('example'),
);
final MockFuchsiaDevice fuchsiaDevice = MockFuchsiaDevice('123', const NoOpDevicePortForwarder(), false);
final MockFuchsiaDevice fuchsiaDevice =
MockFuchsiaDevice('123', const NoOpDevicePortForwarder(), false);
final FuchsiaIsolateDiscoveryProtocol discoveryProtocol =
FuchsiaIsolateDiscoveryProtocol(
FuchsiaIsolateDiscoveryProtocol(
fuchsiaDevice,
expectedIsolateName,
(Uri uri) async => fakeVmServiceHost.vmService,
@@ -676,7 +753,8 @@ void main() {
return discoveryProtocol.uri;
}
testUsingContext('can find flutter view with matching isolate name', () async {
testUsingContext('can find flutter view with matching isolate name',
() async {
const String expectedIsolateName = 'foobar';
final Uri uri = await findUri(<FlutterView>[
// no ui isolate.
@@ -693,25 +771,29 @@ void main() {
FlutterView(
id: '3',
uiIsolate: vm_service.Isolate.parse(<String, dynamic>{
...fakeIsolate.toJson(),
...fakeIsolate.toJson(),
'name': expectedIsolateName,
}),
),
], expectedIsolateName);
expect(uri.toString(), 'http://${InternetAddress.loopbackIPv4.address}:0/');
expect(
uri.toString(), 'http://${InternetAddress.loopbackIPv4.address}:0/');
});
testUsingContext('can handle flutter view without matching isolate name', () async {
testUsingContext('can handle flutter view without matching isolate name',
() async {
const String expectedIsolateName = 'foobar';
final Future<Uri> uri = findUri(<FlutterView>[
// no ui isolate.
FlutterView(id: '1', uiIsolate: fakeIsolate),
// wrong name.
FlutterView(id: '2', uiIsolate: vm_service.Isolate.parse(<String, Object>{
...fakeIsolate.toJson(),
'name': 'wrong name',
})),
FlutterView(
id: '2',
uiIsolate: vm_service.Isolate.parse(<String, Object>{
...fakeIsolate.toJson(),
'name': 'wrong name',
})),
], expectedIsolateName);
expect(uri, throwsException);
@@ -738,28 +820,32 @@ void main() {
platform: FakePlatform(),
operatingSystemUtils: globals.os,
);
expect(artifacts.getArtifactPath(
expect(
artifacts.getArtifactPath(
Artifact.fuchsiaFlutterRunner,
platform: TargetPlatform.fuchsia_x64,
mode: BuildMode.debug,
),
contains('flutter_jit_runner'),
);
expect(artifacts.getArtifactPath(
expect(
artifacts.getArtifactPath(
Artifact.fuchsiaFlutterRunner,
platform: TargetPlatform.fuchsia_x64,
mode: BuildMode.profile,
),
contains('flutter_aot_runner'),
);
expect(artifacts.getArtifactPath(
expect(
artifacts.getArtifactPath(
Artifact.fuchsiaFlutterRunner,
platform: TargetPlatform.fuchsia_x64,
mode: BuildMode.release,
),
contains('flutter_aot_product_runner'),
);
expect(artifacts.getArtifactPath(
expect(
artifacts.getArtifactPath(
Artifact.fuchsiaFlutterRunner,
platform: TargetPlatform.fuchsia_x64,
mode: BuildMode.jitRelease,
@@ -773,7 +859,8 @@ void main() {
FakeProcessManager processManager;
setUp(() {
sshConfig = MemoryFileSystem.test().file('ssh_config')..writeAsStringSync('\n');
sshConfig = MemoryFileSystem.test().file('ssh_config')
..writeAsStringSync('\n');
processManager = FakeProcessManager.empty();
});
@@ -787,11 +874,15 @@ void main() {
FuchsiaSdk: () => FakeFuchsiaSdk(),
});
testUsingContext('returns what we get from the device on success', () async {
processManager.addCommand(const FakeCommand(
command: <String>['ssh', '-F', '/ssh_config', '123', 'cat /pkgfs/packages/build-info/0/data/version'],
stdout: 'version'
));
testUsingContext('returns what we get from the device on success',
() async {
processManager.addCommand(const FakeCommand(command: <String>[
'ssh',
'-F',
'/ssh_config',
'123',
'cat /pkgfs/packages/build-info/0/data/version'
], stdout: 'version'));
final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
expect(await device.sdkNameAndVersion, equals('Fuchsia version'));
@@ -803,7 +894,13 @@ void main() {
testUsingContext('returns "Fuchsia" when device command fails', () async {
processManager.addCommand(const FakeCommand(
command: <String>['ssh', '-F', '/ssh_config', '123', 'cat /pkgfs/packages/build-info/0/data/version'],
command: <String>[
'ssh',
'-F',
'/ssh_config',
'123',
'cat /pkgfs/packages/build-info/0/data/version'
],
exitCode: 1,
));
final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
@@ -815,9 +912,16 @@ void main() {
FuchsiaSdk: () => FakeFuchsiaSdk(),
});
testUsingContext('returns "Fuchsia" when device gives an empty result', () async {
testUsingContext('returns "Fuchsia" when device gives an empty result',
() async {
processManager.addCommand(const FakeCommand(
command: <String>['ssh', '-F', '/ssh_config', '123', 'cat /pkgfs/packages/build-info/0/data/version'],
command: <String>[
'ssh',
'-F',
'/ssh_config',
'123',
'cat /pkgfs/packages/build-info/0/data/version'
],
));
final FuchsiaDevice device = FuchsiaDevice('123', name: 'device');
@@ -855,7 +959,8 @@ class MockFuchsiaDevice extends Fake implements FuchsiaDevice {
final DevicePortForwarder portForwarder;
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.fuchsia_arm64;
Future<TargetPlatform> get targetPlatform async =>
TargetPlatform.fuchsia_arm64;
@override
String get name => 'fuchsia';
@@ -886,6 +991,16 @@ class FakeFuchsiaFfx implements FuchsiaFfx {
Future<String> resolve(String deviceName) async {
return '192.168.42.10';
}
@override
Future<String> sessionShow() async {
return null;
}
@override
Future<bool> sessionAdd(String url) async {
return false;
}
}
class FakeFuchsiaSdk extends Fake implements FuchsiaSdk {
@@ -894,10 +1009,10 @@ class FakeFuchsiaSdk extends Fake implements FuchsiaSdk {
FuchsiaKernelCompiler compiler,
FuchsiaFfx ffx,
String devices,
}) : fuchsiaPM = pm,
fuchsiaKernelCompiler = compiler,
fuchsiaFfx = ffx ?? FakeFuchsiaFfx(),
_devices = devices;
}) : fuchsiaPM = pm,
fuchsiaKernelCompiler = compiler,
fuchsiaFfx = ffx ?? FakeFuchsiaFfx(),
_devices = devices;
@override
final FuchsiaPM fuchsiaPM;
@@ -916,7 +1031,8 @@ class FakeFuchsiaSdk extends Fake implements FuchsiaSdk {
}
}
class FakeDartDevelopmentService extends Fake implements DartDevelopmentService {
class FakeDartDevelopmentService extends Fake
implements DartDevelopmentService {
@override
Future<void> startDartDevelopmentService(
Uri observatoryUri, {

View File

@@ -43,14 +43,14 @@ void main() {
]);
const String expected = '\n'
'┌────────────────────────────────────────────────────────────────────────────┐\n'
'│ General Info │\n'
'│ [✓] App Name: flutter_gallery │\n'
'│ [✓] Supported Platforms: android, ios, web, macos, linux, windows, fuchsia │\n'
'│ [✓] Is Flutter Package: yes │\n'
'│ [✓] Uses Material Design: yes │\n'
'│ [✓] Is Plugin: no │\n'
'└────────────────────────────────────────────────────────────────────────────┘\n';
'┌───────────────────────────────────────────────────────────────────┐\n'
'│ General Info │\n'
'│ [✓] App Name: flutter_gallery │\n'
'│ [✓] Supported Platforms: android, ios, web, macos, linux, windows │\n'
'│ [✓] Is Flutter Package: yes │\n'
'│ [✓] Uses Material Design: yes │\n'
'│ [✓] Is Plugin: no │\n'
'└───────────────────────────────────────────────────────────────────┘\n';
expect(loggerTest.statusText, contains(expected));
});

View File

@@ -252,9 +252,6 @@ class FakeStdin extends Fake implements Stdin {
@override
bool echoMode = true;
@override
bool echoNewlineMode = true;
@override
bool lineMode = true;