Skip to content

Commit d6fdbd7

Browse files
Rollup merge of rust-lang#59136 - jethrogb:jb/sgx-std-test, r=sanxiyn
SGX target: fix std unit tests This fixes some tests and some code in the SGX sys implementation to make the `std` unit test suite pass. rust-lang#59009 must be merged first.
2 parents 0f118f6 + 32bcff1 commit d6fdbd7

27 files changed

+236
-94
lines changed

src/libstd/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@ wasm-bindgen-threads = []
7272
# https://github.com/rust-lang-nursery/stdsimd/blob/master/crates/std_detect/Cargo.toml
7373
std_detect_file_io = []
7474
std_detect_dlsym_getauxval = []
75+
76+
[package.metadata.fortanix-sgx]
77+
# Maximum possible number of threads when testing
78+
threads = 125

src/libstd/env.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ mod tests {
975975
use crate::path::Path;
976976

977977
#[test]
978-
#[cfg_attr(target_os = "emscripten", ignore)]
978+
#[cfg_attr(any(target_os = "emscripten", target_env = "sgx"), ignore)]
979979
fn test_self_exe_path() {
980980
let path = current_exe();
981981
assert!(path.is_ok());
@@ -989,6 +989,7 @@ mod tests {
989989
fn test() {
990990
assert!((!Path::new("test-path").is_absolute()));
991991

992+
#[cfg(not(target_env = "sgx"))]
992993
current_dir().unwrap();
993994
}
994995

src/libstd/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ impl AsInnerMut<fs_imp::DirBuilder> for DirBuilder {
20952095
}
20962096
}
20972097

2098-
#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
2098+
#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten", target_env = "sgx"))))]
20992099
mod tests {
21002100
use crate::io::prelude::*;
21012101

src/libstd/net/addr.rs

+6
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,10 @@ mod tests {
941941
assert_eq!(Ok(vec![a]), tsa(("2a02:6b8:0:1::1", 53)));
942942

943943
let a = sa4(Ipv4Addr::new(127, 0, 0, 1), 23924);
944+
#[cfg(not(target_env = "sgx"))]
944945
assert!(tsa(("localhost", 23924)).unwrap().contains(&a));
946+
#[cfg(target_env = "sgx")]
947+
let _ = a;
945948
}
946949

947950
#[test]
@@ -953,7 +956,10 @@ mod tests {
953956
assert_eq!(Ok(vec![a]), tsa("[2a02:6b8:0:1::1]:53"));
954957

955958
let a = sa4(Ipv4Addr::new(127, 0, 0, 1), 23924);
959+
#[cfg(not(target_env = "sgx"))]
956960
assert!(tsa("localhost:23924").unwrap().contains(&a));
961+
#[cfg(target_env = "sgx")]
962+
let _ = a;
957963
}
958964

959965
#[test]

src/libstd/net/tcp.rs

+47-15
Original file line numberDiff line numberDiff line change
@@ -929,12 +929,12 @@ impl fmt::Debug for TcpListener {
929929

930930
#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
931931
mod tests {
932+
use crate::fmt;
932933
use crate::io::{ErrorKind, IoVec, IoVecMut};
933934
use crate::io::prelude::*;
934935
use crate::net::*;
935936
use crate::net::test::{next_test_ip4, next_test_ip6};
936937
use crate::sync::mpsc::channel;
937-
use crate::sys_common::AsInner;
938938
use crate::time::{Instant, Duration};
939939
use crate::thread;
940940

@@ -1129,7 +1129,7 @@ mod tests {
11291129
connect(i + 1, addr);
11301130
t!(stream.write(&[i as u8]));
11311131
});
1132-
t.join().ok().unwrap();
1132+
t.join().ok().expect("thread panicked");
11331133
}
11341134
}
11351135

@@ -1162,7 +1162,7 @@ mod tests {
11621162
connect(i + 1, addr);
11631163
t!(stream.write(&[99]));
11641164
});
1165-
t.join().ok().unwrap();
1165+
t.join().ok().expect("thread panicked");
11661166
}
11671167
}
11681168

@@ -1377,6 +1377,8 @@ mod tests {
13771377
}
13781378

13791379
#[test]
1380+
// FIXME: https://github.com/fortanix/rust-sgx/issues/110
1381+
#[cfg_attr(target_env = "sgx", ignore)]
13801382
fn shutdown_smoke() {
13811383
each_ip(&mut |addr| {
13821384
let a = t!(TcpListener::bind(&addr));
@@ -1397,6 +1399,8 @@ mod tests {
13971399
}
13981400

13991401
#[test]
1402+
// FIXME: https://github.com/fortanix/rust-sgx/issues/110
1403+
#[cfg_attr(target_env = "sgx", ignore)]
14001404
fn close_readwrite_smoke() {
14011405
each_ip(&mut |addr| {
14021406
let a = t!(TcpListener::bind(&addr));
@@ -1550,30 +1554,51 @@ mod tests {
15501554

15511555
#[test]
15521556
fn debug() {
1553-
let name = if cfg!(windows) {"socket"} else {"fd"};
1557+
#[cfg(not(target_env = "sgx"))]
1558+
fn render_socket_addr<'a>(addr: &'a SocketAddr) -> impl fmt::Debug + 'a {
1559+
addr
1560+
}
1561+
#[cfg(target_env = "sgx")]
1562+
fn render_socket_addr<'a>(addr: &'a SocketAddr) -> impl fmt::Debug + 'a {
1563+
addr.to_string()
1564+
}
1565+
1566+
#[cfg(unix)]
1567+
use crate::os::unix::io::AsRawFd;
1568+
#[cfg(target_env = "sgx")]
1569+
use crate::os::fortanix_sgx::io::AsRawFd;
1570+
#[cfg(not(windows))]
1571+
fn render_inner(addr: &dyn AsRawFd) -> impl fmt::Debug {
1572+
addr.as_raw_fd()
1573+
}
1574+
#[cfg(windows)]
1575+
fn render_inner(addr: &dyn os::windows::io::AsRawSocket) -> impl fmt::Debug {
1576+
addr.as_raw_socket()
1577+
}
1578+
1579+
let inner_name = if cfg!(windows) {"socket"} else {"fd"};
15541580
let socket_addr = next_test_ip4();
15551581

15561582
let listener = t!(TcpListener::bind(&socket_addr));
1557-
let listener_inner = listener.0.socket().as_inner();
15581583
let compare = format!("TcpListener {{ addr: {:?}, {}: {:?} }}",
1559-
socket_addr, name, listener_inner);
1584+
render_socket_addr(&socket_addr),
1585+
inner_name,
1586+
render_inner(&listener));
15601587
assert_eq!(format!("{:?}", listener), compare);
15611588

1562-
let stream = t!(TcpStream::connect(&("localhost",
1563-
socket_addr.port())));
1564-
let stream_inner = stream.0.socket().as_inner();
1565-
let compare = format!("TcpStream {{ addr: {:?}, \
1566-
peer: {:?}, {}: {:?} }}",
1567-
stream.local_addr().unwrap(),
1568-
stream.peer_addr().unwrap(),
1569-
name,
1570-
stream_inner);
1589+
let stream = t!(TcpStream::connect(&("localhost", socket_addr.port())));
1590+
let compare = format!("TcpStream {{ addr: {:?}, peer: {:?}, {}: {:?} }}",
1591+
render_socket_addr(&stream.local_addr().unwrap()),
1592+
render_socket_addr(&stream.peer_addr().unwrap()),
1593+
inner_name,
1594+
render_inner(&stream));
15711595
assert_eq!(format!("{:?}", stream), compare);
15721596
}
15731597

