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