def main(): ui = VUnit.from_argv() ui.add_osvvm() ui.enable_location_preprocessing() # ui.add_com() ui.disable_ieee_warnings() root = dirname(__file__) for library_name in ('common_lib', 'memory'): ui.add_library(library_name).add_source_files( join(root, library_name, 'src', '*.vhd')) ui.add_library('str_format').add_source_files( join(root, 'hdl_string_format', 'src', '*.vhd')) ui.add_library('memory_tb').add_source_files( join(root, 'memory', 'test', 'async_fifo_tb.vhd')) ui.add_library('exp_golomb').add_source_files( join(root, 'exponential_golomb', 'src', '*.vhd')) # ui.add_library('exp_golomb_tb').add_source_files( # join(root, 'exponential_golomb', 'test', '*.vhd')) add_async_fifo_tests(ui.library('memory_tb').entity('async_fifo_tb')) ui.set_compile_option('modelsim.vcom_flags', ['-novopt', '-explicit']) ui.set_sim_option('modelsim.vsim_flags', ['-novopt']) ui.main()
def run(value): """ Utility function to first run with pkg_body1 then pkg_body2 """ tb_pkg_file_name = join(self.data_path, "tb_pkg.vhd") pkg_file_name = join(self.data_path, "pkg.vhd") pkg_body_file_name = join(self.data_path, "pkg_body%i.vhd" % value) argv = ["--output-path=%s" % self.output_path, "-v"] if value == 1: argv.append("--clean") ui = VUnit.from_argv(argv=argv) lib = ui.add_library("lib") lib.add_source_files(tb_pkg_file_name) lib.add_source_files(pkg_file_name) lib.add_source_files(pkg_body_file_name) lib.entity("tb_pkg").set_generic("value", value) try: ui.main() except SystemExit as ex: self.assertEqual(ex.code, 0)
def run(): ui = VUnit.from_argv() # ui.add_osvvm() src_path = join(dirname(__file__), "vhdl_files") src_lib = ui.add_library("src_lib") src_lib.add_source_files(join(src_path, "src", "*.vhd")) test_lib = ui.add_library("test_lib") test_lib.add_source_files(join(src_path, "test", "*.vhd")) ui.main()
def main(): # VUnit steals the command line args so we use an environment variable # to determine which core we're picking up toplevel = os.getenv("CORE", "") if not toplevel: sys.stderr.write("Need to provide CORE environment variable") sys.exit(1) # Create VUnit instance by parsing command line arguments vu = VUnit.from_argv() #Create singleton instances for core manager and configuration handler #Configuration manager is not needed in this example cm = CoreManager() # Assume we're running in the same directory containing the cores cm.add_cores_root(".") #Get the sorted list of dependencies starting from the top-level core try: cores = cm.get_depends(toplevel) except DependencyError as e: print("'{}' or any of its dependencies requires '{}', but this core was not found".format(top_core, e.value)) sys.exit(2) #Iterate over cores, filesets and files and add all relevant sources files to vunit incdirs = set() src_files = [] #'usage' is a list of tags to look for in the filesets. # Only look at filesets where any of these tags are present usage = ['sim'] for core_name in cores: core = cm.get_core(core_name) core.setup() basepath = core.files_root for fs in core.file_sets: if (set(fs.usage) & set(usage)) and ((core_name == toplevel) or not fs.private): for file in fs.file: if file.is_include_file: #TODO: incdirs not used right now incdirs.add(os.path.join(basepath, os.path.dirname(file.name))) else: try: vu.library(file.logical_name) except KeyError: vu.add_library(file.logical_name) vu.add_source_file(os.path.join(basepath, file.name), file.logical_name) # Run vunit function vu.main()
def main(): ui = VUnit.from_argv() ui.add_osvvm() root_path = dirname(__file__) exp_golomb = ui.add_library("exp_golomb") exp_golomb.add_source_files(join(root_path, "src", "*.vhd")) exp_golomb_tb = ui.add_library("exp_golomb_tb") exp_golomb_tb.add_source_files(join(root_path, "test", "*.vhd")) ui.set_compile_option('modelsim.vcom_flags', ['-novopt', '-explicit']) ui.set_sim_option('modelsim.vsim_flags', ['-novopt']) ui.main()
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. # # Copyright (c) 2014-2018, Lars Asplund [email protected] from os.path import join, dirname from vunit import VUnit root = dirname(__file__) prj = VUnit.from_argv() prj.add_com() tb_com_lib = prj.add_library("tb_com_lib") tb_com_lib.add_source_files(join(root, 'test', '*.vhd')) pkg = tb_com_lib.package('custom_types_pkg') pkg.generate_codecs(codec_package_name='custom_codec_pkg', used_packages=[ 'ieee.std_logic_1164', 'constants_pkg', 'tb_com_lib.more_constants_pkg' ]) prj.main()
mod = imp.find_module("run", [os.path.dirname(run_script)]) run = imp.load_module("run", *mod) run.create_test_suite(prj) mod[0].close() # avoid error "type of a shared variable must be a protected type" prj.set_compile_option("ghdl.a_flags", ["-frelaxed"]) prj.set_sim_option("ghdl.elab_flags", ["-frelaxed"]) # add code coverage if supported if prj.simulator_supports_coverage(): prj.set_sim_option("enable_coverage", True) prj.set_compile_option("enable_coverage", True) def post_run(results): """Collect the coverage results and create a report.""" if PRJ.simulator_supports_coverage(): results.merge_coverage(file_name="coverage_data") subprocess.call([ "lcov", "--capture", "--directory", "coverage_data", "--output-file", "coverage.info" ]) if __name__ == "__main__": os.environ["VUNIT_SIMULATOR"] = "ghdl" PRJ = VUnit.from_argv() create_test_suites(PRJ) PRJ.main(post_run=post_run)
def main(): "Main entry point for DVB FPGA test runner" _generateGnuRadioData() cli = VUnit.from_argv() cli.add_osvvm() cli.add_com() cli.enable_location_preprocessing() library = cli.add_library("lib") library.add_source_files(p.join(ROOT, "rtl", "*.vhd")) library.add_source_files(p.join(ROOT, "rtl", "bch_generated", "*.vhd")) library.add_source_files(p.join(ROOT, "testbench", "*.vhd")) library.add_source_files(p.join(ROOT, "testbench", "*", "*.vhd")) cli.add_library("str_format").add_source_files( p.join(ROOT, "third_party", "hdl_string_format", "src", "*.vhd") ) addAllConfigsTest( entity=cli.library("lib").entity("axi_bch_encoder_tb"), configs=TEST_CONFIGS, input_file_basename="bch_encoder_input.bin", reference_file_basename="ldpc_encoder_input.bin", ) addAllConfigsTest( entity=cli.library("lib").entity("axi_baseband_scrambler_tb"), configs=TEST_CONFIGS, input_file_basename="bb_scrambler_input.bin", reference_file_basename="bch_encoder_input.bin", ) # Uncomment this to test configs individually # # BCH encoding doesn't depend on the constellation type, choose any # for config in _getAllConfigs(constellations=(ConstellationType.MOD_8PSK,)): # cli.library("lib").entity("axi_bch_encoder_tb").add_config( # name=config.name, # generics=dict( # test_cfg=config.getTestConfig( # input_file_path="bch_encoder_input.bin", # reference_file_path="ldpc_encoder_input.bin", # ), # NUMBER_OF_TEST_FRAMES=8, # ), # ) for data_width in (1, 8): all_configs = [] for config in _getAllConfigs(): all_configs += [ config.getTestConfig( input_file_path="bit_interleaver_input.bin", reference_file_path="bit_interleaver_output.bin", ) ] # Uncomment this to test configs individually # cli.library("lib").entity("axi_bit_interleaver_tb").add_config( # name=f"data_width={data_width},{config.name}", # generics=dict( # DATA_WIDTH=data_width, # test_cfg=config.getTestConfig( # input_file_path="bit_interleaver_input.bin", # reference_file_path="bit_interleaver_output.bin", # ), # NUMBER_OF_TEST_FRAMES=8, # ), # ) cli.library("lib").entity("axi_bit_interleaver_tb").add_config( name=f"data_width={data_width},all_parameters", generics=dict( DATA_WIDTH=data_width, test_cfg="|".join(all_configs), NUMBER_OF_TEST_FRAMES=2, ), ) addAxiStreamDelayTests(cli.library("lib").entity("axi_stream_delay_tb")) addAxiFileReaderTests(cli.library("lib").entity("axi_file_reader_tb")) addAxiFileCompareTests(cli.library("lib").entity("axi_file_compare_tb")) cli.set_compile_option("modelsim.vcom_flags", ["-explicit"]) # Not all options are supported by all GHDL backends # cli.set_compile_option("ghdl.flags", ["-frelaxed-rules"]) # cli.set_compile_option("ghdl.flags", ["-frelaxed-rules", "-O0", "-g"]) cli.set_compile_option("ghdl.flags", ["-frelaxed-rules", "-O2", "-g"]) # Make components not bound (error 3473) an error cli.set_sim_option("modelsim.vsim_flags", ["-error", "3473", '-voptargs="+acc=n"']) cli.set_sim_option("disable_ieee_warnings", True) cli.set_sim_option("modelsim.init_file.gui", p.join(ROOT, "wave.do")) cli.main()
""" Copy ---- Copy from a vector with mode extacc to another vector with mode extfnc """ from pathlib import Path from subprocess import check_call from vunit import VUnit from cosim.vhpidirect import VHPIDIRECT SRC = Path(__file__).parent / "src" C_OBJ = SRC / "cp.o" # Compile C application to an object check_call(["gcc", "-fPIC", "-c", str(SRC / "cp.c"), "-o", C_OBJ]) # Enable the external feature for strings VU = VUnit.from_argv(vhdl_standard="2008", compile_builtins=False) VU.add_builtins(VHPIDIRECT().bridge({"string": True})) VU.add_library("lib").add_source_files(SRC / "tb_extcp_*.vhd") # Add the C object to the elaboration of GHDL VU.set_sim_option("ghdl.elab_flags", ["-Wl," + str(C_OBJ)]) VU.main()
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. # # Copyright (c) 2014-2018, Lars Asplund [email protected] from os.path import join, dirname from vunit import VUnit root = dirname(__file__) prj = VUnit.from_argv() prj.add_com() tb_com_lib = prj.add_library("tb_com_lib") tb_com_lib.add_source_files(join(root, 'test', '*.vhd')) pkg = tb_com_lib.package('custom_types_pkg') pkg.generate_codecs(codec_package_name='custom_codec_pkg', used_packages=['ieee.std_logic_1164', 'constants_pkg', 'tb_com_lib.more_constants_pkg']) prj.main()
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. # # Copyright (c) 2014-2019, Lars Asplund [email protected] from os.path import join, dirname, basename from vunit import VUnit from glob import glob root = dirname(__file__) ui = VUnit.from_argv() ui.add_array_util() lib = ui.library("vunit_lib") lib.add_source_files(join(root, "test", "*.vhd")) ui.main()
#!/usr/bin/env python3 # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. # # Copyright (c) 2014-2021, Lars Asplund [email protected] """ VHDL User Guide --------------- The most minimal VUnit VHDL project covering the basics of the :ref:`User Guide <user_guide>`, adapted to be used with simulators that don't support VHDL 2008. """ from pathlib import Path from vunit import VUnit VU = VUnit.from_argv(vhdl_standard="93") VU.add_library("lib").add_source_files(Path(__file__).parent / "*.vhd") VU.main()
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. # # Copyright (c) 2015, Lars Asplund [email protected] """ Example of how you can extract compilation order using VUnit Note that you cannot run VUnit normally via this script """ from os.path import join from vunit import VUnit from project import create_project, ROOT ui = VUnit.from_argv(argv=[]) create_project(ui) source_files = ui.get_project_compile_order(target=join(ROOT, "compile_order_top.vhd")) for source_file in source_files: print(source_file.library.name + ", " + source_file.name)
from os.path import join, dirname, exists from os import makedirs from vunit import VUnit vhdl_standard = ["2002", "2008"] root = dirname(__file__) ui = VUnit.from_argv(vhdl_standard=vhdl_standard[1]) vunit_out = join(root, "vunit_out") libraries = dict.fromkeys([ "lcd", "i2c", "button", "state", "system_bus", "testing", "board", "binary_counter", "address_counter", "timer_counter", "debouncer", "enabler", "toggler", "edge_detector", "inout_controller", "flip_flop" ]) for name, library in libraries.items(): library = ui.add_library(name) library.add_source_files(join(root, name, "*.vhd")) ui.main()
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. # # Copyright (c) 2015-2017, Lars Asplund [email protected] from os.path import join, dirname, basename from vunit import VUnit from vunit.check_preprocessor import CheckPreprocessor from glob import glob vhdl_path = join(dirname(__file__), "test") ui = VUnit.from_argv(compile_builtins=False) ui.add_builtins('vunit_lib', mock_log=True) lib = ui.add_library('lib') lib.add_source_files(join(vhdl_path, "test_support.vhd")) if ui.vhdl_standard in ('2002', '2008'): lib.add_source_files(join(vhdl_path, "test_count.vhd")) lib.add_source_files(join(vhdl_path, "test_types.vhd")) elif ui.vhdl_standard == '93': lib.add_source_files(join(vhdl_path, "test_count93.vhd")) if ui.vhdl_standard == '2008': lib.add_source_files(join(vhdl_path, "tb_check_relation.vhd"), [CheckPreprocessor()]) else: lib.add_source_files(join(vhdl_path, "tb_check_relation93_2002.vhd"), [CheckPreprocessor()]) for file_name in glob(join(vhdl_path, "tb_*.vhd")):
def create(self) -> VUnit: """ Override this function to specify custom instantiation of VUnit. """ return VUnit.from_argv()
from pathlib import Path from vunit import VUnit from GHDLSynth import ICE40, TOOLS_ICE40 VU = VUnit.from_argv(vhdl_standard="2008") #VU.add_verification_components() ROOT = Path(__file__).parent.resolve().parent OUT_DIR = ROOT / "synth_out" SRC_PATH = ROOT / "modules" / "leds" / "src" VU.add_library("lib").add_source_files([SRC_PATH / "*.vhd"]) def sim(): VU.main() def build(): srcs = [ Path(sfile.name).name[0:-4] for sfile in VU.get_source_files(SRC_PATH / "**.vhd") ] srcs.remove('leds') srcs = { sname: [ ifile.name for ifile in VU.get_implementation_subset( VU.get_source_files(SRC_PATH / ("%s.vhd" % sname))) ] for sname in srcs
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. # # Copyright (c) 2015, Lars Asplund [email protected] from os.path import join, dirname, basename from vunit import VUnit from vunit.check_preprocessor import CheckPreprocessor from glob import glob vhdl_path = join(dirname(__file__), "test") ui = VUnit.from_argv(compile_builtins=False) ui.add_builtins('vunit_lib', mock_log=True) lib = ui.add_library('lib') lib.add_source_files(join(vhdl_path, "test_support.vhd")) if ui.vhdl_standard in ('2002', '2008'): lib.add_source_files(join(vhdl_path, "test_count.vhd")) lib.add_source_files(join(vhdl_path, "test_types.vhd")) elif ui.vhdl_standard == '93': lib.add_source_files(join(vhdl_path, "test_count93.vhd")) if ui.vhdl_standard == '2008': lib.add_source_files(join(vhdl_path, "tb_check_relation.vhd"), [CheckPreprocessor()]) else: lib.add_source_files(join(vhdl_path, "tb_check_relation93_2002.vhd"), [CheckPreprocessor()]) for file_name in glob(join(vhdl_path, "tb_*.vhd")): if basename(file_name) == "tb_check_relation.vhd": continue
from pathlib import Path from vunit import VUnit root = Path(__file__).parent project = VUnit.from_argv() project.add_library("Zx7E4").add_source_files( [root / "pkgs" / "*.vhd", root / "src" / "*.vhd", root / "test" / "*.vhd"]) project.main()
# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. # # Copyright (c) 2014-2015, Lars Asplund [email protected] from os.path import join, dirname from vunit import VUnit root = dirname(__file__) ui = VUnit.from_argv() lib = ui.add_library("lib") lib.add_source_files(join(root, "test", "*.vhd")) ui.main()
from os.path import join, dirname from vunit import VUnit import sys import os import subprocess proj = VUnit.from_argv() lib = proj.add_library("lib") lib.add_source_files(join(dirname(__file__), "*.vhdl")) class StreamingIOTest(object): def __init__(self): self._input_gen = None self._output_val = None def pre_config(self, output_path): assert self._input_gen is None assert self._output_val is None input_file_name = join(output_path, "input") output_file_name = join(output_path, "output") os.mkfifo(input_file_name) os.mkfifo(output_file_name) self._input_gen = subprocess.Popen( [join(dirname(__file__), "./gen"), input_file_name]) self._output_gen = subprocess.Popen( [join(dirname(__file__), "./val"), output_file_name])