From f9c98905b9a72c366cf9384b363c33587bb575ea Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 14 Nov 2023 14:52:51 +0100 Subject: [PATCH] fix(draw): make tests work with non default LV_DRAW_BUF_ALIGN --- src/stdlib/builtin/lv_mem_core_builtin.c | 4 ++-- tests/src/lv_test_conf.h | 5 ++++- tests/src/lv_test_init.c | 7 ++++--- tests/src/test_cases/draw/test_draw_vector.c | 3 ++- tests/src/test_cases/test_anim_timeline.c | 7 ++----- tests/src/test_cases/test_bindings.c | 7 ++++--- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/stdlib/builtin/lv_mem_core_builtin.c b/src/stdlib/builtin/lv_mem_core_builtin.c index 40dfa254d..0763ab3d8 100644 --- a/src/stdlib/builtin/lv_mem_core_builtin.c +++ b/src/stdlib/builtin/lv_mem_core_builtin.c @@ -195,9 +195,9 @@ void lv_mem_monitor_core(lv_mem_monitor_t * mon_p) lv_tlsf_walk_pool(*pool_p, lv_mem_walker, mon_p); } - mon_p->used_pct = 100 - (100U * mon_p->free_size) / mon_p->total_size; + mon_p->used_pct = 100 - (uint64_t)100U * mon_p->free_size / mon_p->total_size; if(mon_p->free_size > 0) { - mon_p->frag_pct = mon_p->free_biggest_size * 100U / mon_p->free_size; + mon_p->frag_pct = (uint64_t)mon_p->free_biggest_size * 100U / mon_p->free_size; mon_p->frag_pct = 100 - mon_p->frag_pct; } else { diff --git a/tests/src/lv_test_conf.h b/tests/src/lv_test_conf.h index b01fa2a0f..1433031b5 100644 --- a/tests/src/lv_test_conf.h +++ b/tests/src/lv_test_conf.h @@ -86,8 +86,11 @@ typedef void * lv_user_data_t; #if defined(LVGL_CI_USING_SYS_HEAP) || defined(LVGL_CI_USING_DEF_HEAP) #undef LV_LOG_PRINTF +/*Use a large value be sure any issues will cause crash*/ //#define LV_DRAW_BUF_STRIDE_ALIGN 64 -//#define LV_DRAW_BUF_ALIGN 40 /*Use non power of 2 to avoid the case when `malloc` returns aligned pointer by default*/ + +/*Use non power of 2 to avoid the case when `malloc` returns aligned pointer by default, and use a large value be sure any issues will cause crash*/ +#define LV_DRAW_BUF_ALIGN 852 /*For screenshots*/ #undef LV_USE_PERF_MONITOR diff --git a/tests/src/lv_test_init.c b/tests/src/lv_test_init.c index c62aaa037..5316ff5d8 100644 --- a/tests/src/lv_test_init.c +++ b/tests/src/lv_test_init.c @@ -1,4 +1,4 @@ -#if LV_BUILD_TEST +#if LV_BUILD_TEST || 1 #include "lv_test_init.h" #include "lv_test_indev.h" #include @@ -31,9 +31,10 @@ void lv_test_deinit(void) static void hal_init(void) { - static lv_color32_t test_fb[HOR_RES * VER_RES * 2]; + static lv_color32_t test_fb[(HOR_RES + LV_DRAW_BUF_STRIDE_ALIGN - 1) * VER_RES + LV_DRAW_BUF_ALIGN]; lv_display_t * disp = lv_display_create(HOR_RES, VER_RES); - lv_display_set_draw_buffers(disp, test_fb, NULL, HOR_RES * VER_RES, LV_DISPLAY_RENDER_MODE_DIRECT); + lv_display_set_draw_buffers(disp, lv_draw_buf_align(test_fb, LV_COLOR_FORMAT_ARGB8888), NULL, HOR_RES * VER_RES, + LV_DISPLAY_RENDER_MODE_DIRECT); lv_display_set_flush_cb(disp, dummy_flush_cb); lv_test_mouse_indev = lv_indev_create(); diff --git a/tests/src/test_cases/draw/test_draw_vector.c b/tests/src/test_cases/draw/test_draw_vector.c index 858687134..f3f5398ca 100644 --- a/tests/src/test_cases/draw/test_draw_vector.c +++ b/tests/src/test_cases/draw/test_draw_vector.c @@ -204,7 +204,8 @@ static void canvas_draw(const char * name, void (*draw_cb)(lv_layer_t *)) { static uint8_t canvas_buf[CANVAS_WIDTH_TO_STRIDE(640, 4) * 480 + LV_DRAW_BUF_ALIGN]; lv_obj_t * canvas = lv_canvas_create(lv_screen_active()); - lv_canvas_set_buffer(canvas, canvas_buf, 640, 480, LV_COLOR_FORMAT_ARGB8888); + lv_canvas_set_buffer(canvas, lv_draw_buf_align(canvas_buf, LV_COLOR_FORMAT_ARGB8888), 640, 480, + LV_COLOR_FORMAT_ARGB8888); lv_layer_t layer; lv_canvas_init_layer(canvas, &layer); diff --git a/tests/src/test_cases/test_anim_timeline.c b/tests/src/test_cases/test_anim_timeline.c index 56ffa609a..6ac472acd 100644 --- a/tests/src/test_cases/test_anim_timeline.c +++ b/tests/src/test_cases/test_anim_timeline.c @@ -1,4 +1,5 @@ -#if LV_BUILD_TEST || 1 +#if LV_BUILD_TEST + #include "../lvgl.h" #include "unity/unity.h" @@ -77,10 +78,8 @@ void test_anim_timeline_progress_1(void) lv_refr_now(NULL); TEST_ASSERT_EQUAL(700, lv_obj_get_x(obj)); - } - void test_anim_timeline_progress_2(void) { lv_obj_t * obj = lv_obj_create(lv_scr_act()); @@ -106,7 +105,6 @@ void test_anim_timeline_progress_2(void) * 0 21845 43690 65535 progress */ - anim_timeline = lv_anim_timeline_create(); lv_anim_timeline_add(anim_timeline, 0, &a1); lv_anim_timeline_add(anim_timeline, 500, &a2); @@ -146,5 +144,4 @@ void test_anim_timeline_progress_2(void) TEST_ASSERT_EQUAL(300, lv_obj_get_y(obj)); } - #endif diff --git a/tests/src/test_cases/test_bindings.c b/tests/src/test_cases/test_bindings.c index 5dcb0f56c..4b48cfadd 100644 --- a/tests/src/test_cases/test_bindings.c +++ b/tests/src/test_cases/test_bindings.c @@ -1,8 +1,9 @@ -#if LV_BUILD_TEST || 1 +#if LV_BUILD_TEST #include "../lvgl.h" #include "unity/unity.h" #include "lv_test_indev.h" +#include "lv_test_helpers.h" static void create_ui(void); static void chart_type_observer_cb(lv_subject_t * subject, lv_observer_t * observer); @@ -152,12 +153,12 @@ static void create_ui(void) } /*Large byte array*/ - static uint8_t canvas_buf[400 * 100 * 2]; + static uint8_t canvas_buf[CANVAS_WIDTH_TO_STRIDE(400, 2) * 100 * 2]; lv_obj_t * canvas = lv_canvas_create(scr); lv_obj_set_grid_cell(canvas, LV_GRID_ALIGN_START, 0, 2, LV_GRID_ALIGN_START, 2, 1); /*Test RGB565 rendering*/ - lv_canvas_set_buffer(canvas, canvas_buf, 400, 100, LV_COLOR_FORMAT_RGB565); + lv_canvas_set_buffer(canvas, lv_draw_buf_align(canvas_buf, LV_COLOR_FORMAT_RGB565), 400, 100, LV_COLOR_FORMAT_RGB565); lv_canvas_fill_bg(canvas, c2, LV_OPA_COVER); draw_to_canvas(canvas);