1 //! Helper module which helps to determine amount of threads to be used
2 //! during tests execution.
6 pub fn get_concurrency() -> usize {
7 return match env::var("RUST_TEST_THREADS") {
9 let opt_n: Option<usize> = s.parse().ok();
11 Some(n) if n > 0 => n,
12 _ => panic!("RUST_TEST_THREADS is `{}`, should be a positive integer.", s),
15 Err(..) => num_cpus(),
19 #[allow(nonstandard_style)]
20 fn num_cpus() -> usize {
23 wProcessorArchitecture: u16,
26 lpMinimumApplicationAddress: *mut u8,
27 lpMaximumApplicationAddress: *mut u8,
28 dwActiveProcessorMask: *mut u8,
29 dwNumberOfProcessors: u32,
31 dwAllocationGranularity: u32,
33 wProcessorRevision: u16,
36 fn GetSystemInfo(info: *mut SYSTEM_INFO) -> i32;
39 let mut sysinfo = std::mem::zeroed();
40 GetSystemInfo(&mut sysinfo);
41 sysinfo.dwNumberOfProcessors as usize
45 #[cfg(target_os = "vxworks")]
46 fn num_cpus() -> usize {
47 // FIXME: Implement num_cpus on vxWorks
51 #[cfg(target_os = "redox")]
52 fn num_cpus() -> usize {
53 // FIXME: Implement num_cpus on Redox
57 #[cfg(target_os = "hermit")]
58 fn num_cpus() -> usize {
59 // FIXME: Implement num_cpus on HermitCore
64 all(target_arch = "wasm32", not(target_os = "emscripten")),
65 all(target_vendor = "fortanix", target_env = "sgx")
67 fn num_cpus() -> usize {
72 target_os = "android",
73 target_os = "cloudabi",
74 target_os = "emscripten",
75 target_os = "fuchsia",
79 target_os = "solaris",
81 fn num_cpus() -> usize {
82 unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as usize }
85 #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd"))]
86 fn num_cpus() -> usize {
89 let mut cpus: libc::c_uint = 0;
90 let mut cpus_size = std::mem::size_of_val(&cpus);
93 cpus = libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as libc::c_uint;
96 let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
101 &mut cpus as *mut _ as *mut _,
102 &mut cpus_size as *mut _ as *mut _,
114 #[cfg(target_os = "openbsd")]
115 fn num_cpus() -> usize {
118 let mut cpus: libc::c_uint = 0;
119 let mut cpus_size = std::mem::size_of_val(&cpus);
120 let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
126 &mut cpus as *mut _ as *mut _,
127 &mut cpus_size as *mut _ as *mut _,
138 #[cfg(target_os = "haiku")]
139 fn num_cpus() -> usize {
144 #[cfg(target_os = "l4re")]
145 fn num_cpus() -> usize {