mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 13:57:58 +00:00
[vm/ffi] Cleanup tests
Address all warnings and errors in positive tests. Move all static checks tests to tests/ffi/static_checks/ so it's easier to ignore them in the analyzer. Change-Id: I16ac2c00432a4e1b6750bffd9b03ac8a2e988fe6 Cq-Include-Trybots: luci.dart.try:vm-fuchsia-release-arm64-try,vm-fuchsia-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351123 Reviewed-by: Liam Appelbe <liama@google.com>
This commit is contained in:
parent
dc339962c3
commit
fbee607329
|
@ -6,8 +6,6 @@ import 'dart:ffi';
|
|||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
||||
|
||||
typedef NativeAsyncCallbackTest = Void Function(Pointer);
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
import 'dart:async';
|
||||
import 'dart:ffi';
|
||||
import 'dart:isolate';
|
||||
import 'dart:math';
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
|
|
|
@ -7,13 +7,11 @@
|
|||
// SharedObjects=ffi_test_functions
|
||||
|
||||
import 'dart:ffi';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:ffi/ffi.dart";
|
||||
|
||||
import 'ffi_test_helpers.dart';
|
||||
import 'regress_47673_test.dart';
|
||||
|
||||
void main() {
|
||||
testPointerBasic();
|
||||
|
@ -43,7 +41,6 @@ void main() {
|
|||
testPointerPointerNull();
|
||||
testSizeOf();
|
||||
testPointerChain(100);
|
||||
testTypeTest();
|
||||
testToString();
|
||||
testEquality();
|
||||
testDynamicInvocation();
|
||||
|
@ -139,7 +136,8 @@ void testCastGeneric() {
|
|||
}
|
||||
|
||||
Pointer<Int16> p = calloc();
|
||||
Pointer<Int64> p2 = generic(p);
|
||||
// ignore: unused_local_variable
|
||||
Pointer<Int64> p2 = generic<Int64>(p);
|
||||
calloc.free(p);
|
||||
}
|
||||
|
||||
|
@ -149,6 +147,7 @@ void testCastGeneric2() {
|
|||
}
|
||||
|
||||
Pointer<Int16> p = calloc();
|
||||
// ignore: unused_local_variable
|
||||
Pointer<Int64> p2 = generic(p);
|
||||
calloc.free(p);
|
||||
}
|
||||
|
@ -407,12 +406,6 @@ void testPointerChain(int length) {
|
|||
freeChain(head, length);
|
||||
}
|
||||
|
||||
void testTypeTest() {
|
||||
Pointer<Int8> p = calloc();
|
||||
Expect.isTrue(p is Pointer);
|
||||
calloc.free(p);
|
||||
}
|
||||
|
||||
void testToString() {
|
||||
Pointer<Int16> p = calloc();
|
||||
Expect.stringEquals("Pointer: address=0x", p.toString().substring(0, 19));
|
||||
|
@ -438,13 +431,13 @@ typedef Int8UnOp = Int8 Function(Int8);
|
|||
void testDynamicInvocation() {
|
||||
dynamic p = calloc<Int8>();
|
||||
Expect.throws(() {
|
||||
final int i = p.value;
|
||||
p.value;
|
||||
});
|
||||
Expect.throws(() => p.value = 1);
|
||||
Expect.throws(() => p.elementAt(5));
|
||||
Expect.throws(() => p += 5);
|
||||
final int addr = p.address;
|
||||
final Pointer<Int16> p2 = p.cast<Int16>();
|
||||
p.address;
|
||||
p.cast<Int16>();
|
||||
calloc.free(p);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
import 'dart:ffi';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
// SharedObjects=ffi_test_functions
|
||||
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ regress_47594_test: Skip # DartDev is not available on Android.
|
|||
vmspecific_native_finalizer_isolate_groups_test: Skip # SpawnUri not available on Android tester.
|
||||
|
||||
[ $system == fuchsia ]
|
||||
static_checks/*: SkipByDesign # Expecting compile time failures in multi tests doesn't work on the Fuchsia test runner.
|
||||
vmspecific_pointer_load_il_test: SkipByDesign # Not bloating the Fuchsia test package with package:vm/testing/il_matchers.dart
|
||||
|
||||
[ $system == windows ]
|
||||
|
|
|
@ -10,11 +10,9 @@
|
|||
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:async_helper/async_helper.dart';
|
||||
import 'package:expect/expect.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
import 'dart:ffi';
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:ffi/ffi.dart";
|
||||
|
||||
import 'callback_tests_utils.dart';
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
import 'dart:ffi';
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:ffi/ffi.dart";
|
||||
|
||||
import 'callback_tests_utils.dart';
|
||||
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
import 'dart:async';
|
||||
import 'dart:ffi';
|
||||
import 'dart:isolate';
|
||||
import 'dart:math';
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import 'dart:async';
|
|||
import 'dart:ffi';
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:ffi/ffi.dart";
|
||||
|
||||
import 'async_callback_tests_utils.dart';
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import 'dart:async';
|
|||
import 'dart:ffi';
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:ffi/ffi.dart";
|
||||
|
||||
import 'async_callback_tests_utils.dart';
|
||||
|
||||
|
|
|
@ -5,10 +5,8 @@
|
|||
// SharedObjects=ffi_test_functions
|
||||
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
|
@ -20,8 +18,10 @@ void main() {
|
|||
testVariadicAt1Int64x5NativeLeaf();
|
||||
}
|
||||
|
||||
@Native<Int64 Function(Int64, VarArgs<(Int64, Int64, Int64, Int64)>)>(symbol: 'VariadicAt1Int64x5', isLeaf:true)
|
||||
external int variadicAt1Int64x5NativeLeaf(int a0, int a1, int a2, int a3, int a4);
|
||||
@Native<Int64 Function(Int64, VarArgs<(Int64, Int64, Int64, Int64)>)>(
|
||||
symbol: 'VariadicAt1Int64x5', isLeaf: true)
|
||||
external int variadicAt1Int64x5NativeLeaf(
|
||||
int a0, int a1, int a2, int a3, int a4);
|
||||
|
||||
void testVariadicAt1Int64x5NativeLeaf() {
|
||||
final result = variadicAt1Int64x5NativeLeaf(1, 2, 3, 4, 5);
|
||||
|
|
|
@ -6,9 +6,7 @@
|
|||
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
final DynamicLibrary testLibrary = dlopenPlatformSpecific("ffi_test_functions");
|
||||
final testLibrary = DynamicLibrary.process();
|
||||
|
||||
// Correct type of exceptionalReturn argument to Pointer.fromFunction.
|
||||
double testExceptionalReturn() {
|
|
@ -10,8 +10,6 @@ import 'dart:ffi';
|
|||
|
||||
import "package:ffi/ffi.dart";
|
||||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
void main() {
|
||||
testGetGeneric();
|
||||
testGetGeneric2();
|
||||
|
@ -525,7 +523,7 @@ void testNativeCallableIsolateLocalFunctionExceptionValueMustBeConst() {
|
|||
|
||||
void testLookupFunctionGeneric() {
|
||||
Function generic<T extends Function>() {
|
||||
DynamicLibrary l = dlopenPlatformSpecific("ffi_test_dynamic_library");
|
||||
DynamicLibrary l = DynamicLibrary.process();
|
||||
Function result = () => "dummy";
|
||||
result = l.lookupFunction<T, DoubleUnOp>("cos");
|
||||
// ^
|
||||
|
@ -540,7 +538,7 @@ void testLookupFunctionGeneric() {
|
|||
|
||||
void testLookupFunctionGeneric2() {
|
||||
Function generic<T extends Function>() {
|
||||
DynamicLibrary l = dlopenPlatformSpecific("ffi_test_dynamic_library");
|
||||
DynamicLibrary l = DynamicLibrary.process();
|
||||
Function result = () => "dummy";
|
||||
result = l.lookupFunction<NativeDoubleUnOp, T>("cos");
|
||||
// ^
|
||||
|
@ -554,7 +552,7 @@ void testLookupFunctionGeneric2() {
|
|||
}
|
||||
|
||||
void testLookupFunctionWrongNativeFunctionSignature() {
|
||||
DynamicLibrary l = dlopenPlatformSpecific("ffi_test_dynamic_library");
|
||||
DynamicLibrary l = DynamicLibrary.process();
|
||||
l.lookupFunction<IntUnOp, IntUnOp>("cos");
|
||||
// ^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.MUST_BE_A_NATIVE_FUNCTION_TYPE
|
||||
|
@ -563,7 +561,7 @@ void testLookupFunctionWrongNativeFunctionSignature() {
|
|||
}
|
||||
|
||||
void testLookupFunctionTypeMismatch() {
|
||||
DynamicLibrary l = dlopenPlatformSpecific("ffi_test_dynamic_library");
|
||||
DynamicLibrary l = DynamicLibrary.process();
|
||||
l.lookupFunction<NativeDoubleUnOp, IntUnOp>("cos");
|
||||
// ^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.MUST_BE_A_SUBTYPE
|
||||
|
@ -575,7 +573,7 @@ typedef PointervoidN = Void Function(Pointer<void>);
|
|||
typedef PointervoidD = void Function(Pointer<void>);
|
||||
|
||||
void testLookupFunctionPointervoid() {
|
||||
DynamicLibrary l = dlopenPlatformSpecific("ffi_test_dynamic_library");
|
||||
DynamicLibrary l = DynamicLibrary.process();
|
||||
// TODO(https://dartbug.com/44593): This should be a compile-time error in CFE.
|
||||
// l.lookupFunction<PointervoidN, PointervoidD>("cos");
|
||||
}
|
||||
|
@ -584,7 +582,7 @@ typedef PointerNFdynN = Void Function(Pointer<NativeFunction>);
|
|||
typedef PointerNFdynD = void Function(Pointer<NativeFunction>);
|
||||
|
||||
void testLookupFunctionPointerNFdyn() {
|
||||
DynamicLibrary l = dlopenPlatformSpecific("ffi_test_dynamic_library");
|
||||
DynamicLibrary l = DynamicLibrary.process();
|
||||
// TODO(https://dartbug.com/44594): Should this be an error or not?
|
||||
// l.lookupFunction<PointerNFdynN, PointerNFdynD>("cos");
|
||||
}
|
||||
|
@ -919,7 +917,7 @@ class MyClass {
|
|||
MyClass(this.x);
|
||||
}
|
||||
|
||||
final testLibrary = dlopenPlatformSpecific("ffi_test_functions");
|
||||
final testLibrary = DynamicLibrary.process();
|
||||
|
||||
void testHandleVariance() {
|
||||
// Taking a more specific argument is okay.
|
||||
|
@ -1241,7 +1239,7 @@ final class TestStruct1405 extends Struct {
|
|||
|
||||
void testLookupFunctionIsLeafMustBeConst() {
|
||||
bool notAConst = false;
|
||||
DynamicLibrary l = dlopenPlatformSpecific("ffi_test_dynamic_library");
|
||||
DynamicLibrary l = DynamicLibrary.process();
|
||||
/**/ l.lookupFunction<NativeDoubleUnOp, DoubleUnOp>("timesFour",
|
||||
// ^
|
||||
// [cfe] Argument 'isLeaf' must be a constant.
|
||||
|
@ -1264,7 +1262,7 @@ typedef NativeTakesHandle = Void Function(Handle);
|
|||
typedef TakesHandle = void Function(Object);
|
||||
|
||||
void testLookupFunctionTakesHandle() {
|
||||
DynamicLibrary l = dlopenPlatformSpecific("ffi_test_dynamic_library");
|
||||
DynamicLibrary l = DynamicLibrary.process();
|
||||
l.lookupFunction<NativeTakesHandle, TakesHandle>("takesHandle", isLeaf: true);
|
||||
// ^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.LEAF_CALL_MUST_NOT_TAKE_HANDLE
|
||||
|
@ -1285,7 +1283,7 @@ typedef NativeReturnsHandle = Handle Function();
|
|||
typedef ReturnsHandle = Object Function();
|
||||
|
||||
void testLookupFunctionReturnsHandle() {
|
||||
DynamicLibrary l = dlopenPlatformSpecific("ffi_test_dynamic_library");
|
||||
DynamicLibrary l = DynamicLibrary.process();
|
||||
/**/ l.lookupFunction<NativeReturnsHandle, ReturnsHandle>("returnsHandle",
|
||||
// ^^^^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.LEAF_CALL_MUST_NOT_RETURN_HANDLE
|
|
@ -4,22 +4,12 @@
|
|||
|
||||
// SharedObjects=ffi_test_functions
|
||||
|
||||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
void main() {
|
||||
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
||||
|
||||
// Try to lookup a symbol that exists, but don't use it.
|
||||
// With both valid and invalid C signatures.
|
||||
|
||||
print(ffiTestFunctions.lookupFunction<
|
||||
Void Function(Pointer<Utf8>, VarArgs<(Int32, Int32)>),
|
||||
void Function(Pointer<Utf8>, int, int)>('PassObjectToC'));
|
||||
final ffiTestFunctions = DynamicLibrary.process();
|
||||
|
||||
// Error: a named record field.
|
||||
print(ffiTestFunctions.lookupFunction< //# 1: compile-time error
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
// ============================================
|
||||
// Tests checks on Dart to native (asFunction).
|
||||
|
@ -22,7 +21,7 @@ final paramOpName = "NativeTypePointerParam";
|
|||
final returnOpName = "NativeTypePointerReturn";
|
||||
|
||||
final DynamicLibrary ffiTestFunctions =
|
||||
dlopenPlatformSpecific("ffi_test_functions");
|
||||
DynamicLibrary.process();
|
||||
|
||||
final p1 =
|
||||
ffiTestFunctions.lookup<NativeFunction<Int64PointerParamOp>>(paramOpName);
|
|
@ -19,7 +19,6 @@ void main() {
|
|||
testStructFromAddress();
|
||||
testStructFromAddressWithOperator();
|
||||
testStructWithNulls();
|
||||
testTypeTest();
|
||||
testUtf8();
|
||||
}
|
||||
}
|
||||
|
@ -124,13 +123,6 @@ void testStructWithNulls() {
|
|||
calloc.free(coordinate);
|
||||
}
|
||||
|
||||
void testTypeTest() {
|
||||
final pointer = calloc<Coordinate>();
|
||||
Coordinate c = pointer.ref;
|
||||
Expect.isTrue(c is Struct);
|
||||
calloc.free(pointer);
|
||||
}
|
||||
|
||||
void testUtf8() {
|
||||
final String test = 'Hasta Mañana';
|
||||
final Pointer<Utf8> medium = test.toNativeUtf8();
|
||||
|
|
|
@ -21,7 +21,6 @@ void main() {
|
|||
testStructIndexedAccess();
|
||||
testStructIndexedAccessWithOperator();
|
||||
testStructWithNulls();
|
||||
testTypeTest();
|
||||
testUtf8();
|
||||
testDotDotRef();
|
||||
}
|
||||
|
@ -182,13 +181,6 @@ void testStructWithNulls() {
|
|||
calloc.free(coordinate);
|
||||
}
|
||||
|
||||
void testTypeTest() {
|
||||
final pointer = calloc<Coordinate>();
|
||||
Coordinate c = pointer.ref;
|
||||
Expect.isTrue(c is Struct);
|
||||
calloc.free(pointer);
|
||||
}
|
||||
|
||||
void testUtf8() {
|
||||
final String test = 'Hasta Mañana';
|
||||
final Pointer<Utf8> medium = test.toNativeUtf8();
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
// The only architecture on which this is known to fail is arm32 on Android.
|
||||
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
@ -32,7 +31,7 @@ final bool isUnalignedFloatingPointAccessSupported = switch (Abi.current()) {
|
|||
//
|
||||
// [1]: https://developer.arm.com/documentation/ddi0406/c/Application-Level-Architecture/Application-Level-Memory-Model/Alignment-support/Unaligned-data-access?lang=en
|
||||
// [2]: https://docs.kernel.org/arch/arm/mem_alignment.html
|
||||
Abi.androidArm || Abi.linuxArm || Abi.iosArm => false,
|
||||
Abi.androidArm || Abi.linuxArm || Abi.iosArm => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ void functionArgumentVariance() {
|
|||
NativeFunction<
|
||||
Pointer<NativeType> Function(
|
||||
Pointer<Int8>)>>)>>.fromAddress(0x1234);
|
||||
final f = p.asFunction<
|
||||
p.asFunction<
|
||||
Pointer<NativeFunction<Pointer<NativeType> Function(Pointer<Int8>)>> Function(
|
||||
Pointer<
|
||||
NativeFunction<Pointer<Int8> Function(Pointer<NativeType>)>>)>();
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
// SharedObjects=ffi_test_functions
|
||||
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
|
||||
import 'dylib_utils.dart';
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ void main() {
|
|||
}
|
||||
|
||||
void testOpen() {
|
||||
DynamicLibrary l = dlopenPlatformSpecific("ffi_test_dynamic_library");
|
||||
dlopenPlatformSpecific("ffi_test_dynamic_library");
|
||||
}
|
||||
|
||||
void testOpenError() {
|
||||
|
|
Loading…
Reference in a new issue