From 44d7e7d20d912aac7e8e3451a88dd56e33df9fe9 Mon Sep 17 00:00:00 2001 From: Fabio D'Urso Date: Tue, 30 Jun 2020 02:40:55 +0200 Subject: [PATCH] Added test to check that compilation succeeds for all supported chips --- autotests/51-all-target-chips/main.cpp | 8 +++ autotests/51-all-target-chips/testdef.py | 75 ++++++++++++++++++++++++ autotests/testrun/__main__.py | 8 ++- autotests/testrun/bundle_io.py | 2 +- autotests/testrun/project_builder.py | 2 +- autotests/testrun/report_writer.py | 2 +- autotests/testrun/test_loader.py | 18 +++--- 7 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 autotests/51-all-target-chips/main.cpp create mode 100644 autotests/51-all-target-chips/testdef.py diff --git a/autotests/51-all-target-chips/main.cpp b/autotests/51-all-target-chips/main.cpp new file mode 100644 index 0000000..e2d936d --- /dev/null +++ b/autotests/51-all-target-chips/main.cpp @@ -0,0 +1,8 @@ +#include + +int main (int argc, char *argv[]) +{ + char dummy[5]; + sprintf(dummy, "1234"); + return 0; +} diff --git a/autotests/51-all-target-chips/testdef.py b/autotests/51-all-target-chips/testdef.py new file mode 100644 index 0000000..9ffe123 --- /dev/null +++ b/autotests/51-all-target-chips/testdef.py @@ -0,0 +1,75 @@ +import os +import re +from testrun import * + +THIS_DIR = os.path.abspath(os.path.dirname(__file__)) +GLD_RE = re.compile('p(.*)\\.gld') + +SKIPLIST = { + (1, 10): [ + # CPU not recognized + '24EP64GP203' + ], + (1, 20): [ + # CPU not recognized + '24FJ64GB502' + ], + (1, 21): [ + # CPU not recognized + '24FJ64GB502' + ], + (1, 22): [ + # CPU not recognized + '33EP32GS202', + + # Undefined symbol `__reset' + '33EP16GS502', + '33EP16GS504', + '33EP16GS506', + '33EP32GS502', + '33EP32GS504', + '33EP32GS506', + ] +} + + +def _matrix_generator_family(target_family, family_dir): + for gld_file in os.listdir(os.path.join(family_dir, 'gld')): + m = GLD_RE.fullmatch(gld_file) + chip = m.group(1) + + yield { + 'target_family': target_family, + 'target_chip': chip, + 'omf': 'elf' + } + + yield { + 'target_family': target_family, + 'target_chip': chip, + 'omf': 'coff' + } + + +def _matrix_generator(compilation_env): + support_dir = os.path.join(compilation_env.compiler_abspath, 'support') + for target_family in os.listdir(support_dir): + if target_family.startswith('PIC') or target_family.startswith('dsPIC'): + family_dir = os.path.join(support_dir, target_family) + yield from _matrix_generator_family(target_family, family_dir) + + +@register_test_with_matrix_generator(_matrix_generator) +class MyTest(CompileOnlyTest): + test_dir = THIS_DIR + + def __init__(self, target_family, target_chip, omf): + self.target = (target_family, target_chip) + super().__init__(omf) + + def compile(self, compilation_env): + ver_major, ver_minor = compilation_env.compiler_version + if self.target[1] in SKIPLIST.get((ver_major, ver_minor), []): + return CompilationOutput(Outcome.SKIPPED, dict()) + + return super().compile(compilation_env) diff --git a/autotests/testrun/__main__.py b/autotests/testrun/__main__.py index 02405c8..c645590 100644 --- a/autotests/testrun/__main__.py +++ b/autotests/testrun/__main__.py @@ -17,7 +17,7 @@ from .test_loader import TestLoader, error_if_unexpected_working_directory -def load_test_directories(test_directories): +def load_test_directories(test_directories, compilation_env): """ Load test definitions from a list of directories. @@ -26,6 +26,8 @@ def load_test_directories(test_directories): subdirectory of the root of the test hierarchy (i.e. the 'autotests' directory). :type test_directories: List[str] + :param compilation_env: The compilation environment for the loaded tests. + :type compilation_env: CompilationEnvironment :return: (test_instance, test_package_name) tuples :rtype: Generator[Tuple[Test, str]] """ @@ -37,7 +39,7 @@ def load_test_directories(test_directories): seen_package_names = set() for test_directory in test_directories: # Load tests from current test_directory - test_loader = TestLoader(test_directory) + test_loader = TestLoader(test_directory, compilation_env) if test_loader.package_name in seen_package_names: print('Warning!', test_loader.package_name, @@ -76,7 +78,7 @@ def do_compile(args): # bundle with BundleWriter(args.output) as bw: for test_instance, test_package_name \ - in load_test_directories(args.test_directory): + in load_test_directories(args.test_directory, compilation_env): print('Compiling test', test_instance, 'defined in', test_package_name, file=sys.stderr) diff --git a/autotests/testrun/bundle_io.py b/autotests/testrun/bundle_io.py index 9641678..f6d1579 100644 --- a/autotests/testrun/bundle_io.py +++ b/autotests/testrun/bundle_io.py @@ -67,7 +67,7 @@ def add_record(self, bundle_record): # Create a human-readable unique folder name self.counter += 1 test_repr_encoded = urllib.parse.quote(repr(test_instance), - safe="=()[]{}'") + safe="=()[]{}' ,") base_folder = '%08d,%s,%s' \ % (self.counter, test_package_name, test_repr_encoded) diff --git a/autotests/testrun/project_builder.py b/autotests/testrun/project_builder.py index e4d81fb..2a4c5b2 100644 --- a/autotests/testrun/project_builder.py +++ b/autotests/testrun/project_builder.py @@ -43,7 +43,7 @@ def __init__(self, compiler_abspath, compiler_version, omf, target): '-p' + target_chip, '--report-mem', '--script', ldscript, - '--heap=512', + '--heap=128', '-L' + os.path.join(compiler_abspath, 'lib'), '-L' + os.path.join(compiler_abspath, 'lib', target_family) ] diff --git a/autotests/testrun/report_writer.py b/autotests/testrun/report_writer.py index 45c2f7f..b163faf 100644 --- a/autotests/testrun/report_writer.py +++ b/autotests/testrun/report_writer.py @@ -64,7 +64,7 @@ def write_test_outcome(self, test_instance, test_package_name, # generated by BundleWriter) self._current_test_counter += 1 test_repr_encoded = urllib.parse.quote(repr(test_instance), - safe="=()[]{}'") + safe="=()[]{}' ,") test_extended_name = \ '%08d,%s,%s' % \ (self._current_test_counter, test_package_name, test_repr_encoded) diff --git a/autotests/testrun/test_loader.py b/autotests/testrun/test_loader.py index 0daf85c..2c68e6d 100644 --- a/autotests/testrun/test_loader.py +++ b/autotests/testrun/test_loader.py @@ -1,17 +1,19 @@ +import functools import importlib import itertools import os from .call_in_subprocess import call_and_capture_output -# helper variable used during the loading phase by TestLoader +# helper variables used during the loading phase by TestLoader LOADED_TESTS = None +COMPILATION_ENV = None def register_test_with_matrix_generator(gen_func): def wrapper(cls): if LOADED_TESTS is not None: # do not run it while unpickling - for assignment in gen_func(): + for assignment in gen_func(COMPILATION_ENV): LOADED_TESTS.append(cls(**assignment)) return cls @@ -19,7 +21,7 @@ def wrapper(cls): def register_test(**matrix): - def matrix_generator(): + def matrix_generator(compilation_env): keys = [] lists_of_values = [] for key, list_of_values in matrix.items(): @@ -42,7 +44,7 @@ def error_if_unexpected_working_directory(): class TestLoader: - def __init__(self, test_directory): + def __init__(self, test_directory, compilation_env): self.test_directory = test_directory # Transform test_directory into a package name (sibling of this package) @@ -53,18 +55,20 @@ def __init__(self, test_directory): self.package_name = test_directory_rel.replace(os.pathsep, '.') - load_test_output = call_and_capture_output(self._load_tests) + load_test_output = call_and_capture_output( + functools.partial(self._load_tests, compilation_env)) if load_test_output.exception is None: self.loaded_tests = load_test_output.result else: raise RuntimeError('Failed to load tests from test directory %s' % test_directory) from load_test_output.exception - def _load_tests(self): - global LOADED_TESTS + def _load_tests(self, compilation_env): + global LOADED_TESTS, COMPILATION_ENV # Import the target module LOADED_TESTS = [] + COMPILATION_ENV = compilation_env importlib.import_module('%s.testdef' % self.package_name) # Since every TestLoader instance imports its test module is a dedicated