From 79b9f0c918e2c6cbe14f1450f1342feb0227f902 Mon Sep 17 00:00:00 2001
From: Andrea Shepard <andrea@persephoneslair.org>
Date: Mon, 8 May 2017 09:56:04 +0000
Subject: [PATCH] Add valgrind test suite script and leak suppressions for
 gtest

---
 testing/leak-check.sh               | 22 ++++++++++++++++
 testing/valgrind/valgrind-glib.supp | 40 +++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)
 create mode 100755 testing/leak-check.sh
 create mode 100644 testing/valgrind/valgrind-glib.supp

diff --git a/testing/leak-check.sh b/testing/leak-check.sh
new file mode 100755
index 00000000..b3f2d250
--- /dev/null
+++ b/testing/leak-check.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+#
+# Script to run valgrind against the test suite for hunting memory leaks
+#
+# This assumes you run it in the Hammer base directory and have a debug build
+
+HAMMER_ROOT=.
+VARIANT=debug
+BUILD_PATH=$HAMMER_ROOT/build/$VARIANT
+LD_LIBRARY_PATH=$BUILD_PATH/src:$LD_LIBRARY_PATH
+VALGRIND=valgrind
+VALGRIND_OPTS="-v --leak-check=full --leak-resolution=high --num-callers=40 --partial-loads-ok=no --show-leak-kinds=all --track-origins=yes --undef-value-errors=yes"
+VALGRIND_SUPPRESSIONS="valgrind-glib.supp"
+
+for s in $VALGRIND_SUPPRESSIONS
+do
+  VALGRIND_OPTS="$VALGRIND_OPTS --suppressions=$HAMMER_ROOT/testing/valgrind/$s"
+done
+
+export LD_LIBRARY_PATH
+
+$VALGRIND $VALGRIND_OPTS $BUILD_PATH/src/test_suite $@
diff --git a/testing/valgrind/valgrind-glib.supp b/testing/valgrind/valgrind-glib.supp
new file mode 100644
index 00000000..9b35108f
--- /dev/null
+++ b/testing/valgrind/valgrind-glib.supp
@@ -0,0 +1,40 @@
+{
+   <g_test_add_vtable_supp>
+   Memcheck:Leak
+   match-leak-kinds: reachable
+   ...
+   fun:g_malloc
+   ...
+   fun:g_test_add_vtable
+   ...
+}
+{
+   <g_test_init_malloc_supp>
+   Memcheck:Leak
+   match-leak-kinds: reachable
+   fun:malloc
+   ...
+   fun:g_test_init
+   ...
+}
+{
+   <g_test_init_calloc_supp>
+   Memcheck:Leak
+   match-leak-kinds: reachable
+   fun:calloc
+   ...
+   fun:g_test_init
+   ...
+}
+{
+   <g_rand_new_with_seed_array_supp>
+   Memcheck:Leak
+   match-leak-kinds: reachable
+   fun:calloc
+   fun:g_malloc0
+   fun:g_rand_new_with_seed_array
+   ...
+   fun:g_test_run_suite
+   fun:g_test_run
+   ...
+}
-- 
GitLab