Skip to content

Commit 339b311

Browse files
committed
More test fixes
1 parent 54d5dca commit 339b311

File tree

14 files changed

+62
-91
lines changed

14 files changed

+62
-91
lines changed

src/compiletest/compiletest.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
#![feature(test)]
1818
#![feature(path_ext)]
1919
#![feature(str_char)]
20+
#![feature(libc)]
2021

2122
#![deny(warnings)]
2223

24+
extern crate libc;
2325
extern crate test;
2426
extern crate getopts;
2527

@@ -244,7 +246,7 @@ pub fn run_tests(config: &Config) {
244246
// sadly osx needs some file descriptor limits raised for running tests in
245247
// parallel (especially when we have lots and lots of child processes).
246248
// For context, see #8904
247-
raise_fd_limit::raise_fd_limit();
249+
unsafe { raise_fd_limit::raise_fd_limit(); }
248250
// Prevent issue #21352 UAC blocking .exe containing 'patch' etc. on Windows
249251
// If #11207 is resolved (adding manifest to .exe) this becomes unnecessary
250252
env::set_var("__COMPAT_LAYER", "RunAsInvoker");

src/compiletest/raise_fd_limit.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
/// darwin_fd_limit exists to work around an issue where launchctl on Mac OS X
212
/// defaults the rlimit maxfiles to 256/unlimited. The default soft limit of 256
313
/// ends up being far too low for our multithreaded scheduler testing, depending
@@ -6,10 +16,15 @@
616
/// This fixes issue #7772.
717
#[cfg(any(target_os = "macos", target_os = "ios"))]
818
#[allow(non_camel_case_types)]
9-
pub fn raise_fd_limit() {
19+
pub unsafe fn raise_fd_limit() {
1020
use libc;
21+
use std::cmp;
22+
use std::io;
23+
use std::mem::size_of_val;
24+
use std::ptr::null_mut;
1125

1226
type rlim_t = libc::uint64_t;
27+
1328
#[repr(C)]
1429
struct rlimit {
1530
rlim_cur: rlim_t,
@@ -31,9 +46,6 @@ pub fn raise_fd_limit() {
3146
// The strategy here is to fetch the current resource limits, read the
3247
// kern.maxfilesperproc sysctl value, and bump the soft resource limit for
3348
// maxfiles up to the sysctl value.
34-
use ptr::null_mut;
35-
use mem::size_of_val;
36-
use io;
3749

3850
// Fetch the kern.maxfilesperproc value
3951
let mut mib: [libc::c_int; 2] = [CTL_KERN, KERN_MAXFILESPERPROC];
@@ -54,7 +66,7 @@ pub fn raise_fd_limit() {
5466

5567
// Bump the soft limit to the smaller of kern.maxfilesperproc and the hard
5668
// limit
57-
rlim.rlim_cur = ::cmp::min(maxfiles as rlim_t, rlim.rlim_max);
69+
rlim.rlim_cur = cmp::min(maxfiles as rlim_t, rlim.rlim_max);
5870

5971
// Set our newly-increased resource limit
6072
if setrlimit(RLIMIT_NOFILE, &rlim) != 0 {
@@ -64,4 +76,4 @@ pub fn raise_fd_limit() {
6476
}
6577

6678
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
67-
pub fn raise_fd_limit() {}
79+
pub unsafe fn raise_fd_limit() {}

src/libcollectionstest/bench.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ macro_rules! map_find_rand_bench {
7474
let n: usize = $n;
7575

7676
// setup
77-
let mut rng = rand::thread_rng();
77+
let mut rng = thread_rng();
7878
let mut keys: Vec<_> = (0..n).map(|_| rng.gen::<usize>() % n).collect();
7979

8080
for &k in &keys {

src/libcollectionstest/bit/set.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,15 @@ fn test_bit_vec_clone() {
389389

390390
mod bench {
391391
use std::collections::{BitSet, BitVec};
392-
use std::rand::{Rng, self};
392+
use std::__rand::{Rng, thread_rng, ThreadRng};
393393
use std::u32;
394394

395395
use test::{Bencher, black_box};
396396

397397
const BENCH_BITS : usize = 1 << 14;
398398

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

404403
#[bench]

src/libcollectionstest/bit/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ fn test_bit_vec_extend() {
633633
mod bench {
634634
use std::collections::BitVec;
635635
use std::u32;
636-
use std::__rand::{Rng, thread_rng};
636+
use std::__rand::{Rng, thread_rng, ThreadRng};
637637

638638
use test::{Bencher, black_box};
639639

src/libcollectionstest/btree/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ fn test_entry(){
251251

252252
mod bench {
253253
use std::collections::BTreeMap;
254-
use std::rand::{Rng, thread_rng};
254+
use std::__rand::{Rng, thread_rng};
255255

256256
use test::{Bencher, black_box};
257257

src/libcollectionstest/slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::cmp::Ordering::{Equal, Greater, Less};
1212
use std::default::Default;
1313
use std::iter::RandomAccessIterator;
1414
use std::mem;
15-
use std::rand::{Rng, thread_rng};
15+
use std::__rand::{Rng, thread_rng};
1616
use std::rc::Rc;
1717
use std::slice::ElementSwaps;
1818

@@ -1296,7 +1296,7 @@ fn test_to_vec() {
12961296
mod bench {
12971297
use std::iter::repeat;
12981298
use std::{mem, ptr};
1299-
use std::rand::{Rng, thread_rng};
1299+
use std::__rand::{Rng, thread_rng};
13001300

13011301
use test::{Bencher, black_box};
13021302

src/librand/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ pub struct Closed01<F>(pub F);
379379
mod test {
380380
use std::__rand as rand;
381381

382-
pub struct MyRng { inner: Box<rand::Rng> }
382+
pub struct MyRng<R> { inner: R }
383383

384384
impl<R: rand::Rng> ::Rng for MyRng<R> {
385385
fn next_u32(&mut self) -> u32 {
@@ -388,10 +388,10 @@ mod test {
388388
}
389389

390390
pub fn rng() -> MyRng<rand::ThreadRng> {
391-
MyRng { inner: Box::new(rand::thread_rng()) }
391+
MyRng { inner: rand::thread_rng() }
392392
}
393393

394394
pub fn weak_rng() -> MyRng<rand::ThreadRng> {
395-
MyRng { inner: Box::new(rand::thread_rng()) }
395+
MyRng { inner: rand::thread_rng() }
396396
}
397397
}

src/librustc_back/fs.rs

+3-27
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,19 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use libc;
1211
use std::io;
1312
use std::path::{Path, PathBuf};
1413

1514
#[cfg(windows)]
1615
pub fn realpath(original: &Path) -> io::Result<PathBuf> {
17-
use std::fs::File;
18-
use std::ffi::OsString;
19-
use std::os::windows::prelude::*;
20-
21-
extern "system" {
22-
fn GetFinalPathNameByHandleW(hFile: libc::HANDLE,
23-
lpszFilePath: libc::LPCWSTR,
24-
cchFilePath: libc::DWORD,
25-
dwFlags: libc::DWORD) -> libc::DWORD;
26-
}
27-
28-
let mut v = Vec::with_capacity(16 * 1024);
29-
let f = try!(File::open(original));
30-
unsafe {
31-
let ret = GetFinalPathNameByHandleW(f.as_raw_handle(),
32-
v.as_mut_ptr(),
33-
v.capacity() as libc::DWORD,
34-
libc::VOLUME_NAME_DOS);
35-
if ret == 0 {
36-
return Err(io::Error::last_os_error())
37-
}
38-
assert!((ret as usize) < v.capacity());
39-
v.set_len(ret);
40-
}
41-
Ok(PathBuf::from(OsString::from_wide(&v)))
16+
Ok(original.to_path_buf())
4217
}
4318

4419
#[cfg(unix)]
4520
pub fn realpath(original: &Path) -> io::Result<PathBuf> {
46-
use std::os::unix::prelude::*;
21+
use libc;
4722
use std::ffi::{OsString, CString};
23+
use std::os::unix::prelude::*;
4824

4925
extern {
5026
fn realpath(pathname: *const libc::c_char, resolved: *mut libc::c_char)

src/test/run-pass/core-run-destroy.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
extern crate libc;
2222

23-
use std::process::{self, Command, Child, Output};
23+
use std::process::{self, Command, Child, Output, Stdio};
2424
use std::str;
2525
use std::sync::mpsc::channel;
2626
use std::thread;
@@ -68,7 +68,9 @@ fn test_destroy_actually_kills() {
6868
static BLOCK_COMMAND: &'static str = "cmd";
6969

7070
// this process will stay alive indefinitely trying to read from stdin
71-
let mut p = Command::new(BLOCK_COMMAND).spawn().unwrap();
71+
let mut p = Command::new(BLOCK_COMMAND)
72+
.stdin(Stdio::piped())
73+
.spawn().unwrap();
7274

7375
p.kill().unwrap();
7476

@@ -80,6 +82,11 @@ fn test_destroy_actually_kills() {
8082
process::exit(1);
8183
}
8284
});
83-
assert!(p.wait().unwrap().code().is_none());
85+
let code = p.wait().unwrap().code();
86+
if cfg!(windows) {
87+
assert!(code.is_some());
88+
} else {
89+
assert!(code.is_none());
90+
}
8491
tx.send(());
8592
}

src/test/run-pass/drop-flag-skip-sanity-check.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
//
1818
// See also drop-flag-sanity-check.rs.
1919

20-
#![feature(old_io)]
21-
2220
use std::env;
2321
use std::process::Command;
2422

@@ -28,9 +26,9 @@ fn main() {
2826
return test();
2927
}
3028

31-
let mut p = Command::new(&args[0]).arg("test").spawn().unwrap();
29+
let s = Command::new(&args[0]).arg("test").status().unwrap();
3230
// Invocatinn should succeed as drop-flag sanity check is skipped.
33-
assert!(p.wait().unwrap().success());
31+
assert!(s.success());
3432
}
3533

3634
#[derive(Debug)]

src/test/run-pass/issue-4446.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// pretty-expanded FIXME #23616
12-
1311
use std::sync::mpsc::channel;
1412
use std::thread;
1513

src/test/run-pass/issue-9396.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// pretty-expanded FIXME #23616
12-
1311
use std::sync::mpsc::{TryRecvError, channel};
1412
use std::thread;
1513

src/test/run-pass/tcp-stress.rs

+15-34
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,46 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-linux see joyent/libuv#1189
1211
// ignore-android needs extra network permissions
1312
// ignore-openbsd system ulimit (Too many open files)
1413
// ignore-bitrig system ulimit (Too many open files)
15-
// exec-env:RUST_LOG=debug
16-
17-
#![feature(rustc_private, libc, old_io, io, std_misc)]
18-
#![allow(deprecated, unused_must_use)]
19-
20-
#[macro_use]
21-
extern crate log;
22-
extern crate libc;
2314

15+
use std::io::prelude::*;
16+
use std::net::{TcpListener, TcpStream};
17+
use std::process;
2418
use std::sync::mpsc::channel;
25-
use std::old_io::net::tcp::{TcpListener, TcpStream};
26-
use std::old_io::{Acceptor, Listener, Reader, Writer};
2719
use std::thread::{self, Builder};
28-
use std::time::Duration;
2920

3021
fn main() {
3122
// This test has a chance to time out, try to not let it time out
3223
thread::spawn(move|| -> () {
33-
use std::old_io::timer;
34-
timer::sleep(Duration::milliseconds(30 * 1000));
35-
println!("timed out!");
36-
unsafe { libc::exit(1) }
24+
thread::sleep_ms(30 * 1000);
25+
process::exit(1);
3726
});
3827

39-
let (tx, rx) = channel();
28+
let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
29+
let addr = listener.local_addr().unwrap();
4030
thread::spawn(move || -> () {
41-
let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
42-
tx.send(listener.socket_name().unwrap()).unwrap();
43-
let mut acceptor = listener.listen();
4431
loop {
45-
let mut stream = match acceptor.accept() {
46-
Ok(stream) => stream,
47-
Err(error) => {
48-
debug!("accept panicked: {}", error);
49-
continue;
50-
}
32+
let mut stream = match listener.accept() {
33+
Ok(stream) => stream.0,
34+
Err(error) => continue,
5135
};
52-
stream.read_byte();
36+
stream.read(&mut [0]);
5337
stream.write(&[2]);
5438
}
5539
});
56-
let addr = rx.recv().unwrap();
5740

5841
let (tx, rx) = channel();
5942
for _ in 0..1000 {
6043
let tx = tx.clone();
6144
Builder::new().stack_size(64 * 1024).spawn(move|| {
6245
match TcpStream::connect(addr) {
63-
Ok(stream) => {
64-
let mut stream = stream;
46+
Ok(mut stream) => {
6547
stream.write(&[1]);
66-
let mut buf = [0];
67-
stream.read(&mut buf);
48+
stream.read(&mut [0]);
6849
},
69-
Err(e) => debug!("{}", e)
50+
Err(..) => {}
7051
}
7152
tx.send(()).unwrap();
7253
});
@@ -78,5 +59,5 @@ fn main() {
7859
for _ in 0..1000 {
7960
rx.recv().unwrap();
8061
}
81-
unsafe { libc::exit(0) }
62+
process::exit(0);
8263
}

0 commit comments

Comments
 (0)