Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 89a2c96

Browse files
author
Emmanuel Garcia
committed
Explicitly test no dart plugin registrant
1 parent 1b426a7 commit 89a2c96

15 files changed

+150
-30
lines changed

BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ group("flutter") {
103103
"//flutter/flow:flow_unittests",
104104
"//flutter/fml:fml_unittests",
105105
"//flutter/lib/ui:ui_unittests",
106+
"//flutter/runtime:no_dart_plugin_registrant_unittests",
106107
"//flutter/runtime:runtime_unittests",
107108
"//flutter/shell/common:shell_unittests",
108109
"//flutter/shell/platform/embedder:embedder_proctable_unittests",

lib/ui/painting/image_decoder_unittests.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,9 @@ TEST_F(ImageDecoderFixtureTest,
637637
});
638638
latch.Wait();
639639

640-
auto isolate =
641-
RunDartCodeInIsolate(vm_ref, settings, runners, "main", {},
642-
GetFixturesPath(), io_manager->GetWeakIOManager());
640+
auto isolate = RunDartCodeInIsolate(vm_ref, settings, runners, "main", {},
641+
GetDefaultKernelFilePath(),
642+
io_manager->GetWeakIOManager());
643643

644644
// Latch the IO task runner.
645645
runners.GetIOTaskRunner()->PostTask([&]() { io_latch.Wait(); });

lib/ui/ui_benchmarks.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void BM_PlatformMessageResponseDartComplete(benchmark::State& state) {
3232
auto vm_ref = DartVMRef::Create(settings);
3333
auto isolate =
3434
testing::RunDartCodeInIsolate(vm_ref, settings, task_runners, "main", {},
35-
testing::GetFixturesPath(), {});
35+
testing::GetDefaultKernelFilePath(), {});
3636

3737
while (state.KeepRunning()) {
3838
state.PauseTiming();

runtime/BUILD.gn

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,24 @@ if (enable_unittests) {
136136
"//third_party/skia",
137137
]
138138
}
139+
140+
test_fixtures("no_dart_plugin_registrant_test") {
141+
dart_main = "fixtures/no_dart_plugin_registrant_test.dart"
142+
dart_kernel = "$target_gen_dir/assets/no_plugin_registrant_kernel_blob.bin"
143+
}
144+
145+
executable("no_dart_plugin_registrant_unittests") {
146+
testonly = true
147+
148+
sources = [ "no_dart_plugin_registrant_unittests.cc" ]
149+
150+
public_configs = [ "//flutter:export_dynamic_symbols" ]
151+
152+
public_deps = [
153+
":no_dart_plugin_registrant_test",
154+
"//flutter/fml",
155+
"//flutter/testing",
156+
"//flutter/testing:fixture_test",
157+
]
158+
}
139159
}

runtime/dart_isolate_unittests.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ TEST_F(DartIsolateTest, IsolateCanLoadAndRunDartCode) {
214214
GetCurrentTaskRunner() //
215215
);
216216
auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners, "main",
217-
{}, GetFixturesPath());
217+
{}, GetDefaultKernelFilePath());
218218
ASSERT_TRUE(isolate);
219219
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
220220
}
@@ -231,7 +231,7 @@ TEST_F(DartIsolateTest, IsolateCannotLoadAndRunUnknownDartEntrypoint) {
231231
);
232232
auto isolate =
233233
RunDartCodeInIsolate(vm_ref, settings, task_runners, "thisShouldNotExist",
234-
{}, GetFixturesPath());
234+
{}, GetDefaultKernelFilePath());
235235
ASSERT_FALSE(isolate);
236236
}
237237

@@ -246,7 +246,7 @@ TEST_F(DartIsolateTest, CanRunDartCodeCodeSynchronously) {
246246
GetCurrentTaskRunner() //
247247
);
248248
auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners, "main",
249-
{}, GetFixturesPath());
249+
{}, GetDefaultKernelFilePath());
250250

