Flutter Engine
 
Loading...
Searching...
No Matches
dart_fixture.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
6
7#include <utility>
8#include "flutter/fml/paths.h"
9
10namespace flutter::testing {
11
16
17DartFixture::DartFixture(std::string kernel_filename,
18 std::string elf_filename,
19 std::string elf_split_filename)
20 : native_resolver_(std::make_shared<TestDartNativeResolver>()),
22 std::move(elf_split_filename))),
23 kernel_filename_(std::move(kernel_filename)),
24 assets_dir_(fml::OpenDirectory(GetFixturesPath(),
25 false,
26 fml::FilePermission::kRead)),
27 aot_symbols_(
28 LoadELFSymbolFromFixturesIfNeccessary(std::move(elf_filename))) {}
29
31 Settings settings;
32 settings.leak_vm = false;
33 settings.task_observer_add = [](intptr_t, const fml::closure&) {
35 };
36 settings.task_observer_remove = [](fml::TaskQueueId, intptr_t) {};
37 settings.isolate_create_callback = [this]() {
38 native_resolver_->SetNativeResolverForIsolate();
39 };
40 settings.enable_vm_service = false;
41 SetSnapshotsAndAssets(settings);
42 return settings;
43}
44
46 if (!assets_dir_.is_valid()) {
47 return;
48 }
49
50 settings.assets_dir = assets_dir_.get();
51
52 // In JIT execution, all snapshots are present within the binary itself and
53 // don't need to be explicitly supplied by the embedder. In AOT, these
54 // snapshots will be present in the application AOT dylib.
57#if FML_OS_LINUX
59 {GetTestingAssetsPath(), "libvmservice_snapshot.so"}));
60#endif // FML_OS_LINUX
61 } else {
62 settings.application_kernels = [this]() -> Mappings {
63 std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
64 auto kernel_mapping =
66 if (!kernel_mapping || !kernel_mapping->IsValid()) {
67 FML_LOG(ERROR) << "Could not find kernel blob for test fixture not "
68 "running in precompiled mode.";
69 return kernel_mappings;
70 }
71 kernel_mappings.emplace_back(std::move(kernel_mapping));
72 return kernel_mappings;
73 };
74 }
75}
76
77void DartFixture::AddNativeCallback(const std::string& name,
78 Dart_NativeFunction callback) {
79 native_resolver_->AddNativeCallback(name, callback);
80}
81
83 void* callback_ptr) {
84 native_resolver_->AddFfiNativeCallback(name, callback_ptr);
85}
86
87} // namespace flutter::testing
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
Definition dart_vm.cc:176
void SetSnapshotsAndAssets(Settings &settings)
void AddFfiNativeCallback(const std::string &name, void *callback_ptr)
virtual Settings CreateSettingsForFixture()
void AddNativeCallback(const std::string &name, Dart_NativeFunction callback)
std::shared_ptr< TestDartNativeResolver > native_resolver_
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
Definition mapping.cc:20
static TaskQueueId Invalid()
bool is_valid() const
const T & get() const
FlutterDesktopBinaryReply callback
#define FML_LOG(severity)
Definition logging.h:101
#define FML_CHECK(condition)
Definition logging.h:104
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
ELFAOTSymbols LoadELFSymbolFromFixturesIfNeccessary(std::string elf_filename)
Attempts to resolve AOT symbols from the portable ELF loader. This location is automatically resolved...
Definition elf_loader.cc:16
bool PrepareSettingsForAOTWithSymbols(Settings &settings, const ELFAOTSymbols &symbols)
Prepare the settings objects various AOT mappings resolvers with the symbols already loaded....
ELFAOTSymbols LoadELFSplitSymbolFromFixturesIfNeccessary(std::string elf_split_filename)
Attempts to resolve split loading unit AOT symbols from the portable ELF loader. If the dart code doe...
Definition elf_loader.cc:65
const char * GetTestingAssetsPath()
Returns the directory containing assets shared across all tests.
constexpr const char * kDefaultAOTAppELFSplitFileName
Definition elf_loader.h:23
constexpr const char * kDefaultAOTAppELFFileName
Definition elf_loader.h:16
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27
std::vector< std::unique_ptr< const fml::Mapping > > Mappings
Definition settings.h:88
std::string JoinPaths(std::initializer_list< std::string > components)
Definition paths.cc:14
std::function< void()> closure
Definition closure.h:14
Definition ref_ptr.h:261
fml::UniqueFD::element_type assets_dir
Definition settings.h:331
std::vector< std::string > vmservice_snapshot_library_path
Definition settings.h:138
TaskObserverRemove task_observer_remove
Definition settings.h:282
MappingsCallback application_kernels
Definition settings.h:142
TaskObserverAdd task_observer_add
Definition settings.h:281
fml::closure isolate_create_callback
Definition settings.h:288