Skip to content

Commit 9c846ee

Browse files
cmumfordkisvegabor
andauthored
test convert Makefile to CMake (lvgl#2495)
* Convert tests/Makefile to a cmake project file. This change switches the building of LVGL tests to use cmake which is more portable than make. Additionally, whenever cmake can be used, instead of the Python script (`main.py`), the former is preferred. The interface to `main.py` is unchanged, and tests are built and executated the same as before. This closes lvgl#2474. * Installing `gcovr` in GitHub workflow. * Documented steps to install libpng-dev. * Added missing stdout flush when running tests. * Grammar tweak in README. Co-authored-by: Gabor Kiss-Vamosi <[email protected]>
1 parent 5dbea7d commit 9c846ee

File tree

12 files changed

+472
-478
lines changed

12 files changed

+472
-478
lines changed

.github/workflows/ccpp.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v2
1616
- uses: ammaraskar/gcc-problem-matcher@master
1717
- name: Run tests
18-
run: sudo apt-get install libpng-dev ruby-full; cd tests; python ./main.py report
18+
run: sudo apt-get install libpng-dev ruby-full gcovr; cd tests; python ./main.py report
1919
- name: Upload coverage to Codecov
2020
uses: codecov/codecov-action@v1
2121
if: github.event_name == 'push'

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ out_html
1919
__pycache__
2020
/emscripten_builder
2121
test_screenshot_error.h
22+
build/
23+
tests/build_*/
24+
tests/report/

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ endif() # CONFIG_LVGL
6868

6969
else()
7070

71-
file(GLOB_RECURSE SOURCES src/*.c)
71+
file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/*.c)
7272
add_library(lvgl STATIC ${SOURCES})
7373

74+
file(GLOB_RECURSE EXAMPLE_SOURCES ${CMAKE_CURRENT_LIST_DIR}/examples/*.c)
75+
add_library(lvgl_examples STATIC ${EXAMPLE_SOURCES})
76+
7477
endif()

tests/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
*.out
22
*_Runner.c
3-
/report

tests/CMakeLists.txt

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

tests/Makefile

-56
This file was deleted.

0 commit comments

Comments
 (0)