Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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::Dictionary;
21using component_testing::Directory;
22using component_testing::ParentRef;
23using component_testing::Protocol;
24using component_testing::RealmBuilder;
25using component_testing::RealmRoot;
26using component_testing::Route;
27
28constexpr auto kDartRunnerEnvironment = "dart_runner_env";
29
30constexpr auto kDartAotRunner = "dart_aot_runner";
31constexpr auto kDartAotRunnerRef = ChildRef{kDartAotRunner};
32constexpr auto kDartAotRunnerUrl =
33 "fuchsia-pkg://fuchsia.com/oot_dart_aot_runner#meta/"
34 "dart_aot_runner.cm";
35
36constexpr auto kDartAotEchoServer = "dart_aot_echo_server";
37constexpr auto kDartAotEchoServerRef = ChildRef{kDartAotEchoServer};
38constexpr auto kDartAotEchoServerUrl =
39 "fuchsia-pkg://fuchsia.com/dart_aot_echo_server#meta/"
40 "dart_aot_echo_server.cm";
41
42class RealmBuilderTest : public ::loop_fixture::RealLoop,
43 public ::testing::Test {
44 public:
45 RealmBuilderTest() = default;
46};
47
48TEST_F(RealmBuilderTest, DartRunnerStartsUp) {
49 auto realm_builder = RealmBuilder::Create();
50 // Add Dart AOT runner as a child of RealmBuilder
51 realm_builder.AddChild(kDartAotRunner, kDartAotRunnerUrl);
52
53 // Add environment providing the Dart AOT runner
54 fuchsia::component::decl::Environment dart_runner_environment;
55 dart_runner_environment.set_name(kDartRunnerEnvironment);
56 dart_runner_environment.set_extends(
57 fuchsia::component::decl::EnvironmentExtends::REALM);
58 dart_runner_environment.set_runners({});
59 auto environment_runners = dart_runner_environment.mutable_runners();
60
61 fuchsia::component::decl::RunnerRegistration dart_aot_runner_reg;
62 dart_aot_runner_reg.set_source(fuchsia::component::decl::Ref::WithChild(
63 fuchsia::component::decl::ChildRef{.name = kDartAotRunner}));
64 dart_aot_runner_reg.set_source_name(kDartAotRunner);
65 dart_aot_runner_reg.set_target_name(kDartAotRunner);
66 environment_runners->push_back(std::move(dart_aot_runner_reg));
67
68 auto realm_decl = realm_builder.GetRealmDecl();
69 if (!realm_decl.has_environments()) {
70 realm_decl.set_environments({});
71 }
72 auto realm_environments = realm_decl.mutable_environments();
73 realm_environments->push_back(std::move(dart_runner_environment));
74 realm_builder.ReplaceRealmDecl(std::move(realm_decl));
75
76 // Add Dart server component as a child of Realm Builder
77 realm_builder.AddChild(kDartAotEchoServer, kDartAotEchoServerUrl,
78 ChildOptions{.environment = kDartRunnerEnvironment});
79
80 // Route base capabilities to the Dart AOT runner
81 realm_builder.AddRoute(
82 Route{.capabilities = {Protocol{"fuchsia.logger.LogSink"},
83 Protocol{"fuchsia.tracing.provider.Registry"},
84 Protocol{"fuchsia.posix.socket.Provider"},
85 Protocol{"fuchsia.intl.PropertyProvider"},
86 Protocol{"fuchsia.vulkan.loader.Loader"},
87 Protocol{"fuchsia.inspect.InspectSink"},
88 Directory{"config-data"}},
89 .source = ParentRef(),
90 .targets = {kDartAotRunnerRef, kDartAotEchoServerRef}});
91
92 realm_builder.AddRoute(
93 Route{.capabilities = {Dictionary{"diagnostics"}},
94 .source = ParentRef(),
95 .targets = {kDartAotRunnerRef, kDartAotEchoServerRef}});
96
97 // Route the Echo FIDL protocol, this allows the Dart echo server to
98 // communicate with the Realm Builder
99 realm_builder.AddRoute(Route{.capabilities = {Protocol{"dart.test.Echo"}},
100 .source = kDartAotEchoServerRef,
101 .targets = {ParentRef()}});
102
103 // Build the Realm with the provided child and protocols
104 auto realm = realm_builder.Build(dispatcher());
105 FML_LOG(INFO) << "Realm built: " << realm.component().GetChildName();
106 // Connect to the Dart echo server
107 auto echo = realm.component().ConnectSync<dart::test::Echo>();
108 fidl::StringPtr response;
109 // Attempt to ping the Dart echo server for a response
110 echo->EchoString("hello", &response);
111 ASSERT_EQ(response, "hello");
112}
113
114} // namespace
115} // namespace dart_aot_runner_testing::testing
#define FML_LOG(severity)
Definition logging.h:101