Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
f4d42e80
Commit
f4d42e80
authored
Feb 20, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add initial nogil coverage test (not currently tracing nogil code)
parent
31189fdb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
0 deletions
+89
-0
tests/run/coverage_nogil.srctree
tests/run/coverage_nogil.srctree
+89
-0
No files found.
tests/run/coverage_nogil.srctree
0 → 100644
View file @
f4d42e80
# mode: run
# tag: coverage,trace,nogil
"""
PYTHON setup.py build_ext -i
PYTHON coverage_test.py
"""
######## setup.py ########
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize([
'coverage_test_*.pyx',
]))
######## .coveragerc ########
[run]
plugins = Cython.Coverage
######## coverage_test_nogil.pyx ########
# cython: linetrace=True
# distutils: define_macros=CYTHON_TRACE=1
cdef int func1(int a, int b) nogil:
cdef int x = 1 # 5
cdef int c = func2(a) + b # 6
return x + c # 7
cdef int func2(int a) with gil:
return a * 2 # 11
def call(int a, int b):
with nogil: # 15
result = func1(a, b) # 16
return result # 17
######## coverage_test.py ########
import os.path
try:
# io.StringIO in Py2.x cannot handle str ...
from StringIO import StringIO
except ImportError:
from io import StringIO
from coverage import coverage
import coverage_test_nogil
assert not any(coverage_test_nogil.__file__.endswith(ext)
for ext in '.py .pyc .pyo .pyw .pyx .pxi'.split()), \
coverage_test_nogil.__file__
def run_coverage(module):
module_name = module.__name__
module_path = module_name + '.pyx'
cov = coverage()
cov.start()
assert module.call(1, 2) == (1 * 2) + 2 + 1
cov.stop()
out = StringIO()
cov.report(file=out)
#cov.report([module], file=out)
lines = out.getvalue().splitlines()
assert any(module_path in line for line in lines), \
"'%s' not found in coverage report:\n\n%s" % (module_path, out.getvalue())
mod_file, exec_lines, excl_lines, missing_lines, _ = cov.analysis2(os.path.abspath(module_path))
assert module_path in mod_file
executed = set(exec_lines) - set(missing_lines)
# check that everything that runs with the gil owned was executed
assert all(line in executed for line in [11, 15, 17]), '%s / %s' % (exec_lines, missing_lines)
# currently, we do not trace nogil code lines, but that should eventually be implemented
if __name__ == '__main__':
run_coverage(coverage_test_nogil)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment