1use rustix::process::Resource;
2#[cfg(not(target_os = "haiku"))] // No `Core` on Haiku.
3use rustix::process::Rlimit;
4
5#[test]
6fn test_getrlimit() {
7    let lim = rustix::process::getrlimit(Resource::Stack);
8    assert_ne!(lim.current, Some(0));
9    assert_ne!(lim.maximum, Some(0));
10}
11
12#[cfg(not(target_os = "haiku"))] // No `Core` on Haiku.
13#[test]
14fn test_setrlimit() {
15    let old = rustix::process::getrlimit(Resource::Core);
16    let new = Rlimit {
17        current: Some(0),
18        maximum: Some(4096),
19    };
20    assert_ne!(old, new);
21    rustix::process::setrlimit(Resource::Core, new.clone()).unwrap();
22
23    let lim = rustix::process::getrlimit(Resource::Core);
24    assert_eq!(lim, new);
25
26    #[cfg(any(target_os = "android", target_os = "linux"))]
27    {
28        let new = Rlimit {
29            current: Some(0),
30            maximum: Some(0),
31        };
32
33        let first = rustix::process::getrlimit(Resource::Core);
34
35        let old = match rustix::process::prlimit(None, Resource::Core, new.clone()) {
36            Ok(rlimit) => rlimit,
37            Err(rustix::io::Errno::NOSYS) => return,
38            Err(err) => Err(err).unwrap(),
39        };
40
41        assert_eq!(first, old);
42
43        let other = Rlimit {
44            current: Some(0),
45            maximum: Some(0),
46        };
47
48        let again =
49            rustix::process::prlimit(Some(rustix::process::getpid()), Resource::Core, other)
50                .unwrap();
51
52        assert_eq!(again, new);
53    }
54}
55