Skip to content

Commit

Permalink
WIP: add support for valgrind suppressions file when running under py…
Browse files Browse the repository at this point in the history
…thon
  • Loading branch information
mmathesius committed Feb 5, 2020
1 parent 4d616ce commit f5ece13
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 7 deletions.
80 changes: 80 additions & 0 deletions contrib/valgrind/libmodulemd-python.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# libmodulemd valgrind suppressions file
#
# This provides a list of suppressions for libmodulemd for valgrind for
# the false positives that are reported when running under valgrind.
#
# Pass this suppression file to valgrind using --suppressions=/path/to/this-file.supp
#
# See http://valgrind.org/docs/manual/manual-core.html#manual-core.suppress
# for details about the format of this file.
#
# Also see https://wiki.wxwidgets.org/Parse_valgrind_suppressions.sh for a
# handy script to extract suppression entries from the valgrind test log.
#
{
Handle PyMalloc confusing valgrind
Memcheck:Leak
fun:malloc
...
fun:_PyObject_GC_New
}
{
Handle PyMalloc confusing valgrind
Memcheck:Leak
fun:malloc
...
fun:_PyObject_GC_NewVar
}
{
Handle PyMalloc confusing valgrind
Memcheck:Leak
fun:realloc
...
fun:_PyObject_GC_Resize
}
{
Handle PyMalloc confusing valgrind
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:_PyMem_RawWcsdup
obj:/usr/lib64/libpython3.7m.so.1.0
fun:_Py_InitializeCore
obj:/usr/lib64/libpython3.7m.so.1.0
obj:/usr/lib64/libpython3.7m.so.1.0
fun:_Py_UnixMain
fun:(below main)
}
{
Handle PyMalloc confusing valgrind
Memcheck:Cond
fun:PyUnicode_Decode
fun:PyUnicode_FromEncodedObject
obj:/usr/lib64/libpython3.7m.so.1.0
fun:_PyObject_FastCallKeywords
obj:/usr/lib64/libpython3.7m.so.1.0
fun:_PyEval_EvalFrameDefault
fun:_PyFunction_FastCallDict
fun:_PyObject_Call_Prepend
obj:/usr/lib64/libpython3.7m.so.1.0
fun:_PyObject_FastCallKeywords
obj:/usr/lib64/libpython3.7m.so.1.0
fun:_PyEval_EvalFrameDefault
}
{
Handle PyMalloc confusing valgrind
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:g_malloc
fun:g_strdup
obj:/usr/lib64/python3.7/site-packages/gi/_gi.cpython-37m-x86_64-linux-gnu.so
obj:/usr/lib64/python3.7/site-packages/gi/_gi.cpython-37m-x86_64-linux-gnu.so
obj:/usr/lib64/python3.7/site-packages/gi/_gi.cpython-37m-x86_64-linux-gnu.so
obj:/usr/lib64/python3.7/site-packages/gi/_gi.cpython-37m-x86_64-linux-gnu.so
obj:/usr/lib64/python3.7/site-packages/gi/_gi.cpython-37m-x86_64-linux-gnu.so
fun:PyObject_SetAttr
fun:_PyEval_EvalFrameDefault
fun:_PyFunction_FastCallKeywords
obj:/usr/lib64/libpython3.7m.so.1.0
}
4 changes: 4 additions & 0 deletions modulemd/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,16 @@ foreach name, script : python_tests
env : py_test_release_env,
args : files(script))

valgrind_tests += name + '_python3_debug'

test (name + '_python2_debug', python2,
env : py_test_env,
args : files(script))
test (name + '_python2_release', python2,
env : py_test_release_env,
args : files(script))

valgrind_tests += name + '_python2_debug'
endforeach


Expand Down
24 changes: 17 additions & 7 deletions modulemd/tests/test-valgrind.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
if os.getenv("MMD_SKIP_VALGRIND"):
sys.exit(77)

supp_file = os.path.join(
os.getenv("MESON_SOURCE_ROOT", "."),
"contrib",
"valgrind",
"libmodulemd-python.supp",
)

failed = False

Expand All @@ -41,8 +47,9 @@ def exec_valgrind(test):
"/usr/bin/valgrind "
"--leak-check=full "
"--suppressions=/usr/share/glib-2.0/valgrind/glib.supp "
"--suppressions=%s "
"--xml=yes "
"--xml-file=%s/%s.xml " % (tmpdirname, test)
"--xml-file=%s/%s.xml " % (supp_file, tmpdirname, test)
)
proc_result = subprocess.run(
[
Expand Down Expand Up @@ -70,6 +77,8 @@ def exec_valgrind(test):
failed = True
continue

test_failed = False

# Process the XML for leaks
tree = ET.parse("%s/%s.xml" % (tmpdirname, test))
root = tree.getroot()
Expand All @@ -83,33 +92,34 @@ def exec_valgrind(test):
"Memory leak detected in %s" % test,
file=sys.stderr,
)
failed = True
test_failed = True

elif error_child.text == "InvalidFree":
print(
"Invalid free() detected in %s" % test,
file=sys.stderr,
)
failed = True
test_failed = True

elif error_child.text == "InvalidRead":
print(
"Invalid read detected in %s" % test,
file=sys.stderr,
)
failed = True
test_failed = True

elif error_child.text == "UninitCondition":
print(
"Uninitialized usage detected in %s"
% test,
file=sys.stderr,
)
failed = True
if failed:
test_failed = True

if test_failed:
with open("%s/%s.xml" % (tmpdirname, test), "r") as xml:
print(xml.read())

failed = True

if failed:
sys.exit(1)

0 comments on commit f5ece13

Please sign in to comment.