4 This file contains a stand-alone CPU scheduler test to be run on a node.
5 It still needs to be integrated into the testing framework.
11 from threading import Thread
14 def __init__(self, ctx, cpu, resv, share, min, max, desc):
24 class Spinner(Thread):
25 def __init__(self, test):
28 cmd = '/usr/bin/time ./_busyloop.py 15'
34 self.cmd = 'taskset -c ' + str(test.cpu) \
35 + ' vcontext --create --xid ' + str(test.ctx) + ' --disconnect ' \
36 + '-- vsched --fill-rate ' + str(test.resv) + ' --interval 100 ' \
37 + '--fill-rate2 ' + str(test.share) + ' --interval2 1000 ' \
38 + '--tokens 100 --tokens-min 50 --tokens-max 100 --force '\
39 + flags + ' -- vattribute --flag sched_hard -- ' + cmd
44 self.output = commands.getoutput( self.cmd )
47 match = re.search('elapsed (\d+)%CPU', self.output)
49 self.pct = int(match.group(1))
51 print "Error parsing output: cannot get CPU%"
54 return ( self.pct >= self.test.min and self.pct <= self.test.max )
57 def run_test(testlist):
61 test.thread = Spinner(test)
68 if test.thread.passed():
69 print "[PASSED] (" + str(test.thread.pct) + "%)\t", test.desc
71 print "[FAILED] (" + str(test.thread.pct) + "%)\t", test.desc
76 ### Test 1: test share scheduling of a single task (should get 100%)
78 test = CpuTest(ctx=600, cpu=0, resv=0, share=1, min=99, max=100,
79 desc = "Test 1: single ctx, one share")
81 return run_test([ test ])
83 ### Test 2: test hard rate-limiting to 25% (should get <= 25%)
85 test = CpuTest(ctx=600, cpu=0, resv=25, share=0, min=24, max=25,
86 desc = "Test 2: single ctx, 25% resv")
88 return run_test([ test ])
90 ### Test 3: test hard & share scheduling of a single task (should get 100%)
92 test = CpuTest(ctx=600, cpu=0, resv=25, share=1, min=99, max=100,
93 desc = "Test 3: single ctx, 25% resv, one share")
95 return run_test([ test ])
97 ### Test 4: test relative share scheduling of several tasks
99 test1 = CpuTest(ctx=600, cpu=0, resv=0, share=1, min=15, max=17,
100 desc = "Test 4: ctx 1, one share")
101 test2 = CpuTest(ctx=601, cpu=0, resv=0, share=2, min=32, max=34,
102 desc = " ctx 2, two shares")
103 test3 = CpuTest(ctx=602, cpu=0, resv=0, share=3, min=49, max=51,
104 desc = " ctx 3, three shares")
106 return run_test([ test1, test2, test3 ])
108 ### Test 5: test hard rate limit and shares
110 test1 = CpuTest(ctx=600, cpu=0, resv=0, share=1, min=14, max=16,
111 desc = "Test 5: ctx 1, one share")
112 test2 = CpuTest(ctx=601, cpu=0, resv=0, share=2, min=29, max=33,
113 desc = " ctx 2, two shares")
114 test3 = CpuTest(ctx=602, cpu=0, resv=0, share=3, min=44, max=47,
115 desc = " ctx 3, three shares")
116 test4 = CpuTest(ctx=603, cpu=0, resv=10, share=0, min=9, max=10,
117 desc = " ctx 4, 10% resv")
119 return run_test([ test1, test2, test3, test4 ])
121 ### Test 6: test guarantee and shares
123 test1 = CpuTest(ctx=600, cpu=0, resv=0, share=1, min=9, max=11,
124 desc = "Test 6: ctx 1, one share")
125 test2 = CpuTest(ctx=601, cpu=0, resv=0, share=2, min=19, max=21,
126 desc = " ctx 2, two shares")
127 test3 = CpuTest(ctx=602, cpu=0, resv=0, share=3, min=29, max=31,
128 desc = " ctx 3, three shares")
129 test4 = CpuTest(ctx=603, cpu=0, resv=30, share=1, min=38, max=41,
130 desc = " ctx 4, 30% resv, one share")
132 return run_test([ test1, test2, test3, test4 ])
134 ### Now, run all tests on two processors
135 ### Test 7: SMP active (both tasks should get 100% on an SMP)
137 test1 = CpuTest(ctx=600, cpu=0, resv=0, share=1, min=99, max=100,
138 desc = "Test 7: ctx 1, processor 1, one share")
139 test2 = CpuTest(ctx=601, cpu=1, resv=0, share=1, min=99, max=100,
140 desc = " ctx 2, processor 2, one share")
142 return run_test([ test1, test2 ])
144 ### Test 8: SMP, test hard rate-limiting to 25% (should get <= 25%)
146 test1 = CpuTest(ctx=600, cpu=0, resv=25, share=0, min=24, max=25,
147 desc = "Test 8: ctx 1, proc 1, 25% resv")
148 test2 = CpuTest(ctx=601, cpu=1, resv=25, share=0, min=24, max=25,
149 desc = " ctx 2, proc 2, 25% resv")
151 return run_test([ test1, test2 ])
153 ### Test 9: SMP, test hard & share scheduling of a single task
155 test1 = CpuTest(ctx=600, cpu=0, resv=25, share=1, min=99, max=100,
156 desc = "Test 9: ctx 1, proc 1, 25% resv, one share")
157 test2 = CpuTest(ctx=601, cpu=1, resv=25, share=1, min=99, max=100,
158 desc = " ctx 2, proc 2, 25% resv, one share")
160 return run_test([ test1, test2 ])
162 ### Test 10: SMP, test relative share scheduling of several tasks
164 test1 = CpuTest(ctx=600, cpu=0, resv=0, share=1, min=15, max=17,
165 desc = "Test 10: ctx 1, proc 1, one share")
166 test2 = CpuTest(ctx=601, cpu=0, resv=0, share=2, min=32, max=34,
167 desc = " ctx 2, proc 1, two shares")
168 test3 = CpuTest(ctx=602, cpu=0, resv=0, share=3, min=49, max=51,
169 desc = " ctx 3, proc 1, three shares")
170 test4 = CpuTest(ctx=603, cpu=1, resv=0, share=1, min=15, max=17,
171 desc = " ctx 4, proc 2, one share")
172 test5 = CpuTest(ctx=604, cpu=1, resv=0, share=2, min=32, max=34,
173 desc = " ctx 5, proc 2, two shares")
174 test6 = CpuTest(ctx=605, cpu=1, resv=0, share=3, min=49, max=51,
175 desc = " ctx 6, proc 2, three shares")
177 return run_test([ test1, test2, test3, test4, test5, test6 ])
179 ### Test 11: SMP, test hard rate limit and shares
181 test1 = CpuTest(ctx=600, cpu=0, resv=0, share=1, min=14, max=16,
182 desc = "Test 11: ctx 1, proc 1, one share")
183 test2 = CpuTest(ctx=601, cpu=0, resv=0, share=2, min=29, max=33,
184 desc = " ctx 2, proc 1, two shares")
185 test3 = CpuTest(ctx=602, cpu=0, resv=0, share=3, min=44, max=47,
186 desc = " ctx 3, proc 1, three shares")
187 test4 = CpuTest(ctx=603, cpu=0, resv=10, share=0, min=9, max=10,
188 desc = " ctx 4, proc 1, 10% resv")
189 test5 = CpuTest(ctx=604, cpu=1, resv=0, share=1, min=14, max=16,
190 desc = " ctx 5, proc 2, one share")
191 test6 = CpuTest(ctx=605, cpu=1, resv=0, share=2, min=29, max=33,
192 desc = " ctx 6, proc 2, two shares")
193 test7 = CpuTest(ctx=606, cpu=1, resv=0, share=3, min=44, max=47,
194 desc = " ctx 7, proc 2, three shares")
195 test8 = CpuTest(ctx=607, cpu=1, resv=10, share=0, min=9, max=10,
196 desc = " ctx 8, proc 2, 10% resv")
198 return run_test([ test1, test2, test3, test4, test5, test6, test7, test8 ])
200 ### Test 12: SMP, test guarantee and shares
202 test1 = CpuTest(ctx=600, cpu=0, resv=0, share=1, min=9, max=11,
203 desc = "Test 12: ctx 1, proc 1, one share")
204 test2 = CpuTest(ctx=601, cpu=0, resv=0, share=2, min=19, max=21,
205 desc = " ctx 2, proc 1, two shares")
206 test3 = CpuTest(ctx=602, cpu=0, resv=0, share=3, min=29, max=31,
207 desc = " ctx 3, proc 1, three shares")
208 test4 = CpuTest(ctx=603, cpu=0, resv=30, share=1, min=38, max=41,
209 desc = " ctx 4, proc 1, 30% resv, one share")
210 test5 = CpuTest(ctx=604, cpu=1, resv=0, share=1, min=9, max=11,
211 desc = " ctx 5, proc 2, one share")
212 test6 = CpuTest(ctx=605, cpu=1, resv=0, share=2, min=19, max=21,
213 desc = " ctx 6, proc 2, two shares")
214 test7 = CpuTest(ctx=606, cpu=1, resv=0, share=3, min=29, max=31,
215 desc = " ctx 7, proc 2, three shares")
216 test8 = CpuTest(ctx=607, cpu=1, resv=30, share=1, min=38, max=41,
217 desc = " ctx 8, proc 2, 30% resv, one share")
219 return run_test([ test1, test2, test3, test4, test5, test6, test7, test8 ])
234 failures += test_10()
235 failures += test_11()
236 failures += test_12()
240 if __name__ == "__main__":