Skip to content

Commit

Permalink
Added test to check that compilation succeeds for all supported chips
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-d committed Jun 30, 2020
1 parent beea4e8 commit 44d7e7d
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 13 deletions.
8 changes: 8 additions & 0 deletions autotests/51-all-target-chips/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>

int main (int argc, char *argv[])
{
char dummy[5];
sprintf(dummy, "1234");
return 0;
}
75 changes: 75 additions & 0 deletions autotests/51-all-target-chips/testdef.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 5 additions & 3 deletions autotests/testrun/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]]
"""
Expand All @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion autotests/testrun/bundle_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion autotests/testrun/project_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
Expand Down
2 changes: 1 addition & 1 deletion autotests/testrun/report_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 11 additions & 7 deletions autotests/testrun/test_loader.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
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

return wrapper


def register_test(**matrix):
def matrix_generator():
def matrix_generator(compilation_env):
keys = []
lists_of_values = []
for key, list_of_values in matrix.items():
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 44d7e7d

Please sign in to comment.