fix(sanitizers): Set stack size to 64 KB during tests for Sanitizers (#4454)

* fix(rdb_test): Fix sanitizers for RdbTest

Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>

* Revert "fix(rdb_test): Fix sanitizers for RdbTest"

This reverts commit 39ae4cf9958c517e70c666caee5a7fdd6beeba0d.

* feat: Add default fiber stack size

Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>

* fix: Increase default stack size

Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>

* fix: Specify default stack size for sanitizers

Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>

* fix: Add SANITIZERS to dfly_test_lib

Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>

---------

Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>
This commit is contained in:
Stepan Bagritsevich 2025-01-16 10:00:42 +01:00 committed by GitHub
parent 0e116b1535
commit 99f52642c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 8 deletions

View file

@ -98,6 +98,9 @@ endif()
add_library(dfly_test_lib test_utils.cc) add_library(dfly_test_lib test_utils.cc)
cxx_link(dfly_test_lib dragonfly_lib facade_test gtest_main_ext) cxx_link(dfly_test_lib dragonfly_lib facade_test gtest_main_ext)
if (WITH_ASAN OR WITH_USAN)
target_compile_definitions(dfly_test_lib PRIVATE SANITIZERS)
endif()
cxx_test(dragonfly_test dfly_test_lib LABELS DFLY) cxx_test(dragonfly_test dfly_test_lib LABELS DFLY)
cxx_test(multi_test dfly_test_lib LABELS DFLY) cxx_test(multi_test dfly_test_lib LABELS DFLY)

View file

@ -42,14 +42,6 @@ class RdbTest : public BaseFamilyTest {
protected: protected:
void SetUp(); void SetUp();
static void SetUpTestSuite() {
static bool init = true;
if (exchange(init, false)) {
fb2::SetDefaultStackResource(&fb2::std_malloc_resource, 32_KB);
}
BaseFamilyTest::SetUpTestSuite();
}
io::FileSource GetSource(string name); io::FileSource GetSource(string name);
std::error_code LoadRdb(const string& filename) { std::error_code LoadRdb(const string& filename) {

View file

@ -34,6 +34,23 @@ ABSL_FLAG(bool, force_epoll, false, "If true, uses epoll api instead iouring to
ABSL_DECLARE_FLAG(uint32_t, acllog_max_len); ABSL_DECLARE_FLAG(uint32_t, acllog_max_len);
namespace dfly { namespace dfly {
namespace {
// Default stack size for fibers. We decrease it by 16 bytes because some allocators
// need additional 8-16 bytes for their internal structures, thus over reserving additional
// memory pages if using round sizes.
#ifdef NDEBUG
constexpr size_t kFiberDefaultStackSize = 32_KB - 16;
#elif defined SANITIZERS
// Increase stack size for sanitizers builds.
constexpr size_t kFiberDefaultStackSize = 64_KB - 16;
#else
// Increase stack size for debug builds.
constexpr size_t kFiberDefaultStackSize = 50_KB - 16;
#endif
} // namespace
std::ostream& operator<<(std::ostream& os, const DbStats& stats) { std::ostream& operator<<(std::ostream& os, const DbStats& stats) {
os << "keycount: " << stats.key_count << ", tiered_size: " << stats.tiered_used_bytes os << "keycount: " << stats.key_count << ", tiered_size: " << stats.tiered_used_bytes
<< ", tiered_entries: " << stats.tiered_entries << "\n"; << ", tiered_entries: " << stats.tiered_entries << "\n";
@ -168,6 +185,12 @@ void BaseFamilyTest::SetUpTestSuite() {
absl::SetFlag(&FLAGS_rss_oom_deny_ratio, -1); absl::SetFlag(&FLAGS_rss_oom_deny_ratio, -1);
absl::SetFlag(&FLAGS_dbfilename, ""); absl::SetFlag(&FLAGS_dbfilename, "");
static bool init = true;
if (exchange(init, false)) {
fb2::SetDefaultStackResource(&fb2::std_malloc_resource, kFiberDefaultStackSize);
}
init_zmalloc_threadlocal(mi_heap_get_backing()); init_zmalloc_threadlocal(mi_heap_get_backing());
// TODO: go over all env variables starting with FLAGS_ and make sure they are in the below list. // TODO: go over all env variables starting with FLAGS_ and make sure they are in the below list.