Move tests to the 'tests' directory
cover Move tests to the 'tests' directory
As it was suggested by Anup Patel <[email protected]>, the tests should be moved to the separate directory lib/sbi/tests. This patch series puts the test-related code into the right place and updates the documentation correspondingly.
Ivan Orlov (2):
lib: tests: Move tests to a separate directory
docs/writing_tests: Update tests paths
Makefile | 2 ++
docs/writing_tests.md | 21 ++++++++++-----------
lib/sbi/objects.mk | 6 ------
lib/sbi/sbi_console.c | 2 +-
lib/sbi/tests/objects.mk | 6 ++++++
lib/sbi/{ => tests}/sbi_bitmap_test.c | 0
lib/sbi/{ => tests}/sbi_console_test.c | 0
lib/sbi/{ => tests}/sbi_unit_test.c | 0
lib/sbi/{ => tests}/sbi_unit_tests.carray | 0
9 files changed, 19 insertions(+), 18 deletions(-)
create mode 100644 lib/sbi/tests/objects.mk
rename lib/sbi/{ => tests}/sbi_bitmap_test.c (100%)
rename lib/sbi/{ => tests}/sbi_console_test.c (100%)
rename lib/sbi/{ => tests}/sbi_unit_test.c (100%)
rename lib/sbi/{ => tests}/sbi_unit_tests.carray (100%)Signature · 1 line
2.34.1
PATCH 1/2 lib: tests: Move tests to a separate directory
Move all of the SBIUnit-related code into the lib/sbi/tests directory. Update 'Makefile' to index objects from the tests subdirectory.
I don't think creating the full separate list of Makefile variables (libsbitests-objs-path-y, libsbitests-object-mks, etc. as it is done for libsbiutils) is necessary for the tests because:
1) lib/sbi/tests/objects.mk is already indexed into 'libsbi-objects-mks' since the find expression for the libsbi-object-mks variable looks for objects.mk files in the nested directories as well).
2) Tests are tightly coupled with the lib/sbi/ sources, therefore it may be reasonable to store the list of lib/sbi and lib/sbi/tests object files together in the libsbi-objs-path-y variable.
Additionally, update relative paths in the tests where necessary.
---
Makefile | 2 ++
lib/sbi/objects.mk | 6 ------
lib/sbi/sbi_console.c | 2 +-
lib/sbi/tests/objects.mk | 6 ++++++
lib/sbi/{ => tests}/sbi_bitmap_test.c | 0
lib/sbi/{ => tests}/sbi_console_test.c | 0
lib/sbi/{ => tests}/sbi_unit_test.c | 0
lib/sbi/{ => tests}/sbi_unit_tests.carray | 0
8 files changed, 9 insertions(+), 7 deletions(-)
create mode 100644 lib/sbi/tests/objects.mk
rename lib/sbi/{ => tests}/sbi_bitmap_test.c (100%)
rename lib/sbi/{ => tests}/sbi_console_test.c (100%)
rename lib/sbi/{ => tests}/sbi_unit_test.c (100%)
rename lib/sbi/{ => tests}/sbi_unit_tests.carray (100%)Makefile +2 -0
@@ -247,6 +247,8 @@ include $(firmware-object-mks) # Setup list of objects libsbi-objs-path-y=$(foreach obj,$(libsbi-objs-y),$(build_dir)/lib/sbi/$(obj)) +# Index unit tests +libsbi-objs-path-y+=$(foreach obj,$(libsbitests-objs-y),$(build_dir)/lib/sbi/tests/$(obj)) ifdef PLATFORM libsbiutils-objs-path-y=$(foreach obj,$(libsbiutils-objs-y),$(platform_build_dir)/lib/utils/$(obj)) platform-objs-path-y=$(foreach obj,$(platform-objs-y),$(platform_build_dir)/$(obj))
lib/sbi/objects.mk +0 -6
@@ -11,12 +11,6 @@ libsbi-objs-y += riscv_asm.o libsbi-objs-y += riscv_atomic.o libsbi-objs-y += riscv_hardfp.o libsbi-objs-y += riscv_locks.o -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o - -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.o -carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite -carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += console_test_suite libsbi-objs-y += sbi_ecall.o libsbi-objs-y += sbi_ecall_exts.o
lib/sbi/sbi_console.c +1 -1
@@ -490,5 +490,5 @@ int sbi_console_init(struct sbi_scratch *scratch) }#ifdef CONFIG_SBIUNIT -#include "sbi_console_test.c" +#include "tests/sbi_console_test.c" #endif
lib/sbi/tests/objects.mk new file +6 -0
@@ -0,0 +1,6 @@ +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o + +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.o +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += console_test_suite
lib/sbi/tests/sbi_bitmap_test.c renamed from lib/sbi/sbi_bitmap_test.c +0 -0
lib/sbi/tests/sbi_console_test.c renamed from lib/sbi/sbi_console_test.c +0 -0
lib/sbi/tests/sbi_unit_test.c renamed from lib/sbi/sbi_unit_test.c +0 -0
lib/sbi/tests/sbi_unit_tests.carray renamed from lib/sbi/sbi_unit_tests.carray +0 -0
Signature · 1 line
2.34.1
Anup Patel
AppliedPATCH 1/2 lib: tests: Move tests to a separate directory
Quoted 40 lines · On Wed, Mar 13, 2024 at 8:32?PM Ivan Orlov <[email protected]> wrote:
Move all of the SBIUnit-related code into the
lib/sbi/testsdirectory. Update 'Makefile' to index objects from the tests subdirectory.I don't think creating the full separate list of
Makefilevariables (libsbitests-objs-path-y, libsbitests-object-mks, etc. as it is done for libsbiutils) is necessary for the tests because:1)
lib/sbi/tests/objects.mkis already indexed into 'libsbi-objects-mks' since the find expression for the libsbi-object-mks variable looks for objects.mk files in the nested directories as well).2) Tests are tightly coupled with the
lib/sbi/sources, therefore it may be reasonable to store the list of lib/sbi andlib/sbi/testsobject files together in the libsbi-objs-path-y variable.Additionally, update relative paths in the tests where necessary.
Signed-off-by Ivan Orlov <[email protected]>--- Makefile | 2 ++ lib/sbi/objects.mk | 6 ------ lib/sbi/sbi_console.c | 2 +- lib/sbi/tests/objects.mk | 6 ++++++ lib/sbi/{ => tests}/sbi_bitmap_test.c | 0 lib/sbi/{ => tests}/sbi_console_test.c | 0 lib/sbi/{ => tests}/sbi_unit_test.c | 0 lib/sbi/{ => tests}/sbi_unit_tests.carray | 0 8 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 lib/sbi/tests/objects.mk rename lib/sbi/{ => tests}/sbi_bitmap_test.c (100%) rename lib/sbi/{ => tests}/sbi_console_test.c (100%) rename lib/sbi/{ => tests}/sbi_unit_test.c (100%) rename lib/sbi/{ => tests}/sbi_unit_tests.carray (100%)Makefile +0
-0
Makefile include $(firmware-object-mks) · line 251
Quoted 5 lines
Makefile +2
-0@@ -247,6 +247,8 @@ include $(firmware-object-mks) # Setup list of objects libsbi-objs-path-y=$(foreach obj,$(libsbi-objs-y),$(build_dir)/lib/sbi/$(obj)) +# Index unit tests +libsbi-objs-path-y+=$(foreach obj,$(libsbitests-objs-y),$(build_dir)/lib/sbi/tests/$(obj))
No need for changing top-level Makefile.
Quoted 25 lines
Makefile +0
-0ifdef PLATFORM libsbiutils-objs-path-y=$(foreach obj,$(libsbiutils-objs-y),$(platform_build_dir)/lib/utils/$(obj)) platform-objs-path-y=$(foreach obj,$(platform-objs-y),$(platform_build_dir)/$(obj))lib/sbi/objects.mk +0
-6@@ -11,12 +11,6 @@ libsbi-objs-y += riscv_asm.o libsbi-objs-y += riscv_atomic.o libsbi-objs-y += riscv_hardfp.o libsbi-objs-y += riscv_locks.o -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o - -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.o -carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite -carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += console_test_suite libsbi-objs-y += sbi_ecall.o libsbi-objs-y += sbi_ecall_exts.olib/sbi/sbi_console.c +0
-0
lib/sbi/sbi_console.c int sbi_console_init(struct sbi_scratch *scratch) · line 494
Quoted 6 lines
lib/sbi/sbi_console.c +1
-1@@ -490,5 +490,5 @@ int sbi_console_init(struct sbi_scratch *scratch) }#ifdef CONFIG_SBIUNIT -#include "sbi_console_test.c" +#include "tests/sbi_console_test.c" #endif
We can simply drop including "tests/sbi_console_test.c" by relaxing the check in sbi_console_set_device().
lib/sbi/tests/objects.mk line 4
Quoted 10 lines
lib/sbi/tests/objects.mk new file +4
-0@@ -0,0 +1,6 @@ +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o + +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.o
We just need "tests/" prefix to above objects. Just like we do in various objects.mk under utils directory.
Quoted 19 lines
lib/sbi/tests/objects.mk new file +2
-0+carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += console_test_suitelib/sbi/tests/sbi_bitmap_test.c renamed from lib/sbi/sbi_bitmap_test.c +0
-0lib/sbi/tests/sbi_console_test.c renamed from lib/sbi/sbi_console_test.c +0
-0lib/sbi/tests/sbi_unit_test.c renamed from lib/sbi/sbi_unit_test.c +0
-0lib/sbi/tests/sbi_unit_tests.carray renamed from lib/sbi/sbi_unit_tests.carray +0
-1--
Quoted 2 lines
2.34.1
I have taken care of the above minor issues at the time of merging this patch.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
PATCH 1/2 lib: tests: Move tests to a separate directory
Quoted 123 lines · Anup Patel
Quoted 40 lines · On Wed, Mar 13, 2024 at 8:32?PM Ivan Orlov <[email protected]> wrote:
Move all of the SBIUnit-related code into the
lib/sbi/testsdirectory. Update 'Makefile' to index objects from the tests subdirectory.I don't think creating the full separate list of
Makefilevariables (libsbitests-objs-path-y, libsbitests-object-mks, etc. as it is done for libsbiutils) is necessary for the tests because:1)
lib/sbi/tests/objects.mkis already indexed into 'libsbi-objects-mks' since the find expression for the libsbi-object-mks variable looks for objects.mk files in the nested directories as well).2) Tests are tightly coupled with the
lib/sbi/sources, therefore it may be reasonable to store the list of lib/sbi andlib/sbi/testsobject files together in the libsbi-objs-path-y variable.Additionally, update relative paths in the tests where necessary.
Signed-off-by Ivan Orlov <[email protected]>--- Makefile | 2 ++ lib/sbi/objects.mk | 6 ------ lib/sbi/sbi_console.c | 2 +- lib/sbi/tests/objects.mk | 6 ++++++ lib/sbi/{ => tests}/sbi_bitmap_test.c | 0 lib/sbi/{ => tests}/sbi_console_test.c | 0 lib/sbi/{ => tests}/sbi_unit_test.c | 0 lib/sbi/{ => tests}/sbi_unit_tests.carray | 0 8 files changed, 9 insertions(+), 7 deletions(-)create mode 100644
lib/sbi/tests/objects.mkrenamelib/sbi/{=>tests}/sbi_bitmap_test.c(100%) renamelib/sbi/{=>tests}/sbi_console_test.c(100%) renamelib/sbi/{=>tests}/sbi_unit_test.c(100%) renamelib/sbi/{=> tests}/sbi_unit_tests.carray (100%)Makefile +0
-0Makefile include $(firmware-object-mks) · line 251
Quoted 5 lines
Makefile +2
-0@@ -247,6 +247,8 @@ include $(firmware-object-mks) # Setup list of objects libsbi-objs-path-y=$(foreach obj,$(libsbi-objs-y),$(build_dir)/lib/sbi/$(obj)) +# Index unit tests +libsbi-objs-path-y+=$(foreach obj,$(libsbitests-objs-y),$(build_dir)/lib/sbi/tests/$(obj))No need for changing top-level
Makefile.Quoted 25 lines
Makefile +0
-0ifdef PLATFORM libsbiutils-objs-path-y=$(foreach obj,$(libsbiutils-objs-y),$(platform_build_dir)/lib/utils/$(obj)) platform-objs-path-y=$(foreach obj,$(platform-objs-y),$(platform_build_dir)/$(obj))lib/sbi/objects.mk +0
-6@@ -11,12 +11,6 @@ libsbi-objs-y += riscv_asm.o libsbi-objs-y += riscv_atomic.o libsbi-objs-y += riscv_hardfp.o libsbi-objs-y += riscv_locks.o -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o - -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.o -carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite -carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += console_test_suite libsbi-objs-y += sbi_ecall.o libsbi-objs-y += sbi_ecall_exts.olib/sbi/sbi_console.c +0
-0lib/sbi/sbi_console.c int sbi_console_init(struct sbi_scratch *scratch) · line 494
Quoted 6 lines
lib/sbi/sbi_console.c +1
-1@@ -490,5 +490,5 @@ int sbi_console_init(struct sbi_scratch *scratch) }#ifdef CONFIG_SBIUNIT -#include "sbi_console_test.c" +#include "tests/sbi_console_test.c" #endif We can simply drop including "
tests/sbi_console_test.c" by relaxing the check insbi_console_set_device().lib/sbi/tests/objects.mk line 4
Quoted 10 lines
lib/sbi/tests/objects.mk new file +4
-0@@ -0,0 +1,6 @@ +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o + +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.oWe just need "tests/" prefix to above objects. Just like we do in various objects.mk under utils directory.
Quoted 19 lines
lib/sbi/tests/objects.mk new file +2
-0+carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += console_test_suitelib/sbi/tests/sbi_bitmap_test.c renamed from lib/sbi/sbi_bitmap_test.c +0
-0lib/sbi/tests/sbi_console_test.c renamed from lib/sbi/sbi_console_test.c +0
-0lib/sbi/tests/sbi_unit_test.c renamed from lib/sbi/sbi_unit_test.c +0
-0lib/sbi/tests/sbi_unit_tests.carray renamed from lib/sbi/sbi_unit_tests.carray +0
-1--Quoted 2 lines
2.34.1
I have taken care of the above minor issues at the time of merging this patch.
Quoted 4 lines
Reviewed-by Anup Patel <[email protected]>Applied this patch to the riscv/opensbi repo.
Hi Anup,
Thank you so much for the review and for fixing these issues.
Now the documentation should be updated as well, correspondingly with the updates you made: currently, 'writing_tests.md' doc specifies the wrong Makefile variable name for the tests (libsbitests-... instead of libsbi-...). I'll fix it and send the patch today.
Signature · 2 lines
Kind regards, Ivan Orlov
PATCH 1/2 lib: tests: Move tests to a separate directory
Quoted 130 lines · On Tue, Mar 19, 2024 at 9:14?PM Ivan Orlov <[email protected]> wrote:
Quoted 123 lines · Anup Patel
Quoted 40 lines · On Wed, Mar 13, 2024 at 8:32?PM Ivan Orlov <[email protected]> wrote:
Move all of the SBIUnit-related code into the
lib/sbi/testsdirectory. Update 'Makefile' to index objects from the tests subdirectory.I don't think creating the full separate list of
Makefilevariables (libsbitests-objs-path-y, libsbitests-object-mks, etc. as it is done for libsbiutils) is necessary for the tests because:1)
lib/sbi/tests/objects.mkis already indexed into 'libsbi-objects-mks' since the find expression for the libsbi-object-mks variable looks for objects.mk files in the nested directories as well).2) Tests are tightly coupled with the
lib/sbi/sources, therefore it may be reasonable to store the list of lib/sbi andlib/sbi/testsobject files together in the libsbi-objs-path-y variable.Additionally, update relative paths in the tests where necessary.
Signed-off-by Ivan Orlov <[email protected]>--- Makefile | 2 ++ lib/sbi/objects.mk | 6 ------ lib/sbi/sbi_console.c | 2 +- lib/sbi/tests/objects.mk | 6 ++++++ lib/sbi/{ => tests}/sbi_bitmap_test.c | 0 lib/sbi/{ => tests}/sbi_console_test.c | 0 lib/sbi/{ => tests}/sbi_unit_test.c | 0 lib/sbi/{ => tests}/sbi_unit_tests.carray | 0 8 files changed, 9 insertions(+), 7 deletions(-)create mode 100644
lib/sbi/tests/objects.mkrenamelib/sbi/{=>tests}/sbi_bitmap_test.c(100%) renamelib/sbi/{=>tests}/sbi_console_test.c(100%) renamelib/sbi/{=>tests}/sbi_unit_test.c(100%) renamelib/sbi/{=> tests}/sbi_unit_tests.carray (100%)Makefile +0
-0Makefile include $(firmware-object-mks) · line 251
Quoted 5 lines
Makefile +2
-0@@ -247,6 +247,8 @@ include $(firmware-object-mks) # Setup list of objects libsbi-objs-path-y=$(foreach obj,$(libsbi-objs-y),$(build_dir)/lib/sbi/$(obj)) +# Index unit tests +libsbi-objs-path-y+=$(foreach obj,$(libsbitests-objs-y),$(build_dir)/lib/sbi/tests/$(obj))No need for changing top-level
Makefile.Quoted 25 lines
Makefile +0
-0ifdef PLATFORM libsbiutils-objs-path-y=$(foreach obj,$(libsbiutils-objs-y),$(platform_build_dir)/lib/utils/$(obj)) platform-objs-path-y=$(foreach obj,$(platform-objs-y),$(platform_build_dir)/$(obj))lib/sbi/objects.mk +0
-6@@ -11,12 +11,6 @@ libsbi-objs-y += riscv_asm.o libsbi-objs-y += riscv_atomic.o libsbi-objs-y += riscv_hardfp.o libsbi-objs-y += riscv_locks.o -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o - -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.o -carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite -carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += console_test_suite libsbi-objs-y += sbi_ecall.o libsbi-objs-y += sbi_ecall_exts.olib/sbi/sbi_console.c +0
-0lib/sbi/sbi_console.c int sbi_console_init(struct sbi_scratch *scratch) · line 494
Quoted 6 lines
lib/sbi/sbi_console.c +1
-1@@ -490,5 +490,5 @@ int sbi_console_init(struct sbi_scratch *scratch) }#ifdef CONFIG_SBIUNIT -#include "sbi_console_test.c" +#include "tests/sbi_console_test.c" #endif We can simply drop including "
tests/sbi_console_test.c" by relaxing the check insbi_console_set_device().lib/sbi/tests/objects.mk line 4
Quoted 10 lines
lib/sbi/tests/objects.mk new file +4
-0@@ -0,0 +1,6 @@ +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o + +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.oWe just need "tests/" prefix to above objects. Just like we do in various objects.mk under utils directory.
Quoted 19 lines
lib/sbi/tests/objects.mk new file +2
-0+carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += console_test_suitelib/sbi/tests/sbi_bitmap_test.c renamed from lib/sbi/sbi_bitmap_test.c +0
-0lib/sbi/tests/sbi_console_test.c renamed from lib/sbi/sbi_console_test.c +0
-0lib/sbi/tests/sbi_unit_test.c renamed from lib/sbi/sbi_unit_test.c +0
-0lib/sbi/tests/sbi_unit_tests.carray renamed from lib/sbi/sbi_unit_tests.carray +0
-1--Quoted 2 lines
2.34.1
I have taken care of the above minor issues at the time of merging this patch.
Quoted 4 lines
Reviewed-by Anup Patel <[email protected]>Applied this patch to the riscv/opensbi repo.
Quoted 8 lines
Hi Anup,
Thank you so much for the review and for fixing these issues.
Now the documentation should be updated as well, correspondingly with the updates you made: currently, 'writing_tests.md' doc specifies the wrong
Makefilevariable name for the tests (libsbitests-... instead of libsbi-...). I'll fix it and send the patch today.
Ahh, my bad. I will wait for your patch.
Thanks,
Anup
Quoted 10 lines
--
Kind regards,
Ivan Orlov--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH 1/2 lib: tests: Move tests to a separate directory
Quoted 133 lines · Anup Patel
Quoted 132 lines · On Tue, Mar 19, 2024 at 9:14?PM Ivan Orlov <[email protected]> wrote:
Quoted 123 lines · Anup Patel
Quoted 40 lines · On Wed, Mar 13, 2024 at 8:32?PM Ivan Orlov <[email protected]> wrote:
Move all of the SBIUnit-related code into the
lib/sbi/testsdirectory. Update 'Makefile' to index objects from the tests subdirectory.I don't think creating the full separate list of
Makefilevariables (libsbitests-objs-path-y, libsbitests-object-mks, etc. as it is done for libsbiutils) is necessary for the tests because:1)
lib/sbi/tests/objects.mkis already indexed into 'libsbi-objects-mks' since the find expression for the libsbi-object-mks variable looks for objects.mk files in the nested directories as well).2) Tests are tightly coupled with the
lib/sbi/sources, therefore it may be reasonable to store the list of lib/sbi andlib/sbi/testsobject files together in the libsbi-objs-path-y variable.Additionally, update relative paths in the tests where necessary.
Signed-off-by Ivan Orlov <[email protected]>--- Makefile | 2 ++ lib/sbi/objects.mk | 6 ------ lib/sbi/sbi_console.c | 2 +- lib/sbi/tests/objects.mk | 6 ++++++ lib/sbi/{ => tests}/sbi_bitmap_test.c | 0 lib/sbi/{ => tests}/sbi_console_test.c | 0 lib/sbi/{ => tests}/sbi_unit_test.c | 0 lib/sbi/{ => tests}/sbi_unit_tests.carray | 0 8 files changed, 9 insertions(+), 7 deletions(-)create mode 100644
lib/sbi/tests/objects.mkrenamelib/sbi/{=>tests}/sbi_bitmap_test.c(100%) renamelib/sbi/{=>tests}/sbi_console_test.c(100%) renamelib/sbi/{=>tests}/sbi_unit_test.c(100%) renamelib/sbi/{=> tests}/sbi_unit_tests.carray (100%)Makefile +0
-0Makefile include $(firmware-object-mks) · line 251
Quoted 5 lines
Makefile +2
-0@@ -247,6 +247,8 @@ include $(firmware-object-mks) # Setup list of objects libsbi-objs-path-y=$(foreach obj,$(libsbi-objs-y),$(build_dir)/lib/sbi/$(obj)) +# Index unit tests +libsbi-objs-path-y+=$(foreach obj,$(libsbitests-objs-y),$(build_dir)/lib/sbi/tests/$(obj))No need for changing top-level
Makefile.Quoted 25 lines
Makefile +0
-0ifdef PLATFORM libsbiutils-objs-path-y=$(foreach obj,$(libsbiutils-objs-y),$(platform_build_dir)/lib/utils/$(obj)) platform-objs-path-y=$(foreach obj,$(platform-objs-y),$(platform_build_dir)/$(obj))lib/sbi/objects.mk +0
-6@@ -11,12 +11,6 @@ libsbi-objs-y += riscv_asm.o libsbi-objs-y += riscv_atomic.o libsbi-objs-y += riscv_hardfp.o libsbi-objs-y += riscv_locks.o -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o - -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.o -carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite -carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += console_test_suite libsbi-objs-y += sbi_ecall.o libsbi-objs-y += sbi_ecall_exts.olib/sbi/sbi_console.c +0
-0lib/sbi/sbi_console.c int sbi_console_init(struct sbi_scratch *scratch) · line 494
Quoted 6 lines
lib/sbi/sbi_console.c +1
-1@@ -490,5 +490,5 @@ int sbi_console_init(struct sbi_scratch *scratch) }#ifdef CONFIG_SBIUNIT -#include "sbi_console_test.c" +#include "tests/sbi_console_test.c" #endif We can simply drop including "
tests/sbi_console_test.c" by relaxing the check insbi_console_set_device().lib/sbi/tests/objects.mk line 4
Quoted 10 lines
lib/sbi/tests/objects.mk new file +4
-0@@ -0,0 +1,6 @@ +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o + +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.oWe just need "tests/" prefix to above objects. Just like we do in various objects.mk under utils directory.
Quoted 19 lines
lib/sbi/tests/objects.mk new file +2
-0+carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += console_test_suitelib/sbi/tests/sbi_bitmap_test.c renamed from lib/sbi/sbi_bitmap_test.c +0
-0lib/sbi/tests/sbi_console_test.c renamed from lib/sbi/sbi_console_test.c +0
-0lib/sbi/tests/sbi_unit_test.c renamed from lib/sbi/sbi_unit_test.c +0
-0lib/sbi/tests/sbi_unit_tests.carray renamed from lib/sbi/sbi_unit_tests.carray +0
-1--Quoted 2 lines
2.34.1
I have taken care of the above minor issues at the time of merging this patch.
Quoted 4 lines
Reviewed-by Anup Patel <[email protected]>Applied this patch to the riscv/opensbi repo.
Hi Anup,
Quoted 9 lines
Quoted 6 lines
Thank you so much for the review and for fixing these issues.
Now the documentation should be updated as well, correspondingly with the updates you made: currently, 'writing_tests.md' doc specifies the wrong
Makefilevariable name for the tests (libsbitests-... instead of libsbi-...). I'll fix it and send the patch today.Ahh, my bad. I will wait for your patch.
No worries, give me 15 minutes :)
Signature · 2 lines
Kind regards, Ivan Orlov
PATCH 1/2 lib: tests: Move tests to a separate directory
Quoted 154 lines · Ivan Orlov
Quoted 153 lines · Anup Patel
Quoted 150 lines · On Tue, Mar 19, 2024 at 9:14?PM Ivan Orlov <[email protected]> wrote:
Quoted 135 lines · Anup Patel
Quoted 50 lines · On Wed, Mar 13, 2024 at 8:32?PM Ivan Orlov <[email protected]> wrote:
Move all of the SBIUnit-related code into the
lib/sbi/testsdirectory. Update 'Makefile' to index objects from the tests subdirectory.I don't think creating the full separate list of
Makefilevariables (libsbitests-objs-path-y, libsbitests-object-mks, etc. as it is done for
libsbiutils) is necessary for the tests because:1)
lib/sbi/tests/objects.mkis already indexed into 'libsbi-objects-mks' since the find expression for the libsbi-object-mks
variable looks for objects.mk files in the nested directories as well).2) Tests are tightly coupled with the
lib/sbi/sources, therefore it may be reasonable to store the list of lib/sbi andlib/sbi/testsobject
files together in the libsbi-objs-path-y variable.Additionally, update relative paths in the tests where necessary.
Signed-off-by Ivan Orlov <[email protected]>---
?? Makefile????????????????????????????????? | 2 ++ ?? lib/sbi/objects.mk??????????????????????? | 6 ------ ?? lib/sbi/sbi_console.c???????????????????? | 2 +- ?? lib/sbi/tests/objects.mk????????????????? | 6 ++++++ ?? lib/sbi/{ => tests}/sbi_bitmap_test.c???? | 0 ?? lib/sbi/{ => tests}/sbi_console_test.c??? | 0 ?? lib/sbi/{ => tests}/sbi_unit_test.c?????? | 0 ?? lib/sbi/{ => tests}/sbi_unit_tests.carray | 0?? 8 files changed, 9 insertions(+), 7 deletions(-) ?? create mode 100644
lib/sbi/tests/objects.mk
?? renamelib/sbi/{=>tests}/sbi_bitmap_test.c(100%) ?? renamelib/sbi/{=>tests}/sbi_console_test.c(100%) ?? renamelib/sbi/{=>tests}/sbi_unit_test.c(100%) ?? renamelib/sbi/{=> tests}/sbi_unit_tests.carray (100%)Makefile +0
-0@@ -247,6 +247,8 @@ include $(firmware-object-mks)?? # Setup list of objects
?? libsbi-objs-path-y=$(foreach
obj,$(libsbi-objs-y),$(build_dir)/lib/sbi/$(obj))Makefile +2
-0+# Index unit tests +libsbi-objs-path-y+=$(foreachQuoted 1 line
obj,$(libsbitests-objs-y),$(build_dir)/lib/sbi/tests/$(obj))
No need for changing top-level
Makefile.Quoted 32 lines
?? ifdef PLATFORM
?? libsbiutils-objs-path-y=$(foreach obj,$(libsbiutils-objs-y),$(platform_build_dir)/lib/utils/$(obj)) ?? platform-objs-path-y=$(foreach obj,$(platform-objs-y),$(platform_build_dir)/$(obj))lib/sbi/objects.mk +0
-0@@ -11,12 +11,6 @@ libsbi-objs-y += riscv_asm.o?? libsbi-objs-y += riscv_atomic.o
?? libsbi-objs-y += riscv_hardfp.o
?? libsbi-objs-y += riscv_locks.olib/sbi/objects.mk +0
-6-libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o - -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.o -carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite -carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += console_test_suite?? libsbi-objs-y += sbi_ecall.o
?? libsbi-objs-y += sbi_ecall_exts.olib/sbi/sbi_console.c +0
-0@@ -490,5 +490,5 @@ int sbi_console_init(struct sbi_scratch *scratch) ?? }?? #ifdef
CONFIG_SBIUNITlib/sbi/sbi_console.c +1
-1-#include "sbi_console_test.c" +#include "tests/sbi_console_test.c" Quoted 1 line
?? #endif
We can simply drop including "
tests/sbi_console_test.c" by relaxing the check insbi_console_set_device().lib/sbi/tests/objects.mk line 4
Quoted 10 lines
lib/sbi/tests/objects.mk new file +4
-0@@ -0,0 +1,6 @@ +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_unit_test.o +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_unit_tests.o + +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_bitmap_test.oWe just need "tests/" prefix to above objects. Just like we do in various objects.mk under utils directory.
Quoted 24 lines
lib/sbi/tests/objects.mk new file +2
-0+carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += console_test_suitelib/sbi/tests/sbi_bitmap_test.c renamed from lib/sbi/sbi_bitmap_test.c +0
-0lib/sbi/tests/sbi_console_test.c renamed from lib/sbi/sbi_console_test.c +0
-0lib/sbi/tests/sbi_unit_test.c renamed from lib/sbi/sbi_unit_test.c +0
-0lib/sbi/tests/sbi_unit_tests.carray renamed from lib/sbi/sbi_unit_tests.carray +0
-0Signature · 1 line
2.34.1I have taken care of the above minor issues at the time of merging this patch.
Quoted 4 lines
Reviewed-by Anup Patel <[email protected]>Applied this patch to the riscv/opensbi repo.
Hi Anup,
Thank you so much for the review and for fixing these issues.
Now the documentation should be updated as well, correspondingly with the updates you made: currently, 'writing_tests.md' doc specifies the wrong
Makefilevariable name for the tests (libsbitests-... instead of libsbi-...). I'll fix it and send the patch today.
Quoted 5 lines
Quoted 2 lines
Ahh, my bad. I will wait for your patch.
No worries, give me 15 minutes :)
Done
Signature · 2 lines
Kind regards, Ivan Orlov
PATCH 2/2 docs/writing_tests: Update tests paths
In reply to Ivan OrlovSince the tests should be moved to the lib/sbi/tests directory, the documentation should be updated correspondingly. So, update the paths where they have to be changed.
--- docs/writing_tests.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
docs/writing_tests.md +10 -11
@@ -6,7 +6,7 @@ SBIUnit SBIUnit is a set of macros and functions which simplify the test development and automate the test execution and evaluation. All of the SBIUnit definitions are in the `include/sbi/sbi_unit_test.h` header file, and implementations are -available in `lib/sbi/sbi_unit_test.c`. +available in `lib/sbi/tests/sbi_unit_test.c`. Simple SBIUnit test -------------------
@@ -30,7 +30,7 @@ size_t sbi_strlen(const char *str) which calculates the string length. -Create the file `lib/sbi/sbi_string_test.c` with the following content: +Create the file `lib/sbi/tests/sbi_string_test.c` with the following content: ```c #include <sbi/sbi_unit_test.h>
@@ -50,10 +50,10 @@ static struct sbiunit_test_case string_test_cases[] = { SBIUNIT_TEST_SUITE(string_test_suite, string_test_cases); ``` -Then, add the corresponding Makefile entries to `lib/sbi/objects.mk`: +Then, add the corresponding Makefile entries to `lib/sbi/tests/objects.mk`: ```lang-makefile ... -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_string_test.o +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_string_test.o carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += string_test_suite ```
@@ -86,7 +86,7 @@ Now let's try to change this test in the way that it will fail: # Running SBIUNIT tests # ... ## Running test suite: string_test_suite -[SBIUnit] [.../opensbi/lib/sbi/sbi_string_test.c:6]: strlen_test: Condition "(sbi_strlen("Hello")) == (100)" expected to be true! +[SBIUnit] [.../opensbi/lib/sbi/tests/sbi_string_test.c:6]: strlen_test: Condition "(sbi_strlen("Hello")) == (100)" expected to be true! [FAILED] strlen_test 0 PASSED / 1 FAILED / 1 TOTAL ```
@@ -95,17 +95,16 @@ Covering the static functions / using the static definitions SBIUnit also allows you to test static functions. In order to do so, simply include your test source in the file you would like to test. Complementing the -example above, just add this to the -`lib/sbi/sbi_string.c` file: +example above, just add this to the `lib/sbi/sbi_string.c` file: ```c #ifdef CONFIG_SBIUNIT -#include "sbi_string_test.c" +#include "tests/sbi_string_test.c" #endif ``` In this case you should only add a new carray entry pointing to the test suite -to `lib/sbi/objects.mk`: +to `lib/sbi/tests/objects.mk`: ```lang-makefile ... carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += string_test_suite
@@ -114,12 +113,12 @@ carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += string_test_suite You don't have to compile the `sbi_string_test.o` separately, because the test code will be included into the `sbi_string` object file. -See example in `lib/sbi/sbi_console_test.c`, where statically declared +See example in `lib/sbi/tests/sbi_console_test.c`, where statically declared `console_dev` variable is used to mock the `sbi_console_device` structure. "Mocking" the structures ------------------------ -See the example of structure "mocking" in the `lib/sbi/sbi_console_test.c`, +See the example of structure "mocking" in `lib/sbi/tests/sbi_console_test.c`, where the sbi_console_device structure was mocked to be used in various console-related functions in order to test them.
Signature · 1 line
2.34.1
Anup Patel
AppliedPATCH 2/2 docs/writing_tests: Update tests paths
Quoted 6 lines · On Wed, Mar 13, 2024 at 8:32?PM Ivan Orlov <[email protected]> wrote:
Since the tests should be moved to the
lib/sbi/testsdirectory, the documentation should be updated correspondingly. So, update the paths where they have to be changed.Signed-off-by Ivan Orlov <[email protected]>
LGTM.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 87 lines
--- docs/writing_tests.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)docs/writing_tests.md +10
-12@@ -6,7 +6,7 @@ SBIUnit SBIUnit is a set of macros and functions which simplify the test development and automate the test execution and evaluation. All of the SBIUnit definitions are in the `include/sbi/sbi_unit_test.h` header file, and implementations are -available in `lib/sbi/sbi_unit_test.c`. +available in `lib/sbi/tests/sbi_unit_test.c`. Simple SBIUnit test -------------------@@ -30,7 +30,7 @@ size_t sbi_strlen(const char *str) which calculates the string length. -Create the file `lib/sbi/sbi_string_test.c` with the following content: +Create the file `lib/sbi/tests/sbi_string_test.c` with the following content: ```c #include <sbi/sbi_unit_test.h>@@ -50,10 +50,10 @@ static struct sbiunit_test_case string_test_cases[] = { SBIUNIT_TEST_SUITE(string_test_suite, string_test_cases); ``` -Then, add the corresponding Makefile entries to `lib/sbi/objects.mk`: +Then, add the corresponding Makefile entries to `lib/sbi/tests/objects.mk`: ```lang-makefile -libsbi-objs-$(CONFIG_SBIUNIT) += sbi_string_test.o +libsbitests-objs-$(CONFIG_SBIUNIT) += sbi_string_test.o carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += string_test_suite ```@@ -86,7 +86,7 @@ Now let's try to change this test in the way that it will fail: # Running SBIUNIT tests # ## Running test suite: string_test_suite -[SBIUnit] [.../opensbi/lib/sbi/sbi_string_test.c:6]: strlen_test: Condition "(sbi_strlen("Hello")) == (100)" expected to be true! +[SBIUnit] [.../opensbi/lib/sbi/tests/sbi_string_test.c:6]: strlen_test: Condition "(sbi_strlen("Hello")) == (100)" expected to be true! [FAILED] strlen_test 0 PASSED / 1 FAILED / 1 TOTAL ```@@ -95,17 +95,16 @@ Covering the static functions / using the static definitions SBIUnit also allows you to test static functions. In order to do so, simply include your test source in the file you would like to test. Complementing the -example above, just add this to the -`lib/sbi/sbi_string.c` file: +example above, just add this to the `lib/sbi/sbi_string.c` file: ```c #ifdef CONFIG_SBIUNIT -#include "sbi_string_test.c" +#include "tests/sbi_string_test.c" #endif ``` In this case you should only add a new carray entry pointing to the test suite -to `lib/sbi/objects.mk`: +to `lib/sbi/tests/objects.mk`: ```lang-makefile carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += string_test_suite@@ -114,12 +113,12 @@ carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += string_test_suite You don't have to compile the `sbi_string_test.o` separately, because the test code will be included into the `sbi_string` object file. -See example in `lib/sbi/sbi_console_test.c`, where statically declared +See example in `lib/sbi/tests/sbi_console_test.c`, where statically declared `console_dev` variable is used to mock the `sbi_console_device` structure. "Mocking" the structures ------------------------ -See the example of structure "mocking" in the `lib/sbi/sbi_console_test.c`, +See the example of structure "mocking" in `lib/sbi/tests/sbi_console_test.c`, where the sbi_console_device structure was mocked to be used in various console-related functions in order to test them. --2.34.1