def test_vcs_no_tool_options(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__, 'no_tool_options') paramtypes = ['plusarg', 'vlogdefine', 'vlogparam'] name = 'test_vcs_0' tool = 'vcs' tool_options = {} (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options, use_vpi=False) backend.configure(args) compare_files(ref_dir, work_root, ['Makefile', name + '.scr']) backend.build() compare_files(ref_dir, work_root, ['vcs.cmd']) backend.run(args) compare_files(ref_dir, work_root, ['run.cmd'])
def test_spyglass_defaults(): """ Test if the SpyGlass backend picks up the tool defaults """ import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__, 'defaults') paramtypes = ['vlogdefine', 'vlogparam'] name = 'test_spyglass_0' tool = 'spyglass' tool_options = {} (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure(args) compare_files(ref_dir, work_root, [ 'Makefile', 'spyglass-run-design_read.tcl', 'spyglass-run-lint_lint_rtl.tcl', name + '.prj', ]) backend.build() compare_files(ref_dir, work_root, [ 'spyglass.cmd', ])
def test_quartus(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['vlogdefine', 'vlogparam'] name = 'test_quartus_0' tool = 'quartus' tool_options = { 'family': 'Cyclone V', 'device': '5CSXFC6D6F31C8ES', 'quartus_options': ['some', 'quartus_options'], } (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure(args) compare_files(ref_dir, work_root, ['Makefile', 'config.mk', name + '.tcl']) backend.build() compare_files(ref_dir, work_root, [ 'ip-generate.cmd', 'quartus_asm.cmd', 'quartus_fit.cmd', 'quartus_sh.cmd', 'quartus_sta.cmd', ])
def test_ghdl(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['generic'] name = 'test_ghdl' tool = 'ghdl' tool_options = {'analyze_options' : ['some', 'analyze_options'], 'run_options' : ['a', 'few', 'run_options']} (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options) for vhdl_file in ['vhdl_file.vhd', 'vhdl_lfile', 'vhdl2008_file']: with open(os.path.join(work_root, vhdl_file), 'a'): os.utime(os.path.join(work_root, vhdl_file), None) backend.configure(args) compare_files(ref_dir, work_root, ['Makefile']) backend.build() compare_files(ref_dir, work_root, ['analyze.cmd']) backend.run(args) compare_files(ref_dir, work_root, ['elab-run.cmd'])
def test_icarus(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['plusarg', 'vlogdefine', 'vlogparam'] name = 'test_icarus_0' tool = 'icarus' tool_options = { 'iverilog_options': ['some', 'iverilog_options'], 'timescale': '1ns/1ns', } (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options, use_vpi=True) backend.configure(args) compare_files(ref_dir, work_root, [ 'Makefile', name + '.scr', 'timescale.v', ]) backend.build() compare_files(ref_dir, work_root, ['iverilog.cmd']) compare_files(ref_dir, work_root, ['iverilog-vpi.cmd']) backend.run(args) compare_files(ref_dir, work_root, ['vvp.cmd'])
def test_ise(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['vlogdefine', 'vlogparam'] name = 'test_ise_0' tool = 'ise' tool_options = { 'family': 'spartan6', 'device': 'xc6slx45', 'package': 'csg324', 'speed': '-2' } (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure(args) compare_files(ref_dir, work_root, [ 'Makefile', 'config.mk', name + '.tcl', name + '_run.tcl', ]) #f = os.path.join(work_root, 'pcf_file.pcf') #with open(f, 'a'): # os.utime(f, None) backend.build() compare_files(ref_dir, work_root, ['xtclsh.cmd'])
def test_xsim(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['plusarg', 'vlogdefine', 'vlogparam'] name = 'test_xsim_0' tool = 'xsim' tool_options = { 'xelab_options': ['some', 'xelab_options'], 'xsim_options': ['a', 'few', 'xsim_options'] } (backend, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure() compare_files(ref_dir, work_root, [ 'config.mk', 'Makefile', name + '.prj', ]) backend.build() compare_files(ref_dir, work_root, ['xelab.cmd']) xsimkdir = os.path.join(work_root, 'xsim.dir', name) os.makedirs(xsimkdir) with open(os.path.join(xsimkdir, 'xsimk'), 'w') as f: f.write("I am a compiled simulation kernel\n") backend.run() compare_files(ref_dir, work_root, ['xsim.cmd'])
def test_vivado(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['vlogdefine', 'vlogparam'] name = 'test_vivado_0' tool = 'vivado' tool_options = { 'part' : 'xc7a35tcsg324-1', } (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure(args) compare_files(ref_dir, work_root, [ 'Makefile', name+'.tcl', name+'_run.tcl', ]) backend.build() compare_files(ref_dir, work_root, [ 'vivado.cmd', ])
def test_diamond(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['generic', 'vlogdefine', 'vlogparam'] tool = 'diamond' name = 'test_{}_0'.format(tool) tool_options = { 'part' : 'LFE5U-85F-6BG381C', } (backend, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure() compare_files(ref_dir, work_root, [ name+'.tcl', name+'_run.tcl', ]) backend.build() compare_files(ref_dir, work_root, [ 'diamondc.cmd', ])
def test_icestorm_nextpnr(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__, 'nextpnr') paramtypes = ['vlogdefine', 'vlogparam'] name = 'test_icestorm_0' tool = 'icestorm' tool_options = { 'yosys_synth_options': ['some', 'yosys_synth_options'], 'arachne_pnr_options': ['a', 'few', 'arachne_pnr_options'], 'nextpnr_options': ['multiple', 'nextpnr_options'], 'pnr': 'next', } (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure(args) compare_files(ref_dir, work_root, ['Makefile', name + '.ys']) f = os.path.join(work_root, 'pcf_file.pcf') with open(f, 'a'): os.utime(f, None) backend.build() compare_files(ref_dir, work_root, ['yosys.cmd']) compare_files(ref_dir, work_root, ['nextpnr-ice40.cmd']) compare_files(ref_dir, work_root, ['icepack.cmd'])
def test_ghdl(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['vlogparam'] name = 'test_ghdl' tool = 'ghdl' tool_options = { 'analyze_options': ['some', 'analyze_options'], 'run_options': ['a', 'few', 'run_options'] } (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure(args) compare_files(ref_dir, work_root, ['Makefile']) backend.build() compare_files(ref_dir, work_root, ['analyze.cmd']) backend.run(args) compare_files(ref_dir, work_root, ['elab-run.cmd'])
def test_vcs_tool_options(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__, 'tool_options') paramtypes = ['plusarg', 'vlogdefine', 'vlogparam'] name = 'test_vcs_tool_options_0' tool = 'vcs' tool_options = { 'vcs_options': ['-debug_access+pp', '-debug_access+all'], 'run_options': ['-licqueue'], } (backend, work_root) = setup_backend(paramtypes, name, tool, tool_options, use_vpi=False) backend.configure() compare_files(ref_dir, work_root, ['Makefile', name + '.scr']) backend.build() compare_files(ref_dir, work_root, ['vcs.cmd']) backend.run() compare_files(ref_dir, work_root, ['run.cmd'])
def test_spyglass_tooloptions(): """ Test passing tool options to the Spyglass backend """ import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__, 'tooloptions') paramtypes = ['vlogdefine', 'vlogparam'] name = 'test_spyglass_0' tool = 'spyglass' tool_options = { 'methodology': 'GuideWare/latest/block/rtl_somethingelse', 'goals': ['lint/lint_rtl', 'some/othergoal'], 'spyglass_options': ['handlememory yes'], 'rule_parameters': ['handle_static_caselabels yes'], } (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure(args) compare_files(ref_dir, work_root, [ 'Makefile', 'spyglass-run-design_read.tcl', 'spyglass-run-lint_lint_rtl.tcl', 'spyglass-run-some_othergoal.tcl', name + '.prj', ]) backend.build() compare_files(ref_dir, work_root, [ 'spyglass.cmd', ])
def test_isim(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['plusarg', 'vlogdefine', 'vlogparam'] name = 'test_isim_0' tool = 'isim' tool_options = { 'fuse_options': ['some', 'fuse_options'], 'isim_options': ['a', 'few', 'isim_options'], } (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure(args) compare_files( ref_dir, work_root, ['config.mk', 'Makefile', 'run_test_isim_0.tcl', 'test_isim_0.prj']) dummy_exe = 'test_isim_0' shutil.copy(os.path.join(ref_dir, dummy_exe), os.path.join(work_root, dummy_exe)) backend.run([]) compare_files(ref_dir, work_root, ['run.cmd'])
def test_verilator_cc(): import os.path import shutil from edalize_common import compare_files, setup_backend, tests_dir mode = 'cc' ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['cmdlinearg', 'plusarg', 'vlogdefine', 'vlogparam'] name = 'test_verilator_0' tool = 'verilator' tool_options = { 'libs' : ['-lelf'], 'mode' : mode, 'verilator_options' : ['-Wno-fatal', '--trace'], 'make_options' : ['OPT_FAST=-O2'], } (backend, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure() compare_files(ref_dir, work_root, ['Makefile']) compare_files(os.path.join(ref_dir, mode), work_root, ['config.mk', name+'.vc']) dummy_exe = 'Vtop_module' shutil.copy(os.path.join(ref_dir, dummy_exe), os.path.join(work_root, dummy_exe)) backend.run() compare_files(ref_dir, work_root, ['run.cmd'])
def test_ascentlint_defaults(): """ Test the default configuration of Ascent Lint """ import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__, 'defaults') paramtypes = ['vlogdefine', 'vlogparam'] name = 'test_ascentlint' tool = 'ascentlint' tool_options = {} (backend, args, work_root) = setup_backend( paramtypes, name, tool, tool_options) backend.configure(args) compare_files(ref_dir, work_root, [ 'Makefile', 'run-ascentlint.tcl', 'sources.f', ]) backend.build() compare_files(ref_dir, work_root, [ 'ascentlint.cmd', ])
def test_quartus(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir paramtypes = ['vlogdefine', 'vlogparam'] name = 'test_quartus_0' tool = 'quartus' tool_options = { 'family': 'Cyclone V', 'device': '5CSXFC6D6F31C8ES', 'quartus_options': ['some', 'quartus_options'], } # Test each edition of Quartus for edition in ["Standard", "Pro"]: # Each edition has its own set of representative files ref_dir = os.path.join(tests_dir, __name__, edition) # Ensure we test the edition we intend to, even if quartus_sh is present os.environ["FUSESOC_QUARTUS_EDITION"] = edition (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options) # Each edition performs checks on the QSYS files present, so provide # a minimal example with open(os.path.join(work_root, "qsys_file"), 'w') as f: f.write(qsys_file.format(qsys_fill[edition])) backend.configure(args) compare_files(ref_dir, work_root, ['Makefile', name + '.tcl']) backend.build() compare_files(ref_dir, work_root, test_sets[edition])
def test_xcelium(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['plusarg', 'vlogdefine', 'vlogparam'] name = 'test_xcelium_0' tool = 'xcelium' tool_options = { 'xmvhdl_options': ['various', 'xmvhdl_options'], 'xmvlog_options': ['some', 'xmvlog_options'], 'xmsim_options': ['a', 'few', 'xmsim_options'], 'xrun_options': ['plenty', 'of', 'xrun_options'], } #FIXME: Add VPI tests (backend, work_root) = setup_backend(paramtypes, name, tool, tool_options, use_vpi=False) backend.configure() compare_files(ref_dir, work_root, [ 'Makefile', 'edalize_build_rtl.f', 'edalize_main.f', ]) orig_env = os.environ.copy() os.environ['PATH'] = '{}:{}'.format( os.path.join(tests_dir, 'mock_commands/xcelium'), os.environ['PATH']) # For some strange reason, writing to os.environ['PATH'] doesn't update the environment. This # leads to test fails, but only when running multiple tests. When running this test by itself, # everything works fine without the 'putenv'. os.putenv('PATH', os.environ['PATH']) backend.build() os.makedirs(os.path.join(work_root, 'work')) backend.run() compare_files(ref_dir, work_root, ['xrun.cmd']) os.environ = orig_env
def test_vunit_codegen(): from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['cmdlinearg'] name = 'test_vunit_0' tool = 'vunit' tool_options = {} (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options, use_vpi=False) backend.configure(args) compare_files(ref_dir, work_root, ['run.py'])
def test_icestorm_invalid_pnr(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['vlogdefine', 'vlogparam'] name = 'test_icestorm_0' tool = 'icestorm' tool_options = { 'pnr' : 'invalid', } (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options) with pytest.raises(RuntimeError) as e: backend.configure(args) assert "nvalid pnr option 'invalid'. Valid values are 'arachne' for Arachne-pnr or 'next' for nextpnr" in str(e.value)
def test_modelsim(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['plusarg', 'vlogdefine', 'vlogparam'] name = 'test_modelsim_0' tool = 'modelsim' tool_options = { 'vcom_options': ['various', 'vcom_options'], 'vlog_options': ['some', 'vlog_options'], 'vsim_options': ['a', 'few', 'vsim_options'], } #FIXME: Add VPI tests (backend, args, work_root) = setup_backend(paramtypes, name, tool, tool_options, use_vpi=False) backend.configure(args) compare_files(ref_dir, work_root, [ 'Makefile', 'edalize_build_rtl.tcl', 'edalize_main.tcl', ]) orig_env = os.environ.copy() os.environ['MODEL_TECH'] = os.path.join(tests_dir, 'mock_commands') backend.build() os.makedirs(os.path.join(work_root, 'work')) compare_files(ref_dir, work_root, ['vsim.cmd']) backend.run(args) with open(os.path.join(ref_dir, 'vsim2.cmd')) as fref, open( os.path.join(work_root, 'vsim.cmd')) as fgen: assert fref.read() == fgen.read() os.environ = orig_env
def test_veriblelint_default(): """ Test the lint mode of Verible """ import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__, 'lint') paramtypes = ['vlogdefine', 'vlogparam'] name = 'test_verible' tool = 'veriblelint' tool_options = {} (backend, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure() backend.build() backend.run() compare_files(ref_dir, work_root, [ 'verilog_lint.cmd', ])
def test_rivierapro(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['plusarg', 'vlogdefine', 'vlogparam'] name = 'test_rivierapro_0' tool = 'rivierapro' tool_options = { 'vlog_options': ['some', 'vlog_options'], 'vsim_options': ['a', 'few', 'vsim_options'], } #FIXME: Add VPI tests (backend, work_root) = setup_backend(paramtypes, name, tool, tool_options, use_vpi=False) backend.configure() compare_files(ref_dir, work_root, [ 'edalize_build_rtl.tcl', 'edalize_launch.tcl', 'edalize_main.tcl', ]) orig_env = copy.deepcopy(os.environ) os.environ['ALDEC_PATH'] = os.path.join(tests_dir, 'mock_commands') backend.build() os.makedirs(os.path.join(work_root, 'work')) compare_files(ref_dir, work_root, ['vsim.cmd']) backend.run() with open(os.path.join(ref_dir, 'vsim2.cmd')) as fref, open( os.path.join(work_root, 'vsim.cmd')) as fgen: assert fref.read() == fgen.read() os.environ = orig_env
def test_ise_missing_options(): import os import shutil from edalize_common import compare_files, setup_backend, tests_dir ref_dir = os.path.join(tests_dir, __name__) paramtypes = ['vlogdefine', 'vlogparam'] name = 'test_ise_0' tool = 'ise' tool_options = { 'family': 'spartan6', 'device': 'xc6slx45', 'package': 'csg324', } (backend, work_root) = setup_backend(paramtypes, name, tool, tool_options) with pytest.raises(RuntimeError) as e: backend.configure() assert "Missing required option 'speed'" in str(e.value)
def test_verilator_lint_only(): import os.path import shutil from edalize_common import compare_files, setup_backend, tests_dir mode = 'lint-only' ref_dir = os.path.join(tests_dir, __name__) paramtypes = [] name = 'test_verilator_0' tool = 'verilator' tool_options = { 'mode' : mode, } (backend, work_root) = setup_backend(paramtypes, name, tool, tool_options) backend.configure() compare_files(ref_dir, work_root, ['Makefile']) compare_files(os.path.join(ref_dir, mode), work_root, ['config.mk', name+'.vc'])