Mirror of espurna firmware for wireless switches and more
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
8.0 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. # crude test builder based on
  2. # - https://github.com/esp8266/Arduino/blob/3.0.2/tests/host/Makefile
  3. # - https://github.com/mcspr/rpnlib/blob/0.24.1/examples/host/CMakeLists.txt
  4. #
  5. # we do require certain pre-requisites
  6. # - https://github.com/esp8266/Arduino/ git tree for both Core's and Mock files
  7. # - https://github.com/ThrowTheSwitch/Unity git tree (or tool-unity from platformio)
  8. #
  9. # after everything is installed
  10. # $ cmake -B build
  11. # $ cmake --build build --target test
  12. cmake_minimum_required(VERSION 3.5)
  13. project(host-test VERSION 1 LANGUAGES C CXX)
  14. set(CMAKE_C_STANDARD 11 CACHE STRING "Global C standard version (...does not yet work with 17 though)")
  15. set(CMAKE_CXX_STANDARD 17 "Global C++ standard version")
  16. # required for esp8266 host mocking
  17. set(COMMON_FLAGS
  18. -Os
  19. -g
  20. -fno-common
  21. -funsigned-char
  22. -DPROGMEM_STRING_ATTR=
  23. -DCORE_MOCK
  24. -DHOST_MOCK=1
  25. -DLWIP_IPV6=0
  26. -Dstrnlen_P=strnlen
  27. -Dmemcmp_P=memcmp
  28. -Dstrncasecmp_P=strncasecmp
  29. -DUNITY_INCLUDE_DOUBLE
  30. )
  31. set(ESPURNA_PATH ${CMAKE_SOURCE_DIR}/../../../ CACHE PATH "ESPurna source code repo root")
  32. # Make sure to generate compile_commands.json
  33. set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  34. # PIO does not really make it easy to install packages outside of the 'platform' context,
  35. # so sharing these between a normal builder might not be an option. (...big TODO though)
  36. # for right now, just fetch these as raw repos. plus, there's no need for any extra params
  37. set(unity_version v2.5.2)
  38. include(FetchContent)
  39. FetchContent_Declare(
  40. unitygit
  41. GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity
  42. GIT_TAG ${unity_version}
  43. GIT_CONFIG core.autocrlf=false core.eol=lf
  44. SOURCE_DIR ${CMAKE_SOURCE_DIR}/cache/unitygit-${unity_version}-src
  45. SUBBUILD_DIR ${CMAKE_SOURCE_DIR}/cache/unitygit-${unity_version}-subbuild
  46. )
  47. FetchContent_MakeAvailable(unitygit)
  48. FetchContent_GetProperties(unitygit SOURCE_DIR)
  49. target_compile_options(unity BEFORE PRIVATE
  50. -DUNITY_OUTPUT_COLOR
  51. -DUNITY_INCLUDE_DOUBLE
  52. )
  53. set(esp8266_version a4a8782c5611c02df3c0dd4744c86d02a4f037d3)
  54. FetchContent_Declare(
  55. esp8266git
  56. GIT_REPOSITORY https://github.com/esp8266/Arduino/
  57. GIT_TAG ${esp8266_version}
  58. GIT_CONFIG core.autocrlf=false core.eol=lf
  59. SOURCE_DIR ${CMAKE_SOURCE_DIR}/cache/esp8266git-${esp8266_version}-src
  60. SUBBUILD_DIR ${CMAKE_SOURCE_DIR}/cache/esp8266git-${esp8266_version}-subbuild
  61. )
  62. FetchContent_MakeAvailable(esp8266git)
  63. FetchContent_GetProperties(esp8266git SOURCE_DIR)
  64. set(arduinojson_version v5.13.5)
  65. FetchContent_Declare(
  66. ArduinoJson
  67. GIT_REPOSITORY https://github.com/bblanchon/ArduinoJson
  68. GIT_TAG ${arduinojson_version}
  69. GIT_CONFIG core.autocrlf=false core.eol=lf
  70. SOURCE_DIR ${CMAKE_SOURCE_DIR}/cache/arduinojson-${arduinojson_version}-src
  71. SOURCE_SUBDIR src
  72. SUBBUILD_DIR ${CMAKE_SOURCE_DIR}/cache/arduinojson-${arduinojson_version}-subbuild
  73. )
  74. FetchContent_MakeAvailable(ArduinoJson)
  75. FetchContent_GetProperties(ArduinoJson SOURCE_DIR)
  76. # mock'ed Arduino Core headers sometimes expect to be included with some pre-requisites, which we obviously don't have
  77. add_library(common INTERFACE)
  78. target_compile_options(common INTERFACE
  79. "SHELL:-include ${esp8266git_SOURCE_DIR}/tests/host/common/mock.h"
  80. "SHELL:-include ${esp8266git_SOURCE_DIR}/tests/host/common/c_types.h"
  81. )
  82. # try to hack esp8266 host test layer
  83. # - we need to specify bunch of things that the original Makefile does
  84. # - there are a lot of cross-dependencies, we need to include a lot of .cpp files here
  85. add_library(esp8266 STATIC
  86. src/unity_fixtures.c
  87. src/ArduinoMainOverride.cpp
  88. ${esp8266git_SOURCE_DIR}/tests/host/common/Arduino.cpp
  89. ${esp8266git_SOURCE_DIR}/tests/host/common/ArduinoMainUdp.cpp
  90. ${esp8266git_SOURCE_DIR}/tests/host/common/WMath.cpp
  91. ${esp8266git_SOURCE_DIR}/tests/host/common/MockUART.cpp
  92. ${esp8266git_SOURCE_DIR}/tests/host/common/MockTools.cpp
  93. ${esp8266git_SOURCE_DIR}/tests/host/common/MocklwIP.cpp
  94. ${esp8266git_SOURCE_DIR}/tests/host/common/MockEsp.cpp
  95. ${esp8266git_SOURCE_DIR}/tests/host/common/UdpContextSocket.cpp
  96. ${esp8266git_SOURCE_DIR}/tests/host/common/user_interface.cpp
  97. ${esp8266git_SOURCE_DIR}/tests/host/common/HostWiring.cpp
  98. ${esp8266git_SOURCE_DIR}/tests/host/common/md5.c
  99. ${esp8266git_SOURCE_DIR}/tests/host/common/noniso.c
  100. ${esp8266git_SOURCE_DIR}/tests/host/common/flash_hal_mock.cpp
  101. ${esp8266git_SOURCE_DIR}/tests/host/common/spiffs_mock.cpp
  102. ${esp8266git_SOURCE_DIR}/tests/host/common/littlefs_mock.cpp
  103. ${esp8266git_SOURCE_DIR}/tests/host/common/sdfs_mock.cpp
  104. ${esp8266git_SOURCE_DIR}/tests/host/common/ArduinoMainUdp.cpp
  105. ${esp8266git_SOURCE_DIR}/tests/host/common/ArduinoMainSpiffs.cpp
  106. ${esp8266git_SOURCE_DIR}/tests/host/common/ArduinoMainLittlefs.cpp
  107. ${esp8266git_SOURCE_DIR}/tests/host/common/user_interface.cpp
  108. ${esp8266git_SOURCE_DIR}/cores/esp8266/debug.cpp
  109. ${esp8266git_SOURCE_DIR}/cores/esp8266/core_esp8266_noniso.cpp
  110. ${esp8266git_SOURCE_DIR}/cores/esp8266/stdlib_noniso.cpp
  111. ${esp8266git_SOURCE_DIR}/cores/esp8266/WString.cpp
  112. ${esp8266git_SOURCE_DIR}/cores/esp8266/HardwareSerial.cpp
  113. ${esp8266git_SOURCE_DIR}/cores/esp8266/Print.cpp
  114. ${esp8266git_SOURCE_DIR}/cores/esp8266/Schedule.cpp
  115. ${esp8266git_SOURCE_DIR}/cores/esp8266/time.cpp
  116. ${esp8266git_SOURCE_DIR}/cores/esp8266/Stream.cpp
  117. ${esp8266git_SOURCE_DIR}/cores/esp8266/StreamSend.cpp
  118. ${esp8266git_SOURCE_DIR}/cores/esp8266/FS.cpp
  119. ${esp8266git_SOURCE_DIR}/cores/esp8266/spiffs_api.cpp
  120. ${esp8266git_SOURCE_DIR}/cores/esp8266/spiffs/spiffs_cache.cpp
  121. ${esp8266git_SOURCE_DIR}/cores/esp8266/spiffs/spiffs_check.cpp
  122. ${esp8266git_SOURCE_DIR}/cores/esp8266/spiffs/spiffs_gc.cpp
  123. ${esp8266git_SOURCE_DIR}/cores/esp8266/spiffs/spiffs_hydrogen.cpp
  124. ${esp8266git_SOURCE_DIR}/cores/esp8266/spiffs/spiffs_nucleus.cpp
  125. ${esp8266git_SOURCE_DIR}/libraries/LittleFS/src/LittleFS.cpp
  126. ${esp8266git_SOURCE_DIR}/libraries/LittleFS/src/lfs.c
  127. ${esp8266git_SOURCE_DIR}/libraries/LittleFS/src/lfs_util.c
  128. )
  129. target_include_directories(esp8266 PUBLIC
  130. ${esp8266git_SOURCE_DIR}/tests/host/common/
  131. ${esp8266git_SOURCE_DIR}/tests/host
  132. ${esp8266git_SOURCE_DIR}/tools/sdk/lwip2/include
  133. ${esp8266git_SOURCE_DIR}/tools/sdk/include
  134. ${esp8266git_SOURCE_DIR}/cores/esp8266/
  135. ${esp8266git_SOURCE_DIR}/libraries/LittleFS/src/
  136. ${esp8266git_SOURCE_DIR}/libraries/SPI/
  137. ${esp8266git_SOURCE_DIR}/libraries/ESP8266SdFat/src
  138. )
  139. target_compile_options(esp8266 PUBLIC
  140. ${COMMON_FLAGS}
  141. -DF_CPU=80000000
  142. -Wl,--defsym,_FS_start=0x40300000
  143. -Wl,--defsym,_FS_end=0x411FA000
  144. -Wl,--defsym,_FS_page=0x100
  145. -Wl,--defsym,_FS_block=0x2000
  146. -Wl,--defsym,_EEPROM_start=0x411fb000
  147. )
  148. target_link_libraries(esp8266 PUBLIC common)
  149. # our library source (maybe some day this will be a simple glob)
  150. add_library(espurna STATIC
  151. ${ESPURNA_PATH}/code/espurna/settings_convert.cpp
  152. ${ESPURNA_PATH}/code/espurna/terminal_commands.cpp
  153. ${ESPURNA_PATH}/code/espurna/terminal_parsing.cpp
  154. ${ESPURNA_PATH}/code/espurna/types.cpp
  155. ${ESPURNA_PATH}/code/espurna/utils.cpp
  156. )
  157. target_link_libraries(espurna PUBLIC esp8266)
  158. target_include_directories(espurna PUBLIC
  159. ${ESPURNA_PATH}/code/
  160. ${CMAKE_SOURCE_DIR}/cache/arduinojson-${arduinojson_version}-src/src
  161. )
  162. target_compile_options(espurna PUBLIC
  163. ${COMMON_FLAGS}
  164. )
  165. target_compile_options(espurna PRIVATE
  166. -Wall
  167. -Wextra
  168. )
  169. # each case is built separately, we expect these to work like a normal executable
  170. include(CTest)
  171. list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
  172. function(build_tests)
  173. foreach(ARG IN LISTS ARGN)
  174. add_executable(test-${ARG} src/${ARG}/${ARG}.cpp)
  175. target_link_libraries(test-${ARG} espurna unity)
  176. target_compile_options(test-${ARG} PRIVATE
  177. ${COMMON_FLAGS}
  178. -Wall
  179. -Wextra
  180. )
  181. set_target_properties(test-${ARG} PROPERTIES COMPILE_FLAGS -g)
  182. add_test(NAME ${ARG} COMMAND test-${ARG})
  183. endforeach()
  184. endfunction()
  185. build_tests(
  186. basic
  187. embedis
  188. settings
  189. terminal
  190. tuya
  191. types
  192. url
  193. utils
  194. )