1#!/usr/bin/env python3 2# Copyright 2023 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 21try: 22 from rp2040_utils import unit_test_server 23except ImportError: 24 # Load from this directory if rp2040_utils is not available. 25 import unit_test_server # type: ignore 26 27_TARGET_CLIENT_COMMAND = 'pw_target_runner_client' 28 29 30def parse_args(): 31 """Parses command-line arguments.""" 32 33 parser = argparse.ArgumentParser(description=__doc__) 34 parser.add_argument('binary', help='The target test binary to run') 35 parser.add_argument( 36 '--server-port', 37 type=int, 38 default=unit_test_server.DEFAULT_PORT, 39 help='Port the test server is located on', 40 ) 41 42 return parser.parse_args() 43 44 45def launch_client(binary: str, server_port: int) -> int: 46 """Sends a test request to the specified server port.""" 47 cmd = (_TARGET_CLIENT_COMMAND, '-binary', binary, '-port', str(server_port)) 48 return subprocess.call(cmd) 49 50 51def main() -> int: 52 """Launch a test by sending a request to a pw_target_runner_server.""" 53 args = parse_args() 54 return launch_client(args.binary, args.server_port) 55 56 57if __name__ == '__main__': 58 sys.exit(main()) 59