From f5ece13b1c7cd67ef9853da7c798f063d08baeb3 Mon Sep 17 00:00:00 2001 From: Merlin Mathesius Date: Wed, 5 Feb 2020 16:09:34 -0600 Subject: [PATCH] WIP: add support for valgrind suppressions file when running under python --- contrib/valgrind/libmodulemd-python.supp | 80 ++++++++++++++++++++++++ modulemd/meson.build | 4 ++ modulemd/tests/test-valgrind.py | 24 ++++--- 3 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 contrib/valgrind/libmodulemd-python.supp diff --git a/contrib/valgrind/libmodulemd-python.supp b/contrib/valgrind/libmodulemd-python.supp new file mode 100644 index 000000000..626a97867 --- /dev/null +++ b/contrib/valgrind/libmodulemd-python.supp @@ -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 +} diff --git a/modulemd/meson.build b/modulemd/meson.build index ff96ad1fd..7e7e5b76a 100644 --- a/modulemd/meson.build +++ b/modulemd/meson.build @@ -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 diff --git a/modulemd/tests/test-valgrind.py b/modulemd/tests/test-valgrind.py index db2bf2a27..cbd5f24a6 100644 --- a/modulemd/tests/test-valgrind.py +++ b/modulemd/tests/test-valgrind.py @@ -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 @@ -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( [ @@ -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() @@ -83,21 +92,21 @@ 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( @@ -105,11 +114,12 @@ def exec_valgrind(test): % 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)