Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
dart-jit-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 kDartJitRunner = "dart_jit_runner";
31constexpr auto kDartJitRunnerRef = ChildRef{kDartJitRunner};
32constexpr auto kDartJitRunnerUrl = "dart_jit_runner#meta/dart_jit_runner.cm";
33
34constexpr auto kDartJitEchoServer = "dart_jit_echo_server";
35constexpr auto kDartJitEchoServerRef = ChildRef{kDartJitEchoServer};
36constexpr auto kDartJitEchoServerUrl =
37 "dart_jit_echo_server#meta/dart_jit_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 JIT runner as a child of RealmBuilder
48 realm_builder.AddChild(kDartJitRunner, kDartJitRunnerUrl);
49
50 // Add environment providing the Dart JIT 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_jit_runner_reg;
59 dart_jit_runner_reg.set_source(fuchsia::component::decl::Ref::WithChild(
60 fuchsia::component::decl::ChildRef{.name = kDartJitRunner}));
61 dart_jit_runner_reg.set_source_name(kDartJitRunner);
62 dart_jit_runner_reg.set_target_name(kDartJitRunner);
63 environment_runners->push_back(std::move(dart_jit_runner_reg));
64 auto realm_decl = realm_builder.GetRealmDecl();
65 if (!realm_decl.has_environments()) {
66 realm_decl.set_environments({});
67 }
68 auto realm_environments = realm_decl.mutable_environments();
69 realm_environments->push_back(std::move(dart_runner_environment));
70 realm_builder.ReplaceRealmDecl(std::move(realm_decl));
71
72 // Add Dart server component as a child of Realm Builder
73 realm_builder.AddChild(kDartJitEchoServer, kDartJitEchoServerUrl,
74 ChildOptions{.environment = kDartRunnerEnvironment});
75
76 // Route base capabilities to the Dart JIT runner
77 realm_builder.AddRoute(
78 Route{.capabilities = {Protocol{"fuchsia.inspect.InspectSink"},
79 Protocol{"fuchsia.intl.PropertyProvider"},
80 Protocol{"fuchsia.kernel.VmexResource"},
81 Protocol{"fuchsia.logger.LogSink"},
82 Protocol{"fuchsia.posix.socket.Provider"},
83 Protocol{"fuchsia.tracing.provider.Registry"},
84 Directory{"config-data"}},
85 .source = ParentRef(),
86 .targets = {kDartJitRunnerRef, kDartJitEchoServerRef}});
87
88 realm_builder.AddRoute(
89 Route{.capabilities = {Dictionary{"diagnostics"}},
90 .source = ParentRef(),
91 .targets = {kDartJitRunnerRef, kDartJitEchoServerRef}});
92
93 // Route the Echo FIDL protocol, this allows the Dart echo server to
94 // communicate with the Realm Builder
95 realm_builder.AddRoute(Route{.capabilities = {Protocol{"dart.test.Echo"}},
96 .source = kDartJitEchoServerRef,
97 .targets = {ParentRef()}});
98
99 // Build the Realm with the provided child and protocols
100 auto realm = realm_builder.Build(dispatcher());
101 FML_LOG(INFO) << "Realm built: " << realm.component().GetChildName();
102 // Connect to the Dart echo server
103 auto echo = realm.component().ConnectSync<dart::test::Echo>();
104 fidl::StringPtr response;
105 // Attempt to ping the Dart echo server for a response
106 echo->EchoString("hello", &response);
107 ASSERT_EQ(response, "hello");
108}
109
110} // namespace
111} // namespace dart_jit_runner_testing::testing
#define FML_LOG(severity)
Definition logging.h:101