Skip to content

Commit 19f4ae1

Browse files
committed
Try to fix mac valgrind bot by disabling thread-heavy activities.
1 parent 29a449a commit 19f4ae1

File tree

6 files changed

+64
-15
lines changed

6 files changed

+64
-15
lines changed

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

0 commit comments

Comments
 (0)