1 //! Test background threads run-time default settings.
2 
3 extern crate jemalloc_ctl;
4 extern crate jemallocator;
5 extern crate libc;
6 
7 use jemallocator::Jemalloc;
8 
9 #[global_allocator]
10 static A: Jemalloc = Jemalloc;
11 
12 // Returns true if background threads are enabled.
13 fn background_threads() -> bool {
14     jemalloc_ctl::opt::background_thread::read().unwrap()
15 }
16 
17 #[test]
18 fn background_threads_runtime_defaults() {
19     if !cfg!(feature = "background_threads_runtime_support") {
20         // If the crate was compiled without background thread support,
21         // then background threads are always disabled at run-time by default:
22         assert_eq!(background_threads(), false);
23         return;
24     }
25 
26     if cfg!(feature = "background_threads") {
27         // The crate was compiled with background-threads enabled by default:
28         assert_eq!(background_threads(), true);
29     } else {
30         // The crate was compiled with background-threads disabled by default:
31         assert_eq!(background_threads(), false);
32     }
33 }
34