Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests with ASan #17

Open
damb opened this issue Jan 14, 2021 · 3 comments
Open

Run tests with ASan #17

damb opened this issue Jan 14, 2021 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed tests Unit and integration test related topics

Comments

@damb
Copy link
Collaborator

damb commented Jan 14, 2021

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 damb added enhancement New feature or request help wanted Extra attention is needed labels Jan 14, 2021
@damb
Copy link
Collaborator Author

damb commented Jan 14, 2021

References #16.

@damb
Copy link
Collaborator Author

damb commented Jan 14, 2021

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.

  • gcc version:
$ g++ --version
g++ (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  • boost version:
libboost_unit_test_framework.so.1.69.0
  • OS:
uname -a
Linux seiscomp-fedora32 5.4.72-gentoo #1 SMP Mon Oct 19 16:07:57 CEST 2020 x86_64 x86_64 x86_64 GNU/Linux`

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

@damb
Copy link
Collaborator Author

damb commented Jan 14, 2021

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

@damb damb added the tests Unit and integration test related topics label Jan 13, 2022
damb pushed a commit that referenced this issue Apr 21, 2022
Note that this is a regression (see #17).
damb pushed a commit that referenced this issue May 9, 2022
Note that this is a regression (see #17).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed tests Unit and integration test related topics
Projects
None yet
Development

No branches or pull requests

1 participant