Commit Graph

52 Commits

Author SHA1 Message Date
Simon Glass
2ac3226758 test: Add tests for unit-test arguments
Add a set of tests to check the behaviour of test arguments and the ut
command. This includes failure cases, where the wrong type or a
non-existent argument is requested.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-14 09:17:31 -07:00
Simon Glass
2ddc96ae88 vsprintf: Add support for the %pV format-specifier
Add support for the %pV format-specifier which allows printing a
struct va_format. This is used by the Linux kernel for recursive
printf() formatting and is needed by the ext4l filesystem driver.

Add the struct to include/linux/printk.h to match the kernel location.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-13 16:28:53 -07:00
Simon Glass
95f10a6302 malloc: Make mcheck respect REALLOC_ZERO_BYTES_FREES
The mcheck wrapper for realloc() unconditionally frees memory and
returns NULL when size is 0. This differs from dlmalloc's default
behaviour which returns a minimum-sized allocation unless
REALLOC_ZERO_BYTES_FREES is defined.

Make the mcheck wrapper respect the same REALLOC_ZERO_BYTES_FREES
setting for consistent behavior with or without mcheck enabled.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-10 05:53:03 -07:00
Simon Glass
13197ab962 test: Add some tests for dlmalloc
We know or assume that dlmalloc itself works correctly, but there is
still the possibility that the U-Boot integration has bugs.

Add a test suite for the malloc() implementation, covering:
- Basic malloc/free operations
- Edge cases (zero size, NULL pointer handling)
- realloc() in various scenarios
- memalign() with different alignments
- Multiple allocations and fragmentation
- malloc_enable_testing() failure simulation
- Large allocations (1MB, 16MB)
- Full pool allocation (CONFIG_SYS_MALLOC_LEN plus environment size)
- Fill pool test with random sizes

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-01 17:00:23 +00:00
Simon Glass
d26f3fe96a bootstage: Add a way to read the time from a record
Add a function which returns the time given a record ID.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-23 10:00:31 +01:00
Simon Glass
5094bffc50 bootstage: Add some more tests
There is already a Python test. Add a few C tests as well, for bootstage
itself and for the 'bootstage' command.

Add helpers to access the internal state. Be careful to zero records
when removing them, since if the record is later reused, bootstage
expects the time to be zero.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-23 10:00:06 +01:00
Simon Glass
8434d55382 bloblist: Provide a way to remove a blob
Add a function to remove a blob of a particular type.

Signed-off-by: Simon Glass <sjg@chromium.org>
Co-developed-by: Claude <noreply@anthropic.com>
2025-10-18 09:07:43 +01:00
Simon Glass
dd80fd963c console: Add a way to quit pager with no further output
Add support for pressing 'q' to throw away any further output until the
prompt is reached.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-22 11:23:04 -06:00
Simon Glass
c7ba355d1f console: Add bypass keypress to disable paging
Add support for pressing 'Q' to put the pager into bypass mode,disabling
further paging for the current session.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-22 11:23:04 -06:00
Simon Glass
b54422a25d console: Restore old pager test-bypass value
The test.py tests pass -P to sandbox to tell it to bypass the pager.
Tests which change this value must restore it to the old value.

Fix this, so that the -P setting remains in place across test runs.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-22 11:23:04 -06:00
Simon Glass
c5188188e2 api: Rename legacy API files and examples
The API is not very useful these days, since it doesn't support driver
model. It is laborious to add new functions to the API as there are so
many needed.

A better approach would be to create a library containing all of U-Boot,
then have the API be generated by a script containing a list of
functions, perhaps with wildcards. Then a stub could be created, with
a list of entry points, which links with and calls through into the
library.

In preparation for heading in this direction, rename some of the
existing files and directories:

- examples/api -> examples/legacy_api
- include/api*.h -> include/legacy_api*.h
- API_BUILD to LEGACY_API_BUILD

Co-developed-by: Claude <noreply@anthropic.com>
2025-09-05 07:02:09 -06:00
Simon Glass
f3d27f9841 console: Add tests for calc_check_console_lines()
Add tests for checking:
- environment variable override with hex values
- invalid environment variable handling
- Kconfig-default behavior with device detection
- precedence rules (environment overrides device detection)
- serial terminal detection by manipulating sandbox state

