dart-sdk/tests/ffi/vmspecific_regress_37511_callbacks_test.dart
Martin Kustermann c52acadd15 [vm/ffi] Split up some tests/ffi into vmspecific and non-vmspecific
The separation will allow flutter/flutter integration tests to run the
non-vmspecific parts.

Change-Id: I0e771f1247ec62d2f0c3faa95ee10560e62524f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127144
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2019-12-04 15:56:08 +00:00

53 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 struct pointers.
//
// VMOptions=--deterministic --enable-testing-pragmas
//
// SharedObjects=ffi_test_functions
//
// TODO(37295): Merge this file with regress_37511_test.dart when callback
// support lands.
import 'dart:ffi';
import 'ffi_test_helpers.dart';
/// Estimate of how many allocations functions in `functionsToTest` do at most.
const gcAfterNAllocationsMax = 10;
void main() {
for (Function() f in functionsToTest) {
f(); // Ensure code is compiled.
for (int n = 1; n <= gcAfterNAllocationsMax; n++) {
collectOnNthAllocation(n);
f();
}
}
}
final List<Function()> functionsToTest = [
// Callback trampolines.
doFromFunction,
() => callbackSmallDouble(dartFunctionPointer),
];
// Callback trampoline helpers.
typedef NativeCallbackTest = Int32 Function(Pointer);
typedef NativeCallbackTestFn = int Function(Pointer);
final callbackSmallDouble =
ffiTestFunctions.lookupFunction<NativeCallbackTest, NativeCallbackTestFn>(
"TestSimpleMultiply");
typedef SimpleMultiplyType = Double Function(Double);
double simpleMultiply(double x) => x * 1.337;
final doFromFunction =
() => Pointer.fromFunction<SimpleMultiplyType>(simpleMultiply, 0.0);
final dartFunctionPointer = doFromFunction();