1 //! Test enabling / disabling background threads at run-time if the
2 //! library was compiled with background thread run-time support.
3 #![cfg(feature = "background_threads_runtime_support")]
4 #![cfg(not(feature = "unprefixed_malloc_on_supported_platforms"))]
5 #![cfg(not(target_env = "musl"))]
6 
7 extern crate jemalloc_ctl;
8 extern crate jemallocator;
9 extern crate libc;
10 
11 use jemallocator::Jemalloc;
12 
13 #[global_allocator]
14 static A: Jemalloc = Jemalloc;
15 
16 union U {
17     x: &'static u8,
18     y: &'static libc::c_char,
19 }
20 
21 // Even if background threads are not enabled at run-time by default
22 // at configuration time, this enables them.
23 #[allow(non_upper_case_globals)]
24 #[export_name = "_rjem_malloc_conf"]
25 pub static malloc_conf: Option<&'static libc::c_char> = Some(unsafe {
26     U {
27         x: &b"background_thread:true\0"[0],
28     }
29     .y
30 });
31 
32 #[test]
background_threads_enabled()33 fn background_threads_enabled() {
34     // Background threads are unconditionally enabled at run-time by default.
35     assert_eq!(jemalloc_ctl::opt::background_thread::read().unwrap(), true);
36 }
37