Skip to content

Commit 8b5a50c

Browse files
authored
Test saving compilation traces. (flutter#8618)
1 parent 7d3caf8 commit 8b5a50c

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

runtime/dart_isolate_unittests.cc

+25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "flutter/runtime/runtime_test.h"
1414
#include "flutter/testing/testing.h"
1515
#include "flutter/testing/thread_test.h"
16+
#include "third_party/tonic/converter/dart_converter.h"
1617
#include "third_party/tonic/scopes/dart_isolate_scope.h"
1718

1819
namespace flutter {
@@ -320,5 +321,29 @@ TEST_F(DartIsolateTest, CanRegisterNativeCallback) {
320321
latch.Wait();
321322
}
322323

324+
TEST_F(DartIsolateTest, CanSaveCompilationTrace) {
325+
if (DartVM::IsRunningPrecompiledCode()) {
326+
// Can only save compilation traces in JIT modes.
327+
GTEST_SKIP();
328+
return;
329+
}
330+
fml::AutoResetWaitableEvent latch;
331+
AddNativeCallback("NotifyNative",
332+
CREATE_NATIVE_ENTRY(([&latch](Dart_NativeArguments args) {
333+
ASSERT_TRUE(tonic::DartConverter<bool>::FromDart(
334+
Dart_GetNativeArgument(args, 0)));
335+
latch.Signal();
336+
})));
337+
338+
const auto settings = CreateSettingsForFixture();
339+
auto vm_ref = DartVMRef::Create(settings);
340+
auto isolate = RunDartCodeInIsolate(vm_ref, settings, GetThreadTaskRunner(),
341+
"testCanSaveCompilationTrace");
342+
ASSERT_TRUE(isolate);
343+
ASSERT_EQ(isolate->get()->GetPhase(), DartIsolate::Phase::Running);
344+
345+
latch.Wait();
346+
}
347+
323348
} // namespace testing
324349
} // namespace flutter

runtime/fixtures/simple_main.dart

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'dart:isolate';
6+
import 'dart:ui';
67

78
void main() {
89
}
@@ -26,6 +27,18 @@ void canRegisterNativeCallback() async {
2627

2728
void NotifyNative() native "NotifyNative";
2829

29-
3030
@pragma('vm:entry-point')
3131
void testIsolateShutdown() { }
32+
33+
@pragma('vm:entry-point')
34+
void testCanSaveCompilationTrace() {
35+
List<int> trace = null;
36+
try {
37+
trace = saveCompilationTrace();
38+
} catch (exception) {
39+
print("Could not save compilation trace: " + exception);
40+
}
41+
NotifyResult(trace != null && trace.length > 0);
42+
}
43+
44+
void NotifyResult(bool success) native "NotifyNative";

0 commit comments

Comments
 (0)