Commit a9b2d18f authored by Robert Bradshaw's avatar Robert Bradshaw

Avoid more gdb errors for insufficient gdb.

parent fe17af96
...@@ -29,6 +29,49 @@ with open(codefile) as f: ...@@ -29,6 +29,49 @@ with open(codefile) as f:
# can't access the module anymore. Get it from sys.modules instead. # can't access the module anymore. Get it from sys.modules instead.
build_ext = sys.modules['Cython.Distutils.build_ext'] build_ext = sys.modules['Cython.Distutils.build_ext']
have_gdb = None
def test_gdb():
global have_gdb
if have_gdb is None:
try:
p = subprocess.Popen(['gdb', '-v'], stdout=subprocess.PIPE)
have_gdb = True
except OSError:
# gdb was not installed
have_gdb = False
else:
gdb_version = p.stdout.read().decode('ascii')
p.wait()
p.stdout.close()
if have_gdb:
# Based on Lib/test/test_gdb.py
regex = "^GNU gdb [^\d]*(\d+)\.(\d+)"
gdb_version_number = list(map(int, re.search(regex, gdb_version).groups()))
if gdb_version_number >= [7, 2]:
python_version_script = tempfile.NamedTemporaryFile(mode='w+')
python_version_script.write(
'python import sys; print("%s %s" % sys.version_info[:2])')
python_version_script.flush()
p = subprocess.Popen(['gdb', '-batch', '-x', python_version_script.name],
stdout=subprocess.PIPE)
python_version = p.stdout.read().decode('ascii')
p.wait()
python_version_number = list(map(int, python_version.split()))
# Be Python 3 compatible
if (not have_gdb
or gdb_version_number < [7, 2]
or python_version_number < [2, 6]):
warnings.warn(
'Skipping gdb tests, need gdb >= 7.2 with Python >= 2.6')
have_gdb = False
return have_gdb
class DebuggerTestCase(unittest.TestCase): class DebuggerTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -36,6 +79,9 @@ class DebuggerTestCase(unittest.TestCase): ...@@ -36,6 +79,9 @@ class DebuggerTestCase(unittest.TestCase):
Run gdb and have cygdb import the debug information from the code Run gdb and have cygdb import the debug information from the code
defined in TestParseTreeTransforms's setUp method defined in TestParseTreeTransforms's setUp method
""" """
if not test_gdb():
return
self.tempdir = tempfile.mkdtemp() self.tempdir = tempfile.mkdtemp()
self.destfile = os.path.join(self.tempdir, 'codefile.pyx') self.destfile = os.path.join(self.tempdir, 'codefile.pyx')
self.debug_dest = os.path.join(self.tempdir, self.debug_dest = os.path.join(self.tempdir,
...@@ -100,6 +146,8 @@ class DebuggerTestCase(unittest.TestCase): ...@@ -100,6 +146,8 @@ class DebuggerTestCase(unittest.TestCase):
# ) # )
def tearDown(self): def tearDown(self):
if not test_gdb():
return
os.chdir(self.cwd) os.chdir(self.cwd)
shutil.rmtree(self.tempdir) shutil.rmtree(self.tempdir)
...@@ -107,6 +155,9 @@ class DebuggerTestCase(unittest.TestCase): ...@@ -107,6 +155,9 @@ class DebuggerTestCase(unittest.TestCase):
class GdbDebuggerTestCase(DebuggerTestCase): class GdbDebuggerTestCase(DebuggerTestCase):
def setUp(self): def setUp(self):
if not test_gdb():
return
super(GdbDebuggerTestCase, self).setUp() super(GdbDebuggerTestCase, self).setUp()
prefix_code = textwrap.dedent('''\ prefix_code = textwrap.dedent('''\
...@@ -167,6 +218,11 @@ class GdbDebuggerTestCase(DebuggerTestCase): ...@@ -167,6 +218,11 @@ class GdbDebuggerTestCase(DebuggerTestCase):
p.stdout.close() p.stdout.close()
if have_gdb: if have_gdb:
# Based on Lib/test/test_gdb.py
regex = "^GNU gdb [^\d]*(\d+)\.(\d+)"
gdb_version_number = list(map(int, re.search(regex, gdb_version).groups()))
if gdb_version_number >= [7, 2]:
python_version_script = tempfile.NamedTemporaryFile(mode='w+') python_version_script = tempfile.NamedTemporaryFile(mode='w+')
python_version_script.write( python_version_script.write(
'python import sys; print("%s %s" % sys.version_info[:2])') 'python import sys; print("%s %s" % sys.version_info[:2])')
...@@ -175,16 +231,12 @@ class GdbDebuggerTestCase(DebuggerTestCase): ...@@ -175,16 +231,12 @@ class GdbDebuggerTestCase(DebuggerTestCase):
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
python_version = p.stdout.read().decode('ascii') python_version = p.stdout.read().decode('ascii')
p.wait() p.wait()
python_version_number = [int(a) for a in python_version.split()] python_version_number = list(map(int, python_version.split()))
if have_gdb:
# Based on Lib/test/test_gdb.py
regex = "^GNU gdb [^\d]*(\d+)\.(\d+)"
gdb_version_number = re.search(regex, gdb_version).groups()
# Be Python 3 compatible # Be Python 3 compatible
if (not have_gdb if (not have_gdb
or list(map(int, gdb_version_number)) < [7, 2] or gdb_version_number < [7, 2]
or python_version_number < [2, 6]): or python_version_number < [2, 6]):
self.p = None self.p = None
warnings.warn( warnings.warn(
...@@ -197,6 +249,9 @@ class GdbDebuggerTestCase(DebuggerTestCase): ...@@ -197,6 +249,9 @@ class GdbDebuggerTestCase(DebuggerTestCase):
env=env) env=env)
def tearDown(self): def tearDown(self):
if not test_gdb():
return
super(GdbDebuggerTestCase, self).tearDown() super(GdbDebuggerTestCase, self).tearDown()
if self.p: if self.p:
self.p.stderr.close() self.p.stderr.close()
...@@ -207,7 +262,7 @@ class GdbDebuggerTestCase(DebuggerTestCase): ...@@ -207,7 +262,7 @@ class GdbDebuggerTestCase(DebuggerTestCase):
class TestAll(GdbDebuggerTestCase): class TestAll(GdbDebuggerTestCase):
def test_all(self): def test_all(self):
if self.p is None: if not test_gdb():
return return
out, err = self.p.communicate() out, err = self.p.communicate()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment