// except according to those terms.
use cell::Cell;
+use libc;
use uint;
use option::{Some, None};
use rt::sched::Scheduler;
/// Get a port number, starting at 9600, for use in tests
pub fn next_test_port() -> u16 {
unsafe {
- return rust_dbg_next_port() as u16;
+ return rust_dbg_next_port(base_port() as libc::uintptr_t) as u16;
}
extern {
- fn rust_dbg_next_port() -> ::libc::uintptr_t;
+ fn rust_dbg_next_port(base: libc::uintptr_t) -> libc::uintptr_t;
}
}
Ipv4(127, 0, 0, 1, next_test_port())
}
+/*
+XXX: Welcome to MegaHack City.
+
+The bots run multiple builds at the same time, and these builds
+all want to use ports. This function figures out which workspace
+it is running in and assigns a port range based on it.
+*/
+fn base_port() -> uint {
+ use os;
+ use str::StrSlice;
+ use to_str::ToStr;
+ use vec::ImmutableVector;
+
+ let base = 9600u;
+ let range = 1000;
+
+ let bases = [
+ ("32-opt", base + range * 1),
+ ("32-noopt", base + range * 2),
+ ("64-opt", base + range * 3),
+ ("64-noopt", base + range * 4),
+ ("64-opt-vg", base + range * 5),
+ ("all-opt", base + range * 6),
+ ("snap3", base + range * 7),
+ ("dist", base + range * 8)
+ ];
+
+ let path = os::getcwd().to_str();
+
+ let mut final_base = base;
+
+ for bases.iter().advance |&(dir, base)| {
+ if path.contains(dir) {
+ final_base = base;
+ break;
+ }
+ }
+
+ return final_base;
+}
+
/// Get a constant that represents the number of times to repeat
/// stress tests. Default 1.
pub fn stress_factor() -> uint {
// Generates increasing port numbers for network testing
extern "C" CDECL uintptr_t
-rust_dbg_next_port() {
+rust_dbg_next_port(uintptr_t base_port) {
static lock_and_signal dbg_port_lock;
- static uintptr_t next_port = 9600;
+ static uintptr_t next_offset = 0;
scoped_lock with(dbg_port_lock);
- uintptr_t this_port = next_port;
- next_port += 1;
+ uintptr_t this_port = base_port + next_offset;
+ next_offset += 1;
return this_port;
}