dart-sdk/tests/ffi_2/data_not_asan_test.dart
Daco Harkes 1fdd242e4b [deps] Roll package:ffi to 2.0.1
Bug: https://github.com/dart-lang/ffi/issues/148
Change-Id: I406c6a0fbdb53c07507519f1237e09362e3475d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249160
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Devon Carew <devoncarew@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-06-19 18:29:11 +00:00

37 lines
1.2 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 primitive data pointers.
//
// These callocs trigger an asan alarm, so these tests are in a separate file
// which is excluded in asan mode.
// @dart = 2.9
import 'dart:ffi';
import "package:ffi/ffi.dart";
import "package:expect/expect.dart";
void main() {
testPointerAllocateTooLarge();
testPointerAllocateNegative();
}
void testPointerAllocateTooLarge() {
// Try to allocate something that doesn't fit in 64 bit address space.
int maxInt = 9223372036854775807; // 2^63 - 1
Expect.throws(() => calloc<Int8>(maxInt));
// Try to allocate almost the full 64 bit address space.
int maxInt1_8 = 1152921504606846975; // 2^60 -1
Expect.throws(() => calloc<Int8>(maxInt1_8));
}
void testPointerAllocateNegative() {
// Passing in -1 will be converted into an unsigned integer. So, it will try
// to allocate SIZE_MAX - 1 + 1 bytes. This will fail as it is the max amount
// of addressable memory on the system.
Expect.throws(() => calloc<Int8>(-1));
}