1#!/usr/bin/env python3 2# Copyright 2020 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', 31 type=int, 32 default=8081, 33 help='Port the test server is located on', 34 ) 35 parser.add_argument( 36 'runner_args', 37 nargs=argparse.REMAINDER, 38 help='Arguments to forward to the test runner', 39 ) 40 41 return parser.parse_args() 42 43 44def launch_client(binary: str, server_port: int | None) -> int: 45 """Sends a test request to the specified server port.""" 46 cmd = [_TARGET_CLIENT_COMMAND, '-binary', binary] 47 48 if server_port is not None: 49 cmd.extend(['-port', str(server_port)]) 50 51 return subprocess.call(cmd) 52 53 54def main() -> int: 55 """Launch a test by sending a request to a pw_target_runner_server.""" 56 args = parse_args() 57 return launch_client(args.binary, args.server_port) 58 59 60if __name__ == '__main__': 61 sys.exit(main()) 62