Skip to content

Commit 16a6fce

Browse files
committed
Move common to gdb
1 parent 96f9271 commit 16a6fce

File tree

7 files changed

+61
-72
lines changed

7 files changed

+61
-72
lines changed

numba_dpex/tests/debugging/common.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

numba_dpex/tests/debugging/gdb.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
# SPDX-License-Identifier: Apache-2.0
66

77
import os
8+
import pathlib
89
import sys
910

1011
import pytest
1112

13+
import numba_dpex
1214
from numba_dpex.core import config
1315

14-
from .common import script_path
15-
1616
if config.TESTING_SKIP_NO_DEBUGGING:
1717
pexpect = pytest.importorskip("pexpect")
1818
else:
@@ -102,3 +102,57 @@ def set_scheduler_lock(self):
102102
@staticmethod
103103
def script_path(script):
104104
return script_path(script)
105+
106+
107+
def script_path(script):
108+
package_path = pathlib.Path(numba_dpex.__file__).parent
109+
return str(package_path / "examples/debug" / script)
110+
111+
112+
def line_number(file_path, text):
113+
"""Return line number of the text in the file"""
114+
with open(file_path, "r") as lines:
115+
for line_number, line in enumerate(lines):
116+
if text in line:
117+
return line_number + 1
118+
119+
raise RuntimeError(f"Can not find {text} in {file_path}")
120+
121+
122+
def breakpoint_by_mark(script, mark, offset=0):
123+
"""Return breakpoint for the mark in the script
124+
125+
Example: breakpoint_by_mark("script.py", "Set here") -> "script.py:25"
126+
"""
127+
return f"{script}:{line_number(script_path(script), mark) + offset}"
128+
129+
130+
def breakpoint_by_function(script, function):
131+
"""Return breakpoint for the function in the script"""
132+
return breakpoint_by_mark(script, f"def {function}", 1)
133+
134+
135+
def setup_breakpoint(
136+
app: gdb,
137+
breakpoint: str,
138+
script=None,
139+
expected_location=None,
140+
expected_line=None,
141+
):
142+
if not script:
143+
script = breakpoint.split(" ")[0].split(":")[0]
144+
145+
if not expected_location:
146+
expected_location = breakpoint.split(" ")[0]
147+
if not expected_location.split(":")[-1].isnumeric():
148+
expected_location = breakpoint_by_function(
149+
script, expected_location.split(":")[-1]
150+
)
151+
152+
app.breakpoint(breakpoint)
153+
app.run(script)
154+
155+
app.child.expect(rf"Thread .* hit Breakpoint .* at {expected_location}")
156+
157+
if expected_line:
158+
app.child.expect(expected_line)

numba_dpex/tests/debugging/test_backtraces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from numba_dpex.tests._helper import skip_no_gdb
1313

14-
from .common import setup_breakpoint
14+
from .gdb import setup_breakpoint
1515

1616
pytestmark = skip_no_gdb
1717

numba_dpex/tests/debugging/test_breakpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from numba_dpex.tests._helper import skip_no_gdb
1515

16-
from .common import breakpoint_by_function, breakpoint_by_mark, setup_breakpoint
16+
from .gdb import breakpoint_by_function, breakpoint_by_mark, setup_breakpoint
1717

1818
pytestmark = skip_no_gdb
1919

numba_dpex/tests/debugging/test_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from numba_dpex.tests._helper import skip_no_gdb
1212

13-
from .common import breakpoint_by_function, breakpoint_by_mark, setup_breakpoint
13+
from .gdb import breakpoint_by_function, breakpoint_by_mark, setup_breakpoint
1414

1515
pytestmark = skip_no_gdb
1616

numba_dpex/tests/debugging/test_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from numba_dpex.tests._helper import skip_no_gdb
1515

16-
from .common import setup_breakpoint
16+
from .gdb import setup_breakpoint
1717
from .test_breakpoints import side_by_side_breakpoint
1818

1919
pytestmark = skip_no_gdb

numba_dpex/tests/debugging/test_stepping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from numba_dpex.tests._helper import skip_no_gdb
1313

14-
from .common import setup_breakpoint
14+
from .gdb import setup_breakpoint
1515

1616
pytestmark = skip_no_gdb
1717

0 commit comments

Comments
 (0)