Videre
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
from os.path import dirname
|
||||
import unittest
|
||||
from unittest.suite import TestSuite
|
||||
|
||||
from numba.testing import load_testsuite
|
||||
|
||||
def load_tests(loader, tests, pattern):
|
||||
suite = TestSuite()
|
||||
suite.addTests(load_testsuite(loader, dirname(__file__)))
|
||||
return suite
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,51 @@
|
||||
# NOTE: This test is sensitive to line numbers as it checks breakpoints
|
||||
from numba import njit, types
|
||||
import numpy as np
|
||||
from numba.tests.gdb_support import GdbMIDriver
|
||||
from numba.tests.support import TestCase, needs_subprocess
|
||||
import unittest
|
||||
|
||||
|
||||
@needs_subprocess
|
||||
class Test(TestCase):
|
||||
|
||||
def test(self):
|
||||
@njit(debug=True)
|
||||
def foo(x):
|
||||
z = np.ones_like(x) # break here
|
||||
return x, z
|
||||
|
||||
tmp = np.ones(5)
|
||||
foo(tmp)
|
||||
|
||||
driver = GdbMIDriver(__file__)
|
||||
driver.set_breakpoint(line=15)
|
||||
driver.run()
|
||||
driver.check_hit_breakpoint(1)
|
||||
driver.stack_list_arguments(2)
|
||||
llvm_intp = f"i{types.intp.bitwidth}"
|
||||
expect = (
|
||||
'[frame={level="0",args=[{name="x",type="array(float64, 1d, C) '
|
||||
f'({{i8*, i8*, {llvm_intp}, {llvm_intp}, double*, '
|
||||
f'[1 x {llvm_intp}], [1 x {llvm_intp}]}})"}}]}}]'
|
||||
)
|
||||
driver.assert_output(expect)
|
||||
driver.stack_list_variables(1)
|
||||
# 'z' should be zero-init
|
||||
expect = ('{name="z",value="{meminfo = 0x0, parent = 0x0, nitems = 0, '
|
||||
'itemsize = 0, data = 0x0, shape = {0}, strides = {0}}"}')
|
||||
driver.assert_output(expect)
|
||||
driver.set_breakpoint(line=16)
|
||||
driver.cont()
|
||||
driver.check_hit_breakpoint(2)
|
||||
driver.stack_list_variables(1)
|
||||
# 'z' should be populated
|
||||
expect = (r'^.*\{name="z",value="\{meminfo = 0x[0-9a-f]+ .*, '
|
||||
r'parent = 0x0, nitems = 5, itemsize = 8, '
|
||||
r'data = 0x[0-9a-f]+, shape = \{5\}, strides = \{8\}\}.*$')
|
||||
driver.assert_regex_output(expect)
|
||||
driver.quit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,39 @@
|
||||
# NOTE: This test is sensitive to line numbers as it checks breakpoints
|
||||
from numba import njit, types
|
||||
from numba.tests.gdb_support import GdbMIDriver
|
||||
from numba.tests.support import TestCase, needs_subprocess
|
||||
import unittest
|
||||
|
||||
|
||||
@needs_subprocess
|
||||
class Test(TestCase):
|
||||
|
||||
def test(self):
|
||||
@njit(debug=True)
|
||||
def foo(x):
|
||||
z = 7 + x # break here
|
||||
return x, z
|
||||
|
||||
foo(120)
|
||||
|
||||
sz = types.intp.bitwidth
|
||||
driver = GdbMIDriver(__file__)
|
||||
driver.set_breakpoint(line=14)
|
||||
driver.run()
|
||||
driver.check_hit_breakpoint(1)
|
||||
driver.stack_list_arguments(2)
|
||||
expect = ('[frame={level="0",args=[{name="x",type="int%s",'
|
||||
'value="120"}]}]' % sz)
|
||||
driver.assert_output(expect)
|
||||
driver.stack_list_variables(1)
|
||||
expect = '[{name="x",arg="1",value="120"},{name="z",value="0"}]'
|
||||
driver.assert_output(expect)
|
||||
driver.next()
|
||||
driver.stack_list_variables(1)
|
||||
expect = '[{name="x",arg="1",value="120"},{name="z",value="127"}]'
|
||||
driver.assert_output(expect)
|
||||
driver.quit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,34 @@
|
||||
# NOTE: This test is sensitive to line numbers as it checks breakpoints
|
||||
from numba import njit, types
|
||||
from numba.tests.gdb_support import GdbMIDriver
|
||||
from numba.tests.support import TestCase, needs_subprocess
|
||||
import unittest
|
||||
|
||||
|
||||
@njit(debug=True)
|
||||
def foo(x):
|
||||
z = 7 + x
|
||||
return x, z
|
||||
|
||||
|
||||
@needs_subprocess
|
||||
class Test(TestCase):
|
||||
|
||||
def test(self):
|
||||
foo(120)
|
||||
sz = types.intp.bitwidth
|
||||
driver = GdbMIDriver(__file__)
|
||||
driver.set_breakpoint(symbol="__main__::foo")
|
||||
driver.run() # will hit cpython symbol match
|
||||
driver.check_hit_breakpoint(number=1)
|
||||
driver.cont() # will hit njit symbol match
|
||||
driver.check_hit_breakpoint(number=1, line=10) # Ensure line number
|
||||
driver.stack_list_arguments(2)
|
||||
expect = ('[frame={level="0",args=[{name="x",type="int%s",'
|
||||
'value="120"}]}]' % sz)
|
||||
driver.assert_output(expect)
|
||||
driver.quit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,65 @@
|
||||
# NOTE: This test is sensitive to line numbers as it checks breakpoints
|
||||
from numba import njit
|
||||
from numba.tests.gdb_support import GdbMIDriver
|
||||
from numba.tests.support import TestCase, needs_subprocess
|
||||
import unittest
|
||||
|
||||
|
||||
def foo_factory(n):
|
||||
@njit(debug=True)
|
||||
def foo(x):
|
||||
z = 7 + n
|
||||
return x, z
|
||||
|
||||
return foo
|
||||
|
||||
|
||||
foo1, foo2, foo3 = [foo_factory(x) for x in range(3)]
|
||||
|
||||
|
||||
@njit(debug=True)
|
||||
def call_foo():
|
||||
a = foo1(10)
|
||||
b = foo2(20)
|
||||
c = foo3(30)
|
||||
return a, b, c
|
||||
|
||||
|
||||
@needs_subprocess
|
||||
class Test(TestCase):
|
||||
|
||||
def test(self):
|
||||
call_foo()
|
||||
driver = GdbMIDriver(__file__)
|
||||
# A specific foo, the first one, it has uid=2
|
||||
vsym = "__main__::foo_factory::_3clocals_3e::foo[abi:v2]"
|
||||
driver.set_breakpoint(symbol=vsym)
|
||||
driver.run()
|
||||
driver.check_hit_breakpoint(number=1)
|
||||
driver.assert_regex_output(r'^.*foo\[abi:v2\].*line="11"')
|
||||
driver.stack_list_arguments(2)
|
||||
expect = ('[frame={level="0",args=[{name="x",type="Literal[int](10)",'
|
||||
'value="10"}]}]')
|
||||
driver.assert_output(expect)
|
||||
# Now break on any foo
|
||||
driver.set_breakpoint(symbol="foo")
|
||||
driver.cont()
|
||||
driver.check_hit_breakpoint(number=2)
|
||||
driver.assert_regex_output(r'^.*foo\[abi:v3\].*line="11"')
|
||||
driver.stack_list_arguments(2)
|
||||
expect = ('[frame={level="0",args=[{name="x",type="Literal[int](20)",'
|
||||
'value="20"}]}]')
|
||||
driver.assert_output(expect)
|
||||
# and again, hit the third foo
|
||||
driver.cont()
|
||||
driver.check_hit_breakpoint(number=2)
|
||||
driver.assert_regex_output(r'^.*foo\[abi:v4\].*line="11"')
|
||||
driver.stack_list_arguments(2)
|
||||
expect = ('[frame={level="0",args=[{name="x",type="Literal[int](30)",'
|
||||
'value="30"}]}]')
|
||||
driver.assert_output(expect)
|
||||
driver.quit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,45 @@
|
||||
# NOTE: This test is sensitive to line numbers as it checks breakpoints
|
||||
from numba import njit
|
||||
from numba.tests.gdb_support import GdbMIDriver
|
||||
from numba.tests.support import TestCase, needs_subprocess
|
||||
import unittest
|
||||
|
||||
|
||||
@needs_subprocess
|
||||
class Test(TestCase):
|
||||
|
||||
def test(self):
|
||||
|
||||
@njit(debug=True)
|
||||
def foo(x, y):
|
||||
c = x + y # break-here
|
||||
return c
|
||||
|
||||
@njit(debug=True)
|
||||
def call_foo(a):
|
||||
acc = 0
|
||||
for i in range(10):
|
||||
acc += foo(i, a)
|
||||
return acc
|
||||
|
||||
call_foo(10)
|
||||
|
||||
driver = GdbMIDriver(__file__)
|
||||
driver.set_breakpoint(line=15, condition='x == 4')
|
||||
driver.run()
|
||||
driver.check_hit_breakpoint(1)
|
||||
driver.stack_list_arguments(1)
|
||||
expect = ('[frame={level="0",args=[{name="x",value="4"},'
|
||||
'{name="y",value="10"}]}]')
|
||||
driver.assert_output(expect)
|
||||
driver.set_breakpoint(line=22, condition='i == 8')
|
||||
driver.cont()
|
||||
driver.check_hit_breakpoint(2)
|
||||
driver.stack_list_variables(1)
|
||||
# i should be 8
|
||||
driver.assert_output('{name="i",value="8"}')
|
||||
driver.quit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,69 @@
|
||||
# NOTE: This test is sensitive to line numbers as it checks breakpoints
|
||||
from numba import njit
|
||||
import numpy as np
|
||||
from numba.tests.gdb_support import GdbMIDriver, needs_gdb_py3
|
||||
from numba.tests.support import TestCase, needs_subprocess
|
||||
from numba.misc.numba_gdbinfo import collect_gdbinfo
|
||||
import unittest
|
||||
import re
|
||||
|
||||
|
||||
@needs_gdb_py3
|
||||
@needs_subprocess
|
||||
class Test(TestCase):
|
||||
|
||||
def test(self):
|
||||
rdt_a = np.dtype([("x", np.int16), ("y", np.float64)], align=True)
|
||||
|
||||
@njit(debug=True)
|
||||
def foo():
|
||||
a = 1.234
|
||||
b = (1, 2, 3)
|
||||
c = ('a', b, 4)
|
||||
d = np.arange(5.)
|
||||
e = np.array([[1, 3j], [2, 4j]])
|
||||
f = "Some string" + " L-Padded string".lstrip()
|
||||
g = 11 + 22j
|
||||
h = np.arange(24).reshape((4, 6))[::2, ::3]
|
||||
i = np.zeros(2, dtype=rdt_a)
|
||||
return a, b, c, d, e, f, g, h, i
|
||||
|
||||
foo()
|
||||
|
||||
extension = collect_gdbinfo().extension_loc
|
||||
driver = GdbMIDriver(__file__, init_cmds=['-x', extension], debug=False)
|
||||
driver.set_breakpoint(line=29)
|
||||
driver.run()
|
||||
driver.check_hit_breakpoint(1)
|
||||
|
||||
# Ideally the function would be run to get the string repr of locals
|
||||
# but not everything appears in DWARF e.g. string literals. Further,
|
||||
# str on NumPy arrays seems to vary a bit in output. Therefore a custom
|
||||
# match is used.
|
||||
|
||||
driver.stack_list_variables(1)
|
||||
output = driver._captured.after.decode('UTF-8')
|
||||
done_str = output.splitlines()[0]
|
||||
pat = r'^\^done,variables=\[\{(.*)\}\]$'
|
||||
lcls_strs = re.match(pat, done_str).groups()[0].split('},{')
|
||||
lcls = {k: v for k, v in [re.match(r'name="(.*)",value="(.*)"',
|
||||
x).groups() for x in lcls_strs]}
|
||||
expected = dict()
|
||||
expected['a'] = r'1\.234'
|
||||
expected['b'] = r'\(1, 2, 3\)'
|
||||
expected['c'] = r'\(0x0, \(1, 2, 3\), 4\)'
|
||||
expected['d'] = r'\\n\[0. 1. 2. 3. 4.\]'
|
||||
expected['e'] = r'\\n\[\[1.\+0.j 0.\+3.j\]\\n \[2.\+0.j 0.\+4.j\]\]'
|
||||
expected['f'] = "'Some stringL-Padded string'"
|
||||
expected['g'] = r"11\+22j"
|
||||
expected['h'] = r'\\n\[\[ 0 3\]\\n \[12 15\]\]'
|
||||
expected['i'] = r'\\n\[\(0, 0.\) \(0, 0.\)\]'
|
||||
|
||||
for k, v in expected.items():
|
||||
self.assertRegex(lcls[k], v)
|
||||
|
||||
driver.quit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user