Skip to content

Commit 2ec9b8c

Browse files
committed
auto merge of #8500 : graydon/rust/2013-08-13-self-rollup, r=thestinger
close #8424 r=brson close #8173 r=brson close #8209 r=strcat
2 parents e6e678f + 610b2b5 commit 2ec9b8c

17 files changed

+303
-17
lines changed

src/compiletest/runtest.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::os;
2626
use std::str;
2727
use std::task::{spawn_sched, SingleThreaded};
2828
use std::vec;
29+
use std::unstable::running_on_valgrind;
2930

3031
use extra::test::MetricMap;
3132

@@ -38,11 +39,21 @@ pub fn run(config: config, testfile: ~str) {
3839
// that destroys parallelism if we let normal schedulers block.
3940
// It should be possible to remove this spawn once std::run is
4041
// rewritten to be non-blocking.
41-
do spawn_sched(SingleThreaded) {
42+
//
43+
// We do _not_ create another thread if we're running on V because
44+
// it serializes all threads anyways.
45+
if running_on_valgrind() {
4246
let config = config.take();
4347
let testfile = testfile.take();
4448
let mut _mm = MetricMap::new();
4549
run_metrics(config, testfile, &mut _mm);
50+
} else {
51+
do spawn_sched(SingleThreaded) {
52+
let config = config.take();
53+
let testfile = testfile.take();
54+
let mut _mm = MetricMap::new();
55+
run_metrics(config, testfile, &mut _mm);
56+
}
4657
}
4758
}
4859

src/libstd/rt/comm.rs

+10
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ mod test {
727727
use rt::test::*;
728728
use cell::Cell;
729729
use iter::Times;
730+
use rt::util;
730731

731732
#[test]
732733
fn oneshot_single_thread_close_port_first() {
@@ -875,6 +876,7 @@ mod test {
875876

876877
#[test]
877878
fn oneshot_multi_thread_close_stress() {
879+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
878880
do stress_factor().times {
879881
do run_in_newsched_task {
880882
let (port, chan) = oneshot::<int>();
@@ -890,6 +892,7 @@ mod test {
890892

891893
#[test]
892894
fn oneshot_multi_thread_send_close_stress() {
895+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
893896
do stress_factor().times {
894897
do run_in_newsched_task {
895898
let (port, chan) = oneshot::<int>();
@@ -910,6 +913,7 @@ mod test {
910913

911914
#[test]
912915
fn oneshot_multi_thread_recv_close_stress() {
916+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
913917
do stress_factor().times {
914918
do run_in_newsched_task {
915919
let (port, chan) = oneshot::<int>();
@@ -936,6 +940,7 @@ mod test {
936940

937941
#[test]
938942
fn oneshot_multi_thread_send_recv_stress() {
943+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
939944
do stress_factor().times {
940945
do run_in_newsched_task {
941946
let (port, chan) = oneshot::<~int>();
@@ -955,6 +960,7 @@ mod test {
955960

956961
#[test]
957962
fn stream_send_recv_stress() {
963+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
958964
do stress_factor().times {
959965
do run_in_mt_newsched_task {
960966
let (port, chan) = stream::<~int>();
@@ -999,6 +1005,7 @@ mod test {
9991005

10001006
#[test]
10011007
fn shared_chan_stress() {
1008+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
10021009
do run_in_mt_newsched_task {
10031010
let (port, chan) = stream();
10041011
let chan = SharedChan::new(chan);
@@ -1018,6 +1025,7 @@ mod test {
10181025

10191026
#[test]
10201027
fn shared_port_stress() {
1028+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
10211029
do run_in_mt_newsched_task {
10221030
// XXX: Removing these type annotations causes an ICE
10231031
let (end_port, end_chan) = stream::<()>();
@@ -1098,6 +1106,8 @@ mod test {
10981106
use rand;
10991107
use rand::RngUtil;
11001108

1109+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
1110+
11011111
do run_in_mt_newsched_task {
11021112
let (end_port, end_chan) = stream::<()>();
11031113
let end_chan = SharedChan::new(end_chan);

src/libstd/rt/sched.rs

+2
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ mod test {
819819
use cell::Cell;
820820
use rt::thread::Thread;
821821
use rt::task::{Task, Sched};
822+
use rt::util;
822823
use option::{Some};
823824

824825
#[test]
@@ -1040,6 +1041,7 @@ mod test {
10401041

10411042
#[test]
10421043
fn test_stress_schedule_task_states() {
1044+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
10431045
let n = stress_factor() * 120;
10441046
for _ in range(0, n as int) {
10451047
test_schedule_home_states();

src/libstd/rt/test.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use iterator::{Iterator, range};
1818
use super::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr};
1919
use vec::{OwnedVector, MutableVector, ImmutableVector};
2020
use rt::sched::Scheduler;
21-
use unstable::run_in_bare_thread;
21+
use unstable::{run_in_bare_thread};
2222
use rt::thread::Thread;
2323
use rt::task::Task;
2424
use rt::uv::uvio::UvEventLoop;
@@ -162,10 +162,14 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
162162
let nthreads = match os::getenv("RUST_RT_TEST_THREADS") {
163163
Some(nstr) => FromStr::from_str(nstr).unwrap(),
164164
None => {
165-
// Using more threads than cores in test code
166-
// to force the OS to preempt them frequently.
167-
// Assuming that this help stress test concurrent types.
168-
util::num_cpus() * 2
165+
if util::limit_thread_creation_due_to_osx_and_valgrind() {
166+
1
167+
} else {
168+
// Using more threads than cores in test code
169+
// to force the OS to preempt them frequently.
170+
// Assuming that this help stress test concurrent types.
171+
util::num_cpus() * 2
172+
}
169173
}
170174
};
171175

src/libstd/rt/util.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ use option::{Some, None};
1515
use os;
1616
use str::StrSlice;
1717

18+
#[cfg(target_os="macos")]
19+
use unstable::running_on_valgrind;
20+
1821
/// Get the number of cores available
1922
pub fn num_cpus() -> uint {
2023
#[fixed_stack_segment]; #[inline(never)];
@@ -28,12 +31,35 @@ pub fn num_cpus() -> uint {
2831
}
2932
}
3033

34+
/// Valgrind has a fixed-sized array (size around 2000) of segment descriptors wired into it; this
35+
/// is a hard limit and requires rebuilding valgrind if you want to go beyond it. Normally this is
36+
/// not a problem, but in some tests, we produce a lot of threads casually. Making lots of threads
37+
/// alone might not be a problem _either_, except on OSX, the segments produced for new threads
38+
/// _take a while_ to get reclaimed by the OS. Combined with the fact that libuv schedulers fork off
39+
/// a separate thread for polling fsevents on OSX, we get a perfect storm of creating "too many
40+
/// mappings" for valgrind to handle when running certain stress tests in the runtime.
41+
#[cfg(target_os="macos")]
42+
pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool {
43+
running_on_valgrind()
44+
}
45+
46+
#[cfg(not(target_os="macos"))]
47+
pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool {
48+
false
49+
}
50+
3151
/// Get's the number of scheduler threads requested by the environment
3252
/// either `RUST_THREADS` or `num_cpus`.
3353
pub fn default_sched_threads() -> uint {
3454
match os::getenv("RUST_THREADS") {
3555
Some(nstr) => FromStr::from_str(nstr).unwrap(),
36-
None => num_cpus()
56+
None => {
57+
if limit_thread_creation_due_to_osx_and_valgrind() {
58+
1
59+
} else {
60+
num_cpus()
61+
}
62+
}
3763
}
3864
}
3965

src/libstd/run.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,7 @@ mod tests {
955955
use path::Path;
956956
use run;
957957
use str;
958+
use unstable::running_on_valgrind;
958959

959960
#[test]
960961
#[cfg(windows)]
@@ -1365,13 +1366,4 @@ mod tests {
13651366
13661367
assert!(output.contains("RUN_TEST_NEW_ENV=123"));
13671368
}
1368-
1369-
fn running_on_valgrind() -> bool {
1370-
#[fixed_stack_segment]; #[inline(never)];
1371-
unsafe { rust_running_on_valgrind() != 0 }
1372-
}
1373-
1374-
extern {
1375-
fn rust_running_on_valgrind() -> uintptr_t;
1376-
}
13771369
}

src/libstd/unstable/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use comm::{GenericChan, GenericPort};
1414
use comm;
1515
use prelude::*;
1616
use task;
17+
use libc::uintptr_t;
1718

1819
pub mod dynamic_lib;
1920

@@ -118,3 +119,17 @@ pub fn change_dir_locked(p: &Path, action: &fn()) -> bool {
118119
fn rust_drop_change_dir_lock();
119120
}
120121
}
122+
123+
124+
/// Dynamically inquire about whether we're running under V.
125+
/// You should usually not use this unless your test definitely
126+
/// can't run correctly un-altered. Valgrind is there to help
127+
/// you notice weirdness in normal, un-doctored code paths!
128+
pub fn running_on_valgrind() -> bool {
129+
#[fixed_stack_segment]; #[inline(never)];
130+
unsafe { rust_running_on_valgrind() != 0 }
131+
}
132+
133+
extern {
134+
fn rust_running_on_valgrind() -> uintptr_t;
135+
}

src/test/auxiliary/xc_conditions.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2012 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+
11+
#[crate_type="lib"];
12+
13+
condition! {
14+
pub oops: int -> int;
15+
}
16+
17+
pub fn trouble() -> int {
18+
oops::cond.raise(1)
19+
}

src/test/auxiliary/xc_conditions_2.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2012 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+
11+
#[crate_type="lib"];
12+
13+
condition! {
14+
pub oops: int -> int;
15+
}

src/test/auxiliary/xc_conditions_3.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2012 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+
11+
#[crate_type="lib"];
12+
13+
condition! {
14+
pub oops: int -> int;
15+
}
16+
17+
pub fn guard(k: extern fn() -> int, x: int) -> int {
18+
do oops::cond.trap(|i| i*x).inside {
19+
k()
20+
}
21+
}

src/test/auxiliary/xc_conditions_4.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2012 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+
11+
#[crate_type="lib"];
12+
13+
#[deriving(Eq)]
14+
pub enum Color {
15+
Red, Green, Blue
16+
}
17+
18+
condition! {
19+
pub oops: (int,float,~str) -> ::Color;
20+
}
21+
22+
pub trait Thunk<T> {
23+
fn call(self) -> T;
24+
}
25+
26+
pub fn callback<T,TH:Thunk<T>>(t:TH) -> T {
27+
t.call()
28+
}
29+

src/test/run-pass/foreign-struct.rs

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

11-
// xfail-win32
1211
// Passing enums by value
1312

1413
pub enum void { }

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

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2013 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+
11+
fn make_adder(x: int) -> @fn(int) -> int { |y| x + y }
12+
pub fn main() { }
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2012 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+
11+
// xfail-fast
12+
// aux-build:xc_conditions.rs
13+
14+
extern mod xc_conditions;
15+
use xc_conditions::oops;
16+
use xc_conditions::trouble;
17+
18+
// Tests of cross-crate conditions; the condition is
19+
// defined in lib, and we test various combinations
20+
// of `trap` and `raise` in the client or the lib where
21+
// the condition was defined. Also in test #4 we use
22+
// more complex features (generics, traits) in
23+
// combination with the condition.
24+
//
25+
// trap raise
26+
// ------------
27+
// xc_conditions : client lib
28+
// xc_conditions_2: client client
29+
// xc_conditions_3: lib client
30+
// xc_conditions_4: client client (with traits)
31+
//
32+
// the trap=lib, raise=lib case isn't tested since
33+
// there's no cross-crate-ness to test in that case.
34+
35+
pub fn main() {
36+
do oops::cond.trap(|_i| 12345).inside {
37+
let x = trouble();
38+
assert_eq!(x,12345);
39+
}
40+
}

0 commit comments

Comments
 (0)