29 std::unordered_map<Dart_Isolate, std::vector<std::unique_ptr<IsolateData>>>;
45 auto vm_data = vm_ref.GetVMData();
55 auto isolate_configuration =
62 vm_data->GetSettings(),
63 vm_data->GetIsolateSnapshot(),
67 settings.isolate_create_callback,
68 settings.isolate_shutdown_callback,
72 std::move(isolate_configuration),
75 root_isolate_ = weak_isolate.lock()->isolate();
76 ASSERT_TRUE(root_isolate_);
80 Dart_EnterIsolate(root_isolate_);
81 Dart_ShutdownIsolate();
90 char*
error =
nullptr;
91 Dart_Isolate isolate =
92 Dart_CreateIsolateInGroup(root_isolate_,
"TestIsolate", OnShutdown,
93 nullptr, isolate_data, &
error);
94 isolate_data->
isolate = isolate;
99 std::unique_ptr<IsolateData>(isolate_data));
118 Dart_Isolate root_isolate_ =
nullptr;
120 static void OnShutdown(
void*,
void* raw_isolate_data) {
123 EXPECT_TRUE(isolate_data->
isolate);
135 TestWithRootIsolate([
this]() {
140 Dart_Isolate isolateA = CreateAndRegisterIsolate(&mgr);
141 ASSERT_TRUE(isolateA);
142 EXPECT_FALSE(IsolateIsShutdown(isolateA));
143 EXPECT_TRUE(IsolateWasRegistered(isolateA));
146 Dart_Isolate isolateB = CreateAndRegisterIsolate(&mgr);
147 ASSERT_TRUE(isolateB);
148 EXPECT_FALSE(IsolateIsShutdown(isolateB));
149 EXPECT_TRUE(IsolateWasRegistered(isolateB));
156 EXPECT_TRUE(IsolateIsShutdown(isolateA));
158 EXPECT_TRUE(IsolateIsShutdown(isolateB));
164 TestWithRootIsolate([
this]() {
168 Dart_Isolate isolateA = CreateAndRegisterIsolate(&mgr);
169 ASSERT_TRUE(isolateA);
170 EXPECT_FALSE(IsolateIsShutdown(isolateA));
171 EXPECT_TRUE(IsolateWasRegistered(isolateA));
174 Dart_Isolate isolateB = CreateAndRegisterIsolate(&mgr);
175 ASSERT_TRUE(isolateB);
176 EXPECT_FALSE(IsolateIsShutdown(isolateB));
177 EXPECT_TRUE(IsolateWasRegistered(isolateB));
180 Dart_EnterIsolate(isolateA);
181 Dart_ShutdownIsolate();
182 EXPECT_TRUE(IsolateIsShutdown(isolateA));
185 Dart_EnterIsolate(isolateB);
186 Dart_ShutdownIsolate();
187 EXPECT_TRUE(IsolateIsShutdown(isolateB));
193 EXPECT_TRUE(IsolateIsShutdown(isolateA));
195 EXPECT_TRUE(IsolateIsShutdown(isolateB));
201 TestWithRootIsolate([
this]() {
205 Dart_Isolate isolateA = CreateAndRegisterIsolate(&mgr);
206 ASSERT_TRUE(isolateA);
207 EXPECT_FALSE(IsolateIsShutdown(isolateA));
208 EXPECT_TRUE(IsolateWasRegistered(isolateA));
214 EXPECT_TRUE(IsolateIsShutdown(isolateA));
217 Dart_Isolate isolateB = CreateAndRegisterIsolate(&mgr);
218 ASSERT_TRUE(isolateB);
219 EXPECT_FALSE(IsolateIsShutdown(isolateB));
220 EXPECT_FALSE(IsolateWasRegistered(isolateB));
223 Dart_EnterIsolate(isolateB);
224 Dart_ShutdownIsolate();
225 EXPECT_TRUE(IsolateIsShutdown(isolateB));
233 TestWithRootIsolate([
this]() {
237 std::atomic<bool> test_finished =
false;
238 std::vector<std::thread> threads;
240 for (
int i = 0;
i < 10; ++
i) {
241 threads.push_back(std::thread([
this, &mgr, &test_finished]() {
242 for (
int j = 0; j < 100; ++j) {
243 Dart_Isolate isolate = CreateAndRegisterIsolate(&mgr);
244 ASSERT_TRUE(isolate);
246 if (!IsolateWasRegistered(isolate)) {
247 Dart_EnterIsolate(isolate);
248 Dart_ShutdownIsolate();
251 while (!test_finished.load()) {
261 test_finished =
true;
262 for (
auto& thread : threads) {
static std::weak_ptr< DartIsolate > CreateRunningRootIsolate(const Settings &settings, const fml::RefPtr< const DartSnapshot > &isolate_snapshot, std::unique_ptr< PlatformConfiguration > platform_configuration, Flags flags, const fml::closure &root_isolate_create_callback, const fml::closure &isolate_create_callback, const fml::closure &isolate_shutdown_callback, std::optional< std::string > dart_entrypoint, std::optional< std::string > dart_entrypoint_library, const std::vector< std::string > &dart_entrypoint_args, std::unique_ptr< IsolateConfiguration > isolate_configuration, const UIDartState::Context &context, const DartIsolate *spawning_isolate=nullptr, std::shared_ptr< NativeAssetsManager > native_assets_manager=nullptr)
Creates an instance of a root isolate and returns a weak pointer to the same. The isolate instance ma...
static DartVMRef Create(const Settings &settings, fml::RefPtr< const DartSnapshot > vm_snapshot=nullptr, fml::RefPtr< const DartSnapshot > isolate_snapshot=nullptr)
static bool IsInstanceRunning()
static std::unique_ptr< IsolateConfiguration > InferFromSettings(const Settings &settings, const std::shared_ptr< AssetManager > &asset_manager=nullptr, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer the isolate configuration from the Settings object. If the VM is configured for AOT...
virtual Settings CreateSettingsForFixture()
fml::RefPtr< fml::TaskRunner > GetCurrentTaskRunner()
Get the task runner for the thread that the current unit-test is running on. This creates a message l...
const uint8_t uint32_t uint32_t GError ** error
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
TEST_F(DisplayListTest, Defaults)
std::unordered_map< Dart_Isolate, std::vector< std::unique_ptr< IsolateData > > > IsolateDataMap
static thread_local std::unique_ptr< IsolateDataMap > isolate_data_map_
The subset of state which is owned by the shell or engine and passed through the RuntimeController in...
std::string advisory_script_uri
std::string advisory_script_entrypoint
PlatformIsolateManager * mgr
IsolateData(PlatformIsolateManager *_mgr)