Skip to content

Commit 98dc7b1

Browse files
committed
Try to fix mac valgrind bot by disabling thread-heavy activities.
1 parent 9db698a commit 98dc7b1

File tree

6 files changed

+61
-14
lines changed

6 files changed

+61
-14
lines changed

src/libstd/rt/comm.rs

+10
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ mod test {
692692
use rt::test::*;
693693
use cell::Cell;
694694
use iter::Times;
695+
use rt::util;
695696

696697
#[test]
697698
fn oneshot_single_thread_close_port_first() {
@@ -840,6 +841,7 @@ mod test {
840841

841842
#[test]
842843
fn oneshot_multi_thread_close_stress() {
844+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
843845
do stress_factor().times {
844846
do run_in_newsched_task {
845847
let (port, chan) = oneshot::<int>();
@@ -855,6 +857,7 @@ mod test {
855857

856858
#[test]
857859
fn oneshot_multi_thread_send_close_stress() {
860+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
858861
do stress_factor().times {
859862
do run_in_newsched_task {
860863
let (port, chan) = oneshot::<int>();
@@ -875,6 +878,7 @@ mod test {
875878

876879
#[test]
877880
fn oneshot_multi_thread_recv_close_stress() {
881+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
878882
do stress_factor().times {
879883
do run_in_newsched_task {
880884
let (port, chan) = oneshot::<int>();
@@ -901,6 +905,7 @@ mod test {
901905

902906
#[test]
903907
fn oneshot_multi_thread_send_recv_stress() {
908+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
904909
do stress_factor().times {
905910
do run_in_newsched_task {
906911
let (port, chan) = oneshot::<~int>();
@@ -920,6 +925,7 @@ mod test {
920925

921926
#[test]
922927
fn stream_send_recv_stress() {
928+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
923929
do stress_factor().times {
924930
do run_in_mt_newsched_task {
925931
let (port, chan) = stream::<~int>();
@@ -964,6 +970,7 @@ mod test {
964970

965971
#[test]
966972
fn shared_chan_stress() {
973+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
967974
do run_in_mt_newsched_task {
968975
let (port, chan) = stream();
969976
let chan = SharedChan::new(chan);
@@ -983,6 +990,7 @@ mod test {
983990

984991
#[test]
985992
fn shared_port_stress() {
993+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
986994
do run_in_mt_newsched_task {
987995
// XXX: Removing these type annotations causes an ICE
988996
let (end_port, end_chan) = stream::<()>();
@@ -1063,6 +1071,8 @@ mod test {
10631071
use rand;
10641072
use rand::RngUtil;
10651073

1074+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
1075+
10661076
do run_in_mt_newsched_task {
10671077
let (end_port, end_chan) = stream::<()>();
10681078
let end_chan = SharedChan::new(end_chan);

src/libstd/rt/sched.rs

+2
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ mod test {
754754
use cell::Cell;
755755
use rt::thread::Thread;
756756
use rt::task::{Task, Sched};
757+
use rt::util;
757758
use option::{Some};
758759

759760
#[test]
@@ -971,6 +972,7 @@ mod test {
971972

972973
#[test]
973974
fn test_stress_schedule_task_states() {
975+
if util::limit_thread_creation_due_to_osx_and_valgrind() { return; }
974976
let n = stress_factor() * 120;
975977
for _ in range(0, n as int) {
976978
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 vec::{OwnedVector, MutableVector};
1919
use super::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr};
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;
@@ -156,10 +156,14 @@ pub fn run_in_mt_newsched_task(f: ~fn()) {
156156
let nthreads = match os::getenv("RUST_RT_TEST_THREADS") {
157157
Some(nstr) => FromStr::from_str(nstr).unwrap(),
158158
None => {
159-
// Using more threads than cores in test code
160-
// to force the OS to preempt them frequently.
161-
// Assuming that this help stress test concurrent types.
162-
util::num_cpus() * 2
159+
if util::limit_thread_creation_due_to_osx_and_valgrind() {
160+
1
161+
} else {
162+
// Using more threads than cores in test code
163+
// to force the OS to preempt them frequently.
164+
// Assuming that this help stress test concurrent types.
165+
util::num_cpus() * 2
166+
}
163167
}
164168
};
165169

src/libstd/rt/util.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use libc;
1515
use option::{Some, None};
1616
use os;
1717
use str::StrSlice;
18+
use unstable::running_on_valgrind;
1819

1920
/// Get the number of cores available
2021
pub fn num_cpus() -> uint {
@@ -27,12 +28,35 @@ pub fn num_cpus() -> uint {
2728
}
2829
}
2930

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

src/libstd/run.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ mod tests {
923923
use path::Path;
924924
use run;
925925
use str;
926+
use unstable::running_on_valgrind;
926927

927928
#[test]
928929
#[cfg(windows)]
@@ -1331,12 +1332,4 @@ mod tests {
13311332
13321333
assert!(output.contains("RUN_TEST_NEW_ENV=123"));
13331334
}
1334-
1335-
fn running_on_valgrind() -> bool {
1336-
unsafe { rust_running_on_valgrind() != 0 }
1337-
}
1338-
1339-
extern {
1340-
fn rust_running_on_valgrind() -> uintptr_t;
1341-
}
13421335
}

src/libstd/unstable/mod.rs

+14
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

@@ -116,3 +117,16 @@ pub fn change_dir_locked(p: &Path, action: &fn()) -> bool {
116117
fn rust_drop_change_dir_lock();
117118
}
118119
}
120+
121+
122+
/// Dynamically inquire about whether we're running under V.
123+
/// You should usually not use this unless your test definitely
124+
/// can't run correctly un-altered. Valgrind is there to help
125+
/// you notice weirdness in normal, un-doctored code paths!
126+
pub fn running_on_valgrind() -> bool {
127+
unsafe { rust_running_on_valgrind() != 0 }
128+
}
129+
130+
extern {
131+
fn rust_running_on_valgrind() -> uintptr_t;
132+
}

0 commit comments

Comments
 (0)