summaryrefslogtreecommitdiff
path: root/test/lib
AgeCommit message (Collapse)Author
3 daysabuf: Remove code that prevented test code runningAndrew Goodbody
When abuf was introduced some test code was prevented from running using a 'return 0' early in the functions. A comment said it crashed on sandbox due to a 'bug' in realloc. Some time later a bug in abuf_realloc was fixed but this test code was never enabled. Remove the early 'return 0' instances so that the test code can run. Also remove some checks that relied on the implementation details of the U-Boot memory code as these can fail on sandbox which uses system memory code. Besides that this code should be testing abuf implementation not the underlying memory code which has its own tests. Finally use a new #define for the allocs that are meant to fail to ensure they do fail on all CI platforms. This issue found by Smatch. Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
2025-06-26Merge patch series "sandbox: align LMB memory"Tom Rini
Heinrich Schuchardt <heinrich.schuchardt@canonical.com> says: To implement the EFI_SYSTEM_TABLE_POINTER we need 4 MiB aligned memory. On the sandbox LMB uses addresses relative to the start of a page aligned RAM buffer allocated with mmap(). This leads to a mismatch of alignment between EFI which uses pointers and LMB which uses phys_addr_t. Ensure that the RAM buffer used for LMB is 4 MiB aligned. Provide a unit test for efi_alloc_aligned_pages() verifying this alignment. Do not overwrite RAM size in dram_init(). Link: https://lore.kernel.org/r/20250608075428.32631-1-heinrich.schuchardt@canonical.com
2025-06-26test: unit test for efi_alloc_aligned_pages()Heinrich Schuchardt
Provide unit tests for efi_alloc_aligned_pages() and efi_allocate_pages(). Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2025-06-25lmb: use a single function to free up memorySughosh Ganu
There is no need to have two separate API's for freeing up memory. Use a single API lmb_free() to achieve this. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2025-06-25lmb: replace the lmb_alloc() and lmb_alloc_base() API'sSughosh Ganu
There currently are two API's for requesting memory from the LMB module, lmb_alloc() and lmb_alloc_base(). The function which does the actual allocation is the same. Use the earlier introduced API lmb_alloc_mem() for both types of allocation requests. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2025-06-25lmb: replace lmb_reserve() and lmb_alloc_addr() API'sSughosh Ganu
There currently are multiple allocation API's in the LMB module. There are a couple of API's for allocating memory(lmb_alloc() and lmb_alloc_base()), and then there are two for requesting a reservation for a particular memory region (lmb_reserve() and lmb_alloc_addr()). Introduce a single API lmb_alloc_mem() which will cater to all types of allocation requests and replace lmb_reserve() and lmb_alloc_addr() with the new API. Moreover, the lmb_reserve() API is pretty similar to the lmb_alloc_addr() API, with the one difference being that the lmb_reserve() API allows for reserving any address passed to it -- the address need not be part of the LMB memory map. The lmb_alloc_addr() does check that the address being requested is actually part of the LMB memory map. There is no need to support reserving memory regions which are outside the LMB memory map. Remove the lmb_reserve() API functionality and use the functionality provided by lmb_alloc_addr() instead. The lmb_alloc_addr() will check if the requested address is part of the LMB memory map and return an error if not. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2025-05-30abuf: Add a way to printf() into a bufferSimon Glass
It is useful to format a string into a buffer, with the sizing handled automatically. Add a function for this. Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-30abuf: Add a function to copy a bufferSimon Glass
It is useful to be able to copy an abuf, to allow changes while preserving the original. Add a function for this. Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-30abuf: Add a helper for initing and allocating a bufferSimon Glass
This construct appears in various places. Reduce code size by adding a function for it. It inits the abuf, then allocates it to the requested size. Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-29Merge patch series "regex patches"Tom Rini
Rasmus Villemoes <ravi@prevas.dk> says: This started as a rather simple patch, 1/12, adding the ability to more conveniently do regex matching in shell. But with that, it became very easy to see what the slre library can and especially what it cannot do, and that way I found both outright bugs and a "wow, doesn't it support that syntax" gotcha. I couldn't find any tests ('git grep slre -- test/' was empty), so I added a small test suite and tweaked slre.c. Link: https://lore.kernel.org/r/20250513084034.654865-1-ravi@prevas.dk
2025-05-29test: slre: add tests for regex libraryRasmus Villemoes
Inspecting the slre.c code reveals a few bugs; those are easy to demonstrate with the new '=~' test operator. Before fixing them, let's add a place to add test cases. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
2025-05-29test: slre: add tests for character rangesRasmus Villemoes
The first of these, { "U-Boot", "^[B-Uo-t]*$", 0 }, would match previously when the - and the letters were all interpreted literally. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
2025-05-29test: slre: add test cases for escape char in character classRasmus Villemoes
Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
2025-05-29test: slre: add some (negative) character class testsRasmus Villemoes
Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
2025-05-29test: slre: add more test casesRasmus Villemoes
Add some tests for the "drop wrong anchored optimization". Without the previous commit, the first, fifth and seventh of these would fail, i.e. those: { "xby", "^a|b", 1}, { "", "x*$", 1}, { "yy", "x*$", 1}, Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
2025-05-26Merge tag 'v2025.07-rc3' into nextTom Rini
Prepare v2025.07-rc3
2025-05-25efi_loader: Separate device path into its own headerSimon Glass
These functions are useful for the EFI app. As a first step towards making these available outside lib/efi_loader, create a separate header file and include it where needed. Add proper comments to the functions, since many are missing at present. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2025-05-16test: Add a test for strim()Simon Glass
This function trims whitespace from the start and end of a string. Add a test for it. Signed-off-by: Simon Glass <sjg@chromium.org>
2025-04-23test: lib: add uthread_mutex testJerome Forissier
Add a test for uthread mutexes. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
2025-04-23test: lib: add uthread testJerome Forissier
Add a thread framework test to the lib tests. Update the API documentation to use the test as an example. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2025-04-23test: lib: add initjmp() testJerome Forissier
Test the initjmp() function when HAVE_INITJMP is set. Use the test as an example in the API documentation. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2025-04-11Merge patch series "Switch to using $(PHASE_) in Makefiles"Tom Rini
Tom Rini <trini@konsulko.com> says: This series switches to always using $(PHASE_) in Makefiles when building rather than $(PHASE_) or $(XPL_). It also starts on documenting this part of the build, but as a follow-up we need to rename doc/develop/spl.rst and expand on explaining things a bit. Link: https://lore.kernel.org/r/20250401225851.1125678-1-trini@konsulko.com
2025-04-11Kbuild: Always use $(PHASE_)Tom Rini
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-04-03Merge patch series "membuff: Add tests and update to support a flag for ↵Tom Rini
empty/full" Simon Glass <sjg@chromium.org> says: The membuff implementation curently has no tests. It also assumes that head and tail can never correspond unless the buffer is empty. This series provides a compile-time flag to support a 'full' flag. It also adds some tests of the main routines. The data structure is also renamed to membuf which fits better with U-Boot. There may be some cases in the code which could be optimised a little, but the implementation is functional. Link: https://lore.kernel.org/r/20250318152059.1464369-1-sjg@chromium.org
2025-04-03membuf: Add some testsSimon Glass
Add tests for the membuf implementation. Signed-off-by: Simon Glass <sjg@chromium.org>
2025-03-26test: lmb: fix the lmb_alloc_addr() based test casesSughosh Ganu
Commit 56f186a68b3 ("lmb: check if a region can be reserved by lmb_reserve()") fixed the lmb_reserve() and lmb_alloc_addr() API's for some corner case scenarios, and also added corresonding test cases for these corner cases. These tests were checking, among other things, the lmb_alloc_addr() API. The above commit was applied to the next branch. Subsequently, there was commit 67be24906fe ("lmb: change the return code on lmb_alloc_addr()") which was first applied on the master branch, and subsequently got merged to next as part of the rebase. The second commit changes the return value of the lmb_alloc_addr() API, which now results in some of the tests added as part of the first commit to fail. Fix those test cases. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
2025-03-24Merge tag 'v2025.04-rc5' into nextTom Rini
Prepare v2025.04-rc5
2025-03-24lmb: change the return code on lmb_alloc_addr()Ilias Apalodimas
Ben reports a failure to boot the kernel on hardware that starts its physical memory from 0x0. The reason is that lmb_alloc_addr(), which is supposed to reserve a specific address, takes the address as the first argument, but then also returns the address for success or failure and treats 0 as a failure. Since we already know the address change the prototype to return an int. Reported-by: Ben Schneider <ben@bens.haus> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Tested-by: Ben Schneider <ben@bens.haus> Reviewed-by: Sughosh Ganu <sughosh.ganu@linaro.org>
2025-03-17Merge patch series "lmb: miscellaneous fixes and improvements"Tom Rini
Sughosh Ganu <sughosh.ganu@linaro.org> says: The patch series contains some fixes and improvements in the lmb code, along with addition of corresponding test cases for the changes made. The lmb_reserve() function currently does not check if the requested reservation would overlap with existing reserved regions. While some scenarios are being handled, some corner cases still exist. These are being handled by patch 1, along with adding test cases for these scenarios. Patch 2 is handling the case of reserving a new region of memory, but that region overlaps with an existing region. The current code only handles one particular scenario, but prints a message for the other scenario of an encompassing overlap and returns back. The patch handles the encompassing overlap. Patch 3 is an improvement whereby we allow coalescing a newly reserved region with an existing region. The current code exits this check prematurely. Patch 4 is removing a now superfluous check for overlapping regions with flag other than LMB_NONE. This now gets handled at an earlier point in lmb_reserve(). Patch 5 is clubbing the functionality to check if two regions are adjacent, or overlap, allowing some code re-use. Patch 6 is optimising the lmb_alloc() function by having it call _lmb_alloc_base() directly. Link: https://lore.kernel.org/r/20250303133231.405279-1-sughosh.ganu@linaro.org
2025-03-17lmb: check if a region can be reserved by lmb_reserve()Sughosh Ganu
The logic used in lmb_alloc() takes into consideration the existing reserved regions, and ensures that the allocated region does not overlap with any existing allocated regions. The lmb_reserve() function is not doing any such checks -- the requested region might overlap with an existing region. This also shows up with lmb_alloc_addr() as this function ends up calling lmb_reserve(). Add a function which checks if the region requested is overlapping with an existing reserved region, and allow for the reservation to happen only if both the regions have LMB_NONE flag, which allows re-requesting of the region. In any other scenario of an overlap, have lmb_reserve() return -EEXIST, implying that the requested region is already reserved. Add corresponding test cases which check for overlapping reservation requests made through lmb_reserve() and lmb_alloc_addr(). And while here, fix some of the comments in the test function being touched. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2025-03-12Merge branch 'graph' of ↵Tom Rini
https://source.denx.de/u-boot/custodians/u-boot-tegra into next
2025-03-10common: clean up setjmp.hHeinrich Schuchardt
Separate setjmp.h into an architecture independent part and an architecture specific part. This simplifies moving from using struct jmp_buf_data directly to using type jmp_buf in our code which is the C compliant way. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2025-03-08sandbox: remap memory load addressesSvyatoslav Ryhel
The existing memory layout places the bloblist at 0xb000 and the fdt at 0x100, resulting in a 0xaf00 size constraint for the fdt. This constraint has been reached. Lets modify the layout by moving the bloblist to 0x100, device tree to 0x1000 and placing early memory allocation after pre-console buffer at 0xf4000. This should guarantee sufficient memory allocation for future expansion. Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
2025-02-12test: unit tests for strstr() and strnstr()Heinrich Schuchardt
Add unit tests for the library functions. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> [jf: drop unwanted change to lib/string.c] Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
2025-01-24Merge patch series "test: Improvements to ut command and test-suite running"Tom Rini
Simon Glass <sjg@chromium.org> says: The current method of running unit tests relies on subcommands of the ut command. Only the code in each subcommand knows how to find the tests related to that subcomand. This is not ideal and we now have quite a few subcommands which do nothing but locate the relevant tests in a linker list, then call a common function to run them. This series adds a list of test suites, so that these subcommands can be removed. An issue with 'ut all' is that it doesn't record how many tests failed overall, so it is necessary to examine copious amounts of output to look for failures. This series adds a new 'total' feature allow recording the total number of failed tests. To help with 'ut all' a new pytest is created which runs it (as well as 'ut info') and makes sure that all is well. Due to the 'ut all' failures this does not pass, so the test is disabled for now. It is here because it provides security against misnaming a test suite and causing it not to run. Future work may: - get 'ut all' passing - enable test_suite() in CL, to ensure that 'ut all' keeps passing - record duration of each suite - allow running the tests in random order to tease out dependencies - tweak the output to remove common prefixes - getting rid of bootstd, optee and seame 'ut' subcommands Link: https://lore.kernel.org/r/20250120212613.516664-1-sjg@chromium.org
2025-01-24test: Drop the function for running lib testsSimon Glass
Use the new suite-runner to run these tests instead. Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-24test: Drop the _test suffix on linker listsSimon Glass
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-01-24test: str_ut.c depends on CONFIG_STRTOHeinrich Schuchardt
The string conversion functions are implemented in lib/strto.c which is only compiled if CONFIG_STRTO=y. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2025-01-22Merge patch series "upl: Prerequite patches for updated spec"Tom Rini
Simon Glass <sjg@chromium.org> says: The current UPL spec[1] has been tidied up and improved over the last year, since U-Boot's original UPL support was written. This series includes some prerequisite patches needed for the real UPL patches. It is split from [2] [1] https://github.com/UniversalPayload/spec/tree/3f1450d [2] https://patchwork.ozlabs.org/project/uboot/list/?series=438574&state=* Link: https://lore.kernel.org/r/20250111000029.245022-1-sjg@chromium.org
2025-01-22abuf: Provide a constant bufferSimon Glass
Add a new initialiser which can accept a constant pointer. Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-22abuf: Provide a way to get the buffer addressSimon Glass
In many cases it is useful to get the address of a buffer, e.g. when booting from it. Add a function to handle this. Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-18Merge patch series "add the support of sha256_hmac and sha256_hkdf"Tom Rini
Philippe Reynes <philippe.reynes@softathome.com> says: This serie adds the support of sha256_hmac and sha256_hkdf. A first version was sent several months ago just before the integration of mbedtls. This new version is based on mbedtls. The first patch of this serie add the support of hkdf using mbedtls. Link: https://lore.kernel.org/r/20241219130554.49825-1-philippe.reynes@softathome.com
2025-01-18test: lib: add test for key derivationPhilippe Reynes
Adds a test for the function sha256_hkdf. Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> Reviewed-by: Raymond Mao <raymond.mao@linaro.org>
2025-01-18test: lib: add test for sha256_hmacPhilippe Reynes
Adds a test for the function sha256_hmac Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> Reviewed-by: Raymond Mao <raymond.mao@linaro.org>
2024-12-31Merge patch series "Select CONFIG_64BIT for sandbox64 and x86_64"Tom Rini
Andrew Goodbody <andrew.goodbody@linaro.org> says: Picking up a series from Dan Carpenter and applying requested changes for v2. I had previously set CONFIG_64BIT for arm64. This patchset does the same thing for sandbox and x86_64. (Mips and riscv were already doing it). This CONFIG option is used in the Makefile to determine if it's a 32 or 64 bit system for the CHECKER. Makefile 1052 # the checker needs the correct machine size 1053 CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32) Link: https://lore.kernel.org/r/20241216180736.1933807-1-andrew.goodbody@linaro.org
2024-12-31test: lib: Use CONFIG_64BIT to detect 64 bit compileAndrew Goodbody
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>
2024-12-30lmb: Remove lmb_alloc_base_flags()Ilias Apalodimas
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>
2024-12-30lmb: Remove lmb_alloc_addr_flags()Ilias Apalodimas
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>
2024-12-30lmb: Rename free_mem to available_memIlias Apalodimas
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>
2024-12-30lmb: Remove lmb_reserve_flags()Ilias Apalodimas
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>