Skip to content

Commit d8b9f29

Browse files
authored
Revert "In the test harness, don’t attempt to load AOT snapshots from non-existent dylibs. (flutter-team-archive#16210)"
This reverts commit 34e8604.
1 parent a58afab commit d8b9f29

2 files changed

Lines changed: 32 additions & 59 deletions

File tree

shell/platform/embedder/tests/embedder_test_context.cc

Lines changed: 31 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "flutter/shell/platform/embedder/tests/embedder_test_context.h"
66

77
#include "flutter/fml/make_copyable.h"
8-
#include "flutter/fml/paths.h"
98
#include "flutter/runtime/dart_vm.h"
109
#include "flutter/shell/platform/embedder/tests/embedder_assertions.h"
1110
#include "third_party/dart/runtime/bin/elf_loader.h"
@@ -14,12 +13,40 @@
1413
namespace flutter {
1514
namespace testing {
1615

17-
static constexpr const char* kAppAOTELFFileName = "app_elf_snapshot.so";
18-
1916
EmbedderTestContext::EmbedderTestContext(std::string assets_path)
2017
: assets_path_(std::move(assets_path)),
2118
native_resolver_(std::make_shared<TestDartNativeResolver>()) {
22-
SetupAOTMappingsIfNecessary();
19+
auto assets_dir = fml::OpenDirectory(assets_path_.c_str(), false,
20+
fml::FilePermission::kRead);
21+
22+
if (flutter::DartVM::IsRunningPrecompiledCode()) {
23+
std::string filename(assets_path_);
24+
filename += "/app_elf_snapshot.so";
25+
26+
const uint8_t *vm_snapshot_data = nullptr,
27+
*vm_snapshot_instructions = nullptr,
28+
*isolate_snapshot_data = nullptr,
29+
*isolate_snapshot_instructions = nullptr;
30+
const char* error = nullptr;
31+
32+
elf_library_handle_ =
33+
Dart_LoadELF(filename.c_str(), /*file_offset=*/0, &error,
34+
&vm_snapshot_data, &vm_snapshot_instructions,
35+
&isolate_snapshot_data, &isolate_snapshot_instructions);
36+
37+
if (elf_library_handle_ != nullptr) {
38+
vm_snapshot_data_.reset(new fml::NonOwnedMapping(vm_snapshot_data, 0));
39+
vm_snapshot_instructions_.reset(
40+
new fml::NonOwnedMapping(vm_snapshot_instructions, 0));
41+
isolate_snapshot_data_.reset(
42+
new fml::NonOwnedMapping(isolate_snapshot_data, 0));
43+
isolate_snapshot_instructions_.reset(
44+
new fml::NonOwnedMapping(isolate_snapshot_instructions, 0));
45+
} else {
46+
FML_LOG(WARNING) << "Could not load snapshot: " << error;
47+
}
48+
}
49+
2350
isolate_create_callbacks_.push_back(
2451
[weak_resolver =
2552
std::weak_ptr<TestDartNativeResolver>{native_resolver_}]() {
@@ -30,64 +57,11 @@ EmbedderTestContext::EmbedderTestContext(std::string assets_path)
3057
}
3158

3259
EmbedderTestContext::~EmbedderTestContext() {
33-
vm_snapshot_data_.reset();
34-
vm_snapshot_instructions_.reset();
35-
isolate_snapshot_data_.reset();
36-
isolate_snapshot_instructions_.reset();
3760
if (elf_library_handle_ != nullptr) {
3861
Dart_UnloadELF(elf_library_handle_);
3962
}
4063
}
4164

42-
void EmbedderTestContext::SetupAOTMappingsIfNecessary() {
43-
if (!DartVM::IsRunningPrecompiledCode()) {
44-
// Not in AOT mode. Nothing to do.
45-
return;
46-
}
47-
48-
auto elf_path = fml::paths::JoinPaths({assets_path_, kAppAOTELFFileName});
49-
50-
if (!fml::IsFile(elf_path.c_str())) {
51-
FML_LOG(ERROR) << "Could not find the applications AOT ELF file in an "
52-
"AOT environment. Engine launches attempted with this "
53-
"context will fail. File not found: "
54-
<< elf_path;
55-
return;
56-
}
57-
58-
const uint8_t* vm_snapshot_data = nullptr;
59-
const uint8_t* vm_snapshot_instructions = nullptr;
60-
const uint8_t* isolate_snapshot_data = nullptr;
61-
const uint8_t* isolate_snapshot_instructions = nullptr;
62-
63-
const char* error = nullptr;
64-
65-
elf_library_handle_ =
66-
Dart_LoadELF(elf_path.c_str(), // filename
67-
0u, // file offset
68-
&error, // error (must not be freed)
69-
&vm_snapshot_data, // VM snapshot data
70-
&vm_snapshot_instructions, // VM snapshot instructions
71-
&isolate_snapshot_data, // VM isolate data
72-
&isolate_snapshot_instructions // VM isolate instructions
73-
);
74-
75-
if (elf_library_handle_ == nullptr) {
76-
FML_LOG(ERROR) << "Could not load snapshot in an AOT environment. Engine "
77-
"launches attempted with this context will fail. Error: "
78-
<< error;
79-
return;
80-
}
81-
82-
vm_snapshot_data_.reset(new fml::NonOwnedMapping(vm_snapshot_data, 0));
83-
vm_snapshot_instructions_.reset(
84-
new fml::NonOwnedMapping(vm_snapshot_instructions, 0));
85-
isolate_snapshot_data_.reset(
86-
new fml::NonOwnedMapping(isolate_snapshot_data, 0));
87-
isolate_snapshot_instructions_.reset(
88-
new fml::NonOwnedMapping(isolate_snapshot_instructions, 0));
89-
}
90-
9165
const std::string& EmbedderTestContext::GetAssetsPath() const {
9266
return assets_path_;
9367
}

shell/platform/embedder/tests/embedder_test_context.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class EmbedderTestContext {
8181
std::unique_ptr<fml::Mapping> vm_snapshot_instructions_;
8282
std::unique_ptr<fml::Mapping> isolate_snapshot_data_;
8383
std::unique_ptr<fml::Mapping> isolate_snapshot_instructions_;
84+
8485
std::vector<fml::closure> isolate_create_callbacks_;
8586
std::shared_ptr<TestDartNativeResolver> native_resolver_;
8687
SemanticsNodeCallback update_semantics_node_callback_;
@@ -101,8 +102,6 @@ class EmbedderTestContext {
101102
static FlutterUpdateSemanticsCustomActionCallback
102103
GetUpdateSemanticsCustomActionCallbackHook();
103104

104-
void SetupAOTMappingsIfNecessary();
105-
106105
void SetupCompositor();
107106

108107
void FireIsolateCreateCallbacks();

0 commit comments

Comments
 (0)