[fuchsia] - remove device-finder for device discovery (#91502)

device-finder binary is being from removed from the Fuchsia SDK
in fxb/85985.
This commit is contained in:
omerlevran46
2021-10-13 16:04:27 -04:00
committed by GitHub
parent 92dd9d2358
commit 4b1b65118e
10 changed files with 23 additions and 438 deletions

View File

@@ -1,134 +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.
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_dev_finder.dart';
import 'package:flutter_tools/src/fuchsia/fuchsia_sdk.dart';
import 'package:test/fake.dart';
import '../../src/common.dart';
import '../../src/fake_process_manager.dart';
void main() {
late FakeFuchsiaArtifacts fuchsiaArtifacts;
late BufferLogger logger;
late MemoryFileSystem memoryFileSystem;
late File deviceFinder;
setUp(() {
fuchsiaArtifacts = FakeFuchsiaArtifacts();
memoryFileSystem = MemoryFileSystem.test();
logger = BufferLogger.test();
deviceFinder = memoryFileSystem.file('device-finder');
fuchsiaArtifacts.devFinder = deviceFinder;
});
group('device-finder list', () {
testWithoutContext('device-finder not found', () {
final FuchsiaDevFinder fuchsiaDevFinder = FuchsiaDevFinder(
fuchsiaArtifacts: fuchsiaArtifacts,
logger: logger,
processManager: FakeProcessManager.any(),
);
expect(() async => fuchsiaDevFinder.list(),
throwsToolExit(message: 'Fuchsia device-finder tool not found.'));
});
testWithoutContext('no devices', () async {
deviceFinder.createSync();
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[ deviceFinder.path, 'list', '-full' ],
exitCode: 1,
stderr: 'list.go:72: no devices found',
),
]);
final FuchsiaDevFinder fuchsiaDevFinder = FuchsiaDevFinder(
fuchsiaArtifacts: fuchsiaArtifacts,
logger: logger,
processManager: processManager,
);
expect(await fuchsiaDevFinder.list(), isNull);
expect(logger.errorText, isEmpty);
});
testWithoutContext('error', () async {
deviceFinder.createSync();
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[ deviceFinder.path, 'list', '-full' ],
exitCode: 1,
stderr: 'unexpected error',
),
]);
final FuchsiaDevFinder fuchsiaDevFinder = FuchsiaDevFinder(
fuchsiaArtifacts: fuchsiaArtifacts,
logger: logger,
processManager: processManager,
);
expect(await fuchsiaDevFinder.list(), isNull);
expect(logger.errorText, contains('unexpected error'));
});
testWithoutContext('devices found', () async {
deviceFinder.createSync();
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[ deviceFinder.path, 'list', '-full' ],
stdout: 'device1\ndevice2',
),
]);
final FuchsiaDevFinder fuchsiaDevFinder = FuchsiaDevFinder(
fuchsiaArtifacts: fuchsiaArtifacts,
logger: logger,
processManager: processManager,
);
expect(await fuchsiaDevFinder.list(), <String>['device1', 'device2']);
expect(logger.errorText, isEmpty);
});
testWithoutContext('timeout', () async {
deviceFinder.createSync();
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[
deviceFinder.path,
'list',
'-full',
'-timeout',
'2000ms',
],
stdout: 'device1',
),
]);
final FuchsiaDevFinder fuchsiaDevFinder = FuchsiaDevFinder(
fuchsiaArtifacts: fuchsiaArtifacts,
logger: logger,
processManager: processManager,
);
expect(await fuchsiaDevFinder.list(timeout: const Duration(seconds: 2)), <String>['device1']);
});
});
}
class FakeFuchsiaArtifacts extends Fake implements FuchsiaArtifacts {
@override
File? devFinder;
}

View File

