Add libfdt unit test cases
This patch incorporates the standalone libfdt unit tests written by Andre
Przywara into the unit test framework. These tests use DTB files to
exercise the functions in libfdt and fdt_wrappers.c to ensure that they work
correctly.
Several of these DTBs cannot be supplied in this repository due to license
restrictions, they are found in the Linux kernel source tree and in the
trusted firmware a source tree. A script has been provided to build these
DTB files and place them in the correct location to be used and can be
found in tests/lib/fdt/device_trees, it requires the two source trees to
be provided as arguments.
At some point we'd like to include DTS files in this repository to make
things easier but for now they are external dependencies.
Signed-off-by: John Powell <john.powell@arm.com>
Co-authored-by: Andre Przywara <andre.przywara@arm.com>
Change-Id: Ieccc61f84fc6ae91d6871224e8538e2d78218444
diff --git a/tests/lib/fdt/test_fdt.cmake b/tests/lib/fdt/test_fdt.cmake
new file mode 100644
index 0000000..098e4ae
--- /dev/null
+++ b/tests/lib/fdt/test_fdt.cmake
@@ -0,0 +1,43 @@
+#
+# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+include(UnitTest)
+
+unit_test_add_suite(
+ NAME fdt
+ SOURCES
+ ${CMAKE_CURRENT_LIST_DIR}/test_fdt.cpp
+ ${TF_A_UNIT_TESTS_PATH}/mocks/common/debug.cpp
+ ${TF_A_PATH}/common/fdt_wrappers.c
+ ${TF_A_PATH}/lib/libc/strlcpy.c
+ ${TF_A_PATH}/lib/libfdt/fdt.c
+ ${TF_A_PATH}/lib/libfdt/fdt_addresses.c
+ ${TF_A_PATH}/lib/libfdt/fdt_empty_tree.c
+ ${TF_A_PATH}/lib/libfdt/fdt_overlay.c
+ ${TF_A_PATH}/lib/libfdt/fdt_ro.c
+ ${TF_A_PATH}/lib/libfdt/fdt_rw.c
+ ${TF_A_PATH}/lib/libfdt/fdt_strerror.c
+ ${TF_A_PATH}/lib/libfdt/fdt_sw.c
+ ${TF_A_PATH}/lib/libfdt/fdt_wip.c
+ INCLUDE_DIRECTORIES
+ ${TF_A_UNIT_TESTS_PATH}/mocks/include/
+ ${TF_A_UNIT_TESTS_PATH}/mocks/include/lib/libc/
+ ${TF_A_PATH}/include/
+ ${TF_A_PATH}/include/lib/libfdt/
+ COMPILE_DEFINITIONS
+ # Several additional DTB files from the Linux kernel and the TFA source
+ # are needed to run these tests. They cannot be included here due to
+ # license restrictions but can be built from the sources using the
+ # script device_trees/build_dtb.sh. The script takes the paths to these
+ # two source repositories as arguments, builds the DTB files, and places
+ # them in a folder here called dtb.
+ TFA_FVP_DTB_PATH="${CMAKE_CURRENT_LIST_DIR}/device_trees/dtb/fvp-base-gicv3-psci.dtb"
+ LINUX64_JUNO_R1_DTB="${CMAKE_CURRENT_LIST_DIR}/device_trees/dtb/juno-r1.dtb"
+ LINUX64_SUN50I_PINE64_PLUS_DTB="${CMAKE_CURRENT_LIST_DIR}/device_trees/dtb/sun50i-a64-pine64-plus.dtb"
+ LINUX32_ATLAS7_EVB_DTB="${CMAKE_CURRENT_LIST_DIR}/device_trees/dtb/atlas7-evb.dtb"
+ LINUX32_BCM2837_RPI_3_B_DTB="${CMAKE_CURRENT_LIST_DIR}/device_trees/dtb/bcm2837-rpi-3-b-plus.dtb"
+ TEST_DTB="${CMAKE_CURRENT_LIST_DIR}/device_trees/dtb/test.dtb"
+)