[fuchsia] - migrate devicer discovery workflows to use ffx (#76241)

This commit is contained in:
omerlevran46
2021-03-01 13:16:13 -08:00
committed by GitHub
parent 54455c706d
commit f996033fcc
12 changed files with 483 additions and 54 deletions

View File

@@ -25,6 +25,7 @@ import 'package:flutter_tools/src/fuchsia/amber_ctl.dart';
import 'package:flutter_tools/src/fuchsia/application_package.dart';
import 'package:flutter_tools/src/fuchsia/fuchsia_dev_finder.dart';
import 'package:flutter_tools/src/fuchsia/fuchsia_device.dart';
import 'package:flutter_tools/src/fuchsia/fuchsia_ffx.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';
@@ -103,17 +104,18 @@ void main() {
expect(await fuchsiaDevices.pollingGetDevices(), isEmpty);
});
testWithoutContext('can parse device-finder output for single device', () async {
testWithoutContext('can parse ffx output for single device', () async {
final MockFuchsiaWorkflow fuchsiaWorkflow = MockFuchsiaWorkflow();
final MockFuchsiaSdk fuchsiaSdk = MockFuchsiaSdk();
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
platform: FakePlatform(operatingSystem: 'linux'),
platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{},),
fuchsiaSdk: fuchsiaSdk,
fuchsiaWorkflow: fuchsiaWorkflow,
logger: BufferLogger.test(),
);
when(fuchsiaWorkflow.shouldUseDeviceFinder).thenReturn(false);
when(fuchsiaWorkflow.canListDevices).thenReturn(true);
when(fuchsiaSdk.listDevices()).thenAnswer((Invocation invocation) async {
when(fuchsiaSdk.listDevices(useDeviceFinder: false)).thenAnswer((Invocation invocation) async {
return '2001:0db8:85a3:0000:0000:8a2e:0370:7334 paper-pulp-bush-angel';
});
@@ -123,7 +125,28 @@ void main() {
expect(device.id, '192.168.42.10');
});
testWithoutContext('can parse device-finder output for multiple devices', () async {
testWithoutContext('can parse device-finder output for single device', () async {
final MockFuchsiaWorkflow fuchsiaWorkflow = MockFuchsiaWorkflow();
final MockFuchsiaSdk fuchsiaSdk = MockFuchsiaSdk();
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{'FUCHSIA_DISABLED_ffx_discovery': '1'},),
fuchsiaSdk: fuchsiaSdk,
fuchsiaWorkflow: fuchsiaWorkflow,
logger: BufferLogger.test(),
);
when(fuchsiaWorkflow.shouldUseDeviceFinder).thenReturn(true);
when(fuchsiaWorkflow.canListDevices).thenReturn(true);
when(fuchsiaSdk.listDevices(useDeviceFinder: true)).thenAnswer((Invocation invocation) async {
return '2001:0db8:85a3:0000:0000:8a2e:0370:7334 paper-pulp-bush-angel';
});
final Device device = (await fuchsiaDevices.pollingGetDevices()).single;
expect(device.name, 'paper-pulp-bush-angel');
expect(device.id, '192.168.11.999');
});
testWithoutContext('can parse ffx output for multiple devices', () async {
final MockFuchsiaWorkflow fuchsiaWorkflow = MockFuchsiaWorkflow();
final MockFuchsiaSdk fuchsiaSdk = MockFuchsiaSdk();
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
@@ -132,8 +155,9 @@ void main() {
fuchsiaWorkflow: fuchsiaWorkflow,
logger: BufferLogger.test(),
);
when(fuchsiaWorkflow.shouldUseDeviceFinder).thenReturn(false);
when(fuchsiaWorkflow.canListDevices).thenReturn(true);
when(fuchsiaSdk.listDevices()).thenAnswer((Invocation invocation) async {
when(fuchsiaSdk.listDevices(useDeviceFinder: false)).thenAnswer((Invocation invocation) async {
return '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';
});
@@ -146,7 +170,7 @@ void main() {
expect(devices.last.id, '192.168.42.10');
});
testWithoutContext('can parse junk output from the dev-finder', () async {
testWithoutContext('can parse device-finder output for multiple devices', () async {
final MockFuchsiaWorkflow fuchsiaWorkflow = MockFuchsiaWorkflow();
final MockFuchsiaSdk fuchsiaSdk = MockFuchsiaSdk();
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
@@ -155,6 +179,31 @@ void main() {
fuchsiaWorkflow: fuchsiaWorkflow,
logger: BufferLogger.test(),
);
when(fuchsiaWorkflow.shouldUseDeviceFinder).thenReturn(true);
when(fuchsiaWorkflow.canListDevices).thenReturn(true);
when(fuchsiaSdk.listDevices(useDeviceFinder: true)).thenAnswer((Invocation invocation) async {
return '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 List<Device> devices = await fuchsiaDevices.pollingGetDevices();
expect(devices.first.name, 'paper-pulp-bush-angel');
expect(devices.first.id, '192.168.11.999');
expect(devices.last.name, 'foo-bar-fiz-buzz');
expect(devices.last.id, '192.168.11.999');
});
testWithoutContext('can parse junk output from ffx', () async {
final MockFuchsiaWorkflow fuchsiaWorkflow = MockFuchsiaWorkflow();
final MockFuchsiaSdk fuchsiaSdk = MockFuchsiaSdk();
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
platform: FakePlatform(operatingSystem: 'linux'),
fuchsiaSdk: fuchsiaSdk,
fuchsiaWorkflow: fuchsiaWorkflow,
logger: BufferLogger.test(),
);
when(fuchsiaWorkflow.shouldUseDeviceFinder).thenReturn(false);
when(fuchsiaWorkflow.canListDevices).thenReturn(true);
when(fuchsiaSdk.listDevices()).thenAnswer((Invocation invocation) async {
return 'junk';
@@ -165,6 +214,26 @@ void main() {
expect(devices, isEmpty);
});
testWithoutContext('can parse junk output from device-finder', () async {
final MockFuchsiaWorkflow fuchsiaWorkflow = MockFuchsiaWorkflow();
final MockFuchsiaSdk fuchsiaSdk = MockFuchsiaSdk();
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
platform: FakePlatform(operatingSystem: 'linux'),
fuchsiaSdk: fuchsiaSdk,
fuchsiaWorkflow: fuchsiaWorkflow,
logger: BufferLogger.test(),
);
when(fuchsiaWorkflow.shouldUseDeviceFinder).thenReturn(true);
when(fuchsiaWorkflow.canListDevices).thenReturn(true);
when(fuchsiaSdk.listDevices(useDeviceFinder: true)).thenAnswer((Invocation invocation) async {
return 'junk';
});
final List<Device> devices = await fuchsiaDevices.pollingGetDevices();
expect(devices, isEmpty);
});
testUsingContext('disposing device disposes the portForwarder', () async {
final MockPortForwarder mockPortForwarder = MockPortForwarder();
final FuchsiaDevice device = FuchsiaDevice('123');
@@ -335,6 +404,7 @@ void main() {
FuchsiaArtifacts: () => FuchsiaArtifacts(
sshConfig: artifactFile,
devFinder: artifactFile,
ffx: artifactFile,
),
FuchsiaSdk: () => MockFuchsiaSdk(),
});
@@ -355,6 +425,7 @@ void main() {
StreamController<List<int>> stdout;
StreamController<List<int>> stderr;
File devFinder;
File ffx;
File sshConfig;
setUp(() {
@@ -370,6 +441,7 @@ void main() {
when(mockProcess.stderr).thenAnswer((Invocation _) => stderr.stream);
final FileSystem memoryFileSystem = MemoryFileSystem.test();
devFinder = memoryFileSystem.file('device-finder')..writeAsStringSync('\n');
ffx = memoryFileSystem.file('ffx')..writeAsStringSync('\n');
sshConfig = memoryFileSystem.file('ssh_config')..writeAsStringSync('\n');
});
@@ -403,7 +475,7 @@ void main() {
ProcessManager: () => mockProcessManager,
SystemClock: () => SystemClock.fixed(DateTime(2018, 11, 9, 1, 25, 45)),
FuchsiaArtifacts: () =>
FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig),
FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: ffx),
});
testUsingContext('cuts off prior logs', () async {
@@ -429,7 +501,7 @@ void main() {
ProcessManager: () => mockProcessManager,
SystemClock: () => SystemClock.fixed(DateTime(2018, 11, 9, 1, 29, 45)),
FuchsiaArtifacts: () =>
FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig),
FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: ffx),
});
testUsingContext('can be parsed for all apps', () async {
@@ -458,7 +530,7 @@ void main() {
ProcessManager: () => mockProcessManager,
SystemClock: () => SystemClock.fixed(DateTime(2018, 11, 9, 1, 25, 45)),
FuchsiaArtifacts: () =>
FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig),
FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: ffx),
});
});
});
@@ -1577,7 +1649,19 @@ class FailingKernelCompiler implements FuchsiaKernelCompiler {
class FakeFuchsiaDevFinder implements FuchsiaDevFinder {
@override
Future<List<String>> list({ Duration timeout }) async {
return <String>['192.168.42.172 scare-cable-skip-joy'];
return <String>['192.168.11.999 scare-cable-device-finder'];
}
@override
Future<String> resolve(String deviceName) async {
return '192.168.11.999';
}
}
class FakeFuchsiaFfx implements FuchsiaFfx {
@override
Future<List<String>> list({Duration timeout}) async {
return <String>['192.168.42.172 scare-cable-skip-ffx'];
}
@override
@@ -1591,9 +1675,11 @@ class MockFuchsiaSdk extends Mock implements FuchsiaSdk {
FuchsiaPM pm,
FuchsiaKernelCompiler compiler,
FuchsiaDevFinder devFinder,
FuchsiaFfx ffx,
}) : fuchsiaPM = pm ?? FakeFuchsiaPM(),
fuchsiaKernelCompiler = compiler ?? FakeFuchsiaKernelCompiler(),
fuchsiaDevFinder = devFinder ?? FakeFuchsiaDevFinder();
fuchsiaDevFinder = devFinder ?? FakeFuchsiaDevFinder(),
fuchsiaFfx = ffx ?? FakeFuchsiaFfx();
@override
final FuchsiaPM fuchsiaPM;
@@ -1603,6 +1689,9 @@ class MockFuchsiaSdk extends Mock implements FuchsiaSdk {
@override
final FuchsiaDevFinder fuchsiaDevFinder;
@override
final FuchsiaFfx fuchsiaFfx;
}
class MockDartDevelopmentService extends Mock implements DartDevelopmentService {}

View File

@@ -0,0 +1,138 @@
// 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:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/fuchsia/fuchsia_ffx.dart';
import 'package:flutter_tools/src/fuchsia/fuchsia_sdk.dart';
import 'package:process/process.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/context.dart';
void main() {
FakeFuchsiaArtifacts fakeFuchsiaArtifacts;
BufferLogger logger;
MemoryFileSystem memoryFileSystem;
File ffx;
setUp(() {
fakeFuchsiaArtifacts = FakeFuchsiaArtifacts();
memoryFileSystem = MemoryFileSystem.test();
logger = BufferLogger.test();
ffx = memoryFileSystem.file('ffx');
fakeFuchsiaArtifacts.ffx = ffx;
});
group('ffx list', () {
testWithoutContext('ffx not found', () {
final FuchsiaFfx fuchsiaFfx = FuchsiaFfx(
fuchsiaArtifacts: fakeFuchsiaArtifacts,
logger: logger,
processManager: FakeProcessManager.any(),
);
expect(() async => await fuchsiaFfx.list(),
throwsToolExit(message: 'Fuchsia ffx tool not found.'));
});
testWithoutContext('no device found', () async {
ffx.createSync();
final ProcessManager processManager =
FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[ffx.path, 'target', 'list', '--format', 's'],
exitCode: 0,
stderr: 'No devices found.',
),
]);
final FuchsiaFfx fuchsiaFfx = FuchsiaFfx(
fuchsiaArtifacts: fakeFuchsiaArtifacts,
logger: logger,
processManager: processManager,
);
expect(await fuchsiaFfx.list(), isNull);
expect(logger.errorText, isEmpty);
});
testWithoutContext('error', () async {
ffx.createSync();
final ProcessManager processManager =
FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[ffx.path, 'target', 'list', '--format', 's'],
exitCode: 1,
stderr: 'unexpected error',
),
]);
final FuchsiaFfx fuchsiaFfx = FuchsiaFfx(
fuchsiaArtifacts: fakeFuchsiaArtifacts,
logger: logger,
processManager: processManager,
);
expect(await fuchsiaFfx.list(), isNull);
expect(logger.errorText, contains('unexpected error'));
});
testWithoutContext('devices found', () async {
ffx.createSync();
final ProcessManager processManager =
FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[ffx.path, 'target', 'list', '--format', 's'],
exitCode: 0,
stdout: 'device1\ndevice2',
),
]);
final FuchsiaFfx fuchsiaFfx = FuchsiaFfx(
fuchsiaArtifacts: fakeFuchsiaArtifacts,
logger: logger,
processManager: processManager,
);
expect(await fuchsiaFfx.list(), <String>['device1', 'device2']);
expect(logger.errorText, isEmpty);
});
testWithoutContext('timeout', () async {
ffx.createSync();
final ProcessManager processManager =
FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[ffx.path, '-T', '2', 'target', 'list', '--format', 's'],
exitCode: 0,
stdout: 'device1',
),
]);
final FuchsiaFfx fuchsiaFfx = FuchsiaFfx(
fuchsiaArtifacts: fakeFuchsiaArtifacts,
logger: logger,
processManager: processManager,
);
expect(await fuchsiaFfx.list(timeout: const Duration(seconds: 2)),
<String>['device1']);
});
});
}
class FakeFuchsiaArtifacts extends Fake implements FuchsiaArtifacts {
@override
File ffx;
}

