Skip to main content
Rugix Bakery 0.9.6 is here: Build rules for custom image pipelines and verified boot for EFI and Raspberry Pi. Read the release post.
Documentation
Preview
You're viewing the Next docs — a rolling preview of in-development changes. The current release docs may differ.

System Testing

Embedded Linux systems are inherently complex, with numerous interconnected components working together. To ensure that all parts of a system work together seamlessly, Rugix Bakery includes a system testing framework designed to validate system images as a complete unit. This framework boots a system image in a virtual machine and then executes a test workflow on the system. By catching integration errors early, it reduces the need for costly and time-consuming testing on physical hardware.

Limitations: Currently, the integration testing framework is limited to the generic-grub-efi target.

Test Workflows

Test workflows are placed in the tests directory of your Rugix Bakery project. Each workflow consists of a TOML file describing the tests to be conducted. To this end, the workflow file starts with a declaration of test systems:

[[systems]]
system = "<system-name>"
ssh = { private-key = "<path-to-private-key>" }

Each test system declaration must specify a system, which is the system to test. In addition, a disk-size can be specified determining the size of the disk. By default, Rugix Bakery will create a 40 GiB disk. Note that Rugix Bakery allocates an image per system that grows on-demand and stores only the changes made over the original system image. Hence, typically much less than disk-space additional space is required. Multiple systems can be specified in the same test workflow. Rugix will then run the workflow for each system. You must not build any images manually while running tests.

To execute commands on the system under test, Rugix Bakery connects to the system running in the VM via SSH. To this end, a private key needs to be specified. This private key must be placed somewhere in the project directory. It is recommended to generate a pair of keys exclusively for this purpose. To generate a suitable pair of SSH keys in the current working directory, run:

ssh-keygen -t rsa -b 4096 -f id_rsa

We recommend generating the keys locally and putting them into a directory outside of version control.

To authorize the public key, override the root_authorized_keys parameter of the core/ssh recipe in a parameter file:

test-parameters.toml
["core/ssh"]
root_authorized_keys = "ssh-rsa AAAA..."

Pass the parameter file to the test command as shown below. Only the systems baked for tests then authorize the key, while images built without the parameter file do not contain it.

For a complete example, see the test workflows of Rugix Bakery itself.

The declaration of test systems is followed by a specification of test steps.

Test Steps

Each test step performs a certain action. Currently, the following actions are supported:

  • wait: Wait for some amount of time.
  • run: Run a script via SSH in the VM.

Wait

The wait action takes a duration option specifying the time to wait in seconds. Here is an example for waiting 20 seconds:

[[steps]]
action = "wait"
duration = 20

Run

The run action takes a script option with a shell script to execute. For example:

[[steps]]
action = "run"
script = """
#!/bin/bash
echo "Hello from the VM."
"""

Note that the script needs a shebang, e.g., #!/bin/bash, to execute.

In addition, the run action supports the following optional options:

  • may-disconnect: Sometimes, e.g., when rebooting the system with a script, the execution may fail because the SSH connection drops, however, this is expected and the test should not fail. In this case, you can set may-disconnect to true indicating that it is okay for the SSH connection to drop. Note that a non-zero exit code of the script will still fail the test.
  • may-fail: Allows the script to fail with a non-zero exit code without failing the test.
  • stdin-file: Path to a file which is provided as stdin to the script. Can be used to stream an update into the system.

Running Tests

Tests can be run with the test command:

./run-bakery test --param-file test-parameters.toml

Without further arguments, the command runs all workflows in the tests directory. To run specific workflows, pass their names, for example, ./run-bakery test --param-file test-parameters.toml boot. The --param-file option is optional and can be repeated.

Configuration Reference

For reference, here is the complete schema for test configuration files:

TestConfigobject

Test configuration.

systemsarray<SystemConfig>required
valueSystemConfig

System configuration for testing.

systemstringrequired
disk-sizeNumBytes

Number of bytes.

sshSshConfig

SSH configuration.

private-keystringrequired
stepsarray<TestStep>required
valueTestStep

Test step.

option 1object
actionconst "run"required
run
descriptionstring
scriptstringrequired
stdin-filestring
may-disconnectboolean
may-failboolean
option 2object
actionconst "wait"required
wait
descriptionstring
durationnumber | stringrequired
  • pattern: ^(NaN|[+-]?Infinity)$

You will find the most recent version of this schema on GitHub.