swiss-seismological-service / scdetect

A computationally efficient earthquake detection module for SeisComP
https://scdetect.readthedocs.io
GNU Affero General Public License v3.0
15 stars 6 forks source link

Run tests with ASan #17

Open damb opened 3 years ago

damb commented 3 years ago

In order to detect memory issues as early as possible, it would be good to enable AddressSanitizer when running unittests. The error detector comes with both gcc and clang builtin, anyway.

damb commented 3 years ago

References #16.

damb commented 3 years ago

Interestingly, Boost.Test seems to leak memory with ASan enabled. Here, the reproducer:

#define BOOST_TEST_MODULE test_foo
#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_CASE(test_foo) {
  BOOST_TEST_MESSAGE("Boost version: " << BOOST_VERSION);

  BOOST_TEST_CHECK(true);
}

which returns

Running 1 test case...
Boost version: 106900

*** No errors detected

=================================================================
==1301184==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 102 byte(s) in 5 object(s) allocated from:
    #0 0x7f16c3693067 in operator new(unsigned long) (/lib64/libasan.so.6+0xb2067)
    #1 0x7f16c359102f  (/lib64/libboost_unit_test_framework.so.1.69.0+0x5202f)

SUMMARY: AddressSanitizer: 102 byte(s) leaked in 5 allocation(s).

when compiled and linked with

-fsanitize=address

and run, afterwards. Of course, this can be suppressed with a corresponding LSan suppression file:

$ cat LSan.supp 
leak:libboost_unit_test_framework.so.*

However, this is rather a work around.

Note that the test binary is both compiled and run from within a Fedora32 LCX container image on a gentoo host.

damb commented 3 years ago

It turns out that Valgrind's Memcheck utility detects the issue, too.