Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 1 | .. _chapter-target-runner: |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 2 | |
| 3 | .. default-domain:: cpp |
| 4 | |
| 5 | .. highlight:: sh |
| 6 | |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 7 | ---------------- |
| 8 | pw_target_runner |
| 9 | ---------------- |
| 10 | The target runner module implements a gRPC server designed to run executables |
| 11 | in parallel. These executables may be run directly on the host, or flashed to |
| 12 | one or more attached targets. |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 13 | |
| 14 | Overview |
| 15 | -------- |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 16 | The target runner server is responsible for processing requests to distribute |
| 17 | executables among a pool of workers that run in parallel. This allows things |
| 18 | like unit tests to be run across multiple devices simultaneously, greatly |
| 19 | reducing the overall time it takes to run a collection of tests. |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 20 | |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 21 | Additionally, the server allows many executables to be queued up at once and |
| 22 | scheduled across available devices, making it possible to automatically run unit |
| 23 | tests from a Ninja build after code is updated. This integrates nicely with the |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 24 | ``pw watch`` command to re-run all affected unit tests after modifying code. |
| 25 | |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 26 | The target runner is implemented as a library in various programming languages. |
| 27 | This library provides the core gRPC server and a mechanism through which worker |
| 28 | routines can be registered. Code using the library instantiates a server with |
| 29 | some custom workers for the desired target to run passed executables. |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 30 | |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 31 | The pw_target_runner module also provides a standalone |
| 32 | ``pw_target_runner_server`` program which runs the server with configurable |
| 33 | workers that launch external processes to execute passed binaries. This |
| 34 | program should be sufficient to quickly get unit tests running in a simple |
| 35 | setup, such as multiple devices plugged into a development machine. |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 36 | |
| 37 | Standalone executable |
| 38 | --------------------- |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 39 | This section describes how to use the ``pw_target_runner_server`` program to |
| 40 | set up a simple unit test server with workers. |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 41 | |
| 42 | Configuration |
| 43 | ^^^^^^^^^^^^^ |
| 44 | The standalone server is configured from a file written in Protobuf text format |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 45 | containing a ``pw.target_runner.ServerConfig`` message as defined in |
| 46 | ``//pw_target_runner/pw_target_runner_protos/exec_server_config.proto``. |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 47 | |
| 48 | At least one ``worker`` message must be specified. Each of the workers refers to |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 49 | a script or program which is invoked with the path to an executable file as a |
| 50 | positional argument. Other arguments provided to the program must be options/ |
| 51 | switches. |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 52 | |
| 53 | For example, the config file below defines two workers, each connecting to an |
| 54 | STM32F429I 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 | |
| 77 | Running the server |
| 78 | ^^^^^^^^^^^^^^^^^^ |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 79 | To start the standalone server, run the ``pw_target_runner_server`` program and |
| 80 | point it to your config file. |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 81 | |
| 82 | .. code:: text |
| 83 | |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 84 | $ pw_target_runner_server -config server_config.txt -port 8080 |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 85 | |
| 86 | |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 87 | Sending requests |
| 88 | ^^^^^^^^^^^^^^^^ |
| 89 | To request the server to run an executable, run the ``pw_target_runner_client``, |
| 90 | specifying the path to the executable through a ``-binary`` option. |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 91 | |
| 92 | .. code:: text |
| 93 | |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 94 | $ pw_target_runner_client -host localhost -port 8080 -binary /path/to/my/test.elf |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 95 | |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 96 | This command blocks until the executable has finished running. Multiple |
| 97 | requests can be scheduled in parallel; the server will distribute them among its |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 98 | available workers. |
| 99 | |
| 100 | Library APIs |
| 101 | ------------ |
Armando Montanez | c0ad978 | 2019-12-30 14:58:00 -0800 | [diff] [blame] | 102 | To use the target runner library in your own code, refer to one of its |
| 103 | programming language APIs below. |
Alexei Frolov | d0b2d48 | 2019-12-04 11:06:23 -0800 | [diff] [blame] | 104 | |
| 105 | .. toctree:: |
| 106 | :maxdepth: 1 |
| 107 | |
| 108 | go/docs |