blob: 2fc87d6283b3136e8be1d09a5327157779bbd55b [file] [log] [blame]
Armando Montanezc0ad9782019-12-30 14:58:00 -08001.. _chapter-target-runner:
Alexei Frolovd0b2d482019-12-04 11:06:23 -08002
3.. default-domain:: cpp
4
5.. highlight:: sh
6
Armando Montanezc0ad9782019-12-30 14:58:00 -08007----------------
8pw_target_runner
9----------------
10The target runner module implements a gRPC server designed to run executables
11in parallel. These executables may be run directly on the host, or flashed to
12one or more attached targets.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080013
14Overview
15--------
Armando Montanezc0ad9782019-12-30 14:58:00 -080016The target runner server is responsible for processing requests to distribute
17executables among a pool of workers that run in parallel. This allows things
18like unit tests to be run across multiple devices simultaneously, greatly
19reducing the overall time it takes to run a collection of tests.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080020
Armando Montanezc0ad9782019-12-30 14:58:00 -080021Additionally, the server allows many executables to be queued up at once and
22scheduled across available devices, making it possible to automatically run unit
23tests from a Ninja build after code is updated. This integrates nicely with the
Alexei Frolovd0b2d482019-12-04 11:06:23 -080024``pw watch`` command to re-run all affected unit tests after modifying code.
25
Armando Montanezc0ad9782019-12-30 14:58:00 -080026The target runner is implemented as a library in various programming languages.
27This library provides the core gRPC server and a mechanism through which worker
28routines can be registered. Code using the library instantiates a server with
29some custom workers for the desired target to run passed executables.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080030
Armando Montanezc0ad9782019-12-30 14:58:00 -080031The pw_target_runner module also provides a standalone
32``pw_target_runner_server`` program which runs the server with configurable
33workers that launch external processes to execute passed binaries. This
34program should be sufficient to quickly get unit tests running in a simple
35setup, such as multiple devices plugged into a development machine.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080036
37Standalone executable
38---------------------
Armando Montanezc0ad9782019-12-30 14:58:00 -080039This section describes how to use the ``pw_target_runner_server`` program to
40set up a simple unit test server with workers.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080041
42Configuration
43^^^^^^^^^^^^^
44The standalone server is configured from a file written in Protobuf text format
Armando Montanezc0ad9782019-12-30 14:58:00 -080045containing a ``pw.target_runner.ServerConfig`` message as defined in
46``//pw_target_runner/pw_target_runner_protos/exec_server_config.proto``.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080047
48At least one ``worker`` message must be specified. Each of the workers refers to
Armando Montanezc0ad9782019-12-30 14:58:00 -080049a script or program which is invoked with the path to an executable file as a
50positional argument. Other arguments provided to the program must be options/
51switches.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080052
53For example, the config file below defines two workers, each connecting to an
54STM32F429I Discovery board with a specified serial number.
55
56**server_config.txt**
57
58.. code:: text
59
60 runner {
61 command: "stm32f429i_disc1_unit_test_runner"
62 args: "--openocd-config"
63 args: "targets/stm32f429i-disc1/py/stm32f429i_disc1_utils/openocd_stm32f4xx.cfg"
64 args: "--serial"
65 args: "066DFF575051717867013127"
66 }
67
68 runner {
69 command: "stm32f429i_disc1_unit_test_runner"
70 args: "--openocd-config"
71 args: "targets/stm32f429i-disc1/py/stm32f429i_disc1_utils/openocd_stm32f4xx.cfg"
72 args: "--serial"
73 args: "0667FF494849887767196023"
74 }
75
76
77Running the server
78^^^^^^^^^^^^^^^^^^
Armando Montanezc0ad9782019-12-30 14:58:00 -080079To start the standalone server, run the ``pw_target_runner_server`` program and
80point it to your config file.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080081
82.. code:: text
83
Armando Montanezc0ad9782019-12-30 14:58:00 -080084 $ pw_target_runner_server -config server_config.txt -port 8080
Alexei Frolovd0b2d482019-12-04 11:06:23 -080085
86
Armando Montanezc0ad9782019-12-30 14:58:00 -080087Sending requests
88^^^^^^^^^^^^^^^^
89To request the server to run an executable, run the ``pw_target_runner_client``,
90specifying the path to the executable through a ``-binary`` option.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080091
92.. code:: text
93
Armando Montanezc0ad9782019-12-30 14:58:00 -080094 $ pw_target_runner_client -host localhost -port 8080 -binary /path/to/my/test.elf
Alexei Frolovd0b2d482019-12-04 11:06:23 -080095
Armando Montanezc0ad9782019-12-30 14:58:00 -080096This command blocks until the executable has finished running. Multiple
97requests can be scheduled in parallel; the server will distribute them among its
Alexei Frolovd0b2d482019-12-04 11:06:23 -080098available workers.
99
100Library APIs
101------------
Armando Montanezc0ad9782019-12-30 14:58:00 -0800102To use the target runner library in your own code, refer to one of its
103programming language APIs below.
Alexei Frolovd0b2d482019-12-04 11:06:23 -0800104
105.. toctree::
106 :maxdepth: 1
107
108 go/docs