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