###############################################################################
# valgrind suppression rules for conduit 
###############################################################################

###############################################################################
# valgrind suppression rules for conduit
#
# These rules were seeded from Python's valgrind suppression rules:
#  http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp
#
# Since several of our tests are testing compiled python modules.
###############################################################################
###############################################################################
# This is a valgrind suppression file that should be used when using valgrind.
#
#  Here's an example of running valgrind:
#
#	cd python/dist/src
#	valgrind --tool=memcheck --suppressions=Misc/valgrind-python.supp \
#		./python -E -tt ./Lib/test/regrtest.py -u bsddb,network
#
# You must edit Objects/obmalloc.c and uncomment Py_USING_MEMORY_DEBUGGER
# to use the preferred suppressions with Py_ADDRESS_IN_RANGE.
#
# If you do not want to recompile Python, you can uncomment
# suppressions for PyObject_Free and PyObject_Realloc.
#
# See Misc/README.valgrind for more information.

# all tool names: Addrcheck,Memcheck,cachegrind,helgrind,massif
{
   ADDRESS_IN_RANGE/Invalid read of size 4
   Memcheck:Addr4
   fun:Py_ADDRESS_IN_RANGE
}

{
   ADDRESS_IN_RANGE/Invalid read of size 4
   Memcheck:Value4
   fun:Py_ADDRESS_IN_RANGE
}

{
   ADDRESS_IN_RANGE/Invalid read of size 8 (x86_64 aka amd64)
   Memcheck:Value8
   fun:Py_ADDRESS_IN_RANGE
}

{
   ADDRESS_IN_RANGE/Conditional jump or move depends on uninitialised value
   Memcheck:Cond
   fun:Py_ADDRESS_IN_RANGE
}

#
# Leaks (including possible leaks)
#    Hmmm, I wonder if this masks some real leaks.  I think it does.
#    Will need to fix that.
#

{
   Suppress leaking the GIL.  Happens once per process, see comment in ceval.c.
   Memcheck:Leak
   fun:malloc
   fun:PyThread_allocate_lock
   fun:PyEval_InitThreads
}

{
   Suppress leaking the GIL after a fork.
   Memcheck:Leak
   fun:malloc
   fun:PyThread_allocate_lock
   fun:PyEval_ReInitThreads
}

{
   Suppress leaking the autoTLSkey.  This looks like it shouldn't leak though.
   Memcheck:Leak
   fun:malloc
   fun:PyThread_create_key
   fun:_PyGILState_Init
   fun:Py_InitializeEx
   fun:Py_Main
}

{
   Hmmm, is this a real leak or like the GIL?
   Memcheck:Leak
   fun:malloc
   fun:PyThread_ReInitTLS
}

{
   Handle PyMalloc confusing valgrind (possibly leaked)
   Memcheck:Leak
   fun:realloc
   fun:_PyObject_GC_Resize
   fun:COMMENT_THIS_LINE_TO_DISABLE_LEAK_WARNING
}

{
   Handle PyMalloc confusing valgrind (possibly leaked)
   Memcheck:Leak
   fun:malloc
   fun:_PyObject_GC_New
   fun:COMMENT_THIS_LINE_TO_DISABLE_LEAK_WARNING
}

{
   Handle PyMalloc confusing valgrind (possibly leaked)
   Memcheck:Leak
   fun:malloc
   fun:_PyObject_GC_NewVar
   fun:COMMENT_THIS_LINE_TO_DISABLE_LEAK_WARNING
}

######################################
# OSX  leaks
#

{
   mac os leak ignore 1
   Memcheck:Leak
   match-leak-kinds: possible
   fun:malloc_zone_malloc
   fun:_objc_copyClassNamesForImage
   fun:_ZL9protocolsv
   fun:_Z9readClassP10objc_classbb
   fun:gc_init
   fun:_ZL33objc_initializeClassPair_internalP10objc_classPKcS0_S0_
   fun:layout_string_create
   fun:_ZL12realizeClassP10objc_class
   fun:_ZL22copySwiftV1MangledNamePKcb
   fun:_ZL22copySwiftV1MangledNamePKcb
   fun:_ZL22copySwiftV1MangledNamePKcb
   fun:_ZL22copySwiftV1MangledNamePKcb
}
#
{
   mac os leak ignore 2
   Memcheck:Leak
   match-leak-kinds: possible
   fun:malloc_zone_calloc
   ...
   fun:environ_init
   fun:_os_object_init
}
#
{
   mac os leak ignore 3
   Memcheck:Leak
   match-leak-kinds: possible
   fun:malloc_zone_malloc
   ...
   fun:_hasObjcContents
   fun:__objc_personality_v0
}
#
{
   mac os leak ignore 4
   Memcheck:Leak
   match-leak-kinds: possible
   fun:malloc_zone_malloc
   ...
   fun:_dyld_objc_notify_register
   fun:environ_init
   fun:_os_object_init
   fun:libdispatch_init
}
#
{
    mac os leak ignore 5
   Memcheck:Leak
   match-leak-kinds: possible
   fun:malloc_zone_malloc
   fun:_ZN10objc_class14setHasCustomRREb
   fun:_ZL11addSubclassP10objc_classS0_
   fun:_ZNSt3__112__hash_tableINS_17__hash_value_typeImPN23objc_references_support20ObjectAssociationMapEEENS_22__unordered_map_hasherImS5_NS2_20DisguisedPointerHashELb1EEENS_21__unordered_map_equalImS5_NS2_21DisguisedPointerEqualELb1EEENS2_13ObjcAllocatorIS5_EEE8__rehashEm
   fun:_ZL18updateCustomRR_AWZP10objc_classP8method_t
   fun:_ZL9addMethodP10objc_classP13objc_selectorPFvvEPKcb
   fun:_ZL17realizeAllClassesv
   fun:_objc_flush_caches
   fun:_objc_flush_caches
   fun:_objc_flush_caches
   fun:_objc_flush_caches
   fun:_read_images
}
#####################################
# end macos leaks
#####################################

