forked from armink/UtestRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utest.py
68 lines (59 loc) · 2.11 KB
/
utest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/user/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2020, Armink, <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
#
# Change Logs:
# Date Author Notes
# 2020-01-27 armink the first version
#
import collections
import logging
import re
LOG_LVL = logging.DEBUG
LOG_TAG = 'utest'
logger = logging.getLogger(LOG_TAG)
class Utest:
def __init__(self, exec_cmd):
self.exec_cmd = exec_cmd
self.testcases = collections.OrderedDict()
signaled, tc_list_log = self.exec_cmd('utest_list', 1)
if tc_list_log == []:
self.init_result = False
else:
self.init_result = True
for line in tc_list_log:
if line.find('[testcase name]') != -1:
# get the testcase name
reg1 = re.compile(r'.*?\[testcase name\]:(.*?)[;]', re.S | re.M)
tc_name = re.findall(reg1, line)[0]
# get the testcase timeout
reg2 = re.compile(r'\[run timeout\]:[0-9]+')
match = reg2.search(line)
timeout_str = match.group(0).replace(r'[run timeout]:', '')
tc_timeout = int(timeout_str)
# add to list
self.testcases[tc_name] = tc_timeout
# self.testcases.append(testcase)
logger.debug('Get a testcase: ' + tc_name + ', timeout: ' + str(tc_timeout))
def test(self, name):
logger.info('Start test: ' + name)
signaled, tc_list_log = self.exec_cmd('utest_run ' + name, self.testcases[name])
if tc_list_log == []:
return False
for line in tc_list_log:
if line.find('[ result ] testcase (' + name + ')') != -1:
if (line.find('PASSED')) != -1:
logger.info('Test passed')
return True
else:
logger.error('Test failed')
return False
def test_all(self):
success = True
for k, v in self.testcases.items():
if not self.test(k):
success = False
return success