View File

@@ -17,6 +17,7 @@ void main() {
final FileSystem fileSystem = MemoryFileSystem.test();
final File devFinder = fileSystem.file('dev_finder');
final File sshConfig = fileSystem.file('ssh_config');
final File ffx = fileSystem.file('ffx');
testWithoutContext('Fuchsia workflow does not apply to host platform if feature is disabled', () {
final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
@@ -38,11 +39,11 @@ void main() {
expect(fuchsiaWorkflow.appliesToHostPlatform, false);
});
testWithoutContext('Fuchsia workflow can not list and launch devices if there is no ssh config and dev finder', () {
testWithoutContext('Fuchsia workflow can not list and launch devices if there is no ffx when using default workflow', () {
final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
featureFlags: TestFeatureFlags(),
fuchsiaArtifacts: FuchsiaArtifacts(devFinder: null, sshConfig: null),
platform: FakePlatform(operatingSystem: 'linux'),
fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: null),
platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{}),
);
expect(fuchsiaWorkflow.canLaunchDevices, false);
@@ -50,11 +51,23 @@ void main() {
expect(fuchsiaWorkflow.canListEmulators, false);
});
testWithoutContext('Fuchsia workflow can not list and launch devices if there is no ssh config and dev finder', () {
testWithoutContext('Fuchsia workflow can not list and launch devices if there is no dev finder when ffx is disabled', () {
final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
featureFlags: TestFeatureFlags(),
fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: null),
platform: FakePlatform(operatingSystem: 'linux'),
fuchsiaArtifacts: FuchsiaArtifacts(devFinder: null, sshConfig: sshConfig, ffx: ffx),
platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{'FUCHSIA_DISABLED_ffx_discovery': '1'}),
);
expect(fuchsiaWorkflow.canLaunchDevices, false);
expect(fuchsiaWorkflow.canListDevices, false);
expect(fuchsiaWorkflow.canListEmulators, false);
});
testWithoutContext('Fuchsia workflow can not launch devices if there is no ssh config when using default workflow', () {
final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
featureFlags: TestFeatureFlags(),
fuchsiaArtifacts: FuchsiaArtifacts(sshConfig: null, ffx: ffx),
platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{}),
);
expect(fuchsiaWorkflow.canLaunchDevices, false);
@@ -62,11 +75,35 @@ void main() {
expect(fuchsiaWorkflow.canListEmulators, false);
});
testWithoutContext('Fuchsia workflow can list and launch devices supported with sufficient SDK artifacts', () {
testWithoutContext('Fuchsia workflow can not launch devices if there is no ssh config when ffx is disabled', () {
final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
featureFlags: TestFeatureFlags(),
fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig),
platform: FakePlatform(operatingSystem: 'linux'),
fuchsiaArtifacts: FuchsiaArtifacts(sshConfig: null, devFinder: devFinder),
platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{'FUCHSIA_DISABLED_ffx_discovery': '1'}),
);
expect(fuchsiaWorkflow.canLaunchDevices, false);
expect(fuchsiaWorkflow.canListDevices, true);
expect(fuchsiaWorkflow.canListEmulators, false);
});
testWithoutContext('Fuchsia workflow can list and launch devices supported with sufficient SDK artifacts when using default workflow', () {
final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
featureFlags: TestFeatureFlags(),
fuchsiaArtifacts: FuchsiaArtifacts(devFinder: null, sshConfig: sshConfig, ffx: ffx),
platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{}),
);
expect(fuchsiaWorkflow.canLaunchDevices, true);
expect(fuchsiaWorkflow.canListDevices, true);
expect(fuchsiaWorkflow.canListEmulators, false);
});
testWithoutContext('Fuchsia workflow can list and launch devices supported with sufficient SDK artifacts when ffx is disabled', () {
final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
featureFlags: TestFeatureFlags(),
fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: null),
platform: FakePlatform(operatingSystem: 'linux', environment: <String, String>{'FUCHSIA_DISABLED_ffx_discovery': '1'}),
);
expect(fuchsiaWorkflow.canLaunchDevices, true);
@@ -77,8 +114,8 @@ void main() {
testWithoutContext('Fuchsia workflow can list and launch devices supported with sufficient SDK artifacts on macOS', () {
final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
featureFlags: TestFeatureFlags(),
fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig),
platform: FakePlatform(operatingSystem: 'macOS'),
fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: ffx),
platform: FakePlatform(operatingSystem: 'macOS', environment: <String, String>{}),
);
expect(fuchsiaWorkflow.canLaunchDevices, true);