#
# Non-python specific leaks
#

{
   Handle pthread issue (possibly leaked)
   Memcheck:Leak
   fun:calloc
   fun:allocate_dtv
   fun:_dl_allocate_tls_storage
   fun:_dl_allocate_tls
}

{
   Handle pthread issue (possibly leaked)
   Memcheck:Leak
   fun:memalign
   fun:_dl_allocate_tls_storage
   fun:_dl_allocate_tls
}

###{
###   ADDRESS_IN_RANGE/Invalid read of size 4
###   Memcheck:Addr4
###   fun:PyObject_Free
###}
###
###{
###   ADDRESS_IN_RANGE/Invalid read of size 4
###   Memcheck:Value4
###   fun:PyObject_Free
###}
###
###{
###   ADDRESS_IN_RANGE/Conditional jump or move depends on uninitialised value
###   Memcheck:Cond
###   fun:PyObject_Free
###}

###{
###   ADDRESS_IN_RANGE/Invalid read of size 4
###   Memcheck:Addr4
###   fun:PyObject_Realloc
###}
###
###{
###   ADDRESS_IN_RANGE/Invalid read of size 4
###   Memcheck:Value4
###   fun:PyObject_Realloc
###}
###
###{
###   ADDRESS_IN_RANGE/Conditional jump or move depends on uninitialised value
###   Memcheck:Cond
###   fun:PyObject_Realloc
###}

###
### All the suppressions below are for errors that occur within libraries
### that Python uses.  The problems to not appear to be related to Python's
### use of the libraries.
###

{
   Generic ubuntu ld problems
   Memcheck:Addr8
   obj:/lib/ld-2.4.so
   obj:/lib/ld-2.4.so
   obj:/lib/ld-2.4.so
   obj:/lib/ld-2.4.so
}

{
   Generic gentoo ld problems
   Memcheck:Cond
   obj:/lib/ld-2.3.4.so
   obj:/lib/ld-2.3.4.so
   obj:/lib/ld-2.3.4.so
   obj:/lib/ld-2.3.4.so
}

{
   DBM problems, see test_dbm
   Memcheck:Param
   write(buf)
   fun:write
   obj:/usr/lib/libdb1.so.2
   obj:/usr/lib/libdb1.so.2
   obj:/usr/lib/libdb1.so.2
   obj:/usr/lib/libdb1.so.2
   fun:dbm_close
}

{
   DBM problems, see test_dbm
   Memcheck:Value8
   fun:memmove
   obj:/usr/lib/libdb1.so.2
   obj:/usr/lib/libdb1.so.2
   obj:/usr/lib/libdb1.so.2
   obj:/usr/lib/libdb1.so.2
   fun:dbm_store
   fun:dbm_ass_sub
}

{
   DBM problems, see test_dbm
   Memcheck:Cond
   obj:/usr/lib/libdb1.so.2
   obj:/usr/lib/libdb1.so.2
   obj:/usr/lib/libdb1.so.2
   fun:dbm_store
   fun:dbm_ass_sub
}

{
   DBM problems, see test_dbm
   Memcheck:Cond
   fun:memmove
   obj:/usr/lib/libdb1.so.2
   obj:/usr/lib/libdb1.so.2
   obj:/usr/lib/libdb1.so.2
   obj:/usr/lib/libdb1.so.2
   fun:dbm_store
   fun:dbm_ass_sub
}

{
   GDBM problems, see test_gdbm
   Memcheck:Param
   write(buf)
   fun:write
   fun:gdbm_open

}

