1 |
2 |
drasko |
#!/usr/bin/python
|
2 |
|
|
import os
|
3 |
|
|
import shutil
|
4 |
|
|
from os.path import join
|
5 |
|
|
import sys
|
6 |
|
|
|
7 |
|
|
project_root = join(os.getcwd(), "../..")
|
8 |
|
|
source_root = os.path.join(project_root, 'src')
|
9 |
|
|
headers_root = os.path.join(project_root, 'include')
|
10 |
|
|
tests_run_root = os.path.join(os.getcwd(), 'tmp')
|
11 |
|
|
tools_root = os.getcwd()
|
12 |
|
|
|
13 |
|
|
init_state = "page_init.out"
|
14 |
|
|
exit_state = "page_exit.out"
|
15 |
|
|
SZ_10MB = 1024 * 1024 * 10
|
16 |
|
|
|
17 |
|
|
def power(x, y):
|
18 |
|
|
res = 1
|
19 |
|
|
for i in range(y):
|
20 |
|
|
res = res * x;
|
21 |
|
|
return res
|
22 |
|
|
|
23 |
|
|
def test_mm():
|
24 |
|
|
'''
|
25 |
|
|
Tries to set up meaningful input parameters for page_size, maximum allocation
|
26 |
|
|
size, total number of allocations, and total pages, and tests the memory allocator
|
27 |
|
|
in every one of these combinations. The parameter guessing is not great, but at least
|
28 |
|
|
some test cases are reasonable.
|
29 |
|
|
'''
|
30 |
|
|
page_sizes = [128, 256, 512, 1024, 2048, 4096, 8192]
|
31 |
|
|
max_alloc_sizes = [1, 10, 40, 50, 100, 200]
|
32 |
|
|
|
33 |
|
|
for page_size in page_sizes:
|
34 |
|
|
numpages = SZ_10MB / page_size
|
35 |
|
|
for i in range(1, 3):
|
36 |
|
|
res = numpages / power(10, i) # Divide numpages to 10, 100, 1000
|
37 |
|
|
if res > 0:
|
38 |
|
|
max_alloc_sizes.append(numpages/10)
|
39 |
|
|
max_alloc_sizes.append(numpages/100)
|
40 |
|
|
max_alloc_sizes.append(numpages/1000)
|
41 |
|
|
for max_alloc_size in max_alloc_sizes:
|
42 |
|
|
if max_alloc_size >= numpages: # If a single allocation exceeds total, adjust.
|
43 |
|
|
max_alloc_size = numpages / 2
|
44 |
|
|
num_allocs = numpages / (max_alloc_size) * 2 * 2 / 3
|
45 |
|
|
cmd = "./test -a=p -n=%d -s=%d -fi=%s -fx=%s -ps=%d -pn=%d" % \
|
46 |
|
|
(num_allocs, max_alloc_size, join(tests_run_root, init_state),\
|
47 |
|
|
join(tests_run_root, exit_state), page_size, numpages)
|
48 |
|
|
print "num_allocs = %d, max_alloc_size = %d, page_size = %d, numpages = %d" % \
|
49 |
|
|
(num_allocs, max_alloc_size, page_size, numpages)
|
50 |
|
|
os.system(cmd)
|
51 |
|
|
#os.system("cat %s" % join(tests_run_root, init_state))
|
52 |
|
|
diffcmd = "diff " + join(tests_run_root, init_state) + " " + join(tests_run_root, exit_state)
|
53 |
|
|
if os.system(diffcmd) != 0:
|
54 |
|
|
print "Error: %s has failed.\n" % cmd
|
55 |
|
|
sys.exit(1)
|
56 |
|
|
|
57 |
|
|
def test_km():
|
58 |
|
|
'''
|
59 |
|
|
Tries to set up meaningful input parameters for payload size, maximum allocation
|
60 |
|
|
size, total number of allocations, and total pages, and tests kmalloc
|
61 |
|
|
in every one of these combinations. The parameter guessing is not great, but at least
|
62 |
|
|
some test cases are reasonable.
|
63 |
|
|
'''
|
64 |
|
|
page_sizes = [4096, 8192]
|
65 |
|
|
max_alloc_sizes = [1, 10, 40, 50, 100, 200, 1024, 2048, 4096, 10000, 50000, 100000]
|
66 |
|
|
numpages = 1024
|
67 |
|
|
for page_size in page_sizes:
|
68 |
|
|
for max_alloc_size in max_alloc_sizes:
|
69 |
|
|
num_allocs = (numpages * page_size * 3) / (max_alloc_size * 2)
|
70 |
|
|
cmd = "./test -a=k -n=%d -s=%d -fi=%s -fx=%s -ps=%d -pn=%d" % \
|
71 |
|
|
(num_allocs, max_alloc_size, join(tests_run_root, init_state),\
|
72 |
|
|
join(tests_run_root, exit_state), page_size, numpages)
|
73 |
|
|
print "num_allocs = %d, max_alloc_size = %d, page_size = %d, numpages = %d" %\
|
74 |
|
|
(num_allocs, max_alloc_size, page_size, numpages)
|
75 |
|
|
diffcmd = "diff " + join(tests_run_root, init_state) + " " +\
|
76 |
|
|
join(tests_run_root, exit_state)
|
77 |
|
|
if os.system(diffcmd) != 0:
|
78 |
|
|
print "Error: %s has failed.\n" % cmd
|
79 |
|
|
sys.exit(1)
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
def test_mm_params(num_allocs, max_alloc_size, page_size, numpages, iterations):
|
83 |
|
|
for i in range(iterations):
|
84 |
|
|
cmd = "./test -a=p -n=%d -s=%d -fi=%s -fx=%s -ps=%d -pn=%d" % \
|
85 |
|
|
(num_allocs, max_alloc_size, join(tests_run_root, init_state),\
|
86 |
|
|
join(tests_run_root, exit_state), page_size, numpages)
|
87 |
|
|
print "num_allocs = %d, max_alloc_size = %d, page_size = %d, numpages = %d" % \
|
88 |
|
|
(num_allocs, max_alloc_size, page_size, numpages)
|
89 |
|
|
os.system(cmd)
|
90 |
|
|
#os.system("cat %s" % join(tests_run_root, init_state))
|
91 |
|
|
diffcmd = "diff " + join(tests_run_root, init_state) + " " + join(tests_run_root, exit_state)
|
92 |
|
|
if os.system(diffcmd) != 0:
|
93 |
|
|
print "Error: %s has failed.\n" % cmd
|
94 |
|
|
sys.exit(1)
|
95 |
|
|
|
96 |
|
|
def run_tests():
|
97 |
|
|
if os.path.exists(tests_run_root):
|
98 |
|
|
shutil.rmtree(tests_run_root)
|
99 |
|
|
os.mkdir(tests_run_root)
|
100 |
|
|
|
101 |
|
|
# for i in range (100):
|
102 |
|
|
#test_km()
|
103 |
|
|
test_mm()
|
104 |
|
|
#test_mm_params(10922, 10, 128, 81920, 50)
|
105 |
|
|
#test_km()
|
106 |
|
|
#test_mc()
|
107 |
|
|
|
108 |
|
|
if __name__ == '__main__':
|
109 |
|
|
run_tests()
|
110 |
|
|
|