1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2010-2014 Intel Corporation
8 # default autotest, used to run most tests
12 def default_autotest(child, test_name):
13 child.sendline(test_name)
14 result = child.expect(["Test OK", "Test Failed",
15 "Command not found", pexpect.TIMEOUT], timeout=900)
19 return -1, "Fail [Not found]"
21 return -1, "Fail [Timeout]"
24 # autotest used to run dump commands
25 # just fires the command
28 def dump_autotest(child, test_name):
29 child.sendline(test_name)
33 # reads output and waits for Test OK
36 def memory_autotest(child, test_name):
39 child.sendline(test_name)
41 regexp = "IOVA:0x[0-9a-f]*, len:([0-9]*), virt:0x[0-9a-f]*, " \
43 index = child.expect([regexp, "Test OK", "Test Failed",
44 pexpect.TIMEOUT], timeout=10)
46 return -1, "Fail [Timeout]"
53 size = int(child.match.groups()[0], 10)
58 return -1, "Fail [No entries]"
60 return -1, "Fail [{}]".format(error)
64 def spinlock_autotest(child, test_name):
67 child.sendline(test_name)
69 index = child.expect(["Test OK",
71 "Hello from core ([0-9]*) !",
72 "Hello from within recursive locks "
74 pexpect.TIMEOUT], timeout=5)
79 # message, check ordering
81 if int(child.match.groups()[0]) < i:
82 return -1, "Fail [Bad order]"
83 i = int(child.match.groups()[0])
85 if int(child.match.groups()[0]) < ir:
86 return -1, "Fail [Bad order]"
87 ir = int(child.match.groups()[0])
91 return -1, "Fail [Timeout]"
98 def rwlock_autotest(child, test_name):
100 child.sendline(test_name)
102 index = child.expect(["Test OK",
104 "Hello from core ([0-9]*) !",
105 "Global write lock taken on master "
107 pexpect.TIMEOUT], timeout=10)
111 return -1, "Fail [Message is missing]"
114 # message, check ordering
116 if int(child.match.groups()[0]) < i:
117 return -1, "Fail [Bad order]"
118 i = int(child.match.groups()[0])
120 # must be the last message, check ordering
125 return -1, "Fail [Timeout]"
134 def ticketlock_autotest(child, test_name):
137 child.sendline(test_name)
139 index = child.expect(["Test OK",
141 "Hello from core ([0-9]*) !",
142 "Hello from within recursive locks "
144 pexpect.TIMEOUT], timeout=5)
149 # message, check ordering
151 if int(child.match.groups()[0]) < i:
152 return -1, "Fail [Bad order]"
153 i = int(child.match.groups()[0])
155 if int(child.match.groups()[0]) < ir:
156 return -1, "Fail [Bad order]"
157 ir = int(child.match.groups()[0])
161 return -1, "Fail [Timeout]"
167 def mcslock_autotest(child, test_name):
170 child.sendline(test_name)
172 index = child.expect(["Test OK",
174 "lcore ([0-9]*) state: ([0-1])"
175 "MCS lock taken on core ([0-9]*)",
176 "MCS lock released on core ([0-9]*)",
177 pexpect.TIMEOUT], timeout=5)
182 # message, check ordering
184 if int(child.match.groups()[0]) < i:
185 return -1, "Fail [Bad order]"
186 i = int(child.match.groups()[0])
188 if int(child.match.groups()[0]) < ir:
189 return -1, "Fail [Bad order]"
190 ir = int(child.match.groups()[0])
194 return -1, "Fail [Timeout]"
200 def logs_autotest(child, test_name):
201 child.sendline(test_name)
204 "TESTAPP1: error message",
205 "TESTAPP1: critical message",
206 "TESTAPP2: critical message",
207 "TESTAPP1: error message",
210 for log_msg in log_list:
211 index = child.expect([log_msg,
214 pexpect.TIMEOUT], timeout=10)
217 return -1, "Fail [Timeout]"
222 index = child.expect(["Test OK",
224 pexpect.TIMEOUT], timeout=10)
229 def timer_autotest(child, test_name):
230 child.sendline(test_name)
232 index = child.expect(["Start timer stress tests",
234 pexpect.TIMEOUT], timeout=5)
239 return -1, "Fail [Timeout]"
241 index = child.expect(["Start timer stress tests 2",
243 pexpect.TIMEOUT], timeout=5)
248 return -1, "Fail [Timeout]"
250 index = child.expect(["Start timer basic tests",
252 pexpect.TIMEOUT], timeout=5)
257 return -1, "Fail [Timeout]"
265 index = child.expect(["TESTTIMER: ([0-9]*): callback id=([0-9]*) "
266 "count=([0-9]*) on core ([0-9]*)",
269 pexpect.TIMEOUT], timeout=10)
277 return -1, "Fail [Timeout]"
280 id = int(child.match.groups()[1])
281 cnt = int(child.match.groups()[2])
282 lcore = int(child.match.groups()[3])
284 return -1, "Fail [Cannot parse]"
286 # timer0 always expires on the same core when cnt < 20
290 elif lcore != lcore_tim0 and cnt < 20:
291 return -1, "Fail [lcore != lcore_tim0 (%d, %d)]" \
292 % (lcore, lcore_tim0)
294 return -1, "Fail [tim0 cnt > 21]"
296 # timer1 each time expires on a different core
298 if lcore == lcore_tim1:
299 return -1, "Fail [lcore == lcore_tim1 (%d, %d)]" \
300 % (lcore, lcore_tim1)
303 return -1, "Fail [tim1 cnt > 30]"
305 # timer0 always expires on the same core
309 elif lcore != lcore_tim2:
310 return -1, "Fail [lcore != lcore_tim2 (%d, %d)]" \
311 % (lcore, lcore_tim2)
313 return -1, "Fail [tim2 cnt > 30]"
315 # timer0 always expires on the same core
319 elif lcore != lcore_tim3:
320 return -1, "Fail [lcore_tim3 changed (%d -> %d)]" \
321 % (lcore, lcore_tim3)
323 return -1, "Fail [tim3 cnt > 30]"
325 # must be 2 different cores
326 if lcore_tim0 == lcore_tim3:
327 return -1, "Fail [lcore_tim0 (%d) == lcore_tim3 (%d)]" \
328 % (lcore_tim0, lcore_tim3)
333 def ring_autotest(child, test_name):
334 child.sendline(test_name)
335 index = child.expect(["Test OK", "Test Failed",
336 pexpect.TIMEOUT], timeout=2)
340 return -1, "Fail [Timeout]"