Skip to content

Commit a5bdd4a

Browse files
committed
More comments added to methods in host_test.py
1 parent 005c3a7 commit a5bdd4a

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

workspace_tools/host_tests/host_test.py

Lines changed: 44 additions & 17 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()
@@ -83,10 +82,11 @@ def __init__(self):
8382
self.extra_serial = None
8483
self.serial = None
8584
self.timeout = self.DEFAULT_TOUT if self.options.timeout is None else self.options.timeout
86-
print 'Mbed: "%s" "%s"' % (self.port, self.disk)
85+
print 'Host test instrumentation on port: "%s" with serial: "%s"' % (self.port, self.disk)
8786

8887
def init_serial(self, baud=9600, extra_baud=9600):
89-
""" Initialize serial port. Function will return error is port can't be opened or initialized """
88+
""" Initialize serial port. Function will return error is port can't be opened or initialized
89+
"""
9090
result = True
9191
try:
9292
self.serial = Serial(self.port, timeout=1)
@@ -102,15 +102,17 @@ def init_serial(self, baud=9600, extra_baud=9600):
102102
return result
103103

104104
def serial_timeout(self, timeout):
105-
""" Wraps self.mbed.serial object timeout property """
105+
""" Wraps self.mbed.serial object timeout property
106+
"""
106107
result = None
107108
if self.serial:
108109
self.serial.timeout = timeout
109110
result = True
110111
return result
111112

112113
def serial_read(self, count=1):
113-
""" Wraps self.mbed.serial object read method """
114+
""" Wraps self.mbed.serial object read method
115+
"""
114116
result = None
115117
if self.serial:
116118
try:
@@ -120,7 +122,8 @@ def serial_read(self, count=1):
120122
return result
121123

122124
def serial_write(self, write_buffer):
123-
""" Wraps self.mbed.serial object write method """
125+
""" Wraps self.mbed.serial object write method
126+
"""
124127
result = -1
125128
if self.serial:
126129
try:
@@ -131,12 +134,12 @@ def serial_write(self, write_buffer):
131134

132135
def safe_sendBreak(self, serial):
133136
""" Wraps serial.sendBreak() to avoid serial::serialposix.py exception on Linux
134-
Traceback (most recent call last):
135-
File "make.py", line 189, in <module>
136-
serial.sendBreak()
137-
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 511, in sendBreak
138-
termios.tcsendbreak(self.fd, int(duration/0.25))
139-
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')
140143
"""
141144
result = True
142145
try:
@@ -151,15 +154,22 @@ def safe_sendBreak(self, serial):
151154
return result
152155

153156
def touch_file(self, path):
157+
""" Touch file and set timestamp to items
158+
"""
154159
with open(path, 'a'):
155160
os.utime(path, None)
156161

157162
def reset_timeout(self, timeout):
163+
""" Timeout executed just after reset command is issued
164+
"""
158165
for n in range(0, timeout):
159166
sleep(1)
160167

161168
def reset(self):
162-
""" 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.
163173
shutdown.txt - shutdown from run mode
164174
reset.txt - reset FPGA during run mode
165175
"""
@@ -173,6 +183,8 @@ def reset(self):
173183
self.reset_timeout(reset_tout_s)
174184

175185
def flush(self):
186+
""" Flush serial ports
187+
"""
176188
self.serial.flushInput()
177189
self.serial.flushOutput()
178190
if self.extra_serial:
@@ -181,10 +193,15 @@ def flush(self):
181193

182194

183195
class Test:
196+
""" Baseclass for host test's test runner
197+
"""
184198
def __init__(self):
185199
self.mbed = Mbed()
186200

187201
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+
"""
188205
try:
189206
result = self.test()
190207
self.print_result("success" if result else "failure")
@@ -193,31 +210,40 @@ def run(self):
193210
self.print_result("error")
194211

195212
def setup(self):
196-
""" 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+
"""
197215
result = True
198216
if not self.mbed.serial:
199217
result = False
200218
self.print_result("ioerr_serial")
201219
return result
202220

203221
def notify(self, message):
204-
""" On screen notification function """
222+
""" On screen notification function
223+
"""
205224
print message
206225
stdout.flush()
207226

208227
def print_result(self, result):
209-
""" Test result unified printing function """
228+
""" Test result unified printing function
229+
"""
210230
self.notify("\n{%s}\n{end}" % result)
211231

212232

213233
class DefaultTest(Test):
234+
""" Test class with serial port initialization
235+
"""
214236
def __init__(self):
215237
Test.__init__(self)
216238
serial_init_res = self.mbed.init_serial()
217239
self.mbed.reset()
218240

219241

220242
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+
"""
221247
def run(self):
222248
try:
223249
while True:
@@ -230,5 +256,6 @@ def run(self):
230256
except KeyboardInterrupt, _:
231257
print "\n[CTRL+c] exit"
232258

259+
233260
if __name__ == '__main__':
234261
Simple().run()

0 commit comments

Comments
 (0)