Also expose calc_check_console_lines() in console.h for testing
and update pager functionality to use bypass mode when serial
is not connected to a terminal.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
5c8817090b console: Add a few more paging tests
Provide a test that the prompt is displayed and another that paging
happens but does not appear in the recorded console-output.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
28311413de console: Support paging with single characters
A single character may result in a stall waiting for user input, which
means that it may request that a string be output. So when the pager is
active we never actually use the devices' putc() methods. Add a special
case so they don't go to wrack and ruin.

As before, the pager is only supported with CONFIG_CONSOLE_MUX enabled.

Series-changes: 2
- Drop unnecessary '!= NULL'

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
cad364dd79 console: test: Allow tests to bypass the pager
We generally don't want the pager to be active when running tests,
since U-Boot appears to hang forever. Perhaps we could detect when the
tests are being run interactively and use the pager in that case. But
for now, just bypass it.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
984b363d02 console: Provide a way to output without the pager
Sometimes output should be sent ignoring the pager, such as when it is
a message related to paging. Add a parameter to support this.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:06 -06:00
Simon Glass
4a74dee5ce console: Add tests for the basic functionality
Cover the various cases in the base code. Put the tests in the 'common'
suite to match where the pager implementation is.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:06 -06:00
Simon Glass
5b5694a0f8 event: Mark test_event_probe() as sandbox-only
This test skips itself if not running on sandbox, but by that time the
driver model state has already been reset. This can impact other tests.

Change the test so that it is only started on sandbox.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-11 21:12:11 +02:00
Jerome Forissier
f6e7e8c348 lib/uuid.c: use unique name for PARTITION_SYSTEM_GUID
The name defined for PARTITION_SYSTEM_GUID in list_guid[] depends on
configuration options. It is "system" if CONFIG_PARTITION_TYPE_GUID is
enabled or "System Partition" if CONFIG_CMD_EFIDEBUG or CONFIG_EFI are
enabled. In addition, the unit test in test/common/print.c is incorrect
because it expects only "system" (or a hex GUID).

Make things more consistent by using a clear and unique name: "EFI
System Partition" whatever the configuration, and update the unit test
accordingly.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2025-05-29 16:08:37 +01:00
Tom Rini
2825b387b0 Kbuild: Always use $(PHASE_)
It is confusing to have both "$(PHASE_)" and "$(XPL_)" be used in our
Makefiles as part of the macros to determine when to do something in our
Makefiles based on what phase of the build we are in. For consistency,
bring this down to a single macro and use "$(PHASE_)" only.

Signed-off-by: Tom Rini <trini@konsulko.com>
2025-05-01 05:56:48 -06:00
Raymond Mao
addb58f5f4 bloblist: add api to get blob with size
bloblist_find function only returns the pointer of blob data,
which is fine for those self-describing data like FDT.
But as a common scenario, an interface is needed to retrieve both
the pointer and the size of the blob data.

Add a few ut test cases for the new api.

Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2025-03-15 15:47:34 +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
f2b9f61b36 bloblist: Make BLOBLIST_ALLOC the default
We want to encourage people to use an allocated bloblist since it is
more flexible than a fixed one. Make this the default, being sure not to
change existing users.

The unit tests require BLOBLIST_FIXED so add a dependency in the
Makefile to avoid build errors.

All sandbox builds require BLOBLIST_FIXED so make that the default for
sandbox.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-15 19:07:09 -07: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
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
Simon Glass
a4a4b0641e test: Drop the _test suffix on linker lists
Most test suites have a _test suffix. This is not necessary as there is
also a ut_ prefix.

Drop the suffix so that (with future work) the suite name can be used as
the linker-list name.

Remove the suffix from the pytest regex as well, moving it to the top of
the file, as it is a constant.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
0b9b5fde55 test: Adjust print_ut test to use unsigned char
Since char is unsigned on arm64, this test currently fails. It seems
better to use unsigned anyway, since 0xff is written into the string at
the start. Update the terminator-assert to use a character instead of a
byte.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Changes in v6:
- Re-introduce

Changes in v2:
- Use '\0' instead of 0

 test/print_ut.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
2024-12-17 06:53:19 -07:00
Heinrich Schuchardt
20b23f049f test: print_printf() must check availability of %ls
Availability of %ls in printf() depends on having
CONFIG_EFI_LOADER or CONFIG_EFI_APP.

