feat(test): automatically generate test image (#4976)
Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
@@ -36,7 +36,7 @@ jobs:
|
||||
- name: Install prerequisites
|
||||
run: scripts/install-prerequisites.sh
|
||||
- name: Run tests
|
||||
run: python tests/main.py --report test
|
||||
run: python tests/main.py --report --update-image test
|
||||
- name: Archive screenshot errors
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v4
|
||||
@@ -95,7 +95,9 @@ jobs:
|
||||
|
||||
install: |
|
||||
apt-get update -y
|
||||
apt-get install build-essential ccache libgcc-10-dev python3 libpng-dev ruby-full gcovr cmake libjpeg62-turbo-dev libfreetype6-dev libasan6 -q -y
|
||||
apt-get install build-essential ccache libgcc-10-dev python3 libpng-dev ruby-full gcovr cmake libjpeg62-turbo-dev libfreetype6-dev libasan6 pngquant python3-pip
|
||||
-q -y
|
||||
pip install pypng lz4
|
||||
/usr/sbin/update-ccache-symlinks
|
||||
echo 'export PATH="/usr/lib/ccache:$PATH"' | tee -a ~/.bashrc
|
||||
|
||||
|
||||
@@ -28,3 +28,4 @@ tests/report/
|
||||
.vscode
|
||||
.idea
|
||||
*.bak
|
||||
tests/test_images/
|
||||
|
||||
@@ -591,6 +591,8 @@ class LVGLImage:
|
||||
header = f'''
|
||||
#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
|
||||
#include "lvgl.h"
|
||||
#elif defined(LV_BUILD_TEST)
|
||||
#include "../lvgl.h"
|
||||
#else
|
||||
#include "lvgl/lvgl.h"
|
||||
#endif
|
||||
|
||||
@@ -6,4 +6,5 @@
|
||||
#
|
||||
# Note: This script is run by the CI workflows.
|
||||
sudo apt update
|
||||
sudo apt install gcc python3 libpng-dev ruby-full gcovr cmake libjpeg-turbo8-dev libfreetype6-dev
|
||||
sudo apt install gcc python3 libpng-dev ruby-full gcovr cmake libjpeg-turbo8-dev libfreetype6-dev pngquant
|
||||
pip3 install pypng lz4
|
||||
|
||||
@@ -18,6 +18,12 @@ scripts/install-prerequisites.sh
|
||||
3. Clean prior test build, build all build-only tests,
|
||||
run executable tests, and generate code coverage
|
||||
report `./tests/main.py --clean --report build test`.
|
||||
4. You can re-generate the test images by adding option `--update-image`.
|
||||
It relies on scripts/LVGLImage.py, which requires pngquant and pypng.
|
||||
You can run below command firstly and follow instructions in logs to install them.
|
||||
`./tests/main.py --update-image test`
|
||||
Note that different version of pngquant may generate different images.
|
||||
As of now the generated image on CI uses pngquant 2.13.1-1.
|
||||
|
||||
For full information on running tests run: `./tests/main.py --help`.
|
||||
|
||||
|
||||
@@ -7,8 +7,13 @@ import subprocess
|
||||
import sys
|
||||
import os
|
||||
from itertools import chain
|
||||
from pathlib import Path
|
||||
|
||||
lvgl_test_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
lvgl_script_path = os.path.join(lvgl_test_dir, "../scripts")
|
||||
sys.path.append(lvgl_script_path)
|
||||
|
||||
from LVGLImage import LVGLImage, ColorFormat, CompressMethod
|
||||
|
||||
# Key values must match variable names in CMakeLists.txt.
|
||||
build_only_options = {
|
||||
@@ -139,6 +144,31 @@ def generate_code_coverage_report():
|
||||
print("Done: See %s" % html_report_file, flush=True)
|
||||
|
||||
|
||||
def generate_test_images():
|
||||
invalids = (ColorFormat.UNKNOWN, ColorFormat.TRUECOLOR, ColorFormat.TRUECOLOR_ALPHA)
|
||||
formats = [i for i in ColorFormat if i not in invalids]
|
||||
png_path = os.path.join(lvgl_test_dir, "test_images/pngs")
|
||||
pngs = list(Path(png_path).rglob("*.[pP][nN][gG]"))
|
||||
print(f"png files: {pngs}")
|
||||
|
||||
align_options = [1, 64]
|
||||
|
||||
for align in align_options:
|
||||
for compress in CompressMethod:
|
||||
compress_name = compress.name if compress != CompressMethod.NONE else "UNCOMPRESSED"
|
||||
outputs = os.path.join(lvgl_test_dir, f"test_images/stride_align{align}/{compress_name}/")
|
||||
os.makedirs(outputs, exist_ok=True)
|
||||
for fmt in formats:
|
||||
for png in pngs:
|
||||
img = LVGLImage().from_png(png, cf=fmt, background=0xffffff)
|
||||
img.adjust_stride(align=16)
|
||||
output = os.path.join(outputs, f"{Path(png).stem}_{fmt.name}.bin")
|
||||
img.to_bin(output, compress=compress)
|
||||
output = os.path.join(outputs, f"{Path(png).stem}_{fmt.name}_{compress.name}_align{align}.c")
|
||||
img.to_c_array(output, compress=compress)
|
||||
print(f"converting {os.path.basename(png)}, format: {fmt.name}, compress: {compress_name}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
epilog = '''This program builds and optionally runs the LVGL test programs.
|
||||
There are two types of LVGL tests: "build", and "test". The build-only
|
||||
@@ -161,9 +191,14 @@ if __name__ == "__main__":
|
||||
help='build: compile build tests, test: compile/run executable tests.')
|
||||
parser.add_argument('--test-suite', default=None,
|
||||
help='select test suite to run')
|
||||
parser.add_argument('--update-image', action='store_true', default=False,
|
||||
help='Update test image using LVGLImage.py script')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.update_image:
|
||||
generate_test_images()
|
||||
|
||||
if args.build_options:
|
||||
options_to_build = args.build_options
|
||||
else:
|
||||
|
||||
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |