diff options
Diffstat (limited to 'library/std/src/sys/unix/ext/ucred/tests.rs')
| -rw-r--r-- | library/std/src/sys/unix/ext/ucred/tests.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/library/std/src/sys/unix/ext/ucred/tests.rs b/library/std/src/sys/unix/ext/ucred/tests.rs index 451b534b266..b3e45d3337c 100644 --- a/library/std/src/sys/unix/ext/ucred/tests.rs +++ b/library/std/src/sys/unix/ext/ucred/tests.rs @@ -1,5 +1,5 @@ use crate::os::unix::net::UnixStream; -use libc::{getegid, geteuid}; +use libc::{getegid, geteuid, getpid}; #[test] #[cfg(any( @@ -23,3 +23,20 @@ fn test_socket_pair() { assert_eq!(cred_a.uid, uid); assert_eq!(cred_a.gid, gid); } + +#[test] +#[cfg(any( + target_os = "linux", + target_os = "ios", + target_os = "macos", +))] +fn test_socket_pair_pids(arg: Type) -> RetType { + // Create two connected sockets and get their peer credentials. + let (sock_a, sock_b) = UnixStream::pair().unwrap(); + let (cred_a, cred_b) = (sock_a.peer_cred().unwrap(), sock_b.peer_cred().unwrap()); + + // On supported platforms (see the cfg above), the credentials should always include the PID. + let pid = unsafe { getpid() }; + assert_eq!(cred_a.pid, Some(pid)); + assert_eq!(cred_b.pid, Some(pid)); +} |
