forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime_test.cc
89 lines (73 loc) · 2.68 KB
/
runtime_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// 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"
namespace flutter {
namespace testing {
RuntimeTest::RuntimeTest()
: native_resolver_(std::make_shared<TestDartNativeResolver>()) {}
RuntimeTest::~RuntimeTest() = default;
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]() {
return fml::FileMapping::CreateReadOnly(assets_dir_, "vm_snapshot_data");
};
settings.isolate_snapshot_data = [this]() {
return fml::FileMapping::CreateReadOnly(assets_dir_,
"isolate_snapshot_data");
};
if (DartVM::IsRunningPrecompiledCode()) {
settings.vm_snapshot_instr = [this]() {
return fml::FileMapping::CreateReadExecute(assets_dir_,
"vm_snapshot_instr");
};
settings.isolate_snapshot_instr = [this]() {
return fml::FileMapping::CreateReadExecute(assets_dir_,
"isolate_snapshot_instr");
};
}
} else {
settings.application_kernels = [this]() {
std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
kernel_mappings.emplace_back(
fml::FileMapping::CreateReadOnly(assets_dir_, "kernel_blob.bin"));
return kernel_mappings;
};
}
}
Settings RuntimeTest::CreateSettingsForFixture() {
Settings settings;
settings.leak_vm = false;
settings.task_observer_add = [](intptr_t, fml::closure) {};
settings.task_observer_remove = [](intptr_t) {};
settings.isolate_create_callback = [this]() {
native_resolver_->SetNativeResolverForIsolate();
};
SetSnapshotsAndAssets(settings);
return settings;
}
// |testing::ThreadTest|
void RuntimeTest::SetUp() {
assets_dir_ =
fml::OpenDirectory(GetFixturesPath(), false, fml::FilePermission::kRead);
ThreadTest::SetUp();
}
// |testing::ThreadTest|
void RuntimeTest::TearDown() {
ThreadTest::TearDown();
assets_dir_.reset();
}
void RuntimeTest::AddNativeCallback(std::string name,
Dart_NativeFunction callback) {
native_resolver_->AddNativeCallback(std::move(name), callback);
}
} // namespace testing
} // namespace flutter