Skip to content

Commit

Permalink
Add a test for LSan
Browse files Browse the repository at this point in the history
v2: fix type check
Signed-off-by: Azat Khuzhin <[email protected]>
  • Loading branch information
azat committed Jul 18, 2022
1 parent b4eae94 commit 51e7c41
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Common/tests/gtest_lsan.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <base/defines.h> // ADDRESS_SANITIZER

#ifdef ADDRESS_SANITIZER

#include <cstdlib>
#include <thread>

#include <gtest/gtest.h>
#include <sanitizer/lsan_interface.h>

/// Test that ensures that LSan works.
///
/// Regression test for the case when it may not work,
/// because of broken getauxval() [1].
///
/// [1]: https://github.com/ClickHouse/ClickHouse/pull/33957
TEST(Common, LSan)
{
int sanitizers_exit_code = 1;

ASSERT_EXIT({
std::thread leak_in_thread([]()
{
void * leak = malloc(4096);
ASSERT_NE(leak, nullptr);
});
leak_in_thread.join();

__lsan_do_leak_check();
}, ::testing::ExitedWithCode(sanitizers_exit_code), ".*LeakSanitizer: detected memory leaks.*");
}

#endif

0 comments on commit 51e7c41

Please sign in to comment.