lib: add tests for sbi_ecall functionality
PATCH 1/1 lib: add tests for sbi_ecall functionality
This patch adds unit tests for verifying the sbi_ecall version, impid handling, and extension registration functions. The tests ensure that the extension registration and unregistration work as expected.
--- lib/sbi/tests/objects.mk | 5 +++- lib/sbi/tests/sbi_ecall_test.c | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 lib/sbi/tests/sbi_ecall_test.c
lib/sbi/tests/objects.mk +4 -1
@@ -14,4 +14,7 @@ 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 +libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_math_test.o + +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += ecall_test_suite +libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_ecall_test.o
lib/sbi/tests/sbi_ecall_test.c new file +49 -0
50 lines not on this page · raw message
Signature · 1 line
2.34.1
Anup Patel
AppliedPATCH 1/1 lib: add tests for sbi_ecall functionality
HI Akshay,
Quoted 7 lines · On Wed, Feb 19, 2025 at 12:08?AM Akshay Behl <[email protected]> wrote:
This patch adds unit tests for verifying the
sbi_ecallversion, impid handling, and extension registration functions. The tests ensure that the extension registration and unregistration work as expected.Signed-off-by Akshay Behl <[email protected]>
Overall, the patch looks good but please use tabs for alignment instead of spaces.
Quoted 47 lines
--- lib/sbi/tests/objects.mk | 5 +++- lib/sbi/tests/sbi_ecall_test.c | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 lib/sbi/tests/sbi_ecall_test.clib/sbi/tests/objects.mk +4
-1@@ -14,4 +14,7 @@ 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 +libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_math_test.o + +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += ecall_test_suite +libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_ecall_test.olib/sbi/tests/sbi_ecall_test.c new file +20
-0@@ -0,0 +1,49 @@ +#include <sbi/sbi_unit_test.h> +#include <sbi/sbi_ecall.h> + +static void test_sbi_ecall_version (struct sbiunit_test_case *test) +{ +SBIUNIT_EXPECT_EQ (test,sbi_ecall_version_major (),SBI_ECALL_VERSION_MAJOR ); +SBIUNIT_EXPECT_EQ (test,sbi_ecall_version_minor (),SBI_ECALL_VERSION_MINOR ); +} + +static void test_sbi_ecall_impid (struct sbiunit_test_case *test) +{ +unsigned long old_impid =sbi_ecall_get_impid (); +sbi_ecall_set_impid (42 ); +SBIUNIT_EXPECT_EQ (test,sbi_ecall_get_impid (),42 ); +sbi_ecall_set_impid (old_impid); +} + +static int dummy_handler (unsigned long extid,unsigned long funcid, +struct sbi_trap_regs *regs, +struct sbi_ecall_return *out)
lib/sbi/tests/sbi_ecall_test.c line 30
Quoted 10 lines
lib/sbi/tests/sbi_ecall_test.c new file +10
-0+{ +return 0 ; +} + +static void test_sbi_ecall_register_find_extension (struct sbiunit_test_case *test) +{ +struct sbi_ecall_extension test_ext = { +/*large extid_start for no overlap*/ + .extid_start =0x80 , + .extid_end =0x80 ,
We should use SBI experimental extension ID over here.
Quoted 24 lines
lib/sbi/tests/sbi_ecall_test.c new file +19
-1+ .name = "TestExt", + .handle = dummy_handler, + }; + +SBIUNIT_EXPECT_EQ (test,sbi_ecall_register_extension (&test_ext),0 ); +SBIUNIT_EXPECT_EQ (test,sbi_ecall_find_extension (0x80 ), &test_ext); + +sbi_ecall_unregister_extension (&test_ext); +SBIUNIT_EXPECT_EQ (test,sbi_ecall_find_extension (0x80 ),NULL ); +} + +static struct sbiunit_test_case ecall_tests[] = { +SBIUNIT_TEST_CASE (test_sbi_ecall_version), +SBIUNIT_TEST_CASE (test_sbi_ecall_impid), +SBIUNIT_TEST_CASE (test_sbi_ecall_register_find_extension), +SBIUNIT_END_CASE , +}; + +SBIUNIT_TEST_SUITE (ecall_test_suite, ecall_tests); --2.34.1
Quoted 4 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
I have taken care of the above comments at the time of merging this patch.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup