summaryrefslogtreecommitdiff
path: root/test/lib
AgeCommit message (Collapse)AuthorFilesLines
2021-07-27test: Fix size_t formats in strlcat testSimon Glass1-2/+2
Some of the printf() formats do not match their types. Fix this. Reported-by: Minkyu Kang <mk7.kang@samsung.com> Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Minkyu Kang <mk7.kang@samsung.com>
2021-07-23lib: wrap crypt API to hide errno usageSteffen Jaeckel1-2/+22
In order to prevent using the global errno, replace it with a static version and create a wrapper function which returns the error value. Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heiko Schocher <hs@denx.de>
2021-07-23lib: add crypt subsystemSteffen Jaeckel2-0/+45
Add the basic functionality required to support the standard crypt format. The files crypt-sha256.c and crypt-sha512.c originate from libxcrypt and their formatting is therefor retained. The integration is done via a crypt_compare() function in crypt.c. ``` libxcrypt $ git describe --long --always --all tags/v4.4.17-0-g6b110bc ``` Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heiko Schocher <hs@denx.de>
2021-06-07test: lmb: add test for lmb_reserve_flagsPatrick Delaunay1-0/+89
Add a test to check the management of reserved region with flags. Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-04-22test: lmb: add test for overflow protection in lmb_add_regionPatrick Delaunay1-0/+64
Add test for max number of memory regions and in reserved regions. Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
2021-04-13test: Add test for strlcatSean Anderson2-0/+127
This test is adapted from glibc, which is very concerned about alignment. It also tests strlcpy by dependency. Signed-off-by: Sean Anderson <seanga2@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2021-04-08test: unit test for longjmpHeinrich Schuchardt2-0/+74
Provide a unit test for the longjmp() library function Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Acked-by: Sean Anderson <seanga2@gmail.com>
2021-03-27test: Silenece the echo and print testsSimon Glass1-2/+6
These tests current produce unwanted output on sandbox. Use the correct functions to controller console output, to avoid this. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-12test: Add a macros for finding tests in linker_listsSimon Glass1-2/+2
At present we use the linker list directly. This is not very friendly, so add a helpful macro instead. This will also allow us to change the naming later without updating this code. Signed-off-by: Simon Glass <sjg@chromium.org>
2021-02-02common: Drop asm/global_data.h from common headerSimon Glass1-0/+1
Move this out of the common header and include it only where needed. In a number of cases this requires adding "struct udevice;" to avoid adding another large header or in other cases replacing / adding missing header files that had been pulled in, very indirectly. Finally, we have a few cases where we did not need to include <asm/global_data.h> at all, so remove that include. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Rini <trini@konsulko.com>
2021-01-16test: test/lib/test_print.c depends on CONSOLE_RECORDHeinrich Schuchardt1-1/+1
The tests in test/lib/test_print.c fail without CONFIG_CONSOLE_RECORD=y. Add a build dependency. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2020-10-30test: Add a test for getoptSean Anderson2-0/+124
A few of these tests were inspired by those in glibc. The syntax for invoking test_getopt is a bit funky, but it's necessary so that the CPP can parse the arguments correctly. Signed-off-by: Sean Anderson <seanga2@gmail.com>
2020-10-23test: unit tests for print_freq(), print_size()Heinrich Schuchardt2-0/+72
Provide unit tests for functions print_freq() and print_size(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-08-27test: undefined reference to 'sscanf'Heinrich Schuchardt1-1/+1
Compiling with CONFIG_UNIT_TEST=y leads to: aarch64-linux-gnu-ld.bfd: test/lib/sscanf.c:50: undefined reference to `sscanf' Add missing build dependency. Fixes:e87dfb0526be ("lib: sscanf: add sscanf implementation") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-08-24test: unit test for efi_dp_check_length()Heinrich Schuchardt2-0/+51
Provide a unit test for function efi_dp_check_length(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-08-14lib: sscanf: add sscanf implementationAndrii Anisov2-0/+175
Port sscanf implementation from mini-os and introduce new Kconfig option to enable it: CONFIG_SSCANF. Disable by default. Signed-off-by: Andrii Anisov <andrii_anisov@epam.com> Signed-off-by: Anastasiia Lukianenko <anastasiia_lukianenko@epam.com> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
2020-08-08dm: Rename DM test flags to make them more genericSimon Glass1-9/+9
The test flags used by driver model are currently not available to other tests. Rather than creating two sets of flags, make these flags generic by changing the DM_ prefix to UT_ and moving them to the test.h header. This will allow adding other test flags without confusion. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-08-04dm: core: Drop header files from dm/test.hSimon Glass1-0/+2
These header file should not be included in other header files. Remove them and add to each individual file. Add test/test.h to test/ui.h since that is a reasonable place. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-07-03test: provide tests for efi_image_region_add()Heinrich Schuchardt2-0/+164
Provide unit tests for efi_image_region_add(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-05-19common: Drop log.h from common headerSimon Glass2-0/+2
Move this header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-19command: Remove the cmd_tbl_t typedefSimon Glass1-1/+1
We should not use typedefs in U-Boot. They cannot be used as forward declarations which means that header files must include the full header to access them. Drop the typedef and rename the struct to remove the _s suffix which is now not useful. This requires quite a few header-file additions. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-19common: Drop net.h from common headerSimon Glass1-0/+1
Move this header out of the common header. Network support is used in quite a few places but it still does not warrant blanket inclusion. Note that this net.h header itself has quite a lot in it. It could be split into the driver-mode support, functions, structures, checksumming, etc. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-04lib/crypto, efi_loader: move some headers to include/cryptoAKASHI Takahiro1-2/+2
Pkcs7_parse.h and x509_parser.h are used in UEFI subsystem, in particular, secure boot. So move them to include/crypto to avoid relative paths. Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Don't include include x509_parser.h twice. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-03-12test: add rsa_verify() unit testAKASHI Takahiro2-0/+207
In this patch, a very simple test is added to verify that rsa_verify() using rsa_verify_with_pkey() work correctly. To keep the code simple, all the test data, either public key and verified binary data, are embedded in the source. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2020-02-13test: aes: fix memleakPhilippe Reynes1-6/+7
In the first version, the result of malloc is checked with ut_assertnonnull. But on a fail, this macro exit the function, so previously malloc are not freed. So to avoid a memleak, we don't use ut_assertnonnull, but simply check the return of malloc. If one has failed, we freed all the allocated memory and quit the function. Reported-by: Coverity (CID: 284403) Reported-by: Coverity (CID: 284404) Reported-by: Coverity (CID: 284405) Reported-by: Coverity (CID: 284406) Reported-by: Coverity (CID: 284407) Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
2020-02-06dm: core: Create a new header file for 'compat' featuresSimon Glass1-0/+1
At present dm/device.h includes the linux-compatible features. This requires including linux/compat.h which in turn includes a lot of headers. One of these is malloc.h which we thus end up including in every file in U-Boot. Apart from the inefficiency of this, it is problematic for sandbox which needs to use the system malloc() in some files. Move the compatibility features into a separate header file. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-01-17aes: add test unit for aes196 and aes256Philippe Reynes1-0/+4
This commit add test unit for aes196 and aes256. Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2020-01-17aes: add test unit for aes128Philippe Reynes2-0/+163
This commit add test unit for aes128. Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2020-01-07cmd_ut: add a parameter prefix to the function cmd_ut_categoryPhilippe Reynes1-1/+1
There is black magic in the file conftest.py that list all the test unit. Then, all those test unit are called in pytest. This call is done with the end of the name (for example checksum if the full name is bloblist_test_checksum). The result is that only test for dm are really executed. by pytest, all others tests are listed but never executed. This behaviour happens because the dm test unit only check the end of the name and others tests checks the full name. To fix this issue, I've added a prefix to the function cmd_ut_category, and this prefix is removed when looking for the unit test. Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-12-07test: add asn1 unit testAKASHI Takahiro2-0/+393
This test will exercise asn1 compiler as well as asn1 decoder functions via various parsers. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2019-10-31test: provide test for errno_str()Heinrich Schuchardt2-0/+47
Provide a unit test for errno_str(). Test that known and unknown error numbers are handled correctly. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2019-04-23test: call hexdump tests via `ut lib`Heinrich Schuchardt1-4/+5
The unit tests in test/lib/hexdump.c are not related to the device tree. So they should be executed via `ut lib` and not via `ut dm`. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
2019-02-09test: provide unit test for memory functionsHeinrich Schuchardt3-0/+216
Memory functions may have architecture specific implementations. These should be tested. Provide unit tests for memset(), memcpy(), memmove(). Provide a 'ut lib' sub-command to execute the tests. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2019-02-02test: lib: lmb: add lmb test for multiple RAM banksSimon Goldschmidt1-19/+75
This adds one test case that checks that allocation with multiple DRAM banks works correctly. Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2019-01-26lib: lmb: rename lmb_get_unreserved_size to lmb_get_free_sizeSimon Goldschmidt1-11/+11
As a follow-up, change the name of the newly introduced function 'lmb_get_unreserved_size' to 'lmb_get_free_size', which is more appropriate. Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> [trini: Fix test/lib/lmb.c] Signed-off-by: Tom Rini <trini@konsulko.com>
2019-01-17lib: lmb: extend lmb for checks at load timeSimon Goldschmidt1-0/+202
This adds two new functions, lmb_alloc_addr and lmb_get_unreserved_size. lmb_alloc_addr behaves like lmb_alloc, but it tries to allocate a pre-specified address range. Unlike lmb_reserve, this address range must be inside one of the memory ranges that has been set up with lmb_add. lmb_get_unreserved_size returns the number of bytes that can be used up to the next reserved region or the end of valid ram. This can be 0 if the address passed is reserved. Added test for these new functions. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
2019-01-17lib: lmb: reserving overlapping regions should failSimon Goldschmidt1-8/+87
lmb_add_region handles overlapping regions wrong: instead of merging or rejecting to add a new reserved region that overlaps an existing one, it just adds the new region. Since internally the same function is used for lmb_alloc, change lmb_add_region to reject overlapping regions. Also, to keep reserved memory correct after 'free', reserved entries created by allocating memory must not set their size to a multiple of alignment but to the original size. This ensures the reserved region is completely removed when the caller calls 'lmb_free', as this one takes the same size as passed to 'lmb_alloc' etc. Add test to assert this. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
2019-01-17lmb: fix allocation at end of address rangeSimon Goldschmidt1-3/+26
The lmb code fails if base + size of RAM overflows to zero. Fix this by calculating end as 'base + size - 1' instead of 'base + size' where appropriate. Added tests to assert this is fixed. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
2019-01-17test: add test for lib/lmb.cSimon Goldschmidt2-0/+298
Add basic tests for the lmb memory allocation code used to reserve and allocate memory during boot. Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-12-12test: hexdump: fix misplaced returnSimon Goldschmidt1-2/+2
One of the hexdump tests in test/lib/hexdump.c returns right at the start of the function without testing anything. Fix this by moving the 'return 0;' statement to the end of the function. Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2018-09-28test: list: Add tests for hexdump.cMario Six2-0/+100
Add tests for the hex2bin, bin2hex, and hex_to_bin functions, which were recently added to U-Boot. Signed-off-by: Mario Six <mario.six@gdsys.cc> Reviewed-by: Simon Glass <sjg@chromium.org>