Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete the timer that create in lv_demo_stress when exit #25

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions demos/stress/lv_demo_stress.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static lv_obj_t * main_page;
static lv_obj_t * ta;
static size_t mem_free_start = 0;
static int16_t g_state = -1;
static lv_timer_t * g_demo_timer = NULL;

/**********************
* MACROS
Expand All @@ -46,8 +47,13 @@ static int16_t g_state = -1;
void lv_demo_stress(void)
{
LV_LOG_USER("Starting stress test. (< 100 bytes permanent memory leak is normal due to fragmentation)");
lv_timer_t * t = lv_timer_create(obj_test_task_cb, LV_DEMO_STRESS_TIME_STEP, NULL);
lv_timer_ready(t); /*Prepare the test right now in first state change.*/
g_demo_timer = lv_timer_create(obj_test_task_cb, LV_DEMO_STRESS_TIME_STEP, NULL);
lv_timer_ready(g_demo_timer); /*Prepare the test right now in first state change.*/
}

void lv_demo_stress_deinit(void)
{
if(g_demo_timer) lv_timer_delete(g_demo_timer);
}

bool lv_demo_stress_finished(void)
Expand Down
5 changes: 5 additions & 0 deletions demos/stress/lv_demo_stress.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ void lv_demo_stress(void);
*/
bool lv_demo_stress_finished(void);

/********************
* stress demo deinit
*/
void lv_demo_stress_deinit(void);

/**********************
* MACROS
**********************/
Expand Down
90 changes: 90 additions & 0 deletions tests/check_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env python3
import os
import re
import sys


def convert_config_to_kconfig(filename):
configs = {}
with open(filename, "r") as file:
lines = file.readlines()

for line in lines:
line = line.strip()
if line.startswith("#define "):
kv = line[8:]
space_pos = kv.find(" ")
key = kv[0:space_pos].strip()
val = kv[space_pos:].strip()
print("key:", key, "val:", val)
config = ""
if val == "1":
configs[key] = "y"
if val == "0":
configs[key] = "n"
elif re.match(r"\((-*[0-9]*\s*\**)+\)", val):
val = val[1 : len(val) - 1]
vals = val.split("*")
multi = 1
for subval in vals:
multi = multi * int(subval)
configs[key] = str(multi)
elif re.match(r"\'[A-Za-z]\'", val):
val = val[1:2]
configs[key] = str(ord(val))
elif re.match(r"\"\w+.\w+\"", val):
configs[key] = val

return configs


def read_kconfig(filename):
configs = {}
with open(filename, "r") as file:
lines = file.readlines()

for line in lines:
line = line.strip()
if not line.startswith("#"):
kv = line.split("=")
key = kv[0].replace("CONFIG_", "")
val = kv[1]
if len(kv) == 2:
configs[key] = val

return configs


def merge_rewrite_map(filename, map1, map2):
map1.update(map2)
sorted_dict = {k: map1[k] for k in sorted(map1)}
desc = """#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
"""
with open(filename, "w") as file:
file.writelines(desc)
for key, value in sorted_dict.items():
file.write("".join(["CONFIG_", key, "=", value, "\n"]))


if __name__ == "__main__":
if len(sys.argv) != 3:
print(
"""usage: python check_config.py config.h defconfig defconfig_new
config.h: a header configuration file that you want to convert;
defconfig: a default configuration file
defconfig_new: a new configuration file that contains config.h and defconfig"""
)
sys.exit(1)

filename = sys.argv[1]
filename_kconfig = sys.argv[2]
filename_kconfig_new = sys.argv[3]
configs = convert_config_to_kconfig(filename)
configs_def = read_kconfig(filename_kconfig)
merge_rewrite_map(filename_kconfig_new, configs_def, configs)
70 changes: 48 additions & 22 deletions tests/src/lv_test_init.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#if LV_BUILD_TEST
#include "lv_test_init.h"
#include "../unity/unity.h"
#include "lv_test_indev.h"
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include "../unity/unity.h"
#include <sys/time.h>

#define HOR_RES 800
#define VER_RES 480

static void hal_init(void);
static void dummy_flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * color_p);
static void dummy_flush_cb(lv_display_t* disp, const lv_area_t* area, uint8_t* color_p);

uint8_t * last_flushed_buf;
lv_indev_t * lv_test_mouse_indev;
lv_indev_t * lv_test_keypad_indev;
lv_indev_t * lv_test_encoder_indev;
uint8_t* last_flushed_buf;
lv_indev_t* lv_test_mouse_indev = NULL;
lv_indev_t* lv_test_keypad_indev = NULL;
lv_indev_t* lv_test_encoder_indev = NULL;
lv_display_t* lv_test_disp = NULL;

