mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2025-12-19 08:21:27 +01:00
test: provide unit tests for the RISC-V private GCC library
Add unit tests for the functions for counting leading and trailing zero bits. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
This commit is contained in:
parent
dd0ad45920
commit
cf386262d5
@ -10,6 +10,10 @@ obj-y += abuf.o
|
||||
obj-y += alist.o
|
||||
obj-$(CONFIG_EFI_LOADER) += efi_device_path.o efi_memory.o
|
||||
obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o
|
||||
ifdef CONFIG_RISCV
|
||||
obj-$(CONFIG_USE_PRIVATE_LIBGCC) += test_clz.o
|
||||
obj-$(CONFIG_USE_PRIVATE_LIBGCC) += test_ctz.o
|
||||
endif
|
||||
obj-y += hexdump.o
|
||||
obj-$(CONFIG_SANDBOX) += kconfig.o
|
||||
obj-y += lmb.o
|
||||
|
||||
53
test/lib/test_clz.c
Normal file
53
test/lib/test_clz.c
Normal file
@ -0,0 +1,53 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* Copyright 2025, Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
|
||||
*/
|
||||
|
||||
#include <test/lib.h>
|
||||
#include <test/test.h>
|
||||
#include <test/ut.h>
|
||||
|
||||
int __clzsi2(int a);
|
||||
int __clzdi2(long a);
|
||||
int __clzti2(long long a);
|
||||
|
||||
/**
|
||||
* test_clz() - test library functions to count leading zero bits
|
||||
*
|
||||
* @uts: unit test state
|
||||
*/
|
||||
static int test_clz(struct unit_test_state *uts)
|
||||
{
|
||||
ut_asserteq(0, __clzti2(0xffffffffffffffffLL));
|
||||
ut_asserteq(0, __clzti2(0x8000000000000000LL));
|
||||
ut_asserteq(1, __clzti2(0x4000000000000000LL));
|
||||
ut_asserteq(17, __clzti2(0x0000500000a00000LL));
|
||||
ut_asserteq(62, __clzti2(0x0000000000000002LL));
|
||||
ut_asserteq(63, __clzti2(0x0000000000000001LL));
|
||||
|
||||
#if BITS_PER_LONG == 64
|
||||
ut_asserteq(0, __clzdi2(0xffffffffffffffffLL));
|
||||
ut_asserteq(0, __clzti2(0x8000000000000000LL));
|
||||
ut_asserteq(1, __clzti2(0x4000000000000000LL));
|
||||
ut_asserteq(17, __clzdi2(0x0000500000a00000LL));
|
||||
ut_asserteq(62, __clzdi2(0x0000000000000002LL));
|
||||
ut_asserteq(63, __clzdi2(0x0000000000000001LL));
|
||||
#else
|
||||
ut_asserteq(0, __clzdi2(0xffffffff));
|
||||
ut_asserteq(0, __clzdi2(0x80000000));
|
||||
ut_asserteq(1, __clzdi2(0x40000000));
|
||||
ut_asserteq(9, __clzdi2(0x0050a000));
|
||||
ut_asserteq(30, __clzdi2(0x00000002));
|
||||
ut_asserteq(31, __clzdi2(0x00000001));
|
||||
#endif
|
||||
|
||||
ut_asserteq(0, __clzsi2(0xffffffff));
|
||||
ut_asserteq(0, __clzsi2(0x80000000));
|
||||
ut_asserteq(1, __clzsi2(0x40000000));
|
||||
ut_asserteq(9, __clzsi2(0x0050a000));
|
||||
ut_asserteq(30, __clzsi2(0x00000002));
|
||||
ut_asserteq(31, __clzsi2(0x00000001));
|
||||
|
||||
return 0;
|
||||
}
|
||||
LIB_TEST(test_clz, 0);
|
||||
53
test/lib/test_ctz.c
Normal file
53
test/lib/test_ctz.c
Normal file
@ -0,0 +1,53 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
/*
|
||||
* Copyright 2025, Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
|
||||
*/
|
||||
|
||||
#include <test/lib.h>
|
||||
#include <test/test.h>
|
||||
#include <test/ut.h>
|
||||
|
||||
int __ctzsi2(int a);
|
||||
int __ctzdi2(long a);
|
||||
int __ctzti2(long long a);
|
||||
|
||||
/**
|
||||
* test_ctz() - test library functions to count trailing zero bits
|
||||
*
|
||||
* @uts: unit test state
|
||||
*/
|
||||
static int test_ctz(struct unit_test_state *uts)
|
||||
{
|
||||
ut_asserteq(0, __ctzti2(0xffffffffffffffffLL));
|
||||
ut_asserteq(63, __ctzti2(0x8000000000000000LL));
|
||||
ut_asserteq(62, __ctzti2(0x4000000000000000LL));
|
||||
ut_asserteq(21, __ctzti2(0x0000500000a00000LL));
|
||||
ut_asserteq(1, __ctzti2(0x0000000000000002LL));
|
||||
ut_asserteq(0, __ctzti2(0x0000000000000001LL));
|
||||
|
||||
#if BITS_PER_LONG == 64
|
||||
ut_asserteq(0, __ctzdi2(0xffffffffffffffffLL));
|
||||
ut_asserteq(63, __ctzdi2(0x8000000000000000LL));
|
||||
ut_asserteq(62, __ctzdi2(0x4000000000000000LL));
|
||||
ut_asserteq(21, __ctzdi2(0x0000500000a00000LL));
|
||||
ut_asserteq(1, __ctzdi2(0x0000000000000002LL));
|
||||
ut_asserteq(0, __ctzdi2(0x0000000000000001LL));
|
||||
#else
|
||||
ut_asserteq(0, __ctzdi2(0xffffffff));
|
||||
ut_asserteq(31, __ctzdi2(0x80000000));
|
||||
ut_asserteq(30, __ctzdi2(0x40000000));
|
||||
ut_asserteq(13, __ctzdi2(0x0050a000));
|
||||
ut_asserteq(1, __ctzdi2(0x00000002));
|
||||
ut_asserteq(0, __ctzdi2(0x00000001));
|
||||
#endif
|
||||
|
||||
ut_asserteq(0, __ctzsi2(0xffffffff));
|
||||
ut_asserteq(31, __ctzsi2(0x80000000));
|
||||
ut_asserteq(30, __ctzsi2(0x40000000));
|
||||
ut_asserteq(13, __ctzsi2(0x0050a000));
|
||||
ut_asserteq(1, __ctzsi2(0x00000002));
|
||||
ut_asserteq(0, __ctzsi2(0x00000001));
|
||||
|
||||
return 0;
|
||||
}
|
||||
LIB_TEST(test_ctz, 0);
|
||||
Loading…
x
Reference in New Issue
Block a user