1 use rustix
::process
::nice
;
2 #[cfg(not(target_os = "redox"))]
3 use rustix
::process
::{getpriority_process, setpriority_process}
;
5 #[cfg(not(target_os = "freebsd"))] // FreeBSD's nice(3) doesn't return the old value.
8 let old
= nice(0).unwrap();
10 #[cfg(not(target_os = "redox"))]
12 let get_prio
= getpriority_process(None
).unwrap();
13 assert_eq
!(get_prio
, old
);
16 // Lower the priority by one.
17 let new
= nice(1).unwrap();
19 // If the test wasn't running with the lowest priority initially, test that
20 // we were able to lower the priority.
22 assert_eq
!(old
+ 1, new
);
25 let get
= nice(0).unwrap();
28 #[cfg(not(target_os = "redox"))]
30 let get_prio
= getpriority_process(None
).unwrap();
31 assert_eq
!(get_prio
, new
);
33 setpriority_process(None
, get
+ 1).unwrap();
34 let now
= getpriority_process(None
).unwrap();
36 // If the test wasn't running with the lowest priority initially, test
37 // that we were able to lower the priority.
39 assert_eq
!(get
+ 1, now
);
41 setpriority_process(None
, get
+ 10000).unwrap();
42 let now
= getpriority_process(None
).unwrap();
43 // Linux's max is 19; Darwin's max is 20.
44 assert
!(now
>= 19 && now
<= 20);
45 // Darwin appears to return `EPERM` on an out of range `nice`.
46 if let Ok(again
) = nice(1) {
47 assert_eq
!(now
, again
);
52 /// FreeBSD's `nice` doesn't return the new nice value, so use a specialized
54 #[cfg(target_os = "freebsd")]
56 fn test_priorities() {
57 let start
= getpriority_process(None
).unwrap();
59 let _
= nice(0).unwrap();
61 let now
= getpriority_process(None
).unwrap();
62 assert_eq
!(start
, now
);
64 let _
= nice(1).unwrap();
66 let now
= getpriority_process(None
).unwrap();
67 assert_eq
!(start
+ 1, now
);
69 setpriority_process(None
, start
+ 2).unwrap();
71 let now
= getpriority_process(None
).unwrap();
72 assert_eq
!(start
+ 2, now
);
74 setpriority_process(None
, 10000).unwrap();
76 let now
= getpriority_process(None
).unwrap();
79 let _
= nice(1).unwrap();
81 let now
= getpriority_process(None
).unwrap();