Skip to content

WIP test debug commands #548

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
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
95 changes: 95 additions & 0 deletions numba_dppy/tests/test_debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#! /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 re
import subprocess
from subprocess import Popen, PIPE
import os
import pytest

import contextlib


def make_check(text, val_to_search):
m = re.search(val_to_search, text, re.I)
got = m is not None
return got


def utils():
wd = os.getcwd() + "/numba_dppy/examples/debug"
os.chdir(wd)
os.environ["NUMBA_OPT"] = "0"


@contextlib.contextmanager
def run_command(command_name):
previous_dir = os.getcwd()
previous_numba_opt = os.environ.get("NUMBA_OPT")
os.chdir(previous_dir + "/numba_dppy/examples/debug")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use absolute paths instead of changing current dir.

os.environ["NUMBA_OPT"] = "0"

process = Popen(
[
"gdb-oneapi",
"-q",
"-command",
command_name,
"python",
],
stdout=PIPE,
stderr=PIPE,
)
(output, err) = process.communicate()
process.wait()
output_str = str(output)
yield output_str

os.chdir(previous_dir)
if previous_numba_opt:
os.environ["NUMBA_OPT"] = previous_numba_opt
else:
os.environ.pop("NUMBA_OPT")


# out = Popen(["ls", "-la", "."], stdout=PIPE)
def test_backtrace():
expected_commands = [
r"Thread .*",
r"Thread .\.. hit Breakpoint ., with SIMD lanes \[.\-.\], __main__::func_sum \(\) at simple_dppy_func.py:..",
r".*result = a_in_func \+ b_in_func",
r"\#0 __main__::func_sum \(\) at simple_dppy_func.py:..",
r"\#1 __main__::kernel_sum \(\) at simple_dppy_func.py:..",
r"\[Switching to Thread .* lane .\]",
r"Thread .\.. hit Breakpoint 1, with SIMD lanes \[.\-.\], __main__::func_sum \(\) at simple_dppy_func.py:..",
r".*result = a_in_func \+ b_in_func",
r"Done\.\.\.",
]

with run_command("commands/backtrace") as backtrace_out:
for command in expected_commands:
assert make_check(backtrace_out, command)


def test_break_func():
expected_commands = [
r"Thread .\.. hit Breakpoint ., with SIMD lanes \[.\-.\], __main__::data_parallel_sum \(\) at simple_sum.py:..",
r"i = dppy.get_global_id\(0\)",
r"Done\.\.\.",
]

with run_command("commands/break_func") as break_func_out:
for command in expected_commands:
assert make_check(break_func_out, command)