@@ -36,13 +36,15 @@ def serial_ports():
3636 return ports
3737
3838
39- def usbdev ():
40- port = next (iter (serial_ports ()), None )
39+ def default_serial_port ():
40+ return next (iter (serial_ports ()), None )
4141
42- if port is None :
42+
43+ def usbdev (uart ):
44+ if uart is None :
4345 raise DeviceError ("No available usb device" )
4446
45- dev = serial .Serial (port , 38400 )
47+ dev = serial .Serial (uart , 38400 )
4648 return dev
4749
4850
@@ -118,7 +120,6 @@ class PLATFORM(Enum):
118120
119121
120122class RecursiveNamespace (SimpleNamespace ):
121-
122123 @staticmethod
123124 def map_entry (entry ):
124125 if isinstance (entry , dict ):
@@ -159,6 +160,7 @@ def base_test(
159160 expect_proc ,
160161 actual_proc ,
161162 verbose ,
163+ uart ,
162164):
163165 """
164166 test_type: test, speed, stack, nistkat
@@ -206,7 +208,7 @@ def base_test(
206208 logging .info (f"Check { file } passed" )
207209
208210 if platform_cfg is not None :
209- dev = usbdev ()
211+ dev = usbdev (uart )
210212
211213 for scheme in ["mlkem512" , "mlkem768" , "mlkem1024" ]:
212214 file = f"elf/{ scheme } -{ test_type } .elf"
@@ -246,6 +248,14 @@ _shared_options = [
246248 type = bool ,
247249 help = "Show verbose output or not" ,
248250 ),
251+ click .option (
252+ "-u" ,
253+ "--uart" ,
254+ type = click .Path (),
255+ show_default = True ,
256+ default = default_serial_port (),
257+ help = "TTY serial device for UART, default to the 1st serial device connected to your board or an empty string" ,
258+ ),
249259 click .argument (
250260 "platform" ,
251261 nargs = 1 ,
@@ -269,9 +279,9 @@ def add_options(options):
269279 type = click .Path (),
270280 help = "The binary hex file that you wanted to test." ,
271281)
272- def run (platform , bin , verbose ):
282+ def run (platform , bin , verbose , uart ):
273283 config_logger (True )
274- dev = usbdev ()
284+ dev = usbdev (uart )
275285
276286 try :
277287 result = asyncio .run (
@@ -289,7 +299,7 @@ def run(platform, bin, verbose):
289299)
290300@add_options (_shared_options )
291301@click .option ("-i" , "--iterations" , default = 1 , type = int , help = "Number of tests" )
292- def func (platform , iterations , verbose ):
302+ def func (platform , iterations , verbose , uart ):
293303 try :
294304 base_test (
295305 TEST_TYPE .TEST ,
@@ -298,6 +308,7 @@ def func(platform, iterations, verbose):
298308 lambda _ : iterations * 3 ,
299309 lambda output : count (output , "OK" ),
300310 verbose ,
311+ uart ,
301312 )
302313 except asyncio .CancelledError :
303314 pass
@@ -306,7 +317,7 @@ def func(platform, iterations, verbose):
306317@click .command (short_help = "Run speed tests" , context_settings = {"show_default" : True })
307318@add_options (_shared_options )
308319@click .option ("-i" , "--iterations" , default = 1 , type = int , help = "Number of tests" )
309- def speed (platform , iterations , verbose ):
320+ def speed (platform , iterations , verbose , uart ):
310321 try :
311322 base_test (
312323 TEST_TYPE .SPEED ,
@@ -315,14 +326,15 @@ def speed(platform, iterations, verbose):
315326 lambda _ : 1 ,
316327 lambda output : count (output , "OK" ),
317328 verbose ,
329+ uart ,
318330 )
319331 except asyncio .CancelledError :
320332 pass
321333
322334
323335@click .command (short_help = "Run stack tests" , context_settings = {"show_default" : True })
324336@add_options (_shared_options )
325- def stack (platform , verbose ):
337+ def stack (platform , verbose , uart ):
326338 try :
327339 base_test (
328340 TEST_TYPE .STACK ,
@@ -331,14 +343,15 @@ def stack(platform, verbose):
331343 lambda _ : 1 ,
332344 lambda output : count (output , "OK" ),
333345 verbose ,
346+ uart ,
334347 )
335348 except asyncio .CancelledError :
336349 pass
337350
338351
339352@click .command (short_help = "Run nistkat tests" , context_settings = {"show_default" : True })
340353@add_options (_shared_options )
341- def nistkat (platform , verbose ):
354+ def nistkat (platform , verbose , uart ):
342355 def scheme_hash (scheme ):
343356 result = subprocess .run (
344357 [
@@ -364,6 +377,7 @@ def nistkat(platform, verbose):
364377 scheme_hash ,
365378 lambda output : str (output , encoding = "utf-8" ).strip ().lower (),
366379 verbose ,
380+ uart ,
367381 )
368382 except asyncio .CancelledError :
369383 pass
0 commit comments