Beispiel #1
0
def run_file(path):
    print(f'Running example {path}')
    example = os.path.splitext(os.path.basename(path))[0]
    cfg_fn = os.path.splitext(path)[0] + '_cfg.py'

    clear()
    runpy.run_path(path)

    if os.path.exists(cfg_fn):
        runpy.run_path(cfg_fn)
    else:
        gear = get_example_gear(example).basename

        for inp in find(f'/{gear}').in_ports:
            reg['debug/trace'].append(inp.name)

        for outp in find(f'/{gear}').out_ports:
            reg['debug/trace'].append(outp.name)

    # reg['results-dir'] = '/tools/home/tmp'
    reg['wavejson/trace_fn'] = os.path.join(examples_dir, f'{example}.json')
    reg['sim/extens'].append(WaveJSON)
    # reg['trace/level'] = 0

    sim()
Beispiel #2
0
def call(f, *args, **kwds):
    clear()
    kwd_intfs, kwd_params = extract_arg_kwds(kwds, f)
    args_comb = combine_arg_kwds(args, kwd_intfs, f)

    paramspec = inspect.getfullargspec(f.func)
    args, annotations = resolve_args(args_comb, paramspec.args,
                                     paramspec.annotations, paramspec.varargs)

    dtypes = [infer_dtype(args[arg], annotations[arg]) for arg in args]

    seqs = [drv(t=t, seq=[v]) for t, v in zip(dtypes, args_comb)]

    outputs = f(*seqs, **kwd_params)

    if isinstance(outputs, tuple):
        res = [[] for _ in outputs]

        for o, r in zip(outputs, res):
            collect(o | mon, result=r)
    else:
        res = [[]]
        collect(outputs | mon, result=res[0])

    sim(check_activity=False)

    if isinstance(outputs, tuple):
        return res
    else:
        return res[0]
Beispiel #3
0
def test_conf_getter():
    clear()

    def get_b(var):
        return var.path

    reg.confdef('a/b', getter=get_b)

    assert reg['a/b'] == 'a/b'
Beispiel #4
0
def test_subreg():
    clear()

    reg.subreg('a')

    a = reg['a']

    a['b'] = 1
    a['c/d'] = 2

    assert reg['a/b'] == 1
    assert reg['a/c/d'] == 2
Beispiel #5
0
def test_basic():
    clear()

    reg['a/b'] = 1

    reg['a/c'] = 3
    reg['a/b'] = 2

    reg['d'] = 4

    assert reg['a/b'] == 2
    assert reg['a/c'] == 3
    assert reg['d'] == 4
Beispiel #6
0
def test_conf_setter():
    clear()

    values = []

    def set_b(var, val):
        if val is None:
            return

        values.append(val)

    reg.confdef('a/b', setter=set_b)

    reg['a/b'] = 1
    reg['a/b'] = 2

    assert values == [1, 2]
Beispiel #7
0
def resdir(tmp_path_factory, pytestconfig):
    if not pytestconfig.getoption('--pg'):
        return None

    from pygears import clear, reg
    from pygears.conf.custom_settings import load_rc
    clear()
    load_rc('.pygears', pytestconfig.rootdir)

    resdir = pytestconfig.getoption("--pg-resdir")

    if resdir is None:
        resdir = str(tmp_path_factory.getbasetemp())

    from pygears import reg
    reg['results-dir'] = resdir

    return resdir