mbuf: add a copy routine
[dpdk.git] / app / test / autotest_test_funcs.py
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2010-2014 Intel Corporation
3
4 # Test functions
5
6 import pexpect
7
8 # default autotest, used to run most tests
9 # waits for "Test OK"
10
11
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)
16     if result == 1:
17         return -1, "Fail"
18     elif result == 2:
19         return -1, "Fail [Not found]"
20     elif result == 3:
21         return -1, "Fail [Timeout]"
22     return 0, "Success"
23
24 # autotest used to run dump commands
25 # just fires the command
26
27
28 def dump_autotest(child, test_name):
29     child.sendline(test_name)
30     return 0, "Success"
31
32 # memory autotest
33 # reads output and waits for Test OK
34
35
36 def memory_autotest(child, test_name):
37     lines = 0
38     error = ''
39     child.sendline(test_name)
40     while True:
41         regexp = "IOVA:0x[0-9a-f]*, len:([0-9]*), virt:0x[0-9a-f]*, " \
42                  "socket_id:[0-9]*"
43         index = child.expect([regexp, "Test OK", "Test Failed",
44                               pexpect.TIMEOUT], timeout=10)
45         if index == 3:
46             return -1, "Fail [Timeout]"
47         elif index == 1:
48             break
49         elif index == 2:
50             return -1, "Fail"
51         else:
52             lines = lines + 1
53             size = int(child.match.groups()[0], 10)
54             if size <= 0:
55                 error = 'Bad size'
56
57     if lines <= 0:
58         return -1, "Fail [No entries]"
59     if error != '':
60         return -1, "Fail [{}]".format(error)
61     return 0, "Success"
62
63
64 def spinlock_autotest(child, test_name):
65     i = 0
66     ir = 0
67     child.sendline(test_name)
68     while True:
69         index = child.expect(["Test OK",
70                               "Test Failed",
71                               "Hello from core ([0-9]*) !",
72                               "Hello from within recursive locks "
73                               "from ([0-9]*) !",
74                               pexpect.TIMEOUT], timeout=5)
75         # ok
76         if index == 0:
77             break
78
79         # message, check ordering
80         elif index == 2:
81             if int(child.match.groups()[0]) < i:
82                 return -1, "Fail [Bad order]"
83             i = int(child.match.groups()[0])
84         elif index == 3:
85             if int(child.match.groups()[0]) < ir:
86                 return -1, "Fail [Bad order]"
87             ir = int(child.match.groups()[0])
88
89         # fail
90         elif index == 4:
91             return -1, "Fail [Timeout]"
92         elif index == 1:
93             return -1, "Fail"
94
95     return 0, "Success"
96
97
98 def rwlock_autotest(child, test_name):
99     i = 0
100     child.sendline(test_name)
101     while True:
102         index = child.expect(["Test OK",
103                               "Test Failed",
104                               "Hello from core ([0-9]*) !",
105                               "Global write lock taken on master "
106                               "core ([0-9]*)",
107                               pexpect.TIMEOUT], timeout=10)
108         # ok
109         if index == 0:
110             if i != 0xffff:
111                 return -1, "Fail [Message is missing]"
112             break
113
114         # message, check ordering
115         elif index == 2:
116             if int(child.match.groups()[0]) < i:
117                 return -1, "Fail [Bad order]"
118             i = int(child.match.groups()[0])
119
120         # must be the last message, check ordering
121         elif index == 3:
122             i = 0xffff
123
124         elif index == 4:
125             return -1, "Fail [Timeout]"
126
127         # fail
128         else:
129             return -1, "Fail"
130
131     return 0, "Success"
132
133
134 def ticketlock_autotest(child, test_name):
135     i = 0
136     ir = 0
137     child.sendline(test_name)
138     while True:
139         index = child.expect(["Test OK",
140                               "Test Failed",
141                               "Hello from core ([0-9]*) !",
142                               "Hello from within recursive locks "
143                               "from ([0-9]*) !",
144                               pexpect.TIMEOUT], timeout=5)
145         # ok
146         if index == 0:
147             break
148
149         # message, check ordering
150         elif index == 2:
151             if int(child.match.groups()[0]) < i:
152                 return -1, "Fail [Bad order]"
153             i = int(child.match.groups()[0])
154         elif index == 3:
155             if int(child.match.groups()[0]) < ir:
156                 return -1, "Fail [Bad order]"
157             ir = int(child.match.groups()[0])
158
159         # fail
160         elif index == 4:
161             return -1, "Fail [Timeout]"
162         elif index == 1:
163             return -1, "Fail"
164
165     return 0, "Success"
166
167 def mcslock_autotest(child, test_name):
168     i = 0
169     ir = 0
170     child.sendline(test_name)
171     while True:
172         index = child.expect(["Test OK",
173                               "Test Failed",
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)
178         # ok
179         if index == 0:
180             break
181
182         # message, check ordering
183         elif index == 2:
184             if int(child.match.groups()[0]) < i:
185                 return -1, "Fail [Bad order]"
186             i = int(child.match.groups()[0])
187         elif index == 3:
188             if int(child.match.groups()[0]) < ir:
189                 return -1, "Fail [Bad order]"
190             ir = int(child.match.groups()[0])
191
192         # fail
193         elif index == 4:
194             return -1, "Fail [Timeout]"
195         elif index == 1:
196             return -1, "Fail"
197
198     return 0, "Success"
199
200 def logs_autotest(child, test_name):
201     child.sendline(test_name)
202
203     log_list = [
204         "TESTAPP1: error message",
205         "TESTAPP1: critical message",
206         "TESTAPP2: critical message",
207         "TESTAPP1: error message",
208     ]
209
210     for log_msg in log_list:
211         index = child.expect([log_msg,
212                               "Test OK",
213                               "Test Failed",
214                               pexpect.TIMEOUT], timeout=10)
215
216         if index == 3:
217             return -1, "Fail [Timeout]"
218         # not ok
219         elif index != 0:
220             return -1, "Fail"
221
222     index = child.expect(["Test OK",
223                           "Test Failed",
224                           pexpect.TIMEOUT], timeout=10)
225
226     return 0, "Success"
227
228
229 def timer_autotest(child, test_name):
230     child.sendline(test_name)
231
232     index = child.expect(["Start timer stress tests",
233                           "Test Failed",
234                           pexpect.TIMEOUT], timeout=5)
235
236     if index == 1:
237         return -1, "Fail"
238     elif index == 2:
239         return -1, "Fail [Timeout]"
240
241     index = child.expect(["Start timer stress tests 2",
242                           "Test Failed",
243                           pexpect.TIMEOUT], timeout=5)
244
245     if index == 1:
246         return -1, "Fail"
247     elif index == 2:
248         return -1, "Fail [Timeout]"
249
250     index = child.expect(["Start timer basic tests",
251                           "Test Failed",
252                           pexpect.TIMEOUT], timeout=5)
253
254     if index == 1:
255         return -1, "Fail"
256     elif index == 2:
257         return -1, "Fail [Timeout]"
258
259     lcore_tim0 = -1
260     lcore_tim1 = -1
261     lcore_tim2 = -1
262     lcore_tim3 = -1
263
264     while True:
265         index = child.expect(["TESTTIMER: ([0-9]*): callback id=([0-9]*) "
266                               "count=([0-9]*) on core ([0-9]*)",
267                               "Test OK",
268                               "Test Failed",
269                               pexpect.TIMEOUT], timeout=10)
270
271         if index == 1:
272             break
273
274         if index == 2:
275             return -1, "Fail"
276         elif index == 3:
277             return -1, "Fail [Timeout]"
278
279         try:
280             id = int(child.match.groups()[1])
281             cnt = int(child.match.groups()[2])
282             lcore = int(child.match.groups()[3])
283         except:
284             return -1, "Fail [Cannot parse]"
285
286         # timer0 always expires on the same core when cnt < 20
287         if id == 0:
288             if lcore_tim0 == -1:
289                 lcore_tim0 = lcore
290             elif lcore != lcore_tim0 and cnt < 20:
291                 return -1, "Fail [lcore != lcore_tim0 (%d, %d)]" \
292                     % (lcore, lcore_tim0)
293             if cnt > 21:
294                 return -1, "Fail [tim0 cnt > 21]"
295
296         # timer1 each time expires on a different core
297         if id == 1:
298             if lcore == lcore_tim1:
299                 return -1, "Fail [lcore == lcore_tim1 (%d, %d)]" \
300                     % (lcore, lcore_tim1)
301             lcore_tim1 = lcore
302             if cnt > 10:
303                 return -1, "Fail [tim1 cnt > 30]"
304
305         # timer0 always expires on the same core
306         if id == 2:
307             if lcore_tim2 == -1:
308                 lcore_tim2 = lcore
309             elif lcore != lcore_tim2:
310                 return -1, "Fail [lcore != lcore_tim2 (%d, %d)]" \
311                     % (lcore, lcore_tim2)
312             if cnt > 30:
313                 return -1, "Fail [tim2 cnt > 30]"
314
315         # timer0 always expires on the same core
316         if id == 3:
317             if lcore_tim3 == -1:
318                 lcore_tim3 = lcore
319             elif lcore != lcore_tim3:
320                 return -1, "Fail [lcore_tim3 changed (%d -> %d)]" \
321                     % (lcore, lcore_tim3)
322             if cnt > 30:
323                 return -1, "Fail [tim3 cnt > 30]"
324
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)
329
330     return 0, "Success"
331
332
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)
337     if index == 1:
338         return -1, "Fail"
339     elif index == 2:
340         return -1, "Fail [Timeout]"
341
342     return 0, "Success"