2017-07-07 18:07:16 +00:00
|
|
|
#![feature(global_allocator, allocator_api)]
|
2017-07-07 15:23:27 +00:00
|
|
|
|
2017-05-30 04:58:12 +00:00
|
|
|
extern crate libc;
|
2017-07-07 15:23:27 +00:00
|
|
|
extern crate jemallocator;
|
|
|
|
|
|
|
|
use std::heap::{Alloc, Layout};
|
|
|
|
use jemallocator::Jemalloc;
|
2017-05-30 04:58:12 +00:00
|
|
|
|
2017-07-07 18:07:16 +00:00
|
|
|
#[global_allocator]
|
|
|
|
static A: Jemalloc = Jemalloc;
|
|
|
|
|
2017-05-30 04:58:12 +00:00
|
|
|
#[test]
|
|
|
|
fn smoke() {
|
2017-07-07 15:23:27 +00:00
|
|
|
let layout = Layout::from_size_align(100, 8).unwrap();
|
|
|
|
unsafe {
|
2018-04-27 09:37:16 +00:00
|
|
|
let ptr = Jemalloc.alloc(layout.clone()).unwrap();
|
2017-07-07 15:23:27 +00:00
|
|
|
Jemalloc.dealloc(ptr, layout);
|
|
|
|
}
|
2017-05-30 04:58:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_mallctl() {
|
|
|
|
let mut epoch: u64 = 0;
|
|
|
|
unsafe {
|
2017-07-07 15:23:27 +00:00
|
|
|
assert_eq!(jemallocator::mallctl_fetch(b"", &mut epoch), Err(libc::EINVAL));
|
|
|
|
assert_eq!(jemallocator::mallctl_fetch(b"epoch", &mut epoch),
|
2017-05-30 04:58:12 +00:00
|
|
|
Err(libc::EINVAL));
|
2017-07-07 15:23:27 +00:00
|
|
|
jemallocator::mallctl_fetch(b"epoch\0", &mut epoch).unwrap();
|
2017-05-30 04:58:12 +00:00
|
|
|
assert!(epoch > 0);
|
2017-07-07 15:23:27 +00:00
|
|
|
assert_eq!(jemallocator::mallctl_set(b"", epoch), Err(libc::EINVAL));
|
|
|
|
assert_eq!(jemallocator::mallctl_set(b"epoch", epoch), Err(libc::EINVAL));
|
|
|
|
jemallocator::mallctl_set(b"epoch\0", epoch).unwrap();
|
2017-05-30 04:58:12 +00:00
|
|
|
}
|
|
|
|
}
|