251251
ASSERT_TRUE(isolate);
252252
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
@@ -275,9 +275,9 @@ TEST_F(DartIsolateTest, CanRegisterNativeCallback) {
275275
thread, //
276276
thread //
277277
);
278-
auto isolate =
279-
RunDartCodeInIsolate(vm_ref, settings, task_runners,
280-
"canRegisterNativeCallback", {}, GetFixturesPath());
278+
auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners,
279+
"canRegisterNativeCallback", {},
280+
GetDefaultKernelFilePath());
281281
ASSERT_TRUE(isolate);
282282
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
283283
Wait();
@@ -307,7 +307,7 @@ TEST_F(DartIsolateTest, CanSaveCompilationTrace) {
307307
);
308308
auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners,
309309
"testCanSaveCompilationTrace", {},
310-
GetFixturesPath());
310+
GetDefaultKernelFilePath());
311311
ASSERT_TRUE(isolate);
312312
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
313313

@@ -367,7 +367,7 @@ TEST_F(DartSecondaryIsolateTest, CanLaunchSecondaryIsolates) {
367367
);
368368
auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners,
369369
"testCanLaunchSecondaryIsolate", {},
370-
GetFixturesPath());
370+
GetDefaultKernelFilePath());
371371
ASSERT_TRUE(isolate);
372372
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
373373
ChildShutdownWait(); // wait for child isolate to shutdown first
@@ -395,7 +395,7 @@ TEST_F(DartIsolateTest, CanRecieveArguments) {
395395
);
396396
auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners,
397397
"testCanRecieveArguments", {"arg1"},
398-
GetFixturesPath());
398+
GetDefaultKernelFilePath());
399399
ASSERT_TRUE(isolate);
400400
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
401401

@@ -477,7 +477,7 @@ TEST_F(DartIsolateTest,
477477
);
478478
{
479479
auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners, "main",
480-
{}, GetFixturesPath());
480+
{}, GetDefaultKernelFilePath());
481481
ASSERT_TRUE(isolate);
482482
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
483483
}
@@ -505,7 +505,7 @@ TEST_F(DartIsolateTest,
505505
);
506506
{
507507
auto isolate = RunDartCodeInIsolate(vm_ref, instance_settings, task_runners,
508-
"main", {}, GetFixturesPath());
508+
"main", {}, GetDefaultKernelFilePath());
509509
ASSERT_TRUE(isolate);
510510
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
511511
}
@@ -596,9 +596,9 @@ TEST_F(DartIsolateTest, DISABLED_ValidLoadingUnitSucceeds) {
596596
thread, //
597597
thread //
598598
);
599-
auto isolate =
600-
RunDartCodeInIsolate(vm_ref, settings, task_runners,
601-
"canCallDeferredLibrary", {}, GetFixturesPath());
599+
auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners,
600+
"canCallDeferredLibrary", {},
601+
GetDefaultKernelFilePath());
602602
ASSERT_TRUE(isolate);
603603
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
604604
Wait();
@@ -639,7 +639,7 @@ TEST_F(DartIsolateTest, DartPluginRegistrantIsCalled) {
639639
);
640640
auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners,
641641
"mainForPluginRegistrantTest", {},
642-
GetFixturesPath());
642+
GetDefaultKernelFilePath());
643643
ASSERT_TRUE(isolate);
644644
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
645645
latch.Wait();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
void passMessage(String message) native 'PassMessage';
6+
7+
void main() {
8+
passMessage('main() was called');
9+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "flutter/runtime/dart_isolate.h"
6+
7+
#include "flutter/fml/paths.h"
8+
#include "flutter/testing/fixture_test.h"
9+
#include "flutter/runtime/dart_vm.h"
10+
#include "flutter/runtime/dart_vm_lifecycle.h"
11+
#include "flutter/testing/dart_isolate_runner.h"
12+
#include "flutter/testing/testing.h"
13+
14+
namespace flutter {
15+
namespace testing {
16+
17+
const std::string kernel_file_name = "no_plugin_registrant_kernel_blob.bin";
18+
19+
class DartIsolateTest : public FixtureTest {
20+
public:
21+
DartIsolateTest() : FixtureTest(kernel_file_name) {}
22+
};
23+
24+
TEST_F(DartIsolateTest, DartPluginRegistrantIsNotPresent) {
25+
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
26+
27+
std::vector<std::string> messages;
28+
fml::AutoResetWaitableEvent latch;
29+
30+
AddNativeCallback(
31+
"PassMessage",
32+
CREATE_NATIVE_ENTRY(([&latch, &messages](Dart_NativeArguments args) {
33+
auto message = tonic::DartConverter<std::string>::FromDart(
34+
Dart_GetNativeArgument(args, 0));
35+
messages.push_back(message);
36+
latch.Signal();
37+
})));
38+
39+
const auto settings = CreateSettingsForFixture();
40+
auto vm_ref = DartVMRef::Create(settings);
41+
auto thread = CreateNewThread();
42+
TaskRunners task_runners(GetCurrentTestName(), //
43+
thread, //
44+
thread, //
45+
thread, //
46+
thread //
47+
);
48+
49+
50+
auto kernel_file_path = fml::paths::JoinPaths({GetFixturesPath(), kernel_file_name});
51+
auto isolate = RunDartCodeInIsolate(vm_ref, settings, task_runners,
52+
"main", {},
53+
kernel_file_path);
54+
55+
ASSERT_TRUE(isolate);
56+
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
57+
58+
latch.Wait();
59+
60+
ASSERT_EQ(messages.size(), 1u);
61+
ASSERT_EQ(messages[0], "main() was called");
62+
}
63+
64+
} // namespace testing
65+
} // namespace flutter

runtime/type_conversions_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TypeConversionsTest : public FixtureTest {
2828
thread, thread, thread);
2929
auto isolate =
3030
RunDartCodeInIsolate(vm_, settings_, single_threaded_task_runner,
31-
entrypoint, {}, GetFixturesPath());
31+
entrypoint, {}, GetDefaultKernelFilePath());
3232
if (!isolate || isolate->get()->GetPhase() != DartIsolate::Phase::Running) {
3333
return false;
3434
}

