From cb3d3592d4740774e5c799639d8d68868b2716ef Mon Sep 17 00:00:00 2001 From: Siva Date: Tue, 20 Jul 2021 11:14:54 -0700 Subject: [PATCH] Add embedder unit test that reproduces https://github.com/dart-lang/sdk/issues/46275 (#27392) * Add embedder unit test that reproduces the problem described in https://github.com/dart-lang/sdk/issues/46275 * Address code review comments. --- shell/platform/embedder/fixtures/main.dart | 17 +++++++++++++---- .../embedder/tests/embedder_unittests.cc | 9 +++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/shell/platform/embedder/fixtures/main.dart b/shell/platform/embedder/fixtures/main.dart index 9ec4a2c6a87dd..bd2232b656f62 100644 --- a/shell/platform/embedder/fixtures/main.dart +++ b/shell/platform/embedder/fixtures/main.dart @@ -3,12 +3,13 @@ // found in the LICENSE file. import 'dart:async'; +import 'dart:convert'; +import 'dart:core'; +import 'dart:ffi'; +import 'dart:io'; +import 'dart:isolate'; import 'dart:typed_data'; import 'dart:ui'; -import 'dart:isolate'; -import 'dart:ffi'; -import 'dart:core'; -import 'dart:convert'; void main() {} @@ -32,6 +33,14 @@ void sayHiFromCustomEntrypoint2() native 'SayHiFromCustomEntrypoint2'; void sayHiFromCustomEntrypoint3() native 'SayHiFromCustomEntrypoint3'; +@pragma('vm:entry-point') +void terminateExitCodeHandler() { + final ProcessResult result = Process.runSync( + 'ls', [] + ); +} + + @pragma('vm:entry-point') void invokePlatformTaskRunner() { PlatformDispatcher.instance.sendPlatformMessage('OhHi', null, null); diff --git a/shell/platform/embedder/tests/embedder_unittests.cc b/shell/platform/embedder/tests/embedder_unittests.cc index 9a57e1aae5f89..ea9904d9c0e1f 100644 --- a/shell/platform/embedder/tests/embedder_unittests.cc +++ b/shell/platform/embedder/tests/embedder_unittests.cc @@ -123,6 +123,15 @@ TEST_F(EmbedderTest, CanInvokeCustomEntrypointMacro) { ASSERT_TRUE(engine.is_valid()); } +TEST_F(EmbedderTest, CanTerminateCleanly) { + auto& context = GetEmbedderContext(EmbedderTestContextType::kSoftwareContext); + EmbedderConfigBuilder builder(context); + builder.SetSoftwareRendererConfig(); + builder.SetDartEntrypoint("terminateExitCodeHandler"); + auto engine = builder.LaunchEngine(); + ASSERT_TRUE(engine.is_valid()); +} + std::atomic_size_t EmbedderTestTaskRunner::sEmbedderTaskRunnerIdentifiers = {}; TEST_F(EmbedderTest, CanSpecifyCustomPlatformTaskRunner) {