1 use std::alloc::{GlobalAlloc, Layout};
2 use tikv_jemalloc_ctl::{Access, AsName};
3 use tikv_jemallocator::Jemalloc;
4 
5 #[global_allocator]
6 static A: Jemalloc = Jemalloc;
7 
8 #[test]
smoke()9 fn smoke() {
10     let layout = Layout::from_size_align(100, 8).unwrap();
11     unsafe {
12         let ptr = Jemalloc.alloc(layout);
13         assert!(!ptr.is_null());
14         Jemalloc.dealloc(ptr, layout);
15     }
16 }
17 
18 #[test]
ctl_get_set()19 fn ctl_get_set() {
20     let epoch: u64 = "epoch\0".name().read().unwrap();
21     assert!(epoch > 0);
22     "epoch\0".name().write(epoch).unwrap();
23 }
24 
25 #[test]
26 #[should_panic]
ctl_panic_empty_get()27 fn ctl_panic_empty_get() {
28     let _: u64 = "".name().read().unwrap();
29 }
30 
31 #[test]
32 #[should_panic]
ctl_panic_empty_set()33 fn ctl_panic_empty_set() {
34     let epoch: u64 = "epoch\0".name().read().unwrap();
35     "".name().write(epoch).unwrap();
36 }
37 
38 #[test]
39 #[should_panic]
ctl_panic_non_null_terminated_get()40 fn ctl_panic_non_null_terminated_get() {
41     let _: u64 = "epoch".name().read().unwrap();
42 }
43 
44 #[test]
45 #[should_panic]
ctl_panic_non_null_terminated_set()46 fn ctl_panic_non_null_terminated_set() {
47     let epoch: u64 = "epoch\0".name().read().unwrap();
48     "epoch".name().write(epoch).unwrap();
49 }
50