15741598
// FIXME: re-enabled bitrig/openbsd tests once their socket timeout code
15751599
// no longer has rounding errors.
15761600
#[cfg_attr(any(target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"), ignore)]
1601+
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
15771602
#[test]
15781603
fn timeouts() {
15791604
let addr = next_test_ip4();
@@ -1601,6 +1626,7 @@ mod tests {
16011626
}
16021627

16031628
#[test]
1629+
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
16041630
fn test_read_timeout() {
16051631
let addr = next_test_ip4();
16061632
let listener = t!(TcpListener::bind(&addr));
@@ -1618,6 +1644,7 @@ mod tests {
16181644
}
16191645

16201646
#[test]
1647+
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
16211648
fn test_read_with_timeout() {
16221649
let addr = next_test_ip4();
16231650
let listener = t!(TcpListener::bind(&addr));
@@ -1661,6 +1688,7 @@ mod tests {
16611688
}
16621689

16631690
#[test]
1691+
#[cfg_attr(target_env = "sgx", ignore)]
16641692
fn nodelay() {
16651693
let addr = next_test_ip4();
16661694
let _listener = t!(TcpListener::bind(&addr));
@@ -1675,6 +1703,7 @@ mod tests {
16751703
}
16761704

16771705
#[test]
1706+
#[cfg_attr(target_env = "sgx", ignore)]
16781707
fn ttl() {
16791708
let ttl = 100;
16801709

@@ -1691,6 +1720,7 @@ mod tests {
16911720
}
16921721

16931722
#[test]
1723+
#[cfg_attr(target_env = "sgx", ignore)]
16941724
fn set_nonblocking() {
16951725
let addr = next_test_ip4();
16961726
let listener = t!(TcpListener::bind(&addr));
@@ -1712,6 +1742,7 @@ mod tests {
17121742
}
17131743

17141744
#[test]
1745+
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
17151746
fn peek() {
17161747
each_ip(&mut |addr| {
17171748
let (txdone, rxdone) = channel();
@@ -1743,6 +1774,7 @@ mod tests {
17431774
}
17441775

17451776
#[test]
1777+
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
17461778
fn connect_timeout_valid() {
17471779
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
17481780
let addr = listener.local_addr().unwrap();

src/libstd/net/test.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ pub fn tsa<A: ToSocketAddrs>(a: A) -> Result<Vec<SocketAddr>, String> {
3636
// all want to use ports. This function figures out which workspace
3737
// it is running in and assigns a port range based on it.
3838
fn base_port() -> u16 {
39-
let cwd = env::current_dir().unwrap();
39+
let cwd = if cfg!(target_env = "sgx") {
40+
String::from("sgx")
41+
} else {
42+
env::current_dir().unwrap().into_os_string().into_string().unwrap()
43+
};
4044
let dirs = ["32-opt", "32-nopt",
4145
"musl-64-opt", "cross-opt",
4246
"64-opt", "64-nopt", "64-opt-vg", "64-debug-opt",
43-
"all-opt", "snap3", "dist"];
47+
"all-opt", "snap3", "dist", "sgx"];
4448
dirs.iter().enumerate().find(|&(_, dir)| {
45-
cwd.to_str().unwrap().contains(dir)
49+
cwd.contains(dir)
4650
}).map(|p| p.0).unwrap_or(0) as u16 * 1000 + 19600
4751
}

src/libstd/net/udp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ impl fmt::Debug for UdpSocket {
837837
}
838838
}
839839

840-
#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
840+
#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten", target_env = "sgx"))))]
841841
mod tests {
842842
use crate::io::ErrorKind;
843843
use crate::net::*;

src/libstd/path.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3801,7 +3801,7 @@ mod tests {
38013801
});
38023802
);
38033803

3804-
if cfg!(unix) {
3804+
if cfg!(unix) || cfg!(all(target_env = "sgx", target_vendor = "fortanix")) {
38053805
tp!("", "foo", "foo");
38063806
tp!("foo", "bar", "foo/bar");
38073807
tp!("foo/", "bar", "foo/bar");
@@ -3960,7 +3960,7 @@ mod tests {
39603960
tfn!("foo", "bar", "bar");
39613961
tfn!("foo", "", "");
39623962
tfn!("", "foo", "foo");
3963-
if cfg!(unix) {
3963+
if cfg!(unix) || cfg!(all(target_env = "sgx", target_vendor = "fortanix")) {
39643964
tfn!(".", "foo", "./foo");
39653965
tfn!("foo/", "bar", "bar");
39663966
tfn!("foo/.", "bar", "bar");

src/libstd/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ impl Termination for ExitCode {
16211621
}
16221622
}
16231623

1624-
#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
1624+
#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten", target_env = "sgx"))))]
16251625
mod tests {
16261626
use crate::io::prelude::*;
16271627

src/libstd/sync/condvar.rs

+4
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ mod tests {
705705

706706
#[test]
707707
#[cfg_attr(target_os = "emscripten", ignore)]
708+
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
708709
fn wait_timeout_wait() {
709710
let m = Arc::new(Mutex::new(()));
710711
let c = Arc::new(Condvar::new());
@@ -724,6 +725,7 @@ mod tests {
724725

725726
#[test]
726727
#[cfg_attr(target_os = "emscripten", ignore)]
728+
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
727729
fn wait_timeout_until_wait() {
728730
let m = Arc::new(Mutex::new(()));
729731
let c = Arc::new(Condvar::new());
@@ -748,6 +750,7 @@ mod tests {
748750

749751
#[test]
750752
#[cfg_attr(target_os = "emscripten", ignore)]
753+
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
751754
fn wait_timeout_until_wake() {
752755
let pair = Arc::new((Mutex::new(false), Condvar::new()));
753756
let pair_copy = pair.clone();
@@ -771,6 +774,7 @@ mod tests {
771774

772775
#[test]
773776
#[cfg_attr(target_os = "emscripten", ignore)]
777+
#[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
774778
fn wait_timeout_wake() {
775779
let m = Arc::new(Mutex::new(()));
776780
let c = Arc::new(Condvar::new());

0 commit comments

Comments
 (0)