tile: fix build
[dpdk.git] / app / test / autotest_test_funcs.py
1 #   BSD LICENSE
2 #
3 #   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
4 #   All rights reserved.
5 #
6 #   Redistribution and use in source and binary forms, with or without
7 #   modification, are permitted provided that the following conditions
8 #   are met:
9 #
10 #     * Redistributions of source code must retain the above copyright
11 #       notice, this list of conditions and the following disclaimer.
12 #     * Redistributions in binary form must reproduce the above copyright
13 #       notice, this list of conditions and the following disclaimer in
14 #       the documentation and/or other materials provided with the
15 #       distribution.
16 #     * Neither the name of Intel Corporation nor the names of its
17 #       contributors may be used to endorse or promote products derived
18 #       from this software without specific prior written permission.
19 #
20 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 #   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 #   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 #   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 #   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 #   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 #   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 #   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 #   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 # Test functions
33
34 import pexpect
35
36 # default autotest, used to run most tests
37 # waits for "Test OK"
38
39
40 def default_autotest(child, test_name):
41     child.sendline(test_name)
42     result = child.expect(["Test OK", "Test Failed",
43                            "Command not found", pexpect.TIMEOUT], timeout=900)
44     if result == 1:
45         return -1, "Fail"
46     elif result == 2:
47         return -1, "Fail [Not found]"
48     elif result == 3:
49         return -1, "Fail [Timeout]"
50     return 0, "Success"
51
52 # autotest used to run dump commands
53 # just fires the command
54
55
56 def dump_autotest(child, test_name):
57     child.sendline(test_name)
58     return 0, "Success"
59
60 # memory autotest
61 # reads output and waits for Test OK
62
63
64 def memory_autotest(child, test_name):
65     child.sendline(test_name)
66     regexp = "phys:0x[0-9a-f]*, len:([0-9]*), virt:0x[0-9a-f]*, " \
67              "socket_id:[0-9]*"
68     index = child.expect([regexp, pexpect.TIMEOUT], timeout=180)
69     if index != 0:
70         return -1, "Fail [Timeout]"
71     size = int(child.match.groups()[0], 16)
72     if size <= 0:
73         return -1, "Fail [Bad size]"
74     index = child.expect(["Test OK", "Test Failed",
75                           pexpect.TIMEOUT], timeout=10)
76     if index == 1:
77         return -1, "Fail"
78     elif index == 2:
79         return -1, "Fail [Timeout]"
80     return 0, "Success"
81
82
83 def spinlock_autotest(child, test_name):
84     i = 0
85     ir = 0
86     child.sendline(test_name)
87     while True:
88         index = child.expect(["Test OK",
89                               "Test Failed",
90                               "Hello from core ([0-9]*) !",
91                               "Hello from within recursive locks "
92                               "from ([0-9]*) !",
93                               pexpect.TIMEOUT], timeout=5)
94         # ok
95         if index == 0:
96             break
97
98         # message, check ordering
99         elif index == 2:
100             if int(child.match.groups()[0]) < i:
101                 return -1, "Fail [Bad order]"
102             i = int(child.match.groups()[0])
103         elif index == 3:
104             if int(child.match.groups()[0]) < ir:
105                 return -1, "Fail [Bad order]"
106             ir = int(child.match.groups()[0])
107
108         # fail
109         elif index == 4:
110             return -1, "Fail [Timeout]"
111         elif index == 1:
112             return -1, "Fail"
113
114     return 0, "Success"
115
116
117 def rwlock_autotest(child, test_name):
118     i = 0
119     child.sendline(test_name)
120     while True:
121         index = child.expect(["Test OK",
122                               "Test Failed",
123                               "Hello from core ([0-9]*) !",
124                               "Global write lock taken on master "
125                               "core ([0-9]*)",
126                               pexpect.TIMEOUT], timeout=10)
127         # ok
128         if index == 0:
129             if i != 0xffff:
130                 return -1, "Fail [Message is missing]"
131             break
132
133         # message, check ordering
134         elif index == 2:
135             if int(child.match.groups()[0]) < i:
136                 return -1, "Fail [Bad order]"
137             i = int(child.match.groups()[0])
138
139         # must be the last message, check ordering
140         elif index == 3:
141             i = 0xffff
142
143         elif index == 4:
144             return -1, "Fail [Timeout]"
145
146         # fail
147         else:
148             return -1, "Fail"
149
150     return 0, "Success"
151
152
153 def logs_autotest(child, test_name):
154     child.sendline(test_name)
155
156     log_list = [
157         "TESTAPP1: error message",
158         "TESTAPP1: critical message",
159         "TESTAPP2: critical message",
160         "TESTAPP1: error message",
161     ]
162
163     for log_msg in log_list:
164         index = child.expect([log_msg,
165                               "Test OK",
166                               "Test Failed",
167                               pexpect.TIMEOUT], timeout=10)
168
169         if index == 3:
170             return -1, "Fail [Timeout]"
171         # not ok
172         elif index != 0:
173             return -1, "Fail"
174
175     index = child.expect(["Test OK",
176                           "Test Failed",
177                           pexpect.TIMEOUT], timeout=10)
178
179     return 0, "Success"
180
181
182 def timer_autotest(child, test_name):
183     child.sendline(test_name)
184
185     index = child.expect(["Start timer stress tests",
186                           "Test Failed",
187                           pexpect.TIMEOUT], timeout=5)
188
189     if index == 1:
190         return -1, "Fail"
191     elif index == 2:
192         return -1, "Fail [Timeout]"
193
194     index = child.expect(["Start timer stress tests 2",
195                           "Test Failed",
196                           pexpect.TIMEOUT], timeout=5)
197
198     if index == 1:
199         return -1, "Fail"
200     elif index == 2:
201         return -1, "Fail [Timeout]"
202
203     index = child.expect(["Start timer basic tests",
204                           "Test Failed",
205                           pexpect.TIMEOUT], timeout=5)
206
207     if index == 1:
208         return -1, "Fail"
209     elif index == 2:
210         return -1, "Fail [Timeout]"
211
212     lcore_tim0 = -1
213     lcore_tim1 = -1
214     lcore_tim2 = -1
215     lcore_tim3 = -1
216
217     while True:
218         index = child.expect(["TESTTIMER: ([0-9]*): callback id=([0-9]*) "
219                               "count=([0-9]*) on core ([0-9]*)",
220                               "Test OK",
221                               "Test Failed",
222                               pexpect.TIMEOUT], timeout=10)
223
224         if index == 1:
225             break
226
227         if index == 2:
228             return -1, "Fail"
229         elif index == 3:
230             return -1, "Fail [Timeout]"
231
232         try:
233             id = int(child.match.groups()[1])
234             cnt = int(child.match.groups()[2])
235             lcore = int(child.match.groups()[3])
236         except:
237             return -1, "Fail [Cannot parse]"
238
239         # timer0 always expires on the same core when cnt < 20
240         if id == 0:
241             if lcore_tim0 == -1:
242                 lcore_tim0 = lcore
243             elif lcore != lcore_tim0 and cnt < 20:
244                 return -1, "Fail [lcore != lcore_tim0 (%d, %d)]" \
245                     % (lcore, lcore_tim0)
246             if cnt > 21:
247                 return -1, "Fail [tim0 cnt > 21]"
248
249         # timer1 each time expires on a different core
250         if id == 1:
251             if lcore == lcore_tim1:
252                 return -1, "Fail [lcore == lcore_tim1 (%d, %d)]" \
253                     % (lcore, lcore_tim1)
254             lcore_tim1 = lcore
255             if cnt > 10:
256                 return -1, "Fail [tim1 cnt > 30]"
257
258         # timer0 always expires on the same core
259         if id == 2:
260             if lcore_tim2 == -1:
261                 lcore_tim2 = lcore
262             elif lcore != lcore_tim2:
263                 return -1, "Fail [lcore != lcore_tim2 (%d, %d)]" \
264                     % (lcore, lcore_tim2)
265             if cnt > 30:
266                 return -1, "Fail [tim2 cnt > 30]"
267
268         # timer0 always expires on the same core
269         if id == 3:
270             if lcore_tim3 == -1:
271                 lcore_tim3 = lcore
272             elif lcore != lcore_tim3:
273                 return -1, "Fail [lcore_tim3 changed (%d -> %d)]" \
274                     % (lcore, lcore_tim3)
275             if cnt > 30:
276                 return -1, "Fail [tim3 cnt > 30]"
277
278     # must be 2 different cores
279     if lcore_tim0 == lcore_tim3:
280         return -1, "Fail [lcore_tim0 (%d) == lcore_tim3 (%d)]" \
281             % (lcore_tim0, lcore_tim3)
282
283     return 0, "Success"
284
285
286 def ring_autotest(child, test_name):
287     child.sendline(test_name)
288     index = child.expect(["Test OK", "Test Failed",
289                           pexpect.TIMEOUT], timeout=2)
290     if index == 1:
291         return -1, "Fail"
292     elif index == 2:
293         return -1, "Fail [Timeout]"
294
295     child.sendline("set_watermark test 100")
296     child.sendline("dump_ring test")
297     index = child.expect(["  watermark=100",
298                           pexpect.TIMEOUT], timeout=1)
299     if index != 0:
300         return -1, "Fail [Bad watermark]"
301
302     return 0, "Success"