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.
38 # default autotest, used to run most tests
42 def default_autotest(child, test_name):
43 child.sendline(test_name)
44 result = child.expect(["Test OK", "Test Failed",
45 "Command not found", pexpect.TIMEOUT], timeout=900)
49 return -1, "Fail [Not found]"
51 return -1, "Fail [Timeout]"
54 # autotest used to run dump commands
55 # just fires the command
58 def dump_autotest(child, test_name):
59 child.sendline(test_name)
63 # reads output and waits for Test OK
66 def memory_autotest(child, test_name):
67 child.sendline(test_name)
68 regexp = "phys:0x[0-9a-f]*, len:([0-9]*), virt:0x[0-9a-f]*, " \
70 index = child.expect([regexp, pexpect.TIMEOUT], timeout=180)
72 return -1, "Fail [Timeout]"
73 size = int(child.match.groups()[0], 16)
75 return -1, "Fail [Bad size]"
76 index = child.expect(["Test OK", "Test Failed",
77 pexpect.TIMEOUT], timeout=10)
81 return -1, "Fail [Timeout]"
85 def spinlock_autotest(child, test_name):
88 child.sendline(test_name)
90 index = child.expect(["Test OK",
92 "Hello from core ([0-9]*) !",
93 "Hello from within recursive locks "
95 pexpect.TIMEOUT], timeout=5)
100 # message, check ordering
102 if int(child.match.groups()[0]) < i:
103 return -1, "Fail [Bad order]"
104 i = int(child.match.groups()[0])
106 if int(child.match.groups()[0]) < ir:
107 return -1, "Fail [Bad order]"
108 ir = int(child.match.groups()[0])
112 return -1, "Fail [Timeout]"
119 def rwlock_autotest(child, test_name):
121 child.sendline(test_name)
123 index = child.expect(["Test OK",
125 "Hello from core ([0-9]*) !",
126 "Global write lock taken on master "
128 pexpect.TIMEOUT], timeout=10)
132 return -1, "Fail [Message is missing]"
135 # message, check ordering
137 if int(child.match.groups()[0]) < i:
138 return -1, "Fail [Bad order]"
139 i = int(child.match.groups()[0])
141 # must be the last message, check ordering
146 return -1, "Fail [Timeout]"
155 def logs_autotest(child, test_name):
156 child.sendline(test_name)
159 "TESTAPP1: error message",
160 "TESTAPP1: critical message",
161 "TESTAPP2: critical message",
162 "TESTAPP1: error message",
165 for log_msg in log_list:
166 index = child.expect([log_msg,
169 pexpect.TIMEOUT], timeout=10)
172 return -1, "Fail [Timeout]"
177 index = child.expect(["Test OK",
179 pexpect.TIMEOUT], timeout=10)
184 def timer_autotest(child, test_name):
185 child.sendline(test_name)
187 index = child.expect(["Start timer stress tests",
189 pexpect.TIMEOUT], timeout=5)
194 return -1, "Fail [Timeout]"
196 index = child.expect(["Start timer stress tests 2",
198 pexpect.TIMEOUT], timeout=5)
203 return -1, "Fail [Timeout]"
205 index = child.expect(["Start timer basic tests",
207 pexpect.TIMEOUT], timeout=5)
212 return -1, "Fail [Timeout]"
220 index = child.expect(["TESTTIMER: ([0-9]*): callback id=([0-9]*) "
221 "count=([0-9]*) on core ([0-9]*)",
224 pexpect.TIMEOUT], timeout=10)
232 return -1, "Fail [Timeout]"
235 id = int(child.match.groups()[1])
236 cnt = int(child.match.groups()[2])
237 lcore = int(child.match.groups()[3])
239 return -1, "Fail [Cannot parse]"
241 # timer0 always expires on the same core when cnt < 20
245 elif lcore != lcore_tim0 and cnt < 20:
246 return -1, "Fail [lcore != lcore_tim0 (%d, %d)]" \
247 % (lcore, lcore_tim0)
249 return -1, "Fail [tim0 cnt > 21]"
251 # timer1 each time expires on a different core
253 if lcore == lcore_tim1:
254 return -1, "Fail [lcore == lcore_tim1 (%d, %d)]" \
255 % (lcore, lcore_tim1)
258 return -1, "Fail [tim1 cnt > 30]"
260 # timer0 always expires on the same core
264 elif lcore != lcore_tim2:
265 return -1, "Fail [lcore != lcore_tim2 (%d, %d)]" \
266 % (lcore, lcore_tim2)
268 return -1, "Fail [tim2 cnt > 30]"
270 # timer0 always expires on the same core
274 elif lcore != lcore_tim3:
275 return -1, "Fail [lcore_tim3 changed (%d -> %d)]" \
276 % (lcore, lcore_tim3)
278 return -1, "Fail [tim3 cnt > 30]"
280 # must be 2 different cores
281 if lcore_tim0 == lcore_tim3:
282 return -1, "Fail [lcore_tim0 (%d) == lcore_tim3 (%d)]" \
283 % (lcore_tim0, lcore_tim3)
288 def ring_autotest(child, test_name):
289 child.sendline(test_name)
290 index = child.expect(["Test OK", "Test Failed",
291 pexpect.TIMEOUT], timeout=2)
295 return -1, "Fail [Timeout]"
297 child.sendline("set_watermark test 100")
298 child.sendline("dump_ring test")
299 index = child.expect([" watermark=100",
300 pexpect.TIMEOUT], timeout=1)
302 return -1, "Fail [Bad watermark]"