Skip to content

Refactoring for debugging tests #655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4843097
Make test parameterized and add description
PokhodenkoSA Dec 2, 2021
1183a5b
Merge branch 'spokhode/enh/gdb' into spokhode/enh/7415
PokhodenkoSA Dec 3, 2021
fa4da05
Use side-by-side scenario
PokhodenkoSA Dec 3, 2021
b434ecd
Test with different api
PokhodenkoSA Dec 3, 2021
88f7caa
Switch order for api and breakpoint
PokhodenkoSA Dec 3, 2021
9975748
Merge branch 'spokhode/enh/gdb' into spokhode/enh/7415
PokhodenkoSA Dec 16, 2021
e93b41f
Move test_debug_dppy_numba.py to numba_dppy/tests/debugging
PokhodenkoSA Dec 16, 2021
1da64f7
Extract tests/debugging/gdb.py
PokhodenkoSA Dec 16, 2021
78e3360
Move app() to conftests.py
PokhodenkoSA Dec 16, 2021
0fbec72
Move skip_no_numba055 to tests/_helper.py
PokhodenkoSA Dec 16, 2021
e8cd9f7
Move skip_no_gdb to tests/_helper.py
PokhodenkoSA Dec 16, 2021
969c0d8
Extract tests for breakpoints in tests/debugging/test_breakpoints.py
PokhodenkoSA Dec 16, 2021
2f0d12d
Move test_break_conditional to test_breakpoints.py
PokhodenkoSA Dec 17, 2021
129f711
Move tests to test_breakpoints.py
PokhodenkoSA Dec 17, 2021
f3a533a
Add docstring for test_breakpoints.py module
PokhodenkoSA Dec 17, 2021
f622c56
Add docstring for test_break_conditional
PokhodenkoSA Dec 17, 2021
3b9d49e
Add common_loop_body_native_function_name
PokhodenkoSA Dec 17, 2021
015d6b7
Add test_side_by_side.py
PokhodenkoSA Dec 17, 2021
fb72b89
Add test_stepping.py
PokhodenkoSA Dec 17, 2021
9647129
Fix black and pre-commit
PokhodenkoSA Dec 17, 2021
31720a6
Add test_info.py
PokhodenkoSA Dec 17, 2021
54586cc
Add test_backtraces.py
PokhodenkoSA Dec 17, 2021
d7cc779
Add file:function case to test_breakpoint_with_condition_by_function_…
PokhodenkoSA Dec 17, 2021
e60e57a
Add breakpoint_api_cases
PokhodenkoSA Dec 17, 2021
8103dfc
Add test_breakpoint_common
PokhodenkoSA Dec 17, 2021
82d9bb1
Replace test_break_function with parameter
PokhodenkoSA Dec 17, 2021
6bb940b
Replace test_break_nested_function with parameter
PokhodenkoSA Dec 17, 2021
3ed7e60
Add test_breakpoint_with_condition_common
PokhodenkoSA Dec 17, 2021
d4d8f7a
Add common.py with script_path() and breakpoint_by_mark()
PokhodenkoSA Dec 17, 2021
678ccaf
Add test_common.py
PokhodenkoSA Dec 17, 2021
94edf42
Add side_by_side_breakpoint
PokhodenkoSA Dec 17, 2021
99a8650
Use marks for simple_sum.py
PokhodenkoSA Dec 17, 2021
ab5c486
Add breakpoint_by_function()
PokhodenkoSA Dec 17, 2021
eeb57b1
Add setup_breakpoint()
PokhodenkoSA Dec 17, 2021
0d562ab
Use setup_breakpoint
PokhodenkoSA Dec 17, 2021
3e53fd2
Remove expected_line
PokhodenkoSA Dec 17, 2021
34fc845
Use setup_breakpoint
PokhodenkoSA Dec 17, 2021
3f5d744
Skip if no GDB for test_common.py
PokhodenkoSA Dec 20, 2021
4d614c3
Add examples into package
PokhodenkoSA Dec 21, 2021
f139116
Print more info for testing
PokhodenkoSA Dec 22, 2021
933b014
Skip tests with app() if pexpect not installed
PokhodenkoSA Dec 22, 2021
9768b57
Add pexpect in test dependencies
PokhodenkoSA Dec 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ jobs:
run: |
# echo "libintelocl.so" | tee /etc/OpenCL/vendors/intel-cpu.icd
export OCL_ICD_FILENAMES=libintelocl.so
python -m pytest --pyargs $MODULE_NAME
python -m pytest -q -ra --disable-warnings --pyargs $MODULE_NAME -vv

test_windows:
needs: build_windows
Expand Down Expand Up @@ -275,7 +275,7 @@ jobs:
run: echo "NUMBA_DPPY_TESTING_SKIP_NO_DPNP=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Run tests
run: |
python -m pytest --pyargs ${{ env.MODULE_NAME }}
python -m pytest -q -ra --disable-warnings --pyargs ${{ env.MODULE_NAME }} -vv

upload_linux:
needs: test_linux
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ recursive-include numba_dppy *.spir

include versioneer.py
include numba_dppy/_version.py

recursive-include numba_dppy/examples *
1 change: 1 addition & 0 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ test:
requires:
- pytest
- {{ compiler('dpcpp') }} # [not osx]
- pexpect

about:
home: https://github.com/IntelPython/numba-dppy
Expand Down
2 changes: 1 addition & 1 deletion numba_dppy/examples/debug/side-by-side.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


def common_loop_body(param_a, param_b):
param_c = param_a + 10 # Set breakpoint
param_c = param_a + 10 # Set breakpoint here
param_d = param_b * 0.5
result = param_c + param_d
return result
Expand Down
2 changes: 1 addition & 1 deletion numba_dppy/examples/debug/simple_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@dppy.kernel(debug=True)
def data_parallel_sum(a, b, c):
i = dppy.get_global_id(0)
c[i] = a[i] + b[i]
c[i] = a[i] + b[i] # Condition breakpoint location


