28
28
from sys import stdout
29
29
30
30
class Mbed :
31
- """
32
- Base class for a host driven test
31
+ """ Base class for a host driven test
33
32
"""
34
33
def __init__ (self ):
35
34
parser = OptionParser ()
@@ -83,10 +82,11 @@ def __init__(self):
83
82
self .extra_serial = None
84
83
self .serial = None
85
84
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 )
87
86
88
87
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
+ """
90
90
result = True
91
91
try :
92
92
self .serial = Serial (self .port , timeout = 1 )
@@ -102,15 +102,17 @@ def init_serial(self, baud=9600, extra_baud=9600):
102
102
return result
103
103
104
104
def serial_timeout (self , timeout ):
105
- """ Wraps self.mbed.serial object timeout property """
105
+ """ Wraps self.mbed.serial object timeout property
106
+ """
106
107
result = None
107
108
if self .serial :
108
109
self .serial .timeout = timeout
109
110
result = True
110
111
return result
111
112
112
113
def serial_read (self , count = 1 ):
113
- """ Wraps self.mbed.serial object read method """
114
+ """ Wraps self.mbed.serial object read method
115
+ """
114
116
result = None
115
117
if self .serial :
116
118
try :
@@ -120,7 +122,8 @@ def serial_read(self, count=1):
120
122
return result
121
123
122
124
def serial_write (self , write_buffer ):
123
- """ Wraps self.mbed.serial object write method """
125
+ """ Wraps self.mbed.serial object write method
126
+ """
124
127
result = - 1
125
128
if self .serial :
126
129
try :
@@ -131,12 +134,12 @@ def serial_write(self, write_buffer):
131
134
132
135
def safe_sendBreak (self , serial ):
133
136
""" 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')
140
143
"""
141
144
result = True
142
145
try :
@@ -151,15 +154,22 @@ def safe_sendBreak(self, serial):
151
154
return result
152
155
153
156
def touch_file (self , path ):
157
+ """ Touch file and set timestamp to items
158
+ """
154
159
with open (path , 'a' ):
155
160
os .utime (path , None )
156
161
157
162
def reset_timeout (self , timeout ):
163
+ """ Timeout executed just after reset command is issued
164
+ """
158
165
for n in range (0 , timeout ):
159
166
sleep (1 )
160
167
161
168
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.
163
173
shutdown.txt - shutdown from run mode
164
174
reset.txt - reset FPGA during run mode
165
175
"""
@@ -173,6 +183,8 @@ def reset(self):
173
183
self .reset_timeout (reset_tout_s )
174
184
175
185
def flush (self ):
186
+ """ Flush serial ports
187
+ """
176
188
self .serial .flushInput ()
177
189
self .serial .flushOutput ()
178
190
if self .extra_serial :
@@ -181,10 +193,15 @@ def flush(self):
181
193
182
194
183
195
class Test :
196
+ """ Baseclass for host test's test runner
197
+ """
184
198
def __init__ (self ):
185
199
self .mbed = Mbed ()
186
200
187
201
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
+ """
188
205
try :
189
206
result = self .test ()
190
207
self .print_result ("success" if result else "failure" )
@@ -193,31 +210,40 @@ def run(self):
193
210
self .print_result ("error" )
194
211
195
212
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
+ """
197
215
result = True
198
216
if not self .mbed .serial :
199
217
result = False
200
218
self .print_result ("ioerr_serial" )
201
219
return result
202
220
203
221
def notify (self , message ):
204
- """ On screen notification function """
222
+ """ On screen notification function
223
+ """
205
224
print message
206
225
stdout .flush ()
207
226
208
227
def print_result (self , result ):
209
- """ Test result unified printing function """
228
+ """ Test result unified printing function
229
+ """
210
230
self .notify ("\n {%s}\n {end}" % result )
211
231
212
232
213
233
class DefaultTest (Test ):
234
+ """ Test class with serial port initialization
235
+ """
214
236
def __init__ (self ):
215
237
Test .__init__ (self )
216
238
serial_init_res = self .mbed .init_serial ()
217
239
self .mbed .reset ()
218
240
219
241
220
242
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
+ """
221
247
def run (self ):
222
248
try :
223
249
while True :
@@ -230,5 +256,6 @@ def run(self):
230
256
except KeyboardInterrupt , _ :
231
257
print "\n [CTRL+c] exit"
232
258
259
+
233
260
if __name__ == '__main__' :
234
261
Simple ().run ()
0 commit comments