forked from swiftlang/swift
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallocator_sanity.swift
35 lines (29 loc) · 1.22 KB
/
allocator_sanity.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// RUN: %target-run-simple-swiftgyb
// REQUIRES: executable_test
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime
import StdlibUnittest
varAllocationsTestSuite=TestSuite("Allocations")
AllocationsTestSuite.test("absurd.allocation.misaligned"){
expectCrashLater()
letmustFail=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.
letmustFail=UnsafeMutableRawPointer.allocate(byteCount:Int.max,
alignment:0)
letmustFail2=UnsafeMutableRawPointer.allocate(byteCount:Int.max,
alignment:0)
expectUnreachable()
_ = mustFail
_ = mustFail2
}
runAllTests()