Revision ac4b68fbf45853ba4b9e327cb42f93f42a8fa252 authored by Ellie Shin on 17 March 2023, 04:14:20 UTC, committed by Ellie Shin on 17 March 2023, 04:14:20 UTC
1 parent f2c68fb
Raw File
allocator_sanity.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()
back to top