120 Commits

Author SHA1 Message Date
Simon Glass
20a8d1869b test: Add parallel test execution support
Running the full test suite takes a long time. It would be useful to
distribute tests across multiple sandbox instances to speed up testing.

Add support for running tests in parallel across multiple sandbox
instances. Each worker runs a subset of tests based on its worker ID.

Add -P<n>:<w> option to the ut command where n is the total number of
workers and w is this worker's ID (0 to n-1). Tests are distributed
by index modulo number of workers.

Series-to: u-boot
Series-cc: heinrich
Cover-letter:
test: Various improvements to unit-test infrastructure

This series adds several improvements to the unit-test infrastructure:

- Move disk images to the persistent-data directory so they don't
  pollute the source tree
- Add a way to keep pytest-created artefacts for faster iteration on
  C tests
- Add a helper to simplify running manual unit tests from Python
- Allow combined flags with the ut command (e.g. -Efm)
- Add a -E flag to emit machine-readable result lines
- Add a -P flag to distribute tests across parallel workers
- Add -m as an alias for -f (force manual tests)

These changes make it easier to run and debug tests, especially when
iterating on C test code.
END

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-29 16:18:51 +00:00
Simon Glass
e3708e22ca test: Add a flag to emit per-test result lines
The ut command shows test output but does not provide a machine-readable
indication of whether each individual test passed or failed. External
tools must rely on heuristics like scanning for failure patterns in the
output.

Add a -E flag that emits an explicit result line after each test:
  Result: PASS: test_name: file.c
  Result: FAIL: test_name: file.c

This allows tools to reliably determine per-test pass/fail status
without fragile pattern matching. The flag is optional to maintain
backward compatibility with existing scripts.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-29 16:18:51 +00:00
Simon Glass
58b6eaef82 test: ut: Refactor argument processing to use a loop
The current argument-parsing logic uses switch (str[1]) which only
processes the second character of each argument. This prevents combining
multiple single-character flags in one argument (e.g., -fm).

Refactor the code to use a for loop that iterates through all characters
in the argument. For flags that take a value (like -r and -I), use goto
to skip the rest of the argument after processing.

This allows combined flags like -fmR instead of requiring -f -m -R.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-29 16:18:51 +00:00
Simon Glass
9844bfd977 test: ut: Add -m as alias for the -f flag
Add -m as an alias for the -f flag which forces manual tests to run.
This provides consistency with external test runners that will use -m
for "manual" tests.

Also update the documentation to explain what manual tests are, and fix
a typo ("types" -> "times") in the -r description.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-29 16:18:51 +00:00
Simon Glass
72aeb4a2e2 test: fs: add C-based filesystem tests
Add C implementations of filesystem tests that can be called via
the 'ut fs' command. These tests use UTF_MANUAL flag since they require
external setup, i.e. creation of filesystem images.

This covers the existing TestFsBasic tests.

The tests use typed arguments (fs_type, fs_image, md5 values) passed
via the command line.

Add a few helpers to make the code easier to read.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-14 09:52:56 -07:00
Simon Glass
688e830a22 test: Allow preserving console recording on failure
Update the 'ut' command to have a -R command option to prevent ut_fail()
and ut_failf() from clearing GD_FLG_RECORD. This is useful when testing
the test framework itself, where error messages need to be captured.

Refactor ut_fail() and ut_failf() to call ut_unsilence_console() instead
of duplicating the flag-clearing logic.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-14 09:17:14 -07:00
Simon Glass
64850634f0 test: Enhance the ut command to pass test arguments
Update the ut command to permit passing arguments to tests.

Usage: ut -f fs test_name key1=value1 key2=value2

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-14 09:14:41 -07:00
Simon Glass
a3b60a2094 test: Add support for passing arguments to C tests
Add support for passing key=value arguments to unit tests. The test
framework parses arguments based on definitions provided by each test
and makes them available via uts->args[]

For now the 'ut' command does not support this new feature.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-14 09:14:34 -07:00
Simon Glass
d9152ea75e bootctl: Initial experimentation
This provides a basic prototype for boot control.

Some documentation is in boot/bootctl/README.rst
2025-09-28 14:32:36 -06:00
Simon Glass
c1949994d3 test: Fix the return value when a test fails
When a unit test fails, it returns the error code, which results in a
warning:

   exit not allowed from main input shell.

Fix it by returning a failure code instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-09 23:11:33 +02:00
Simon Glass
777c7a0c20 test: Update documentation
Update documentation for how to write tests and the 'ut' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
9fbcd63202 test: Do flag-processing in the correct place
At present the 'ut' command handles its flags in a strange way, in that
they must come after the subcommand.

So, we must use 'ut bloblist -r2' to run the bloblist tests twice. This
is an artefact of the way tests were run, through subcommands.