Respect this when testing.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-11-14 18:14:06 -06:00
Tom Rini
aa482995a8 Merge patch series "test: Tidy up the test/ directory"
Simon Glass <sjg@chromium.org> says:

Some tests do not use the unit-test framework. Others are in a suite of
their own, for no obvious reason.

This series tidies this up.

Link: https://lore.kernel.org/r/20241102193715.432529-1-sjg@chromium.org
2024-11-13 16:02:58 -06:00
Simon Glass
33ca12b233 test: Move print_ut into the common suite
There is no particular need for bloblist to have its own test suite.
Move it into the common suite instead.

Add the missing help for 'common'.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> # rpi_3, rpi_4, rpi_arm64, am64x_evm_a53, am64-sk
2024-11-13 11:56:01 -06:00
Simon Glass
479b389c3d test: Move print_ut test into common
This test doesn't belong at the top level. Move it into the common/
directory, to match its implementation. Rename it to drop the
unnecessary _ut suffix.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> # rpi_3, rpi_4, rpi_arm64, am64x_evm_a53, am64-sk
2024-11-13 11:56:01 -06:00
Simon Glass
692ed744ba bloblist: test: Drop global_data declarations
This pointer is not used any more, so drop the declarations.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> # rpi_3, rpi_4, rpi_arm64, am64x_evm_a53, am64-sk
2024-11-13 11:56:01 -06:00
Simon Glass
82e6d79d9e bloblist: test: Move test into common
This test doesn't belong at the top level. Move it into the common/
directory, to match its implementation.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> # rpi_3, rpi_4, rpi_arm64, am64x_evm_a53, am64-sk
2024-11-13 11:56:01 -06:00
Simon Glass
d3ac70aac4 test: Use UTF_CONSOLE in remaining tests
Set this flag rather than doing things manually in the test.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-08-26 18:51:49 -06:00
Simon Glass
b073d48e8d test: Drop the blank line before test macros
Most tests don't have this. It helps to keep the test declaration
clearly associated with the function it relates to, rather than the next
one in the file. Remove the extra blank line and mention this in the
docs.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-08-26 18:51:49 -06:00
Simon Glass
725c438c62 test: Rename unit-test flags
The UT_TESTF_ macros read as 'unit test test flags' which is not right.
Rename to UTF ('unit test flags').

This has the benefit of being shorter, which helps keep UNIT_TEST()
declarations on a single line.

Give the enum a name and reference it from the UNIT_TEST() macros while
we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-08-26 18:51:48 -06:00
Rasmus Villemoes
008c4b3c31 cyclic: make clients embed a struct cyclic_info in their own data structure
There are of course not a whole lot of examples in-tree yet, but
before they appear, let's make this API change: Instead of separately
allocating a 'struct cyclic_info', make the users embed such an
instance in their own structure, and make the convention that the
callback simply receives the 'struct cyclic_info *', from which the
clients can get their own data using the container_of() macro.

This has a number of advantages.

First, it means cyclic_register() simply cannot fail, simplifying the
code. The necessary storage will simply be allocated automatically
when the client's own structure is allocated (often via
uclass_priv_auto or similar).

Second, code for which CONFIG_CYCLIC is just an option can more easily
be written without #ifdefs, if we just provide an empty struct
cyclic_info {}. For example, the nested CONFIG_IS_ENABLED()s in
https://lore.kernel.org/u-boot/20240316201416.211480-1-marek.vasut+renesas@mailbox.org/
are mostly due to the existence of the 'struct cyclic_info *' member
being guarded by #ifdef CONFIG_CYCLIC.

And we do probably want to avoid the extra memory overhead of that
member when !CONFIG_CYCLIC. But that is automatic if, instead of a
'struct cyclic_info *', one simply embeds a 'struct cyclic_info',
which will have size 0 when !CONFIG_CYCLIC. Also, the no-op
cyclic_register() function can just unconditionally be called, and the
compiler will see that (1) the callback is referenced, so not emit a
warning for a maybe-unused function and (2) see that it can actually
never be reached, so not emit any code for it.

Reviewed-by: Stefan Roese <sr@denx.de>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2024-06-16 12:13:44 +02:00
Tom Rini
03de305ec4 Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"
As part of bringing the master branch back in to next, we need to allow
for all of these changes to exist here.

