Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
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 35 of file platform_isolate_manager_unittests.cc.

Constructor & Destructor Documentation

◆ PlatformIsolateManagerTest()

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

Definition at line 37 of file platform_isolate_manager_unittests.cc.

37{}

Member Function Documentation

◆ CreateAndRegisterIsolate()

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

Definition at line 83 of file platform_isolate_manager_unittests.cc.

83 {
84 if (isolate_data_map_.get() == nullptr) {
86 }
87
88 IsolateData* isolate_data = new IsolateData(mgr);
89 char* error = nullptr;
90 Dart_Isolate isolate =
91 Dart_CreateIsolateInGroup(root_isolate_, "TestIsolate", OnShutdown,
92 nullptr, isolate_data, &error);
93 isolate_data->isolate = isolate;
94 EXPECT_TRUE(isolate);
96
97 (*isolate_data_map_.get())[isolate].push_back(
98 std::unique_ptr<IsolateData>(isolate_data));
99 isolate_data->was_registered = mgr->RegisterPlatformIsolate(isolate);
100
101 return isolate;
102 }
DART_EXPORT Dart_Isolate Dart_CreateIsolateInGroup(Dart_Isolate group_member, const char *name, Dart_IsolateShutdownCallback shutdown_callback, Dart_IsolateCleanupCallback cleanup_callback, void *child_isolate_data, char **error)
struct _Dart_Isolate * Dart_Isolate
Definition dart_api.h:88
DART_EXPORT void Dart_ExitIsolate(void)
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_
#define EXPECT_TRUE(handle)
Definition unit_test.h:685

◆ IsolateIsShutdown()

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

Definition at line 104 of file platform_isolate_manager_unittests.cc.

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

◆ IsolateWasRegistered()

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

Definition at line 110 of file platform_isolate_manager_unittests.cc.

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

◆ TestWithRootIsolate()

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

Definition at line 39 of file platform_isolate_manager_unittests.cc.

39 {
40 ASSERT_FALSE(DartVMRef::IsInstanceRunning());
42 auto vm_ref = DartVMRef::Create(settings);
43 ASSERT_TRUE(vm_ref);
44 auto vm_data = vm_ref.GetVMData();
45 ASSERT_TRUE(vm_data);
46
47 TaskRunners task_runners(GetCurrentTestName(), //
52 );
53
54 auto isolate_configuration =
56
57 UIDartState::Context context(task_runners);
58 context.advisory_script_uri = "main.dart";
59 context.advisory_script_entrypoint = "main";
60 auto weak_isolate = DartIsolate::CreateRunningRootIsolate(
61 vm_data->GetSettings(), // settings
62 vm_data->GetIsolateSnapshot(), // isolate snapshot
63 nullptr, // platform configuration
64 DartIsolate::Flags{}, // flags
65 nullptr, // root_isolate_create_callback
66 settings.isolate_create_callback, // isolate create callback
67 settings.isolate_shutdown_callback, // isolate shutdown callback
68 "main", // dart entrypoint
69 std::nullopt, // dart entrypoint library
70 {}, // dart entrypoint arguments
71 std::move(isolate_configuration), // isolate configuration
72 context // engine context
73 );
74 root_isolate_ = weak_isolate.lock()->isolate();
75 ASSERT_TRUE(root_isolate_);
76
77 test();
78
79 Dart_EnterIsolate(root_isolate_);
81 }
#define test(name)
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)
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...
DART_EXPORT void Dart_ShutdownIsolate(void)
DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate)
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:15

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