Skip to content

Commit 7487e5e

Browse files
dcharkescommit-bot@chromium.org
authored andcommitted
[test/ffi] Fix errors in tests
A cleanup round of our FFI tests. Change-Id: I3883b9d14785c759c7129c072c9588bfa5a3fba0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214802 Reviewed-by: Clement Skau <[email protected]> Commit-Queue: Daco Harkes <[email protected]>
1 parent e922f30 commit 7487e5e

14 files changed

+1122
-883
lines changed

tests/ffi/ffi_native_test.dart

+9-10
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,23 @@
66
// with type arguments isn't supported in that version of Dart.
77

88
import 'dart:ffi';
9-
import 'dart:nativewrappers';
10-
11-
import 'package:expect/expect.dart';
129

1310
// Error: FFI leaf call must not have Handle return type.
14-
@FfiNative<Handle Function()>("foo", isLeaf: true) //# 01: compile-time error
15-
external Object foo(); //# 01: compile-time error
11+
@FfiNative<Handle Function()>("foo", isLeaf: true) //# 01: compile-time error
12+
external Object foo(); //# 01: compile-time error
1613

1714
// Error: FFI leaf call must not have Handle argument types.
18-
@FfiNative<Void Function(Handle)>("bar", isLeaf: true) //# 02: compile-time error
19-
external void bar(Object); //# 02: compile-time error
15+
@FfiNative<Void Function(Handle)>("bar", //# 02: compile-time error
16+
isLeaf: true) //# 02: compile-time error
17+
external void bar(Object); //# 02: compile-time error
2018

2119
class Classy {
2220
@FfiNative<IntPtr Function(IntPtr)>('ReturnIntPtr')
2321
external static int returnIntPtrStatic(int x);
2422

2523
// Error: FfiNative annotations can only be used on static functions.
26-
@FfiNative<IntPtr Function(IntPtr)>('ReturnIntPtr') //# 03: compile-time error
27-
external int returnIntPtrMethod(int x); //# 03: compile-time error
24+
@FfiNative<IntPtr Function(IntPtr)>('ReturnIntPtr') //# 03: compile-time error
25+
external int returnIntPtrMethod(int x); //# 03: compile-time error
2826
}
2927

3028
// Regression test: Ensure same-name FfiNative functions don't collide in the
@@ -33,9 +31,10 @@ class A {
3331
@FfiNative<Void Function()>('nop')
3432
external static void foo();
3533
}
34+
3635
class B {
3736
@FfiNative<Void Function()>('nop')
3837
external static void foo();
3938
}
4039

41-
void main() { /* Intentionally empty: Compile-time error tests. */ }
40+
void main() {/* Intentionally empty: Compile-time error tests. */}

tests/ffi/function_callbacks_structs_by_value_generated_test.dart

+543-420
Large diffs are not rendered by default.

tests/ffi/function_callbacks_structs_by_value_test.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ final cPassStructRecursive = ffiTestFunctions.lookupFunction<
7272
Struct20BytesHomogeneousInt32 Function(int recursionCounter,
7373
Struct20BytesHomogeneousInt32, Pointer)>("PassStructRecursive");
7474

75-
Struct8BytesNestedInt typedDataBackedStruct = Struct8BytesNestedInt();
75+
Struct8BytesNestedInt typedDataBackedStruct =
76+
Pointer<Struct8BytesNestedInt>.fromAddress(0).ref;
7677
bool typedDataBackedStructSet = false;
7778
void _receiveStructByValue(Struct8BytesNestedInt struct) {
7879
typedDataBackedStruct = struct;

tests/ffi/generator/structs_by_value_tests_generator.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ final ${dartType} ${variableName} = ${variableName}Pointer.ref;
268268
if (structsAsPointers) {
269269
return "Pointer<${dartType}> ${variableName}Pointer = nullptr;\n";
270270
} else {
271-
return "${dartType} ${variableName} = ${dartType}();\n";
271+
return "${dartType} ${variableName} = Pointer<${dartType}>.fromAddress(0).ref;\n";
272272
}
273273
}
274274

tests/ffi/regress_39063_test.dart

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
import "dart:ffi";
1111

12-
import "package:expect/expect.dart";
13-
1412
import "dylib_utils.dart";
1513

1614
typedef VigesimalOp = double Function(

tests/ffi/vmspecific_function_test.dart

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ import 'dart:ffi';
1717

1818
import 'dylib_utils.dart';
1919

20-
import "package:ffi/ffi.dart";
21-
import "package:expect/expect.dart";
22-
2320
void main() {
2421
for (int i = 0; i < 100; ++i) {
2522
testLookupFunctionPointerNativeType();

tests/ffi/vmspecific_highmem_32bit_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'dart:ffi';
66
import 'dart:io';
7-
import 'dart:typed_data';
87

98
import 'package:expect/expect.dart';
109

tests/ffi/vmspecific_leaf_call_test.dart

+11-9
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,30 @@ import 'dart:io';
99

1010
import 'package:expect/expect.dart';
1111

12-
import 'dylib_utils.dart';
13-
import 'ffi_test_helpers.dart';
1412
import 'callback_tests_utils.dart';
13+
import 'dylib_utils.dart';
1514

1615
DynamicLibrary ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
1716

1817
testLeafCall() {
1918
// Note: This test currently fails on Windows AOT: https://dartbug.com/40579
2019
// Regular calls should transition generated -> native.
21-
final isThreadInGenerated = ffiTestFunctions.lookupFunction<
22-
Int8 Function(), int Function()>("IsThreadInGenerated");
20+
final isThreadInGenerated = ffiTestFunctions
21+
.lookupFunction<Int8 Function(), int Function()>("IsThreadInGenerated");
2322
Expect.equals(0, isThreadInGenerated());
2423
// Leaf calls should remain in generated state.
25-
final isThreadInGeneratedLeaf = ffiTestFunctions.lookupFunction<
26-
Int8 Function(), int Function()>("IsThreadInGenerated", isLeaf: true);
24+
final isThreadInGeneratedLeaf = ffiTestFunctions
25+
.lookupFunction<Int8 Function(), int Function()>("IsThreadInGenerated",
26+
isLeaf: true);
2727
Expect.equals(1, isThreadInGeneratedLeaf());
2828
}
2929

3030
testLeafCallApi() {
3131
// Note: This will only crash as expected in debug build mode. In other modes
3232
// it's effectively skip.
33-
final f = ffiTestFunctions.lookupFunction<
34-
Void Function(), void Function()>("TestLeafCallApi", isLeaf: true);
33+
final f = ffiTestFunctions.lookupFunction<Void Function(), void Function()>(
34+
"TestLeafCallApi",
35+
isLeaf: true);
3536
// Calling Dart_.. API is unsafe from leaf calls since we explicitly haven't
3637
// made the generated -> native transition.
3738
f();
@@ -45,7 +46,8 @@ testCallbackLeaf() {
4546
// Note: This will only crash as expected in debug build mode. In other modes
4647
// it's effectively skip.
4748
CallbackTest("CallbackLeaf", Pointer.fromFunction<Void Function()>(nop),
48-
isLeaf:true).run();
49+
isLeaf: true)
50+
.run();
4951
}
5052

5153
main() {

0 commit comments

Comments
 (0)