Skip to contentSkip to conversation

lib:tests: add math test suite

PATCH New [email protected] 2 participants 3 messages Jul 1, 2024 – Jul 23, 2024

lore
Share & tools
lore
#0 lore raw

cover lib:tests: add math test suite

From: Dongdong Zhang <[email protected]>

This patch introduces a new math test suite to the SBI unit tests.

Test report on QEMU virt machine:

OpenSBI v1.4-130-ge23526c
____ _____ ____ _____

  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name : riscv-virtio,qemu
Platform Features : medeleg
Platform HART Count : 1
Platform IPI Device : aclint-mswi
Platform Timer Device : aclint-mtimer @ 10000000Hz
Platform Console Device : uart8250
Platform HSM Device : ---
Platform PMU Device : ---
Platform Reboot Device : syscon-reboot
Platform Shutdown Device : syscon-poweroff
Platform Suspend Device : ---
Platform CPPC Device : ---
Firmware Base : 0x80000000
Firmware Size : 327 KB
Firmware RW Offset : 0x40000
Firmware RW Size : 71 KB
Firmware Heap Offset : 0x49000
Firmware Heap Size : 35 KB (total), 2 KB (reserved), 11 KB (used), 21 KB (free)
Firmware Scratch Size : 4096 B (total), 416 B (used), 3680 B (free)
Runtime SBI Version : 2.0

Domain0 Name : root
Domain0 Boot HART : 0
Domain0 HARTs : 0*
Domain0 Region00 : 0x0000000000100000-0x0000000000100fff M: (I,R,W) S/U: (R,W)
Domain0 Region01 : 0x0000000010000000-0x0000000010000fff M: (I,R,W) S/U: (R,W)
Domain0 Region02 : 0x0000000002000000-0x000000000200ffff M: (I,R,W) S/U: ()
Domain0 Region03 : 0x0000000080040000-0x000000008005ffff M: (R,W) S/U: ()
Domain0 Region04 : 0x0000000080000000-0x000000008003ffff M: (R,X) S/U: ()
Domain0 Region05 : 0x000000000c400000-0x000000000c5fffff M: (I,R,W) S/U: (R,W)
Domain0 Region06 : 0x000000000c000000-0x000000000c3fffff M: (I,R,W) S/U: (R,W)
Domain0 Region07 : 0x0000000000000000-0xffffffffffffffff M: () S/U: (R,W,X)
Domain0 Next Address : 0x0000000080200000
Domain0 Next Arg1 : 0x0000000082200000
Domain0 Next Mode : S-mode
Domain0 SysReset : yes
Domain0 SysSuspend : yes

Boot HART ID : 0
Boot HART Domain : root
Boot HART Priv Version : v1.12
Boot HART Base ISA : rv64imafdch
Boot HART ISA Extensions : sstc,zicntr,zihpm,zicboz,zicbom,sdtrig,svadu
Boot HART PMP Count : 16
Boot HART PMP Granularity : 2 bits
Boot HART PMP Address Bits: 54
Boot HART MHPM Info : 16 (0x0007fff8)
Boot HART Debug Triggers : 2 triggers
Boot HART MIDELEG : 0x0000000000001666
Boot HART MEDELEG : 0x0000000000f0b509

# Running SBIUNIT tests #
## Running test suite: bitmap_test_suite
[PASSED] bitmap_and_test
[PASSED] bitmap_or_test
[PASSED] bitmap_xor_test
3 PASSED / 0 FAILED / 3 TOTAL
## Running test suite: console_test_suite
[PASSED] putc_test
[PASSED] puts_test
[PASSED] printf_test
3 PASSED / 0 FAILED / 3 TOTAL
## Running test suite: atomic_test_suite
[PASSED] atomic_rw_test
[PASSED] add_return_test
[PASSED] sub_return_test
[PASSED] cmpxchg_test
[PASSED] atomic_xchg_test
[PASSED] atomic_raw_set_bit_test
[PASSED] atomic_raw_clear_bit_test
[PASSED] atomic_set_bit_test
[PASSED] atomic_clear_bit_test
9 PASSED / 0 FAILED / 9 TOTAL
## Running test suite: locks_test_suite
[PASSED] spin_lock_test
[PASSED] spin_trylock_fail
[PASSED] spin_trylock_success
3 PASSED / 0 FAILED / 3 TOTAL
## Running test suite: math_test_suite
[PASSED] log2roundup_test
1 PASSED / 0 FAILED / 1 TOTAL
## Running test suite: bitops_test_suite
[PASSED] find_first_bit_test
[PASSED] find_first_zero_bit_test
[PASSED] find_last_bit_test
[PASSED] find_next_bit_test
[PASSED] find_next_zero_bit_test
5 PASSED / 0 FAILED / 5 TOTAL

Test payload running
QEMU: Terminated

*************************************************************

Dongdong Zhang (1):
lib:tests: add math test suite

 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
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 lib:tests: add math test suite

From: Dongdong Zhang <[email protected]>

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.

---
 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
lib/sbi/tests/objects.mk +3 -0
index 8f27289..82b6061 100644
@@ -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
lib/sbi/tests/sbi_math_test.c new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.17.1
Applied
#2 lore raw

PATCH 1/1 lib:tests: add math test suite

Quoted 11 lines · On Mon, Jul 1, 2024 at 8:00?AM <[email protected]> wrote:

From: Dongdong Zhang <[email protected]>

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.

Quoted 4 lines

The addition of this test suite ensures that mathematical functions are verified and work as expected.

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.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 78 lines
---
 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
lib/sbi/tests/objects.mk +3 -0
index 8f27289..82b6061 100644
@@ -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
lib/sbi/tests/sbi_math_test.c new file +46 -1
new file mode 100644
index 0000000..81ed832
@@ -0,0 +1,46 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright  2024  Beijing ESWIN Computing Technology Co., Ltd.
+ *
+ * Author: Dongdong Zhang <[email protected]>
+ */
+#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 at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi