5 # Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in
16 # the documentation and/or other materials provided with the
18 # * Neither the name of Intel Corporation nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 import sys, pexpect, time, os, re
38 # default autotest, used to run most tests
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)
47 return -1, "Fail [Not found]"
49 return -1, "Fail [Timeout]"
52 # autotest used to run dump commands
53 # just fires the command
54 def dump_autotest(child, test_name):
55 child.sendline(test_name)
59 # reads output and waits for Test OK
60 def memory_autotest(child, test_name):
61 child.sendline(test_name)
62 regexp = "phys:0x[0-9a-f]*, len:([0-9]*), virt:0x[0-9a-f]*, socket_id:[0-9]*"
63 index = child.expect([regexp, pexpect.TIMEOUT], timeout = 180)
65 return -1, "Fail [Timeout]"
66 size = int(child.match.groups()[0], 16)
68 return -1, "Fail [Bad size]"
69 index = child.expect(["Test OK", "Test Failed",
70 pexpect.TIMEOUT], timeout = 10)
74 return -1, "Fail [Timeout]"
77 def spinlock_autotest(child, test_name):
80 child.sendline(test_name)
82 index = child.expect(["Test OK",
84 "Hello from core ([0-9]*) !",
85 "Hello from within recursive locks from ([0-9]*) !",
86 pexpect.TIMEOUT], timeout = 20)
91 # message, check ordering
93 if int(child.match.groups()[0]) < i:
94 return -1, "Fail [Bad order]"
95 i = int(child.match.groups()[0])
97 if int(child.match.groups()[0]) < ir:
98 return -1, "Fail [Bad order]"
99 ir = int(child.match.groups()[0])
103 return -1, "Fail [Timeout]"
109 def rwlock_autotest(child, test_name):
111 child.sendline(test_name)
113 index = child.expect(["Test OK",
115 "Hello from core ([0-9]*) !",
116 "Global write lock taken on master core ([0-9]*)",
117 pexpect.TIMEOUT], timeout = 10)
121 return -1, "Fail [Message is missing]"
124 # message, check ordering
126 if int(child.match.groups()[0]) < i:
127 return -1, "Fail [Bad order]"
128 i = int(child.match.groups()[0])
130 # must be the last message, check ordering
135 return -1, "Fail [Timeout]"
143 def logs_autotest(child, test_name):
145 child.sendline(test_name)
148 "TESTAPP1: this is a debug level message",
149 "TESTAPP1: this is a info level message",
150 "TESTAPP1: this is a warning level message",
151 "TESTAPP2: this is a info level message",
152 "TESTAPP2: this is a warning level message",
153 "TESTAPP1: this is a debug level message",
154 "TESTAPP1: this is a debug level message",
155 "TESTAPP1: this is a info level message",
156 "TESTAPP1: this is a warning level message",
157 "TESTAPP2: this is a info level message",
158 "TESTAPP2: this is a warning level message",
159 "TESTAPP1: this is a debug level message",
162 for log_msg in log_list:
163 index = child.expect([log_msg,
166 pexpect.TIMEOUT], timeout = 10)
169 return -1, "Fail [Timeout]"
174 index = child.expect(["Test OK",
176 pexpect.TIMEOUT], timeout = 10)
180 def timer_autotest(child, test_name):
182 child.sendline(test_name)
184 index = child.expect(["Start timer stress tests \(20 seconds\)",
186 pexpect.TIMEOUT], timeout = 10)
191 return -1, "Fail [Timeout]"
193 index = child.expect(["Start timer stress tests 2",
195 pexpect.TIMEOUT], timeout = 40)
200 return -1, "Fail [Timeout]"
202 index = child.expect(["Start timer basic tests \(20 seconds\)",
204 pexpect.TIMEOUT], timeout = 20)
209 return -1, "Fail [Timeout]"
211 prev_lcore_timer1 = -1
219 index = child.expect(["TESTTIMER: ([0-9]*): callback id=([0-9]*) count=([0-9]*) on core ([0-9]*)",
222 pexpect.TIMEOUT], timeout = 10)
230 return -1, "Fail [Timeout]"
233 t = int(child.match.groups()[0])
234 id = int(child.match.groups()[1])
235 cnt = int(child.match.groups()[2])
236 lcore = int(child.match.groups()[3])
238 return -1, "Fail [Cannot parse]"
240 # timer0 always expires on the same core when cnt < 20
244 elif lcore != lcore_tim0 and cnt < 20:
245 return -1, "Fail [lcore != lcore_tim0 (%d, %d)]"%(lcore, lcore_tim0)
247 return -1, "Fail [tim0 cnt > 21]"
249 # timer1 each time expires on a different core
251 if lcore == lcore_tim1:
252 return -1, "Fail [lcore == lcore_tim1 (%d, %d)]"%(lcore, lcore_tim1)
255 return -1, "Fail [tim1 cnt > 30]"
257 # timer0 always expires on the same core
261 elif lcore != lcore_tim2:
262 return -1, "Fail [lcore != lcore_tim2 (%d, %d)]"%(lcore, lcore_tim2)
264 return -1, "Fail [tim2 cnt > 30]"
266 # timer0 always expires on the same core
270 elif lcore != lcore_tim3:
271 return -1, "Fail [lcore_tim3 changed (%d -> %d)]"%(lcore, lcore_tim3)
273 return -1, "Fail [tim3 cnt > 30]"
275 # must be 2 different cores
276 if lcore_tim0 == lcore_tim3:
277 return -1, "Fail [lcore_tim0 (%d) == lcore_tim3 (%d)]"%(lcore_tim0, lcore_tim3)
281 def ring_autotest(child, test_name):
282 child.sendline(test_name)
283 index = child.expect(["Test OK", "Test Failed",
284 pexpect.TIMEOUT], timeout = 15)
288 return -1, "Fail [Timeout]"
290 child.sendline("set_watermark test 100")
291 child.sendline("dump_ring test")
292 index = child.expect([" watermark=100",
293 pexpect.TIMEOUT], timeout = 1)
295 return -1, "Fail [Bad watermark]"