[Fuchsia] Create CFv2 support

This change created a CFv2 build target and provided two
implementations of the FuchsiaEmulator, so that I can continually work
on both CFv2 build and test script integration independently.

The v2 target can be built with
```
tools/build.py --os fuchsia --mode release fuchsia_ffi_test_package_cfv2
```
And v2 FuchsiaEmulator implementation can be triggered with
FUCHSIA_CFV2 environment variable.

Bug: #38752
Change-Id: I31936a2ca967fbfeb2bc5628e2f005aef6762687
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322583
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Zijie He <zijiehe@google.com>
This commit is contained in:
Zijie He 2023-09-12 01:40:52 +00:00 committed by Commit Queue
parent 6f5606d442
commit 5282f6e33f
8 changed files with 240 additions and 88 deletions

View file

@ -279,4 +279,28 @@ if (is_fuchsia) {
package_name = "dart_ffi_test"
deps = [ ":fuchsia_ffi_test_component" ]
}
# TODO(38752): Remove "cfv2" once everything is migrated to CFv2.
dart_fuchsia_test_component("fuchsia_ffi_test_component_cfv2") {
manifest = "build/fuchsia/fuchsia_ffi_test_component.cml"
data_deps = [
"runtime/bin:ffi_test_dynamic_library",
"runtime/bin:ffi_test_functions",
]
library_files = [
"libffi_test_dynamic_library.so",
"libffi_test_functions.so",
]
resource_dirs = [
"pkg/expect",
"pkg/meta",
"tests/ffi",
"third_party/pkg/ffi",
]
}
dart_fuchsia_test_package("fuchsia_ffi_test_package_cfv2") {
package_name = "dart_ffi_test_cfv2"
deps = [ ":fuchsia_ffi_test_component_cfv2" ]
}
}

View file

@ -0,0 +1,54 @@
{
program: {
binary: "exe.stripped/dart",
runner: "elf_test_runner",
},
capabilities: [
{ protocol: "fuchsia.test.Suite" },
],
expose: [
{
protocol: "fuchsia.test.Suite",
from: "self",
},
],
use: [
{
directory: "config-data",
rights: [ "r*" ],
path: "/config/data",
},
{
storage: "cache",
path: "/cache",
},
{
storage: "data",
path: "/data",
},
{
storage: "tmp",
path: "/tmp",
},
{
directory: "root-ssl-certificates",
rights: [ "r*" ],
path: "/config/ssl",
},
{
protocol: [
"fuchsia.deprecatedtimezone.Timezone",
"fuchsia.device.NameProvider",
"fuchsia.feedback.CrashReporter",
"fuchsia.intl.PropertyProvider",
"fuchsia.kernel.VmexResource",
"fuchsia.logger.LogSink",
"fuchsia.net.name.Lookup",
"fuchsia.posix.socket.Provider",
"fuchsia.sysmem.Allocator",
"fuchsia.timezone.Timezone",
"fuchsia.tracing.provider.Registry",
],
},
]
}

View file

