Skip to content

Commit

Permalink
Corrected gdb tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roxx30198 authored and roxx30198 committed Dec 7, 2023
1 parent d1700ff commit 4d14999
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 143 deletions.
13 changes: 11 additions & 2 deletions numba_dpex/examples/debug/side-by-side-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import argparse

import dpctl
import dpnp
import numba
import numpy as np

Expand All @@ -24,23 +25,31 @@ def scenario(api):
print("Using API:", api)

global_size = 10
a, b, c = arguments(global_size)

if api == "numba-ndpx-kernel":
a, b, c = ndpx_arguments(global_size)
ndpx_func_driver(a, b, c)
else:
a, b, c = numba_arguments(global_size)
numba_func_driver(a, b, c)

print(a, b, c, sep="\n")


def arguments(N, dtype=np.float32):
def numba_arguments(N, dtype=np.float32):
a = np.arange(N, dtype=dtype)
b = np.arange(N, dtype=dtype)
c = np.empty_like(a)
return a, b, c


def ndpx_arguments(N, dtype=dpnp.float32):
a = dpnp.arange(N, dtype=dtype)
b = dpnp.arange(N, dtype=dtype)
c = dpnp.empty_like(a)
return a, b, c


@numba.njit(debug=True)
def numba_func_driver(a, b, c):
for i in range(len(c)):
Expand Down
17 changes: 13 additions & 4 deletions numba_dpex/examples/debug/side-by-side.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
import argparse

import dpctl
import dpnp
import numba
import numpy as np

import numba_dpex as ndpx


def common_loop_body(param_a, param_b):
param_c = param_a + 10 # Set breakpoint here
param_d = param_b * 0.5
param_c = param_a + np.float32(10) # Set breakpoint here
param_d = param_b * np.float32(0.5)
result = param_c + param_d
return result

Expand All @@ -22,23 +23,31 @@ def scenario(api):
print("Using API:", api)

global_size = 10
a, b, c = arguments(global_size)

if api == "numba-ndpx-kernel":
a, b, c = ndpx_arguments(global_size)
ndpx_func_driver(a, b, c)
else:
a, b, c = numba_arguments(global_size)
numba_func_driver(a, b, c)

print(a, b, c, sep="\n")


def arguments(N, dtype=np.float32):
def numba_arguments(N, dtype=np.float32):
a = np.arange(N, dtype=dtype)
b = np.arange(N, dtype=dtype)
c = np.empty_like(a)
return a, b, c


def ndpx_arguments(N, dtype=dpnp.float32):
a = dpnp.arange(N, dtype=dtype)
b = dpnp.arange(N, dtype=dtype)
c = dpnp.empty_like(a)
return a, b, c


@numba.njit(debug=True)
def numba_func_driver(a, b, c):
for i in range(len(c)):
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/tests/debugging/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def setup_breakpoint(
script, expected_location.split(":")[-1]
)

app.breakpoint(breakpoint)
app.breakpoint(expected_location)
app.run(script)

app.child.expect(rf"Thread .* hit Breakpoint .* at {expected_location}")
Expand Down
3 changes: 3 additions & 0 deletions numba_dpex/tests/debugging/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def step(self):
def stepi(self):
self._command("stepi")

def set_scheduler_lock(self):
self._command("set scheduler-locking step")

@staticmethod
def script_path(script):
return script_path(script)
10 changes: 3 additions & 7 deletions numba_dpex/tests/debugging/test_backtraces.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@
pytestmark = skip_no_gdb


@pytest.mark.xfail # TODO: https://github.com/IntelPython/numba-dpex/issues/1216
def test_backtrace(app):
"""Simple test for backtrace.
commands/backtrace
"""
setup_breakpoint(
app,
"simple_dpex_func.py:13",
expected_line=r"13\s+result = a_in_func \+ b_in_func",
"simple_dpex_func.py:12",
expected_line=r"12\s+result = a_in_func \+ b_in_func",
)

app.backtrace()

app.child.expect(r"#0.*__main__::func_sum .* at simple_dpex_func.py:13")


