def test_get_scripts(): flag_combos = [{'target' : 'sim' , 'is_toplevel' : False}, {'target' : 'sim' , 'is_toplevel' : True}, {'target' : 'synth', 'is_toplevel' : False}, {'target' : 'synth', 'is_toplevel' : True}, ] filename = os.path.join(os.path.dirname(__file__), 'cores', 'misc', 'scriptscore.core') core = Core(filename) for flags in flag_combos: env = { 'FILES_ROOT' : 'dummyroot' } result = core.get_scripts("dummyroot", flags) expected = {} if flags['target'] == 'sim': sections = ['post_run', 'pre_build', 'pre_run'] else: if flags['is_toplevel']: env['SYSTEM_ROOT'] = core.files_root sections = ['pre_build', 'post_build'] else: sections = [] for section in sections: _name = flags['target']+section+'_scripts{}' expected[section] = [{'cmd' : ['sh', os.path.join('dummyroot', _name.format(i))], 'name' : _name.format(i), 'env' : env} for i in range(2)] assert expected == result
def test_get_scripts(): flag_combos = [ { "target": "sim", "is_toplevel": False }, { "target": "sim", "is_toplevel": True }, { "target": "synth", "is_toplevel": False }, { "target": "synth", "is_toplevel": True }, ] filename = os.path.join(os.path.dirname(__file__), "cores", "misc", "scriptscore.core") core = Core(filename) for flags in flag_combos: env = {"FILES_ROOT": "dummyroot"} result = core.get_scripts("dummyroot", flags) expected = {} if flags["target"] == "sim": sections = ["post_run", "pre_build", "pre_run"] else: if flags["is_toplevel"]: env["SYSTEM_ROOT"] = core.files_root sections = ["pre_build", "post_build"] else: sections = [] for section in sections: _name = flags["target"] + section + "_scripts{}" expected[section] = [{ "cmd": ["sh", os.path.join("dummyroot", _name.format(i))], "name": _name.format(i), "env": env, } for i in range(2)] assert expected == result
def test_get_scripts(): flag_combos = [ { 'target': 'sim', 'is_toplevel': False }, { 'target': 'sim', 'is_toplevel': True }, { 'target': 'synth', 'is_toplevel': False }, { 'target': 'synth', 'is_toplevel': True }, ] filename = os.path.join(os.path.dirname(__file__), 'cores', 'misc', 'scriptscore.core') core = Core(filename) for flags in flag_combos: env = {'FILES_ROOT': 'dummyroot'} result = core.get_scripts("dummyroot", flags) expected = {} if flags['target'] == 'sim': sections = ['post_run', 'pre_build', 'pre_run'] else: if flags['is_toplevel']: env['SYSTEM_ROOT'] = core.files_root sections = ['pre_build', 'post_build'] else: sections = [] for section in sections: _name = flags['target'] + section + '_scripts{}' expected[section] = [{ 'cmd': ['sh', os.path.join('dummyroot', _name.format(i))], 'name': _name.format(i), 'env': env } for i in range(2)] assert expected == result
def test_capi2_get_scripts(): from fusesoc.core import Core simple1 = {'cmd' : ['simple_cmd1'], 'env' : {'FILES_ROOT' : 'my_files_root'}, 'name' : 'simple1'} simple2 = {'cmd' : ['simple_cmd2'], 'env' : {'FILES_ROOT' : 'my_files_root'}, 'name' : 'simple2'} simple3 = {'cmd' : ['simple_cmd3'], 'env' : {'FILES_ROOT' : 'my_files_root'}, 'name' : 'simple3'} simple4 = {'cmd' : ['simple_cmd4'], 'env' : {'FILES_ROOT' : 'my_files_root'}, 'name' : 'simple4'} with_env = {'cmd' : ['simple5'], 'env' : {'FILES_ROOT' : 'my_files_root', 'TESTENV' : 'testvalue'}, 'name' : 'with_env'} multi_cmd = {'cmd' : ['command', 'with', 'args'], 'env' : {'FILES_ROOT' : 'my_files_root'}, 'name' : 'multi_cmd'} core_file = os.path.join(tests_dir, "capi2_cores", "misc", "hooks.core") core = Core(core_file) flags = {'is_toplevel' : True} expected = {'pre_build' : [simple1]} assert expected == core.get_scripts("my_files_root", flags) flags['target'] = 'nohooks' expected = {} assert expected == core.get_scripts("my_files_root", flags) flags['target'] = 'nonexistant' with pytest.raises(SyntaxError) as excinfo: core.get_scripts("", flags) assert "Script 'idontexist', requested by target 'nonexistant', was not found" in str(excinfo.value) flags['target'] = 'allhooks' expected = { 'pre_build' : [simple1], 'post_build' : [simple2], 'pre_run' : [simple3], 'post_run' : [simple4], } assert expected == core.get_scripts("my_files_root", flags) flags['target'] = 'multihooks' expected = { 'pre_run' : [simple1, with_env, multi_cmd] } assert expected == core.get_scripts("my_files_root", flags) flags['target'] = 'use_flags' expected = {'post_run' : [simple2]} assert expected == core.get_scripts("my_files_root", flags) flags['tool'] = 'icarus' expected = {'post_run' : [simple1]} assert expected == core.get_scripts("my_files_root", flags)
def test_capi2_get_scripts(): from fusesoc.core import Core simple1 = { "cmd": ["simple_cmd1"], "env": { "FILES_ROOT": "my_files_root" }, "name": "simple1", } simple2 = { "cmd": ["simple_cmd2"], "env": { "FILES_ROOT": "my_files_root" }, "name": "simple2", } simple3 = { "cmd": ["simple_cmd3"], "env": { "FILES_ROOT": "my_files_root" }, "name": "simple3", } simple4 = { "cmd": ["simple_cmd4"], "env": { "FILES_ROOT": "my_files_root" }, "name": "simple4", } with_env = { "cmd": ["simple5"], "env": { "FILES_ROOT": "my_files_root", "TESTENV": "testvalue" }, "name": "with_env", } multi_cmd = { "cmd": ["command", "with", "args"], "env": { "FILES_ROOT": "my_files_root" }, "name": "multi_cmd", } core_file = os.path.join(tests_dir, "capi2_cores", "misc", "hooks.core") core = Core(core_file) flags = {"is_toplevel": True} expected = {"pre_build": [simple1]} assert expected == core.get_scripts("my_files_root", flags) flags["target"] = "nohooks" expected = {} assert expected == core.get_scripts("my_files_root", flags) flags["target"] = "nonexistant" with pytest.raises(SyntaxError) as excinfo: core.get_scripts("", flags) assert ( "Script 'idontexist', requested by target 'nonexistant', was not found" in str(excinfo.value)) flags["target"] = "allhooks" expected = { "pre_build": [simple1], "post_build": [simple2], "pre_run": [simple3], "post_run": [simple4], } assert expected == core.get_scripts("my_files_root", flags) flags["target"] = "multihooks" expected = {"pre_run": [simple1, with_env, multi_cmd]} assert expected == core.get_scripts("my_files_root", flags) flags["target"] = "use_flags" expected = {"post_run": [simple2]} assert expected == core.get_scripts("my_files_root", flags) flags["tool"] = "icarus" expected = {"post_run": [simple1]} assert expected == core.get_scripts("my_files_root", flags)