It is now possible to correct this, by doing flag-processing before
running the suite.

Update the code to handle this, so that 'ut -r2 bloblist' works. Update
the 'test_suite' test to check the new arguments.

Add a sanity-check for -I while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
cd9f15f9e9 test: Move code out of cmd_ut_category()
Move the logic from this function into run_suite(), on the way to having
flag parsing in the top-level 'ut' command instead of its children.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
816dce0f74 test: Allow running a selection of suites
Enhance the ut command to accept a comma-separated list of test suites
to run. Report the summary information for these at the end.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
9c7ef6c877 test: Drop suites.h
This file is empty now. Remove it and its uses.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
a0b8142de2 test: Make cmd_ut_category() static
This function is not used outside the cmd_ut file anymore, so make it
static.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
d4d0e85771 test: Drop support for test commands
Now that everything is using the new test-suite features, drop support
for running commands.

Fix a missing closing-bracket while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
6b352a1309 test: Drop the function for running optee tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
c52b23fbda test: Drop the function for running bootstd tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
b014146ee2 test: Drop the function for running fdt_overlay tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
07ebcdd543 test: Tweak FDT-overlay tests
Use fdt_overlay consistently in the identifiers and file/dir names.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
c53702a46f test: Leave out the prefix when printing test names
When tests are all in the same suite it is annoying to have to read all
the common text after each name. Skip this to help the user.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
835ede55fd test: Show the average time per test
Show the average duration of a test, so we can keep track of how it is
trending. Report the suite with the longest average test to encourage
people to improve it.

Add a function to update the stats based on the results from a single
suite and another to show the summary information.

Make this optional, since sandbox's SPL tests do not have a timer driver
and people may want to print results without times.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
136ace8d8a test: Add up the number of tests manually
All tests should belong to a suite, but if there is a suite we don't
know about (e.g. not added to cmd_ut.c) then the totals will not add up.
Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-16 14:11:28 +00:00
Simon Glass
b9c671580e test: Move help into the suite declaration
Rather than having the help in the longhelp, put it in the suite info
so 'ut info -s' can show it. This is tidier, particular due to the
removal of #ifdefs

This means that the help text is present in the image (although not
displayed with 'ut info -s') so the image-size increases. But with
UNIT_TEST enabled, we expect large images so this doesn't seem
important.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
8711f24600 test: Sort the test suites
Put the suites in order by name, for easier code-maintenance. This also
helps find test results for a particular swuit in the 'ut all' output.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
e46eb7b69a test: Record and show the totals for all test runs
With 'ut all' multiple test suites are run. Add a way to collect totals
and show them at the end.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
5e6b79b37e test: Pass the test state to cmd_ut_category()
Update this function to access a unit-test state, so that the caller can
collect results from running multiple suites.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
4da42b63ed test: Drop conditional compilation for suites
This is not needed anymore. If a test suite is not built, then it will
have no linker-list entries. So we can just check for that and know that
the suite is not present.

This allows removal of the #ifdefs and the need to keep them in sync
with the associated Makefile rules, which has actually failed, since the
help does not match what commands are actually present.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
7b37496a6f test: Drop the info test from the list
The 'info' test is not a real test. With the new suite array we can drop
this and the associated special-case code.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
bf947cc140 test: Drop the function for running upl tests
Use the new suite-runner to run these tests instead.

It is not clear that these actually work, since they are not enabled on
sandbox for some reason.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
690e5a35a0 test: Drop the function for running seama tests
Use the new suite-runner to run these tests instead.

It is not clear that these actually work, since they are not enabled on
sandbox for some reason.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
2025-02-08 13:50:15 +00:00
Simon Glass
27c302f446 test: Drop the function for running pci_mps tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
d690f4a87b test: Drop the function for running loadm tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
9ebb555e48 test: Drop the function for running hush tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
2f26bb86fc test: Drop the function for running addrmap tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
1b665cea1b test: Drop the function for running bootm tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
01072ef8ef test: Drop the function for running bloblist tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
19791b6871 test: Drop the function for running measurement tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
ad3a9a6de4 test: Drop the function for running setexpr tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
6a1c9e51e7 test: Drop the function for running mem tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
230f92eb9b test: Drop the function for running mbr tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
ad670c9863 test: Drop the function for running log tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
f4e0199d48 test: Drop the function for running lib tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
eaf111fef8 test: Drop the function for running font tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
494b56312d test: Drop the function for running fdt tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
3ad2f721ad test: Drop the function for running exit tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
3ab456ea66 test: Drop the function for running env tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
f0700cc3a3 test: Drop the function for running dm tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
7905e0780e test: Drop the function for running common tests
Use the new suite-runner to run these tests instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00