Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_empty_edam():
import tempfile
from edalize import get_edatool
(h, edam_file) = tempfile.mkstemp()
with pytest.raises(TypeError):
backend = get_edatool('icarus')(edam=None)
def setup_backend_minimal(name, tool, files):
os.environ['PATH'] = os.path.join(tests_dir, 'mock_commands')+':'+os.environ['PATH']
work_root = tempfile.mkdtemp(prefix=tool+'_')
eda_api = {'name' : name,
'files' : files,
'toplevel' : 'top_module',
}
return (get_edatool(tool)(eda_api=eda_api,
work_root=work_root), work_root)
def test_edam_files():
from edalize import get_edatool
files = [{'name' : 'plain_file'},
{'name' : 'subdir/plain_include_file',
'is_include_file' : True},
{'name' : 'file_with_args',
'file_type' : 'verilogSource',
'logical_name' : 'libx'},
{'name' : 'include_file_with_args',
'is_include_file' : True,
'file_type' : 'verilogSource',
'logical_name' : 'libx'}]
edam = {'files' : files,
'name' : 'test_edam_files'}
backend = get_edatool('icarus')(edam=edam)
(parsed_files, incdirs) = backend._get_fileset_files()
assert len(parsed_files) == 2
assert parsed_files[0].name == 'plain_file'
assert parsed_files[0].file_type == ''
assert parsed_files[0].logical_name == ''
assert parsed_files[1].name == 'file_with_args'
assert parsed_files[1].file_type == 'verilogSource'
assert parsed_files[1].logical_name == 'libx'
assert incdirs == ['subdir', '.']
def test_verilator_run():
import os.path
import tempfile
import yaml
from edalize import get_edatool
ref_dir_cc = os.path.join(ref_dir, 'cc')
work_root = tempfile.mkdtemp()
eda_api_file = os.path.join(ref_dir_cc, core_name)+ '.eda.yml'
backend = get_edatool(tool)(eda_api=yaml.load(open(eda_api_file)), work_root=work_root)
dummy_exe = 'V'+backend.tool_options['top_module']
shutil.copy(os.path.join(ref_dir, dummy_exe),
os.path.join(work_root, dummy_exe))
backend.run(params)
compare_files(ref_dir, work_root, ['run.cmd'])
import tempfile
from edalize import get_edatool
from edalize_common import compare_files, tests_dir
ref_dir = os.path.join(tests_dir, __name__, 'minimal')
os.environ['PATH'] = os.path.join(tests_dir, 'mock_commands')+':'+os.environ['PATH']
tool = 'icarus'
name = 'test_'+tool+'_minimal_0'
work_root = tempfile.mkdtemp(prefix=tool+'_')
eda_api = {'name' : name,
'toplevel' : 'top'}
backend = get_edatool(tool)(eda_api=eda_api, work_root=work_root)
backend.configure([])
compare_files(ref_dir, work_root, ['Makefile',
name+'.scr',
])
backend.build()
compare_files(ref_dir, work_root, ['iverilog.cmd'])
backend.run([])
compare_files(ref_dir, work_root, ['vvp.cmd'])
import tempfile
from edalize import get_edatool
tests_dir = os.path.dirname(__file__)
ref_dir = os.path.join(tests_dir, __name__)
script = 'exit_1_script'
hooks = {'pre_build' : [
{'cmd' : ['sh', os.path.join(ref_dir, script)],
'name' : script}]}
work_root = tempfile.mkdtemp(prefix='eda_api_hooks_')
eda_api = {'hooks' : hooks,
'name' : script}
backend = get_edatool('icarus')(eda_api=eda_api,
work_root=work_root)
with pytest.raises(RuntimeError):
backend.build()
ref_dir = os.path.join(tests_dir, __name__, 'minimal')
tool = 'vunit'
name = 'test_' + tool + '_minimal_0'
work_root = str(tmpdir)
files = [{'name' : os.path.join(ref_dir, 'vunit_runner_test.py'),
'file_type' : 'pythonSource-3.7'},
{'name' : os.path.join(ref_dir, 'tb_minimal.vhd'),
'file_type' : 'vhdlSource-2008',
'logical_name' : 'libx'}]
edam = {'name' : name,
'files' : files,
'toplevel' : 'top'}
backend = get_edatool(tool)(edam=edam, work_root=work_root)
original_impl = subprocess.check_call
def subprocess_intercept(args, **kwargs):
if len(args) > 1 and args[1].endswith('run.py'):
import sys
with patch.object(sys, 'argv', args):
spec = importlib.util.spec_from_file_location("__main__", args[1])
runner_script = importlib.util.module_from_spec(spec)
spec.loader.exec_module(runner_script)
else:
original_impl(args, **kwargs)
with mock.patch('subprocess.check_call', new=subprocess_intercept):
backend.configure()
import os
from edalize import get_edatool
from edalize_common import compare_files, tests_dir
ref_dir = os.path.join(tests_dir, __name__, 'minimal')
os.environ['PATH'] = os.path.join(tests_dir, 'mock_commands')+':'+os.environ['PATH']
tool = 'icarus'
name = 'test_'+tool+'_minimal_0'
work_root = str(tmpdir)
edam = {'name' : name,
'toplevel' : 'top'}
backend = get_edatool(tool)(edam=edam, work_root=work_root)
backend.configure()
compare_files(ref_dir, work_root, ['Makefile',
name+'.scr',
])
backend.build()
compare_files(ref_dir, work_root, ['iverilog.cmd'])
backend.run()
compare_files(ref_dir, work_root, ['vvp.cmd'])
logger.error(e.msg)
exit(1)
except RuntimeError as e:
logger.error("Setup failed : {}".format(str(e)))
exit(1)
edalizer.to_yaml(eda_api_file)
#Frontend/backend separation
try:
if do_configure:
edam = edalizer.edalize
else:
import yaml
edam = yaml.safe_load(open(eda_api_file))
backend = get_edatool(tool)(edam=edam,
work_root=work_root)
except ImportError:
logger.error('Backend "{}" not found'.format(tool))
exit(1)
except RuntimeError as e:
logger.error(str(e))
exit(1)
except FileNotFoundError as e:
logger.error('Could not find EDA API file "{}"'.format(e.filename))
exit(1)
if do_configure:
try:
backend.configure(backendargs)
print('')