mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
![Alexander Thomas](/assets/img/avatar_default.png)
https://github.com/dart-lang/co19/issues/1090 TEST=Standard tryjobs, all changes are in test code only. Change-Id: Ie73174447ab165827335652cf035f85b7510ab55 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/201564 Commit-Queue: Alexander Thomas <athom@google.com> Reviewed-by: Erik Ernst <eernst@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com>
63 lines
2.1 KiB
Dart
63 lines
2.1 KiB
Dart
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// @dart = 2.9
|
|
|
|
// SharedObjects=ffi_test_functions
|
|
|
|
import 'dart:ffi';
|
|
import 'dart:io';
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
import 'dylib_utils.dart';
|
|
import 'ffi_test_helpers.dart';
|
|
import 'callback_tests_utils.dart';
|
|
|
|
DynamicLibrary ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
|
|
|
testLeafCall() {
|
|
// Regular calls should transition generated -> native.
|
|
final isThreadInGenerated = ffiTestFunctions.lookupFunction<
|
|
Int8 Function(), int Function()>("IsThreadInGenerated");
|
|
Expect.equals(0, isThreadInGenerated());
|
|
// Leaf calls should remain in generated state.
|
|
final isThreadInGeneratedLeaf = ffiTestFunctions.lookupFunction<
|
|
Int8 Function(), int Function()>("IsThreadInGenerated", isLeaf: true);
|
|
Expect.equals(1, isThreadInGeneratedLeaf());
|
|
}
|
|
|
|
testLeafCallApi() {
|
|
// Note: This will only crash as expected in debug build mode. In other modes
|
|
// it's effectively skip.
|
|
final f = ffiTestFunctions.lookupFunction<
|
|
Void Function(), void Function()>("TestLeafCallApi", isLeaf: true);
|
|
// Calling Dart_.. API is unsafe from leaf calls since we explicitly haven't
|
|
// made the generated -> native transition.
|
|
f();
|
|
}
|
|
|
|
void nop() {}
|
|
|
|
testCallbackLeaf() {
|
|
// This should crash with "expected: T->IsAtSafepoint()", since it's unsafe to
|
|
// do callbacks from leaf calls (otherwise they wouldn't be leaf calls).
|
|
// Note: This will only crash as expected in debug build mode. In other modes
|
|
// it's effectively skip.
|
|
CallbackTest("CallbackLeaf", Pointer.fromFunction<Void Function()>(nop),
|
|
isLeaf:true).run();
|
|
}
|
|
|
|
main() {
|
|
testLeafCall(); //# 01: ok
|
|
// These tests terminate the process after successful completion, so we have
|
|
// to run them separately.
|
|
//
|
|
// Since they use signal handlers they only run on Linux.
|
|
if (Platform.isLinux && !const bool.fromEnvironment("dart.vm.product")) {
|
|
testLeafCallApi(); //# 02: ok
|
|
testCallbackLeaf(); //# 03: ok
|
|
}
|
|
}
|