2019-03-29 17:15:38 -07:00
|
|
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
#include "flutter/runtime/runtime_test.h"
|
|
|
|
|
|
|
|
|
|
#include "flutter/runtime/dart_vm.h"
|
|
|
|
|
#include "flutter/testing/testing.h"
|
|
|
|
|
|
2019-04-09 12:44:42 -07:00
|
|
|
namespace flutter {
|
2019-03-29 17:15:38 -07:00
|
|
|
namespace testing {
|
|
|
|
|
|
2019-03-29 17:53:49 -07:00
|
|
|
RuntimeTest::RuntimeTest()
|
2019-12-03 14:33:02 -08:00
|
|
|
: native_resolver_(std::make_shared<TestDartNativeResolver>()),
|
|
|
|
|
assets_dir_(fml::OpenDirectory(GetFixturesPath(),
|
|
|
|
|
false,
|
|
|
|
|
fml::FilePermission::kRead)) {}
|
2019-03-29 17:15:38 -07:00
|
|
|
|
|
|
|
|
void RuntimeTest::SetSnapshotsAndAssets(Settings& settings) {
|
|
|
|
|
if (!assets_dir_.is_valid()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settings.assets_dir = assets_dir_.get();
|
|
|
|
|
|
|
|
|
|
// In JIT execution, all snapshots are present within the binary itself and
|
|
|
|
|
// don't need to be explicitly suppiled by the embedder.
|
|
|
|
|
if (DartVM::IsRunningPrecompiledCode()) {
|
|
|
|
|
settings.vm_snapshot_data = [this]() {
|
2019-04-19 12:48:53 -07:00
|
|
|
return fml::FileMapping::CreateReadOnly(assets_dir_, "vm_snapshot_data");
|
2019-03-29 17:15:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
settings.isolate_snapshot_data = [this]() {
|
2019-04-19 12:48:53 -07:00
|
|
|
return fml::FileMapping::CreateReadOnly(assets_dir_,
|
|
|
|
|
"isolate_snapshot_data");
|
2019-03-29 17:15:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (DartVM::IsRunningPrecompiledCode()) {
|
|
|
|
|
settings.vm_snapshot_instr = [this]() {
|
2019-04-19 12:48:53 -07:00
|
|
|
return fml::FileMapping::CreateReadExecute(assets_dir_,
|
|
|
|
|
"vm_snapshot_instr");
|
2019-03-29 17:15:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
settings.isolate_snapshot_instr = [this]() {
|
2019-04-19 12:48:53 -07:00
|
|
|
return fml::FileMapping::CreateReadExecute(assets_dir_,
|
|
|
|
|
"isolate_snapshot_instr");
|
2019-03-29 17:15:38 -07:00
|
|
|
};
|
|
|
|
|
}
|
2019-04-05 13:34:40 -07:00
|
|
|
} else {
|
|
|
|
|
settings.application_kernels = [this]() {
|
|
|
|
|
std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
|
|
|
|
|
kernel_mappings.emplace_back(
|
2019-04-19 12:48:53 -07:00
|
|
|
fml::FileMapping::CreateReadOnly(assets_dir_, "kernel_blob.bin"));
|
2019-04-05 13:34:40 -07:00
|
|
|
return kernel_mappings;
|
|
|
|
|
};
|
2019-03-29 17:15:38 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 17:53:49 -07:00
|
|
|
Settings RuntimeTest::CreateSettingsForFixture() {
|
|
|
|
|
Settings settings;
|
2019-04-17 19:06:03 -07:00
|
|
|
settings.leak_vm = false;
|
2019-03-29 17:53:49 -07:00
|
|
|
settings.task_observer_add = [](intptr_t, fml::closure) {};
|
|
|
|
|
settings.task_observer_remove = [](intptr_t) {};
|
2019-04-19 17:36:36 -07:00
|
|
|
settings.isolate_create_callback = [this]() {
|
2019-03-29 17:53:49 -07:00
|
|
|
native_resolver_->SetNativeResolverForIsolate();
|
|
|
|
|
};
|
|
|
|
|
SetSnapshotsAndAssets(settings);
|
|
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RuntimeTest::AddNativeCallback(std::string name,
|
|
|
|
|
Dart_NativeFunction callback) {
|
|
|
|
|
native_resolver_->AddNativeCallback(std::move(name), callback);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 17:15:38 -07:00
|
|
|
} // namespace testing
|
2019-04-09 12:44:42 -07:00
|
|
|
} // namespace flutter
|