• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use rustix::process;
2 
3 #[test]
test_getuid()4 fn test_getuid() {
5     assert_eq!(process::getuid(), process::getuid());
6     unsafe {
7         assert_eq!(process::getuid().as_raw(), libc::getuid());
8         assert_eq!(process::getuid().is_root(), libc::getuid() == 0);
9     }
10 }
11 
12 #[test]
test_getgid()13 fn test_getgid() {
14     assert_eq!(process::getgid(), process::getgid());
15     unsafe {
16         assert_eq!(process::getgid().as_raw(), libc::getgid());
17         assert_eq!(process::getgid().is_root(), libc::getgid() == 0);
18     }
19 }
20 
21 #[test]
test_geteuid()22 fn test_geteuid() {
23     assert_eq!(process::geteuid(), process::geteuid());
24     unsafe {
25         assert_eq!(process::geteuid().as_raw(), libc::geteuid());
26         assert_eq!(process::geteuid().is_root(), libc::geteuid() == 0);
27     }
28 }
29 
30 #[test]
test_getegid()31 fn test_getegid() {
32     assert_eq!(process::getegid(), process::getegid());
33     unsafe {
34         assert_eq!(process::getegid().as_raw(), libc::getegid());
35         assert_eq!(process::getegid().is_root(), libc::getegid() == 0);
36     }
37 }
38 
39 #[test]
test_getpid()40 fn test_getpid() {
41     assert_eq!(process::getpid(), process::getpid());
42     unsafe {
43         assert_eq!(
44             process::getpid().as_raw_nonzero().get() as libc::pid_t,
45             libc::getpid()
46         );
47         assert_eq!(process::getpid().is_init(), libc::getpid() == 1);
48     }
49 }
50 
51 #[test]
test_getppid()52 fn test_getppid() {
53     assert_eq!(process::getppid(), process::getppid());
54     unsafe {
55         assert_eq!(
56             process::Pid::as_raw(process::getppid()) as libc::pid_t,
57             libc::getppid()
58         );
59         if let Some(ppid) = process::getppid() {
60             assert_eq!(ppid.is_init(), libc::getppid() == 1);
61         } else {
62             assert_eq!(libc::getppid(), 0);
63         }
64     }
65 }
66 
67 #[test]
test_getpgid()68 fn test_getpgid() {
69     assert_eq!(process::getpgid(None), process::getpgid(None));
70     assert_eq!(
71         process::getpgid(Some(process::getpid())),
72         process::getpgid(Some(process::getpid()))
73     );
74     unsafe {
75         assert_eq!(
76             process::getpgid(None).unwrap().as_raw_nonzero().get() as libc::pid_t,
77             libc::getpgid(0)
78         );
79         assert_eq!(
80             process::getpgid(None).unwrap().is_init(),
81             libc::getpgid(0) == 1
82         );
83         assert_eq!(
84             process::getpgid(Some(process::getpid()))
85                 .unwrap()
86                 .as_raw_nonzero()
87                 .get() as libc::pid_t,
88             libc::getpgid(libc::getpid())
89         );
90     }
91 }
92 
93 #[test]
test_getpgrp()94 fn test_getpgrp() {
95     assert_eq!(process::getpgrp(), process::getpgrp());
96     unsafe {
97         assert_eq!(
98             process::getpgrp().as_raw_nonzero().get() as libc::pid_t,
99             libc::getpgrp()
100         );
101     }
102 }
103