示例#1
0
def check_error(func, rel_lineno):
    """check if TIR script throws error"""
    # Override the default renderer to accumulate errors
    errors = []

    def render(e):
        for d in e.diagnostics:
            errors.append(d)

    override_renderer(render)
    # The diagnostic context throws an exception when it gets an error
    try:
        source_code = inspect.getsource(func)
        source_code = "@T.prim_func\n" + source_code
        from tvm.script import from_source

        # to avoid cyclic import
        from_source(source_code)
    except tvm.error.DiagnosticError as e:
        pass
    assert len(errors) == 1, errors
    for d in errors:
        assert (
            d.span.line - 1 == rel_lineno
        ), f"Expected error to be on line {rel_lineno}, but it was on {d.span.line - 1}"
示例#2
0
文件: tir.py 项目: were/tvm
def check_error(func, rel_lineno):
    """check if TIR script throws error"""
    # Override the default renderer to accumulate errors
    errors = []

    def render(e):
        for d in e.diagnostics:
            errors.append(d)

    override_renderer(render)
    # The diagnostic context throws an exception when it gets an error
    try:
        source_code = inspect.getsource(func)
        source_code = "@T.prim_func\n" + source_code
        from tvm.script import from_source

        # to avoid cyclic import
        from_source(source_code)
    except tvm.error.DiagnosticError as e:
        pass
    assert len(errors) == 1, errors
    for d in errors:
        assert (
            d.span.line - 1 == rel_lineno
        ), f"Expected error to be on line {rel_lineno}, but it was on {d.span.line - 1}"

    error_line = source_code.split("\n")[rel_lineno]
    m = CHECK_ERROR_RE.match(error_line)
    if m:
        expected_error_text = m.group(1)
        errors = [e.message for e in errors]
        assert (
            expected_error_text in errors
        ), f'check_error expects "{expected_error_text} in str(errors): {errors}'
示例#3
0
def test_complete_opaque_block_error():
    def render(e):
        pass

    override_renderer(render)

    try:
        from_source(func_with_opaque_block)
    except tvm.error.DiagnosticError:
        return
    assert False
示例#4
0
def check_error(module, rel_lineno):
    # Override the default renderer to accumulate errors
    _, start_line = inspect.getsourcelines(module)
    lineno = start_line + rel_lineno - 1
    errors = []

    def render(e):
        for d in e.diagnostics:
            errors.append(d)

    override_renderer(render)
    # The diagnostic context throws an exception when it gets an error
    try:
        mod = from_source(module)
    except tvm.error.DiagnosticError as e:
        pass
    assert len(errors) == 1, errors
    for d in errors:
        assert (
            d.span.line == lineno
        ), f"Expected error to be on line {lineno}, but it was on {d.span.line}"