diff options
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/tests/heap.rs | 45 | ||||
| -rw-r--r-- | src/liballoc/tests/lib.rs | 4 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/liballoc/tests/heap.rs b/src/liballoc/tests/heap.rs new file mode 100644 index 00000000000..d3ce12056bb --- /dev/null +++ b/src/liballoc/tests/heap.rs @@ -0,0 +1,45 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use alloc_system::System; +use std::heap::{Heap, Alloc, Layout}; + +/// https://github.com/rust-lang/rust/issues/45955 +/// +/// Note that `#[global_allocator]` is not used, +/// so `liballoc_jemalloc` is linked (on some platforms). +#[test] +fn alloc_system_overaligned_request() { + check_overalign_requests(System) +} + +#[test] +fn std_heap_overaligned_request() { + check_overalign_requests(Heap) +} + +fn check_overalign_requests<T: Alloc>(mut allocator: T) { + let size = 8; + let align = 16; // greater than size + let iterations = 100; + unsafe { + let pointers: Vec<_> = (0..iterations).map(|_| { + allocator.alloc(Layout::from_size_align(size, align).unwrap()).unwrap() + }).collect(); + for &ptr in &pointers { + assert_eq!((ptr as usize) % align, 0, "Got a pointer less aligned than requested") + } + + // Clean up + for &ptr in &pointers { + allocator.dealloc(ptr, Layout::from_size_align(size, align).unwrap()) + } + } +} diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs index 00ebd88d464..f1e95883b38 100644 --- a/src/liballoc/tests/lib.rs +++ b/src/liballoc/tests/lib.rs @@ -10,6 +10,8 @@ #![deny(warnings)] +#![feature(allocator_api)] +#![feature(alloc_system)] #![feature(attr_literals)] #![feature(box_syntax)] #![feature(inclusive_range_syntax)] @@ -29,6 +31,7 @@ #![feature(unboxed_closures)] #![feature(unicode)] +extern crate alloc_system; extern crate std_unicode; extern crate rand; @@ -39,6 +42,7 @@ mod binary_heap; mod btree; mod cow_str; mod fmt; +mod heap; mod linked_list; mod slice; mod str; |
