jemallocator/tests/malloctl.rs

54 lines
1.1 KiB
Rust
Raw Permalink Normal View History

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
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-07-07 18:07:16 +00:00
#[global_allocator]
static A: Jemalloc = Jemalloc;
#[test]
fn smoke() {
2017-07-07 15:23:27 +00:00
let layout = Layout::from_size_align(100, 8).unwrap();
unsafe {
let ptr = Jemalloc.alloc(layout.clone());
assert!(!ptr.is_null());
2017-07-07 15:23:27 +00:00
Jemalloc.dealloc(ptr, layout);
}
}
#[test]
fn ctl_get_set() {
let epoch: u64 = "epoch\0".name().read().unwrap();
assert!(epoch > 0);
"epoch\0".name().write(epoch).unwrap();
}
#[test]
#[should_panic]
fn ctl_panic_empty_get() {
let _: u64 = "".name().read().unwrap();
}
#[test]
#[should_panic]
fn ctl_panic_empty_set() {
let epoch: u64 = "epoch\0".name().read().unwrap();
"".name().write(epoch).unwrap();
}
#[test]
#[should_panic]
fn ctl_panic_non_null_terminated_get() {
let _: u64 = "epoch".name().read().unwrap();
}
#[test]
#[should_panic]
fn ctl_panic_non_null_terminated_set() {
let epoch: u64 = "epoch\0".name().read().unwrap();
"epoch".name().write(epoch).unwrap();
}