dart-sdk/tests/ffi/vmspecific_function_callbacks_test.dart
Vyacheslav Egorov 3e0ae6da5f [vm] Remove dual mapping of code
We are no longer using Dart VM in a setting where this
matters as a security measure and it just complicates
portability for no benefit.

There is an indication that it is causing problems when
running Linux build of Dart VM under Docker on Mac OS X.

Fixes https://github.com/dart-lang/sdk/issues/54446

TEST=ci

Cq-Include-Trybots: luci.dart.try:vm-fuchsia-release-arm64-try,vm-fuchsia-release-x64-try
Change-Id: I11bdaa8faebaca1df6fd59097049bdaea9cb8e12
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/344581
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-01-09 12:36:55 +00:00

58 lines
1.5 KiB
Dart

// Copyright (c) 2019, 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 test program for testing dart:ffi function pointers with callbacks.
//
// VMOptions=
// VMOptions=--stacktrace-every=100
// VMOptions=--use-slow-path
// VMOptions=--use-slow-path --stacktrace-every=100
// SharedObjects=ffi_test_functions
import 'dart:ffi';
import 'ffi_test_helpers.dart';
import 'callback_tests_utils.dart';
import 'dylib_utils.dart';
typedef ReturnVoid = Void Function();
final testLibrary = dlopenPlatformSpecific("ffi_test_functions");
void testGC() {
triggerGc();
}
typedef WaitForHelperNative = Void Function(Pointer<Void>);
typedef WaitForHelper = void Function(Pointer<Void>);
void waitForHelper(Pointer<Void> helper) {
print("helper: $helper");
testLibrary.lookupFunction<WaitForHelperNative, WaitForHelper>(
"WaitForHelper")(helper);
}
final testcases = [
CallbackTest("GC", Pointer.fromFunction<ReturnVoid>(testGC)),
CallbackTest("UnprotectCode",
Pointer.fromFunction<WaitForHelperNative>(waitForHelper)),
];
const double zeroPointZero = 0.0;
// Correct type of exceptionalReturn argument to Pointer.fromFunction.
double testExceptionalReturn() {
Pointer.fromFunction<Double Function()>(testExceptionalReturn, 0.0);
Pointer.fromFunction<Double Function()>(testExceptionalReturn, zeroPointZero);
return 0.0;
}
void main() {
testExceptionalReturn();
testcases.forEach((t) => t.run());
}