diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-12-12 17:20:58 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-12-24 14:42:00 -0800 |
| commit | dafb310ba131b34a8819566201dc8d0af9bbd406 (patch) | |
| tree | 865428479b868978c74cfc040a600b37cdf89a7b /src/libstd/io/test.rs | |
| parent | 1815aea36818cd86ebae607522318f56e35c01a2 (diff) | |
| download | rust-dafb310ba131b34a8819566201dc8d0af9bbd406.tar.gz rust-dafb310ba131b34a8819566201dc8d0af9bbd406.zip | |
std: Delete rt::test
This module contains many M:N specific concepts. This will no longer be available with libgreen, and most functions aren't really that necessary today anyway. New testing primitives will be introduced as they become available for 1:1 and M:N. A new io::test module is introduced with the new ip4/ip6 address helpers to continue usage in io tests.
Diffstat (limited to 'src/libstd/io/test.rs')
| -rw-r--r-- | src/libstd/io/test.rs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/libstd/io/test.rs b/src/libstd/io/test.rs new file mode 100644 index 00000000000..212e4ebffa8 --- /dev/null +++ b/src/libstd/io/test.rs @@ -0,0 +1,79 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +/// Get a port number, starting at 9600, for use in tests +pub fn next_test_port() -> u16 { + use unstable::atomics::{AtomicUint, INIT_ATOMIC_UINT, Relaxed}; + static mut next_offset: AtomicUint = INIT_ATOMIC_UINT; + unsafe { + base_port() + next_offset.fetch_add(1, Relaxed) as u16 + } +} + +/// Get a temporary path which could be the location of a unix socket +pub fn next_test_unix() -> Path { + if cfg!(unix) { + os::tmpdir().join(rand::task_rng().gen_ascii_str(20)) + } else { + Path::new(r"\\.\pipe\" + rand::task_rng().gen_ascii_str(20)) + } +} + +/// Get a unique IPv4 localhost:port pair starting at 9600 +pub fn next_test_ip4() -> SocketAddr { + SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: next_test_port() } +} + +/// Get a unique IPv6 localhost:port pair starting at 9600 +pub fn next_test_ip6() -> SocketAddr { + SocketAddr { ip: Ipv6Addr(0, 0, 0, 0, 0, 0, 0, 1), port: 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() -> u16 { + use os; + use str::StrSlice; + use vec::ImmutableVector; + + let base = 9600u16; + let range = 1000u16; + + 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) + ]; + + // FIXME (#9639): This needs to handle non-utf8 paths + let path = os::getcwd(); + let path_s = path.as_str().unwrap(); + + let mut final_base = base; + + for &(dir, base) in bases.iter() { + if path_s.contains(dir) { + final_base = base; + break; + } + } + + return final_base; +} |
