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 =
33 "fuchsia-pkg://fuchsia.com/oot_dart_jit_runner#meta/"
34 "dart_jit_runner.cm";
35
36constexpr auto kDartJitEchoServer = "dart_jit_echo_server";
37constexpr auto kDartJitEchoServerRef = ChildRef{kDartJitEchoServer};
38constexpr auto kDartJitEchoServerUrl =
39 "fuchsia-pkg://fuchsia.com/dart_jit_echo_server#meta/"
40 "dart_jit_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 JIT runner as a child of RealmBuilder
51 realm_builder.AddChild(kDartJitRunner, kDartJitRunnerUrl);
52
53 // Add environment providing the Dart JIT 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_jit_runner_reg;
62 dart_jit_runner_reg.set_source(fuchsia::component::decl::Ref::WithChild(
63 fuchsia::component::decl::ChildRef{.name = kDartJitRunner}));
64 dart_jit_runner_reg.set_source_name(kDartJitRunner);
65 dart_jit_runner_reg.set_target_name(kDartJitRunner);
66 environment_runners->push_back(std::move(dart_jit_runner_reg));
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(kDartJitEchoServer, kDartJitEchoServerUrl,
77 ChildOptions{.environment = kDartRunnerEnvironment});
78
79 // Route base capabilities to the Dart JIT 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.inspect.InspectSink"},
86 Directory{"config-data"}},
87 .source = ParentRef(),
88 .targets = {kDartJitRunnerRef, kDartJitEchoServerRef}});
89
90 realm_builder.AddRoute(
91 Route{.capabilities = {Dictionary{"diagnostics"}},
92 .source = ParentRef(),
93 .targets = {kDartJitRunnerRef, kDartJitEchoServerRef}});
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 = kDartJitEchoServerRef,
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_jit_runner_testing::testing
#define FML_LOG(severity)
Definition logging.h:101