@@ -17,7 +17,6 @@ import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/device.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';
@@ -746,18 +745,6 @@ class FailingKernelCompiler implements FuchsiaKernelCompiler {
}
}
class FakeFuchsiaDevFinder implements FuchsiaDevFinder {
@override
Future<List<String>> list({ Duration timeout }) async {
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 {
@@ -774,11 +761,9 @@ class FakeFuchsiaSdk extends Fake implements FuchsiaSdk {
FakeFuchsiaSdk({
FuchsiaPM pm,
FuchsiaKernelCompiler compiler,
FuchsiaDevFinder devFinder,
FuchsiaFfx ffx,
}) : fuchsiaPM = pm ?? FakeFuchsiaPM(),
fuchsiaKernelCompiler = compiler ?? FakeFuchsiaKernelCompiler(),
fuchsiaDevFinder = devFinder ?? FakeFuchsiaDevFinder(),
fuchsiaFfx = ffx ?? FakeFuchsiaFfx();
@override
@@ -787,9 +772,6 @@ class FakeFuchsiaSdk extends Fake implements FuchsiaSdk {
@override
final FuchsiaKernelCompiler fuchsiaKernelCompiler;
@override
final FuchsiaDevFinder fuchsiaDevFinder;
@override
final FuchsiaFfx fuchsiaFfx;
}

View File

@@ -19,7 +19,6 @@ import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/device_port_forwarder.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';
@@ -102,7 +101,7 @@ void main() {
});
testWithoutContext('can parse ffx output for single device', () async {
final FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow(shouldUseDeviceFinder: false);
final FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow();
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>{}),
@@ -117,24 +116,8 @@ void main() {
expect(device.id, '192.168.42.10');
});
testWithoutContext('can parse device-finder output for single device', () async {
final FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow();
final FakeFuchsiaSdk fuchsiaSdk = FakeFuchsiaSdk(devFinderDevices: '2001:0db8:85a3:0000:0000:8a2e:0370:7334 paper-pulp-bush-angel');
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
platform: FakePlatform(environment: <String, String>{'FUCHSIA_DISABLED_ffx_discovery': '1'}),
fuchsiaSdk: fuchsiaSdk,
fuchsiaWorkflow: fuchsiaWorkflow,
logger: BufferLogger.test(),
);
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 FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow(shouldUseDeviceFinder: false);
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'
@@ -154,45 +137,9 @@ void main() {
expect(devices.last.id, '192.168.42.10');
});
testWithoutContext('can parse device-finder output for multiple devices', () async {
final FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow();
final FakeFuchsiaSdk fuchsiaSdk = FakeFuchsiaSdk(devFinderDevices:
'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,
fuchsiaWorkflow: fuchsiaWorkflow,
logger: BufferLogger.test(),
);
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 FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow(shouldUseDeviceFinder: false, canListDevices: false);
final FakeFuchsiaSdk fuchsiaSdk = FakeFuchsiaSdk(devices: 'junk', devFinderDevices: 'junk');
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
platform: FakePlatform(),
fuchsiaSdk: fuchsiaSdk,
fuchsiaWorkflow: fuchsiaWorkflow,
logger: BufferLogger.test(),
);
final List<Device> devices = await fuchsiaDevices.pollingGetDevices();
expect(devices, isEmpty);
});
testWithoutContext('can parse junk output from device-finder', () async {
final FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow();
final FakeFuchsiaSdk fuchsiaSdk = FakeFuchsiaSdk(devices: 'junk', devFinderDevices: 'junk');
final FakeFuchsiaWorkflow fuchsiaWorkflow = FakeFuchsiaWorkflow(canListDevices: false);
final FakeFuchsiaSdk fuchsiaSdk = FakeFuchsiaSdk(devices: 'junk');
final FuchsiaDevices fuchsiaDevices = FuchsiaDevices(
platform: FakePlatform(),
fuchsiaSdk: fuchsiaSdk,
@@ -349,7 +296,6 @@ void main() {
ProcessManager: () => processManager,
FuchsiaArtifacts: () => FuchsiaArtifacts(
sshConfig: artifactFile,
devFinder: artifactFile,
ffx: artifactFile,
),
FuchsiaSdk: () => FakeFuchsiaSdk(),
@@ -366,14 +312,12 @@ void main() {
''';
FakeProcessManager processManager;
File devFinder;
File ffx;
File sshConfig;
setUp(() {
processManager = FakeProcessManager.empty();
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');
});
@@ -405,7 +349,7 @@ void main() {
ProcessManager: () => processManager,
SystemClock: () => SystemClock.fixed(DateTime(2018, 11, 9, 1, 25, 45)),
FuchsiaArtifacts: () =>
FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: ffx),
FuchsiaArtifacts(sshConfig: sshConfig, ffx: ffx),
});
testUsingContext('cuts off prior logs', () async {
@@ -432,7 +376,7 @@ void main() {
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
SystemClock: () => SystemClock.fixed(DateTime(2018, 11, 9, 1, 29, 45)),
FuchsiaArtifacts: () => FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: ffx),
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig, ffx: ffx),
});
testUsingContext('can be parsed for all apps', () async {
@@ -463,7 +407,7 @@ void main() {
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
SystemClock: () => SystemClock.fixed(DateTime(2018, 11, 9, 1, 25, 45)),
FuchsiaArtifacts: () => FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: ffx),
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig, ffx: ffx),
});
});
});
@@ -940,18 +884,6 @@ class FakeFuchsiaIsolateDiscoveryProtocol implements FuchsiaIsolateDiscoveryProt
void dispose() {}
}
class FakeFuchsiaDevFinder implements FuchsiaDevFinder {
@override
Future<List<String>> list({ Duration timeout }) async {
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 {
@@ -968,16 +900,12 @@ class FakeFuchsiaSdk extends Fake implements FuchsiaSdk {
FakeFuchsiaSdk({
FuchsiaPM pm,
FuchsiaKernelCompiler compiler,
FuchsiaDevFinder devFinder,
FuchsiaFfx ffx,
String devices,
String devFinderDevices,
}) : fuchsiaPM = pm,
fuchsiaKernelCompiler = compiler,
fuchsiaDevFinder = devFinder ?? FakeFuchsiaDevFinder(),
fuchsiaFfx = ffx ?? FakeFuchsiaFfx(),
_devices = devices,
_devFinderDevices = devFinderDevices;
_devices = devices;
@override
final FuchsiaPM fuchsiaPM;
@@ -985,20 +913,13 @@ class FakeFuchsiaSdk extends Fake implements FuchsiaSdk {
@override
final FuchsiaKernelCompiler fuchsiaKernelCompiler;
@override
final FuchsiaDevFinder fuchsiaDevFinder;
@override
final FuchsiaFfx fuchsiaFfx;
final String _devices;
final String _devFinderDevices;
@override
Future<String> listDevices({Duration timeout, bool useDeviceFinder = false}) async {
if (useDeviceFinder) {
return _devFinderDevices;
}
Future<String> listDevices({Duration timeout}) async {
return _devices;
}
}
@@ -1023,7 +944,6 @@ class FakeFuchsiaWorkflow implements FuchsiaWorkflow {
this.canLaunchDevices = true,
this.canListDevices = true,
this.canListEmulators = true,
this.shouldUseDeviceFinder = true,
});
@override
@@ -1037,7 +957,4 @@ class FakeFuchsiaWorkflow implements FuchsiaWorkflow {
@override
bool canListEmulators;
@override
bool shouldUseDeviceFinder;
}

View File

@@ -13,14 +13,13 @@ import '../../src/fakes.dart';
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(
featureFlags: TestFeatureFlags(),
fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig),
fuchsiaArtifacts: FuchsiaArtifacts(ffx: ffx, sshConfig: sshConfig),
platform: FakePlatform(),
);
@@ -30,7 +29,7 @@ void main() {
testWithoutContext('Fuchsia workflow does not apply to host platform on Windows', () {
final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
featureFlags: TestFeatureFlags(isFuchsiaEnabled: true),
fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig),
fuchsiaArtifacts: FuchsiaArtifacts(ffx: ffx, sshConfig: sshConfig),
platform: FakePlatform(operatingSystem: 'windows'),
);
@@ -40,7 +39,7 @@ void main() {
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: devFinder, sshConfig: sshConfig),
fuchsiaArtifacts: FuchsiaArtifacts(sshConfig: sshConfig),
platform: FakePlatform(environment: <String, String>{}),
);
@@ -49,18 +48,6 @@ void main() {
expect(fuchsiaWorkflow.canListEmulators, false);
});
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(sshConfig: sshConfig, ffx: ffx),
platform: FakePlatform(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(),
@@ -73,18 +60,6 @@ void main() {
expect(fuchsiaWorkflow.canListEmulators, false);
});
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),
platform: FakePlatform(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(),
@@ -97,22 +72,10 @@ void main() {
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),
platform: FakePlatform(environment: <String, String>{'FUCHSIA_DISABLED_ffx_discovery': '1'}),
);
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 on macOS', () {
final FuchsiaWorkflow fuchsiaWorkflow = FuchsiaWorkflow(
featureFlags: TestFeatureFlags(),
fuchsiaArtifacts: FuchsiaArtifacts(devFinder: devFinder, sshConfig: sshConfig, ffx: ffx),
fuchsiaArtifacts: FuchsiaArtifacts(sshConfig: sshConfig, ffx: ffx),
platform: FakePlatform(operatingSystem: 'macOS', environment: <String, String>{}),
);