mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:07:49 +00:00
[vm/ffi] Split up function_callbacks_test
This simplifies manual testing. Change-Id: I77c5ac1e9942b793f746587e44bb061eabf90297 Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-precomp-mac-release-simarm_x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124328 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
parent
ca2983a7cd
commit
5371380e80
|
@ -9,9 +9,7 @@ data_not_asan_test: SkipByDesign # This test tries to allocate too much memory o
|
||||||
# They're incompatible with ASAN because not all memory is freed when aborting and
|
# They're incompatible with ASAN because not all memory is freed when aborting and
|
||||||
# with AppJit because the abort the VM before it can generate a snapshot.
|
# with AppJit because the abort the VM before it can generate a snapshot.
|
||||||
[ $compiler == app_jitk || $builder_tag == asan ]
|
[ $compiler == app_jitk || $builder_tag == asan ]
|
||||||
vmspecific_function_callbacks_test/01: Skip
|
vmspecific_function_callbacks_exit_test: SkipByDesign
|
||||||
vmspecific_function_callbacks_test/02: Skip
|
|
||||||
vmspecific_function_callbacks_test/03: Skip
|
|
||||||
|
|
||||||
[ $arch == arm && $system != android ]
|
[ $arch == arm && $system != android ]
|
||||||
*: Skip # "hardfp" calling convention is not yet supported (iOS is also supported but not tested): dartbug.com/36309
|
*: Skip # "hardfp" calling convention is not yet supported (iOS is also supported but not tested): dartbug.com/36309
|
||||||
|
|
1069
tests/ffi/function_callbacks_many_test.dart
Normal file
1069
tests/ffi/function_callbacks_many_test.dart
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
78
tests/ffi/vmspecific_function_callbacks_exit_test.dart
Normal file
78
tests/ffi/vmspecific_function_callbacks_exit_test.dart
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
// 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=--use-slow-path
|
||||||
|
// SharedObjects=ffi_test_functions
|
||||||
|
import 'dart:io';
|
||||||
|
import 'dart:ffi';
|
||||||
|
import 'dart:isolate';
|
||||||
|
import "package:expect/expect.dart";
|
||||||
|
import 'dylib_utils.dart';
|
||||||
|
|
||||||
|
typedef NativeCallbackTest = Int32 Function(Pointer);
|
||||||
|
typedef NativeCallbackTestFn = int Function(Pointer);
|
||||||
|
final DynamicLibrary testLibrary = dlopenPlatformSpecific("ffi_test_functions");
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
final String name;
|
||||||
|
final Pointer callback;
|
||||||
|
final bool skip;
|
||||||
|
Test(this.name, this.callback, {bool skipIf: false}) : skip = skipIf {}
|
||||||
|
void run() {
|
||||||
|
if (skip) return;
|
||||||
|
print("Test $name.");
|
||||||
|
final NativeCallbackTestFn tester = testLibrary
|
||||||
|
.lookupFunction<NativeCallbackTest, NativeCallbackTestFn>("Test$name");
|
||||||
|
final int testCode = tester(callback);
|
||||||
|
if (testCode != 0) {
|
||||||
|
Expect.fail("Test $name failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef ReturnVoid = Void Function();
|
||||||
|
void returnVoid() {}
|
||||||
|
testCallbackWrongThread() {
|
||||||
|
print("Test CallbackWrongThread.");
|
||||||
|
Test("CallbackWrongThread", Pointer.fromFunction<ReturnVoid>(returnVoid))
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
testCallbackOutsideIsolate() {
|
||||||
|
print("Test CallbackOutsideIsolate.");
|
||||||
|
Test("CallbackOutsideIsolate", Pointer.fromFunction<ReturnVoid>(returnVoid))
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
isolateHelper(int callbackPointer) {
|
||||||
|
final Pointer<Void> ptr = Pointer.fromAddress(callbackPointer);
|
||||||
|
final NativeCallbackTestFn tester =
|
||||||
|
testLibrary.lookupFunction<NativeCallbackTest, NativeCallbackTestFn>(
|
||||||
|
"TestCallbackWrongIsolate");
|
||||||
|
Expect.equals(0, tester(ptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
testCallbackWrongIsolate() async {
|
||||||
|
final int callbackPointer =
|
||||||
|
Pointer.fromFunction<ReturnVoid>(returnVoid).address;
|
||||||
|
final ReceivePort exitPort = ReceivePort();
|
||||||
|
await Isolate.spawn(isolateHelper, callbackPointer,
|
||||||
|
errorsAreFatal: true, onExit: exitPort.sendPort);
|
||||||
|
await exitPort.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
// 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")) {
|
||||||
|
testCallbackWrongThread(); //# 01: ok
|
||||||
|
testCallbackOutsideIsolate(); //# 02: ok
|
||||||
|
await testCallbackWrongIsolate(); //# 03: ok
|
||||||
|
}
|
||||||
|
}
|
26
tests/ffi/vmspecific_function_callbacks_negative_test.dart
Normal file
26
tests/ffi/vmspecific_function_callbacks_negative_test.dart
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'dylib_utils.dart';
|
||||||
|
|
||||||
|
final DynamicLibrary testLibrary = dlopenPlatformSpecific("ffi_test_functions");
|
||||||
|
|
||||||
|
// Correct type of exceptionalReturn argument to Pointer.fromFunction.
|
||||||
|
double testExceptionalReturn() {
|
||||||
|
Pointer.fromFunction<Double Function()>(returnVoid, null); //# 59: compile-time error
|
||||||
|
Pointer.fromFunction<Void Function()>(returnVoid, 0); //# 60: compile-time error
|
||||||
|
Pointer.fromFunction<Double Function()>(testExceptionalReturn, "abc"); //# 61: compile-time error
|
||||||
|
Pointer.fromFunction<Double Function()>(testExceptionalReturn, 0); //# 62: compile-time error
|
||||||
|
Pointer.fromFunction<Double Function()>(testExceptionalReturn); //# 63: compile-time error
|
||||||
|
|
||||||
|
return 0.0; // not used
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testExceptionalReturn();
|
||||||
|
}
|
|
@ -17,16 +17,10 @@
|
||||||
// VMOptions=--use-slow-path --enable-testing-pragmas --write-protect-code --no-dual-map-code --stacktrace-every=100
|
// VMOptions=--use-slow-path --enable-testing-pragmas --write-protect-code --no-dual-map-code --stacktrace-every=100
|
||||||
// SharedObjects=ffi_test_functions
|
// SharedObjects=ffi_test_functions
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
import 'dart:ffi';
|
import 'dart:ffi';
|
||||||
import 'dart:isolate';
|
|
||||||
import 'dylib_utils.dart';
|
|
||||||
|
|
||||||
import "package:expect/expect.dart";
|
|
||||||
|
|
||||||
import 'ffi_test_helpers.dart';
|
import 'ffi_test_helpers.dart';
|
||||||
import 'function_callbacks_test.dart' show Test, testLibrary,
|
import 'function_callbacks_test.dart' show Test, testLibrary, ReturnVoid;
|
||||||
NativeCallbackTest, NativeCallbackTestFn, ReturnVoid, returnVoid;
|
|
||||||
|
|
||||||
void testGC() {
|
void testGC() {
|
||||||
triggerGc();
|
triggerGc();
|
||||||
|
@ -37,40 +31,16 @@ typedef WaitForHelper = void Function(Pointer<Void>);
|
||||||
|
|
||||||
void waitForHelper(Pointer<Void> helper) {
|
void waitForHelper(Pointer<Void> helper) {
|
||||||
print("helper: $helper");
|
print("helper: $helper");
|
||||||
testLibrary
|
testLibrary.lookupFunction<WaitForHelperNative, WaitForHelper>(
|
||||||
.lookupFunction<WaitForHelperNative, WaitForHelper>("WaitForHelper")(helper);
|
"WaitForHelper")(helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<Test> testcases = [
|
final List<Test> testcases = [
|
||||||
Test("GC", Pointer.fromFunction<ReturnVoid>(testGC)),
|
Test("GC", Pointer.fromFunction<ReturnVoid>(testGC)),
|
||||||
Test("UnprotectCode", Pointer.fromFunction<WaitForHelperNative>(waitForHelper)),
|
Test("UnprotectCode",
|
||||||
|
Pointer.fromFunction<WaitForHelperNative>(waitForHelper)),
|
||||||
];
|
];
|
||||||
|
|
||||||
testCallbackWrongThread() =>
|
|
||||||
Test("CallbackWrongThread", Pointer.fromFunction<ReturnVoid>(returnVoid))
|
|
||||||
.run();
|
|
||||||
|
|
||||||
testCallbackOutsideIsolate() =>
|
|
||||||
Test("CallbackOutsideIsolate", Pointer.fromFunction<ReturnVoid>(returnVoid))
|
|
||||||
.run();
|
|
||||||
|
|
||||||
isolateHelper(int callbackPointer) {
|
|
||||||
final Pointer<Void> ptr = Pointer.fromAddress(callbackPointer);
|
|
||||||
final NativeCallbackTestFn tester =
|
|
||||||
testLibrary.lookupFunction<NativeCallbackTest, NativeCallbackTestFn>(
|
|
||||||
"TestCallbackWrongIsolate");
|
|
||||||
Expect.equals(0, tester(ptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
testCallbackWrongIsolate() async {
|
|
||||||
final int callbackPointer =
|
|
||||||
Pointer.fromFunction<ReturnVoid>(returnVoid).address;
|
|
||||||
final ReceivePort exitPort = ReceivePort();
|
|
||||||
await Isolate.spawn(isolateHelper, callbackPointer,
|
|
||||||
errorsAreFatal: true, onExit: exitPort.sendPort);
|
|
||||||
await exitPort.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
const double zeroPointZero = 0.0;
|
const double zeroPointZero = 0.0;
|
||||||
|
|
||||||
// Correct type of exceptionalReturn argument to Pointer.fromFunction.
|
// Correct type of exceptionalReturn argument to Pointer.fromFunction.
|
||||||
|
@ -78,26 +48,11 @@ double testExceptionalReturn() {
|
||||||
Pointer.fromFunction<Double Function()>(testExceptionalReturn, 0.0);
|
Pointer.fromFunction<Double Function()>(testExceptionalReturn, 0.0);
|
||||||
Pointer.fromFunction<Double Function()>(testExceptionalReturn, zeroPointZero);
|
Pointer.fromFunction<Double Function()>(testExceptionalReturn, zeroPointZero);
|
||||||
|
|
||||||
Pointer.fromFunction<Double Function()>(returnVoid, null); //# 59: compile-time error
|
return 0.0;
|
||||||
Pointer.fromFunction<Void Function()>(returnVoid, 0); //# 60: compile-time error
|
|
||||||
Pointer.fromFunction<Double Function()>(testExceptionalReturn, "abc"); //# 61: compile-time error
|
|
||||||
Pointer.fromFunction<Double Function()>(testExceptionalReturn, 0); //# 62: compile-time error
|
|
||||||
Pointer.fromFunction<Double Function()>(testExceptionalReturn); //# 63: compile-time error
|
|
||||||
|
|
||||||
return 0.0; // not used
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() async {
|
void main() {
|
||||||
testcases.forEach((t) => t.run()); //# 00: ok
|
testExceptionalReturn();
|
||||||
testExceptionalReturn(); //# 00: ok
|
|
||||||
|
|
||||||
// These tests terminate the process after successful completion, so we have
|
testcases.forEach((t) => t.run());
|
||||||
// to run them separately.
|
|
||||||
//
|
|
||||||
// Since they use signal handlers they only run on Linux.
|
|
||||||
if (Platform.isLinux && !const bool.fromEnvironment("dart.vm.product")) {
|
|
||||||
testCallbackWrongThread(); //# 01: ok
|
|
||||||
testCallbackOutsideIsolate(); //# 02: ok
|
|
||||||
await testCallbackWrongIsolate(); //# 03: ok
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue