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 20from typing import Optional 21 22_TARGET_CLIENT_COMMAND = 'pw_target_runner_client' 23 24 25def parse_args(): 26 """Parses command-line arguments.""" 27 28 parser = argparse.ArgumentParser(description=__doc__) 29 parser.add_argument('binary', help='The target test binary to run') 30 parser.add_argument( 31 '--server-port', 32 type=int, 33 default=8081, 34 help='Port the test server is located on', 35 ) 36 parser.add_argument( 37 'runner_args', 38 nargs=argparse.REMAINDER, 39 help='Arguments to forward to the test runner', 40 ) 41 42 return parser.parse_args() 43 44 45def launch_client(binary: str, server_port: Optional[int]) -> int: 46 """Sends a test request to the specified server port.""" 47 cmd = [_TARGET_CLIENT_COMMAND, '-binary', binary] 48 49 if server_port is not None: 50 cmd.extend(['-port', str(server_port)]) 51 52 return subprocess.call(cmd) 53 54 55def main() -> int: 56 """Launch a test by sending a request to a pw_target_runner_server.""" 57 args = parse_args() 58 return launch_client(args.binary, args.server_port) 59 60 61if __name__ == '__main__': 62 sys.exit(main()) 63