Commit Graph

3259 Commits

Author SHA1 Message Date
Simon Glass
84a64607a3 sandbox: Add --quiet_vidconsole option to speed up output
When running sandbox with lots of console output, the vidconsole slows
things down significantly since it renders truetype fonts to the
internal framebuffer. Add a -Q/--quiet_vidconsole command-line option
that removes vidconsole from stdout and stderr, using only the serial
console.

This can provide a ~300x speedup for output-heavy operations.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2026-01-01 14:27:12 -07:00
Simon Glass
1d6e3d59c8 test: py: Use run_ut() helper for vbe_test_fixup
Split the base_script to separate the ut command from the U-Boot command
sequence. This allows using run_ut() for the vbe_test_fixup test,
reducing duplication and improving consistency.

Cover-letter:
test: py: Convert more tests to use run_ut() helper
This series converts additional Python tests to use the run_ut() helper.
This reduces duplication and makes the tests more concise and consistent.

The ext4l tests are straightforward conversions, while test_vbe.py
requires splitting the U-Boot command script to separate the ut command.
END

Series-to: concept
Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-29 11:26:49 -07:00
Simon Glass
680dfeb7ab test: py: Use run_ut() helper for ext4l tests
Convert test_ext4l.py to use the run_ut() helper instead of manually
building the ut command and checking for failures. This reduces
duplication and makes the tests more concise.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-29 11:07:02 -07:00
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
aa1ada905b test: py: Add run_ut() helper for manual unit tests
Running manual unit tests (those with _norun suffix) involves a common
pattern: building the ut command with the -f flag, running it, and
checking for failures. This is verbose and error-prone.

Add a run_ut() method to ConsoleBase that simplifies this. It handles
the command construction, test arguments and failure checking
automatically.

Before:
    output = ubman.run_command(
        f'ut -f fs fs_test_ext4l_probe_norun fs_image={ext4_image}')
    assert 'failures: 0' in output

After:
    ubman.run_ut('fs', 'fs_test_ext4l_probe', fs_image=ext4_image)

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
1dd04b3fcb test: py: Add --persist flag to keep test artefacts
When iterating on C test code, the Python fixtures that create disk
images run each time, even though the images have not changed. This
slows down the development cycle unnecessarily.

Add a -P/--persist option to prevent cleanup of test-generated files
like disk images. This allows re-running C tests directly, without
re-running the Python fixture each time.

Update the ext4l test to respect the persist flag.

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
0f1d14835b test: Write the SPI image to the persistent-data directory
It is annoying to have disk images in the source directory since it
clutters up the working space.

Move spi.bin (used by the SPI tests) into the persistent-data
directory, update the driver and add a comment.

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
3f133727bf test: Move disk images to persistent-data directory
It is annoying to have disk images in the source directory since it
clutters up the working space.

Remove cur_dir=True from DiskHelper calls so disk images are written to
the persistent-data directory instead.

