]> git.lizzy.rs Git - rust.git/commitdiff
std::rt: Add a hack to allocate different test port ranges to different bots
authorBrian Anderson <banderson@mozilla.com>
Mon, 8 Jul 2013 21:41:07 +0000 (14:41 -0700)
committerBrian Anderson <banderson@mozilla.com>
Mon, 8 Jul 2013 21:41:07 +0000 (14:41 -0700)
src/libstd/rt/test.rs
src/rt/rust_test_helpers.cpp

index 659c7eb49857374bf9d6a5e08b491397ba678abc..89687cf3fd2f780b9bc8ee1e208d996a2f310f1a 100644 (file)
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 use cell::Cell;
+use libc;
 use uint;
 use option::{Some, None};
 use rt::sched::Scheduler;
@@ -316,10 +317,10 @@ pub fn spawntask_thread(f: ~fn()) -> Thread {
 /// 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;
     }
 }
 
@@ -328,6 +329,47 @@ pub fn next_test_ip4() -> IpAddr {
     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 {
index d82c39d6838ec7f866757d96e24a2034697a34f4..2cfd5cf1eb63c0653165323ef675fb1f0dd1c27f 100644 (file)
@@ -168,11 +168,11 @@ rust_dbg_extern_identity_TwoDoubles(TwoDoubles u) {
 
 // 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;
 }