Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
flutter::testing::PlatformIsolateManagerTest Class Reference
Inheritance diagram for flutter::testing::PlatformIsolateManagerTest:
flutter::testing::FixtureTest flutter::testing::DartFixture flutter::testing::ThreadTest

Public Member Functions

 PlatformIsolateManagerTest ()
 
void TestWithRootIsolate (const std::function< void()> &test)
 
Dart_Isolate CreateAndRegisterIsolate (PlatformIsolateManager *mgr)
 
bool IsolateIsShutdown (Dart_Isolate isolate)
 
bool IsolateWasRegistered (Dart_Isolate isolate)
 
- Public Member Functions inherited from flutter::testing::FixtureTest
 FixtureTest ()
 
 FixtureTest (std::string kernel_filename, std::string elf_filename, std::string elf_split_filename)
 
- Public Member Functions inherited from flutter::testing::DartFixture
 DartFixture ()
 
 DartFixture (std::string kernel_filename, std::string elf_filename, std::string elf_split_filename)
 
virtual Settings CreateSettingsForFixture ()
 
void AddNativeCallback (const std::string &name, Dart_NativeFunction callback)
 
void AddFfiNativeCallback (const std::string &name, void *callback_ptr)
 
- Public Member Functions inherited from flutter::testing::ThreadTest
 ThreadTest ()
 
fml::RefPtr< fml::TaskRunnerGetCurrentTaskRunner ()
 Get the task runner for the thread that the current unit-test is running on. This creates a message loop as necessary.
 
fml::RefPtr< fml::TaskRunnerCreateNewThread (const std::string &name="")
 Creates a new thread, initializes a message loop on it, and, returns its task runner to the unit-test. The message loop is terminated (and its thread joined) when the test ends. This allows tests to create multiple named threads as necessary.
 

Additional Inherited Members

- Protected Member Functions inherited from flutter::testing::DartFixture
void SetSnapshotsAndAssets (Settings &settings)
 
- Protected Attributes inherited from flutter::testing::DartFixture
std::shared_ptr< TestDartNativeResolvernative_resolver_
 
ELFAOTSymbols split_aot_symbols_
 
std::string kernel_filename_
 
std::string elf_filename_
 
fml::UniqueFD assets_dir_
 
ELFAOTSymbols aot_symbols_
 

Detailed Description

Definition at line 36 of file platform_isolate_manager_unittests.cc.

Constructor & Destructor Documentation

◆ PlatformIsolateManagerTest()

flutter::testing::PlatformIsolateManagerTest::PlatformIsolateManagerTest ( )
inline

Definition at line 38 of file platform_isolate_manager_unittests.cc.

38{}

Member Function Documentation

◆ CreateAndRegisterIsolate()

Dart_Isolate flutter::testing::PlatformIsolateManagerTest::CreateAndRegisterIsolate ( PlatformIsolateManager mgr)
inline

Definition at line 84 of file platform_isolate_manager_unittests.cc.

84 {
85 if (isolate_data_map_.get() == nullptr) {
87 }
88
89 IsolateData* isolate_data = new IsolateData(mgr);
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;
95 EXPECT_TRUE(isolate);
96 Dart_ExitIsolate();
97
98 (*isolate_data_map_.get())[isolate].push_back(
99 std::unique_ptr<IsolateData>(isolate_data));
100 isolate_data->was_registered = mgr->RegisterPlatformIsolate(isolate);
101
102 return isolate;
103 }
const uint8_t uint32_t uint32_t GError ** error
std::unordered_map< Dart_Isolate, std::vector< std::unique_ptr< IsolateData > > > IsolateDataMap
static thread_local std::unique_ptr< IsolateDataMap > isolate_data_map_

References error, flutter::testing::IsolateData::isolate, flutter::testing::isolate_data_map_, flutter::PlatformIsolateManager::RegisterPlatformIsolate(), and flutter::testing::IsolateData::was_registered.

◆ IsolateIsShutdown()

bool flutter::testing::PlatformIsolateManagerTest::IsolateIsShutdown ( Dart_Isolate  isolate)
inline

Definition at line 105 of file platform_isolate_manager_unittests.cc.

105 {
106 EXPECT_EQ(1u, isolate_data_map_.get()->count(isolate));
107 EXPECT_LT(0u, (*isolate_data_map_.get())[isolate].size());
108 return (*isolate_data_map_.get())[isolate].back()->is_shutdown;
109 }

References flutter::testing::isolate_data_map_.

◆ IsolateWasRegistered()

bool flutter::testing::PlatformIsolateManagerTest::IsolateWasRegistered ( Dart_Isolate  isolate)
inline

Definition at line 111 of file platform_isolate_manager_unittests.cc.

111 {
112 EXPECT_EQ(1u, isolate_data_map_.get()->count(isolate));
113 EXPECT_LT(0u, (*isolate_data_map_.get())[isolate].size());
114 return (*isolate_data_map_.get())[isolate].back()->was_registered;
115 }

References flutter::testing::isolate_data_map_.

◆ TestWithRootIsolate()

void flutter::testing::PlatformIsolateManagerTest::TestWithRootIsolate ( const std::function< void()> &  test)
inline

Definition at line 40 of file platform_isolate_manager_unittests.cc.

40 {
41 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
42 auto settings = CreateSettingsForFixture();
43 auto vm_ref = DartVMRef::Create(settings);
44 ASSERT_TRUE(vm_ref);
45 auto vm_data = vm_ref.GetVMData();
46 ASSERT_TRUE(vm_data);
47
48 TaskRunners task_runners(GetCurrentTestName(), //
53 );
54
55 auto isolate_configuration =
57
58 UIDartState::Context context(task_runners);
59 context.advisory_script_uri = "main.dart";
60 context.advisory_script_entrypoint = "main";
61 auto weak_isolate = DartIsolate::CreateRunningRootIsolate(
62 vm_data->GetSettings(), // settings
63 vm_data->GetIsolateSnapshot(), // isolate snapshot
64 nullptr, // platform configuration
65 DartIsolate::Flags{}, // flags
66 nullptr, // root_isolate_create_callback
67 settings.isolate_create_callback, // isolate create callback
68 settings.isolate_shutdown_callback, // isolate shutdown callback
69 "main", // dart entrypoint
70 std::nullopt, // dart entrypoint library
71 {}, // dart entrypoint arguments
72 std::move(isolate_configuration), // isolate configuration
73 context // engine context
74 );
75 root_isolate_ = weak_isolate.lock()->isolate();
76 ASSERT_TRUE(root_isolate_);
77
78 test();
79
80 Dart_EnterIsolate(root_isolate_);
81 Dart_ShutdownIsolate();
82 }
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...
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition testing.cc:14

References flutter::UIDartState::Context::advisory_script_entrypoint, flutter::UIDartState::Context::advisory_script_uri, flutter::DartVMRef::Create(), flutter::DartIsolate::CreateRunningRootIsolate(), flutter::testing::DartFixture::CreateSettingsForFixture(), flutter::testing::ThreadTest::GetCurrentTaskRunner(), flutter::testing::GetCurrentTestName(), flutter::IsolateConfiguration::InferFromSettings(), and flutter::DartVMRef::IsInstanceRunning().


The documentation for this class was generated from the following file: