Skip to content

Commit 84a89ed

Browse files
committed
compiletest: Re-add raise_fd_limit
This apparently fixes obscure bugs on OSX!
1 parent 0516c40 commit 84a89ed

File tree

3 files changed

+70
-13
lines changed

3 files changed

+70
-13
lines changed

src/compiletest/compiletest.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
#![feature(box_syntax)]
1414
#![feature(collections)]
15-
#![feature(old_io)]
1615
#![feature(rustc_private)]
17-
#![feature(unboxed_closures)]
1816
#![feature(std_misc)]
1917
#![feature(test)]
2018
#![feature(path_ext)]
@@ -42,6 +40,7 @@ pub mod header;
4240
pub mod runtest;
4341
pub mod common;
4442
pub mod errors;
43+
mod raise_fd_limit;
4544

4645
pub fn main() {
4746
let config = parse_config(env::args().collect());
@@ -245,11 +244,7 @@ pub fn run_tests(config: &Config) {
245244
// sadly osx needs some file descriptor limits raised for running tests in
246245
// parallel (especially when we have lots and lots of child processes).
247246
// For context, see #8904
248-
#[allow(deprecated)]
249-
fn raise_fd_limit() {
250-
std::old_io::test::raise_fd_limit();
251-
}
252-
raise_fd_limit();
247+
raise_fd_limit::raise_fd_limit();
253248
// Prevent issue #21352 UAC blocking .exe containing 'patch' etc. on Windows
254249
// If #11207 is resolved (adding manifest to .exe) this becomes unnecessary
255250
env::set_var("__COMPAT_LAYER", "RunAsInvoker");

src/compiletest/raise_fd_limit.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/// darwin_fd_limit exists to work around an issue where launchctl on Mac OS X
2+
/// defaults the rlimit maxfiles to 256/unlimited. The default soft limit of 256
3+
/// ends up being far too low for our multithreaded scheduler testing, depending
4+
/// on the number of cores available.
5+
///
6+
/// This fixes issue #7772.
7+
#[cfg(any(target_os = "macos", target_os = "ios"))]
8+
#[allow(non_camel_case_types)]
9+
pub fn raise_fd_limit() {
10+
use libc;
11+
12+
type rlim_t = libc::uint64_t;
13+
#[repr(C)]
14+
struct rlimit {
15+
rlim_cur: rlim_t,
16+
rlim_max: rlim_t
17+
}
18+
extern {
19+
// name probably doesn't need to be mut, but the C function doesn't
20+
// specify const
21+
fn sysctl(name: *mut libc::c_int, namelen: libc::c_uint,
22+
oldp: *mut libc::c_void, oldlenp: *mut libc::size_t,
23+
newp: *mut libc::c_void, newlen: libc::size_t) -> libc::c_int;
24+
fn getrlimit(resource: libc::c_int, rlp: *mut rlimit) -> libc::c_int;
25+
fn setrlimit(resource: libc::c_int, rlp: *const rlimit) -> libc::c_int;
26+
}
27+
static CTL_KERN: libc::c_int = 1;
28+
static KERN_MAXFILESPERPROC: libc::c_int = 29;
29+
static RLIMIT_NOFILE: libc::c_int = 8;
30+
31+
// The strategy here is to fetch the current resource limits, read the
32+
// kern.maxfilesperproc sysctl value, and bump the soft resource limit for
33+
// maxfiles up to the sysctl value.
34+
use ptr::null_mut;
35+
use mem::size_of_val;
36+
use io;
37+
38+
// Fetch the kern.maxfilesperproc value
39+
let mut mib: [libc::c_int; 2] = [CTL_KERN, KERN_MAXFILESPERPROC];
40+
let mut maxfiles: libc::c_int = 0;
41+
let mut size: libc::size_t = size_of_val(&maxfiles) as libc::size_t;
42+
if sysctl(&mut mib[0], 2, &mut maxfiles as *mut _ as *mut _, &mut size,
43+
null_mut(), 0) != 0 {
44+
let err = io::Error::last_os_error();
45+
panic!("raise_fd_limit: error calling sysctl: {}", err);
46+
}
47+
48+
// Fetch the current resource limits
49+
let mut rlim = rlimit{rlim_cur: 0, rlim_max: 0};
50+
if getrlimit(RLIMIT_NOFILE, &mut rlim) != 0 {
51+
let err = io::Error::last_os_error();
52+
panic!("raise_fd_limit: error calling getrlimit: {}", err);
53+
}
54+
55+
// Bump the soft limit to the smaller of kern.maxfilesperproc and the hard
56+
// limit
57+
rlim.rlim_cur = ::cmp::min(maxfiles as rlim_t, rlim.rlim_max);
58+
59+
// Set our newly-increased resource limit
60+
if setrlimit(RLIMIT_NOFILE, &rlim) != 0 {
61+
let err = io::Error::last_os_error();
62+
panic!("raise_fd_limit: error calling setrlimit: {}", err);
63+
}
64+
}
65+
66+
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
67+
pub fn raise_fd_limit() {}

src/compiletest/runtest.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use std::net::TcpStream;
2929
use std::path::{Path, PathBuf};
3030
use std::process::{Command, Output, ExitStatus};
3131
use std::str;
32-
use std::time::Duration;
3332
use test::MetricMap;
3433

3534
pub fn run(config: Config, testfile: &Path) {
@@ -452,11 +451,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
452451
.expect(&format!("failed to exec `{:?}`", config.adb_path));
453452
loop {
454453
//waiting 1 second for gdbserver start
455-
#[allow(deprecated)]
456-
fn sleep() {
457-
::std::old_io::timer::sleep(Duration::milliseconds(1000));
458-
}
459-
sleep();
454+
::std::thread::sleep_ms(1000);
460455
if TcpStream::connect("127.0.0.1:5039").is_ok() {
461456
break
462457
}

0 commit comments

Comments
 (0)