Files
lvgl/tests/build.py
Chris Mumford 53986b4b0e test Refactor unit test scripts. (#2473)
* Refactor unit test scripts.

Does the following:

1. Remove as many dependencies on the operating system shell as possible.
   For example, use of shutil.rmtree(...) instead of os.system('rm -r ...').
   This brings this script a bit closer to being able to run on Windows.
2. Switch from os.system() to subprocess.check_call().
   * This is a bit more secure as check_call() directly invokes the subprocess
     without evaluation the arguments on a command-line.
   * Removes the need to evaluate the return code as check_call() does this.
   * Can directly set environment variables (e.g. env=cmd_env) instead of
     including with subprocess invocation (e.g. BIN=test.bin).
3. Minor cleanup to main.py sys.argv parsing.
4. PEP8 formatting.

* Ignore FileNotFoundError for rmtree('report').

* Back to os.system for gcovr.

* Removed unused shutil import.
2021-08-25 15:37:59 +02:00

106 lines
3.0 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import re
import subprocess
test_dir = os.path.dirname(os.path.realpath(__file__))
lvgl_dir = os.path.abspath(os.path.join(test_dir, os.pardir))
lvgl_dir_name = 'lvgl' # LVGL subdirectory (base name) in lvgl_dir.
lvgl_parent_dir = os.path.abspath(os.path.join(lvgl_dir, os.pardir))
lv_conf_path = os.path.join(lvgl_dir, 'tests/src/lv_test_conf.h')
base_defines = ['-DLV_CONF_PATH="%s"' % lv_conf_path, '-DLV_BUILD_TEST']
def maybe_quote(obj):
if type(obj) == str:
return '"%s"' % obj
return obj
def zip_defines(defines):
return ['-D%s=%s' % (key, maybe_quote(defines[key])) for key in defines]
def build(defines):
global base_defines
optimization = ['-O3', '-g0']
d_all = base_defines + zip_defines(defines)
cmd_env = os.environ.copy()
cmd_env['BIN'] = 'test.bin'
cmd_env['MAINSRC'] = 'src/lv_test_main.c'
cmd_env['LVGL_DIR'] = lvgl_parent_dir
cmd_env['LVGL_DIR_NAME'] = lvgl_dir_name
cmd_env['DEFINES'] = ' '.join(d_all)
cmd_env['OPTIMIZATION'] = ' '.join(optimization)
print("")
print("Build")
print("-----------------------", flush=True)
# -s makes it silence
subprocess.check_call(['make', '-s', '--jobs=%d' % os.cpu_count()], env=cmd_env)
print("")
print("Run")
print("-----------------------", flush=True)
subprocess.check_call("./test.bin")
def build_test(defines, test_name):
global base_defines
optimization = ['-g0']
print("")
print("")
print("~~~~~~~~~~~~~~~~~~~~~~~~")
print(re.search("/[a-z_]*$", test_name).group(0)[1:])
print("~~~~~~~~~~~~~~~~~~~~~~~~", flush=True)
d_all = base_defines + zip_defines(defines)
test_file_name = test_name + ".c"
test_file_runner_name = test_name + "_Runner.c"
test_file_runner_name = test_file_runner_name.replace(
"/test_cases/", "/test_runners/")
cmd_env = os.environ.copy()
cmd_env['BIN'] = 'test.bin'
cmd_env['MAINSRC'] = test_file_name
cmd_env['TEST_SRC'] = test_file_runner_name
cmd_env['LVGL_DIR'] = lvgl_parent_dir
cmd_env['LVGL_DIR_NAME'] = lvgl_dir_name
cmd_env['DEFINES'] = ' '.join(d_all)
cmd_env['OPTIMIZATION'] = ' '.join(optimization)
extra_csrcs = [
'unity/unity.c', 'unity/unity_support.c',
'src/test_fonts/font_1.c', 'src/test_fonts/font_2.c',
'src/test_fonts/font_3.c'
]
cmd_env['EXTRA_CSRCS'] = ' '.join(extra_csrcs)
print("")
print("Build")
print("-----------------------", flush=True)
# -s makes it silence
subprocess.check_call(['make', '-s', '--jobs=%d' % os.cpu_count()], env=cmd_env)
print("")
print("Run")
print("-----------------------")
subprocess.check_call('./test.bin')
def clean():
print("")
print("Clean")
print("-----------------------", flush=True)
cmd_env = os.environ.copy()
cmd_env['LVGL_DIR'] = lvgl_parent_dir
cmd_env['LVGL_DIR_NAME'] = lvgl_dir_name
subprocess.check_call(['make', 'clean'], env=cmd_env)
try:
os.remove('test.bin')
except FileNotFoundError:
pass