Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
dart-aot-runner-integration-test.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <dart/test/cpp/fidl.h>
6#include <fuchsia/tracing/provider/cpp/fidl.h>
7#include <lib/async-loop/testing/cpp/real_loop.h>
8#include <lib/sys/component/cpp/testing/realm_builder.h>
9#include <lib/sys/component/cpp/testing/realm_builder_types.h>
10
11#include "flutter/fml/logging.h"
12#include "gtest/gtest.h"
13
15namespace {
16
17// Types imported for the realm_builder library
18using component_testing::ChildOptions;
19using component_testing::ChildRef;
20using component_testing::Directory;
21using component_testing::ParentRef;
22using component_testing::Protocol;
23using component_testing::RealmBuilder;
24using component_testing::RealmRoot;
25using component_testing::Route;
26
27constexpr auto kDartRunnerEnvironment = "dart_runner_env";
28
29constexpr auto kDartAotRunner = "dart_aot_runner";
30constexpr auto kDartAotRunnerRef = ChildRef{kDartAotRunner};
31constexpr auto kDartAotRunnerUrl =
32 "fuchsia-pkg://fuchsia.com/oot_dart_aot_runner#meta/"
33 "dart_aot_runner.cm";
34
35constexpr auto kDartAotEchoServer = "dart_aot_echo_server";
36constexpr auto kDartAotEchoServerRef = ChildRef{kDartAotEchoServer};
37constexpr auto kDartAotEchoServerUrl =
38 "fuchsia-pkg://fuchsia.com/dart_aot_echo_server#meta/"
39 "dart_aot_echo_server.cm";
40
41class RealmBuilderTest : public ::loop_fixture::RealLoop,
42 public ::testing::Test {
43 public:
44 RealmBuilderTest() = default;
45};
46
47TEST_F(RealmBuilderTest, DartRunnerStartsUp) {
48 auto realm_builder = RealmBuilder::Create();
49 // Add Dart AOT runner as a child of RealmBuilder
50 realm_builder.AddChild(kDartAotRunner, kDartAotRunnerUrl);
51
52 // Add environment providing the Dart AOT runner
53 fuchsia::component::decl::Environment dart_runner_environment;
54 dart_runner_environment.set_name(kDartRunnerEnvironment);
55 dart_runner_environment.set_extends(
56 fuchsia::component::decl::EnvironmentExtends::REALM);
57 dart_runner_environment.set_runners({});
58 auto environment_runners = dart_runner_environment.mutable_runners();
59
60 fuchsia::component::decl::RunnerRegistration dart_aot_runner_reg;
61 dart_aot_runner_reg.set_source(fuchsia::component::decl::Ref::WithChild(
62 fuchsia::component::decl::ChildRef{.name = kDartAotRunner}));
63 dart_aot_runner_reg.set_source_name(kDartAotRunner);
64 dart_aot_runner_reg.set_target_name(kDartAotRunner);
65 environment_runners->push_back(std::move(dart_aot_runner_reg));
66
67 auto realm_decl = realm_builder.GetRealmDecl();
68 if (!realm_decl.has_environments()) {
69 realm_decl.set_environments({});
70 }
71 auto realm_environments = realm_decl.mutable_environments();
72 realm_environments->push_back(std::move(dart_runner_environment));
73 realm_builder.ReplaceRealmDecl(std::move(realm_decl));
74
75 // Add Dart server component as a child of Realm Builder
76 realm_builder.AddChild(kDartAotEchoServer, kDartAotEchoServerUrl,
77 ChildOptions{.environment = kDartRunnerEnvironment});
78
79 // Route base capabilities to the Dart AOT runner
80 realm_builder.AddRoute(
81 Route{.capabilities = {Protocol{"fuchsia.logger.LogSink"},
82 Protocol{"fuchsia.tracing.provider.Registry"},
83 Protocol{"fuchsia.posix.socket.Provider"},
84 Protocol{"fuchsia.intl.PropertyProvider"},
85 Protocol{"fuchsia.vulkan.loader.Loader"},
86 Protocol{"fuchsia.inspect.InspectSink"},
87 Directory{"config-data"}},
88 .source = ParentRef(),
89 .targets = {kDartAotRunnerRef, kDartAotEchoServerRef}});
90
91 // Route the Echo FIDL protocol, this allows the Dart echo server to
92 // communicate with the Realm Builder
93 realm_builder.AddRoute(Route{.capabilities = {Protocol{"dart.test.Echo"}},
94 .source = kDartAotEchoServerRef,
95 .targets = {ParentRef()}});
96
97 // Build the Realm with the provided child and protocols
98 auto realm = realm_builder.Build(dispatcher());
99 FML_LOG(INFO) << "Realm built: " << realm.component().GetChildName();
100 // Connect to the Dart echo server
101 auto echo = realm.component().ConnectSync<dart::test::Echo>();
102 fidl::StringPtr response;
103 // Attempt to ping the Dart echo server for a response
104 echo->EchoString("hello", &response);
105 ASSERT_EQ(response, "hello");
106}
107
108} // namespace
109} // namespace dart_aot_runner_testing::testing
TEST_F(FlGnomeSettingsTest, ClockFormat)
#define FML_LOG(severity)
Definition logging.h:82