Move scsi.img too (used by the bootstd tests) and mmc6.img (used by the
MBR tests.

Add a few comments as to where the images are used.

This keeps the source tree clean and puts disk images in the same place
as other test data.

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
8349f9f700 fs: ext4l: Add statfs support
Implement ext4l_statfs() to return filesystem statistics using the
ext4 superblock. The function returns block size, total block count,
and free block count.

Add unit test to verify the statfs implementation returns valid data.

Cover-letter:
fs: ext4l: Complete read-only filesystem support (Part I)
This series completes read-only support for the ext4l filesystem driver,
which is a port of the Linux ext4 driver to U-Boot.

The ext4l driver provides more complete ext4 support than the existing
ext4 driver, including proper handling of extents, directory hashing,
and other ext4 features.

Changes include:

Sandbox infrastructure:
- Fix IRQ macros and buffer_head includes for sandbox builds

Core fixes:
- Fix path lookup by implementing proper dentry operations
- Fix fscrypt_match_name to do actual name comparison

Filesystem operations:
- Add directory listing (opendir/readdir/closedir)
- Add file existence check (exists)
- Add file size query (size)
- Add file read support (read)
- Add UUID query (uuid)
- Add filesystem statistics (statfs)

New command:
- Add fsinfo command to display filesystem statistics

Testing:
- Add comprehensive unit tests for all operations
- Enable fsuuid command for sandbox testing
END

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-27 13:35:43 -07:00
Simon Glass
a6b1cd23a7 cmd: Add fsinfo command
Add the fsinfo command to display filesystem statistics including block
size, total blocks, used blocks, and free blocks. Both raw byte counts
and human-readable sizes are shown.

Example output:
  => fsinfo mmc 0:1
  Block size: 4096 bytes
  Total blocks: 16384 (67108864 bytes, 64 MiB)
  Used blocks: 2065 (8458240 bytes, 8.1 MiB)
  Free blocks: 14319 (58650624 bytes, 55.9 MiB)

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-27 13:35:43 -07:00
Simon Glass
73848983f5 ext4l: Add uuid() support
The filesystem uuid method is not implemented.

Add ext4l_uuid() which returns the filesystem UUID as a string and
wire it into the filesystem operations table. Add a test.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-27 13:35:43 -07:00
Simon Glass
5180ac32d7 ext4l: Add read() support
Add ext4l_read() function to read file contents. The function resolves
the path to an inode, then reads the file block by block using
ext4_bread() and copies the data to the output buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-27 13:35:43 -07:00
Simon Glass
8810a02743 ext4l: Add size() support
Add ext4l_size() function to retrieve the size of a file or directory.
Wire it into the filesystem operations table in fs_legacy.c.

Signed-off-by: Simon Glass <sjg@chromium.org>

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-27 13:35:43 -07:00
Simon Glass
0e9c88b170 ext4l: Add exists() support
Implement ext4l_exists() to check if a file or directory exists on the
filesystem. This uses ext4l_resolve_path() to look up the path and
returns 1 if found, 0 otherwise.

Wire the function into fs_legacy.c and add a basic test.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-27 13:35:42 -07:00
Simon Glass
b9558d8a06 ext4l: Add open/read/close directory
Implement directory-iteration for the ext4l filesystem driver, allowing
callers to iterate through directory entries one at a time.

Add ext4l_opendir() which opens a directory and returns a stream handle,
ext4l_readdir() which returns the next directory entry, and
ext4l_closedir() which closes the stream and frees resources.

The implementation uses a struct dir_context to capture single entries
from ext4_readdir(), with logic to skip previously returned entries
since the htree code may re-emit them.

Update struct file to include a position.

Wire these functions into fs_legacy.c for the ext4l filesystem type.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-27 13:35:42 -07:00
Simon Glass
9806965e3e test: ext4l: Handle variable console output in tests
Directory entries appear in hash order and mount messages may appear
multiple times during probe operations.

Update tests to skip remaining output after finding expected content.

We could perhaps refine this with more powerful matching, but that is
left for another day.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-27 13:35:42 -07:00
Simon Glass
545acab06c travis-ci: add qemu-riscv64_smode* test environments
Provide test environments for running
qemu-riscv64_smode and qemu-riscv64_smode_acpi.

These use the OpenSBI implementation provided by QEMU and
pass main u-boot as -kernel parameter.

ACPI is enabled for both boards. We still expect the boards to use
QEMU's device-tree as control device-tree.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
(cherry picked from d94ebdd2c823ce8776723184cda960dcd2954711)
Remove the rva23s64 CPU since we don't have that in our QEMU:
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-27 11:09:13 -07:00
Simon Glass
073cddf846 Revert "test: hooks: Update qemu-riscv64 config for S-mode with OpenSBI"
This reverts commit 5f66188fd5.
2025-12-27 10:14:32 -07:00
Simon Glass
e16a9fa8b5 test: pytest: Add --quiet-hooks option
Add a --quiet-hooks option to suppress display of hook commands to
stdout while still logging them to the HTML log file. This reduces
console noise during test runs.

Cover-letter:
test: pytest and hook improvements
This series includes several improvements to the pytest infrastructure
and test hook configurations:

- Fix the timing check in conftest to properly check if timing is enabled
- Add a --quiet-hooks option to suppress hook command display
- Add and update ellesmere hook config files for various QEMU boards
- Update qemu-riscv64 config for S-mode with OpenSBI
END

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-26 20:22:28 -07:00
Simon Glass
b5b75c768e test: hooks: Add more ellesmere config files
Add configuration files for qemu-riscv32_smode, qemu-riscv64_smode,
qemu-riscv64_smode_acpi, qemu_arm64_acpi, and qemu_arm64_lwip boards.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-26 20:09:09 -07:00
Simon Glass
5f66188fd5 test: hooks: Update qemu-riscv64 config for S-mode with OpenSBI
Update the qemu-riscv64 hook config to use OpenSBI as the BIOS and load
U-Boot as the kernel, which is required for S-mode operation.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-26 20:09:09 -07:00
Simon Glass
227cc00fd8 test: hooks: Add missing ellesmere config files
Add configuration files for qemu-arm-sbsa, qemu-ppce500, and
qemu-xtensa-dc233c boards.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-26 20:09:09 -07:00
Simon Glass
af5b84be61 test: pytest: Fix timing check in conftest
The check uses hasattr() to see if the 'timing' attribute exists, but
does not check if it is actually enabled. Fix this by checking the
attribute value instead.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-26 20:09:02 -07:00
Andrew Goodbody
86c381e54d test: lib: Use CONFIG_64BIT to detect 64 bit compile
Should use CONFIG_64BIT to detect a 64 bit compile and not
CONFIG_PHYS_64BIT. This allows more platforms to run the
full test code.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
(cherry picked from commit 43ca65b305)
2025-12-24 05:17:05 -07:00
Ilias Apalodimas
c20372170e lmb: Remove lmb_alloc_base_flags()
lmb_alloc_base() is just calling lmb_alloc_base_flags() with LMB_NONE.
There's not much we gain from this abstraction, so let's remove the
former add the flags argument to lmb_alloc_base() and make the code
a bit easier to follow.

Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 3075708017)
2025-12-24 05:17:05 -07:00
Ilias Apalodimas
e005799d8f lmb: Remove lmb_alloc_addr_flags()
lmb_alloc_addr() is just calling lmb_alloc_addr_flags() with LMB_NONE
There's not much we gain from this abstraction, so let's remove the
latter, add a flags argument to lmb_alloc_addr() and make the code a
bit easier to follow.

Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 15e0c5e390)
2025-12-24 05:17:05 -07:00
Ilias Apalodimas
8692e10965 lmb: Rename free_mem to available_mem
free_mem is a misnomer. We never update it with the free memory for
LMB. Instead, it describes all available memory and is checked against
used_mem to decide whether an area is free or not.

