@@ -62,6 +62,11 @@ def _parse_args():
62
62
"--flash_image" ,
63
63
help = "a firmware image which will be flashed berfore runnning the test" ,
64
64
)
65
+ parser .add_argument (
66
+ "-y" ,
67
+ "--flash_directory" ,
68
+ help = "A directory containing image files, each of which will be flashed and then run." ,
69
+ )
65
70
parser .add_argument (
66
71
"-o" ,
67
72
"--output" ,
@@ -96,22 +101,41 @@ def get_hdlc_rpc_client(device: str, baudrate: int, output: Any, **kwargs):
96
101
)
97
102
98
103
99
- def runner (client : rpc .HdlcRpcClient ) -> int :
100
- """Run the tests"""
104
+ def run (args ) -> int :
105
+ """Run the tests. Return the number of failed tests."""
106
+ with get_hdlc_rpc_client (** vars (args )) as client :
107
+ test_records = run_tests (client .rpcs ())
108
+ return len (test_records .failing_tests )
101
109
102
- test_records = run_tests (client .rpcs ())
103
110
104
- return len (test_records .failing_tests )
111
+ def list_images (flash_directory : str , ** kwargs ) -> list [str ]:
112
+ filenames : list [str ] = os .listdir (flash_directory )
113
+ # filenames = filter(lambda x: not x.endswith('.map'), filenames)
114
+ return list (map (lambda x : os .path .join (flash_directory , x ), filenames ))
105
115
106
116
107
117
def main () -> int :
108
118
args = _parse_args ()
109
- if args .flash_image :
110
- flash_device (** vars (args ))
111
- time .sleep (1 ) # Give time for device to boot
112
119
113
- with get_hdlc_rpc_client (** vars (args )) as client :
114
- return runner (client )
120
+ images : list [str ] = None
121
+ if args .flash_directory :
122
+ images = list_images (** vars (args ))
123
+ if not images :
124
+ raise Exception (f"No images found in `{ args .flash_directory } `" )
125
+ elif args .flash_image :
126
+ images = [args .flash_image ]
127
+
128
+ failures : int = 0
129
+ if images :
130
+ for image in images :
131
+ flash_device (args .device , image )
132
+ time .sleep (1 ) # Give time for device to boot
133
+
134
+ failures += run (args )
135
+ else : # No image provided. Just run.
136
+ failures += run (args )
137
+
138
+ return failures
115
139
116
140
117
141
if __name__ == "__main__" :
0 commit comments