# app.child.expect(r"#1.*__main__::kernel_sum .* at simple_dpex_func.py:20")
app.child.expect(r"#0.*__main__::func_sum.* at simple_dpex_func.py:12")
20 changes: 12 additions & 8 deletions numba_dpex/tests/debugging/test_breakpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@

common_loop_body_native_function_name = {
"numba": "common_loop_body",
"numba-dpex-kernel": "common_loop_body",
"numba-ndpx-kernel": "common_loop_body",
}

breakpoint_api_cases = [
(side_by_side_breakpoint, "numba"),
(side_by_side_breakpoint, "numba-dpex-kernel"),
(side_by_side_breakpoint, "numba-ndpx-kernel"),
*((fn, api) for api, fn in common_loop_body_native_function_name.items()),
*(
(f"side-by-side.py:{fn}", api)
Expand All @@ -51,16 +51,16 @@ def test_breakpoint_with_condition_by_function_argument(app, breakpoint, api):
Test that it is possible to set conditional breakpoint at the beginning
of the function and use a function argument in the condition.
It is important that breakpoint by function name hits at the firts line in
It is important that breakpoint by function name hits at the first line in
the function body and not at the function definition line.
Test for https://github.com/numba/numba/issues/7415
SAT-4449
"""
if api == "numba-dpex-kernel":
if api == "numba-ndpx-kernel":
pytest.xfail(
"Wrong name for kernel api."
) # TODO: https://github.com/IntelPython/numba-dpex/issues/1216
"Conditional breakpoints for numba-ndpx-kernel doesn't work." # TODO: https://github.com/IntelPython/numba-dpex/issues/1221
)

variable_name = "param_a"
variable_value = "3"
Expand All @@ -78,7 +78,6 @@ def test_breakpoint_with_condition_by_function_argument(app, breakpoint, api):
app.child.expect(rf"\$1 = {variable_value}")


@pytest.mark.xfail # TODO: https://github.com/IntelPython/numba-dpex/issues/1216
@pytest.mark.parametrize(
"breakpoint, script",
[
Expand All @@ -98,11 +97,16 @@ def test_breakpoint_common(app, breakpoint, script):
setup_breakpoint(app, breakpoint, script=script)


@pytest.mark.xfail # TODO: https://github.com/IntelPython/numba-dpex/issues/1221
@pytest.mark.parametrize(
"breakpoint, variable_name, variable_value",
[
# commands/break_conditional # noqa: E800
(f"{simple_sum_condition_breakpoint} if i == 1", "i", "1"),
(
f"{simple_sum_condition_breakpoint} --api=numba-ndpx-kernel if i == 1",
"i",
"1",
),
],
)
def test_breakpoint_with_condition_common(
Expand Down
12 changes: 2 additions & 10 deletions numba_dpex/tests/debugging/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

@pytest.mark.parametrize(
"file_name, mark, expected",
[("side-by-side.py", "Set breakpoint here", "side-by-side.py:15")],
[("side-by-side.py", "Set breakpoint here", "side-by-side.py:16")],
)
def test_breakpoint_by_mark(file_name, mark, expected):
assert expected == breakpoint_by_mark(file_name, mark)


@pytest.mark.parametrize(
"file_name, function, expected",
[("side-by-side.py", "common_loop_body", "side-by-side.py:15")],
[("side-by-side.py", "common_loop_body", "side-by-side.py:16")],
)
def test_breakpoint_by_function(file_name, function, expected):
assert expected == breakpoint_by_function(file_name, function)
Expand All @@ -50,12 +50,4 @@ def test_breakpoint_by_function(file_name, function, expected):
def test_setup_breakpoint(
app, breakpoint, script, expected_location, expected_line
):
if (
breakpoint == "simple_sum.py:data_parallel_sum"
or breakpoint == "data_parallel_sum"
):
pytest.xfail(
"Expected failures for these files."
) # TODO: https://github.com/IntelPython/numba-dpex/issues/1216

setup_breakpoint(app, breakpoint, script, expected_location, expected_line)
Loading

0 comments on commit 4d14999

Please sign in to comment.