So let's rename this field to better match its usage.

Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 400c34db89)
2025-12-24 05:17:04 -07:00
Ilias Apalodimas
8e54e97f09 lmb: Remove lmb_reserve_flags()
lmb_reserve() is just calling lmb_reserve_flags() with LMB_NONE.
There's not much we gain from this abstraction.
So let's remove the latter, add the flags argument to lmb_reserve()
and make the code a bit easier to follow.

Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 900a8951c3)
2025-12-24 05:17:04 -07:00
Ilias Apalodimas
65a9881993 lmb: Move enum lmb_flags to a u32
LMB flags is not an enum anymore. It's currently used as a bitmask
in various places of our code. So make it a u32 which is more
appropriate when dealing with masks.

Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 3d56c06551)
2025-12-24 05:17:04 -07:00
Evgeny Bachinin
54f6f7134d test: sandbox: fix invalid_use_of_IF_ENABLED_INT if BLOBLIST=n
Having CONFIG_OF_EMBED=y && CONFIG_BLOBLIST=n leads to the link
error:
```
ld: /tmp/ccRVty.ltrans40.ltrans.o: in function `lib_test_is_enabled':
test/lib/kconfig.c:24: undefined reference to \
                                       `invalid_use_of_IF_ENABLED_INT'
ld: test/lib/kconfig.c:26: undefined reference to \
                                `invalid_use_of_CONFIG_IF_ENABLED_INT'
