2019-01-15 09:49:50 +08:00
|
|
|
include(ExternalProject)
|
|
|
|
|
|
|
|
add_library(cmocka STATIC IMPORTED)
|
|
|
|
|
2019-01-31 04:25:53 +08:00
|
|
|
if(DEFINED CMOCKA_DIRECTORY)
|
|
|
|
# Prebuilt Cmocka lib
|
|
|
|
set_property(TARGET cmocka PROPERTY IMPORTED_LOCATION "${CMOCKA_DIRECTORY}/lib/libcmocka-static.a")
|
|
|
|
set(CMOCKA_INCLUDE_DIR "${CMOCKA_DIRECTORY}/include")
|
|
|
|
else()
|
2019-03-19 21:08:53 +08:00
|
|
|
set(cmocka_binary_directory "${PROJECT_BINARY_DIR}/cmocka_git/build")
|
|
|
|
|
2019-01-31 04:25:53 +08:00
|
|
|
# Build Cmocka locally
|
|
|
|
ExternalProject_Add(cmocka_git
|
|
|
|
GIT_REPOSITORY https://github.com/thesofproject/cmocka
|
|
|
|
PREFIX "${PROJECT_BINARY_DIR}/cmocka_git"
|
2019-03-19 21:08:53 +08:00
|
|
|
BINARY_DIR ${cmocka_binary_directory}
|
2019-01-31 04:25:53 +08:00
|
|
|
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release
|
2019-03-19 22:12:36 +08:00
|
|
|
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmocka-xtensa-xt-toolchain.cmake
|
2019-01-31 04:25:53 +08:00
|
|
|
-DWITH_SHARED_LIB=OFF
|
|
|
|
-DWITH_STATIC_LIB=ON
|
|
|
|
-DWITH_EXAMPLES=OFF
|
|
|
|
-DWITH_POSITION_INDEPENDENT_CODE=OFF
|
|
|
|
-DWITH_TINY_CONFIG=ON
|
2019-03-19 21:08:53 +08:00
|
|
|
BUILD_BYPRODUCTS "${cmocka_binary_directory}/src/libcmocka-static.a"
|
2019-01-31 04:25:53 +08:00
|
|
|
INSTALL_COMMAND ""
|
|
|
|
)
|
|
|
|
|
2019-03-19 21:08:53 +08:00
|
|
|
set_property(TARGET cmocka PROPERTY IMPORTED_LOCATION "${cmocka_binary_directory}/src/libcmocka-static.a")
|
2019-01-15 09:49:50 +08:00
|
|
|
|
2019-01-31 04:25:53 +08:00
|
|
|
add_dependencies(cmocka cmocka_git)
|
2019-01-15 09:49:50 +08:00
|
|
|
|
2019-01-31 04:25:53 +08:00
|
|
|
ExternalProject_Get_Property(cmocka_git source_dir)
|
|
|
|
set(CMOCKA_INCLUDE_DIR ${source_dir}/include)
|
|
|
|
endif()
|
2019-01-15 09:49:50 +08:00
|
|
|
|
2019-02-27 18:51:27 +08:00
|
|
|
if(CONFIG_CAVS)
|
|
|
|
target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/platform/intel/cavs/include)
|
|
|
|
endif()
|
|
|
|
|
2019-01-15 09:49:50 +08:00
|
|
|
# linker script, just for log entries
|
|
|
|
set(memory_mock_lds_in ${PROJECT_SOURCE_DIR}/test/cmocka/memory_mock.x.in)
|
|
|
|
set(memory_mock_lds_out ${PROJECT_BINARY_DIR}/test/cmocka/memory_mock.x)
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT ${memory_mock_lds_out}
|
2019-03-19 21:18:56 +08:00
|
|
|
COMMAND ${CMAKE_C_COMPILER} -E -DLINKER -P -o ${memory_mock_lds_out} -x c ${memory_mock_lds_in}
|
2019-01-15 09:49:50 +08:00
|
|
|
DEPENDS ${memory_mock_lds_in}
|
|
|
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
|
|
COMMENT "Generating linker script: ${memory_mock_lds_out}"
|
|
|
|
VERBATIM
|
|
|
|
USES_TERMINAL
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(ld_script_memory_mock DEPENDS ${memory_mock_lds_out})
|
2019-03-12 21:39:37 +08:00
|
|
|
SET(arch_src ${PROJECT_SOURCE_DIR}/src/arch/xtensa/smp/idc.c)
|
|
|
|
add_library(universal_mock STATIC ${PROJECT_SOURCE_DIR}/test/cmocka/src/universal_mocks.c)
|
|
|
|
target_link_libraries(universal_mock PRIVATE sof_options)
|
|
|
|
link_libraries(universal_mock)
|
2019-01-15 09:49:50 +08:00
|
|
|
|
|
|
|
# creates exectuable for new test and adds it as test for ctest
|
|
|
|
function(cmocka_test test_name)
|
|
|
|
add_executable(${test_name} "")
|
|
|
|
add_local_sources(${test_name} ${ARGN})
|
|
|
|
add_dependencies(${test_name} ld_script_memory_mock)
|
|
|
|
target_include_directories(${test_name} PRIVATE ${PROJECT_SOURCE_DIR}/test/cmocka/include)
|
|
|
|
target_include_directories(${test_name} PRIVATE ${CMOCKA_INCLUDE_DIR})
|
|
|
|
target_link_libraries(${test_name} PRIVATE "-T${memory_mock_lds_out}")
|
|
|
|
target_link_libraries(${test_name} PRIVATE cmocka)
|
|
|
|
target_link_libraries(${test_name} PRIVATE sof_options)
|
2019-03-25 18:18:07 +08:00
|
|
|
target_compile_definitions(${test_name} PRIVATE -DUNIT_TEST)
|
2019-03-20 03:32:42 +08:00
|
|
|
|
|
|
|
# Cmocka requires this define for stdint.h that defines uintptr
|
|
|
|
target_compile_definitions(${test_name} PRIVATE -D_UINTPTR_T_DEFINED)
|
|
|
|
|
2019-01-15 09:49:50 +08:00
|
|
|
add_test(NAME ${test_name} COMMAND xt-run --exit_with_target_code ${test_name})
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
add_subdirectory(src)
|