]> git.proxmox.com Git - rustc.git/blob - library/std/src/sys/unix/ext/ucred/tests.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / library / std / src / sys / unix / ext / ucred / tests.rs
1 use crate::os::unix::net::UnixStream;
2 use libc::{getegid, geteuid};
3
4 #[test]
5 #[cfg(any(
6 target_os = "android",
7 target_os = "linux",
8 target_os = "dragonfly",
9 target_os = "freebsd",
10 target_os = "ios",
11 target_os = "macos",
12 target_os = "openbsd"
13 ))]
14 fn test_socket_pair() {
15 // Create two connected sockets and get their peer credentials. They should be equal.
16 let (sock_a, sock_b) = UnixStream::pair().unwrap();
17 let (cred_a, cred_b) = (sock_a.peer_cred().unwrap(), sock_b.peer_cred().unwrap());
18 assert_eq!(cred_a, cred_b);
19
20 // Check that the UID and GIDs match up.
21 let uid = unsafe { geteuid() };
22 let gid = unsafe { getegid() };
23 assert_eq!(cred_a.uid, uid);
24 assert_eq!(cred_a.gid, gid);
25 }