CMakeLists.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. if(ESP_PLATFORM)
  2. ###################################
  3. # Tests do not build for ESP-IDF. #
  4. ###################################
  5. else()
  6. cmake_minimum_required(VERSION 3.13)
  7. project(lvgl_tests LANGUAGES C)
  8. include(CTest)
  9. set(LVGL_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  10. set(LVGL_TEST_COMMON_EXAMPLE_OPTIONS
  11. -DLV_BUILD_EXAMPLES=1
  12. -DLV_USE_DEMO_WIDGETS=1
  13. -DLV_USE_DEMO_STRESS=1
  14. )
  15. set(LVGL_TEST_OPTIONS_MINIMAL_MONOCHROME
  16. -DLV_COLOR_DEPTH=1
  17. -DLV_MEM_SIZE=65535
  18. -DLV_DPI_DEF=40
  19. -DLV_DRAW_COMPLEX=0
  20. -DLV_USE_METER=0
  21. -DLV_USE_LOG=1
  22. -DLV_USE_ASSERT_NULL=0
  23. -DLV_USE_ASSERT_MALLOC=0
  24. -DLV_USE_ASSERT_MEM_INTEGRITY=0
  25. -DLV_USE_ASSERT_OBJ=0
  26. -DLV_USE_ASSERT_STYLE=0
  27. -DLV_USE_USER_DATA=0
  28. -DLV_FONT_UNSCII_8=1
  29. -DLV_USE_BIDI=0
  30. -DLV_USE_ARABIC_PERSIAN_CHARS=0
  31. -DLV_BUILD_EXAMPLES=1
  32. -DLV_FONT_DEFAULT=&lv_font_montserrat_14
  33. -DLV_USE_PNG=1
  34. -DLV_USE_BMP=1
  35. -DLV_USE_GIF=1
  36. -DLV_USE_QRCODE=1
  37. )
  38. set(LVGL_TEST_OPTIONS_NORMAL_8BIT
  39. -DLV_COLOR_DEPTH=8
  40. -DLV_MEM_SIZE=65535
  41. -DLV_DPI_DEF=40
  42. -DLV_DRAW_COMPLEX=1
  43. -DLV_USE_LOG=1
  44. -DLV_USE_ASSERT_NULL=0
  45. -DLV_USE_ASSERT_MALLOC=0
  46. -DLV_USE_ASSERT_MEM_INTEGRITY=0
  47. -DLV_USE_ASSERT_OBJ=0
  48. -DLV_USE_ASSERT_STYLE=0
  49. -DLV_USE_USER_DATA=1
  50. -DLV_FONT_UNSCII_8=1
  51. -DLV_USE_FONT_SUBPX=1
  52. -DLV_USE_BIDI=0
  53. -DLV_USE_ARABIC_PERSIAN_CHARS=0
  54. ${LVGL_TEST_COMMON_EXAMPLE_OPTIONS}
  55. -DLV_FONT_DEFAULT=&lv_font_montserrat_14
  56. -DLV_USE_PNG=1
  57. -DLV_USE_BMP=1
  58. -DLV_USE_SJPG=1
  59. -DLV_USE_GIF=1
  60. -DLV_USE_QRCODE=1
  61. )
  62. set(LVGL_TEST_OPTIONS_16BIT
  63. -DLV_COLOR_DEPTH=16
  64. -DLV_COLOR_16_SWAP=0
  65. -DLV_MEM_SIZE=65536
  66. -DLV_DPI_DEF=40
  67. -DLV_DRAW_COMPLEX=1
  68. -DLV_DITHER_GRADIENT=1
  69. -DLV_USE_LOG=1
  70. -DLV_USE_ASSERT_NULL=0
  71. -DLV_USE_ASSERT_MALLOC=0
  72. -DLV_USE_ASSERT_MEM_INTEGRITY=0
  73. -DLV_USE_ASSERT_OBJ=0
  74. -DLV_USE_ASSERT_STYLE=0
  75. -DLV_USE_USER_DATA=1
  76. -DLV_FONT_UNSCII_8=1
  77. -DLV_USE_FONT_SUBPX=1
  78. -DLV_USE_BIDI=0
  79. -DLV_USE_ARABIC_PERSIAN_CHARS=0
  80. ${LVGL_TEST_COMMON_EXAMPLE_OPTIONS}
  81. -DLV_FONT_DEFAULT=&lv_font_montserrat_14
  82. -DLV_USE_PNG=1
  83. -DLV_USE_BMP=1
  84. -DLV_USE_SJPG=1
  85. -DLV_USE_GIF=1
  86. -DLV_USE_QRCODE=1
  87. )
  88. set(LVGL_TEST_OPTIONS_16BIT_SWAP
  89. -DLV_COLOR_DEPTH=16
  90. -DLV_COLOR_16_SWAP=1
  91. -DLV_MEM_SIZE=65536
  92. -DLV_DPI_DEF=40
  93. -DLV_DRAW_COMPLEX=1
  94. -DLV_DITHER_GRADIENT=1
  95. -DLV_DITHER_ERROR_DIFFUSION=1
  96. -DLV_GRAD_CACHE_DEF_SIZE=8*1024
  97. -DLV_USE_LOG=1
  98. -DLV_USE_ASSERT_NULL=0
  99. -DLV_USE_ASSERT_MALLOC=0
  100. -DLV_USE_ASSERT_MEM_INTEGRITY=0
  101. -DLV_USE_ASSERT_OBJ=0
  102. -DLV_USE_ASSERT_STYLE=0
  103. -DLV_USE_USER_DATA=1
  104. -DLV_FONT_UNSCII_8=1
  105. -DLV_USE_FONT_SUBPX=1
  106. -DLV_USE_BIDI=0
  107. -DLV_USE_ARABIC_PERSIAN_CHARS=0
  108. ${LVGL_TEST_COMMON_EXAMPLE_OPTIONS}
  109. -DLV_FONT_DEFAULT=&lv_font_montserrat_14
  110. -DLV_USE_PNG=1
  111. -DLV_USE_BMP=1
  112. -DLV_USE_SJPG=1
  113. -DLV_USE_GIF=1
  114. -DLV_USE_QRCODE=1
  115. )
  116. set(LVGL_TEST_OPTIONS_FULL_32BIT
  117. -DLV_COLOR_DEPTH=32
  118. -DLV_MEM_SIZE=8388608
  119. -DLV_DPI_DEF=160
  120. -DLV_DRAW_COMPLEX=1
  121. -DLV_SHADOW_CACHE_SIZE=1
  122. -DLV_IMG_CACHE_DEF_SIZE=32
  123. -DLV_USE_LOG=1
  124. -DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE
  125. -DLV_LOG_PRINTF=1
  126. -DLV_USE_FONT_SUBPX=1
  127. -DLV_FONT_SUBPX_BGR=1
  128. -DLV_USE_PERF_MONITOR=1
  129. -DLV_USE_ASSERT_NULL=1
  130. -DLV_USE_ASSERT_MALLOC=1
  131. -DLV_USE_ASSERT_MEM_INTEGRITY=1
  132. -DLV_USE_ASSERT_OBJ=1
  133. -DLV_USE_ASSERT_STYLE=1
  134. -DLV_USE_USER_DATA=1
  135. -DLV_USE_LARGE_COORD=1
  136. -DLV_FONT_MONTSERRAT_8=1
  137. -DLV_FONT_MONTSERRAT_10=1
  138. -DLV_FONT_MONTSERRAT_12=1
  139. -DLV_FONT_MONTSERRAT_14=1
  140. -DLV_FONT_MONTSERRAT_16=1
  141. -DLV_FONT_MONTSERRAT_18=1
  142. -DLV_FONT_MONTSERRAT_20=1
  143. -DLV_FONT_MONTSERRAT_22=1
  144. -DLV_FONT_MONTSERRAT_24=1
  145. -DLV_FONT_MONTSERRAT_26=1
  146. -DLV_FONT_MONTSERRAT_28=1
  147. -DLV_FONT_MONTSERRAT_30=1
  148. -DLV_FONT_MONTSERRAT_32=1
  149. -DLV_FONT_MONTSERRAT_34=1
  150. -DLV_FONT_MONTSERRAT_36=1
  151. -DLV_FONT_MONTSERRAT_38=1
  152. -DLV_FONT_MONTSERRAT_40=1
  153. -DLV_FONT_MONTSERRAT_42=1
  154. -DLV_FONT_MONTSERRAT_44=1
  155. -DLV_FONT_MONTSERRAT_46=1
  156. -DLV_FONT_MONTSERRAT_48=1
  157. -DLV_FONT_MONTSERRAT_12_SUBPX=1
  158. -DLV_FONT_MONTSERRAT_28_COMPRESSED=1
  159. -DLV_FONT_DEJAVU_16_PERSIAN_HEBREW=1
  160. -DLV_FONT_SIMSUN_16_CJK=1
  161. -DLV_FONT_UNSCII_8=1
  162. -DLV_FONT_UNSCII_16=1
  163. -DLV_FONT_FMT_TXT_LARGE=1
  164. -DLV_USE_FONT_COMPRESSED=1
  165. -DLV_USE_BIDI=1
  166. -DLV_USE_ARABIC_PERSIAN_CHARS=1
  167. -DLV_USE_PERF_MONITOR=1
  168. -DLV_USE_MEM_MONITOR=1
  169. -DLV_LABEL_TEXT_SELECTION=1
  170. ${LVGL_TEST_COMMON_EXAMPLE_OPTIONS}
  171. -DLV_FONT_DEFAULT=&lv_font_montserrat_24
  172. -DLV_USE_FS_STDIO=1
  173. -DLV_FS_STDIO_LETTER='A'
  174. -DLV_USE_FS_POSIX=1
  175. -DLV_FS_POSIX_LETTER='B'
  176. -DLV_USE_PNG=1
  177. -DLV_USE_BMP=1
  178. -DLV_USE_SJPG=1
  179. -DLV_USE_GIF=1
  180. -DLV_USE_QRCODE=1
  181. -DLV_USE_FRAGMENT=1
  182. -DLV_USE_IMGFONT=1
  183. -DLV_USE_MSG=1
  184. )
  185. set(LVGL_TEST_OPTIONS_TEST_COMMON
  186. --coverage
  187. -DLV_COLOR_DEPTH=32
  188. -DLV_MEM_SIZE=2097152
  189. -DLV_SHADOW_CACHE_SIZE=10240
  190. -DLV_IMG_CACHE_DEF_SIZE=32
  191. -DLV_DITHER_GRADIENT=1
  192. -DLV_DITHER_ERROR_DIFFUSION=1
  193. -DLV_GRAD_CACHE_DEF_SIZE=8*1024
  194. -DLV_USE_LOG=1
  195. -DLV_LOG_PRINTF=1
  196. -DLV_USE_FONT_SUBPX=1
  197. -DLV_FONT_SUBPX_BGR=1
  198. -DLV_USE_ASSERT_NULL=0
  199. -DLV_USE_ASSERT_MALLOC=0
  200. -DLV_USE_ASSERT_MEM_INTEGRITY=0
  201. -DLV_USE_ASSERT_OBJ=0
  202. -DLV_USE_ASSERT_STYLE=0
  203. -DLV_USE_USER_DATA=1
  204. -DLV_USE_LARGE_COORD=1
  205. -DLV_FONT_MONTSERRAT_14=1
  206. -DLV_FONT_MONTSERRAT_16=1
  207. -DLV_FONT_MONTSERRAT_18=1
  208. -DLV_FONT_MONTSERRAT_24=1
  209. -DLV_FONT_MONTSERRAT_48=1
  210. -DLV_FONT_MONTSERRAT_12_SUBPX=1
  211. -DLV_FONT_MONTSERRAT_28_COMPRESSED=1
  212. -DLV_FONT_DEJAVU_16_PERSIAN_HEBREW=1
  213. -DLV_FONT_SIMSUN_16_CJK=1
  214. -DLV_FONT_UNSCII_8=1
  215. -DLV_FONT_UNSCII_16=1
  216. -DLV_FONT_FMT_TXT_LARGE=1
  217. -DLV_USE_FONT_COMPRESSED=1
  218. -DLV_USE_BIDI=1
  219. -DLV_USE_ARABIC_PERSIAN_CHARS=1
  220. -DLV_LABEL_TEXT_SELECTION=1
  221. -DLV_USE_FS_STDIO=1
  222. -DLV_FS_STDIO_LETTER='A'
  223. -DLV_FS_STDIO_CACHE_SIZE=100
  224. -DLV_USE_FS_POSIX=1
  225. -DLV_FS_POSIX_LETTER='B'
  226. -DLV_FS_POSIX_CACHE_SIZE=0
  227. ${LVGL_TEST_COMMON_EXAMPLE_OPTIONS}
  228. -DLV_FONT_DEFAULT=&lv_font_montserrat_14
  229. -Wno-unused-but-set-variable # unused variables are common in the dual-heap arrangement
  230. -Wno-unused-variable
  231. )
  232. set(LVGL_TEST_OPTIONS_TEST_SYSHEAP
  233. ${LVGL_TEST_OPTIONS_TEST_COMMON}
  234. -DLVGL_CI_USING_SYS_HEAP
  235. -DLV_MEM_CUSTOM=1
  236. -fsanitize=address
  237. )
  238. set(LVGL_TEST_OPTIONS_TEST_DEFHEAP
  239. ${LVGL_TEST_OPTIONS_TEST_COMMON}
  240. -DLVGL_CI_USING_DEF_HEAP
  241. -DLV_MEM_SIZE=2097152
  242. -fsanitize=address
  243. )
  244. if (OPTIONS_MINIMAL_MONOCHROME)
  245. set (BUILD_OPTIONS ${LVGL_TEST_OPTIONS_MINIMAL_MONOCHROME})
  246. elseif (OPTIONS_NORMAL_8BIT)
  247. set (BUILD_OPTIONS ${LVGL_TEST_OPTIONS_NORMAL_8BIT})
  248. elseif (OPTIONS_16BIT)
  249. set (BUILD_OPTIONS ${LVGL_TEST_OPTIONS_16BIT})
  250. elseif (OPTIONS_16BIT_SWAP)
  251. set (BUILD_OPTIONS ${LVGL_TEST_OPTIONS_16BIT_SWAP})
  252. elseif (OPTIONS_FULL_32BIT)
  253. set (BUILD_OPTIONS ${LVGL_TEST_OPTIONS_FULL_32BIT})
  254. elseif (OPTIONS_TEST_SYSHEAP)
  255. set (BUILD_OPTIONS ${LVGL_TEST_OPTIONS_TEST_SYSHEAP})
  256. set (TEST_LIBS --coverage -fsanitize=address)
  257. elseif (OPTIONS_TEST_DEFHEAP)
  258. set (BUILD_OPTIONS ${LVGL_TEST_OPTIONS_TEST_DEFHEAP})
  259. set (TEST_LIBS --coverage -fsanitize=address)
  260. else()
  261. message(FATAL_ERROR "Must provide a known options value (check main.py?).")
  262. endif()
  263. # Options lvgl and examples are compiled with.
  264. set(COMPILE_OPTIONS
  265. -DLV_CONF_PATH=${LVGL_TEST_DIR}/src/lv_test_conf.h
  266. -DLV_BUILD_TEST
  267. -pedantic-errors
  268. -Wall
  269. -Wclobbered
  270. -Wdeprecated
  271. -Wdouble-promotion
  272. -Wempty-body
  273. -Werror
  274. -Wextra
  275. -Wformat-security
  276. -Wmaybe-uninitialized
  277. -Wmissing-prototypes
  278. -Wpointer-arith
  279. -Wmultichar
  280. -Wno-discarded-qualifiers
  281. -Wpedantic
  282. -Wreturn-type
  283. -Wshadow
  284. -Wshift-negative-value
  285. -Wsizeof-pointer-memaccess
  286. -Wstack-usage=5000
  287. -Wtype-limits
  288. -Wundef
  289. -Wuninitialized
  290. -Wunreachable-code
  291. ${BUILD_OPTIONS}
  292. )
  293. # Options test cases are compiled with.
  294. set(LVGL_TESTFILE_COMPILE_OPTIONS
  295. ${COMPILE_OPTIONS}
  296. -Wno-missing-prototypes
  297. )
  298. get_filename_component(LVGL_DIR ${LVGL_TEST_DIR} DIRECTORY)
  299. # Include lvgl project file.
  300. include(${LVGL_DIR}/CMakeLists.txt)
  301. target_compile_options(lvgl PUBLIC ${COMPILE_OPTIONS})
  302. target_compile_options(lvgl_examples PUBLIC ${COMPILE_OPTIONS})
  303. set(TEST_INCLUDE_DIRS
  304. $<BUILD_INTERFACE:${LVGL_TEST_DIR}/src>
  305. $<BUILD_INTERFACE:${LVGL_TEST_DIR}/unity>
  306. $<BUILD_INTERFACE:${LVGL_TEST_DIR}>
  307. )
  308. add_library(test_common
  309. STATIC
  310. src/lv_test_indev.c
  311. src/lv_test_init.c
  312. src/test_fonts/font_1.c
  313. src/test_fonts/font_2.c
  314. src/test_fonts/font_3.c
  315. src/test_fonts/ubuntu_font.c
  316. unity/unity_support.c
  317. unity/unity.c
  318. )
  319. target_include_directories(test_common PUBLIC ${TEST_INCLUDE_DIRS})
  320. target_compile_options(test_common PUBLIC ${LVGL_TESTFILE_COMPILE_OPTIONS})
  321. # Some examples `#include "lvgl/lvgl.h"` - which is a path which is not
  322. # in this source repository. If this repo is in a directory names 'lvgl'
  323. # then we can add our parent directory to the include path.
  324. # TODO: This is not good practice and should be fixed.
  325. get_filename_component(LVGL_PARENT_DIR ${LVGL_DIR} DIRECTORY)
  326. target_include_directories(lvgl_examples PUBLIC $<BUILD_INTERFACE:${LVGL_PARENT_DIR}>)
  327. # Generate one test executable for each source file pair.
  328. # The sources in src/test_runners is auto-generated, the
  329. # sources in src/test_cases is the actual test case.
  330. file( GLOB TEST_CASE_FILES src/test_cases/*.c )
  331. foreach( test_case_fname ${TEST_CASE_FILES} )
  332. # If test file is foo/bar/baz.c then test_name is "baz".
  333. get_filename_component(test_name ${test_case_fname} NAME_WLE)
  334. if (${test_name} STREQUAL "_test_template")
  335. continue()
  336. endif()
  337. # Create path to auto-generated source file.
  338. set(test_runner_fname src/test_runners/${test_name}_Runner.c)
  339. add_executable( ${test_name}
  340. ${test_case_fname}
  341. ${test_runner_fname}
  342. )
  343. target_link_libraries(${test_name} test_common lvgl_examples lvgl_demos lvgl png m ${TEST_LIBS})
  344. target_include_directories(${test_name} PUBLIC ${TEST_INCLUDE_DIRS})
  345. target_compile_options(${test_name} PUBLIC ${LVGL_TESTFILE_COMPILE_OPTIONS})
  346. add_test(
  347. NAME ${test_name}
  348. WORKING_DIRECTORY ${LVGL_TEST_DIR}
  349. COMMAND ${test_name})
  350. endforeach( test_case_fname ${TEST_CASE_FILES} )
  351. endif()