1 use std::alloc::{GlobalAlloc, Layout};
2 use tikv_jemallocator::Jemalloc;
3 
4 #[global_allocator]
5 static A: Jemalloc = Jemalloc;
6 
7 #[test]
smoke()8 fn smoke() {
9     let mut a = Vec::new();
10     a.reserve(1);
11     a.push(3);
12 }
13 
14 /// https://github.com/rust-lang/rust/issues/45955
15 #[test]
overaligned()16 fn overaligned() {
17     let size = 8;
18     let align = 16; // greater than size
19     let iterations = 100;
20     unsafe {
21         let pointers: Vec<_> = (0..iterations)
22             .map(|_| {
23                 let ptr = Jemalloc.alloc(Layout::from_size_align(size, align).unwrap());
24                 assert!(!ptr.is_null());
25                 ptr
26             })
27             .collect();
28         for &ptr in &pointers {
29             assert_eq!(
30                 (ptr as usize) % align,
31                 0,
32                 "Got a pointer less aligned than requested"
33             )
34         }
35 
36         // Clean up
37         for &ptr in &pointers {
38             Jemalloc.dealloc(ptr, Layout::from_size_align(size, align).unwrap())
39         }
40     }
41 }
42