Skip to content

[Test] Make allocator_sanity.swift more robust on 32-bit. #42346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/Runtime/allocator_sanity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ AllocationsTestSuite.test("absurd.allocation.misaligned") {

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless the platform uses separate address spaces for code and data, in which case…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we find a situation where the system has less than three bytes allocated when this test runs, we can revisit it then. 😄

// 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()