Add Dart JIT runner integration test (flutter/engine#36420)

This commit is contained in:
Erik
2022-09-27 13:14:16 -07:00
committed by GitHub
parent 1b6a7356db
commit 75d2baf5fe
22 changed files with 394 additions and 58 deletions

2
DEPS
View File

@@ -109,7 +109,7 @@ allowed_hosts = [
]
deps = {
'src': 'https://github.com/flutter/buildroot.git' + '@' + 'c9c2b77c9520903741ccda2fe12f773408a76c94',
'src': 'https://github.com/flutter/buildroot.git' + '@' + 'b7ef254d8cec53bdad39cdb4a284af1d0a79dbdb',
# Fuchsia compatibility
#

View File

@@ -333,6 +333,9 @@ if (enable_unittests) {
group("tests") {
testonly = true
deps = [ ":dart_runner_tests" ]
deps = [
":dart_runner_tests",
"tests/startup_integration_test",
]
}
}

View File

@@ -0,0 +1,40 @@
# Dart Runner Tests
Contains tests for the Dart Runner and their corresponding utility code
### Running the Tests
<!-- TODO(erkln): Replace steps once test runner script is updated to run Dart runner tests -->
- The tests can be run using the Fuchsia emulator
```
fx set workstation_eng.qemu-x64
ffx emu start --headless
```
- Start up the package server
```
fx serve
```
- Prepare the BUILD files
```
$ENGINE_DIR/flutter/tools/gn --fuchsia --no-lto
```
- Build the Fuchsia binary with the test directory as the target (ie. `flutter/shell/platform/fuchsia/dart_runner/tests/startup_integration_test`)
```
ninja -C $ENGINE_DIR/out/fuchsia_debug_x64 flutter/shell/platform/fuchsia/dart_runner/tests/startup_integration_test
```
- Deploy/publish test FAR files to Fuchsia
```
$FUCHSIA_DIR/.jiri_root/bin/fx pm publish -a -repo $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files -f $ENGINE_DIR/out/fuchsia_debug_x64/dart-jit-runner-integration-test-0.far
```
Note that some tests may have components that also need to be deployed/published (ie. `dart_jit_echo_server` also needs to be published for the Dart JIT integration test to run successfully)
```
$FUCHSIA_DIR/.jiri_root/bin/fx pm publish -a -repo $FUCHSIA_DIR/$(cat $FUCHSIA_DIR/.fx-build-dir)/amber-files -f $ENGINE_DIR/out/fuchsia_debug_x64/gen/flutter/shell/platform/fuchsia/dart_runner/tests/startup_integration_test/dart_jit_runner/dart_jit_echo_server/dart_jit_echo_server/dart_jit_echo_server.far
```
- Run the test
```
ffx test run "fuchsia-pkg://fuchsia.com/dart-jit-runner-integration-test#meta/dart-jit-runner-integration-test.cm"
```
Notes:
- To find the FAR files, `ls` into the output directory provided to the `ninja` command

View File

@@ -0,0 +1,12 @@
# Copyright 2013 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("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/fidl/fidl.gni")
fidl("echo") {
name = "flutter.example.echo"
meta = "//flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo/meta.json"
sources = [ "echo.fidl" ]
}

View File

@@ -0,0 +1,3 @@
# Echo FIDL
This FIDL protocol allows the Dart integration tests to communicate with a Dart Echo server (a test Dart component that echoes back a request).

View File

@@ -0,0 +1,17 @@
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
library flutter.example.echo;
const MAX_STRING_LENGTH uint64 = 32;
@discoverable
protocol Echo {
/// Returns the input.
EchoString(struct {
value string:<MAX_STRING_LENGTH, optional>;
}) -> (struct {
response string:<MAX_STRING_LENGTH, optional>;
});
};

View File

@@ -0,0 +1,9 @@
{
"deps": [],
"name": "flutter.example.echo",
"root": "fidl/flutter.example.echo",
"sources": [
"../../../flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo/echo.fidl"
],
"type": "fidl_library"
}

View File

@@ -2,7 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
group("tests") {
import("//build/fuchsia/sdk.gni")
group("startup_integration_test") {
testonly = true
deps = [ "hello_world:hello_world_dart" ]
deps = [ "dart_jit_runner:tests" ]
}

View File

@@ -0,0 +1,50 @@
# Copyright 2013 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("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/dart/dart_component.gni")
import("//flutter/tools/fuchsia/fidl/fidl.gni")
import("//flutter/tools/fuchsia/fuchsia_archive.gni")
group("tests") {
testonly = true
deps = [ ":dart-jit-runner-integration-test" ]
}
executable("dart-jit-runner-integration-test-bin") {
testonly = true
output_name = "dart-jit-runner-integration-test"
sources = [ "dart-jit-runner-integration-test.cc" ]
# This is needed for //third_party/googletest for linking zircon symbols.
libs = [ "$fuchsia_sdk_path/arch/$target_cpu/sysroot/lib/libzircon.so" ]
deps = [
"$fuchsia_sdk_root/fidl:fuchsia.logger",
"$fuchsia_sdk_root/fidl:fuchsia.tracing.provider",
"$fuchsia_sdk_root/pkg:async",
"$fuchsia_sdk_root/pkg:async-loop-testing",
"$fuchsia_sdk_root/pkg:fidl_cpp",
"$fuchsia_sdk_root/pkg:sys_component_cpp_testing",
"$fuchsia_sdk_root/pkg:zx",
"dart_jit_echo_server:package",
"//flutter/fml",
"//flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo:echo",
"//third_party/googletest:gtest",
"//third_party/googletest:gtest_main",
]
}
fuchsia_test_archive("dart-jit-runner-integration-test") {
deps = [
":dart-jit-runner-integration-test-bin",
"dart_jit_echo_server:package",
]
binary = "$target_name"
cml_file = rebase_path("meta/$target_name.cml")
}

View File

@@ -0,0 +1,3 @@
# dart_jit_runner
Contains the integration test for the Dart JIT runner. The Dart Echo server is launched with a JIT runner.

View File

@@ -0,0 +1,59 @@
// Copyright 2013 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.
// The generated C++ bindings for the Echo FIDL protocol
#include <flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo/flutter/example/echo/cpp/fidl.h>
#include <lib/async-loop/testing/cpp/real_loop.h>
#include <lib/sys/component/cpp/testing/realm_builder.h>
#include <lib/sys/component/cpp/testing/realm_builder_types.h>
#include "flutter/fml/logging.h"
#include "gtest/gtest.h"
namespace dart_jit_runner_testing::testing {
namespace {
using component_testing::ChildRef;
using component_testing::ParentRef;
using component_testing::Protocol;
using component_testing::RealmBuilder;
using component_testing::RealmRoot;
using component_testing::Route;
class RealmBuilderTest : public ::loop_fixture::RealLoop,
public ::testing::Test {
public:
RealmBuilderTest() = default;
};
TEST_F(RealmBuilderTest, DartRunnerStartsUp) {
auto realm_builder = RealmBuilder::Create();
// Add Dart server component as a child of Realm Builder
realm_builder.AddChild("hello_world",
"fuchsia-pkg://fuchsia.com/dart_jit_echo_server#meta/"
"dart_jit_echo_server.cm");
realm_builder.AddRoute(
Route{.capabilities = {Protocol{"fuchsia.logger.LogSink"}},
.source = ParentRef(),
.targets = {ChildRef{"hello_world"}}});
// Route the Echo FIDL protocol, this allows the Dart echo server to
// communicate with the Realm Builder
realm_builder.AddRoute(
Route{.capabilities = {Protocol{"flutter.example.echo.Echo"}},
.source = ChildRef{"hello_world"},
.targets = {ParentRef()}});
// Build the Realm with the provided child and protocols
auto realm = realm_builder.Build(dispatcher());
FML_LOG(INFO) << "Realm built: " << realm.GetChildName();
// Connect to the Dart echo server
auto echo = realm.ConnectSync<flutter::example::echo::Echo>();
fidl::StringPtr response;
// Attempt to ping the Dart echo server for a response
echo->EchoString("hello", &response);
ASSERT_EQ(response, "hello");
}
} // namespace
} // namespace dart_jit_runner_testing::testing

View File

@@ -0,0 +1,45 @@
# Copyright 2013 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("//build/fuchsia/sdk.gni")
import("//flutter/tools/fuchsia/dart/dart_component.gni")
import("//flutter/tools/fuchsia/dart/dart_library.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
dart_library("lib") {
testonly = true
package_name = "dart_jit_echo_server"
null_safe = true
source_dir = "."
sources = [ "main.dart" ]
deps = [
"//flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo:echo",
"//flutter/tools/fuchsia/dart:fidl",
"//flutter/tools/fuchsia/dart:fuchsia_services",
"//flutter/tools/fuchsia/fidl:fuchsia.logger",
"//flutter/tools/fuchsia/fidl:fuchsia.test",
]
}
# Dart component that serves the test Echo FIDL protocol, built using the Dart JIT runner
dart_component("component") {
testonly = true
null_safe = true
manifest = "meta/dart-jit-echo-server.cml"
main_package = "dart_jit_echo_server"
component_name = "dart_jit_echo_server"
deps = [ ":lib" ]
}
fuchsia_package("package") {
testonly = true
package_name = "dart_jit_echo_server"
deps = [ ":component" ]
}

View File

@@ -0,0 +1,48 @@
// Copyright 2013 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.
// The server uses async code to be able to listen for incoming Echo requests and connections
// asynchronously.
import 'dart:async';
// The fidl package contains general utility code for using FIDL in Dart.
import 'package:fidl/fidl.dart' as fidl;
// The generated Dart bindings for the Echo FIDL protocol
import 'package:fidl_flutter_example_echo/fidl_async.dart' as fidl_echo;
// The fuchsia_services package interfaces with the Fuchsia system. In particular, it is used
// to expose a service to other components
import 'package:fuchsia_services/services.dart' as sys;
// Create an implementation for the Echo protocol by overriding the
// fidl_echo.Echo class from the bindings
class _EchoImpl extends fidl_echo.Echo {
// The stream controller for the stream of OnString events
final _onStringStreamController = StreamController<String>();
// Implementation of EchoString that just echoes the request value back
@override
Future<String?> echoString(String? value) async {
return value;
}
}
void main(List<String> args) {
// Create the component context. We should not serve outgoing before we add
// the services.
final context = sys.ComponentContext.create();
// Each FIDL protocol class has an accompanying Binding class, which takes
// an implementation of the protocol and a channel, and dispatches incoming
// requests on the channel to the protocol implementation.
final binding = fidl_echo.EchoBinding();
// Serves the implementation by passing it a handler for incoming requests,
// and the name of the protocol it is providing.
final echo = _EchoImpl();
// Add the outgoing service, and then serve the outgoing directory.
context.outgoing
..addPublicService<fidl_echo.Echo>(
(fidl.InterfaceRequest<fidl_echo.Echo> serverEnd) =>
binding.bind(echo, serverEnd),
fidl_echo.Echo.$serviceName)
..serveFromStartupInfo();
}

View File

@@ -0,0 +1,20 @@
// Copyright 2013 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.
{
include: [ "syslog/client.shard.cml" ],
program: {
runner: "dart_jit_runner",
},
// Capabilities provided by this component.
capabilities: [
{ protocol: "flutter.example.echo.Echo" },
],
expose: [
{
protocol: "flutter.example.echo.Echo",
from: "self",
},
],
}

View File

@@ -0,0 +1,31 @@
// Copyright 2013 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.
{
include: [
"gtest_runner.shard.cml",
"sys/component/realm_builder_absolute.shard.cml",
// This test needs both the vulkan facet and the hermetic-tier-2 facet,
// so we are forced to make it a system test.
"sys/testing/system-test.shard.cml",
],
program: {
binary: "bin/app",
},
offer: [
{
// Offer capabilities needed by components in this test realm.
// Keep it minimal, describe only what's actually needed.
protocol: [
"fuchsia.logger.LogSink",
"fuchsia.sysmem.Allocator",
"fuchsia.tracing.provider.Registry",
"fuchsia.vulkan.loader.Loader",
],
from: "parent",
to: "#realm_builder",
},
],
}

View File

@@ -0,0 +1,18 @@
// Copyright 2013 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.
{
program: {
runner: "gtest_runner",
},
capabilities: [
{ protocol: "fuchsia.test.Suite" },
],
expose: [
{
protocol: "fuchsia.test.Suite",
from: "self",
},
],
}

View File

@@ -1,30 +0,0 @@
# Copyright 2013 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("//flutter/tools/fuchsia/dart/dart_component.gni")
import("//flutter/tools/fuchsia/dart/dart_library.gni")
import("//flutter/tools/fuchsia/gn-sdk/package.gni")
dart_library("lib") {
testonly = true
package_name = "hello_world"
language_version = "2.12"
source_dir = "."
sources = [ "main.dart" ]
deps = []
}
dart_component("hello-world-dart-component") {
testonly = true
manifest = "meta/hello-world.cml"
main_package = "hello_world"
component_name = "hello_world"
deps = [ ":lib" ]
}
fuchsia_component("hello_world_dart") {
testonly = true
deps = [ ":hello-world-dart-component" ]
manifest = "meta/hello-world.cml"
}

View File

@@ -1,7 +0,0 @@
// Copyright 2013 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.
void main() {
print("Hello, World!");
}

View File

@@ -1,6 +0,0 @@
{
program: {
data: "data/hello_world",
runner: "dart_jit_runner"
},
}

View File

@@ -37,3 +37,8 @@
package: embedder_tests-0.far
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/dart_utils_tests#meta/dart_utils_tests.cm
package: dart_utils_tests-0.far
- test_command: run-test-suite fuchsia-pkg://fuchsia.com/dart-jit-runner-integration-test#meta/dart-jit-runner-integration-test.cm
packages:
- dart-jit-runner-integration-test-0.far
- dart_jit_runner-0.far
- gen/flutter/shell/platform/fuchsia/dart_runner/tests/startup_integration_test/dart_jit_runner/dart_jit_echo_server/dart_jit_echo_server/dart_jit_echo_server.far

View File

@@ -19,7 +19,11 @@ template("fidl_dart") {
assert(current_toolchain == dart_toolchain,
"This template can only be used in the $dart_toolchain toolchain.")
not_needed(invoker, [ "sources" ])
not_needed(invoker,
[
"meta",
"sources",
])
main_target_name = target_name
generation_target_name = "${target_name}_dart_generate"

View File

@@ -24,23 +24,33 @@ template("fidl") {
"All FIDL dependencies are inherently " +
"public, use 'public_deps' instead of 'deps'.")
deps = []
if (current_toolchain == dart_toolchain) {
import("//flutter/tools/fuchsia/dart/fidl_dart.gni")
not_needed(invoker, [ "meta" ])
fidl_dart(target_name) {
forward_variables_from(invoker, "*")
}
} else {
if (current_toolchain == fidl_toolchain) {
import("//flutter/tools/fuchsia/fidl/fidl_library.gni")
} else if (current_toolchain == fidl_toolchain) {
import("//flutter/tools/fuchsia/fidl/fidl_library.gni")
fidl_library(target_name) {
forward_variables_from(invoker, "*")
}
} else {
not_needed("*")
not_needed(invoker, [ "meta" ])
fidl_library(target_name) {
forward_variables_from(invoker, "*")
}
} else if (current_toolchain == default_toolchain) {
not_needed(invoker,
[
"name",
"sources",
])
fuchsia_fidl_library(target_name) {
forward_variables_from(invoker, "*")
}
} else {
not_needed("*")
}
}