feat(event): return event dsc for later to remove (#5630)

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Neo Xu
2024-02-20 04:43:57 +08:00
committed by GitHub
parent f8f69215a5
commit f5f19ca7f0
10 changed files with 86 additions and 34 deletions

View File

@@ -90,7 +90,7 @@ def build_tests(options_name, build_type, clean):
created_build_dir = True
os.chdir(build_dir)
if created_build_dir:
subprocess.check_call(['cmake', '-DCMAKE_BUILD_TYPE=%s' % build_type,
subprocess.check_call(['cmake', '-GNinja', '-DCMAKE_BUILD_TYPE=%s' % build_type,
'-D%s=1' % options_name, '..'])
subprocess.check_call(['cmake', '--build', build_dir,
'--parallel', str(os.cpu_count())])

View File

@@ -23,4 +23,23 @@ void test_event_object_deletion(void)
lv_obj_send_event(obj, LV_EVENT_VALUE_CHANGED, NULL);
}
/* Add and then remove event should not memory leak */
void test_event_should_not_memory_lean(void)
{
lv_mem_monitor_t monitor;
lv_mem_monitor(&monitor);
lv_obj_t * obj = lv_obj_create(lv_screen_active());
uint32_t initial_free_size = monitor.free_size;
for(int i = 0; i < 10; i++) {
lv_obj_add_event_cb(obj, NULL, LV_EVENT_ALL, NULL);
}
lv_obj_delete(obj);
lv_mem_monitor_t m2;
lv_mem_monitor(&m2);
TEST_ASSERT_LESS_OR_EQUAL_CHAR(initial_free_size, m2.free_size);
}
#endif

View File

@@ -50,12 +50,9 @@ void test_switch_should_not_leak_memory_after_deletion(void)
{
size_t idx = 0;
uint32_t initial_available_memory = 0;
uint32_t final_available_memory = 0;
lv_mem_monitor_t monitor;
lv_obj_t * switches[SWITCHES_CNT] = {NULL};
lv_mem_monitor(&monitor);
initial_available_memory = monitor.free_size;
initial_available_memory = lv_test_get_free_mem();
for(idx = 0; idx < SWITCHES_CNT; idx++) {
switches[idx] = lv_switch_create(scr);
@@ -65,10 +62,7 @@ void test_switch_should_not_leak_memory_after_deletion(void)
lv_obj_delete(switches[idx]);
}
lv_mem_monitor(&monitor);
final_available_memory = monitor.free_size;
LV_HEAP_CHECK(TEST_ASSERT_LESS_OR_EQUAL(initial_available_memory, final_available_memory));
LV_HEAP_CHECK(TEST_ASSERT_MEM_LEAK_LESS_THAN(initial_available_memory, 24));
}
void test_switch_animation(void)

View File

@@ -8,6 +8,7 @@ extern "C" {
#include <stdbool.h>
#include "../../lvgl.h"
#include "../src/lv_test_helpers.h"
bool lv_test_assert_image_eq(const char * fn_ref);
@@ -38,11 +39,10 @@ bool lv_test_assert_image_eq(const char * fn_ref);
# define TEST_ASSERT_EQUAL_COLOR32_MESSAGE(c1, c2, msg) TEST_ASSERT_TRUE(lv_color32_eq(c1, c2), msg)
# define TEST_ASSERT_MEM_LEAK_LESS_THAN(prev_usage, threshold) TEST_ASSERT_LESS_THAN(threshold, LV_ABS((int64_t)(prev_usage) - (int64_t)lv_test_get_free_mem()));
# define TEST_ASSERT_MEM_LEAK_LESS_THAN(prev_usage, threshold) TEST_ASSERT_LESS_OR_EQUAL(threshold, LV_ABS((int64_t)(prev_usage) - (int64_t)lv_test_get_free_mem()));
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_UNITY_SUPPORT_H*/