void lv_test_init(void)
{
Expand All @@ -26,31 +27,56 @@ void lv_test_init(void)
void lv_test_deinit(void)
{
lv_mem_deinit();
lv_deinit();
lv_test_disp = NULL;
lv_test_mouse_indev = NULL;
lv_test_keypad_indev = NULL;
lv_test_encoder_indev = NULL;
}

static void hal_init(void)
{

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_buffers(disp, lv_draw_buf_align(test_fb, LV_COLOR_FORMAT_ARGB8888), NULL, HOR_RES * VER_RES * 4,
LV_DISPLAY_RENDER_MODE_DIRECT);
lv_display_set_flush_cb(disp, dummy_flush_cb);
lv_memzero(test_fb, sizeof(test_fb));

if (lv_test_disp == NULL) {
lv_test_disp = lv_display_create(HOR_RES, VER_RES);
lv_display_set_buffers(lv_test_disp, lv_draw_buf_align(test_fb, LV_COLOR_FORMAT_ARGB8888), NULL, HOR_RES * VER_RES * 4,
LV_DISPLAY_RENDER_MODE_DIRECT);
lv_display_set_flush_cb(lv_test_disp, dummy_flush_cb);
}

lv_test_mouse_indev = lv_indev_create();
lv_indev_set_type(lv_test_mouse_indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(lv_test_mouse_indev, lv_test_mouse_read_cb);
if (lv_test_mouse_indev == NULL) {
lv_test_mouse_indev = lv_indev_create();
lv_indev_set_type(lv_test_mouse_indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_read_cb(lv_test_mouse_indev, lv_test_mouse_read_cb);
}

lv_test_keypad_indev = lv_indev_create();
lv_indev_set_type(lv_test_keypad_indev, LV_INDEV_TYPE_KEYPAD);
lv_indev_set_read_cb(lv_test_keypad_indev, lv_test_keypad_read_cb);
if (lv_test_keypad_indev == NULL) {
lv_test_keypad_indev = lv_indev_create();
lv_indev_set_type(lv_test_keypad_indev, LV_INDEV_TYPE_KEYPAD);
lv_indev_set_read_cb(lv_test_keypad_indev, lv_test_keypad_read_cb);
}

if (lv_test_encoder_indev == NULL) {
lv_test_encoder_indev = lv_indev_create();
lv_indev_set_type(lv_test_encoder_indev, LV_INDEV_TYPE_ENCODER);
lv_indev_set_read_cb(lv_test_encoder_indev, lv_test_encoder_read_cb);
}
}

void hal_init_colorformat(lv_color_format_t colorformat)
{
static lv_color32_t test_fb[(HOR_RES + LV_DRAW_BUF_STRIDE_ALIGN - 1) * VER_RES + LV_DRAW_BUF_ALIGN];
lv_memzero(test_fb, sizeof(test_fb));

lv_test_encoder_indev = lv_indev_create();
lv_indev_set_type(lv_test_encoder_indev, LV_INDEV_TYPE_ENCODER);
lv_indev_set_read_cb(lv_test_encoder_indev, lv_test_encoder_read_cb);
if (lv_test_disp != NULL) {
lv_display_set_buffers(lv_test_disp, lv_draw_buf_align(test_fb, colorformat), NULL, HOR_RES * VER_RES * 4,
LV_DISPLAY_RENDER_MODE_DIRECT);
}
}

static void dummy_flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * color_p)
static void dummy_flush_cb(lv_display_t* disp, const lv_area_t* area, uint8_t* color_p)
{
LV_UNUSED(area);
LV_UNUSED(color_p);
Expand Down
6 changes: 6 additions & 0 deletions tests/src/lv_test_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ extern "C" {
void lv_test_init(void);
void lv_test_deinit(void);

/*
* a workaround to set colorformat of display.
* reinit the buffer of display by colorformat.
*/
void hal_init_colorformat(lv_color_format_t colorformat);

#ifdef __cplusplus
} /*extern "C"*/
#endif
Expand Down
8 changes: 6 additions & 2 deletions tests/src/test_cases/test_demo_stress.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "../demos/lv_demos.h"
#include "../lvgl.h"

#include "unity/unity.h"

Expand Down Expand Up @@ -28,10 +28,14 @@ void test_demo_stress(void)
loop_through_stress_test();
size_t mem_before = lv_test_get_free_mem();
/* loop 5 more times */
for(uint32_t i = 0; i < 5; i++) {
for (uint32_t i = 0; i < 5; i++) {
loop_through_stress_test();
}
TEST_ASSERT_EQUAL(mem_before, lv_test_get_free_mem());

#if LV_USE_DEMO_STRESS
lv_demo_stress_deinit();
#endif
}

#endif
Loading