Files
swift-mirror/test/Runtime/allocator_sanity.swift
Mike Ash e0d0af83d7 [Test] Make allocator_sanity.swift more robust on 32-bit.
This test attempts to allocate Int.max bytes and asserts that it crashes. However, this can actually succeed in (some) 32-bit environments, since Int.max is only 2^32-1 bytes there. This causes spurious test failures. Ensure the test crashes by making two gargantuan allocations.

rdar://91687691
2022-04-13 11:19:32 -04:00

36 lines
1.2 KiB
Swift

// RUN: %target-run-simple-swiftgyb
// REQUIRES: executable_test
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime
import StdlibUnittest
var AllocationsTestSuite = TestSuite("Allocations")
AllocationsTestSuite.test("absurd.allocation.misaligned") {
expectCrashLater()
let mustFail = UnsafeMutableRawPointer.allocate(byteCount: 1024,
alignment: 19)
expectUnreachable()
_ = mustFail
}
AllocationsTestSuite.test("absurd.allocation.gargantuan") {
expectCrashLater()
// There is a chance that we'll actually be able to allocate Int.max bytes on
// 32-bit platforms, since they often have 4GB address spaces and Int.max is
// 2GB minus one byte. Allocate twice to ensure failure. That will (attempt
// to) allocate 4GB minus two bytes, and we'll definitely have more than two
// bytes of other stuff in the process.
let mustFail = UnsafeMutableRawPointer.allocate(byteCount: Int.max,
alignment: 0)
let mustFail2 = UnsafeMutableRawPointer.allocate(byteCount: Int.max,
alignment: 0)
expectUnreachable()
_ = mustFail
_ = mustFail2
}
runAllTests()