2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2010-2014 Intel Corporation
9 # default autotest, used to run most tests
13 def default_autotest(child, test_name):
14 child.sendline(test_name)
15 result = child.expect(["Test OK", "Test Failed",
16 "Command not found", pexpect.TIMEOUT], timeout=900)
20 return -1, "Fail [Not found]"
22 return -1, "Fail [Timeout]"
25 # autotest used to run dump commands
26 # just fires the command
29 def dump_autotest(child, test_name):
30 child.sendline(test_name)
34 # reads output and waits for Test OK
37 def memory_autotest(child, test_name):
40 child.sendline(test_name)
42 regexp = "IOVA:0x[0-9a-f]*, len:([0-9]*), virt:0x[0-9a-f]*, " \
44 index = child.expect([regexp, "Test OK", "Test Failed",
45 pexpect.TIMEOUT], timeout=10)
47 return -1, "Fail [Timeout]"
54 size = int(child.match.groups()[0], 10)
59 return -1, "Fail [No entries]"
61 return -1, "Fail [{}]".format(error)
65 def spinlock_autotest(child, test_name):
68 child.sendline(test_name)
70 index = child.expect(["Test OK",
72 "Hello from core ([0-9]*) !",
73 "Hello from within recursive locks "
75 pexpect.TIMEOUT], timeout=5)
80 # message, check ordering
82 if int(child.match.groups()[0]) < i:
83 return -1, "Fail [Bad order]"
84 i = int(child.match.groups()[0])
86 if int(child.match.groups()[0]) < ir:
87 return -1, "Fail [Bad order]"
88 ir = int(child.match.groups()[0])
92 return -1, "Fail [Timeout]"
99 def rwlock_autotest(child, test_name):
101 child.sendline(test_name)
103 index = child.expect(["Test OK",
105 "Hello from core ([0-9]*) !",
106 "Global write lock taken on main "
108 pexpect.TIMEOUT], timeout=10)
112 return -1, "Fail [Message is missing]"
115 # message, check ordering
117 if int(child.match.groups()[0]) < i:
118 return -1, "Fail [Bad order]"
119 i = int(child.match.groups()[0])
121 # must be the last message, check ordering
126 return -1, "Fail [Timeout]"
135 def ticketlock_autotest(child, test_name):
138 child.sendline(test_name)
140 index = child.expect(["Test OK",
142 "Hello from core ([0-9]*) !",
143 "Hello from within recursive locks "
145 pexpect.TIMEOUT], timeout=5)
150 # message, check ordering
152 if int(child.match.groups()[0]) < i:
153 return -1, "Fail [Bad order]"
154 i = int(child.match.groups()[0])
156 if int(child.match.groups()[0]) < ir:
157 return -1, "Fail [Bad order]"
158 ir = int(child.match.groups()[0])
162 return -1, "Fail [Timeout]"
168 def mcslock_autotest(child, test_name):
171 child.sendline(test_name)
173 index = child.expect(["Test OK",
175 "lcore ([0-9]*) state: ([0-1])"
176 "MCS lock taken on core ([0-9]*)",
177 "MCS lock released on core ([0-9]*)",
178 pexpect.TIMEOUT], timeout=5)
183 # message, check ordering
185 if int(child.match.groups()[0]) < i:
186 return -1, "Fail [Bad order]"
187 i = int(child.match.groups()[0])
189 if int(child.match.groups()[0]) < ir:
190 return -1, "Fail [Bad order]"
191 ir = int(child.match.groups()[0])
195 return -1, "Fail [Timeout]"
201 def logs_autotest(child, test_name):
202 child.sendline(test_name)
205 "TESTAPP1: error message",
206 "TESTAPP1: critical message",
207 "TESTAPP2: critical message",
208 "TESTAPP1: error message",
211 for log_msg in log_list:
212 index = child.expect([log_msg,
215 pexpect.TIMEOUT], timeout=10)
218 return -1, "Fail [Timeout]"
223 index = child.expect(["Test OK",
225 pexpect.TIMEOUT], timeout=10)
230 def timer_autotest(child, test_name):
231 child.sendline(test_name)
233 index = child.expect(["Start timer stress tests",
235 pexpect.TIMEOUT], timeout=5)
240 return -1, "Fail [Timeout]"
242 index = child.expect(["Start timer stress tests 2",
244 pexpect.TIMEOUT], timeout=5)
249 return -1, "Fail [Timeout]"
251 index = child.expect(["Start timer basic tests",
253 pexpect.TIMEOUT], timeout=5)
258 return -1, "Fail [Timeout]"
266 index = child.expect(["TESTTIMER: ([0-9]*): callback id=([0-9]*) "
267 "count=([0-9]*) on core ([0-9]*)",
270 pexpect.TIMEOUT], timeout=10)
278 return -1, "Fail [Timeout]"
281 id = int(child.match.groups()[1])
282 cnt = int(child.match.groups()[2])
283 lcore = int(child.match.groups()[3])
285 return -1, "Fail [Cannot parse]"
287 # timer0 always expires on the same core when cnt < 20
291 elif lcore != lcore_tim0 and cnt < 20:
292 return -1, "Fail [lcore != lcore_tim0 (%d, %d)]" \
293 % (lcore, lcore_tim0)
295 return -1, "Fail [tim0 cnt > 21]"
297 # timer1 each time expires on a different core
299 if lcore == lcore_tim1:
300 return -1, "Fail [lcore == lcore_tim1 (%d, %d)]" \
301 % (lcore, lcore_tim1)
304 return -1, "Fail [tim1 cnt > 30]"
306 # timer0 always expires on the same core
310 elif lcore != lcore_tim2:
311 return -1, "Fail [lcore != lcore_tim2 (%d, %d)]" \
312 % (lcore, lcore_tim2)
314 return -1, "Fail [tim2 cnt > 30]"
316 # timer0 always expires on the same core
320 elif lcore != lcore_tim3:
321 return -1, "Fail [lcore_tim3 changed (%d -> %d)]" \
322 % (lcore, lcore_tim3)
324 return -1, "Fail [tim3 cnt > 30]"
326 # must be 2 different cores
327 if lcore_tim0 == lcore_tim3:
328 return -1, "Fail [lcore_tim0 (%d) == lcore_tim3 (%d)]" \
329 % (lcore_tim0, lcore_tim3)
334 def ring_autotest(child, test_name):
335 child.sendline(test_name)
336 index = child.expect(["Test OK", "Test Failed",
337 pexpect.TIMEOUT], timeout=2)
341 return -1, "Fail [Timeout]"