test_reference.py 2.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import logging
from pathlib import Path
from .test_common import add_sources, TestsBase, dict_merge, \
                         get_common_modelsim_init_files, get_seed
from textwrap import dedent

log = logging.getLogger(__name__)


class ReferenceTests(TestsBase):
    def __init__(self, *args, **kwds):
        super().__init__(*args, **kwds)
        self._tests = self.config['tests'].keys()

    def add_sources(self) -> None:
16 17 18 19
        sources = []
        sources.append('reference/tb_reference.vhd')
        sources.append('reference/vunit_reference_wrapper.vhd')
        add_sources(self.lib, sources)
20

21
    def create_psl_cov_file_opt(self, name):
22 23
        psl_path = "functional_coverage/coverage_data/psl_cov_reference_{}.json".format(name)
        psl_flag = "--psl-report={}".format(psl_path)
24 25
        return {"ghdl.sim_flags" : [psl_flag]}

26
    def configure(self) -> bool:
27
        tb = self.lib.get_test_benches('*reference*')[0]
28 29
        default = self.config['default']

30 31 32 33
        tcl = self.build / 'modelsim_init_reference.tcl'
        with tcl.open('wt', encoding='utf-8') as f:
            print(dedent('''\
                global TCOMP
34
                set TCOMP tb_reference_wrapper/i_test
35 36 37 38 39
                '''), file=f)

        init_files = get_common_modelsim_init_files()
        init_files += [str(tcl)]

40
        for data_set,cfg in self.config['tests'].items():
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
41
            dict_merge(cfg, default)
42 43 44 45 46 47 48
            # bm = len_to_matrix(cfg['topology'], cfg['bus_len_v'])
            generics = {
                'timeout'      : cfg['timeout'],
                'iterations'   : cfg['iterations'],
                'log_level'    : cfg['log_level'] + '_l',
                'error_tol'    : cfg['error_tolerance'],
                'seed'         : get_seed(cfg),
49
                'data_path'    : str(self.build) + '/../' + cfg['data_path'],
50
            }
Ille, Ondrej, Ing.'s avatar
Ille, Ondrej, Ing. committed
51

52 53 54 55
            if (cfg['psl_coverage']):
                psl_opts = self.create_psl_cov_file_opt(data_set)
                tb.add_config(data_set, generics=generics, sim_options=psl_opts)
            else:
56 57
                tb.add_config(data_set, generics=generics)

58 59
        tb.set_sim_option("modelsim.init_files.after_load", init_files)
        self.add_modelsim_gui_file(tb, default, 'reference', init_files)
60
        return True