```

Fixes: 29784d62ed ("test: Add some tests for kconfig.h")
Signed-off-by: Evgeny Bachinin <EABachinin@salutedevices.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
(cherry picked from commit 844f87366e)
2025-12-24 05:17:02 -07:00
Simon Glass
12af37117f bootstd: Remove prepared images
These are no-longer used. Drop them.

Signed-off-by: Simon Glass <sjg@chromium.org>
(cherry picked from commit bda30f83f9)
2025-12-24 05:16:56 -07:00
Simon Glass
60788f5431 ext4l: Add ls command support
Implement directory listing (ls) for the ext4l filesystem driver. This
includes path resolution with symlink following (limited to 8 levels to
prevent loops).

Add ext4l_ls() which uses ext4_lookup() for path resolution and
ext4_readdir() for directory enumeration. The dir_context actor callback
formats and prints each directory entry.

Export ext4_lookup() from namei.c and add declarations to ext4.h.

Add test_ls to the Python test suite, which creates a test file using
debugfs and verifies it appears in the directory listing with the
correct size.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>

Cover-letter:
ext4l: Add support for listing directoties (Part H)
This series adds directory-listing support to the ext4l filesystem
driver. It exports a few required functions from the Linux ext4 code,
fixes the dir_emit() stub to properly call the actor callback, and
implements ext4l_ls() with path resolution and symlink following.
END

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-22 16:49:47 -07:00
Simon Glass
65ce554ee6 test: fs: Add ext4l filesystem tests
Add initial tests for the ext4l filesystem driver:

- fs_test_ext4l_probe_norun: verifies the driver can probe and mount
  an ext4 filesystem
- fs_test_ext4l_msgs_norun: verifies the ext4l_msgs env var causes
  mount messages to be printed

The C tests use UTF_MANUAL flag and accept fs_image argument,
following the pattern established by fs_basic.c. The Python wrapper
creates an ext4 image and calls the C tests.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-22 16:49:47 -07:00
Heinrich Schuchardt
472fd4aa09 test: fix test_extension.py
extension_bootdev_hunt may have already run.
Without reboot we cannot make any assumption here.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
(cherry picked from commit d01720a8305a1e12b61bb40ff76c3a8a0d52d2f6)
[Resolved conflict: used ubman instead of u_boot_console per ci/master rename]
2025-12-20 08:25:37 -07:00
Simon Glass
5ef532deaa test/py: Simplify test_distro_arm_app_efi
The GRUB menu editing approach is fragile because:
1. GRUB can auto-boot before the test interacts with the menu
2. The command line content varies (e.g. '$vt_handoff' vs 'quiet splash')
3. Character-by-character navigation depends on exact screen layout

Simplify to just verify that EFI boot through GRUB reaches Linux
userspace, without trying to edit the kernel command line.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-19 21:49:06 -07:00
Simon Glass
652e93b301 test/py: Use longer timeout for lab-mode restart
When restarting U-Boot in lab mode, ensure_spawned() sets the timeout
to TIMEOUT_MS (30 seconds) before calling _wait_for_boot_prompt(). In
lab mode, _wait_for_banner() is skipped, so TIMEOUT_PREPARE_MS is never
restored.

This causes tests that boot into Linux and then restart U-Boot (like
test_distro_script) to fail with a timeout if the board takes more than
30 seconds to reset and boot.

Fix this by setting the timeout to TIMEOUT_PREPARE_MS (3 minutes) at
the start of _wait_for_boot_prompt() when in lab mode.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-19 21:48:59 -07:00
Sam Protsenko
23525e545d lmb: Return -EEXIST in lmb_add_region_flags() if region already added
An attempt to add the already added LMB region using
lmb_add_region_flags() ends up in lmb_addrs_overlap() check, which
eventually leads to either returning 0 if 'flags' is LMB_NONE, or -1
otherwise. It makes it impossible for the user of this function to catch
the case when the region is already added and differentiate it from
regular errors. That in turn may lead to incorrect error handling in the
caller code, like reporting misleading errors or interrupting the normal
code path where it could be treated as the normal case. An example is
boot_fdt_reserve_region() function, which might be called twice (e.g.
during board startup in initr_lmb(), and then during 'booti' command
booting the OS), thus trying to reserve exactly the same memory regions
described in the device tree twice, which produces an error message on
second call.

Return -EEXIST error code in case when the added region exists and it's
not LMB_NONE; for LMB_NONE return 0, to conform to unit tests
(specifically test_alloc_addr() in test/lib/lmb.c) and the preferred
behavior described in commit 1d9aa4a283 ("lmb: Fix the allocation of
overlapping memory areas with !LMB_NONE"). The change of
lmb_add_region_flags() return values is described in the table below:

    Return case                        Pre-1d9   1d9    New
    -----------------------------------------------------------
    Added successfully                    0      0      0
    Failed to add                         -1     -1     -1
    Already added, flags == LMB_NONE      0      0      0
    Already added, flags != LMB_NONE      0      -1     -EEXIST

Rework all affected functions and their documentation. Also fix the
corresponding unit test which checks reserving the same region with the
same flags to account for the changed return value.

No functional change is intended (by this patch itself).

Fixes: 1d9aa4a283 ("lmb: Fix the allocation of overlapping memory areas with !LMB_NONE")
Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Tested-by: Michal Simek <michal.simek@amd.com>
(cherry picked from commit 8b8b35a4f5)
2025-12-17 14:02:26 -07:00
Ilias Apalodimas
38a2583258 lmb: Fix the allocation of overlapping memory areas with !LMB_NONE
At the moment the LMB allocator will return 'success' immediately on two
consecutive allocations if the second one is smaller and the flags match
without resizing the reserved area.

This is problematic for two reasons, first of all the new updated
allocation won't update the size and we end up holding more memory than
needed, but most importantly it breaks the EFI SCT tests since EFI
now allocates via LMB.

More specifically when EFI requests a specific address twice with the
EFI_ALLOCATE_ADDRESS flag set, the first allocation will succeed and
update the EFI memory map. Due to the LMB behavior the second allocation
will also succeed but the address ranges are already in the EFI memory
map due the first allocation. EFI will then fail to update the memory map,
returning EFI_OUT_OF_RESOURCES instead of EFI_NOT_FOUND which break EFI
conformance.

So let's remove the fast check with is problematic anyway and leave LMB
resize and calculate address properly. LMB will now
- try to resize the reservations for LMB_NONE
- return -1 if the memory is not LMB_NONE and already reserved

The LMB code needs some cleanup in that part, but since we are close to
2025.01 do the easy fix and plan to refactor it later.
Also update the dm tests with the new behavior.

Fixes: commit 22f2c9ed9f ("efi: memory: use the lmb API's for allocating and freeing memory")
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 1d9aa4a283)
2025-12-16 20:38:21 -07:00
Jerome Forissier
8647480ac9 test/cmd/wget.c: move net_test_wget() to the cmd test suite
Since net_test_wget() is testing a command and is in test/cmd it should
be in the 'cmd' test suite, not 'lib'.

Saving and restoring the values of the environment variables that the
test manipulates is necessary to avoid a regression when running the
whole ut test suite. A minimal reproducer is:

 $ ./u-boot -T -c "ut cmd net_test_wget; ut dm dm_test_eth_act" | \
     grep -E "(Test:|Failures:)"

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
(cherry picked from commit 20f641987f)
2025-12-16 11:12:15 -07:00
Simon Glass
32c67c43fb test: fs: Update Python tests to call C implementations
Update test_basic.py to call the new C-based filesystem tests via the
'ut' command. This allows tests to run more directly, calling the actual
FS layer, without having to go through the command interface and
worrying about which filesystem command to use.

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
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
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
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
a9d6c0322e test: Add type-checked argument accessor functions
Add ut_get_str(), ut_get_int(), and ut_get_bool() functions with
corresponding ut_str(), ut_int(), and ut_bool() macros for accessing
test arguments with type checking.

These functions check that the argument index is within bounds and the
type matches what was requested.

The first failure for a test is reported via ut_failf() which should
make it fairly easy to debug the test.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-14 09:14:52 -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
1fbf894923 test: Add a helper to check the next line against a regex
Add a new ut_assert_nextline_regex() macro and ut_check_console_line_regex()
helper to check console output against a regex pattern. This is useful when
the exact output varies (e.g., file paths or line numbers in error messages).

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-14 09:12:44 -07:00