def simulator_is(*names): """ Check that current simulator is any of names """ supported_names = [sim.name for sim in SIMULATOR_FACTORY.supported_simulators()] for name in names: assert name in supported_names return SIMULATOR_FACTORY.select_simulator().name in names
def get_compile_option(self, name): """ Return a copy of the compile option list """ SIMULATOR_FACTORY.check_compile_option_name(name) if name not in self._compile_options: self._compile_options[name] = [] return copy(self._compile_options[name])
def add_compile_option(self, name, value): """ Add compile option """ SIMULATOR_FACTORY.check_compile_option(name, value) if name not in self._compile_options: self._compile_options[name] = copy(value) else: self._compile_options[name] += value
def compile_standard_libraries(vunit_obj, output_path): """ Compile Xilinx standard libraries using Vivado TCL command """ done_token = join(output_path, "all_done.txt") simulator_class = SIMULATOR_FACTORY.select_simulator() if not exists(done_token): print("Compiling standard libraries into %s ..." % abspath(output_path)) simname = simulator_class.name # Vivado calls rivierapro for riviera if simname == "rivierapro": simname = "riviera" run_vivado(join(dirname(__file__), "tcl", "compile_standard_libs.tcl"), tcl_args=[simname, simulator_class.find_prefix().replace("\\", "/"), output_path]) else: print("Standard libraries already exists in %s, skipping" % abspath(output_path)) for library_name in ["unisim", "unimacro", "unifast", "secureip", "xpm"]: path = join(output_path, library_name) if exists(path): vunit_obj.add_external_library(library_name, path) with open(done_token, "w") as fptr: fptr.write("done")
def compile_standard_libraries(vunit_obj, output_path): """ Compile Xilinx standard libraries using Vivado TCL command """ done_token = join(output_path, "all_done.txt") simulator_class = SIMULATOR_FACTORY.select_simulator() if not exists(done_token): print("Compiling standard libraries into %s ..." % abspath(output_path)) simname = simulator_class.name # Vivado calls rivierapro for riviera if simname == "rivierapro": simname = "riviera" run_vivado(join(dirname(__file__), "tcl", "compile_standard_libs.tcl"), tcl_args=[ simname, simulator_class.find_prefix().replace("\\", "/"), output_path ]) else: print("Standard libraries already exists in %s, skipping" % abspath(output_path)) for library_name in ["unisim", "unimacro", "unifast", "secureip", "xpm"]: path = join(output_path, library_name) if exists(path): vunit_obj.add_external_library(library_name, path) with open(done_token, "w") as fptr: fptr.write("done")
def simulator_check(func): """ Check some method of the selected simulator """ simif = SIMULATOR_FACTORY.select_simulator() if simif is None: return False return func(simif)
def _create_argument_parser(description=None, for_documentation=False): """ Create the argument parser :param description: A custom short description of the command line tool :param for_documentation: When used for user guide documentation :returns: The created :mod:`argparse` parser object """ if description is None: description = "VUnit command line tool version %s" % version() if for_documentation: default_output_path = "./vunit_out" else: default_output_path = join(abspath(os.getcwd()), "vunit_out") parser = argparse.ArgumentParser(description=description) parser.add_argument("test_patterns", metavar="tests", nargs="*", default="*", help="Tests to run") parser.add_argument( "--with-attributes", default=None, action="append", help="Only select tests with these attributes set", ) parser.add_argument( "--without-attributes", default=None, action="append", help="Only select tests without these attributes set", ) parser.add_argument( "-l", "--list", action="store_true", default=False, help="Only list all test cases", ) parser.add_argument( "-f", "--files", action="store_true", default=False, help="Only list all files in compile order", ) parser.add_argument( "--compile", action="store_true", default=False, help="Only compile project without running tests", ) parser.add_argument( "-m", "--minimal", action="store_true", default=False, help="Only compile files required for the (filtered) test benches", ) parser.add_argument( "-k", "--keep-compiling", action="store_true", default=False, help= "Continue compiling even after errors only skipping files that depend on failed files", ) parser.add_argument( "--fail-fast", action="store_true", default=False, help="Stop immediately on first failing test", ) parser.add_argument( "--elaborate", action="store_true", default=False, help="Only elaborate test benches without running", ) parser.add_argument("--clean", action="store_true", default=False, help="Remove output path first") parser.add_argument( "-o", "--output-path", default=default_output_path, help="Output path for compilation and simulation artifacts", ) parser.add_argument("-x", "--xunit-xml", default=None, help="Xunit test report .xml file") parser.add_argument( "--xunit-xml-format", choices=["jenkins", "bamboo"], default="jenkins", help= ("Only valid with --xunit-xml argument. " "Defines where in the XML file the simulator output is stored on a failure. " '"jenkins" = Output stored in <system-out>, ' '"bamboo" = Output stored in <failure>.'), ) parser.add_argument( "--exit-0", default=False, action="store_true", help= ("Exit with code 0 even if a test failed. " "Still exits with code 1 on fatal errors such as compilation failure" ), ) parser.add_argument( "--dont-catch-exceptions", default=False, action="store_true", help=("Let exceptions bubble up all the way. " 'Useful when running with "python -m pdb".'), ) parser.add_argument( "-v", "--verbose", action="store_true", default=False, help="Print test output immediately and not only when failure", ) parser.add_argument( "-q", "--quiet", action="store_true", default=False, help="Do not print test output even in the case of failure", ) parser.add_argument("--no-color", action="store_true", default=False, help="Do not color output") parser.add_argument( "--log-level", default="warning", choices=["info", "error", "warning", "debug"], help=("Log level of VUnit internal python logging. " "Used for debugging"), ) parser.add_argument( "-p", "--num-threads", type=positive_int, default=1, help=( "Number of tests to run in parallel. " "Test output is not continuously written in verbose mode with p > 1" ), ) parser.add_argument( "-u", "--unique-sim", action="store_true", default=False, help= "Do not re-use the same simulator process for running different test cases (slower)", ) parser.add_argument("--export-json", default=None, help="Export project information to a JSON file.") parser.add_argument("--version", action="version", version=version()) SIMULATOR_FACTORY.add_arguments(parser) return parser
def set_sim_option(self, name, value): """ Set sim option """ SIMULATOR_FACTORY.check_sim_option(name, value) self.sim_options[name] = copy(value)
def _create_argument_parser(description=None, for_documentation=False): """ Create the argument parser :param description: A custom short description of the command line tool :param for_documentation: When used for user guide documentation :returns: The created :mod:`argparse` parser object """ if description is None: description = 'VUnit command line tool version %s' % version() if for_documentation: default_output_path = "./vunit_out" else: default_output_path = join(abspath(os.getcwd()), "vunit_out") parser = argparse.ArgumentParser(description=description) parser.add_argument('test_patterns', metavar='tests', nargs='*', default='*', help='Tests to run') parser.add_argument('-l', '--list', action='store_true', default=False, help='Only list all test cases') parser.add_argument('-f', '--files', action='store_true', default=False, help='Only list all files in compile order') parser.add_argument('--compile', action='store_true', default=False, help='Only compile project without running tests') parser.add_argument( '-k', '--keep-compiling', action='store_true', default=False, help= 'Continue compiling even after errors only skipping files that depend on failed files' ) parser.add_argument('--fail-fast', action='store_true', default=False, help='Stop immediately on first failing test') parser.add_argument('--elaborate', action='store_true', default=False, help='Only elaborate test benches without running') parser.add_argument('--clean', action='store_true', default=False, help='Remove output path first') parser.add_argument( '-o', '--output-path', default=default_output_path, help='Output path for compilation and simulation artifacts') parser.add_argument('-x', '--xunit-xml', default=None, help='Xunit test report .xml file') parser.add_argument( '--exit-0', default=False, action="store_true", help= ('Exit with code 0 even if a test failed. ' 'Still exits with code 1 on fatal errors such as compilation failure' )) parser.add_argument('--dont-catch-exceptions', default=False, action="store_true", help=('Let exceptions bubble up all the way. ' 'Useful when running with "python -m pdb".')) parser.add_argument( '-v', '--verbose', action="store_true", default=False, help='Print test output immediately and not only when failure') parser.add_argument( '-q', '--quiet', action="store_true", default=False, help='Do not print test output even in the case of failure') parser.add_argument('--no-color', action='store_true', default=False, help='Do not color output') parser.add_argument('--log-level', default="warning", choices=["info", "error", "warning", "debug"], help=("Log level of VUnit internal python logging. " "Used for debugging")) parser.add_argument( '-p', '--num-threads', type=positive_int, default=1, help=( 'Number of tests to run in parallel. ' 'Test output is not continuously written in verbose mode with p > 1' )) parser.add_argument( "-u", "--unique-sim", action="store_true", default=False, help= "Do not re-use the same simulator process for running different test cases (slower)" ) parser.add_argument( "--coverage", default=None, nargs="?", help="Enable code coverage. Works with ModelSim and RivieraPRO.") parser.add_argument('--version', action='version', version=version()) SIMULATOR_FACTORY.add_arguments(parser) return parser
def _create_argument_parser(description=None, for_documentation=False): """ Create the argument parser :param description: A custom short description of the command line tool :param for_documentation: When used for user guide documentation :returns: The created :mod:`argparse` parser object """ if description is None: description = 'VUnit command line tool version %s' % version() if for_documentation: default_output_path = "./vunit_out" else: default_output_path = join(abspath(os.getcwd()), "vunit_out") parser = argparse.ArgumentParser(description=description) parser.add_argument('test_patterns', metavar='tests', nargs='*', default='*', help='Tests to run') parser.add_argument("--with-attributes", default=None, action="append", help="Only select tests with these attributes set") parser.add_argument("--without-attributes", default=None, action="append", help="Only select tests without these attributes set") parser.add_argument('-l', '--list', action='store_true', default=False, help='Only list all test cases') parser.add_argument('-f', '--files', action='store_true', default=False, help='Only list all files in compile order') parser.add_argument('--compile', action='store_true', default=False, help='Only compile project without running tests') parser.add_argument('-k', '--keep-compiling', action='store_true', default=False, help='Continue compiling even after errors only skipping files that depend on failed files') parser.add_argument('--fail-fast', action='store_true', default=False, help='Stop immediately on first failing test') parser.add_argument('--elaborate', action='store_true', default=False, help='Only elaborate test benches without running') parser.add_argument('--clean', action='store_true', default=False, help='Remove output path first') parser.add_argument('-o', '--output-path', default=default_output_path, help='Output path for compilation and simulation artifacts') parser.add_argument('-x', '--xunit-xml', default=None, help='Xunit test report .xml file') parser.add_argument('--xunit-xml-format', choices=['jenkins', 'bamboo'], default='jenkins', help=('Only valid with --xunit-xml argument. ' 'Defines where in the XML file the simulator output is stored on a failure. ' '"jenkins" = Output stored in <system-out>, ' '"bamboo" = Output stored in <failure>.')) parser.add_argument('--exit-0', default=False, action="store_true", help=('Exit with code 0 even if a test failed. ' 'Still exits with code 1 on fatal errors such as compilation failure')) parser.add_argument('--dont-catch-exceptions', default=False, action="store_true", help=('Let exceptions bubble up all the way. ' 'Useful when running with "python -m pdb".')) parser.add_argument('-v', '--verbose', action="store_true", default=False, help='Print test output immediately and not only when failure') parser.add_argument('-q', '--quiet', action="store_true", default=False, help='Do not print test output even in the case of failure') parser.add_argument('--no-color', action='store_true', default=False, help='Do not color output') parser.add_argument('--log-level', default="warning", choices=["info", "error", "warning", "debug"], help=("Log level of VUnit internal python logging. " "Used for debugging")) parser.add_argument('-p', '--num-threads', type=positive_int, default=1, help=('Number of tests to run in parallel. ' 'Test output is not continuously written in verbose mode with p > 1')) parser.add_argument("-u", "--unique-sim", action="store_true", default=False, help="Do not re-use the same simulator process for running different test cases (slower)") parser.add_argument("--export-json", default=None, help="Export project information to a JSON file.") parser.add_argument('--version', action='version', version=version()) SIMULATOR_FACTORY.add_arguments(parser) return parser
from os.path import join, dirname from vunit import VUnit, VUnitCLI from vunit.simulator_factory import SIMULATOR_FACTORY from run_support import run_with_compile_errors root = dirname(__file__) vhdl_standard = ("2019" if SIMULATOR_FACTORY.select_simulator().name == "rivierapro" else "2008") args = VUnitCLI().parse_args() # keep_going is a planned VUnit feature which adds support for dealing with testbenches # that don't compile if "keep_going" in args: args.keep_going = True ui = VUnit.from_args(args, vhdl_standard=vhdl_standard) vhdl_2008 = ui.add_library("vhdl_2008") vhdl_2019 = ui.add_library("vhdl_2019") vhdl_2008.add_source_files(join(root, "vhdl_2008", "*.vhd")) vhdl_2019.add_source_files(join(root, "vhdl_2019", "*.vhd")) if "keep_going" in args: ui.main() else: # Workaround while keep_going isn't supported run_with_compile_errors(ui, args, vhdl_standard)
def set_compile_option(self, name, value): """ Set compile option """ SIMULATOR_FACTORY.check_compile_option(name, value) self._compile_options[name] = copy(value)
# -*- coding: utf-8 -*- import subprocess from vunit import VUnit from vunit.ghdl_interface import GHDLInterface from vunit.simulator_factory import SIMULATOR_FACTORY ############################################################################## # Check simulator. print("=============================================") simulator_class = SIMULATOR_FACTORY.select_simulator() simname = simulator_class.name print(simname) if (simname == "modelsim"): f = open("modelsim.do", "w+") f.write("add wave * \nlog -r /*\nvcd file\nvcd add -r /*\n") f.close() print("=============================================") # Check GHDL backend. code_coverage = False try: if (GHDLInterface.determine_backend("") == "gcc" or GHDLInterface.determine_backend("") == "GCC"): code_coverage = True else: code_coverage = False except: print("")