Flutter Engine
The Flutter Engine
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
5#include "flutter/testing/dart_fixture.h"
6
7#include <utility>
8#include "flutter/fml/paths.h"
9
10namespace flutter::testing {
11
13 : DartFixture("kernel_blob.bin",
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
32 settings.leak_vm = false;
33 settings.task_observer_add = [](intptr_t, const fml::closure&) {};
34 settings.task_observer_remove = [](intptr_t) {};
35 settings.isolate_create_callback = [this]() {
36 native_resolver_->SetNativeResolverForIsolate();
37 };
38 settings.enable_vm_service = false;
40 return settings;
41}
42
44 if (!assets_dir_.is_valid()) {
45 return;
46 }
47
48 settings.assets_dir = assets_dir_.get();
49
50 // In JIT execution, all snapshots are present within the binary itself and
51 // don't need to be explicitly supplied by the embedder. In AOT, these
52 // snapshots will be present in the application AOT dylib.
55#if FML_OS_LINUX
56 settings.vmservice_snapshot_library_path.emplace_back(fml::paths::JoinPaths(
57 {GetTestingAssetsPath(), "libvmservice_snapshot.so"}));
58#endif // FML_OS_LINUX
59 } else {
60 settings.application_kernels = [this]() -> Mappings {
61 std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
62 auto kernel_mapping =
64 if (!kernel_mapping || !kernel_mapping->IsValid()) {
65 FML_LOG(ERROR) << "Could not find kernel blob for test fixture not "
66 "running in precompiled mode.";
67 return kernel_mappings;
68 }
69 kernel_mappings.emplace_back(std::move(kernel_mapping));
70 return kernel_mappings;
71 };
72 }
73}
74
75void DartFixture::AddNativeCallback(const std::string& name,
77 native_resolver_->AddNativeCallback(name, callback);
78}
79
81 void* callback_ptr) {
82 native_resolver_->AddFfiNativeCallback(name, callback_ptr);
83}
84
85} // 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:205
void SetSnapshotsAndAssets(Settings &settings)
Definition: dart_fixture.cc:43
void AddFfiNativeCallback(const std::string &name, void *callback_ptr)
Definition: dart_fixture.cc:80
virtual Settings CreateSettingsForFixture()
Definition: dart_fixture.cc:30
void AddNativeCallback(const std::string &name, Dart_NativeFunction callback)
Definition: dart_fixture.cc:75
std::shared_ptr< TestDartNativeResolver > native_resolver_
Definition: dart_fixture.h:37
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
Definition: mapping.cc:20
bool is_valid() const
Definition: unique_object.h:89
const T & get() const
Definition: unique_object.h:87
void(* Dart_NativeFunction)(Dart_NativeArguments arguments)
Definition: dart_api.h:3207
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_CHECK(condition)
Definition: logging.h:85
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:17
bool PrepareSettingsForAOTWithSymbols(Settings &settings, const ELFAOTSymbols &symbols)
Prepare the settings objects various AOT mappings resolvers with the symbols already loaded....
Definition: elf_loader.cc:116
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:66
const char * GetTestingAssetsPath()
Returns the directory containing assets shared across all tests.
constexpr const char * kDefaultAOTAppELFSplitFileName
Definition: elf_loader.h:24
constexpr const char * kDefaultAOTAppELFFileName
Definition: elf_loader.h:17
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
std::vector< std::unique_ptr< const fml::Mapping > > Mappings
Definition: settings.h:94
std::string JoinPaths(std::initializer_list< std::string > components)
Definition: paths.cc:14
Definition: ascii_trie.cc:9
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:97
std::function< void()> closure
Definition: closure.h:14
FilePermission
Definition: file.h:24
Definition: ref_ptr.h:256
#define ERROR(message)
Definition: elf_loader.cc:260