-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path30_TestProcesses.py
97 lines (91 loc) · 2.48 KB
/
30_TestProcesses.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from simulux.cpus import CPUS
from simulux.memory import Memory
from simulux.disks import Disks
from simulux.processes import Processes
from lib.utils import jsonify
# Set our environment
cpus = CPUS()
memory = Memory()
disks = Disks()
# Handle processes
processes = Processes(cpus=cpus, memory=memory, disks=disks)
def test_process_counts():
'''
Ensure the default processes are created
'''
expected_cpus = {
'steal': [0.0, 0.0],
'idle': [91.0, 91.0],
'user': [3.0, 3.0],
'irq': [0.0, 0.0],
'iowait': [3.0, 3.0],
'soft': [0.0, 0.0],
'system': [3.0, 3.0],
'guest': [0.0, 0.0],
'nice': [0.0, 0.0]
}
expected_memory = {
'used': 3072,
'cached': 0,
'free': 4191232,
'shared': 0,
'total': 4194304,
'buffers': 0
}
assert len(processes.processes) == 3
assert jsonify(expected_cpus) == jsonify(cpus.dump())
assert jsonify(expected_memory) == jsonify(memory.dump())
def test_kill_process():
'''
Ensure the killing a process by pid + release resources
'''
processes.kill_process(1)
expected_cpus = {
'steal': [0.0, 0.0],
'idle': [94.0, 94.0],
'user': [2.0, 2.0],
'irq': [0.0, 0.0],
'iowait': [2.0, 2.0],
'soft': [0.0, 0.0],
'system': [2.0, 2.0],
'guest': [0.0, 0.0],
'nice': [0.0, 0.0]
}
expected_memory = {
'used': 2048,
'cached': 0,
'free': 4192256,
'shared': 0,
'total': 4194304,
'buffers': 0
}
assert len(processes.processes) == 2
assert jsonify(expected_cpus) == jsonify(cpus.dump())
assert jsonify(expected_memory) == jsonify(memory.dump())
def test_killall_process():
'''
Ensure the killing a process by name + release resources
'''
processes.killall_process('bash')
expected_cpus = {
'steal': [0.0, 0.0],
'idle': [97.0, 97.0],
'user': [1.0, 1.0],
'irq': [0.0, 0.0],
'iowait': [1.0, 1.0],
'soft': [0.0, 0.0],
'system': [1.0, 1.0],
'guest': [0.0, 0.0],
'nice': [0.0, 0.0]
}
expected_memory = {
'used': 1024,
'cached': 0,
'free': 4193280,
'shared': 0,
'total': 4194304,
'buffers': 0
}
assert len(processes.processes) == 1
assert jsonify(expected_cpus) == jsonify(cpus.dump())
assert jsonify(expected_memory) == jsonify(memory.dump())