scipy: Compiled code coverage with `--gcov` doesn't work with Meson

For how this is supposed to work, see the PR description of gh-3021. It works with python runtests.py --gcov, but doesn’t work with dev.py:

$ python dev.py --gcov
Removing previous GCOV .gcda files...
The Meson build system
Version: 0.62.0
Source dir: /home/rgommers/code/scipy
Build dir: /home/rgommers/code/scipy/build
Build type: native build
Project name: SciPy
Project version: 1.9.0.dev0

meson.build:1:0: ERROR: Executables created by c compiler /home/rgommers/anaconda3/envs/scipy-dev/bin/x86_64-conda-linux-gnu-cc --coverage are not runnable.

A full log can be found at /home/rgommers/code/scipy/build/meson-logs/meson-log.txt

I made no attempt to figure out why yet.

Full log:

$ cat build/meson-logs/meson-log.txt 
Build started at 2022-03-29T22:07:44.629711
Main binary: /home/rgommers/anaconda3/envs/scipy-dev/bin/python3.10
Build Options: -Dprefix=/home/rgommers/code/scipy/build-install
Python system: Linux
The Meson build system
Version: 0.62.0
Source dir: /home/rgommers/code/scipy
Build dir: /home/rgommers/code/scipy/build
Build type: native build
Project name: SciPy
Project version: 1.9.0.dev0
Sanity testing C compiler: /home/rgommers/anaconda3/envs/scipy-dev/bin/x86_64-conda-linux-gnu-cc --coverage
Is cross compiler: False.
Sanity check compiler command line: /home/rgommers/anaconda3/envs/scipy-dev/bin/x86_64-conda-linux-gnu-cc --coverage sanitycheckc.c -o sanitycheckc.exe -Wno-unused-function -Wno-conversion -Wno-misleading-indentation -Wno-incompatible-pointer-types -D_FILE_OFFSET_BITS=64 -pthread -B /home/rgommers/anaconda3/envs/scipy-dev/compiler_compat -shared -Wl,-rpath,/home/rgommers/anaconda3/envs/scipy-dev/lib -Wl,-rpath-link,/home/rgommers/anaconda3/envs/scipy-dev/lib -L/home/rgommers/anaconda3/envs/scipy-dev/lib -Wl,-rpath,/home/rgommers/anaconda3/envs/scipy-dev/lib -Wl,-rpath-link,/home/rgommers/anaconda3/envs/scipy-dev/lib -L/home/rgommers/anaconda3/envs/scipy-dev/lib --coverage
Sanity check compile stdout:

-----
Sanity check compile stderr:

-----
Running test binary command: /home/rgommers/code/scipy/build/meson-private/sanitycheckc.exe

meson.build:1:0: ERROR: Executables created by c compiler /home/rgommers/anaconda3/envs/scipy-dev/bin/x86_64-conda-linux-gnu-cc --coverage are not runnable.

@Smit-create is this something you could look at?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (17 by maintainers)

Commits related to this issue

Most upvoted comments

I’m fine with this only working with GCC, since that was the status quo before the move to Meson as well. Let’s make sure that that is reflected in the docs though, and that on macOS the user gets an informative error message rather than a confusing traceback.

then last two commands (out of the four which I mentioned in the beginning of this comment), should execute automatically. Right now I guess they don’t. May be that’s something which we should to close this issue

Yes please, that sounds like a useful thing to do. This should be as easy as possible, so test --coverage should prepare the coverage report and inform the developer how to open it ideally.

IIRC the issue is that clang specifically hates the idea of linking to internal utility libraries providing helper symbols for instrumentation, because it wants to statically link them (why?) and not inline them (interestinger and interestinger, though understandable) and as a result cannot provide them in multiple DSOs so it will only provide them for “main executables”. Which means when you build shared libraries (and that’s what a python extension is) you get outright load errors unless you also build cpython itself with instrumentation. Go figure.

Ok so, I executed the following commands in order as mentioned,

  1. python dev.py build --gcov
  2. python dev.py test --coverage
  3. lcov --capture --directory build --output-file coverage.info
  4. genhtml -q coverage.info --output-directory out --legend --highlight

