blob: 25b210dac1cab1109e3239b20c146e9a23b9cf73 [file] [log] [blame]
Wyatt Heplerf9fb90f2020-09-30 18:59:33 -07001.. _module-pw_target_runner:
Alexei Frolov199045a2020-08-28 13:02:30 -07002
Armando Montanezc0ad9782019-12-30 14:58:00 -08003----------------
4pw_target_runner
5----------------
6The target runner module implements a gRPC server designed to run executables
7in parallel. These executables may be run directly on the host, or flashed to
8one or more attached targets.
Alexei Frolovd0b2d482019-12-04 11:06:23 -08009
10Overview
11--------
Armando Montanezc0ad9782019-12-30 14:58:00 -080012The target runner server is responsible for processing requests to distribute
13executables among a pool of workers that run in parallel. This allows things
14like unit tests to be run across multiple devices simultaneously, greatly
15reducing the overall time it takes to run a collection of tests.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080016
Armando Montanezc0ad9782019-12-30 14:58:00 -080017Additionally, the server allows many executables to be queued up at once and
18scheduled across available devices, making it possible to automatically run unit
19tests from a Ninja build after code is updated. This integrates nicely with the
Alexei Frolovd0b2d482019-12-04 11:06:23 -080020``pw watch`` command to re-run all affected unit tests after modifying code.
21
Armando Montanezc0ad9782019-12-30 14:58:00 -080022The target runner is implemented as a library in various programming languages.
23This library provides the core gRPC server and a mechanism through which worker
24routines can be registered. Code using the library instantiates a server with
25some custom workers for the desired target to run passed executables.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080026
Armando Montanez0054a9b2020-03-13 13:06:24 -070027The ``pw_target_runner`` module also provides a standalone
Armando Montanezc0ad9782019-12-30 14:58:00 -080028``pw_target_runner_server`` program which runs the server with configurable
29workers that launch external processes to execute passed binaries. This
30program should be sufficient to quickly get unit tests running in a simple
31setup, such as multiple devices plugged into a development machine.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080032
33Standalone executable
34---------------------
Armando Montanezc0ad9782019-12-30 14:58:00 -080035This section describes how to use the ``pw_target_runner_server`` program to
36set up a simple unit test server with workers.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080037
38Configuration
39^^^^^^^^^^^^^
40The standalone server is configured from a file written in Protobuf text format
Armando Montanezc0ad9782019-12-30 14:58:00 -080041containing a ``pw.target_runner.ServerConfig`` message as defined in
Wyatt Hepler91741472021-02-03 08:45:10 -080042``//pw_target_runner/pw_target_runner_server_protos/exec_server_config.proto``.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080043
44At least one ``worker`` message must be specified. Each of the workers refers to
Armando Montanezc0ad9782019-12-30 14:58:00 -080045a script or program which is invoked with the path to an executable file as a
46positional argument. Other arguments provided to the program must be options/
47switches.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080048
49For example, the config file below defines two workers, each connecting to an
50STM32F429I Discovery board with a specified serial number.
51
52**server_config.txt**
53
54.. code:: text
55
56 runner {
57 command: "stm32f429i_disc1_unit_test_runner"
58 args: "--openocd-config"
Rob Mohr3d61b322021-05-17 10:52:24 -070059 args: "targets/stm32f429i_disc1/py/stm32f429i_disc1_utils/openocd_stm32f4xx.cfg"
Alexei Frolovd0b2d482019-12-04 11:06:23 -080060 args: "--serial"
61 args: "066DFF575051717867013127"
62 }
63
64 runner {
65 command: "stm32f429i_disc1_unit_test_runner"
66 args: "--openocd-config"
Rob Mohr3d61b322021-05-17 10:52:24 -070067 args: "targets/stm32f429i_disc1/py/stm32f429i_disc1_utils/openocd_stm32f4xx.cfg"
Alexei Frolovd0b2d482019-12-04 11:06:23 -080068 args: "--serial"
69 args: "0667FF494849887767196023"
70 }
71
72
73Running the server
74^^^^^^^^^^^^^^^^^^
Armando Montanezc0ad9782019-12-30 14:58:00 -080075To start the standalone server, run the ``pw_target_runner_server`` program and
76point it to your config file.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080077
78.. code:: text
79
Armando Montanezc0ad9782019-12-30 14:58:00 -080080 $ pw_target_runner_server -config server_config.txt -port 8080
Alexei Frolovd0b2d482019-12-04 11:06:23 -080081
82
Armando Montanezc0ad9782019-12-30 14:58:00 -080083Sending requests
84^^^^^^^^^^^^^^^^
85To request the server to run an executable, run the ``pw_target_runner_client``,
86specifying the path to the executable through a ``-binary`` option.
Alexei Frolovd0b2d482019-12-04 11:06:23 -080087
88.. code:: text
89
Armando Montanezc0ad9782019-12-30 14:58:00 -080090 $ pw_target_runner_client -host localhost -port 8080 -binary /path/to/my/test.elf
Alexei Frolovd0b2d482019-12-04 11:06:23 -080091
Armando Montanezc0ad9782019-12-30 14:58:00 -080092This command blocks until the executable has finished running. Multiple
93requests can be scheduled in parallel; the server will distribute them among its
Alexei Frolovd0b2d482019-12-04 11:06:23 -080094available workers.
95
96Library APIs
97------------
Armando Montanezc0ad9782019-12-30 14:58:00 -080098To use the target runner library in your own code, refer to one of its
99programming language APIs below.
Alexei Frolovd0b2d482019-12-04 11:06:23 -0800100
101.. toctree::
102 :maxdepth: 1
103
104 go/docs