-
Notifications
You must be signed in to change notification settings - Fork 10
/
python_leak_test.py
executable file
·109 lines (78 loc) · 3.32 KB
/
python_leak_test.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
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/python
# test DrQueue Python bindings for memory leaks
import drqueue.base.libdrqueue as drqueue
import os
import subprocess
# find out username
username = os.getlogin()
## TEST 1: request_computer_list()
# determine number of shared memory segments before running the test
p1 = subprocess.Popen(["ipcs", "-m"], stdout=subprocess.PIPE)
p2 = subprocess.Popen(["grep", username], stdin=p1.stdout, stdout=subprocess.PIPE)
p3 = subprocess.Popen(["wc", "-l"], stdin=p2.stdout, stdout=subprocess.PIPE)
numshm = int(p3.communicate()[0])
for x in range(10):
# get list of slaves
slaves = drqueue.request_computer_list(drqueue.CLIENT)
#print slaves
# destroy object
slaves = 0
# determine number of shared memory segments again
p1 = subprocess.Popen(["ipcs", "-m"], stdout=subprocess.PIPE)
p2 = subprocess.Popen(["grep", username], stdin=p1.stdout, stdout=subprocess.PIPE)
p3 = subprocess.Popen(["wc", "-l"], stdin=p2.stdout, stdout=subprocess.PIPE)
shmnew = int(p3.communicate()[0])
print("TEST 1: request_computer_list()\nOld number of SHM segments: "+str(numshm)+"\nNew number of SHM segments: "+str(shmnew)+"\n")
# test if memory was leaked
if shmnew > numshm:
print("Shared memory leaked!")
exit(1)
## TEST 2: request_job_list()
# determine number of shared memory segments before running the test
p1 = subprocess.Popen(["ipcs", "-m"], stdout=subprocess.PIPE)
p2 = subprocess.Popen(["grep", username], stdin=p1.stdout, stdout=subprocess.PIPE)
p3 = subprocess.Popen(["wc", "-l"], stdin=p2.stdout, stdout=subprocess.PIPE)
numshm = int(p3.communicate()[0])
for x in range(10):
# get list of slaves
jobs = drqueue.request_job_list(drqueue.CLIENT)
#print jobs
# destroy object
jobs = 0
# determine number of shared memory segments again
p1 = subprocess.Popen(["ipcs", "-m"], stdout=subprocess.PIPE)
p2 = subprocess.Popen(["grep", username], stdin=p1.stdout, stdout=subprocess.PIPE)
p3 = subprocess.Popen(["wc", "-l"], stdin=p2.stdout, stdout=subprocess.PIPE)
shmnew = int(p3.communicate()[0])
print("TEST 2: request_job_list()\nOld number of SHM segments: "+str(numshm)+"\nNew number of SHM segments: "+str(shmnew)+"\n")
# test if memory was leaked
if shmnew > numshm:
print("Shared memory leaked!")
exit(1)
## TEST 3: request_frame_list()
# determine number of shared memory segments before running the test
p1 = subprocess.Popen(["ipcs", "-m"], stdout=subprocess.PIPE)
p2 = subprocess.Popen(["grep", username], stdin=p1.stdout, stdout=subprocess.PIPE)
p3 = subprocess.Popen(["wc", "-l"], stdin=p2.stdout, stdout=subprocess.PIPE)
numshm = int(p3.communicate()[0])
for x in range(10):
# get list of jobs
jobs = drqueue.request_job_list(drqueue.CLIENT)
for y in range(10):
# get list of frames of job #1
frames = jobs[0].request_frame_list(drqueue.CLIENT)
#print frames
# destroy object
frames = 0
jobs = 0
# determine number of shared memory segments again
p1 = subprocess.Popen(["ipcs", "-m"], stdout=subprocess.PIPE)
p2 = subprocess.Popen(["grep", username], stdin=p1.stdout, stdout=subprocess.PIPE)
p3 = subprocess.Popen(["wc", "-l"], stdin=p2.stdout, stdout=subprocess.PIPE)
shmnew = int(p3.communicate()[0])
print("TEST 3: request_frame_list()\nOld number of SHM segments: "+str(numshm)+"\nNew number of SHM segments: "+str(shmnew)+"\n")
# test if memory was leaked
if shmnew > numshm:
print("Shared memory leaked!")
exit(1)
exit(0)