Message ID | 20240701023006.16977-2-zhangdongdong@eswincomputing.com |
---|---|
State | Accepted |
Headers | show |
Series | lib:tests: add math test suite | expand |
On Mon, Jul 1, 2024 at 8:00 AM <zhangdongdong@eswincomputing.com> wrote: > > From: Dongdong Zhang <zhangdongdong@eswincomputing.com> > > This patch introduces a new math test suite to the SBI unit > tests. The changes include: > > * Updating lib/sbi/tests/objects.mk to include > math_test_suite and sbi_math_test.o. > * Adding a new file lib/sbi/tests/sbi_math_test.c which > contains tests for log2roundup function using various cases. > > The addition of this test suite ensures that mathematical > functions are verified and work as expected. > > Signed-off-by: Dongdong Zhang <zhangdongdong@eswincomputing.com> Need a space between "lib:" and "tests:" in the patch subject. Otherwise, looks good to me. I will take care of this at the time of merging this patch. Reviewed-by: Anup Patel <anup@brainfault.org> Applied this patch to the riscv/opensbi repo. Thanks, Anup > --- > lib/sbi/tests/objects.mk | 3 +++ > lib/sbi/tests/sbi_math_test.c | 46 +++++++++++++++++++++++++++++++++++ > 2 files changed, 49 insertions(+) > create mode 100644 lib/sbi/tests/sbi_math_test.c > > diff --git a/lib/sbi/tests/objects.mk b/lib/sbi/tests/objects.mk > index 8f27289..82b6061 100644 > --- a/lib/sbi/tests/objects.mk > +++ b/lib/sbi/tests/objects.mk > @@ -12,3 +12,6 @@ libsbi-objs-$(CONFIG_SBIUNIT) += tests/riscv_atomic_test.o > > carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += locks_test_suite > libsbi-objs-$(CONFIG_SBIUNIT) += tests/riscv_locks_test.o > + > +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += math_test_suite > +libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_math_test.o > \ No newline at end of file > diff --git a/lib/sbi/tests/sbi_math_test.c b/lib/sbi/tests/sbi_math_test.c > new file mode 100644 > index 0000000..81ed832 > --- /dev/null > +++ b/lib/sbi/tests/sbi_math_test.c > @@ -0,0 +1,46 @@ > +/* > + * SPDX-License-Identifier: BSD-2-Clause > + * > + * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd. > + * > + * Author: Dongdong Zhang <zhangdongdong@eswincomputing.com> > + */ > +#include <sbi/sbi_math.h> > +#include <sbi/sbi_unit_test.h> > + > +static void log2roundup_test(struct sbiunit_test_case *test) > +{ > + struct { > + unsigned long input; > + unsigned long expected; > + } cases[] = { > + {1, 0}, > + {2, 1}, > + {3, 2}, > + {4, 2}, > + {5, 3}, > + {8, 3}, > + {9, 4}, > + {15, 4}, > + {16, 4}, > + {17, 5}, > + {31, 5}, > + {32, 5}, > + {33, 6}, > + {63, 6}, > + {64, 6}, > + {65, 7}, > + }; > + > + for (int i = 0; i < sizeof(cases)/sizeof(cases[0]); i++) { > + unsigned long result = log2roundup(cases[i].input); > + SBIUNIT_EXPECT_EQ(test, result, cases[i].expected); > + } > +} > + > +static struct sbiunit_test_case math_test_cases[] = { > + SBIUNIT_TEST_CASE(log2roundup_test), > + SBIUNIT_END_CASE, > +}; > + > +SBIUNIT_TEST_SUITE(math_test_suite, math_test_cases); > -- > 2.17.1 > > > -- > opensbi mailing list > opensbi@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/opensbi
diff --git a/lib/sbi/tests/objects.mk b/lib/sbi/tests/objects.mk index 8f27289..82b6061 100644 --- a/lib/sbi/tests/objects.mk +++ b/lib/sbi/tests/objects.mk @@ -12,3 +12,6 @@ libsbi-objs-$(CONFIG_SBIUNIT) += tests/riscv_atomic_test.o carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += locks_test_suite libsbi-objs-$(CONFIG_SBIUNIT) += tests/riscv_locks_test.o + +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += math_test_suite +libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_math_test.o \ No newline at end of file diff --git a/lib/sbi/tests/sbi_math_test.c b/lib/sbi/tests/sbi_math_test.c new file mode 100644 index 0000000..81ed832 --- /dev/null +++ b/lib/sbi/tests/sbi_math_test.c @@ -0,0 +1,46 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd. + * + * Author: Dongdong Zhang <zhangdongdong@eswincomputing.com> + */ +#include <sbi/sbi_math.h> +#include <sbi/sbi_unit_test.h> + +static void log2roundup_test(struct sbiunit_test_case *test) +{ + struct { + unsigned long input; + unsigned long expected; + } cases[] = { + {1, 0}, + {2, 1}, + {3, 2}, + {4, 2}, + {5, 3}, + {8, 3}, + {9, 4}, + {15, 4}, + {16, 4}, + {17, 5}, + {31, 5}, + {32, 5}, + {33, 6}, + {63, 6}, + {64, 6}, + {65, 7}, + }; + + for (int i = 0; i < sizeof(cases)/sizeof(cases[0]); i++) { + unsigned long result = log2roundup(cases[i].input); + SBIUNIT_EXPECT_EQ(test, result, cases[i].expected); + } +} + +static struct sbiunit_test_case math_test_cases[] = { + SBIUNIT_TEST_CASE(log2roundup_test), + SBIUNIT_END_CASE, +}; + +SBIUNIT_TEST_SUITE(math_test_suite, math_test_cases);