Using External Files in Tests
You might want to use external libraries, binaries, or other tools depending on your use case. For instance, if your test requires a specific tool or script, you can include it in your test workflow.
Let’s say you want to write a test for power-cycling your board using the latest firmware build and running your own tooling on it. We will demonstrate how to include the necessary tooling in the test.
Step-by-Step Guide:
- Add the Files
The fwci
CLI tool provides multiple commands to add, update, list, and delete files on your FirmwareCI. To add files, simply execute:
$ fwci files add <file-name> <path-to-file>
This command allows you to add files under the specified file-name
. The files can be provided in various formats, including single files, archives, and compressed archives.
Listing files should now result in a representation of the uploaded files:
$ fwci files get
files list:
0. ID: 01JC3DDYRJ81EK6PM6NHZZR0Y5
Name: system_suite
File-Tree:
βββ system-suite: 7372986 bytes
1. ID: 01JCB0MT44NYJ1933RETVHB59X
Name: my_python_testing_library
File-Tree:
βββ testing-binary: 14479360 bytes
- Reference the files in a storage item
After uploading a file, you can reference it within a storage item. Storage items not only link to the files but also include an optional array of commands that are executed within the testing environment.
For a comprehensive explanation, refer to the Storage Configuration documentation.
Examplary storage.yaml
# Reference Name of the storage item
name: my_python_testing_library
# Optional commands executed inside the testing sandbox environment
commands:
- "apt update"
- "apt install pip ipmitool inetutils-ping xvfb lsb-core -y"
- "pip install robotframework"
# Prefix the <files-name> with 'fwci://'
uri: fwci://my_python_testing_library
Add the storage.yaml
file into a subdirectory within the .firmwareci/storage
directory. The file structure should resemble the following:
$ tree .firmwareci
.firmwareci/
β ....
βββ storage
β βββ my_python_testing_library
β βββ storage.yaml
β ....
- Reference the Storage Inside a Test
Let’s modify the boot test from above and add an extra test command, which executes your testing library.
If a storage is referenced inside a test, it will automatically be included at a path inside the testing environment.
You can access the path by using a template identifier in the form of [[storage.<storage-name>]]
.
First copy the files from the storage path on the device, afterwards run the library as an executable.
For a comprehensive explanation, refer to the Templating documentation.
defaults:
transport: &transport
proto: ssh
options:
host: "[[attributes.Host]]"
user: root
password: root
stages:
- name: Run Golang Power Test
steps:
- cmd: ping
name: Wait for SSH service
options:
timeout: 2m
parameters:
host: "[[attributes.Host]]"
- cmd: copy
name: Copy tooling to DUT
transport: *transport
parameters:
source: "[[storage.my_python_testing_library]]"
destination: /tmp/my_python_testing_library
recursive: true
- cmd: cmd
name: Run openbmc-test-go Power Test
transport: *transport
options:
timeout: 20m
parameters:
executable: "/tmp/my_python_testing_library/executable"
args:
[
"-user",
"root",
"-password",
"root",
]