Fix checks in out-of-root builds (#132)

* Fix Python tests
* Fix cppcheck
This commit is contained in:
Alex Kotov 2022-12-05 17:30:26 +04:00 committed by GitHub
parent 042d15f832
commit e369c16e0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 68 deletions

View File

@ -1,6 +1,8 @@
2022-12-05 Alex Kotov <kotovalexarian@gmail.com>
* configure.ac: Fix a bug with building for a freestanding environment
* tests/Makefile.am: Fix Python tests in out-of-root builds
* make/checks.am: Fix cppcheck in out-of-root builds
2022-12-04 Alex Kotov <kotovalexarian@gmail.com>

View File

@ -20,8 +20,8 @@ CPPCHECK_INC = \
-I$(top_srcdir)/include
CPPCHECK_SUPPRESS = \
--suppress='unusedStructMember:examples/multiboot2_header_macro.c' \
--suppress='unusedStructMember:tests/test_multiboot2_info_*.c'
--suppress='unusedStructMember:$(top_srcdir)/examples/multiboot2_header_macro.c' \
--suppress='unusedStructMember:$(top_srcdir)/tests/test_multiboot2_info_*.c'
CPPCHECK_PATHS = \
$(top_builddir)/examples \

View File

@ -103,8 +103,8 @@ endif
CLEANFILES += test_cmdline_gen.c
test_cmdline_gen.c: cmdline_gen.py cmdline_gen.jinja $(top_srcdir)/common/cmdline.yml
$(PYTHON) cmdline_gen.py
test_cmdline_gen.c: $(top_srcdir)/tests/cmdline_gen.py $(top_srcdir)/tests/cmdline_gen.jinja $(top_srcdir)/common/cmdline.yml
$(PYTHON) $+ $@
############
# test_elf #
@ -337,8 +337,8 @@ endif
CLEANFILES += test_printf_fmt_gen.c
test_printf_fmt_gen.c: printf_fmt_gen.py printf_fmt_gen.jinja $(top_srcdir)/common/printf_fmt.yml
$(PYTHON) printf_fmt_gen.py
test_printf_fmt_gen.c: $(top_srcdir)/tests/printf_fmt_gen.py $(top_srcdir)/tests/printf_fmt_gen.jinja $(top_srcdir)/common/printf_fmt.yml
$(PYTHON) $+ $@
###################
# test_printf_gen #
@ -360,8 +360,8 @@ endif
CLEANFILES += test_printf_gen.c
test_printf_gen.c: printf_gen.py printf_gen.jinja $(top_srcdir)/common/printf.yml $(top_srcdir)/common/printf_orig.yml
$(PYTHON) printf_gen.py
test_printf_gen.c: $(top_srcdir)/tests/printf_gen.py $(top_srcdir)/tests/printf_gen.jinja $(top_srcdir)/common/printf.yml $(top_srcdir)/common/printf_orig.yml
$(PYTHON) $+ $@
####################
# test_units_human #

View File

@ -1,27 +1,16 @@
from jinja2 import Environment, FileSystemLoader
from os import path
from yaml import SafeLoader, safe_load
from sys import argv
from yaml import safe_load
CASES_FILENAME = 'cmdline.yml'
TEMPLATE_FILENAME = 'cmdline_gen.jinja'
TEST_FILENAME = 'test_cmdline_gen.c'
ROOT_DIRPATH = path.dirname(path.dirname(path.join(path.abspath(__file__))))
COMMON_DIRPATH = path.join(ROOT_DIRPATH, 'common')
TESTS_DIRPATH = path.join(ROOT_DIRPATH, 'tests')
CASES_FILEPATH = path.join(COMMON_DIRPATH, CASES_FILENAME)
TEST_FILEPATH = path.join(TESTS_DIRPATH, TEST_FILENAME)
def main():
cases = safe_load(open(CASES_FILEPATH))
def main(test_filepath, template_filepath, cases_filepath):
cases = safe_load(open(cases_filepath))
jinja_env = Environment(
keep_trailing_newline=True,
loader=FileSystemLoader(TESTS_DIRPATH),
loader=FileSystemLoader(path.dirname(template_filepath)),
)
jinja_template = jinja_env.get_template(TEMPLATE_FILENAME)
jinja_template = jinja_env.get_template(path.basename(template_filepath))
result = jinja_template.render(
cases=cases,
@ -30,7 +19,7 @@ def main():
len=len,
)
with open(TEST_FILEPATH, 'w') as f:
with open(test_filepath, 'w') as f:
f.write(result)
def escape_int(n):
@ -40,4 +29,21 @@ def escape_str(s):
return '"' + s + '"'
if __name__ == '__main__':
main()
print(argv)
template_filepath = argv[1]
cases_filepath = argv[2]
test_filepath = argv[3]
print('test_filepath: %s' % test_filepath)
print('template_filepath: %s' % template_filepath)
print('cases_filepath: %s' % cases_filepath)
if path.exists(test_filepath) and not path.isfile(test_filepath):
raise RuntimeError('invalid test file path')
if not path.isfile(template_filepath):
raise RuntimeError('invalid template file path')
if not path.isfile(cases_filepath):
raise RuntimeError('invalid cases file path')
main(test_filepath, template_filepath, cases_filepath)

View File

@ -1,27 +1,16 @@
from jinja2 import Environment, FileSystemLoader
from os import path
from yaml import SafeLoader, safe_load
from sys import argv
from yaml import safe_load
CASES_FILENAME = 'printf_fmt.yml'
TEMPLATE_FILENAME = 'printf_fmt_gen.jinja'
TEST_FILENAME = 'test_printf_fmt_gen.c'
ROOT_DIRPATH = path.dirname(path.dirname(path.join(path.abspath(__file__))))
COMMON_DIRPATH = path.join(ROOT_DIRPATH, 'common')
TESTS_DIRPATH = path.join(ROOT_DIRPATH, 'tests')
CASES_FILEPATH = path.join(COMMON_DIRPATH, CASES_FILENAME)
TEST_FILEPATH = path.join(TESTS_DIRPATH, TEST_FILENAME)
def main():
cases = safe_load(open(CASES_FILEPATH))
def main(test_filepath, template_filepath, cases_filepath):
cases = safe_load(open(cases_filepath))
jinja_env = Environment(
keep_trailing_newline=True,
loader=FileSystemLoader(TESTS_DIRPATH),
loader=FileSystemLoader(path.dirname(template_filepath)),
)
jinja_template = jinja_env.get_template(TEMPLATE_FILENAME)
jinja_template = jinja_env.get_template(path.basename(template_filepath))
result = jinja_template.render(
cases=cases,
@ -31,7 +20,7 @@ def main():
none_to_zero=none_to_zero,
)
with open(TEST_FILEPATH, 'w') as f:
with open(test_filepath, 'w') as f:
f.write(result)
def escape_flag(flag):
@ -56,4 +45,21 @@ def none_to_zero(num):
return str(num)
if __name__ == '__main__':
main()
print(argv)
template_filepath = argv[1]
cases_filepath = argv[2]
test_filepath = argv[3]
print('test_filepath: %s' % test_filepath)
print('template_filepath: %s' % template_filepath)
print('cases_filepath: %s' % cases_filepath)
if path.exists(test_filepath) and not path.isfile(test_filepath):
raise RuntimeError('invalid test file path')
if not path.isfile(template_filepath):
raise RuntimeError('invalid template file path')
if not path.isfile(cases_filepath):
raise RuntimeError('invalid cases file path')
main(test_filepath, template_filepath, cases_filepath)

View File

@ -1,32 +1,19 @@
from jinja2 import Environment, FileSystemLoader
from os import path
from yaml import SafeLoader, safe_load
from sys import argv
from yaml import safe_load
CASES_ORIG_FILENAME = 'printf_orig.yml'
CASES_REG_FILENAME = 'printf.yml'
TEMPLATE_FILENAME = 'printf_gen.jinja'
TEST_FILENAME = 'test_printf_gen.c'
ROOT_DIRPATH = path.dirname(path.dirname(path.join(path.abspath(__file__))))
COMMON_DIRPATH = path.join(ROOT_DIRPATH, 'common')
TESTS_DIRPATH = path.join(ROOT_DIRPATH, 'tests')
CASES_ORIG_FILEPATH = path.join(COMMON_DIRPATH, CASES_ORIG_FILENAME)
CASES_REG_FILEPATH = path.join(COMMON_DIRPATH, CASES_REG_FILENAME)
TEST_FILEPATH = path.join(TESTS_DIRPATH, TEST_FILENAME)
def main():
cases_orig = safe_load(open(CASES_ORIG_FILEPATH))
cases_reg = safe_load(open(CASES_REG_FILEPATH))
def main(test_filepath, template_filepath, cases_reg_filepath, cases_orig_filepath):
cases_reg = safe_load(open(cases_reg_filepath))
cases_orig = safe_load(open(cases_orig_filepath))
cases = cases_reg + cases_orig
jinja_env = Environment(
keep_trailing_newline=True,
loader=FileSystemLoader(TESTS_DIRPATH),
loader=FileSystemLoader(path.dirname(template_filepath)),
)
jinja_template = jinja_env.get_template(TEMPLATE_FILENAME)
jinja_template = jinja_env.get_template(path.basename(template_filepath))
result = jinja_template.render(
cases=cases,
@ -35,7 +22,7 @@ def main():
values=values,
)
with open(TEST_FILEPATH, 'w') as f:
with open(test_filepath, 'w') as f:
f.write(result)
def escape_char(c):
@ -77,4 +64,25 @@ def values(args):
return values
if __name__ == '__main__':
main()
print(argv)
template_filepath = argv[1]
cases_reg_filepath = argv[2]
cases_orig_filepath = argv[3]
test_filepath = argv[4]
print('test_filepath: %s' % test_filepath)
print('template_filepath: %s' % template_filepath)
print('cases_reg_filepath: %s' % cases_reg_filepath)
print('cases_orig_filepath: %s' % cases_orig_filepath)
if path.exists(test_filepath) and not path.isfile(test_filepath):
raise RuntimeError('invalid test file path')
if not path.isfile(template_filepath):
raise RuntimeError('invalid template file path')
if not path.isfile(cases_reg_filepath):
raise RuntimeError('invalid regular cases file path')
if not path.isfile(cases_orig_filepath):
raise RuntimeError('invalid original cases file path')
main(test_filepath, template_filepath, cases_reg_filepath, cases_orig_filepath)