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
14 changes: 14 additions & 0 deletions shell/platform/fuchsia/dart_runner/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ jit_runner_package("dart_jit_product_runner") {
product = true
}

# "OOT" copy of the runner used by tests, to avoid conflicting with the runner
# in the base fuchsia image.
# TODO(fxbug.dev/106575): Fix this with subpackages.
aot_runner_package("oot_dart_aot_runner") {
product = false
}

# "OOT" copy of the runner used by tests, to avoid conflicting with the runner
# in the base fuchsia image.
# TODO(fxbug.dev/106575): Fix this with subpackages.
jit_runner_package("oot_dart_jit_runner") {
product = false
}

if (enable_unittests) {
runner_sources("jit_runner_sources_for_test") {
product = false
Expand Down
37 changes: 0 additions & 37 deletions shell/platform/fuchsia/dart_runner/tests/README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
# 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
Expand Up @@ -6,5 +6,8 @@ import("//build/fuchsia/sdk.gni")

group("startup_integration_test") {
testonly = true
deps = [ "dart_jit_runner:tests" ]
deps = [
"dart_aot_runner:tests",
"dart_jit_runner:tests",
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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-aot-runner-integration-test" ]
}

executable("dart-aot-runner-integration-test-bin") {
testonly = true

output_name = "dart-aot-runner-integration-test"

sources = [ "dart-aot-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",
"//flutter/fml",
"//flutter/shell/platform/fuchsia/dart_runner/tests/fidl/flutter.example.echo:echo",
"//flutter/shell/platform/fuchsia/dart_runner/tests/startup_integration_test/dart_echo_server:aot_echo_package",
"//third_party/googletest:gtest",
"//third_party/googletest:gtest_main",
]
}

fuchsia_test_archive("dart-aot-runner-integration-test") {
deps = [ ":dart-aot-runner-integration-test-bin" ]

binary = "$target_name"
cml_file = rebase_path("meta/$target_name.cml")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# dart_aot_runner

Contains the integration test for the Dart AOT runner.

### Running Tests
<!-- TODO(erkln): Replace steps once test runner script is updated to run Dart runner tests -->
#### Setup emulator and PM serve
```
fx set workstation_eng.qemu-x64
ffx emu start --headless

fx serve
```

#### Prepare build files and build binary
```
$ENGINE_DIR/flutter/tools/gn --fuchsia --no-lto --runtime-mode=profile
ninja -C $ENGINE_DIR/out/fuchsia_profile_x64 flutter/shell/platform/fuchsia fuchsia_tests
```

#### Publish files to PM
```
$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_profile_x64/dart-aot-runner-integration-test-0.far

$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_profile_x64/oot_dart_aot_runner-0.far

$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_profile_x64/gen/flutter/shell/platform/fuchsia/dart_runner/tests/startup_integration_test/dart_echo_server/dart_aot_echo_server/dart_aot_echo_server.far
```

#### Run test
```
ffx test run "fuchsia-pkg://fuchsia.com/dart-aot-runner-integration-test#meta/dart-aot-runner-integration-test.cm"
```

## Notes
The `profile` runtime should be used when running the `dart_aot_runner` integration test. Snapshots will fail to generate or generate incorrectly if the wrong runtime is used.
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// 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 <fuchsia/tracing/provider/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_aot_runner_testing::testing {
namespace {

// Types imported for the realm_builder library
using component_testing::ChildOptions;
using component_testing::ChildRef;
using component_testing::Directory;
using component_testing::ParentRef;
using component_testing::Protocol;
using component_testing::RealmBuilder;
using component_testing::RealmRoot;
using component_testing::Route;

constexpr auto kDartRunnerEnvironment = "dart_runner_env";

constexpr auto kDartAotRunner = "dart_aot_runner";
constexpr auto kDartAotRunnerRef = ChildRef{kDartAotRunner};
constexpr auto kDartAotRunnerUrl =
"fuchsia-pkg://fuchsia.com/oot_dart_aot_runner#meta/"
"dart_aot_runner.cm";

constexpr auto kDartAotEchoServer = "dart_aot_echo_server";
constexpr auto kDartAotEchoServerRef = ChildRef{kDartAotEchoServer};
constexpr auto kDartAotEchoServerUrl =
"fuchsia-pkg://fuchsia.com/dart_aot_echo_server#meta/"
"dart_aot_echo_server.cm";

class RealmBuilderTest : public ::loop_fixture::RealLoop,
public ::testing::Test {
public:
RealmBuilderTest() = default;
};

TEST_F(RealmBuilderTest, DartRunnerStartsUp) {
auto realm_builder = RealmBuilder::Create();
// Add Dart AOT runner as a child of RealmBuilder
realm_builder.AddChild(kDartAotRunner, kDartAotRunnerUrl);

// Add environment providing the Dart AOT runner
fuchsia::component::decl::Environment dart_runner_environment;
dart_runner_environment.set_name(kDartRunnerEnvironment);
dart_runner_environment.set_extends(
fuchsia::component::decl::EnvironmentExtends::REALM);
dart_runner_environment.set_runners({});
auto environment_runners = dart_runner_environment.mutable_runners();

fuchsia::component::decl::RunnerRegistration dart_aot_runner_reg;
dart_aot_runner_reg.set_source(fuchsia::component::decl::Ref::WithChild(
fuchsia::component::decl::ChildRef{.name = kDartAotRunner}));
dart_aot_runner_reg.set_source_name(kDartAotRunner);
dart_aot_runner_reg.set_target_name(kDartAotRunner);
environment_runners->push_back(std::move(dart_aot_runner_reg));

auto realm_decl = realm_builder.GetRealmDecl();
if (!realm_decl.has_environments()) {
realm_decl.set_environments({});
}
auto realm_environments = realm_decl.mutable_environments();
realm_environments->push_back(std::move(dart_runner_environment));
realm_builder.ReplaceRealmDecl(std::move(realm_decl));

// Add Dart server component as a child of Realm Builder
realm_builder.AddChild(kDartAotEchoServer, kDartAotEchoServerUrl,
ChildOptions{.environment = kDartRunnerEnvironment});

// Route base capabilities to the Dart AOT runner
realm_builder.AddRoute(
Route{.capabilities = {Protocol{"fuchsia.logger.LogSink"},
Protocol{"fuchsia.tracing.provider.Registry"},
Protocol{"fuchsia.posix.socket.Provider"},
Protocol{"fuchsia.intl.PropertyProvider"},
Protocol{"fuchsia.vulkan.loader.Loader"},
Directory{"config-data"}},
.source = ParentRef(),
.targets = {kDartAotRunnerRef, kDartAotEchoServerRef}});

// 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 = kDartAotEchoServerRef,
.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_aot_runner_testing::testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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",
"fuchsia.posix.socket.Provider",
"fuchsia.intl.PropertyProvider",
],
from: "parent",
to: "#realm_builder",
},
{
directory: "pkg",
subdir: "config",
as: "config-data",
from: "framework",
to: "#realm_builder",
},
],
}
Original file line number Diff line number Diff line change
@@ -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",
},
],
}
Loading