{
   ZLIB problems, see test_gzip
   Memcheck:Cond
   obj:/lib/libz.so.1.2.3
   obj:/lib/libz.so.1.2.3
   fun:deflate
}

{
   Avoid problems w/readline doing a putenv and leaking on exit
   Memcheck:Leak
   fun:malloc
   fun:xmalloc
   fun:sh_set_lines_and_columns
   fun:_rl_get_screen_size
   fun:_rl_init_terminal_io
   obj:/lib/libreadline.so.4.3
   fun:rl_initialize
}

###
### These occur from somewhere within the SSL, when running
###  test_socket_sll.  They are too general to leave on by default.
###
###{
###   somewhere in SSL stuff
###   Memcheck:Cond
###   fun:memset
###}
###{
###   somewhere in SSL stuff
###   Memcheck:Value4
###   fun:memset
###}
###
###{
###   somewhere in SSL stuff
###   Memcheck:Cond
###   fun:MD5_Update
###}
###
###{
###   somewhere in SSL stuff
###   Memcheck:Value4
###   fun:MD5_Update
###}

#
# All of these problems come from using test_socket_ssl
#
{
   from test_socket_ssl
   Memcheck:Cond
   fun:BN_bin2bn
}

{
   from test_socket_ssl
   Memcheck:Cond
   fun:BN_num_bits_word
}

{
   from test_socket_ssl
   Memcheck:Value4
   fun:BN_num_bits_word
}

{
   from test_socket_ssl
   Memcheck:Cond
   fun:BN_mod_exp_mont_word
}

{
   from test_socket_ssl
   Memcheck:Cond
   fun:BN_mod_exp_mont
}

{
   from test_socket_ssl
   Memcheck:Param
   write(buf)
   fun:write
   obj:/usr/lib/libcrypto.so.0.9.7
}

{
   from test_socket_ssl
   Memcheck:Cond
   fun:RSA_verify
}

{
   from test_socket_ssl
   Memcheck:Value4
   fun:RSA_verify
}

{
   from test_socket_ssl
   Memcheck:Value4
   fun:DES_set_key_unchecked
}

{
   from test_socket_ssl
   Memcheck:Value4
   fun:DES_encrypt2
}

{
   from test_socket_ssl
   Memcheck:Cond
   obj:/usr/lib/libssl.so.0.9.7
}

{
   from test_socket_ssl
   Memcheck:Value4
   obj:/usr/lib/libssl.so.0.9.7
}

{
   from test_socket_ssl
   Memcheck:Cond
   fun:BUF_MEM_grow_clean
}

{
   from test_socket_ssl
   Memcheck:Cond
   fun:memcpy
   fun:ssl3_read_bytes
}

{
   from test_socket_ssl
   Memcheck:Cond
   fun:SHA1_Update
}

{
   from test_socket_ssl
   Memcheck:Value4
   fun:SHA1_Update
}

###############################################################################
# valgrind suppressions for bash
###############################################################################
# Adapted from:
# https://www.redhat.com/archives/libvir-list/2008-April/msg00375.html
# 
# conduit's mpi tests may use bash, leading to thousands of errors related to 
# bash
###############################################################################


{
   BashLeak_A
   Memcheck:Leak
   fun:*alloc
   ...
   fun:reader_loop
   fun:main
}

{
   BashLeak_B
   Memcheck:Leak
   fun:*alloc
   ...
   fun:parse_and_execute
   fun:command_substitute
}

{
   BashLeak_C
   Memcheck:Leak
   fun:*alloc
   ...
   fun:reader_loop
   fun:main
}

{
   BashLeak_D
   Memcheck:Leak
   fun:*alloc
   ...
   fun:execute_command_internal
   fun:execute_command
}

{
   BashLeak_E
   Memcheck:Leak
   fun:mallocv
   ...
   fun:execute_command
}

{
   BashLeak_F
   Memcheck:Leak
   fun:*alloc
   fun:set_default_locale
   fun:main
}

{
   BashLeak_G
   Memcheck:Leak
   fun:*alloc
   fun:set_locale_var
   fun:set_default_lang
   fun:main
}

{
   BashLeak_H
   Memcheck:Leak
   fun:*alloc
   ...
   obj:/bin/bash
   fun:execute_command_internal
}


{
   BashLeak_I
   Memcheck:Leak
   fun:*alloc
   ...
   obj:/bin/bash
   fun:execute_command_internal
   fun:execute_command
}

{
   BashAlloc_J
   Memcheck:Leak
   fun:*alloc
   ...
   obj:/bin/bash
   fun:main
}

{
   BashAlloc_K
   Memcheck:Leak
   fun:*alloc
   ...
   obj:/bin/bash
}

{
   MacoOS_LauncherLeak
   Memcheck:Leak
   fun:calloc
   fun:map_images_nolock
   ...
   fun:libSystem_initializer
}


