rscada / python-mbus

Python wrapper for libmbus
BSD 3-Clause "New" or "Revised" License
25 stars 28 forks source link

segfault calling python-mbus #10

Open sjlongland opened 8 years ago

sjlongland commented 8 years ago

Just running the tests that come with python-mbus causes the Python interpreter to segfault.

libmbus is git head as of this morning, tried both with commit https://github.com/vrtsystems/libmbus/commit/716d71231470cde0f5697fa173f305548bba69f2 and https://github.com/vrtsystems/libmbus/commit/ef6c4be655c9ad1e4faa627f3f7eeb061eff4e96. libmbus itself appears to work judging from the test/example programs it comes with, so it looks to be something funny with python-mbus.

RC=0 stuartl@rikishi /tmp/python-mbus $ py.test 
======================================================================== test session starts ========================================================================
platform linux2 -- Python 2.7.7 -- py-1.4.30 -- pytest-2.7.2
rootdir: /tmp/python-mbus, inifile: pytest.ini
plugins: cov
collected 16 items 

tests/test_MBus_connect.py Segmentation fault

Changes to python-mbus:

diff --git a/mbus/MBus.py b/mbus/MBus.py
index 7f26165..671a18f 100644
--- a/mbus/MBus.py
+++ b/mbus/MBus.py
@@ -60,7 +60,7 @@ class MBus:
                 raise TypeError("port number not given as integer")

         if None == libpath:
-            libpath = "/usr/local/lib/libmbus.so"
+            libpath = "/usr/local/lib64/libmbus.so"

         self._libmbus = cdll.LoadLibrary(libpath)

diff --git a/pytest.ini b/pytest.ini
index f84356a..0cd849c 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -1,8 +1,8 @@
 [pytest]
-addopts = --pep8 --cov-config .coveragerc --cov . tests/
+addopts = --cov-config .coveragerc --cov . tests/

-serialdevice = /dev/adjustme
+serialdevice = /dev/ttyS0
 ;serialdevice = /dev/ttyUSB0

 markers =
-       serial: mark a test to be run with serial device attached
\ No newline at end of file
+       serial: mark a test to be run with serial device attached
sjlongland commented 8 years ago

Managed to get a sort-of backtrace. gdb doesn't want to give me the Python backtrace but it seems to come acroppa when it tries to connect:

(gdb) run
Starting program: /usr/bin/python /usr/bin/py.test
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
process 26210 is executing new program: /usr/bin/python2.7
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
======================================================================== test session starts ========================================================================
platform linux2 -- Python 2.7.7 -- py-1.4.30 -- pytest-2.7.2
rootdir: /tmp/python-mbus, inifile: pytest.ini
plugins: cov
collected 16 items 

tests/test_MBus_connect.py 
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff1a71be1 in mbus_connect (handle=0x5598fc80) at mbus-protocol-aux.c:1589
1589        return handle->open(handle);
(gdb) 
sjlongland commented 8 years ago

Further research suggests it might be this bug: https://bugs.python.org/issue11835

I'll try a Python update and see what happens.

sjlongland commented 8 years ago

Okay, after Python update, same thing. I think this might be a bug in the Python package.

RC=0 stuartl@rikishi ~/vrt/projects/metermaster/deps/python-mbus $ gdb --args /usr/bin/python /usr/bin/py.test 
GNU gdb (Gentoo 7.7.1 p1) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/bin/python...(no debugging symbols found)...done.
(gdb) r
Starting program: /usr/bin/python /usr/bin/py.test
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
process 5971 is executing new program: /usr/bin/python2.7
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
======================================================================== test session starts ========================================================================
platform linux2 -- Python 2.7.10 -- py-1.4.30 -- pytest-2.7.2
rootdir: /home/stuartl/vrt/projects/metermaster/deps/python-mbus, inifile: pytest.ini
plugins: cov
collected 16 items 

tests/test_MBus_connect.py 
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff19f5be1 in mbus_connect (handle=0x573e00a0) at mbus-protocol-aux.c:1589
1589    mbus-protocol-aux.c: No such file or directory.