Esempio n. 1
0
def test_capi2_get_parameters():
    from fusesoc.core import Core

    core_file = os.path.join(tests_dir, "capi2_cores", "misc",
                             "parameters.core")
    core = Core(core_file)

    param1 = {}
    param2 = {
        'datatype': 'str',
        'default': 'default_value',
        'description': 'This is a parameter',
        'paramtype': 'vlogparam',
    }
    flags = {'is_toplevel': True}
    expected = {'param1': param1}

    assert expected == core.get_parameters(flags)

    flags['target'] = 'noparameters'
    expected = {}
    assert expected == core.get_parameters(flags)

    flags['target'] = 'nonexistant'
    with pytest.raises(SyntaxError) as excinfo:
        core.get_parameters(flags)
    assert "Parameter 'idontexist', requested by target 'nonexistant', was not found" in str(
        excinfo.value)

    flags['target'] = 'multiparameters'
    expected = {'param1': param1, 'param2': param2}
    assert expected == core.get_parameters(flags)

    flags['target'] = 'use_flags'
    expected = {'param2': param2}
    assert expected == core.get_parameters(flags)

    flags['tool'] = 'icarus'
    expected = {'param1': param1}
    assert expected == core.get_parameters(flags)
Esempio n. 2
0
def test_capi2_get_parameters():
    from fusesoc.core import Core
    from fusesoc.capi2.core import Generators

    core_file = os.path.join(tests_dir,
                             "capi2_cores",
                             "misc",
                             "parameters.core")
    core = Core(core_file)

    param1 = {
        'datatype'  : 'str',
        'paramtype' : 'vlogparam',
    }
    param2 = {
        'datatype'    : 'str',
        'default'     : 'default_value',
        'description' : 'This is a parameter',
        'paramtype'   : 'vlogparam',
        }
    intparam = {
        'datatype'  : 'int',
        'default'   : 5446,
        'paramtype' : 'vlogparam',
    }
    boolfalse = {
        'datatype'  : 'bool',
        'default'   : False,
        'paramtype' : 'vlogparam',
    }

    booltrue = {
        'datatype'  : 'bool',
        'default'   : True,
        'paramtype' : 'vlogparam',
    }
    int0 = {
        'datatype'  : 'int',
        'default'   : 0,
        'paramtype' : 'vlogparam',
    }
    emptystr = {
        'datatype'  : 'str',
        'paramtype' : 'vlogparam',
    }

    flags    = {'is_toplevel' : True}
    expected = {'param1' : param1}

    assert expected == core.get_parameters(flags)

    flags['target'] = 'noparameters'
    expected = {}
    assert expected == core.get_parameters(flags)

    flags['target'] = 'nonexistant'
    with pytest.raises(SyntaxError) as excinfo:
        core.get_parameters(flags)
    assert "Parameter 'idontexist', requested by target 'nonexistant', was not found" in str(excinfo.value)

    flags['target'] = 'multiparameters'
    expected = {'param1' : param1, 'param2' : param2}
    assert expected == core.get_parameters(flags)

    flags['target'] = 'use_flags'
    expected = {'param2' : param2,
                'condparamtype' : {'datatype'  : 'str',
                                   'paramtype' : 'vlogparam'}
    }

    assert expected == core.get_parameters(flags)

    flags['tool'] = 'icarus'
    expected = {'param1' : param1,
                'condparamtype' : {'datatype'  : 'str',
                                   'paramtype' : 'plusarg'}
    }
    assert expected == core.get_parameters(flags)

    flags['target'] = 'types'
    expected = {'param2'    : param2,
                'intparam'  : intparam,
                'boolfalse' : boolfalse,
                'booltrue'  : booltrue,
    }
    result = core.get_parameters(flags)
    assert expected == result
    assert str == type(result['param2']['datatype'])
    assert str == type(result['param2']['default'])
    assert str == type(result['param2']['description'])
    assert str == type(result['param2']['paramtype'])
    assert int == type(result['intparam']['default'])
    assert bool == type(result['boolfalse']['default'])
    assert bool == type(result['booltrue']['default'])

    flags['target'] = 'empty'
    expected = {'int0' : int0,
                'emptystr' : emptystr}

    assert expected == core.get_parameters(flags)

    flags['target'] = 'override'
    param1['default'] = 'def'
    param2['default'] = 'new_def'
    intparam['default'] = 0xdeadbeef
    boolfalse['default'] = True
    booltrue['default'] = False
    expected = {'param1'    : param1,
                'param2'    : param2,
                'intparam'  : intparam,
                'boolfalse' : boolfalse,
                'booltrue'  : booltrue,
    }
    assert expected == core.get_parameters(flags)
