Skip to content

std: Remove old_io/old_path/rand #24303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 15, 2015
11 changes: 4 additions & 7 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

#![feature(box_syntax)]
#![feature(collections)]
#![feature(old_io)]
#![feature(rustc_private)]
#![feature(unboxed_closures)]
#![feature(std_misc)]
#![feature(test)]
#![feature(path_ext)]
#![feature(str_char)]
#![feature(libc)]

#![deny(warnings)]

extern crate libc;
extern crate test;
extern crate getopts;

Expand All @@ -42,6 +42,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());
Expand Down Expand Up @@ -245,11 +246,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();
unsafe { 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");
Expand Down
79 changes: 79 additions & 0 deletions src/compiletest/raise_fd_limit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

/// 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 unsafe fn raise_fd_limit() {
use libc;
use std::cmp;
use std::io;
use std::mem::size_of_val;
use std::ptr::null_mut;

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.

// 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 unsafe fn raise_fd_limit() {}
7 changes: 1 addition & 6 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ mod test {
use std::clone::Clone;
use std::iter::Iterator;
use std::option::Option::{Some, None, self};
use std::rand;
use std::__rand::{thread_rng, Rng};
use std::thread;
use std::vec::Vec;

Expand Down Expand Up @@ -1095,7 +1095,7 @@ mod test {
let mut v = vec![];
for i in 0..sz {
check_links(&m);
let r: u8 = rand::random();
let r: u8 = thread_rng().next_u32() as u8;
match r % 6 {
0 => {
m.pop_back();
Expand Down
10 changes: 4 additions & 6 deletions src/libcollectionstest/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ macro_rules! map_insert_rand_bench {
($name: ident, $n: expr, $map: ident) => (
#[bench]
pub fn $name(b: &mut ::test::Bencher) {
use std::rand;
use std::rand::Rng;
use std::__rand::{thread_rng, Rng};
use test::black_box;

let n: usize = $n;
let mut map = $map::new();
// setup
let mut rng = rand::weak_rng();
let mut rng = thread_rng();

for _ in 0..n {
let i = rng.gen::<usize>() % n;
Expand Down Expand Up @@ -67,16 +66,15 @@ macro_rules! map_find_rand_bench {
#[bench]
pub fn $name(b: &mut ::test::Bencher) {
use std::iter::Iterator;
use std::rand::Rng;
use std::rand;
use std::__rand::{thread_rng, Rng};
use std::vec::Vec;
use test::black_box;

let mut map = $map::new();
let n: usize = $n;

// setup
let mut rng = rand::weak_rng();
let mut rng = thread_rng();
let mut keys: Vec<_> = (0..n).map(|_| rng.gen::<usize>() % n).collect();

for &k in &keys {
Expand Down
7 changes: 3 additions & 4 deletions src/libcollectionstest/bit/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,15 @@ fn test_bit_vec_clone() {

mod bench {
use std::collections::{BitSet, BitVec};
use std::rand::{Rng, self};
use std::__rand::{Rng, thread_rng, ThreadRng};
use std::u32;

use test::{Bencher, black_box};

const BENCH_BITS : usize = 1 << 14;

fn rng() -> rand::IsaacRng {
let seed: &[_] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
rand::SeedableRng::from_seed(seed)
fn rng() -> ThreadRng {
thread_rng()
}

#[bench]
Expand Down
7 changes: 3 additions & 4 deletions src/libcollectionstest/bit/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,15 +633,14 @@ fn test_bit_vec_extend() {
mod bench {
use std::collections::BitVec;
use std::u32;
use std::rand::{Rng, self};
use std::__rand::{Rng, thread_rng, ThreadRng};

use test::{Bencher, black_box};

const BENCH_BITS : usize = 1 << 14;

fn rng() -> rand::IsaacRng {
let seed: &[_] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
rand::SeedableRng::from_seed(seed)
fn rng() -> ThreadRng {
thread_rng()
}

#[bench]
Expand Down
4 changes: 2 additions & 2 deletions src/libcollectionstest/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ fn test_entry(){

mod bench {
use std::collections::BTreeMap;
use std::rand::{Rng, weak_rng};
use std::__rand::{Rng, thread_rng};

use test::{Bencher, black_box};

Expand All @@ -269,7 +269,7 @@ mod bench {

fn bench_iter(b: &mut Bencher, size: i32) {
let mut map = BTreeMap::<i32, i32>::new();
let mut rng = weak_rng();
let mut rng = thread_rng();

for _ in 0..size {
map.insert(rng.gen(), rng.gen());
Expand Down
20 changes: 10 additions & 10 deletions src/libcollectionstest/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::cmp::Ordering::{Equal, Greater, Less};
use std::default::Default;
use std::iter::RandomAccessIterator;
use std::mem;
use std::rand::{Rng, thread_rng};
use std::__rand::{Rng, thread_rng};
use std::rc::Rc;
use std::slice::ElementSwaps;

Expand Down Expand Up @@ -1296,7 +1296,7 @@ fn test_to_vec() {
mod bench {
use std::iter::repeat;
use std::{mem, ptr};
use std::rand::{Rng, weak_rng};
use std::__rand::{Rng, thread_rng};

use test::{Bencher, black_box};

Expand Down Expand Up @@ -1465,7 +1465,7 @@ mod bench {

#[bench]
fn random_inserts(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = thread_rng();
b.iter(|| {
let mut v: Vec<_> = repeat((0, 0)).take(30).collect();
for _ in 0..100 {
Expand All @@ -1477,7 +1477,7 @@ mod bench {
}
#[bench]
fn random_removes(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = thread_rng();
b.iter(|| {
let mut v: Vec<_> = repeat((0, 0)).take(130).collect();
for _ in 0..100 {
Expand All @@ -1489,7 +1489,7 @@ mod bench {

#[bench]
fn sort_random_small(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = thread_rng();
b.iter(|| {
let mut v: Vec<_> = rng.gen_iter::<u64>().take(5).collect();
v.sort();
Expand All @@ -1499,7 +1499,7 @@ mod bench {

#[bench]
fn sort_random_medium(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = thread_rng();
b.iter(|| {
let mut v: Vec<_> = rng.gen_iter::<u64>().take(100).collect();
v.sort();
Expand All @@ -1509,7 +1509,7 @@ mod bench {

#[bench]
fn sort_random_large(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = thread_rng();
b.iter(|| {
let mut v: Vec<_> = rng.gen_iter::<u64>().take(10000).collect();
v.sort();
Expand All @@ -1530,7 +1530,7 @@ mod bench {

#[bench]
fn sort_big_random_small(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = thread_rng();
b.iter(|| {
let mut v = rng.gen_iter::<BigSortable>().take(5)
.collect::<Vec<BigSortable>>();
Expand All @@ -1541,7 +1541,7 @@ mod bench {

#[bench]
fn sort_big_random_medium(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = thread_rng();
b.iter(|| {
let mut v = rng.gen_iter::<BigSortable>().take(100)
.collect::<Vec<BigSortable>>();
Expand All @@ -1552,7 +1552,7 @@ mod bench {

#[bench]
fn sort_big_random_large(b: &mut Bencher) {
let mut rng = weak_rng();
let mut rng = thread_rng();
b.iter(|| {
let mut v = rng.gen_iter::<BigSortable>().take(10000)
.collect::<Vec<BigSortable>>();
Expand Down
Loading