From 00749e937a4aab5771900993f77c9fd2efe4982c Mon Sep 17 00:00:00 2001 From: "elena.totmenina" Date: Thu, 16 Sep 2021 15:47:01 +0300 Subject: [PATCH 1/2] WIP tests debug --- numba_dppy/tests/test_debug.py | 80 ++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 numba_dppy/tests/test_debug.py diff --git a/numba_dppy/tests/test_debug.py b/numba_dppy/tests/test_debug.py new file mode 100644 index 0000000000..8c85362bd2 --- /dev/null +++ b/numba_dppy/tests/test_debug.py @@ -0,0 +1,80 @@ +#! /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 + + +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" + + +# out = Popen(["ls", "-la", "."], stdout=PIPE) +def test_backtrace(): + # utils() + previous_dir = os.getcwd() + previous_numba_opt = os.environ.get("NUMBA_OPT") + os.chdir(previous_dir + "/numba_dppy/examples/debug") + os.environ["NUMBA_OPT"] = "0" + + 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\.\.\.", + ] + process = Popen( + [ + "gdb-oneapi", + "-q", + "-command", + "commands/backtrace", + "python", + ], + # cwd=wd, + stdout=PIPE, + stderr=PIPE, + ) + (output, err) = process.communicate() + exit_code = process.wait() + + output_str = str(output) + # print("!!!!!!!!!!!!!", output_str, "!!!!!!!!!!!!!") + for command in expected_commands: + # print(command) + # assert command in output + assert make_check(output_str, command) + + os.chdir(previous_dir) + if previous_numba_opt: + os.environ["NUMBA_OPT"] = previous_numba_opt + else: + os.environ.pop("NUMBA_OPT") From 6f48df6129adf35043e6ed49fd7e673e12b397e5 Mon Sep 17 00:00:00 2001 From: akharche Date: Thu, 16 Sep 2021 22:47:20 +0300 Subject: [PATCH 2/2] Add test and common runner --- numba_dppy/tests/test_debug.py | 61 +++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/numba_dppy/tests/test_debug.py b/numba_dppy/tests/test_debug.py index 8c85362bd2..a445cb3394 100644 --- a/numba_dppy/tests/test_debug.py +++ b/numba_dppy/tests/test_debug.py @@ -19,6 +19,8 @@ import os import pytest +import contextlib + def make_check(text, val_to_search): m = re.search(val_to_search, text, re.I) @@ -32,49 +34,62 @@ def utils(): os.environ["NUMBA_OPT"] = "0" -# out = Popen(["ls", "-la", "."], stdout=PIPE) -def test_backtrace(): - # utils() +@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") os.environ["NUMBA_OPT"] = "0" - 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\.\.\.", - ] process = Popen( [ "gdb-oneapi", "-q", "-command", - "commands/backtrace", + command_name, "python", ], - # cwd=wd, stdout=PIPE, stderr=PIPE, ) (output, err) = process.communicate() - exit_code = process.wait() - + process.wait() output_str = str(output) - # print("!!!!!!!!!!!!!", output_str, "!!!!!!!!!!!!!") - for command in expected_commands: - # print(command) - # assert command in output - assert make_check(output_str, command) + 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)