Skip to content

Commit ba4f095

Browse files
author
Bogdan Marinescu
committed
Merge branch 'master' of github.com:mbedmicro/mbed
2 parents 8c28ed2 + a09f3dd commit ba4f095

File tree

10 files changed

+391
-111
lines changed

10 files changed

+391
-111
lines changed

workspace_tools/host_tests/echo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test(self):
2929
TEST="longer serial test"
3030
check = True
3131
for i in range(1, 100):
32-
self.mbed.serial.write(TEST + "\n")
32+
self.mbed.serial_write(TEST + "\n")
3333
l = self.mbed.serial.readline().strip()
3434
if not l: continue
3535

workspace_tools/host_tests/host_test.py

Lines changed: 76 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
from sys import stdout
2929

3030
class Mbed:
31-
"""
32-
Base class for a host driven test
31+
""" Base class for a host driven test
3332
"""
3433
def __init__(self):
3534
parser = OptionParser()
@@ -63,8 +62,17 @@ def __init__(self):
6362
dest="forced_reset_type",
6463
help="Forces different type of reset")
6564

65+
parser.add_option("-R", "--reset-timeout",
66+
dest="forced_reset_timeout",
67+
metavar="NUMBER",
68+
type="int",
69+
help="When forcing a reset using option -r you can set up after reset timeout in seconds")
70+
6671
(self.options, _) = parser.parse_args()
6772

73+
self.DEFAULT_RESET_TOUT = 2
74+
self.DEFAULT_TOUT = 10
75+
6876
if self.options.port is None:
6977
raise Exception("The serial port of the target mbed have to be provided as command line arguments")
7078

@@ -73,10 +81,12 @@ def __init__(self):
7381
self.extra_port = self.options.extra
7482
self.extra_serial = None
7583
self.serial = None
76-
self.timeout = 10 if self.options.timeout is None else self.options.timeout
77-
print 'Mbed: "%s" "%s"' % (self.port, self.disk)
84+
self.timeout = self.DEFAULT_TOUT if self.options.timeout is None else self.options.timeout
85+
print 'Host test instrumentation on port: "%s" with serial: "%s"' % (self.port, self.disk)
7886

7987
def init_serial(self, baud=9600, extra_baud=9600):
88+
""" Initialize serial port. Function will return error is port can't be opened or initialized
89+
"""
8090
result = True
8191
try:
8292
self.serial = Serial(self.port, timeout=1)
@@ -91,8 +101,18 @@ def init_serial(self, baud=9600, extra_baud=9600):
91101
self.flush()
92102
return result
93103

104+
def serial_timeout(self, timeout):
105+
""" Wraps self.mbed.serial object timeout property
106+
"""
107+
result = None
108+
if self.serial:
109+
self.serial.timeout = timeout
110+
result = True
111+
return result
112+
94113
def serial_read(self, count=1):
95-
""" Wraps self.mbed.serial object read method """
114+
""" Wraps self.mbed.serial object read method
115+
"""
96116
result = None
97117
if self.serial:
98118
try:
@@ -102,23 +122,24 @@ def serial_read(self, count=1):
102122
return result
103123

104124
def serial_write(self, write_buffer):
105-
""" Wraps self.mbed.serial object write method """
106-
result = -1
125+
""" Wraps self.mbed.serial object write method
126+
"""
127+
result = None
107128
if self.serial:
108129
try:
109130
result = self.serial.write(write_buffer)
110131
except:
111-
result = -1
132+
result = None
112133
return result
113134

114135
def safe_sendBreak(self, serial):
115136
""" Wraps serial.sendBreak() to avoid serial::serialposix.py exception on Linux
116-
Traceback (most recent call last):
117-
File "make.py", line 189, in <module>
118-
serial.sendBreak()
119-
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 511, in sendBreak
120-
termios.tcsendbreak(self.fd, int(duration/0.25))
121-
error: (32, 'Broken pipe')
137+
Traceback (most recent call last):
138+
File "make.py", line 189, in <module>
139+
serial.sendBreak()
140+
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 511, in sendBreak
141+
termios.tcsendbreak(self.fd, int(duration/0.25))
142+
error: (32, 'Broken pipe')
122143
"""
123144
result = True
124145
try:
@@ -132,24 +153,38 @@ def safe_sendBreak(self, serial):
132153
result = False
133154
return result
134155

135-
def touch_file(self, path, name):
136-
with os.open(path, 'a'):
156+
def touch_file(self, path):
157+
""" Touch file and set timestamp to items
158+
"""
159+
with open(path, 'a'):
137160
os.utime(path, None)
138161

162+
def reset_timeout(self, timeout):
163+
""" Timeout executed just after reset command is issued
164+
"""
165+
for n in range(0, timeout):
166+
sleep(1)
167+
139168
def reset(self):
140-
""" reboot.txt - startup from standby state, reboots when in run mode.
169+
""" Reset function. Supports 'standard' send break command via Mbed's CDC,
170+
also handles other reset modes.
171+
E.g. reset by touching file with specific file name:
172+
reboot.txt - startup from standby state, reboots when in run mode.
141173
shutdown.txt - shutdown from run mode
142-
reset.txt - reset fpga during run mode """
143-
if self.options.forced_reset_type:
144-
path = os.path.join([self.disk, self.options.forced_reset_type.lower()])
145-
if self.options.forced_reset_type.endswith('.txt'):
146-
self.touch_file(path)
174+
reset.txt - reset FPGA during run mode
175+
"""
176+
if self.options.forced_reset_type and self.options.forced_reset_type.endswith('.txt'):
177+
reset_file_path = os.path.join(self.disk, self.options.forced_reset_type.lower())
178+
self.touch_file(reset_file_path)
147179
else:
148180
self.safe_sendBreak(self.serial) # Instead of serial.sendBreak()
149181
# Give time to wait for the image loading
150-
sleep(2)
182+
reset_tout_s = self.options.forced_reset_timeout if self.options.forced_reset_timeout is not None else self.DEFAULT_RESET_TOUT
183+
self.reset_timeout(reset_tout_s)
151184

152185
def flush(self):
186+
""" Flush serial ports
187+
"""
153188
self.serial.flushInput()
154189
self.serial.flushOutput()
155190
if self.extra_serial:
@@ -158,10 +193,15 @@ def flush(self):
158193

159194

160195
class Test:
196+
""" Baseclass for host test's test runner
197+
"""
161198
def __init__(self):
162199
self.mbed = Mbed()
163200

164201
def run(self):
202+
""" Test runner for host test. This function will start executing
203+
test and forward test result via serial port to test suite
204+
"""
165205
try:
166206
result = self.test()
167207
self.print_result("success" if result else "failure")
@@ -170,31 +210,40 @@ def run(self):
170210
self.print_result("error")
171211

172212
def setup(self):
173-
""" Setup and check if configuration for test is correct. E.g. if serial port can be opened """
213+
""" Setup and check if configuration for test is correct. E.g. if serial port can be opened
214+
"""
174215
result = True
175216
if not self.mbed.serial:
176217
result = False
177218
self.print_result("ioerr_serial")
178219
return result
179220

180221
def notify(self, message):
181-
""" On screen notification function """
222+
""" On screen notification function
223+
"""
182224
print message
183225
stdout.flush()
184226

185227
def print_result(self, result):
186-
""" Test result unified printing function """
228+
""" Test result unified printing function
229+
"""
187230
self.notify("\n{%s}\n{end}" % result)
188231

189232

190233
class DefaultTest(Test):
234+
""" Test class with serial port initialization
235+
"""
191236
def __init__(self):
192237
Test.__init__(self)
193238
serial_init_res = self.mbed.init_serial()
194239
self.mbed.reset()
195240

196241

197242
class Simple(DefaultTest):
243+
""" Simple, basic host test's test runner waiting for serial port
244+
output from MUT, no supervision over test running in MUT is executed.
245+
Just waiting for result
246+
"""
198247
def run(self):
199248
try:
200249
while True:
@@ -207,5 +256,6 @@ def run(self):
207256
except KeyboardInterrupt, _:
208257
print "\n[CTRL+c] exit"
209258

259+
210260
if __name__ == '__main__':
211261
Simple().run()

workspace_tools/host_tests/rtc_auto.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class RTCTest(DefaultTest):
2626

2727
def run(self):
2828
test_result = True
29-
c = self.mbed.serial.timeout = None
29+
if self.mbed.serial_timeout(None) is None:
30+
self.print_result("ioerr_serial")
31+
return
3032
for i in range(0, 5):
3133
c = self.mbed.serial_read(38) # 38 len("[1256729742] [2009-10-28 11:35:42 AM]\n"
3234
if c is None:

workspace_tools/host_tests/stdio_auto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def run(self):
3131
for i in range(1, 5):
3232
random_integer = random.randint(-10000, 10000)
3333
print "Generated number: " + str(random_integer)
34-
self.mbed.serial.write(str(random_integer) + "\n")
34+
self.mbed.serial_write(str(random_integer) + "\n")
3535
serial_stdio_msg = ""
3636

3737
ip_msg_timeout = self.mbed.options.timeout

workspace_tools/host_tests/tcpecho_client_auto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def send_server_ip_port(self, ip_address, port_no):
3333
self.mbed.reset()
3434
print "Sending server IP Address to target..."
3535
connection_str = ip_address + ":" + str(port_no) + "\n"
36-
self.mbed.serial.write(connection_str)
36+
self.mbed.serial_write(connection_str)
3737

3838

3939
class TCPEchoClient_Handler(BaseRequestHandler):

workspace_tools/host_tests/udpecho_client_auto.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def send_server_ip_port(self, ip_address, port_no):
3232
self.mbed.reset()
3333
print "Sending server IP Address to target..."
3434
connection_str = ip_address + ":" + str(port_no) + "\n"
35-
self.mbed.serial.write(connection_str)
35+
self.mbed.serial_write(connection_str)
3636

3737

3838
class UDPEchoClient_Handler(BaseRequestHandler):

workspace_tools/host_tests/wait_us_auto.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class WaitusTest(DefaultTest):
2323
def run(self):
2424
test_result = True
2525
# First character to start test (to know after reset when test starts)
26-
self.mbed.serial.timeout = None
26+
if self.mbed.serial_timeout(None) is None:
27+
self.print_result("ioerr_serial")
28+
return
2729
c = self.mbed.serial_read(1)
2830
if c is None:
2931
self.print_result("ioerr_serial")

workspace_tools/singletest.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191

9292

9393
def get_version():
94-
""" Returns test script version """
94+
""" Returns test script version
95+
"""
9596
single_test_version_major = 1
9697
single_test_version_minor = 1
9798
return (single_test_version_major, single_test_version_minor)
@@ -168,6 +169,7 @@ def get_version():
168169
single_test = SingleTestRunner(_global_loops_count=opts.test_global_loops_value,
169170
_test_loops_list=opts.test_loops_list,
170171
_muts=MUTs,
172+
_opts_log_file_name=opts.log_file_name,
171173
_test_spec=test_spec,
172174
_opts_goanna_for_mbed_sdk=opts.goanna_for_mbed_sdk,
173175
_opts_goanna_for_tests=opts.goanna_for_tests,
@@ -184,8 +186,9 @@ def get_version():
184186
_opts_suppress_summary=opts.suppress_summary,
185187
_opts_test_x_toolchain_summary=opts.test_x_toolchain_summary,
186188
_opts_copy_method=opts.copy_method,
187-
_opts_mut_reset_type=opts.mut_reset_type
188-
)
189+
_opts_mut_reset_type=opts.mut_reset_type,
190+
_opts_jobs=opts.jobs,
191+
_opts_extend_test_timeout=opts.extend_test_timeout)
189192

190193
# Runs test suite in CLI mode
191194
singletest_in_cli_mode(single_test)

0 commit comments

Comments
 (0)