2018-11-07 18:57:11 +00:00
|
|
|
extern crate jemalloc_ctl;
|
2017-07-07 15:23:27 +00:00
|
|
|
extern crate jemallocator;
|
2018-10-30 19:34:36 +00:00
|
|
|
extern crate libc;
|
2017-07-07 15:23:27 +00:00
|
|
|
|
2018-11-09 09:25:44 +00:00
|
|
|
use jemalloc_ctl::{Access, AsName};
|
2017-07-07 15:23:27 +00:00
|
|
|
use jemallocator::Jemalloc;
|
2018-10-30 19:34:36 +00:00
|
|
|
use std::alloc::{GlobalAlloc, Layout};
|
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-06-13 14:36:07 +00:00
|
|
|
let ptr = Jemalloc.alloc(layout.clone());
|
|
|
|
assert!(!ptr.is_null());
|
2017-07-07 15:23:27 +00:00
|
|
|
Jemalloc.dealloc(ptr, layout);
|
|
|
|
}
|
2017-05-30 04:58:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2018-11-08 09:56:44 +00:00
|
|
|
fn ctl_get_set() {
|
2018-11-09 09:25:44 +00:00
|
|
|
let epoch: u64 = "epoch\0".name().read().unwrap();
|
2018-11-08 09:56:44 +00:00
|
|
|
assert!(epoch > 0);
|
2018-11-09 09:25:44 +00:00
|
|
|
"epoch\0".name().write(epoch).unwrap();
|
2018-11-08 09:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn ctl_panic_empty_get() {
|
2018-11-09 09:25:44 +00:00
|
|
|
let _: u64 = "".name().read().unwrap();
|
2018-11-08 09:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn ctl_panic_empty_set() {
|
2018-11-09 09:25:44 +00:00
|
|
|
let epoch: u64 = "epoch\0".name().read().unwrap();
|
|
|
|
"".name().write(epoch).unwrap();
|
2018-11-08 09:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn ctl_panic_non_null_terminated_get() {
|
2018-11-09 09:25:44 +00:00
|
|
|
let _: u64 = "epoch".name().read().unwrap();
|
2018-11-08 09:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic]
|
|
|
|
fn ctl_panic_non_null_terminated_set() {
|
2018-11-09 09:25:44 +00:00
|
|
|
let epoch: u64 = "epoch\0".name().read().unwrap();
|
|
|
|
"epoch".name().write(epoch).unwrap();
|
2017-05-30 04:58:12 +00:00
|
|
|
}
|