2121 "bodvoltage=1v9,bodmode=disabled,eesave=enable,resetpin=reset," \
2222 "millis=tcb2,startuptime=8,wiremode=mors2,printf=full"
2323
24- TIMEOUT = 10
24+ TIMEOUT = 30
2525
2626
2727def retrieve_examples (examples_directory ):
@@ -85,17 +85,25 @@ def test(example, test_data, serial_handle):
8585 expectation = entry .get ("expectation" , None )
8686 command = entry .get ("command" , None )
8787 repeat = entry .get ("repeat" , 1 )
88+ timeout = entry .get ("timeout" , TIMEOUT )
8889
89- for _ in range (0 , repeat ):
90+ if not expectation :
91+ return (False , f"No expeted value defined for entry: { entry } " )
92+
93+ for i in range (0 , repeat ):
9094 if command != None :
9195 command_stripped = command .strip ("\r " )
9296 logging .info (f"\t Testing command: { command_stripped } " )
9397
9498 serial_handle .write (str .encode (command ))
9599 serial_handle .flush ()
96100
97- # Read until line feed
98- output = serial_handle .read_until ().decode ("utf-8" )
101+ # Read until line feed or timeout
102+ start = time .time ()
103+ output = ""
104+
105+ while time .time () - start < timeout and output == "" :
106+ output = serial_handle .read_until ().decode ("utf-8" )
99107
100108 response = re .search (expectation , output )
101109
@@ -148,9 +156,15 @@ def test(example, test_data, serial_handle):
148156 default = "tests.json" )
149157
150158 parser .add_argument ("-e" ,
151- "--examplesdir" ,
159+ "--examples" ,
160+ type = str ,
161+ help = "Examples to test (all or some specific example, e.g. sandbox)" ,
162+ default = "all" )
163+
164+ parser .add_argument ("-s" ,
165+ "--sketchdir" ,
152166 type = str ,
153- help = "Relative path to the example directory" ,
167+ help = "Relative path to the example directory with the example sketches " ,
154168 default = "../examples" )
155169
156170 parser .add_argument ("-b" ,
@@ -182,7 +196,7 @@ def test(example, test_data, serial_handle):
182196 for name in files :
183197 os .remove (os .path .join (root , name ))
184198
185- examples = retrieve_examples (arguments .examplesdir )
199+ examples = retrieve_examples (arguments .sketchdir )
186200
187201 test_config = {}
188202
@@ -195,6 +209,9 @@ def test(example, test_data, serial_handle):
195209
196210 example_name = os .path .splitext (os .path .basename (example ))[0 ]
197211
212+ if example_name != arguments .examples and arguments .examples != "all" :
213+ continue
214+
198215 if not example_name in test_config :
199216 examples_test_status [example_name ] = {"status" : "No test defined" , "error" : None }
200217 continue
@@ -218,7 +235,7 @@ def test(example, test_data, serial_handle):
218235 if not error :
219236 examples_test_status [example_name ] = {"status" : "Passed" , "error" : None }
220237 else :
221- examples_test_status [example_name ] = {"status" : "Passed " , "error" : error }
238+ examples_test_status [example_name ] = {"status" : "Not passed " , "error" : error }
222239
223240 except serial .SerialException as exception :
224241 logging .error (f"Got exception while opening serial port: { exception } " )
@@ -228,6 +245,8 @@ def test(example, test_data, serial_handle):
228245
229246 backend .disconnect_from_tool ()
230247
248+ all_tests_passed = True
249+
231250 print ("--------------- Test status ---------------" )
232251 for example_name , entry in examples_test_status .items ():
233252 status = entry ["status" ]
@@ -237,5 +256,9 @@ def test(example, test_data, serial_handle):
237256 print (f"{ example_name :<30} : { status } " )
238257 else :
239258 print (f"{ example_name :<30} : { status } - { error } " )
259+ all_tests_passed = False
240260
241- exit (0 )
261+ if all_tests_passed :
262+ exit (0 )
263+ else :
264+ exit (1 )
0 commit comments