From 84a89ed3effb37c86ca686adbb447275f3562a09 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 10 Apr 2015 10:36:13 -0700 Subject: [PATCH] compiletest: Re-add raise_fd_limit This apparently fixes obscure bugs on OSX! --- src/compiletest/compiletest.rs | 9 +---- src/compiletest/raise_fd_limit.rs | 67 +++++++++++++++++++++++++++++++ src/compiletest/runtest.rs | 7 +--- 3 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 src/compiletest/raise_fd_limit.rs diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index e680be2a8c5..b93ab5d3134 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -12,9 +12,7 @@ #![feature(box_syntax)] #![feature(collections)] -#![feature(old_io)] #![feature(rustc_private)] -#![feature(unboxed_closures)] #![feature(std_misc)] #![feature(test)] #![feature(path_ext)] @@ -42,6 +40,7 @@ pub mod header; pub mod runtest; pub mod common; pub mod errors; +mod raise_fd_limit; pub fn main() { let config = parse_config(env::args().collect()); @@ -245,11 +244,7 @@ pub fn run_tests(config: &Config) { // sadly osx needs some file descriptor limits raised for running tests in // parallel (especially when we have lots and lots of child processes). // For context, see #8904 - #[allow(deprecated)] - fn raise_fd_limit() { - std::old_io::test::raise_fd_limit(); - } - raise_fd_limit(); + raise_fd_limit::raise_fd_limit(); // Prevent issue #21352 UAC blocking .exe containing 'patch' etc. on Windows // If #11207 is resolved (adding manifest to .exe) this becomes unnecessary env::set_var("__COMPAT_LAYER", "RunAsInvoker"); diff --git a/src/compiletest/raise_fd_limit.rs b/src/compiletest/raise_fd_limit.rs new file mode 100644 index 00000000000..bf252fa0e74 --- /dev/null +++ b/src/compiletest/raise_fd_limit.rs @@ -0,0 +1,67 @@ +/// darwin_fd_limit exists to work around an issue where launchctl on Mac OS X +/// defaults the rlimit maxfiles to 256/unlimited. The default soft limit of 256 +/// ends up being far too low for our multithreaded scheduler testing, depending +/// on the number of cores available. +/// +/// This fixes issue #7772. +#[cfg(any(target_os = "macos", target_os = "ios"))] +#[allow(non_camel_case_types)] +pub fn raise_fd_limit() { + use libc; + + type rlim_t = libc::uint64_t; + #[repr(C)] + struct rlimit { + rlim_cur: rlim_t, + rlim_max: rlim_t + } + extern { + // name probably doesn't need to be mut, but the C function doesn't + // specify const + fn sysctl(name: *mut libc::c_int, namelen: libc::c_uint, + oldp: *mut libc::c_void, oldlenp: *mut libc::size_t, + newp: *mut libc::c_void, newlen: libc::size_t) -> libc::c_int; + fn getrlimit(resource: libc::c_int, rlp: *mut rlimit) -> libc::c_int; + fn setrlimit(resource: libc::c_int, rlp: *const rlimit) -> libc::c_int; + } + static CTL_KERN: libc::c_int = 1; + static KERN_MAXFILESPERPROC: libc::c_int = 29; + static RLIMIT_NOFILE: libc::c_int = 8; + + // The strategy here is to fetch the current resource limits, read the + // kern.maxfilesperproc sysctl value, and bump the soft resource limit for + // maxfiles up to the sysctl value. + use ptr::null_mut; + use mem::size_of_val; + use io; + + // Fetch the kern.maxfilesperproc value + let mut mib: [libc::c_int; 2] = [CTL_KERN, KERN_MAXFILESPERPROC]; + let mut maxfiles: libc::c_int = 0; + let mut size: libc::size_t = size_of_val(&maxfiles) as libc::size_t; + if sysctl(&mut mib[0], 2, &mut maxfiles as *mut _ as *mut _, &mut size, + null_mut(), 0) != 0 { + let err = io::Error::last_os_error(); + panic!("raise_fd_limit: error calling sysctl: {}", err); + } + + // Fetch the current resource limits + let mut rlim = rlimit{rlim_cur: 0, rlim_max: 0}; + if getrlimit(RLIMIT_NOFILE, &mut rlim) != 0 { + let err = io::Error::last_os_error(); + panic!("raise_fd_limit: error calling getrlimit: {}", err); + } + + // Bump the soft limit to the smaller of kern.maxfilesperproc and the hard + // limit + rlim.rlim_cur = ::cmp::min(maxfiles as rlim_t, rlim.rlim_max); + + // Set our newly-increased resource limit + if setrlimit(RLIMIT_NOFILE, &rlim) != 0 { + let err = io::Error::last_os_error(); + panic!("raise_fd_limit: error calling setrlimit: {}", err); + } +} + +#[cfg(not(any(target_os = "macos", target_os = "ios")))] +pub fn raise_fd_limit() {} diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index daa53e2dbd5..55f15867532 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -29,7 +29,6 @@ use std::net::TcpStream; use std::path::{Path, PathBuf}; use std::process::{Command, Output, ExitStatus}; use std::str; -use std::time::Duration; use test::MetricMap; pub fn run(config: Config, testfile: &Path) { @@ -452,11 +451,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) { .expect(&format!("failed to exec `{:?}`", config.adb_path)); loop { //waiting 1 second for gdbserver start - #[allow(deprecated)] - fn sleep() { - ::std::old_io::timer::sleep(Duration::milliseconds(1000)); - } - sleep(); + ::std::thread::sleep_ms(1000); if TcpStream::connect("127.0.0.1:5039").is_ok() { break }