It doesn’t work on macOS. I get the following error in step 2, i.e., python dev.py test --coverage command,

E   ImportError: dlopen(.../sparse/linalg/_eigen/arpack/_arpack.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '_llvm_gcda_emit_arcs'

More details:

.
.
.
ImportError while importing test module '/Users/czgdp1807/Quansight/scipy/build-install/lib/python3.12/site-packages/scipy/stats/tests/test_stats.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy/stats/__init__.py:617: in <module>
    from ._stats_py import *
scipy/stats/_stats_py.py:38: in <module>
    from scipy import sparse
scipy/__init__.py:136: in __getattr__
    return _importlib.import_module(f'scipy.{name}')
/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy/sparse/__init__.py:312: in <module>
    from . import csgraph
scipy/sparse/csgraph/__init__.py:187: in <module>
    from ._laplacian import laplacian
scipy/sparse/csgraph/_laplacian.py:7: in <module>
    from scipy.sparse.linalg import LinearOperator
scipy/sparse/linalg/__init__.py:132: in <module>
    from ._eigen import *
scipy/sparse/linalg/_eigen/__init__.py:9: in <module>
    from .arpack import *
scipy/sparse/linalg/_eigen/arpack/__init__.py:20: in <module>
    from .arpack import *
scipy/sparse/linalg/_eigen/arpack/arpack.py:50: in <module>
    from . import _arpack
E   ImportError: dlopen(/Users/czgdp1807/Quansight/scipy/build-install/lib/python3.12/site-packages/scipy/sparse/linalg/_eigen/arpack/_arpack.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '_llvm_gcda_emit_arcs'
________________ ERROR collecting build-install/lib/python3.12/site-packages/scipy/stats/tests/test_survival.py ________________
ImportError while importing test module '/Users/czgdp1807/Quansight/scipy/build-install/lib/python3.12/site-packages/scipy/stats/tests/test_survival.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy/stats/__init__.py:617: in <module>
    from ._stats_py import *
scipy/stats/_stats_py.py:38: in <module>
    from scipy import sparse
scipy/__init__.py:136: in __getattr__
    return _importlib.import_module(f'scipy.{name}')
/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy/sparse/__init__.py:312: in <module>
    from . import csgraph
scipy/sparse/csgraph/__init__.py:187: in <module>
    from ._laplacian import laplacian
scipy/sparse/csgraph/_laplacian.py:7: in <module>
    from scipy.sparse.linalg import LinearOperator
scipy/sparse/linalg/__init__.py:132: in <module>
    from ._eigen import *
scipy/sparse/linalg/_eigen/__init__.py:9: in <module>
    from .arpack import *
scipy/sparse/linalg/_eigen/arpack/__init__.py:20: in <module>
    from .arpack import *
scipy/sparse/linalg/_eigen/arpack/arpack.py:50: in <module>
    from . import _arpack
E   ImportError: dlopen(/Users/czgdp1807/Quansight/scipy/build-install/lib/python3.12/site-packages/scipy/sparse/linalg/_eigen/arpack/_arpack.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '_llvm_gcda_emit_arcs'
___________ ERROR collecting build-install/lib/python3.12/site-packages/scipy/stats/tests/test_tukeylambda_stats.py ____________
ImportError while importing test module '/Users/czgdp1807/Quansight/scipy/build-install/lib/python3.12/site-packages/scipy/stats/tests/test_tukeylambda_stats.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy/stats/__init__.py:617: in <module>
    from ._stats_py import *
scipy/stats/_stats_py.py:38: in <module>
    from scipy import sparse
scipy/__init__.py:136: in __getattr__
    return _importlib.import_module(f'scipy.{name}')
/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy/sparse/__init__.py:312: in <module>
    from . import csgraph
scipy/sparse/csgraph/__init__.py:187: in <module>
    from ._laplacian import laplacian
scipy/sparse/csgraph/_laplacian.py:7: in <module>
    from scipy.sparse.linalg import LinearOperator
scipy/sparse/linalg/__init__.py:132: in <module>
    from ._eigen import *
scipy/sparse/linalg/_eigen/__init__.py:9: in <module>
    from .arpack import *
scipy/sparse/linalg/_eigen/arpack/__init__.py:20: in <module>
    from .arpack import *
scipy/sparse/linalg/_eigen/arpack/arpack.py:50: in <module>
    from . import _arpack
E   ImportError: dlopen(/Users/czgdp1807/Quansight/scipy/build-install/lib/python3.12/site-packages/scipy/sparse/linalg/_eigen/arpack/_arpack.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '_llvm_gcda_emit_arcs'
_______________ ERROR collecting build-install/lib/python3.12/site-packages/scipy/stats/tests/test_variation.py ________________
ImportError while importing test module '/Users/czgdp1807/Quansight/scipy/build-install/lib/python3.12/site-packages/scipy/stats/tests/test_variation.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy/stats/__init__.py:617: in <module>
    from ._stats_py import *
scipy/stats/_stats_py.py:38: in <module>
    from scipy import sparse
scipy/__init__.py:136: in __getattr__
    return _importlib.import_module(f'scipy.{name}')
/Users/czgdp1807/mambaforge/envs/scipy-dev/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
scipy/sparse/__init__.py:312: in <module>
    from . import csgraph
scipy/sparse/csgraph/__init__.py:187: in <module>
    from ._laplacian import laplacian
scipy/sparse/csgraph/_laplacian.py:7: in <module>
    from scipy.sparse.linalg import LinearOperator
scipy/sparse/linalg/__init__.py:132: in <module>
    from ._eigen import *
scipy/sparse/linalg/_eigen/__init__.py:9: in <module>
    from .arpack import *
scipy/sparse/linalg/_eigen/arpack/__init__.py:20: in <module>
    from .arpack import *
scipy/sparse/linalg/_eigen/arpack/arpack.py:50: in <module>
    from . import _arpack
E   ImportError: dlopen(/Users/czgdp1807/Quansight/scipy/build-install/lib/python3.12/site-packages/scipy/sparse/linalg/_eigen/arpack/_arpack.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '_llvm_gcda_emit_arcs'
.
.
.

On Linux both of these command work, and gcda files are generated,

(scipy-dev) czgdp18079@scipy-linux-9:~/Quansight/scipy$ python
Python 3.12.6 | packaged by conda-forge | (main, Sep 22 2024, 14:16:49) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> gcda_files = list(Path(".").rglob("*.gcda"))
>>> len(gcda_files)
841
>>> gcda_files[0:2]
[PosixPath('build/scipy/libdummy_g77_abi_wrappers.a.p/_build_utils_src_wrap_dummy_g77_abi.c.gcda'), PosixPath('build/scipy/lib_fortranobject.a.p/f98a5737d97829eed02255ad2e9ce27f72e97b78_site-packages_numpy_f2py_src_fortranobject.c.gcda')]

On Linux it works. Here’s the output (some screenshots). It shows the coverage C/C++ code. You can check the full output at https://github.com/czgdp1807/scipy-lcov-genhtml-coverage-output and explore further.

Screenshot 2024-11-19 at 8 37 48 PM Screenshot 2024-11-19 at 8 38 23 PM Screenshot 2024-11-19 at 8 38 46 PM

Here’s what I noticed somethings,

  1. HTML outputs for coverage reports of Python files (this goes into build/coverage) and C/C++ code (for this it goes into the directory specified in --output-directory option of genhtml) go into different directories. We can provide build/coverage in --output-directory option of genhtml. However, I think it would be better to merge the two outputs so that a user can see everything under the same HTML page they load locally. Something for later.
  2. I think when --coverage option is provided in python dev.py test, then last two commands (out of the four which I mentioned in the beginning of this comment), should execute automatically. Right now I guess they don’t. May be that’s something which we should to close this issue? Am I making sense here?

So that’s all for now. cc: @rgommers