xref: /aosp_15_r20/external/pigweed/targets/stm32f429i_disc1/py/stm32f429i_disc1_utils/unit_test_client.py (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1#!/usr/bin/env python3
2# Copyright 2019 The Pigweed Authors
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may not
5# use this file except in compliance with the License. You may obtain a copy of
6# the License at
7#
8#     https://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations under
14# the License.
15"""Launch a pw_target_runner client that sends a test request."""
16
17import argparse
18import subprocess
19import sys
20
21_TARGET_CLIENT_COMMAND = 'pw_target_runner_client'
22
23
24def parse_args():
25    """Parses command-line arguments."""
26
27    parser = argparse.ArgumentParser(description=__doc__)
28    parser.add_argument('binary', help='The target test binary to run')
29    parser.add_argument(
30        '--server-port', type=int, help='Port the test server is located on'
31    )
32
33    return parser.parse_args()
34
35
36def launch_client(binary: str, server_port: int | None) -> int:
37    """Sends a test request to the specified server port."""
38    cmd = [_TARGET_CLIENT_COMMAND, '-binary', binary]
39
40    if server_port is not None:
41        cmd.extend(['-port', str(server_port)])
42
43    return subprocess.call(cmd)
44
45
46def main() -> int:
47    """Launch a test by sending a request to a pw_target_runner_server."""
48    args = parse_args()
49    return launch_client(args.binary, args.server_port)
50
51
52if __name__ == '__main__':
53    sys.exit(main())
54