예제 #1
0
def warn_test(casefile_path, output=True):
    casefile = os.path.basename(casefile_path)
    casename, _ = os.path.splitext(casefile)
    with open(casefile_path, 'r') as f:
        first_line = f.readline()
        if not first_line.startswith('#'):
            print('The file is not error test file')
            sys.exit(0)
        expected_msg = first_line.split('#')[1].rstrip('\n')
    f = io.StringIO()
    with redirect_stdout(f):
        try:
            compile_main(casefile_path, casename, TMP_DIR, debug_mode=output)
        except Exception as e:
            print(casefile_path)
            print('[WARNING TEST] FAILED')
    msg = f.getvalue()
    header = 'Warning: '
    for line in msg.split('\n'):
        if line.startswith(header):
            actual_msg = line[len(header):]
            if actual_msg != expected_msg:
                print(casefile_path)
                print(
                    '[WARNING TEST] FAILED: actual "{}", expected "{}"'.format(
                        actual_msg, expected_msg))
            return
    print(casefile_path)
    print('[WARNING TEST] FAILED: No warning messages')
예제 #2
0
def exec_test(casefile_path, output=True, compile_only=False):
    casefile = os.path.basename(casefile_path)
    casename, _ = os.path.splitext(casefile)
    options = types.SimpleNamespace()
    options.output_name = casename
    options.output_dir = TMP_DIR
    options.verbose_level = 0
    options.quiet_level = 0
    options.debug_mode = output
    try:
        compile_main(casefile_path, options)
    except Exception as e:
        print('[COMPILE PYTHON] FAILED:' + casefile_path)
        if env.dev_debug_mode:
            traceback.print_exc()
        print(e)
        return
    if compile_only:
        return
    finishes = []
    for testbench in env.testbenches:
        result_lines = simulate_verilog(testbench.orig_name, casename, casefile_path, output)
        if result_lines:
            finishes.append(result_lines[-2])
    return finishes
예제 #3
0
def error_test(casefile_path, output=True):
    casefile = os.path.basename(casefile_path)
    casename, _ = os.path.splitext(casefile)
    with open(casefile_path, 'r') as f:
        first_line = f.readline()
        if not first_line.startswith('#'):
            print('The file is not error test file')
            sys.exit(0)
        expected_msg = first_line.split('#')[1].rstrip('\n')
    options = types.SimpleNamespace()
    options.output_name = casename
    options.output_dir = TMP_DIR
    options.verbose_level = 0
    options.quiet_level = 3
    options.debug_mode = output
    try:
        compile_main(casefile_path, options)
    except AssertionError:
        raise
    except Exception as e:
        if e.args[0] == expected_msg:
            return
        if env.dev_debug_mode:
            traceback.print_exc()
        print(casefile_path)
        print('[ERROR TEST] FAILED: actual "{}", expected "{}"'.format(
            e.args[0], expected_msg))
        return
    print(casefile_path)
    print('[ERROR TEST] FAILED: No exception was raised')
예제 #4
0
def exec_compile(casefile_path, casename, simu_options):
    options = types.SimpleNamespace()
    options.output_name = casename
    options.output_dir = TMP_DIR
    options.verbose_level = 0
    options.quiet_level = 0 if simu_options.debug_mode else 3
    if simu_options:
        options.config = simu_options.config
        options.debug_mode = simu_options.debug_mode
        options.verilog_dump = simu_options.verilog_dump
        options.verilog_monitor = simu_options.verilog_monitor
    else:
        options.config = None
        options.debug_mode = False
        options.verilog_dump = False
        options.verilog_monitor = False
    try:
        compile_main(casefile_path, options)
    except Exception as e:
        print('[COMPILE PYTHON] FAILED:' + casefile_path)
        if env.dev_debug_mode:
            traceback.print_exc()
        print(e)
        return False
    if simu_options.compile_only:
        return False
    return True
예제 #5
0
파일: simu.py 프로젝트: ktok07b6/polyphony
def exec_test(test, output=True, compile_only=False):
    casefile = os.path.basename(test)
    casename, _ = os.path.splitext(casefile)
    try:
        compile_main(test, casename, TMP_DIR, debug_mode=output)
    except Exception as e:
        print('[COMPILE PYTHON] FAILED:'+test)
        if env.dev_debug_mode:
            traceback.print_exc()
        print(e)
        return
    if compile_only:
        return

    hdl_files = ['{}/{}.v'.format(TMP_DIR, casename), '{}/{}_test.v'.format(TMP_DIR, casename)]
    exec_name = '{}/test'.format(TMP_DIR)
    args = ('iverilog -I {} -W all -o {} -s test'.format(TMP_DIR, exec_name)).split(' ')
    args += hdl_files
    try:
        check_call(args)
    except Exception as e:
        print('[COMPILE HDL] FAILED:'+test)
        return

    try:
        out = check_output([exec_name])
        lines = out.decode('utf-8').split('\n')
        for line in lines:
            if output:
                print(line)
            if 'FAILED' in line:
                raise Exception()
    except Exception as e:
        print('[SIMULATION] FAILED:'+test)
        print(e)
예제 #6
0
def error_test(casefile_path, err_options):
    casefile = os.path.basename(casefile_path)
    casename, _ = os.path.splitext(casefile)
    with open(casefile_path, 'r') as f:
        first_line = f.readline()
        if not first_line.startswith('#'):
            print('The file is not error test file')
            sys.exit(0)
        expected_msg = first_line.split('#')[1].rstrip('\n')
    options = make_compile_options(casename, err_options, env.QUIET_ERROR)
    try:
        compile_main(casefile_path, options)
    except AssertionError:
        raise
    except Exception as e:
        if e.args[0] == expected_msg:
            return True
        if err_options.debug_mode:
            traceback.print_exc()
        print(casefile_path)
        print('[ERROR TEST] FAILED: actual "{}", expected "{}"'.format(
            e.args[0], expected_msg))
        return False
    print(casefile_path)
    print('[ERROR TEST] FAILED: No exception was raised')
    return False
예제 #7
0
def exec_test(test, output=True, compile_only=False):
    casefile = os.path.basename(test)
    casename, _ = os.path.splitext(casefile)
    try:
        compile_main(test, casename, TMP_DIR, debug_mode=output)
    except Exception as e:
        print('[COMPILE PYTHON] FAILED:' + test)
        if env.dev_debug_mode:
            traceback.print_exc()
        print(e)
        return
    if compile_only:
        return

    hdl_files = [
        '{}/{}.v'.format(TMP_DIR, casename),
        '{}/{}_test.v'.format(TMP_DIR, casename)
    ]
    exec_name = '{}/test'.format(TMP_DIR)
    args = ('iverilog -I {} -W all -o {} -s test'.format(TMP_DIR,
                                                         exec_name)).split(' ')
    args += hdl_files
    try:
        check_call(args)
    except Exception as e:
        print('[COMPILE HDL] FAILED:' + test)
        return

    try:
        out = check_output([exec_name])
        lines = out.decode('utf-8').split('\n')
        for line in lines:
            if output:
                print(line)
            if 'FAILED' in line:
                raise Exception()
    except Exception as e:
        print('[SIMULATION] FAILED:' + test)
        print(e)