summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/tests/process/id.rs
blob: 10095fa603ff05c8054af186b3740be7cf8b2a62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use rustix::process;

#[test]
fn test_getuid() {
    assert_eq!(process::getuid(), process::getuid());
    unsafe {
        assert_eq!(process::getuid().as_raw(), libc::getuid());
        assert_eq!(process::getuid().is_root(), libc::getuid() == 0);
    }
}

#[test]
fn test_getgid() {
    assert_eq!(process::getgid(), process::getgid());
    unsafe {
        assert_eq!(process::getgid().as_raw(), libc::getgid());
        assert_eq!(process::getgid().is_root(), libc::getgid() == 0);
    }
}

#[test]
fn test_geteuid() {
    assert_eq!(process::geteuid(), process::geteuid());
    unsafe {
        assert_eq!(process::geteuid().as_raw(), libc::geteuid());
        assert_eq!(process::geteuid().is_root(), libc::geteuid() == 0);
    }
}

#[test]
fn test_getegid() {
    assert_eq!(process::getegid(), process::getegid());
    unsafe {
        assert_eq!(process::getegid().as_raw(), libc::getegid());
        assert_eq!(process::getegid().is_root(), libc::getegid() == 0);
    }
}

#[test]
fn test_getpid() {
    assert_eq!(process::getpid(), process::getpid());
    unsafe {
        assert_eq!(
            process::getpid().as_raw_nonzero().get() as libc::pid_t,
            libc::getpid()
        );
        assert_eq!(process::getpid().is_init(), libc::getpid() == 1);
    }
}

#[test]
fn test_getppid() {
    assert_eq!(process::getppid(), process::getppid());
    unsafe {
        assert_eq!(
            process::Pid::as_raw(process::getppid()) as libc::pid_t,
            libc::getppid()
        );
        if let Some(ppid) = process::getppid() {
            assert_eq!(ppid.is_init(), libc::getppid() == 1);
        } else {
            assert_eq!(libc::getppid(), 0);
        }
    }
}