Skip to content

Add LVGL emulator for UI regression testing with enhanced build support#109

Merged
zjwhitehead merged 6 commits intomasterfrom
claude/emulator-screenshot-testing-Z9idh
Apr 1, 2026
Merged

Add LVGL emulator for UI regression testing with enhanced build support#109
zjwhitehead merged 6 commits intomasterfrom
claude/emulator-screenshot-testing-Z9idh

Conversation

@zjwhitehead
Copy link
Copy Markdown
Member

@zjwhitehead zjwhitehead commented Apr 1, 2026

This pull request introduces infrastructure for automated screenshot regression testing of the LVGL UI, enabling reliable detection of visual changes and improving test coverage. It adds a new native build environment, CMake project, CI job, and a comprehensive set of stubs to allow the UI code to be tested on a standard Linux host using GoogleTest and LVGL. The most significant changes are grouped below.

Screenshot Regression Testing Infrastructure

  • Adds a new screenshot-tests job to the GitHub Actions workflow, which builds and runs screenshot regression tests, uploading output artifacts on failure for easier debugging. (.github/workflows/config.yml)
  • Introduces a complete CMake-based build system for the screenshot tests, including logic to fetch LVGL and GoogleTest if not already present, and compiles the UI sources together with emulator and stub code. (test/test_screenshots/CMakeLists.txt)
  • Provides a build-and-run shell script (build_and_run.sh) for local and CI environments, supporting fast builds, generator switching, and reference screenshot updates. (test/test_screenshots/build_and_run.sh)
  • Adds a new PlatformIO environment (native-screenshot) for integration with the rest of the project, specifying build flags, source filters, and dependencies for native screenshot tests. (platformio.ini)

Stubs and Compatibility Layer for Native Testing

  • Implements a comprehensive set of stub headers for Arduino, FreeRTOS, SPI, NimBLE, BMS_CAN, and display drivers, allowing the UI code to be compiled and tested natively without embedded hardware dependencies. (test/screenshot_stubs/*) [1] [2] [3] [4] [5] [6] [7] [8] [9]

Configuration Fixes and Maintenance

  • Fixes a typo in the LVGL configuration header, correcting LV_USE_ANIMIMAGE to LV_USE_ANIMIMG for compatibility with LVGL 9.x. (inc/sp140/lvgl/lv_conf.h)
  • Excludes screenshot tests from the default PlatformIO test runs to avoid running them in embedded test environments. (platformio.ini)

claude and others added 6 commits March 31, 2026 16:59
Introduces a native (non-embedded) build that compiles the real LVGL UI
code against a framebuffer-backed display driver, enabling pixel-perfect
screenshot capture of every screen state. Screenshots are saved as BMP
and compared against checked-in references to catch UI regressions.

Key components:
- test/screenshot_stubs/: Hardware stubs (Arduino, FreeRTOS, SPI, etc.)
- test/test_screenshots/: Emulator display driver, test harness, CMake build
- 12 test scenarios: splash (light/dark), idle, armed, cruising, charging,
  low battery, high altitude, high power, ESC disconnected, full battery
- CI job in GitHub Actions runs tests and uploads artifacts on failure
- build_and_run.sh script for local development

Also fixes LV_USE_ANIMIMAGE -> LV_USE_ANIMIMG in lv_conf.h (LVGL v9 rename).

https://claude.ai/code/session_01K42v6du5RXbJ4qz5H1Fsb5
Add a --local option (and EPPG_SCREENSHOT_LOCAL env) to use Ninja, ccache and a portable CPU-count for faster local builds. Introduce argument parsing to separate flags passed to the test binary, detect --update-references robustly, and add build_parallel_jobs() to choose a sensible parallelism across platforms. Configure CMake with generator and ccache launchers when available, warn when ninja/ccache are missing, and clear the build dir when switching generators so Ninja can be used. Also simplify/configure the cmake invocation and ensure arguments are forwarded to the screenshot_tests executable.
build_and_run.sh: clear the build directory when the cached CMake generator or CMAKE_BUILD_TYPE no longer matches the desired values, and choose RelWithDebInfo for local runs (Debug for CI). Introduce BUILD_TYPE and pass it to CMake so generator/build-type mismatches are handled cleanly. emulator_display.cpp: align the LVGL draw buffer to 4 bytes to satisfy LV_DRAW_BUF_ALIGN (avoids LVGL v9 assert) and call lv_timer_handler() repeatedly before lv_refr_now to drain timers/deferred layout work so the first render doesn't block.
Implement emulator_save_diff_bmp to produce a 3-panel side-by-side BMP (reference | output | diff) where differing pixels are shown in magenta and matching pixels are dimmed. Add declaration to the header and update screenshot tests to save diff images on regression and include diff paths in failure messages for easier debugging. Files changed: test/test_screenshots/emulator_display.cpp, .h, and test/test_screenshots/test_screenshots.cpp.
Split many existing screenshot tests into light and dark variants and add corresponding reference bitmaps. Renamed several reference files to *_dark/_light and added new BMP references for charging, alerts, temps, battery, armed states, ESC disconnected, high power/altitude, etc. Refactored test/test_screenshots.cpp: added new test cases for light/dark modes, alert/temperature scenarios, helpers save_and_compare and render_splash, and improved splash rendering to support dark mode. Tests now generate initial references when missing and save diff images on regression. Binary screenshot files were added/renamed under test/test_screenshots/reference/.
@zjwhitehead zjwhitehead marked this pull request as ready for review April 1, 2026 15:30
@zjwhitehead zjwhitehead merged commit 11304d0 into master Apr 1, 2026
10 checks passed
@zjwhitehead zjwhitehead deleted the claude/emulator-screenshot-testing-Z9idh branch April 1, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants