1# Include filepaths for source and include. 2include( ${MODULE_ROOT_DIR}/test/unit-test/TCPFilePaths.cmake ) 3 4# ==================== Define your project name (edit) ======================== 5set( project_name "FreeRTOS_DNS_Callback" ) 6message( STATUS "${project_name}" ) 7# ===================== Create your mock here (edit) ======================== 8 9# list the files to mock here 10set (mock_list "") 11list(APPEND mock_list 12 "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/task.h" 13 "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/list.h" 14 "${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/queue.h" 15 16#"${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include/portable.h" 17 "${CMAKE_BINARY_DIR}/Annexed_TCP/portable.h" 18 "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP.h" 19 "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_Sockets.h" 20 "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h" 21 "${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h" 22 "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_UDP_IP.h" 23 "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Cache.h" 24 "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_DNS_Parser.h" 25 "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Timers.h" 26 "${MODULE_ROOT_DIR}/test/unit-test/FreeRTOS_Sockets/Sockets_list_macros.h" 27 ) 28# list the directories your mocks need 29list(APPEND mock_include_list 30 . 31 ${TCP_INCLUDE_DIRS} 32 ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include 33 ${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles 34 ) 35 36#list the definitions of your mocks to control what to be included 37list(APPEND mock_define_list 38 ) 39 40# ================= Create the library under test here (edit) ================== 41 42add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) 43# list the files you would like to test here 44set(real_source_files "" 45 ) 46list(APPEND real_source_files 47 ${project_name}/FreeRTOS_UDP_IP_stubs.c 48 ${MODULE_ROOT_DIR}/source/FreeRTOS_DNS_Callback.c 49 ) 50# list the directories the module under test includes 51list(APPEND real_include_directories 52 . 53 ${TCP_INCLUDE_DIRS} 54 ${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles 55 ${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include 56 ${CMOCK_DIR}/vendor/unity/src 57 ) 58 59# ===================== Create UnitTest Code here (edit) ===================== 60 61# list the directories your test needs to include 62list(APPEND test_include_directories 63 . 64 ${CMOCK_DIR}/vendor/unity/src 65 ${TCP_INCLUDE_DIRS} 66 ${MODULE_ROOT_DIR}/test/unit-test/${project_name} 67 ${MODULE_ROOT_DIR}/source/include/ 68 ${MODULE_ROOT_DIR}/test/unit-test/FreeRTOS_Sockets 69 ) 70# To prevent the file under test from using the list macros and instead use our 71# mocked version 72add_definitions( 73 -I${MODULE_ROOT_DIR}/test/unit-test/ConfigFiles 74 -I${MODULE_ROOT_DIR}/test/unit-test/FreeRTOS_Sockets/ 75 -I${MODULE_ROOT_DIR}/test/FreeRTOS-Kernel/include 76 ) 77 78# ============================= (end edit) =================================== 79 80set(mock_name "${project_name}_mock") 81set(real_name "${project_name}_real") 82 83create_mock_list(${mock_name} 84 "${mock_list}" 85 "${MODULE_ROOT_DIR}/test/unit-test/cmock/project.yml" 86 "${mock_include_list}" 87 "${mock_define_list}" 88 ) 89create_real_library(${real_name} 90 "${real_source_files}" 91 "${real_include_directories}" 92 "${mock_name}" 93 ) 94 95set( utest_link_list "") 96list(APPEND utest_link_list 97 -l${mock_name} 98 lib${real_name}.a 99 ) 100 101set (utest_dep_list "") 102list(APPEND utest_dep_list 103 ${real_name} 104 ) 105 106set(utest_name "${project_name}_utest") 107set(utest_source "${project_name}/${project_name}_utest.c") 108 109create_test(${utest_name} 110 ${utest_source} 111 "${utest_link_list}" 112 "${utest_dep_list}" 113 "${test_include_directories}" 114 ) 115 116target_compile_options(${real_name} PUBLIC 117 -include Sockets_list_macros.h 118 ) 119