From 39c8d3693a9bb830252d38f91db192fd4a28666d Mon Sep 17 00:00:00 2001 From: Scott Snyder <scott.snyder@cern.ch> Date: Tue, 29 Nov 2016 16:20:25 +0100 Subject: [PATCH] A couple missing #includes in leakcheck.h. (TestTools-00-07-45) * Tagging TestTools-00-07-45. 2016-11-26 scott snyder <snyder@bnl.gov> * Tagging TestTools-00-07-44. * leakcheck.h: (new) Very simple leak checker. 2016-11-14 scott snyder <snyder@bnl.gov> * Tagging TestTools-00-07-43. * Ignore ubsan warning from regex.h. 2016-10-27 scott snyder <snyder@bnl.gov> * Tagging TestTools-00-07-42. * share/post.sh: Ignore more messages coming from change in gaudi versions. 2016-08-30 scott snyder <snyder@bnl.gov> ... (Long ChangeLog diff - truncated) Former-commit-id: e25995e2f17e9135d18a05df33822900e2a2654a --- .../TestTools/TestTools/expect_exception.h | 2 +- AtlasTest/TestTools/TestTools/leakcheck.h | 99 +++++++++++++++++++ AtlasTest/TestTools/share/post.sh | 8 +- 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 AtlasTest/TestTools/TestTools/leakcheck.h diff --git a/AtlasTest/TestTools/TestTools/expect_exception.h b/AtlasTest/TestTools/TestTools/expect_exception.h index afdcc68056d..dc92614fa87 100644 --- a/AtlasTest/TestTools/TestTools/expect_exception.h +++ b/AtlasTest/TestTools/TestTools/expect_exception.h @@ -27,7 +27,7 @@ * EXPECT_EXCEPTION (std::runtime_error, doSomething()); @endcode * - * This will produce an exception failure if @c doSomething() + * This will produce an assertion failure if @c doSomething() * does _not_ throw a @c std::runtime_error exception. */ #define EXPECT_EXCEPTION(EXC, CODE) do { \ diff --git a/AtlasTest/TestTools/TestTools/leakcheck.h b/AtlasTest/TestTools/TestTools/leakcheck.h new file mode 100644 index 00000000000..8d41b3a72c2 --- /dev/null +++ b/AtlasTest/TestTools/TestTools/leakcheck.h @@ -0,0 +1,99 @@ +// This file's extension implies that it's C, but it's really -*- C++ -*-. + +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// $Id$ +/** + * @file TestTools/leakcheck.h + * @author scott snyder <snyder@bnl.gov> + * @date Nov, 2016 + * @brief Pitifully simple leak checker for unit tests. + * Just verifies that allocations/deallocations + * match over an RAII region. + * + * Overrides the standard new/delete functions, so should not be + * #included from any code that would be included in a library. + */ + + +#ifndef TESTTOOLS_LEAKCHECK_H +#define TESTTOOLS_LEAKCHECK_H + + +#include <malloc.h> +#include <unordered_set> +#include <iostream> +#include <cassert> + + +namespace Athena_test { +std::unordered_set<void*>* allocs = nullptr; +struct LeakCheckDisable +{ + LeakCheckDisable() : m_allocs(allocs) { allocs = nullptr; } + ~LeakCheckDisable() { allocs = m_allocs; } + void insert(void* p) { if (m_allocs) m_allocs->insert(p); } + void erase(void* p) { if (m_allocs) m_allocs->erase(p); } + std::unordered_set<void*>* m_allocs; +}; +} // namespace Athena_test + + +void* operator new(std::size_t size) +{ + void* ptr = malloc(size); + if (Athena_test::allocs) { + Athena_test::LeakCheckDisable disable; + disable.insert (ptr); + } + return ptr; +} +void operator delete (void* ptr) noexcept +{ + if (Athena_test::allocs) { + Athena_test::LeakCheckDisable disable; + disable.erase (ptr); + } + free(ptr); +} +void operator delete (void* ptr, size_t) noexcept +{ + if (Athena_test::allocs) { + Athena_test::LeakCheckDisable disable; + disable.erase (ptr); + } + free(ptr); +} + + +namespace Athena_test { + + +struct Leakcheck +{ + Leakcheck() : m_old_allocs (allocs) { allocs = &m_allocs; } + ~Leakcheck(); + std::unordered_set<void*>* m_old_allocs; + std::unordered_set<void*> m_allocs; +}; + + +// Not inline; this file should NOT be included in any library. +Leakcheck::~Leakcheck() +{ + allocs = m_old_allocs; + if (!m_allocs.empty()) { + std::cerr << "Leaks!\n"; + for (void* p : m_allocs) + std::cerr << " " << p << "\n"; + assert (m_allocs.empty()); + } +} + + +} // namespace Athena_test + + +#endif // not TESTTOOLS_LEAKCHECK_H diff --git a/AtlasTest/TestTools/share/post.sh b/AtlasTest/TestTools/share/post.sh index 6e3c6117021..de0adf8be4c 100755 --- a/AtlasTest/TestTools/share/post.sh +++ b/AtlasTest/TestTools/share/post.sh @@ -143,11 +143,17 @@ PP="$PP"'|^ConditionStore +INFO Start ConditionStore' PP="$PP"'|^ConditionStore +INFO Stop ConditionStore' # Differences between Gaudi versions. -PP="$PP"'|DEBUG input handles:|DEBUG output handles:|DEBUG Data Deps for|DEBUG Property update for OutputLevel :|-ExtraInputs |-ExtraOutputs |-Cardinality |-IsClonable |-NeededResources |-Timeline ' +PP="$PP"'|DEBUG input handles:|DEBUG output handles:|DEBUG Data Deps for|DEBUG Property update for OutputLevel :|-ExtraInputs |-ExtraOutputs |-Cardinality |-IsClonable |-NeededResources |-Timeline |Service base class initialized successfully' # StoreGate INFO messages changed to VERBOSE PP="$PP"'|^(StoreGateSvc|[^ ]+Store) +(INFO|VERBOSE) (Stop|stop|Start)' +# Transient frontier warnings. +PP="$PP"'|^warn .fn-' + +# ubsan +PP="$PP"'|bits/regex.h:1545' + if [ "$extrapatterns" != "" ]; then PP="$PP""|$extrapatterns" -- GitLab