Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Test an image

How-to · Level 2: Building real applications

An image becomes a test once it states what its console must show. nros test builds every such image that runs on this machine, runs it, and checks its console, then says which tests failed.

Make an image a test

Add an [image.<id>.test] table to the image in the bringup’s system.toml:

[image.linux]
board = "linux"

[image.linux.test]
expect = ["Publishing:"]
timeout = 30

Its keys are nros run’s grading flags: expect, expect_regex, forbid, forbid_regex, settle and timeout. One more, exit, is the exit code the target must end with. system.toml keys lists what each one means. The image stays an ordinary image: nros build, nros run and nros flash treat it as before.

A test passes when every expect line has appeared within timeout seconds (60 if the table states none) and no forbid line has. With exit and no expectation, it passes when the target ends with that code. Only a host process or an emulator reports one; a board does not, so a board’s test needs an expectation.

Run the tests

Run nros test in the project. It prints one line per test, then a summary:

PASS  tw_node_bringup:linux            host                2.9 s

1 test(s): 1 passed, 0 failed

The build output and the router’s messages go to stderr. Each run keeps its logs in a directory of its own, build/nros/test/run-<time>-<pid>/<image>/: the console in console.log, and the router’s in router.log. A later run never overwrites them. -v streams the console as well. A failing test’s line says why it failed. The summary then shows the last lines of its console and the log’s path:

FAIL  talker_node_bringup:linux        host               12.2 s  timed out after 8.0 s without `This line is never printed`

1 test(s): 0 passed, 1 failed

FAIL talker_node_bringup:linux: timed out after 8.0 s without `This line is never printed`
  | [INFO] talker_node: [9716162.814898] Publishing: 'Hello World: 7'
  | nros: termination signal received; closing the RMW session
  log: …/build/nros/test/run-1796045627-3802429/talker_node_bringup_linux/console.log

nros test exits 0 when every test passed and 1 when any failed. A selection with no test image in it is an error, never a pass. --json prints the results as one JSON document, for CI.

Choose which tests run

CommandRuns
nros testEvery test image whose board runs on this machine: the host, or an emulator such as QEMU
nros test <image>…Only those images
nros test --board <board>The test images built for that board, real hardware included
nros test --allEvery test image, real hardware included

A board that needs real hardware is flashed and its console watched, as nros flash --monitor does. When a debug probe programs it (pyocd, jlink, openocd, probe-rs, …), the console opens before the flash, so the boot lines are in the log, and timeout counts from the end of the flash. Any other flasher, such as a serial bootloader, flashes first and says that boot lines may be missing. It is tested only when you name it or pass --all, so a plain nros test never fails over a board nobody asked for. A named board that is not attached fails its tests and is never skipped. The failure names the board, and nros bench scan records which port a board is on.

Tests run one after another, since two can need the same port, router or emulator network.

A test shares the router

A test on the host or in an emulator uses the router at the image’s locator, tcp/127.0.0.1:7447 for a scaffolded image, as nros run does. It starts one there, or joins the one already listening, and then says it is reusing it. So a test run beside your own zenohd joins your graph: your nodes see the test’s topics, and a test can pass on a line another process caused. Two nros test runs on one host share one router the same way. Stop your own router before you run the tests, and run one nros test at a time.