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,
17 "Test Skipped"], timeout=900)
21 return -1, "Fail [Not found]"
23 return -1, "Fail [Timeout]"
25 return 0, "Skipped [Not Run]"
28 # autotest used to run dump commands
29 # just fires the command
32 def dump_autotest(child, test_name):
33 child.sendline(test_name)
37 # reads output and waits for Test OK
40 def memory_autotest(child, test_name):
43 child.sendline(test_name)
45 regexp = "IOVA:0x[0-9a-f]*, len:([0-9]*), virt:0x[0-9a-f]*, " \
47 index = child.expect([regexp, "Test OK", "Test Failed",
48 pexpect.TIMEOUT], timeout=10)
50 return -1, "Fail [Timeout]"
57 size = int(child.match.groups()[0], 10)
62 return -1, "Fail [No entries]"
64 return -1, "Fail [{}]".format(error)
68 def spinlock_autotest(child, test_name):
71 child.sendline(test_name)
73 index = child.expect(["Test OK",
75 "Hello from core ([0-9]*) !",
76 "Hello from within recursive locks "
78 pexpect.TIMEOUT], timeout=5)
83 # message, check ordering
85 if int(child.match.groups()[0]) < i:
86 return -1, "Fail [Bad order]"
87 i = int(child.match.groups()[0])
89 if int(child.match.groups()[0]) < ir:
90 return -1, "Fail [Bad order]"
91 ir = int(child.match.groups()[0])
95 return -1, "Fail [Timeout]"
102 def rwlock_autotest(child, test_name):
104 child.sendline(test_name)
106 index = child.expect(["Test OK",
108 "Hello from core ([0-9]*) !",
109 "Global write lock taken on main "
111 pexpect.TIMEOUT], timeout=10)
115 return -1, "Fail [Message is missing]"
118 # message, check ordering
120 if int(child.match.groups()[0]) < i:
121 return -1, "Fail [Bad order]"
122 i = int(child.match.groups()[0])
124 # must be the last message, check ordering
129 return -1, "Fail [Timeout]"
138 def ticketlock_autotest(child, test_name):
141 child.sendline(test_name)
143 index = child.expect(["Test OK",
145 "Hello from core ([0-9]*) !",
146 "Hello from within recursive locks "
148 pexpect.TIMEOUT], timeout=5)
153 # message, check ordering
155 if int(child.match.groups()[0]) < i:
156 return -1, "Fail [Bad order]"
157 i = int(child.match.groups()[0])
159 if int(child.match.groups()[0]) < ir:
160 return -1, "Fail [Bad order]"
161 ir = int(child.match.groups()[0])
165 return -1, "Fail [Timeout]"
171 def mcslock_autotest(child, test_name):
174 child.sendline(test_name)
176 index = child.expect(["Test OK",
178 "lcore ([0-9]*) state: ([0-1])"
179 "MCS lock taken on core ([0-9]*)",
180 "MCS lock released on core ([0-9]*)",
181 pexpect.TIMEOUT], timeout=5)
186 # message, check ordering
188 if int(child.match.groups()[0]) < i:
189 return -1, "Fail [Bad order]"
190 i = int(child.match.groups()[0])
192 if int(child.match.groups()[0]) < ir:
193 return -1, "Fail [Bad order]"
194 ir = int(child.match.groups()[0])
198 return -1, "Fail [Timeout]"
204 def logs_autotest(child, test_name):
205 child.sendline(test_name)
208 "TESTAPP1: error message",
209 "TESTAPP1: critical message",
210 "TESTAPP2: critical message",
211 "TESTAPP1: error message",
214 for log_msg in log_list:
215 index = child.expect([log_msg,
218 pexpect.TIMEOUT], timeout=10)
221 return -1, "Fail [Timeout]"
226 index = child.expect(["Test OK",
228 pexpect.TIMEOUT], timeout=10)
233 def timer_autotest(child, test_name):
234 child.sendline(test_name)
236 index = child.expect(["Start timer stress tests",
238 pexpect.TIMEOUT], timeout=5)
243 return -1, "Fail [Timeout]"
245 index = child.expect(["Start timer stress tests 2",
247 pexpect.TIMEOUT], timeout=5)
252 return -1, "Fail [Timeout]"
254 index = child.expect(["Start timer basic tests",
256 pexpect.TIMEOUT], timeout=5)
261 return -1, "Fail [Timeout]"
269 index = child.expect(["TESTTIMER: ([0-9]*): callback id=([0-9]*) "
270 "count=([0-9]*) on core ([0-9]*)",
273 pexpect.TIMEOUT], timeout=10)
281 return -1, "Fail [Timeout]"
284 id = int(child.match.groups()[1])
285 cnt = int(child.match.groups()[2])
286 lcore = int(child.match.groups()[3])
288 return -1, "Fail [Cannot parse]"
290 # timer0 always expires on the same core when cnt < 20
294 elif lcore != lcore_tim0 and cnt < 20:
295 return -1, "Fail [lcore != lcore_tim0 (%d, %d)]" \
296 % (lcore, lcore_tim0)
298 return -1, "Fail [tim0 cnt > 21]"
300 # timer1 each time expires on a different core
302 if lcore == lcore_tim1:
303 return -1, "Fail [lcore == lcore_tim1 (%d, %d)]" \
304 % (lcore, lcore_tim1)
307 return -1, "Fail [tim1 cnt > 30]"
309 # timer0 always expires on the same core
313 elif lcore != lcore_tim2:
314 return -1, "Fail [lcore != lcore_tim2 (%d, %d)]" \
315 % (lcore, lcore_tim2)
317 return -1, "Fail [tim2 cnt > 30]"
319 # timer0 always expires on the same core
323 elif lcore != lcore_tim3:
324 return -1, "Fail [lcore_tim3 changed (%d -> %d)]" \
325 % (lcore, lcore_tim3)
327 return -1, "Fail [tim3 cnt > 30]"
329 # must be 2 different cores
330 if lcore_tim0 == lcore_tim3:
331 return -1, "Fail [lcore_tim0 (%d) == lcore_tim3 (%d)]" \
332 % (lcore_tim0, lcore_tim3)
337 def ring_autotest(child, test_name):
338 child.sendline(test_name)
339 index = child.expect(["Test OK", "Test Failed",
340 pexpect.TIMEOUT], timeout=2)
344 return -1, "Fail [Timeout]"