Esempio n. 3
0
def test_capi2_get_parameters():
    from fusesoc.capi2.core import Generators
    from fusesoc.core import Core

    core_file = os.path.join(tests_dir, "capi2_cores", "misc",
                             "parameters.core")
    core = Core(core_file)

    param1 = {
        "datatype": "str",
        "paramtype": "vlogparam",
    }
    param2 = {
        "datatype": "str",
        "default": "default_value",
        "description": "This is a parameter",
        "paramtype": "vlogparam",
    }
    intparam = {
        "datatype": "int",
        "default": 5446,
        "paramtype": "vlogparam",
    }
    boolfalse = {
        "datatype": "bool",
        "default": False,
        "paramtype": "vlogparam",
    }

    booltrue = {
        "datatype": "bool",
        "default": True,
        "paramtype": "vlogparam",
    }
    int0 = {
        "datatype": "int",
        "default": 0,
        "paramtype": "vlogparam",
    }
    emptystr = {
        "datatype": "str",
        "paramtype": "vlogparam",
    }
    realpi = {
        "datatype": "real",
        "default": 3.14159,
        "paramtype": "vlogparam",
    }

    flags = {"is_toplevel": True}
    expected = {"param1": param1}

    assert expected == core.get_parameters(flags)

    flags["target"] = "noparameters"
    expected = {}
    assert expected == core.get_parameters(flags)

    flags["target"] = "nonexistant"
    with pytest.raises(SyntaxError) as excinfo:
        core.get_parameters(flags)
    assert (
        "Parameter 'idontexist', requested by target 'nonexistant', was not found"
        in str(excinfo.value))

    flags["target"] = "multiparameters"
    expected = {"param1": param1, "param2": param2}
    assert expected == core.get_parameters(flags)

    flags["target"] = "use_flags"
    expected = {
        "param2": param2,
        "condparamtype": {
            "datatype": "str",
            "paramtype": "vlogparam"
        },
    }

    assert expected == core.get_parameters(flags)

    flags["tool"] = "icarus"
    expected = {
        "param1": param1,
        "condparamtype": {
            "datatype": "str",
            "paramtype": "plusarg"
        },
    }
    assert expected == core.get_parameters(flags)

    flags["target"] = "types"
    expected = {
        "param2": param2,
        "intparam": intparam,
        "boolfalse": boolfalse,
        "booltrue": booltrue,
        "realpi": realpi,
    }
    result = core.get_parameters(flags)
    assert expected == result
    assert str == type(result["param2"]["datatype"])
    assert str == type(result["param2"]["default"])
    assert str == type(result["param2"]["description"])
    assert str == type(result["param2"]["paramtype"])
    assert int == type(result["intparam"]["default"])
    assert bool == type(result["boolfalse"]["default"])
    assert bool == type(result["booltrue"]["default"])
    assert float == type(result["realpi"]["default"])

    flags["target"] = "empty"
    expected = {"int0": int0, "emptystr": emptystr}

    assert expected == core.get_parameters(flags)

    flags["target"] = "override"
    param1["default"] = "def"
    param2["default"] = "new_def"
    intparam["default"] = 0xDEADBEEF
    boolfalse["default"] = True
    booltrue["default"] = False
    realpi["default"] = 3.14
    expected = {
        "param1": param1,
        "param2": param2,
        "intparam": intparam,
        "boolfalse": boolfalse,
        "booltrue": booltrue,
        "realpi": realpi,
    }
    assert expected == core.get_parameters(flags)
Esempio n. 4
0
def test_capi2_get_parameters():
    from fusesoc.core import Core
    from fusesoc.capi2.core import Generators

    core_file = os.path.join(tests_dir,
                             "capi2_cores",
                             "misc",
                             "parameters.core")
    core = Core(core_file)

    param1 = {
        'datatype'  : 'str',
        'paramtype' : 'vlogparam',
    }
    param2 = {
        'datatype'    : 'str',
        'default'     : 'default_value',
        'description' : 'This is a parameter',
        'paramtype'   : 'vlogparam',
        }
    intparam = {
        'datatype'  : 'int',
        'default'   : 5446,
        'paramtype' : 'vlogparam',
    }
    boolfalse = {
        'datatype'  : 'bool',
        'default'   : False,
        'paramtype' : 'vlogparam',
    }

    booltrue = {
        'datatype'  : 'bool',
        'default'   : True,
        'paramtype' : 'vlogparam',
    }
    int0 = {
        'datatype'  : 'int',
        'default'   : 0,
        'paramtype' : 'vlogparam',
    }
    emptystr = {
        'datatype'  : 'str',
        'paramtype' : 'vlogparam',
    }

    flags    = {'is_toplevel' : True}
    expected = {'param1' : param1}

    assert expected == core.get_parameters(flags)

    flags['target'] = 'noparameters'
    expected = {}
    assert expected == core.get_parameters(flags)

    flags['target'] = 'nonexistant'
    with pytest.raises(SyntaxError) as excinfo:
        core.get_parameters(flags)
    assert "Parameter 'idontexist', requested by target 'nonexistant', was not found" in str(excinfo.value)

    flags['target'] = 'multiparameters'
    expected = {'param1' : param1, 'param2' : param2}
    assert expected == core.get_parameters(flags)

    flags['target'] = 'use_flags'
    expected = {'param2' : param2,
                'condparamtype' : {'datatype'  : 'str',
                                   'paramtype' : 'vlogparam'}
    }

    assert expected == core.get_parameters(flags)

    flags['tool'] = 'icarus'
    expected = {'param1' : param1,
                'condparamtype' : {'datatype'  : 'str',
                                   'paramtype' : 'plusarg'}
    }
    assert expected == core.get_parameters(flags)

    flags['target'] = 'types'
    expected = {'param2'    : param2,
                'intparam'  : intparam,
                'boolfalse' : boolfalse,
                'booltrue'  : booltrue,
    }
    result = core.get_parameters(flags)
    assert expected == result
    assert str == type(result['param2']['datatype'])
    assert str == type(result['param2']['default'])
    assert str == type(result['param2']['description'])
    assert str == type(result['param2']['paramtype'])
    assert int == type(result['intparam']['default'])
    assert bool == type(result['boolfalse']['default'])
    assert bool == type(result['booltrue']['default'])

    flags['target'] = 'empty'
    expected = {'int0' : int0,
                'emptystr' : emptystr}

    assert expected == core.get_parameters(flags)

    flags['target'] = 'override'
    param1['default'] = 'def'
    param2['default'] = 'new_def'
    intparam['default'] = 0xdeadbeef
    boolfalse['default'] = True
    booltrue['default'] = False
    expected = {'param1'    : param1,
                'param2'    : param2,
                'intparam'  : intparam,
                'boolfalse' : boolfalse,
                'booltrue'  : booltrue,
    }
    assert expected == core.get_parameters(flags)