Reported-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-20 13:35:03 -06:00
Tom Rini
d678a59d2d Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
When bringing in the series 'arm: dts: am62-beagleplay: Fix Beagleplay
Ethernet"' I failed to notice that b4 noticed it was based on next and
so took that as the base commit and merged that part of next to master.

This reverts commit c8ffd1356d, reversing
changes made to 2ee6f3a5f7.

Reported-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-19 08:16:36 -06:00
Tom Rini
752ed08675 test: Remove <common.h> and add needed includes
Remove <common.h> from all "test/" files and when needed add
missing include files directly.

Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-06 15:05:04 -06:00
Simon Glass
14f0cc49df test: event: Only run test_event_probe() on sandbox
This needs test devices which are only present on sandbox. Add a check
for this and skip just this test if running on a real board.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-12-13 18:39:05 -05:00
Yurii Monakov
2dd86b9075 cli: Consume invalid escape sequences early
Unexpected 'Esc' key presses are accumulated internally, even if it is
already clear that the current escape sequence is invalid. This results
in weird behaviour. For example, the next character after 'Esc' key
simply disappears from input and 'Unknown command' is printed
after 'Enter'.

This commit fixes some issues with extra 'Esc' keys entered by user:

1. Sequence <Esc><Esc><Enter> right after autoboot stop gives:
=>
nknown command 'ry 'help'
=>
2. Sequence <Esc><p><r><i><Enter> gives:
=> ri
Unknown command 'ri' - try 'help'
=>
3. Extra 'Esc' key presses break backspace functionality.

Signed-off-by: Yurii Monakov <monakov.y@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-10-24 16:34:45 -04:00
Heinrich Schuchardt
4c18175413 test: build dependency for event unit tests
The test_event_base and test_event_probe unit tests use function
event_register() which depends on CONFIG_EVENT_DYNAMIC=y.

Fixes: 7d02645fe4 ("event: Add a simple test")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-09-30 15:15:31 -04:00
Simon Glass
ba5e3e1ed0 event: Support a simple spy record
The current event spy is always passed the event context and the event.
The context is always NULL for a static spy. The event is not often used.

Introduce a 'simple' spy which takes no arguments. This allows us to drop
the adaptation code that many of these spy records use.

Update the event script to find these in the image.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-08-31 13:16:54 -04:00
Simon Glass
be0169f07e cli: Correct handling of invalid escape sequences in cread_line()
The second call to cli_ch_process() is in the wrong place, meaning that
the one of the characters of an invalid escape sequence is swallowed
instead of being returned.

Fix the bug and add a test to cover this.

This behaviour matches that of the code before cli_getch() was
introduced. This was verified on the commit before b08e9d4b66 i.e.:

   7d850f85aa ("sandbox: Enable mmc command and legacy images")

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2023-03-28 09:25:51 -04:00
Simon Glass
17b45e684a cli: Correct several bugs in cli_getch()
This function does not behave as expected when unknown escape sequences
are sent to it:

- it fails to store (and thus echo) the last character of the invalid
  sequence
- it fails to set esc_len to 0 when it finishes emitting the invalid
  sequence, meaning that the following character will appear to be part
  of a new escape sequence
- it processes the first character of the rejected sequence as a valid
  character, just starting the sequence all over again

The last two bugs conspire to produce an "impossible condition #876"
message which is the main symptom of this behaviour.

Fix these bugs and add a test to verify the behaviour.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2023-03-28 09:25:51 -04:00
Stefan Roese
29caf9305b cyclic: Use schedule() instead of WATCHDOG_RESET()
Globally replace all occurances of WATCHDOG_RESET() with schedule(),
which handles the HW_WATCHDOG functionality and the cyclic
infrastructure.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Tom Rini <trini@konsulko.com> [am335x_evm, mx6cuboxi, rpi_3,dra7xx_evm, pine64_plus, am65x_evm, j721e_evm]
2022-09-18 10:26:33 +02:00
Stefan Roese
af042c211d cyclic: Add a simple test
Add a test for cyclic function registration and activation.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
2022-09-13 16:01:44 -04:00
Simon Glass
5b896ed585 event: Add events for device probe/remove
Generate events when devices are probed or removed, allowing hooks
to be added for these situations.

This is controlled by the DM_EVENT config option.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-03-10 08:28:36 -05:00
Simon Glass
7d02645fe4 event: Add a simple test
Add a test for event registration and activation.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-03-10 08:28:36 -05:00