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
66
67
68
69
70
71
#[cfg(test)]
mod tests {
use crate::{utils, ProcessExt, System, SystemExt};
#[test]
fn test_refresh_system() {
let mut sys = System::new();
sys.refresh_system();
assert!(sys.get_total_memory() != 0);
assert!(sys.get_free_memory() != 0);
assert!(sys.get_total_memory() >= sys.get_free_memory());
assert!(sys.get_total_swap() >= sys.get_free_swap());
}
#[test]
fn test_refresh_process() {
let mut sys = System::new();
assert!(
sys.get_processes().is_empty(),
"no process should be listed!"
);
sys.refresh_processes();
assert!(
sys.refresh_process(utils::get_current_pid().expect("failed to get current pid")),
"process not listed",
);
}
#[test]
fn test_get_process() {
let mut sys = System::new();
sys.refresh_processes();
let p = sys
.get_process(utils::get_current_pid().expect("failed to get current pid"))
.expect("didn't find process");
assert!(p.memory() > 0);
}
#[test]
fn check_if_send_and_sync() {
trait Foo {
fn foo(&self) {}
}
impl<T> Foo for T where T: Send {}
trait Bar {
fn bar(&self) {}
}
impl<T> Bar for T where T: Sync {}
let mut sys = System::new();
sys.refresh_processes();
let p = sys
.get_process(utils::get_current_pid().expect("failed to get current pid"))
.expect("didn't find process");
p.foo();
p.bar();
}
}