
Add unit tests for library functions __ashldi3() and __lshrdi3).
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- v2: new patch --- test/lib/Makefile | 2 ++ test/lib/bitops.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 test/lib/bitops.c
diff --git a/test/lib/Makefile b/test/lib/Makefile index 7e7922fe3b..ade934dab7 100644 --- a/test/lib/Makefile +++ b/test/lib/Makefile @@ -2,7 +2,9 @@ # # (C) Copyright 2018 # Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc + ifeq ($(CONFIG_SPL_BUILD),) +obj-$(CONFIG_RISCV) += bitops.o obj-y += cmd_ut_lib.o obj-y += abuf.o obj-$(CONFIG_EFI_LOADER) += efi_device_path.o diff --git a/test/lib/bitops.c b/test/lib/bitops.c new file mode 100644 index 0000000000..14813c34b5 --- /dev/null +++ b/test/lib/bitops.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include <test/lib.h> +#include <test/test.h> +#include <test/ut.h> + +long __ashldi3(long a, int b); +long __lshrdi3(long a, int b); + +/** + * lib_ashldi3() - unit test for __ashldi3() + * + * @uts: unit test state + * Return: 0 = success, 1 = failure + */ +static int lib_ashldi3(struct unit_test_state *uts) +{ + long actual, expected, val; + int bits = 4; + + switch (sizeof(long)) { + case 8: + val = (long)0xf6fa765251b9a6c7; + expected = (long)0x6fa765251b9a6c70; + break; + case 4: + val = 0x51b9a6c7; + expected = 0x1b9a6c70; + break; + default: + ut_assert(false); + } + + actual = __ashldi3(val, bits); + ut_asserteq(expected, actual); + + return 0; +} +LIB_TEST(lib_ashldi3, 0); + +/** + * lib_lshrdi3() - unit test for __lshrdi3() + * + * @uts: unit test state + * Return: 0 = success, 1 = failure + */ +static int lib_lshrdi3(struct unit_test_state *uts) +{ + long actual, expected, val; + int bits = 4; + + switch (sizeof(long)) { + case 8: + val = (long)0xf6fa765251b9a6c7; + expected = (long)0x0f6fa765251b9a6c; + break; + case 4: + val = 0x51b9a6c7; + expected = 0x051b9a6c; + break; + default: + ut_assert(false); + } + + actual = __lshrdi3(val, bits); + ut_asserteq(expected, actual); + + return 0; +} +LIB_TEST(lib_lshrdi3, 0);