Jakub Czapiga has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/56257 )
Change subject: tests: Add lib/libgcc-test test case ......................................................................
tests: Add lib/libgcc-test test case
Add tests for src/lib/libgcc.c __clzsi2() implementation. Unlike GCC implementation, coreboot one can handle zero input.
Signed-off-by: Jakub Czapiga jacz@semihalf.com Change-Id: I3f46071d0921e8c5edc5df3c296d11c77de01c88 --- M tests/lib/Makefile.inc A tests/lib/libgcc-test.c 2 files changed, 79 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/56257/1
diff --git a/tests/lib/Makefile.inc b/tests/lib/Makefile.inc index 6750353..028db73 100644 --- a/tests/lib/Makefile.inc +++ b/tests/lib/Makefile.inc @@ -31,6 +31,7 @@ tests-y += spd_cache-ddr3-test tests-y += spd_cache-ddr4-test tests-y += cbmem_stage_cache-test +tests-y += libgcc-test
string-test-srcs += tests/lib/string-test.c string-test-srcs += src/lib/string.c @@ -177,3 +178,5 @@ cbmem_stage_cache-test-cflags += -I 3rdparty/vboot/firmware/include cbmem_stage_cache-test-cflags += -I $(src)/commonlib/include cbmem_stage_cache-test-config += CONFIG_CBMEM_STAGE_CACHE=1 + +libgcc-test-srcs += tests/lib/libgcc-test.c diff --git a/tests/lib/libgcc-test.c b/tests/lib/libgcc-test.c new file mode 100644 index 0000000..a35c537 --- /dev/null +++ b/tests/lib/libgcc-test.c @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include "../lib/libgcc.c" + +#include <tests/test.h> +#include <stdlib.h> +#include <string.h> + +struct { + u32 value; + int expected_output; +} test_data[] = { + /* GCC documentation says, __clzsi2() has undefined result for zero as an input value, + but coreboot implementation can handle this. */ + { .value = 0, .expected_output = 32 }, + + { .value = 1, .expected_output = 31 }, + { .value = 2, .expected_output = 30 }, + { .value = 3, .expected_output = 30 }, + { .value = 4, .expected_output = 29 }, + { .value = 5, .expected_output = 29 }, + { .value = 6, .expected_output = 29 }, + { .value = 7, .expected_output = 29 }, + + { .value = 0xF, .expected_output = 28 }, + { .value = 0x10, .expected_output = 27 }, + { .value = 0x25, .expected_output = 26 }, + { .value = 0x5D, .expected_output = 25 }, + { .value = 0xB7, .expected_output = 24 }, + + { .value = 0x133, .expected_output = 23 }, + { .value = 0x3DC, .expected_output = 22 }, + { .value = 0x6F1, .expected_output = 21 }, + { .value = 0x897, .expected_output = 20 }, + + { .value = 0x1FFF, .expected_output = 19 }, + { .value = 0x2222, .expected_output = 18 }, + { .value = 0x7BAD, .expected_output = 17 }, + { .value = 0xE708, .expected_output = 16 }, + + { .value = 0x1DABD, .expected_output = 15 }, + { .value = 0x29876, .expected_output = 14 }, + { .value = 0x56665, .expected_output = 13 }, + { .value = 0xABCDE, .expected_output = 12 }, + + { .value = 0x18365F, .expected_output = 11 }, + { .value = 0x3D0115, .expected_output = 10 }, + { .value = 0x4B07EB, .expected_output = 9 }, + { .value = 0xCCC74D, .expected_output = 8 }, + + { .value = 0x17933ED, .expected_output = 7 }, + { .value = 0x2B00071, .expected_output = 6 }, + { .value = 0x4D4C1A5, .expected_output = 5 }, + { .value = 0xAD01FFF, .expected_output = 4 }, + + { .value = 0x1C5A8057, .expected_output = 3 }, + { .value = 0x35AB23C3, .expected_output = 2 }, + { .value = 0x7017013B, .expected_output = 1 }, + { .value = 0xAD01EB15, .expected_output = 0 }, +}; + +void test_clzsi2_with_data(void **state) +{ + for (int i = 0; i < ARRAY_SIZE(test_data); ++i) + assert_int_equal(test_data[i].expected_output, __clzsi2(test_data[i].value)); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_clzsi2_with_data), + }; + + + return cmocka_run_group_tests(tests, NULL, NULL); +}