Flutter Engine
fixture_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 "flutter/testing/fixture_test.h"
6 
7 namespace flutter {
8 namespace testing {
9 
11  : native_resolver_(std::make_shared<TestDartNativeResolver>()),
12  assets_dir_(fml::OpenDirectory(GetFixturesPath(),
13  false,
14  fml::FilePermission::kRead)),
15  aot_symbols_(LoadELFSymbolFromFixturesIfNeccessary()) {}
16 
18  Settings settings;
19  settings.leak_vm = false;
20  settings.task_observer_add = [](intptr_t, fml::closure) {};
21  settings.task_observer_remove = [](intptr_t) {};
22  settings.isolate_create_callback = [this]() {
23  native_resolver_->SetNativeResolverForIsolate();
24  };
25  settings.enable_observatory = false;
26  SetSnapshotsAndAssets(settings);
27  return settings;
28 }
29 
31  if (!assets_dir_.is_valid()) {
32  return;
33  }
34 
35  settings.assets_dir = assets_dir_.get();
36 
37  // In JIT execution, all snapshots are present within the binary itself and
38  // don't need to be explicitly supplied by the embedder. In AOT, these
39  // snapshots will be present in the application AOT dylib.
41  FML_CHECK(PrepareSettingsForAOTWithSymbols(settings, aot_symbols_));
42  } else {
43  settings.application_kernels = [this]() -> Mappings {
44  std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
45  auto kernel_mapping =
46  fml::FileMapping::CreateReadOnly(assets_dir_, "kernel_blob.bin");
47  if (!kernel_mapping || !kernel_mapping->IsValid()) {
48  FML_LOG(ERROR) << "Could not find kernel blob for test fixture not "
49  "running in precompiled mode.";
50  return kernel_mappings;
51  }
52  kernel_mappings.emplace_back(std::move(kernel_mapping));
53  return kernel_mappings;
54  };
55  }
56 }
57 
59  Dart_NativeFunction callback) {
60  native_resolver_->AddNativeCallback(std::move(name), callback);
61 }
62 
63 } // namespace testing
64 } // namespace flutter
MappingsCallback application_kernels
Definition: settings.h:93
fml::UniqueFD::element_type assets_dir
Definition: settings.h:215
fml::closure isolate_create_callback
Definition: settings.h:177
Definition: ref_ptr.h:252
#define FML_LOG(severity)
Definition: logging.h:65
const T & get() const
Definition: unique_object.h:87
Definition: ascii_trie.cc:9
bool is_valid() const
Definition: unique_object.h:89
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
Definition: file_posix.cc:94
std::vector< std::unique_ptr< const fml::Mapping > > Mappings
Definition: settings.h:57
std::function< void()> closure
Definition: closure.h:14
FilePermission
Definition: file.h:24
virtual Settings CreateSettingsForFixture()
Definition: fixture_test.cc:17
std::shared_ptr< TestDartNativeResolver > native_resolver_
Definition: fixture_test.h:31
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
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:199
TaskObserverAdd task_observer_add
Definition: settings.h:170
bool enable_observatory
Definition: settings.h:129
const char * name
Definition: fuchsia.cc:50
#define FML_CHECK(condition)
Definition: logging.h:68
void AddNativeCallback(std::string name, Dart_NativeFunction callback)
Definition: fixture_test.cc:58
TaskObserverRemove task_observer_remove
Definition: settings.h:171
void SetSnapshotsAndAssets(Settings &settings)
Definition: fixture_test.cc:30
static std::unique_ptr< FileMapping > CreateReadOnly(const std::string &path)
Definition: mapping.cc:18
ELFAOTSymbols LoadELFSymbolFromFixturesIfNeccessary()
Attempts to resolve AOT symbols from the portable ELF loader. This location is automatically resolved...
Definition: elf_loader.cc:15
bool PrepareSettingsForAOTWithSymbols(Settings &settings, const ELFAOTSymbols &symbols)
Prepare the settings objects various AOT mappings resolvers with the symbols already loaded...
Definition: elf_loader.cc:63