@ -5,90 +5,30 @@
import 'dart:async';
import 'dart:io';
import 'repository.dart';
import 'command.dart';
import 'fuchsia_cfv1.dart';
import 'fuchsia_cfv2.dart';
class FuchsiaEmulator {
static String fsshTool = "./third_party/fuchsia/sdk/linux/tools/x64/fssh";
static String ffx = "./third_party/fuchsia/sdk/linux/tools/x64/ffx";
static String pm = "./third_party/fuchsia/sdk/linux/tools/x64/pm";
// Sets up and executes commands against a Fuchsia environment.
abstract class FuchsiaEmulator {
// Publishes the packages to the Fuchsia environment.
Future<void> publishPackage(String buildDir, String mode, String arch);
// Tears down the Fuchsia environment.
void stop();
// Returns a command to execute a set of tests against the running Fuchsia
// environment.
VMCommand getTestCommand(String mode, String arch, List<String> arguments);
static Future<void> publishPackage(
String buildDir, String mode, String arch) async {
_run(ffx, ["emu", "stop", "--all"]);
_run(ffx, ["repository", "server", "stop"]);
static final FuchsiaEmulator _instance = _create();
// Setup package server.
var packageRepositoryPath = "dart-test-package-repository-$mode-$arch";
var packageRepositoryName = "dart-test-package-repository-$mode-$arch-name";
var f = Directory(packageRepositoryPath);
if (f.existsSync()) f.deleteSync(recursive: true);
_run(pm, ["newrepo", "-repo", packageRepositoryPath]);
_run(pm, [
"publish",
"-a",
"-repo",
packageRepositoryPath,
"-f",
"$buildDir/gen/dart_ffi_test_$mode/dart_ffi_test_$mode.far"
]);
_run(ffx, [
"repository",
"add-from-pm",
packageRepositoryPath,
"-r",
packageRepositoryName
]);
_run(ffx, ["repository", "server", "start"]);
// Setup emulator.
var emulatorName = "dart-fuchsia-$mode-$arch";
_run(ffx, ["product-bundle", "get", "terminal.qemu-$arch"]);
_run(ffx, [
"emu",
"start",
"terminal.qemu-$arch",
"--name",
emulatorName,
"--headless"
]);
_run(ffx, [
"-t",
emulatorName,
"target",
"repository",
"register",
"-r",
packageRepositoryName,
"--alias",
"fuchsia.com"
]);
}
static void stop() {}
static List<String> getTestArgs(
String mode, String arch, List<String> arguments) {
arguments = arguments
.map((arg) => arg.replaceAll(Repository.uri.toFilePath(), '/pkg/data/'))
.toList();
return [
"-device-name",
"dart-fuchsia-$mode-$arch",
"run",
"fuchsia-pkg://fuchsia.com/dart_ffi_test_$mode#meta/fuchsia_ffi_test_component.cmx",
...arguments
];
}
static String _run(String exec, List<String> args) {
var line = "$exec ${args.join(' ')}";
print("+ $line");
var result = Process.runSync(exec, args);
print(result.stdout);
print(result.stderr);
if (result.exitCode != 0) {
throw "$line failed";
static FuchsiaEmulator _create() {
if (Platform.environment.containsKey('FUCHSIA_CFV2')) {
return FuchsiaEmulatorCFv2();
}
return (result.stdout as String).trim();
return FuchsiaEmulatorCFv1();
}
static FuchsiaEmulator instance() {
return _instance;
}
}

View file

@ -0,0 +1,101 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'command.dart';
import 'fuchsia.dart';
import 'repository.dart';
// Runs tests on a fuchsia emulator with legacy tools and CFv1 targets.
class FuchsiaEmulatorCFv1 extends FuchsiaEmulator {
static const String fsshTool =
"./third_party/fuchsia/sdk/linux/tools/x64/fssh";
static const String ffx = "./third_party/fuchsia/sdk/linux/tools/x64/ffx";
static const String pm = "./third_party/fuchsia/sdk/linux/tools/x64/pm";
@override
Future<void> publishPackage(String buildDir, String mode, String arch) async {
stop();
// Setup package server.
var packageRepositoryPath = "dart-test-package-repository-$mode-$arch";
var packageRepositoryName = "dart-test-package-repository-$mode-$arch-name";
var f = Directory(packageRepositoryPath);
if (f.existsSync()) f.deleteSync(recursive: true);
_run(pm, ["newrepo", "-repo", packageRepositoryPath]);
_run(pm, [
"publish",
"-a",
"-repo",
packageRepositoryPath,
"-f",
"$buildDir/gen/dart_ffi_test_$mode/dart_ffi_test_$mode.far"
]);
_run(ffx, [
"repository",
"add-from-pm",
packageRepositoryPath,
"-r",
packageRepositoryName
]);
_run(ffx, ["repository", "server", "start"]);
// Setup emulator.
var emulatorName = "dart-fuchsia-$mode-$arch";
_run(ffx, ["product-bundle", "get", "terminal.qemu-$arch"]);
_run(ffx, [
"emu",
"start",
"terminal.qemu-$arch",
"--name",
emulatorName,
"--headless"
]);
_run(ffx, [
"-t",
emulatorName,
"target",
"repository",
"register",
"-r",
packageRepositoryName,
"--alias",
"fuchsia.com"
]);
}
@override
void stop() {
_run(ffx, ["emu", "stop", "--all"]);
_run(ffx, ["repository", "server", "stop"]);
}
@override
VMCommand getTestCommand(String mode, String arch, List<String> arguments) {
arguments = arguments
.map((arg) => arg.replaceAll(Repository.uri.toFilePath(), '/pkg/data/'))
.toList();
return VMCommand(fsshTool, [
"-device-name",
"dart-fuchsia-$mode-$arch",
"run",
"fuchsia-pkg://fuchsia.com/dart_ffi_test_$mode#meta/fuchsia_ffi_test_component.cmx",
...arguments
], <String, String>{});
}
static String _run(String exec, List<String> args) {
var line = "$exec ${args.join(' ')}";
print("+ $line");
var result = Process.runSync(exec, args);
print(result.stdout);
print(result.stderr);
if (result.exitCode != 0) {
throw "$line failed";
}
return (result.stdout as String).trim();
}
}

View file

@ -0,0 +1,25 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'command.dart';
import 'fuchsia.dart';
// Runs tests on a fuchsia emulator with chromium maintained test-scripts and
// CFv2 targets.
// TODO(#38752): Need implementation.
class FuchsiaEmulatorCFv2 extends FuchsiaEmulator {
@override
Future<void> publishPackage(
String buildDir, String mode, String arch) async {}
@override
void stop() {}
@override
VMCommand getTestCommand(String mode, String arch, List<String> arguments) {
return VMCommand("dummy", arguments, <String, String>{});
}
}

View file

@ -480,11 +480,12 @@ class DartkFuchsiaEmulatorRuntimeConfiguration
if (isCrashExpected) {
arguments.insert(0, '--suppress-core-dump');
}
var runtimeArgs = FuchsiaEmulator.getTestArgs(
var command = FuchsiaEmulator.instance().getTestCommand(
_configuration.mode.name, _configuration.architecture.name, arguments);
runtimeArgs.insert(runtimeArgs.length - 1, '--disable-dart-dev');
command.arguments
.insert(command.arguments.length - 1, '--disable-dart-dev');
return [
VMCommand(FuchsiaEmulator.fsshTool, runtimeArgs, environmentOverrides)
VMCommand(command.executable, command.arguments, environmentOverrides)
];
}
}

View file

@ -176,8 +176,10 @@ Future testConfigurations(List<TestConfiguration> configurations) async {
}
if (configuration.system == System.fuchsia) {
await FuchsiaEmulator.publishPackage(configuration.buildDirectory,
configuration.mode.name, configuration.architecture.name);
await FuchsiaEmulator.instance().publishPackage(
configuration.buildDirectory,
configuration.mode.name,
configuration.architecture.name);
}
}
@ -202,7 +204,11 @@ Future testConfigurations(List<TestConfiguration> configurations) async {
for (var configuration in configurations) {
configuration.stopServers();
}
FuchsiaEmulator.stop();
if (configurations.any((configuration) {
return configuration.system == System.fuchsia;
})) {
FuchsiaEmulator.instance().stop();
}
DebugLogger.close();
if (!firstConf.keepGeneratedFiles) {

View file

@ -1682,7 +1682,8 @@
"runtime",
"create_sdk",
"fuchsia_test_package",
"fuchsia_ffi_test_package"
"fuchsia_ffi_test_package",
"fuchsia_ffi_test_package_cfv2"
]
},
{