testing/dart_isolate_runner.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ std::unique_ptr<AutoIsolateShutdown> RunDartCodeInIsolateOnUITaskRunner(
5555
const TaskRunners& task_runners,
5656
std::string entrypoint,
5757
const std::vector<std::string>& args,
58-
const std::string& fixtures_path,
58+
const std::string& kernel_file_path,
5959
fml::WeakPtr<IOManager> io_manager,
6060
std::shared_ptr<VolatilePathTracker> volatile_path_tracker) {
6161
FML_CHECK(task_runners.GetUITaskRunner()->RunsTasksOnCurrentThread());
@@ -75,9 +75,6 @@ std::unique_ptr<AutoIsolateShutdown> RunDartCodeInIsolateOnUITaskRunner(
7575
settings.dart_entrypoint_args = args;
7676

7777
if (!DartVM::IsRunningPrecompiledCode()) {
78-
auto kernel_file_path =
79-
fml::paths::JoinPaths({fixtures_path, "kernel_blob.bin"});
80-
8178
if (!fml::IsFile(kernel_file_path)) {
8279
FML_LOG(ERROR) << "Could not locate kernel file.";
8380
return nullptr;
@@ -147,15 +144,15 @@ std::unique_ptr<AutoIsolateShutdown> RunDartCodeInIsolate(
147144
const TaskRunners& task_runners,
148145
std::string entrypoint,
149146
const std::vector<std::string>& args,
150-
const std::string& fixtures_path,
147+
const std::string& kernel_file_path,
151148
fml::WeakPtr<IOManager> io_manager,
152149
std::shared_ptr<VolatilePathTracker> volatile_path_tracker) {
153150
std::unique_ptr<AutoIsolateShutdown> result;
154151
fml::AutoResetWaitableEvent latch;
155152
fml::TaskRunner::RunNowOrPostTask(
156153
task_runners.GetUITaskRunner(), fml::MakeCopyable([&]() mutable {
157154
result = RunDartCodeInIsolateOnUITaskRunner(
158-
vm_ref, settings, task_runners, entrypoint, args, fixtures_path,
155+
vm_ref, settings, task_runners, entrypoint, args, kernel_file_path,
159156
io_manager, std::move(volatile_path_tracker));
160157
latch.Signal();
161158
}));

testing/fixture_test.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
namespace flutter {
88
namespace testing {
99

10-
FixtureTest::FixtureTest()
10+
FixtureTest::FixtureTest() : FixtureTest("kernel_blob.bin") {}
11+
12+
FixtureTest::FixtureTest(std::string kernel_file)
1113
: native_resolver_(std::make_shared<TestDartNativeResolver>()),
1214
split_aot_symbols_(LoadELFSplitSymbolFromFixturesIfNeccessary()),
15+
kernel_file_(kernel_file),
1316
assets_dir_(fml::OpenDirectory(GetFixturesPath(),
1417
false,
1518
fml::FilePermission::kRead)),
@@ -44,7 +47,7 @@ void FixtureTest::SetSnapshotsAndAssets(Settings& settings) {
4447
settings.application_kernels = [this]() -> Mappings {
4548
std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
4649
auto kernel_mapping =
47-
fml::FileMapping::CreateReadOnly(assets_dir_, "kernel_blob.bin");
50+
fml::FileMapping::CreateReadOnly(assets_dir_, kernel_file_);
4851
if (!kernel_mapping || !kernel_mapping->IsValid()) {
4952
FML_LOG(ERROR) << "Could not find kernel blob for test fixture not "
5053
"running in precompiled mode.";

testing/fixture_test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace testing {
2020
class FixtureTest : public ThreadTest {
2121
public:
2222
FixtureTest();
23+
FixtureTest(std::string kernel_file);
2324

2425
virtual Settings CreateSettingsForFixture();
2526

@@ -33,6 +34,7 @@ class FixtureTest : public ThreadTest {
3334
ELFAOTSymbols split_aot_symbols_;
3435

3536
private:
37+
std::string kernel_file_;
3638
fml::UniqueFD assets_dir_;
3739
ELFAOTSymbols aot_symbols_;
3840

testing/testing.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "testing.h"
66

77
#include "flutter/fml/file.h"
8+
#include "flutter/fml/paths.h"
89

910
namespace flutter {
1011
namespace testing {
@@ -13,6 +14,10 @@ std::string GetCurrentTestName() {
1314
return ::testing::UnitTest::GetInstance()->current_test_info()->name();
1415
}
1516

17+
std::string GetDefaultKernelFilePath() {
18+
return fml::paths::JoinPaths({GetFixturesPath(), "kernel_blob.bin"});
19+
}
20+
1621
fml::UniqueFD OpenFixturesDirectory() {
1722
auto fixtures_directory =
1823
OpenDirectory(GetFixturesPath(), // path

testing/testing.gni

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,13 @@ template("dart_snapshot") {
156156
testonly = true
157157

158158
dart_snapshot_kernel_target_name = "_dsk_$target_name"
159-
dart_snapshot_kernel_path = "$target_gen_dir/assets/kernel_blob.bin"
159+
160+
if (defined(invoker.dart_kernel)) {
161+
dart_snapshot_kernel_path = invoker.dart_kernel
162+
} else {
163+
dart_snapshot_kernel_path = "$target_gen_dir/assets/kernel_blob.bin"
164+
}
165+
160166
dart_snapshot_kernel(dart_snapshot_kernel_target_name) {
161167
dart_main = invoker.dart_main
162168
dart_kernel = dart_snapshot_kernel_path
@@ -257,7 +263,11 @@ template("test_fixtures") {
257263
dart_snapshot_target_name = "_ds_$target_name"
258264
dart_snapshot(dart_snapshot_target_name) {
259265
dart_main = invoker.dart_main
266+
if (defined(invoker.dart_kernel)) {
267+
dart_kernel = invoker.dart_kernel
268+
}
260269
}
270+
261271
test_public_deps += [ ":$dart_snapshot_target_name" ]
262272
}
263273

testing/testing.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ namespace testing {
2727
///
2828
const char* GetFixturesPath();
2929

30+
//------------------------------------------------------------------------------
31+
/// @brief Returns the default path to kernel_blob.bin. This file is within
32+
/// the directory returned by `GetFixturesPath()`.
33+
///
34+
/// @return The kernel file path.
35+
///
36+
std::string GetDefaultKernelFilePath();
37+
3038
//------------------------------------------------------------------------------
3139
/// @brief Opens the fixtures directory for the unit-test harness.
3240
///

third_party/tonic/tests/dart_weak_persistent_handle_unittest.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DartWeakPersistentHandle : public FixtureTest {
2525
thread, thread, thread);
2626
auto isolate =
2727
RunDartCodeInIsolate(vm_, settings_, single_threaded_task_runner,
28-
entrypoint, {}, GetFixturesPath());
28+
entrypoint, {}, GetDefaultKernelFilePath());
2929
if (!isolate || isolate->get()->GetPhase() != DartIsolate::Phase::Running) {
3030
return false;
3131
}

0 commit comments

Comments
 (0)