From 52bef7e67b8aea5d801b4afac63d15ff110b37ca Mon Sep 17 00:00:00 2001 From: Liu Zhongwei Date: Sun, 27 Oct 2024 13:54:32 +0800 Subject: [PATCH] feat(ci): add run test --- .../{build_test.yml => run_test.yml} | 12 +++++++--- CMakeLists.txt | 4 ++++ main/main.cpp | 23 ++++++++++++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) rename .github/workflows/{build_test.yml => run_test.yml} (73%) diff --git a/.github/workflows/build_test.yml b/.github/workflows/run_test.yml similarity index 73% rename from .github/workflows/build_test.yml rename to .github/workflows/run_test.yml index 129adf7..017d031 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/run_test.yml @@ -1,4 +1,4 @@ -name: Build Test Application +name: Build and Run Test Application on: workflow_dispatch: @@ -11,7 +11,7 @@ on: jobs: build: runs-on: ubuntu-22.04 - name: Build Test Application + name: Build and Run Test Application container: image: ubuntu:22.04 @@ -36,4 +36,10 @@ jobs: - name: Build Application working-directory: ./ run: | - cmake -B ./build && make -C ./build + cmake -DRUN_TEST=1 -B ./build + make -C ./build + + - name: Run Application + working-directory: ./ + run: | + ./bin/esp_brookesia_simulator_vscode diff --git a/CMakeLists.txt b/CMakeLists.txt index 2554689..76bdb1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,9 @@ set(DISP_DEF "-DDISP_HOR_RES=1024 -DDISP_VER_RES=600") # Resolution of the disp set(LVGL_DEF "-DLV_CONF_INCLUDE_SIMPLE") # Used for LVGL related codes set(LV_DRIVERS_DEF "-DUSE_SDL") # Used for lv_drivers related codes set(ESP_BROOKESIA_DEF "-DESP_BROOKESIA_KCONFIG_IGNORE") # Used for ESP-Brookesia related codes +if(RUN_TEST) +set(SIMULATOR_DEF "${SIMULATOR_DEF} -DRUN_TEST=1") # Flag for simulator +endif() # Set C/CXX toolchain if(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(CMAKE_C_COMPILER /usr/bin/gcc) @@ -37,6 +40,7 @@ set(CMAKE_C_FLAGS "-O0 -g -Wall -Wextra -Wshadow -Wundef -Wno-unused-function") set(CMAKE_CXX_FLAGS "-O0 -g -Wall -Wextra -Wshadow -Wundef -Wno-unused-function -Wno-unused-parameter \ -Wno-missing-field-initializers") # Set cmake options +set(CMAKE_OBJECT_PATH_MAX 512) # Avoid long path error in Windows set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) # Set componets directory diff --git a/main/main.cpp b/main/main.cpp index 33cf43a..9faeb18 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -28,6 +28,9 @@ /********************* * DEFINES *********************/ +/** + * Use the stylesheet corresponding to the resolution; otherwise, another built-in stylesheet will be used. + */ #if (DISP_HOR_RES == 320) && (DISP_VER_RES == 240) #define EXAMPLE_ESP_BROOKESIA_PHONE_DARK_STYLESHEET() ESP_BROOKESIA_PHONE_320_240_DARK_STYLESHEET() #elif (DISP_HOR_RES == 320) && (DISP_VER_RES == 480) @@ -44,6 +47,12 @@ #define EXAMPLE_ESP_BROOKESIA_PHONE_DARK_STYLESHEET() ESP_BROOKESIA_PHONE_1280_800_DARK_STYLESHEET() #endif +#define LVGL_TIMER_HANDLER_PERIOD_US (5 * 1000) + +#ifdef RUN_TEST +#define RUN_TEST_TIMEOUT_S (5) +#endif + /********************** * TYPEDEFS **********************/ @@ -124,7 +133,7 @@ int main(int argc, char **argv) ESP_Brookesia_PhoneStylesheet_t *stylesheet = new ESP_Brookesia_PhoneStylesheet_t EXAMPLE_ESP_BROOKESIA_PHONE_DARK_STYLESHEET(); ESP_BROOKESIA_CHECK_NULL_RETURN(stylesheet, 1, "Create phone stylesheet failed"); - printf("Using stylesheet (%s)", stylesheet->core.name); + ESP_BROOKESIA_LOGI("Using stylesheet (%s)", stylesheet->core.name); ESP_BROOKESIA_CHECK_FALSE_RETURN(phone->addStylesheet(stylesheet), 1, "Add phone stylesheet failed"); ESP_BROOKESIA_CHECK_FALSE_RETURN(phone->activateStylesheet(stylesheet), 1, "Activate phone stylesheet failed"); delete stylesheet; @@ -153,11 +162,19 @@ int main(int argc, char **argv) /* Periodically call the lv_task handler. * It could be done in a timer interrupt or an OS task too.*/ lv_timer_handler(); - usleep(5 * 1000); + usleep(LVGL_TIMER_HANDLER_PERIOD_US); + +#ifdef RUN_TEST + static uint32_t loop_cnt = 0; + if (++loop_cnt >= RUN_TEST_TIMEOUT_S * 1000 * 1000 / LVGL_TIMER_HANDLER_PERIOD_US) { + ESP_BROOKESIA_LOGW("Run test timeout"); + break; + } +#endif } // hal_deinit(); - return 0; + return 1; } /**********************