• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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('--server-port',
31                        type=int,
32                        help='Port the test server is located on')
33
34    return parser.parse_args()
35
36
37def launch_client(binary: str, server_port: Optional[int]) -> int:
38    """Sends a test request to the specified server port."""
39    cmd = [_TARGET_CLIENT_COMMAND, '-binary', binary]
40
41    if server_port is not None:
42        cmd.extend(['-port', str(server_port)])
43
44    return subprocess.call(cmd)
45
46
47def main() -> int:
48    """Launch a test by sending a request to a pw_target_runner_server."""
49    args = parse_args()
50    return launch_client(args.binary, args.server_port)
51
52
53if __name__ == '__main__':
54    sys.exit(main())
55