1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_target_runner: 2*61c4878aSAndroid Build Coastguard Worker 3*61c4878aSAndroid Build Coastguard Worker---------------- 4*61c4878aSAndroid Build Coastguard Workerpw_target_runner 5*61c4878aSAndroid Build Coastguard Worker---------------- 6*61c4878aSAndroid Build Coastguard Worker.. pigweed-module:: 7*61c4878aSAndroid Build Coastguard Worker :name: pw_target_runner 8*61c4878aSAndroid Build Coastguard Worker 9*61c4878aSAndroid Build Coastguard WorkerThe target runner module implements a gRPC server designed to run executables 10*61c4878aSAndroid Build Coastguard Workerin parallel. These executables may be run directly on the host, or flashed to 11*61c4878aSAndroid Build Coastguard Workerone or more attached targets. 12*61c4878aSAndroid Build Coastguard Worker 13*61c4878aSAndroid Build Coastguard WorkerOverview 14*61c4878aSAndroid Build Coastguard Worker-------- 15*61c4878aSAndroid Build Coastguard WorkerThe target runner server is responsible for processing requests to distribute 16*61c4878aSAndroid Build Coastguard Workerexecutables among a pool of workers that run in parallel. This allows things 17*61c4878aSAndroid Build Coastguard Workerlike unit tests to be run across multiple devices simultaneously, greatly 18*61c4878aSAndroid Build Coastguard Workerreducing the overall time it takes to run a collection of tests. 19*61c4878aSAndroid Build Coastguard Worker 20*61c4878aSAndroid Build Coastguard WorkerAdditionally, the server allows many executables to be queued up at once and 21*61c4878aSAndroid Build Coastguard Workerscheduled across available devices, making it possible to automatically run unit 22*61c4878aSAndroid Build Coastguard Workertests from a Ninja build after code is updated. This integrates nicely with the 23*61c4878aSAndroid Build Coastguard Worker``pw watch`` command to re-run all affected unit tests after modifying code. 24*61c4878aSAndroid Build Coastguard Worker 25*61c4878aSAndroid Build Coastguard WorkerThe target runner is implemented as a library in various programming languages. 26*61c4878aSAndroid Build Coastguard WorkerThis library provides the core gRPC server and a mechanism through which worker 27*61c4878aSAndroid Build Coastguard Workerroutines can be registered. Code using the library instantiates a server with 28*61c4878aSAndroid Build Coastguard Workersome custom workers for the desired target to run passed executables. 29*61c4878aSAndroid Build Coastguard Worker 30*61c4878aSAndroid Build Coastguard WorkerThe ``pw_target_runner`` module also provides a standalone 31*61c4878aSAndroid Build Coastguard Worker``pw_target_runner_server`` program which runs the server with configurable 32*61c4878aSAndroid Build Coastguard Workerworkers that launch external processes to execute passed binaries. This 33*61c4878aSAndroid Build Coastguard Workerprogram should be sufficient to quickly get unit tests running in a simple 34*61c4878aSAndroid Build Coastguard Workersetup, such as multiple devices plugged into a development machine. 35*61c4878aSAndroid Build Coastguard Worker 36*61c4878aSAndroid Build Coastguard WorkerStandalone executable 37*61c4878aSAndroid Build Coastguard Worker--------------------- 38*61c4878aSAndroid Build Coastguard WorkerThis section describes how to use the ``pw_target_runner_server`` program to 39*61c4878aSAndroid Build Coastguard Workerset up a simple unit test server with workers. 40*61c4878aSAndroid Build Coastguard Worker 41*61c4878aSAndroid Build Coastguard WorkerConfiguration 42*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^ 43*61c4878aSAndroid Build Coastguard WorkerThe standalone server is configured from a file written in Protobuf text format 44*61c4878aSAndroid Build Coastguard Workercontaining a ``pw.target_runner.ServerConfig`` message as defined in 45*61c4878aSAndroid Build Coastguard Worker``//pw_target_runner/pw_target_runner_server_protos/exec_server_config.proto``. 46*61c4878aSAndroid Build Coastguard Worker 47*61c4878aSAndroid Build Coastguard WorkerAt least one ``worker`` message must be specified. Each of the workers refers to 48*61c4878aSAndroid Build Coastguard Workera script or program which is invoked with the path to an executable file as a 49*61c4878aSAndroid Build Coastguard Workerpositional argument. Other arguments provided to the program must be options/ 50*61c4878aSAndroid Build Coastguard Workerswitches. 51*61c4878aSAndroid Build Coastguard Worker 52*61c4878aSAndroid Build Coastguard WorkerFor example, the config file below defines two workers, each connecting to an 53*61c4878aSAndroid Build Coastguard WorkerSTM32F429I Discovery board with a specified serial number. 54*61c4878aSAndroid Build Coastguard Worker 55*61c4878aSAndroid Build Coastguard Worker**server_config.txt** 56*61c4878aSAndroid Build Coastguard Worker 57*61c4878aSAndroid Build Coastguard Worker.. code-block:: text 58*61c4878aSAndroid Build Coastguard Worker 59*61c4878aSAndroid Build Coastguard Worker runner { 60*61c4878aSAndroid Build Coastguard Worker command: "stm32f429i_disc1_unit_test_runner" 61*61c4878aSAndroid Build Coastguard Worker args: "--openocd-config" 62*61c4878aSAndroid Build Coastguard Worker args: "targets/stm32f429i_disc1/py/stm32f429i_disc1_utils/openocd_stm32f4xx.cfg" 63*61c4878aSAndroid Build Coastguard Worker args: "--serial" 64*61c4878aSAndroid Build Coastguard Worker args: "066DFF575051717867013127" 65*61c4878aSAndroid Build Coastguard Worker } 66*61c4878aSAndroid Build Coastguard Worker 67*61c4878aSAndroid Build Coastguard Worker runner { 68*61c4878aSAndroid Build Coastguard Worker command: "stm32f429i_disc1_unit_test_runner" 69*61c4878aSAndroid Build Coastguard Worker args: "--openocd-config" 70*61c4878aSAndroid Build Coastguard Worker args: "targets/stm32f429i_disc1/py/stm32f429i_disc1_utils/openocd_stm32f4xx.cfg" 71*61c4878aSAndroid Build Coastguard Worker args: "--serial" 72*61c4878aSAndroid Build Coastguard Worker args: "0667FF494849887767196023" 73*61c4878aSAndroid Build Coastguard Worker } 74*61c4878aSAndroid Build Coastguard Worker 75*61c4878aSAndroid Build Coastguard Worker 76*61c4878aSAndroid Build Coastguard WorkerRunning the server 77*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^ 78*61c4878aSAndroid Build Coastguard WorkerTo start the standalone server, run the ``pw_target_runner_server`` program and 79*61c4878aSAndroid Build Coastguard Workerpoint it to your config file. 80*61c4878aSAndroid Build Coastguard Worker 81*61c4878aSAndroid Build Coastguard Worker.. code-block:: text 82*61c4878aSAndroid Build Coastguard Worker 83*61c4878aSAndroid Build Coastguard Worker $ pw_target_runner_server -config server_config.txt -port 8080 84*61c4878aSAndroid Build Coastguard Worker 85*61c4878aSAndroid Build Coastguard Worker 86*61c4878aSAndroid Build Coastguard WorkerSending requests 87*61c4878aSAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^ 88*61c4878aSAndroid Build Coastguard WorkerTo request the server to run an executable, run the ``pw_target_runner_client``, 89*61c4878aSAndroid Build Coastguard Workerspecifying the path to the executable through a ``-binary`` option. 90*61c4878aSAndroid Build Coastguard Worker 91*61c4878aSAndroid Build Coastguard Worker.. code-block:: text 92*61c4878aSAndroid Build Coastguard Worker 93*61c4878aSAndroid Build Coastguard Worker $ pw_target_runner_client -host localhost -port 8080 -binary /path/to/my/test.elf 94*61c4878aSAndroid Build Coastguard Worker 95*61c4878aSAndroid Build Coastguard WorkerThis command blocks until the executable has finished running. Multiple 96*61c4878aSAndroid Build Coastguard Workerrequests can be scheduled in parallel; the server will distribute them among its 97*61c4878aSAndroid Build Coastguard Workeravailable workers. 98*61c4878aSAndroid Build Coastguard Worker 99*61c4878aSAndroid Build Coastguard WorkerLibrary APIs 100*61c4878aSAndroid Build Coastguard Worker------------ 101*61c4878aSAndroid Build Coastguard WorkerTo use the target runner library in your own code, refer to one of its 102*61c4878aSAndroid Build Coastguard Workerprogramming language APIs below. 103*61c4878aSAndroid Build Coastguard Worker 104*61c4878aSAndroid Build Coastguard Worker.. toctree:: 105*61c4878aSAndroid Build Coastguard Worker :maxdepth: 1 106*61c4878aSAndroid Build Coastguard Worker 107*61c4878aSAndroid Build Coastguard Worker go/docs 108