Skip to content

Commit 25ebd41

Browse files
committed
Updated test runner to support running all tests in a directory
1 parent a98dc79 commit 25ebd41

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

src/test_driver/efr32/py/pw_test_runner/pw_test_runner.py

+33-9
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def _parse_args():
6262
"--flash_image",
6363
help="a firmware image which will be flashed berfore runnning the test",
6464
)
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+
)
6570
parser.add_argument(
6671
"-o",
6772
"--output",
@@ -96,22 +101,41 @@ def get_hdlc_rpc_client(device: str, baudrate: int, output: Any, **kwargs):
96101
)
97102

98103

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)
101109

102-
test_records = run_tests(client.rpcs())
103110

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))
105115

106116

107117
def main() -> int:
108118
args = _parse_args()
109-
if args.flash_image:
110-
flash_device(**vars(args))
111-
time.sleep(1) # Give time for device to boot
112119

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
115139

116140

117141
if __name__ == "__main__":

0 commit comments

Comments
 (0)