[PATCH 1/2] lib: tests: Move tests to a separate directory

Ivan Orlov ivan.orlov0322 at gmail.com
Wed Mar 13 08:01:57 PDT 2024


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.

Signed-off-by: Ivan Orlov <ivan.orlov0322 at gmail.com>
---
 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%)

diff --git a/Makefile b/Makefile
index 680c19a..eef321e 100644
--- a/Makefile
+++ b/Makefile
@@ -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))
diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk
index 2bed7f3..5d06d25 100644
--- a/lib/sbi/objects.mk
+++ b/lib/sbi/objects.mk
@@ -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
diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c
index d1229d0..8d1ad2e 100644
--- a/lib/sbi/sbi_console.c
+++ b/lib/sbi/sbi_console.c
@@ -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
diff --git a/lib/sbi/tests/objects.mk b/lib/sbi/tests/objects.mk
new file mode 100644
index 0000000..0397172
--- /dev/null
+++ b/lib/sbi/tests/objects.mk
@@ -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
diff --git a/lib/sbi/sbi_bitmap_test.c b/lib/sbi/tests/sbi_bitmap_test.c
similarity index 100%
rename from lib/sbi/sbi_bitmap_test.c
rename to lib/sbi/tests/sbi_bitmap_test.c
diff --git a/lib/sbi/sbi_console_test.c b/lib/sbi/tests/sbi_console_test.c
similarity index 100%
rename from lib/sbi/sbi_console_test.c
rename to lib/sbi/tests/sbi_console_test.c
diff --git a/lib/sbi/sbi_unit_test.c b/lib/sbi/tests/sbi_unit_test.c
similarity index 100%
rename from lib/sbi/sbi_unit_test.c
rename to lib/sbi/tests/sbi_unit_test.c
diff --git a/lib/sbi/sbi_unit_tests.carray b/lib/sbi/tests/sbi_unit_tests.carray
similarity index 100%
rename from lib/sbi/sbi_unit_tests.carray
rename to lib/sbi/tests/sbi_unit_tests.carray
-- 
2.34.1




More information about the opensbi mailing list