Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
5 changes: 4 additions & 1 deletion shell/platform/fuchsia/dart_runner/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ if (enable_unittests) {
group("tests") {
testonly = true

deps = [ ":dart_runner_tests" ]
deps = [
":dart_runner_tests",
"tests/startup_integration_test",
]
}
}
40 changes: 40 additions & 0 deletions shell/platform/fuchsia/dart_runner/tests/README.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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" ]
}
Original file line number Diff line number Diff line change
@@ -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).
Original file line number Diff line number Diff line change
@@ -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>;
});
};
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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" ]
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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",
},
],
}
Original file line number Diff line number Diff line change
@@ -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",
},
],
}
Loading