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.
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.
17 use std::io::net::ip::*;
18 use sync::atomics::{AtomicUint, INIT_ATOMIC_UINT, Relaxed};
21 { fn $name:ident() $b:block } => (
23 #[allow(unused_imports)];
40 #[test] fn green() { f() }
43 let (p, c) = Chan::new();
44 do native::task::spawn { c.send(f()) }
51 /// Get a port number, starting at 9600, for use in tests
52 pub fn next_test_port() -> u16 {
53 static mut next_offset: AtomicUint = INIT_ATOMIC_UINT;
55 base_port() + next_offset.fetch_add(1, Relaxed) as u16
59 /// Get a temporary path which could be the location of a unix socket
60 pub fn next_test_unix() -> Path {
62 os::tmpdir().join(rand::task_rng().gen_ascii_str(20))
64 Path::new(r"\\.\pipe\" + rand::task_rng().gen_ascii_str(20))
68 /// Get a unique IPv4 localhost:port pair starting at 9600
69 pub fn next_test_ip4() -> SocketAddr {
70 SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: next_test_port() }
73 /// Get a unique IPv6 localhost:port pair starting at 9600
74 pub fn next_test_ip6() -> SocketAddr {
75 SocketAddr { ip: Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 1), port: next_test_port() }
79 XXX: Welcome to MegaHack City.
81 The bots run multiple builds at the same time, and these builds
82 all want to use ports. This function figures out which workspace
83 it is running in and assigns a port range based on it.
85 fn base_port() -> u16 {
91 ("32-opt", base + range * 1),
92 ("32-noopt", base + range * 2),
93 ("64-opt", base + range * 3),
94 ("64-noopt", base + range * 4),
95 ("64-opt-vg", base + range * 5),
96 ("all-opt", base + range * 6),
97 ("snap3", base + range * 7),
98 ("dist", base + range * 8)
101 // FIXME (#9639): This needs to handle non-utf8 paths
102 let path = os::getcwd();
103 let path_s = path.as_str().unwrap();
105 let mut final_base = base;
107 for &(dir, base) in bases.iter() {
108 if path_s.contains(dir) {