global_size = 10
Expand Down
11 changes: 11 additions & 0 deletions numba_dppy/tests/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
# limitations under the License.

import contextlib
import shutil

import dpctl
import pytest
from numba.tests.support import captured_stdout

from numba_dppy import config
from numba_dppy.numba_support import numba_version


def has_opencl_gpu():
Expand Down Expand Up @@ -113,6 +115,15 @@ def platform_not_supported(device_type):
pytest.param("level_zero:gpu:0", marks=skip_no_level_zero_gpu),
]

skip_no_numba055 = pytest.mark.skipif(
numba_version < (0, 55), reason="Need Numba 0.55 or higher"
)

skip_no_gdb = pytest.mark.skipif(
not shutil.which("gdb-oneapi"),
reason="Intel® Distribution for GDB* is not available",
)


@contextlib.contextmanager
def override_config(name, value, config=config):
Expand Down
19 changes: 19 additions & 0 deletions numba_dppy/tests/debugging/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
################################################################################
# Numba-DPPY
#
# Copyright 2020-2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################

from . import *
73 changes: 73 additions & 0 deletions numba_dppy/tests/debugging/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#! /usr/bin/env python
# Copyright 2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Common tools for testing debugging"""

import pathlib

import numba_dppy


def script_path(script):
package_path = pathlib.Path(numba_dppy.__file__).parent
return str(package_path / "examples/debug" / script)


def line_number(file_path, text):
"""Return line number of the text in the file"""
with open(file_path, "r") as lines:
for line_number, line in enumerate(lines):
if text in line:
return line_number + 1

raise RuntimeError(f"Can not find {text} in {file_path}")


def breakpoint_by_mark(script, mark, offset=0):
"""Return breakpoint for the mark in the script

Example: breakpoint_by_mark("script.py", "Set here") -> "script.py:25"
"""
return f"{script}:{line_number(script_path(script), mark) + offset}"


def breakpoint_by_function(script, function):
"""Return breakpoint for the function in the script"""
return breakpoint_by_mark(script, f"def {function}", 1)


def setup_breakpoint(
app,
breakpoint: str,
script=None,
expected_location=None,
expected_line=None,
):
if not script:
script = breakpoint.split(" ")[0].split(":")[0]

if not expected_location:
expected_location = breakpoint.split(" ")[0]
if not expected_location.split(":")[-1].isnumeric():
expected_location = breakpoint_by_function(
script, expected_location.split(":")[-1]
)

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

app.child.expect(fr"Thread .* hit Breakpoint .* at {expected_location}")

if expected_line:
app.child.expect(expected_line)
23 changes: 23 additions & 0 deletions numba_dppy/tests/debugging/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /usr/bin/env python
# Copyright 2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest


@pytest.fixture
def app():
from .gdb import gdb

return gdb()
103 changes: 103 additions & 0 deletions numba_dppy/tests/debugging/gdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#! /usr/bin/env python
# Copyright 2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import os
import sys

import pytest

from numba_dppy import config

from .common import script_path

pexpect = pytest.importorskip("pexpect")


class gdb:
def __init__(self):
self.spawn()
self.setup_gdb()

def __del__(self):
self.teardown_gdb()

def spawn(self):
env = os.environ.copy()
env["NUMBA_OPT"] = "0"
env["NUMBA_EXTEND_VARIABLE_LIFETIMES"] = "1"

self.child = pexpect.spawn(
"gdb-oneapi -q python", env=env, encoding="utf-8"
)
if config.DEBUG:
self.child.logfile = sys.stdout

def setup_gdb(self):
self.child.expect("(gdb)", timeout=5)
self.child.sendline("set breakpoint pending on")
self.child.expect("(gdb)", timeout=5)
self.child.sendline("set style enabled off") # disable colors symbols

def teardown_gdb(self):
self.child.sendintr()
self.child.expect("(gdb)", timeout=5)
self.child.sendline("quit")
self.child.expect("Quit anyway?", timeout=5)
self.child.sendline("y")

def _command(self, command):
self.child.expect("(gdb)", timeout=5)
self.child.sendline(command)

def breakpoint(self, breakpoint):
self._command("break " + breakpoint)

def run(self, script):
self._command("run " + self.script_path(script))

def backtrace(self):
self._command("backtrace")

def print(self, var):
self._command("print " + var)

def info_args(self):
self._command("info args")

def info_functions(self, function):
self._command("info functions " + function)

def info_locals(self):
self._command("info locals")

def next(self):
self._command("next")

def ptype(self, var):
self._command("ptype " + var)

def whatis(self, var):
self._command("whatis " + var)

def step(self):
self._command("step")

def stepi(self):
self._command("stepi")

@staticmethod
def script_path(script):
return script_path(script)
41 changes: 41 additions & 0 deletions numba_dppy/tests/debugging/test_backtraces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! /usr/bin/env python
# Copyright 2021 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for Backtraces

https://www.sourceware.org/gdb/onlinedocs/gdb/Backtrace.html
"""

from numba_dppy.tests._helper import skip_no_gdb

from .common import setup_breakpoint

pytestmark = skip_no_gdb


def test_backtrace(app):
"""Simple test for backtrace.

commands/backtrace
"""
setup_breakpoint(
app,
"simple_dppy_func.py:23",
expected_line=r"23\s+result = a_in_func \+ b_in_func",
)

app.backtrace()

app.child.expect(r"#0.*__main__::func_sum .* at simple_dppy_func.py:23")
app.child.expect(r"#1.*__main__::kernel_sum .* at simple_dppy_func.py:30")
Loading