Files
sdk/tests/ffi/regress_40537_test.dart
Daco Harkes 38e250b4d5 [ffi] Format tests/ffi/ with new style - automated
Includes all the files which required no manual treatment.

Change-Id: I3d493bcbc238a2016579a0f804d32f4829efb87b
Cq-Include-Trybots: dart/try:vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-win-debug-x64c-try,vm-checked-mac-release-arm64-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399102
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2024-12-06 08:37:10 +00:00

84 lines
2.2 KiB
Dart

// Copyright (c) 2020, 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.
//
// Truncation and sign extension of small ints, tested with something else than
// equality.
//
// SharedObjects=ffi_test_functions
import 'dart:ffi';
import "package:expect/expect.dart";
import "dylib_utils.dart";
main() {
variant1Negative();
variant1Positive();
variant2Negative();
variant2Positive();
variant3Negative();
}
/// `return x == 249 ? 1 : 0`.
///
/// This doesn't catch the error.
final regress40537 = ffiTestFunctions
.lookupFunction<IntPtr Function(Uint8), int Function(int)>("Regress40537");
variant1Negative() {
// 0xF9 = -7 in 2s complement.
// 0xF9 = 249 in unsigned.
final result = regress40537(-7);
print(result);
Expect.equals(1, result);
}
variant1Positive() {
// 0xF9 = 249 in unsigned.
final result = regress40537(0xFFFFFFF9);
print(result);
Expect.equals(1, result);
}
/// `return x`.
///
/// This does.
final regress40537Variant2 = ffiTestFunctions
.lookupFunction<IntPtr Function(Uint8), int Function(int)>(
"Regress40537Variant2",
);
variant2Negative() {
// The 32 bit representation of -7 is 0xFFFFFFF9.
// Only the lowest byte, 0xF9, should be interpreted by calling convention,
// or it should be truncated and zero extended before calling.
final result = regress40537Variant2(-7);
print(result);
Expect.equals(249, result);
}
variant2Positive() {
// Only the lowest byte, 0xF9, should be interpreted by calling convention,
// or it should be truncated and zero extended before calling.
final result = regress40537Variant2(0xFFFFFFF9);
print(result);
Expect.equals(249, result);
}
/// `return x`.
final regress40537Variant3 = ffiTestFunctions
.lookupFunction<Uint8 Function(IntPtr), int Function(int)>(
"Regress40537Variant3",
);
variant3Negative() {
// This really passes -7 its intptr_t.
final result = regress40537Variant3(-7);
print(result);
Expect.equals(249, result);
}
final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");