From 24ee83dbde24501a22b5a2cb6ec99000778ccd74 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Wed, 17 Apr 2019 19:42:33 -0700 Subject: [PATCH] Test saving compilation traces. (flutter/engine#8618) --- .../flutter/runtime/dart_isolate_unittests.cc | 25 +++++++++++++++++++ .../flutter/runtime/fixtures/simple_main.dart | 15 ++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/runtime/dart_isolate_unittests.cc b/engine/src/flutter/runtime/dart_isolate_unittests.cc index 1c77bc892ac..eb12946e935 100644 --- a/engine/src/flutter/runtime/dart_isolate_unittests.cc +++ b/engine/src/flutter/runtime/dart_isolate_unittests.cc @@ -13,6 +13,7 @@ #include "flutter/runtime/runtime_test.h" #include "flutter/testing/testing.h" #include "flutter/testing/thread_test.h" +#include "third_party/tonic/converter/dart_converter.h" #include "third_party/tonic/scopes/dart_isolate_scope.h" namespace flutter { @@ -320,5 +321,29 @@ TEST_F(DartIsolateTest, CanRegisterNativeCallback) { latch.Wait(); } +TEST_F(DartIsolateTest, CanSaveCompilationTrace) { + if (DartVM::IsRunningPrecompiledCode()) { + // Can only save compilation traces in JIT modes. + GTEST_SKIP(); + return; + } + fml::AutoResetWaitableEvent latch; + AddNativeCallback("NotifyNative", + CREATE_NATIVE_ENTRY(([&latch](Dart_NativeArguments args) { + ASSERT_TRUE(tonic::DartConverter::FromDart( + Dart_GetNativeArgument(args, 0))); + latch.Signal(); + }))); + + const auto settings = CreateSettingsForFixture(); + auto vm_ref = DartVMRef::Create(settings); + auto isolate = RunDartCodeInIsolate(vm_ref, settings, GetThreadTaskRunner(), + "testCanSaveCompilationTrace"); + ASSERT_TRUE(isolate); + ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running); + + latch.Wait(); +} + } // namespace testing } // namespace flutter diff --git a/engine/src/flutter/runtime/fixtures/simple_main.dart b/engine/src/flutter/runtime/fixtures/simple_main.dart index bc2d880ff14..f9ba92d98f7 100644 --- a/engine/src/flutter/runtime/fixtures/simple_main.dart +++ b/engine/src/flutter/runtime/fixtures/simple_main.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:isolate'; +import 'dart:ui'; void main() { } @@ -26,6 +27,18 @@ void canRegisterNativeCallback() async { void NotifyNative() native "NotifyNative"; - @pragma('vm:entry-point') void testIsolateShutdown() { } + +@pragma('vm:entry-point') +void testCanSaveCompilationTrace() { + List trace = null; + try { + trace = saveCompilationTrace(); + } catch (exception) { + print("Could not save compilation trace: " + exception); + } + NotifyResult(trace != null && trace.length > 0); +} + +void NotifyResult(bool success) native "NotifyNative";