Commit 5dc75a83 authored by Mark Florisson's avatar Mark Florisson

Made tests less verbose by not using distutils.core.setup + skip debugger...

Made tests less verbose by not using distutils.core.setup + skip debugger tests when gdb < 7.2 or not available
parent c8376239
...@@ -36,7 +36,7 @@ def make_command_file(path_to_debug_info, prefix_code='', no_import=False): ...@@ -36,7 +36,7 @@ def make_command_file(path_to_debug_info, prefix_code='', no_import=False):
f.write(prefix_code) f.write(prefix_code)
f.write('set breakpoint pending on\n') f.write('set breakpoint pending on\n')
f.write("set print pretty on\n") f.write("set print pretty on\n")
f.write('python from Cython.Debugger import libcython\n') f.write('python from Cython.Debugger import libcython, libpython\n')
if no_import: if no_import:
# don't do this, this overrides file command in .gdbinit # don't do this, this overrides file command in .gdbinit
......
...@@ -5,6 +5,7 @@ import re ...@@ -5,6 +5,7 @@ import re
import sys import sys
import uuid import uuid
import shutil import shutil
import warnings
import textwrap import textwrap
import unittest import unittest
import tempfile import tempfile
...@@ -13,6 +14,7 @@ import distutils.core ...@@ -13,6 +14,7 @@ import distutils.core
from distutils import sysconfig from distutils import sysconfig
from distutils import ccompiler from distutils import ccompiler
import runtests
import Cython.Distutils.extension import Cython.Distutils.extension
from Cython.Debugger import Cygdb as cygdb from Cython.Debugger import Cygdb as cygdb
...@@ -45,18 +47,48 @@ class DebuggerTestCase(unittest.TestCase): ...@@ -45,18 +47,48 @@ class DebuggerTestCase(unittest.TestCase):
compiler = ccompiler.new_compiler() compiler = ccompiler.new_compiler()
compiler.compile(['cfuncs.c'], debug=True) compiler.compile(['cfuncs.c'], debug=True)
ext = Cython.Distutils.extension.Extension( opts = dict(
'codefile', test_directory=self.tempdir,
['codefile.pyx'], module='codefile',
pyrex_gdb=True, )
extra_objects=['cfuncs.o'])
cython_compile_testcase = runtests.CythonCompileTestCase(
workdir=self.tempdir,
# we clean up everything (not only compiled files)
cleanup_workdir=False,
**opts
)
distutils.core.setup( cython_compile_testcase.run_cython(
script_args=['build_ext', '--inplace'], targetdir=self.tempdir,
ext_modules=[ext], incdir=None,
cmdclass=dict(build_ext=Cython.Distutils.build_ext) annotate=False,
extra_compile_options={
'gdb_debug':True,
'output_dir':self.tempdir,
},
**opts
) )
cython_compile_testcase.run_distutils(
incdir=None,
workdir=self.tempdir,
extra_extension_args={'extra_objects':['cfuncs.o']},
**opts
)
# ext = Cython.Distutils.extension.Extension(
# 'codefile',
# ['codefile.pyx'],
# pyrex_gdb=True,
# extra_objects=['cfuncs.o'])
#
# distutils.core.setup(
# script_args=['build_ext', '--inplace'],
# ext_modules=[ext],
# cmdclass=dict(build_ext=Cython.Distutils.build_ext)
# )
def tearDown(self): def tearDown(self):
os.chdir(self.cwd) os.chdir(self.cwd)
shutil.rmtree(self.tempdir) shutil.rmtree(self.tempdir)
...@@ -110,6 +142,26 @@ class GdbDebuggerTestCase(DebuggerTestCase): ...@@ -110,6 +142,26 @@ class GdbDebuggerTestCase(DebuggerTestCase):
os.path.abspath(Cython.__file__)))) os.path.abspath(Cython.__file__))))
env = dict(os.environ, PYTHONPATH=os.pathsep.join(paths)) env = dict(os.environ, PYTHONPATH=os.pathsep.join(paths))
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()
p.wait()
p.stdout.close()
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()
if not have_gdb or map(int, gdb_version_number) < [7, 2]:
self.p = None
warnings.warn('Skipping gdb tests, need gdb >= 7.2')
else:
self.p = subprocess.Popen( self.p = subprocess.Popen(
args, args,
stdout=open(os.devnull, 'w'), stdout=open(os.devnull, 'w'),
...@@ -118,6 +170,7 @@ class GdbDebuggerTestCase(DebuggerTestCase): ...@@ -118,6 +170,7 @@ class GdbDebuggerTestCase(DebuggerTestCase):
def tearDown(self): def tearDown(self):
super(GdbDebuggerTestCase, self).tearDown() super(GdbDebuggerTestCase, self).tearDown()
if self.p:
self.p.stderr.close() self.p.stderr.close()
self.p.wait() self.p.wait()
os.remove(self.gdb_command_file) os.remove(self.gdb_command_file)
...@@ -126,6 +179,9 @@ class GdbDebuggerTestCase(DebuggerTestCase): ...@@ -126,6 +179,9 @@ class GdbDebuggerTestCase(DebuggerTestCase):
class TestAll(GdbDebuggerTestCase): class TestAll(GdbDebuggerTestCase):
def test_all(self): def test_all(self):
if self.p is None:
return
out, err = self.p.communicate() out, err = self.p.communicate()
border = '*' * 30 border = '*' * 30
start = '%s v INSIDE GDB v %s' % (border, border) start = '%s v INSIDE GDB v %s' % (border, border)
......
...@@ -15,6 +15,7 @@ import unittest ...@@ -15,6 +15,7 @@ import unittest
import textwrap import textwrap
import tempfile import tempfile
import traceback import traceback
import itertools
from test import test_support from test import test_support
import gdb import gdb
...@@ -248,6 +249,11 @@ class TestBacktrace(DebugTestCase): ...@@ -248,6 +249,11 @@ class TestBacktrace(DebugTestCase):
self.break_and_run('os.path.join("foo", "bar")') self.break_and_run('os.path.join("foo", "bar")')
result = gdb.execute('cy bt', to_string=True) result = gdb.execute('cy bt', to_string=True)
_debug(libpython.execute, libpython._execute, gdb.execute)
_debug(gdb.execute('cy list', to_string=True))
_debug(repr(result))
assert re.search(r'\#\d+ *0x.* in spam\(\) at .*codefile\.pyx:22', assert re.search(r'\#\d+ *0x.* in spam\(\) at .*codefile\.pyx:22',
result), result result), result
assert 'os.path.join("foo", "bar")' in result, result assert 'os.path.join("foo", "bar")' in result, result
...@@ -339,6 +345,16 @@ class TestExec(DebugTestCase): ...@@ -339,6 +345,16 @@ class TestExec(DebugTestCase):
self.assertEqual('14', self.eval_command('some_random_var')) self.assertEqual('14', self.eval_command('some_random_var'))
_do_debug = os.environ.get('CYTHON_GDB_DEBUG')
if _do_debug:
_debug_file = open('/dev/tty', 'w')
def _debug(*messages):
if _do_debug:
messages = itertools.chain([sys._getframe(1).f_code.co_name],
messages)
_debug_file.write(' '.join(str(msg) for msg in messages) + '\n')
def _main(): def _main():
try: try:
gdb.lookup_type('PyModuleObject') gdb.lookup_type('PyModuleObject')
......
...@@ -59,9 +59,13 @@ import itertools ...@@ -59,9 +59,13 @@ import itertools
import gdb import gdb
# I think this is the only way to fix this bug :'( if sys.version_info[0] < 3:
# http://sourceware.org/bugzilla/show_bug.cgi?id=12285 # I think this is the only way to fix this bug :'(
reload(sys).setdefaultencoding('UTF-8') # http://sourceware.org/bugzilla/show_bug.cgi?id=12285
out, err = sys.stdout, sys.stderr
reload(sys).setdefaultencoding('UTF-8')
sys.stdout = out
sys.stderr = err
# Look up the gdb.Type for some standard types: # Look up the gdb.Type for some standard types:
_type_char_ptr = gdb.lookup_type('char').pointer() # char* _type_char_ptr = gdb.lookup_type('char').pointer() # char*
......
...@@ -342,15 +342,27 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -342,15 +342,27 @@ class CythonCompileTestCase(unittest.TestCase):
else: else:
return geterrors() return geterrors()
def run_cython(self, test_directory, module, targetdir, incdir, annotate): def run_cython(self, test_directory, module, targetdir, incdir, annotate,
extra_compile_options=None):
include_dirs = INCLUDE_DIRS[:] include_dirs = INCLUDE_DIRS[:]
if incdir: if incdir:
include_dirs.append(incdir) include_dirs.append(incdir)
source = self.find_module_source_file( source = self.find_module_source_file(
os.path.join(test_directory, module + '.pyx')) os.path.join(test_directory, module + '.pyx'))
target = os.path.join(targetdir, self.build_target_filename(module)) target = os.path.join(targetdir, self.build_target_filename(module))
if extra_compile_options is None:
extra_compile_options = {}
try:
CompilationOptions
except NameError:
from Cython.Compiler.Main import CompilationOptions
from Cython.Compiler.Main import compile as cython_compile
from Cython.Compiler.Main import default_options
options = CompilationOptions( options = CompilationOptions(
pyrex_default_options, default_options,
include_path = include_dirs, include_path = include_dirs,
output_file = target, output_file = target,
annotate = annotate, annotate = annotate,
...@@ -359,11 +371,13 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -359,11 +371,13 @@ class CythonCompileTestCase(unittest.TestCase):
language_level = self.language_level, language_level = self.language_level,
generate_pxi = False, generate_pxi = False,
evaluate_tree_assertions = True, evaluate_tree_assertions = True,
**extra_compile_options
) )
cython_compile(source, options=options, cython_compile(source, options=options,
full_module_name=module) full_module_name=module)
def run_distutils(self, test_directory, module, workdir, incdir): def run_distutils(self, test_directory, module, workdir, incdir,
extra_extension_args=None):
cwd = os.getcwd() cwd = os.getcwd()
os.chdir(workdir) os.chdir(workdir)
try: try:
...@@ -377,11 +391,16 @@ class CythonCompileTestCase(unittest.TestCase): ...@@ -377,11 +391,16 @@ class CythonCompileTestCase(unittest.TestCase):
if match(module): if match(module):
ext_include_dirs += get_additional_include_dirs() ext_include_dirs += get_additional_include_dirs()
self.copy_related_files(test_directory, workdir, module) self.copy_related_files(test_directory, workdir, module)
if extra_extension_args is None:
extra_extension_args = {}
extension = Extension( extension = Extension(
module, module,
sources = self.find_source_files(workdir, module), sources = self.find_source_files(workdir, module),
include_dirs = ext_include_dirs, include_dirs = ext_include_dirs,
extra_compile_args = CFLAGS, extra_compile_args = CFLAGS,
**extra_extension_args
) )
if self.language == 'cpp': if self.language == 'cpp':
extension.language = 'c++' extension.language = 'c++'
......
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