Skip to content

Commit 4a5c1a2

Browse files
committed
Add accuracy test
1 parent 382db98 commit 4a5c1a2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/python/tir/test_debug_info.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ def find_span(m):
8484

8585

8686
def test_llvm_ir_debug_info():
87+
"""
88+
Check that the right amount of debug locations are present
89+
"""
8790
MyModule = _module()
8891
with tvm.transform.PassContext(opt_level=3, config={"tir.enable_debug": True}):
8992
runtime_module = tvm.build(MyModule, target="llvm")
@@ -94,5 +97,28 @@ def test_llvm_ir_debug_info():
9497
assert len(locations) == 34
9598

9699

100+
def test_llvm_ir_debug_accuracy():
101+
"""
102+
Check that the debug location on an assert is correct
103+
"""
104+
MyModule = _module()
105+
with tvm.transform.PassContext(opt_level=3, config={"tir.enable_debug": True}):
106+
runtime_module = tvm.build(MyModule, target="llvm")
107+
source = runtime_module.get_source()
108+
locations = find_di_locations(source)
109+
110+
# Find the 'assert' from MyModule
111+
debug_dir_match = re.search(
112+
r"tail call void %0\(i8\* getelementptr inbounds .* !dbg !(\d+)\n", source
113+
)
114+
115+
# Extract out the debug directive line
116+
directive_idx = debug_dir_match.groups()[0]
117+
118+
# Check that it matches the expected line number (in main.tir)
119+
debug_line_no = int(locations[directive_idx])
120+
assert debug_line_no == 42
121+
122+
97123
if __name__ == "__main__":
98124
tvm.testing.main()

0 commit comments

Comments
 (0)