Skip to content

Commit

Permalink
test add build test again, add dropdown test, integrate gcov and gvocr
Browse files Browse the repository at this point in the history
  • Loading branch information
kisvegabor committed Jun 18, 2021
1 parent e9e010a commit e35b1d0
Show file tree
Hide file tree
Showing 16 changed files with 408 additions and 175 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
**/*bin
**/*.swp
**/*.swo
**/*.gcda
**/*.gcno
tags
docs/api_doc
scripts/cppcheck_res.txt
Expand All @@ -15,3 +17,4 @@ docs/env
out_html
__pycache__
/emscripten_builder
image_err.h
2 changes: 1 addition & 1 deletion src/widgets/lv_dropdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ const char * lv_dropdown_get_options(const lv_obj_t * obj)
LV_ASSERT_OBJ(obj, MY_CLASS);

lv_dropdown_t * dropdown = (lv_dropdown_t *)obj;
return dropdown->options;
return dropdown->options == NULL ? "" : dropdown->options;
}

uint16_t lv_dropdown_get_selected(const lv_obj_t * obj)
Expand Down
19 changes: 7 additions & 12 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
CC ?= gcc
LVGL_DIR ?= ${shell pwd}/../..
LVGL_DIR_NAME ?= lvgl
OBJDIR = objs

WARNINGS = -Werror -Wall -Wextra \
-Wshadow -Wundef -Wmaybe-uninitialized -Wmissing-prototypes -Wpointer-arith -Wuninitialized \
Expand All @@ -15,22 +14,18 @@ WARNINGS = -Werror -Wall -Wextra \
WARNINGS += -Wpedantic -pedantic-errors

#-Wno-unused-value -Wno-unused-parameter
OPTIMIZATION ?= -O3 -g0
OPTIMIZATION ?= -g0

CFLAGS ?= -I$(LVGL_DIR)/ -Iunity $(DEFINES) $(WARNINGS) $(OPTIMIZATION) -I$(LVGL_DIR) -I.
CFLAGS ?= -I$(LVGL_DIR)/ --coverage -Iunity $(DEFINES) $(WARNINGS) $(OPTIMIZATION) -I$(LVGL_DIR) -I.

LDFLAGS ?= -lpng
LDFLAGS ?= -lpng --coverage
BIN ?= test

include ../lvgl.mk

CSRCS += ${TEST_SRC}
CSRCS += unity/unity.c
CSRCS += unity/unity_support.c
CSRCS += lv_test_init.c
CSRCS += src/test_fonts/font_1.c
CSRCS += src/test_fonts/font_2.c
CSRCS += src/test_fonts/font_3.c
CSRCS := $(CSRCS) $(EXTRA_CSRCS)

OBJEXT ?= .o

Expand All @@ -46,13 +41,13 @@ OBJS = $(AOBJS) $(COBJS)

all: default

$(OBJDIR)/%.o: %.c
%.o: %.c
@$(CC) $(CFLAGS) -c -o $@ $<
@echo "CC $<"
# @echo "CC $<"

default: $(AOBJS) $(COBJS) $(MAINOBJ)
$(CC) -o $(BIN) $(MAINOBJ) $(AOBJS) $(COBJS) $(LDFLAGS)

clean:
find . -type f -name '*.o' -exec rm -f {} +
find ../ -type f -name '*.o' -exec rm -f {} +
rm -f $(BIN)
49 changes: 40 additions & 9 deletions tests/build.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
#!/usr/bin/env python3

import os
import re

lvgldirname = os.path.abspath('..')
lvgldirname = os.path.basename(lvgldirname)
lvgldirname = '"' + lvgldirname + '"'

base_defines = '"-DLV_CONF_PATH=' + lvgldirname +'/tests/lv_test_conf.h -DLV_BUILD_TEST"'
optimization = '"-O3 -g0"'

def build(defines, test_name):
global base_defines, optimization
def build(defines):
global base_defines
optimization = '"-O3 -g0"'
d_all = base_defines[:-1] + " ";

for d in defines:
d_all += " -D" + d + "=" + str(defines[d])

d_all += '"'
# -s makes it silence
cmd = "make -s -j BIN=test.bin " + "MAINSRC=lv_test_main.c LVGL_DIR_NAME=" + lvgldirname + " DEFINES=" + d_all + " OPTIMIZATION=" + optimization

print("")
print("Build")
print("-----------------------")
# print(cmd)
ret = os.system(cmd)
if(ret != 0):
print("BUILD ERROR! (error code " + str(ret) + ")")
exit(1)

print("")
print("Run")
print("-----------------------")
ret = os.system("./test.bin")
if(ret != 0):
print("RUN ERROR! (error code " + str(ret) + ")")
exit(1)


def build_test(defines, test_name):
global base_defines
optimization = '"-g0"'

print("")
print("")
print("~~~~~~~~~~~~~~~~~~~~~~~~")
print(test_name)
print(re.search("/[a-z_]*$", test_name).group(0)[1:])
print("~~~~~~~~~~~~~~~~~~~~~~~~")

d_all = base_defines[:-1] + " ";
Expand All @@ -25,12 +58,14 @@ def build(defines, test_name):
test_file_name = test_name + ".c"
test_file_runner_name = test_name + "_Runner.c"
test_file_runner_name = test_file_runner_name.replace("/test_cases/", "/test_runners/")
csrcs = " EXTRA_CSRCS=\"unity/unity.c unity/unity_support.c src/test_fonts/font_1.c src/test_fonts/font_2.c src/test_fonts/font_3.c \" "
# -s makes it silence
cmd = "make -s -j BIN=test.bin MAINSRC=" + test_file_name + " TEST_SRC=" + test_file_runner_name + " LVGL_DIR_NAME=" + lvgldirname + " DEFINES=" + d_all + " OPTIMIZATION=" + optimization
cmd = "make -s -j BIN=test.bin MAINSRC=" + test_file_name + " TEST_SRC=" + test_file_runner_name + csrcs + " LVGL_DIR_NAME=" + lvgldirname + " DEFINES=" + d_all + " OPTIMIZATION=" + optimization

print("")
print("Build")
print("-----------------------")
# print(cmd)
ret = os.system(cmd)
if(ret != 0):
print("BUILD ERROR! (error code " + str(ret) + ")")
Expand All @@ -43,10 +78,6 @@ def build(defines, test_name):
if(ret != 0):
print("RUN ERROR! (error code " + str(ret) + ")")
exit(1)

print("")
print("Finished")
print("-----------------------")

def clean():
print("")
Expand Down
53 changes: 50 additions & 3 deletions tests/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@

}

minimal_16bit_swap = {
normal_16bit_swap = {
"LV_COLOR_DEPTH":16,
"LV_COLOR_16_SWAP":1,

"LV_MEM_SIZE":64 * 1024,

"LV_DPI_DEF":40,
"LV_DRAW_COMPLEX":0,
"LV_DRAW_COMPLEX":1,

"LV_USE_LOG":1,

Expand Down Expand Up @@ -152,5 +152,52 @@

"LV_BUILD_EXAMPLES":1,

"LV_FONT_DEFAULT":"\\\"&lv_font_montserrat_32\\\"",
"LV_FONT_DEFAULT":"\\\"&lv_font_montserrat_24\\\"",
}

test = {
"LV_COLOR_DEPTH":32,
"LV_MEM_SIZE":2 * 1024 * 1024,

"LV_SHADOW_CACHE_SIZE":10*1024,
"LV_IMG_CACHE_DEF_SIZE":32,

"LV_USE_LOG":1,
"LV_LOG_PRINTF":1,
"LV_USE_FONT_SUBPX": 1,
"LV_FONT_SUBPX_BGR":1,

"LV_USE_ASSERT_NULL":1,
"LV_USE_ASSERT_MALLOC":1,
"LV_USE_ASSERT_MEM_INTEGRITY":1,
"LV_USE_ASSERT_OBJ":1,
"LV_USE_ASSERT_STYLE":1,

"LV_USE_USER_DATA": 1,
"LV_USE_LARGE_COORD": 1,

"LV_FONT_MONTSERRAT_14":1,
"LV_FONT_MONTSERRAT_16":1,
"LV_FONT_MONTSERRAT_18":1,
"LV_FONT_MONTSERRAT_24":1,
"LV_FONT_MONTSERRAT_48":1,
"LV_FONT_MONTSERRAT_12_SUBPX":1,
"LV_FONT_MONTSERRAT_28_COMPRESSED":1,
"LV_FONT_DEJAVU_16_PERSIAN_HEBREW":1,
"LV_FONT_SIMSUN_16_CJK":1,
"LV_FONT_UNSCII_8":1,
"LV_FONT_UNSCII_16":1,
"LV_FONT_FMT_TXT_LARGE":1,
"LV_USE_FONT_COMPRESSED":1,

"LV_USE_BIDI": 1,
"LV_USE_ARABIC_PERSIAN_CHARS":1,
"LV_USE_PERF_MONITOR":1,
"LV_USE_MEM_MONITOR":1,

"LV_LABEL_TEXT_SELECTION":1,

"LV_BUILD_EXAMPLES":1,

"LV_FONT_DEFAULT":"\\\"&lv_font_montserrat_14\\\"",
}
2 changes: 0 additions & 2 deletions tests/lv_test_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ static lv_color_t disp_buf1[HOR_RES * VER_RES];

void lv_test_init(void)
{
printf("Call lv_init...\n");
lv_init();
hal_init();
}

void lv_test_deinit(void)
{
printf("Call lv_deinit...\n");
lv_mem_deinit();
}

Expand Down
134 changes: 2 additions & 132 deletions tests/lv_test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,144 +4,14 @@

#if LV_BUILD_TEST && !defined(LV_BUILD_TEST_NO_MAIN)
#include <sys/time.h>

#define HOR_RES 800
#define VER_RES 480

static void hal_init(void);
static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);

lv_color_t test_fb[HOR_RES * VER_RES];
#include "lv_test_init.h"

int main(void)
{
printf("Call lv_init...\n");
lv_init();

hal_init();

lv_test_core();
// lv_test_label();
lv_test_init();

printf("Exit with success!\n");
return 0;
}

static void * open_cb(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
{
(void) drv;
(void) mode;

FILE * fp = fopen(path, "rb"); // only reading is supported

return fp;
}

static lv_fs_res_t close_cb(lv_fs_drv_t * drv, void * file_p)
{
(void) drv;

fclose(file_p);
return LV_FS_RES_OK;
}

static lv_fs_res_t read_cb(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
{
(void) drv;

*br = fread(buf, 1, btr, file_p);
return (*br <= 0) ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
}

static lv_fs_res_t seek_cb(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t w)
{
(void) drv;

uint32_t w2;
switch(w) {
case LV_FS_SEEK_SET:
w2 = SEEK_SET;
break;
case LV_FS_SEEK_CUR:
w2 = SEEK_CUR;
break;
case LV_FS_SEEK_END:
w2 = SEEK_END;
break;
default:
w2 = SEEK_SET;
}

fseek (file_p, pos, w2);

return LV_FS_RES_OK;
}

static lv_fs_res_t tell_cb(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
{
(void) drv;

*pos_p = ftell(file_p);

return LV_FS_RES_OK;
}


static void hal_init(void)
{
static lv_disp_draw_buf_t draw_buf;
lv_color_t * disp_buf1 = (lv_color_t *)malloc(LV_HOR_RES * LV_VER_RES * sizeof(lv_color_t));

lv_disp_draw_buf_init(&draw_buf, disp_buf1, NULL, LV_HOR_RES * LV_VER_RES);

static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf = &draw_buf;
disp_drv.flush_cb = dummy_flush_cb;
disp_drv.hor_res = HOR_RES;
disp_drv.ver_res = VER_RES;
lv_disp_drv_register(&disp_drv);

static lv_fs_drv_t drv;
lv_fs_drv_init(&drv); /*Basic initialization*/

drv.letter = 'F'; /*An uppercase letter to identify the drive*/
drv.open_cb = open_cb; /*Callback to open a file*/
drv.close_cb = close_cb; /*Callback to close a file*/
drv.read_cb = read_cb; /*Callback to read a file*/
drv.seek_cb = seek_cb; /*Callback to seek in a file (Move cursor)*/
drv.tell_cb = tell_cb; /*Callback to tell the cursor position*/

lv_fs_drv_register(&drv); /*Finally register the drive*/
}
#include <stdio.h>

static void dummy_flush_cb(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
LV_UNUSED(area);
LV_UNUSED(color_p);

memcpy(test_fb, color_p, lv_area_get_size(area) * sizeof(lv_color_t));

lv_disp_flush_ready(disp_drv);
}

uint32_t custom_tick_get(void)
{
static uint64_t start_ms = 0;
if(start_ms == 0) {
struct timeval tv_start;
gettimeofday(&tv_start, NULL);
start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
}

struct timeval tv_now;
gettimeofday(&tv_now, NULL);
uint64_t now_ms;
now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;

uint32_t time_ms = now_ms - start_ms;
return time_ms;
}

#endif
Loading

0 comments on commit e35b1d0

Please sign in to comment.