3 # Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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
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.
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.
36 # 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
56 def dump_autotest(child, test_name):
57 child.sendline(test_name)
61 # reads output and waits for Test OK
64 def memory_autotest(child, test_name):
67 child.sendline(test_name)
69 regexp = "IOVA:0x[0-9a-f]*, len:([0-9]*), virt:0x[0-9a-f]*, " \
71 index = child.expect([regexp, "Test OK", "Test Failed",
72 pexpect.TIMEOUT], timeout=10)
74 return -1, "Fail [Timeout]"
81 size = int(child.match.groups()[0], 10)
86 return -1, "Fail [No entries]"
88 return -1, "Fail [{}]".format(error)
92 def spinlock_autotest(child, test_name):
95 child.sendline(test_name)
97 index = child.expect(["Test OK",
99 "Hello from core ([0-9]*) !",
100 "Hello from within recursive locks "
102 pexpect.TIMEOUT], timeout=5)
107 # message, check ordering
109 if int(child.match.groups()[0]) < i:
110 return -1, "Fail [Bad order]"
111 i = int(child.match.groups()[0])
113 if int(child.match.groups()[0]) < ir:
114 return -1, "Fail [Bad order]"
115 ir = int(child.match.groups()[0])
119 return -1, "Fail [Timeout]"
126 def rwlock_autotest(child, test_name):
128 child.sendline(test_name)
130 index = child.expect(["Test OK",
132 "Hello from core ([0-9]*) !",
133 "Global write lock taken on master "
135 pexpect.TIMEOUT], timeout=10)
139 return -1, "Fail [Message is missing]"
142 # message, check ordering
144 if int(child.match.groups()[0]) < i:
145 return -1, "Fail [Bad order]"
146 i = int(child.match.groups()[0])
148 # must be the last message, check ordering
153 return -1, "Fail [Timeout]"
162 def logs_autotest(child, test_name):
163 child.sendline(test_name)
166 "TESTAPP1: error message",
167 "TESTAPP1: critical message",
168 "TESTAPP2: critical message",
169 "TESTAPP1: error message",
172 for log_msg in log_list:
173 index = child.expect([log_msg,
176 pexpect.TIMEOUT], timeout=10)
179 return -1, "Fail [Timeout]"
184 index = child.expect(["Test OK",
186 pexpect.TIMEOUT], timeout=10)
191 def timer_autotest(child, test_name):
192 child.sendline(test_name)
194 index = child.expect(["Start timer stress tests",
196 pexpect.TIMEOUT], timeout=5)
201 return -1, "Fail [Timeout]"
203 index = child.expect(["Start timer stress tests 2",
205 pexpect.TIMEOUT], timeout=5)
210 return -1, "Fail [Timeout]"
212 index = child.expect(["Start timer basic tests",
214 pexpect.TIMEOUT], timeout=5)
219 return -1, "Fail [Timeout]"
227 index = child.expect(["TESTTIMER: ([0-9]*): callback id=([0-9]*) "
228 "count=([0-9]*) on core ([0-9]*)",
231 pexpect.TIMEOUT], timeout=10)
239 return -1, "Fail [Timeout]"
242 id = int(child.match.groups()[1])
243 cnt = int(child.match.groups()[2])
244 lcore = int(child.match.groups()[3])
246 return -1, "Fail [Cannot parse]"
248 # timer0 always expires on the same core when cnt < 20
252 elif lcore != lcore_tim0 and cnt < 20:
253 return -1, "Fail [lcore != lcore_tim0 (%d, %d)]" \
254 % (lcore, lcore_tim0)
256 return -1, "Fail [tim0 cnt > 21]"
258 # timer1 each time expires on a different core
260 if lcore == lcore_tim1:
261 return -1, "Fail [lcore == lcore_tim1 (%d, %d)]" \
262 % (lcore, lcore_tim1)
265 return -1, "Fail [tim1 cnt > 30]"
267 # timer0 always expires on the same core
271 elif lcore != lcore_tim2:
272 return -1, "Fail [lcore != lcore_tim2 (%d, %d)]" \
273 % (lcore, lcore_tim2)
275 return -1, "Fail [tim2 cnt > 30]"
277 # timer0 always expires on the same core
281 elif lcore != lcore_tim3:
282 return -1, "Fail [lcore_tim3 changed (%d -> %d)]" \
283 % (lcore, lcore_tim3)
285 return -1, "Fail [tim3 cnt > 30]"
287 # must be 2 different cores
288 if lcore_tim0 == lcore_tim3:
289 return -1, "Fail [lcore_tim0 (%d) == lcore_tim3 (%d)]" \
290 % (lcore_tim0, lcore_tim3)
295 def ring_autotest(child, test_name):
296 child.sendline(test_name)
297 index = child.expect(["Test OK", "Test Failed",
298 pexpect.TIMEOUT], timeout=2)
302 return -1, "Fail [Timeout]"