From: Radoslaw Zarzynski Date: Wed, 12 Mar 2025 22:41:45 +0000 (+0000) Subject: test: add unit test for bypassing abort in ceph_assert X-Git-Tag: v20.3.0~189^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bfa83df6d33ee2238f1389ca4518592b5c4fb267;p=ceph.git test: add unit test for bypassing abort in ceph_assert Fixes: https://tracker.ceph.com/issues/70476 Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 4d2779403331..76e93052df7d 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1023,3 +1023,11 @@ add_executable(test_nvmeof_mon_encoding target_link_libraries(test_nvmeof_mon_encoding mon ceph-common global-static ) + +if(NOT WIN32) +# unittest_ceph_assert +add_executable(unittest_ceph_assert + ceph_assert.cc) +add_ceph_unittest(unittest_ceph_assert) +target_link_libraries(unittest_ceph_assert ceph-common global) +endif() diff --git a/src/test/ceph_assert.cc b/src/test/ceph_assert.cc new file mode 100644 index 000000000000..63d3c3f0f176 --- /dev/null +++ b/src/test/ceph_assert.cc @@ -0,0 +1,51 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include + +#include "common/ceph_argparse.h" +#include "common/ceph_context.h" +#include "global/global_context.h" +#include "global/global_init.h" + +#include "include/ceph_assert.h" + +#include "gtest/gtest.h" + +static void non_supressed_assert_line16() { + ceph_assert(42 == 41); // LINE16 +} +static void supressed_assert_line19() { + ceph_assert(42 == 40); // LINE19 +} +static void supressed_assertf_line22() { + ceph_assertf(42 == 39, "FAILED ceph_assertf"); // LINE22 +} +static void non_supressed_assertf_line25() { + ceph_assertf(42 == 38, "FAILED ceph_assertf"); // LINE25 +} + +TEST(CephAssertDeathTest, ceph_assert_supresssions) { + ASSERT_DEATH(non_supressed_assert_line16(), "FAILED ceph_assert"); + supressed_assert_line19(); + supressed_assertf_line22(); + ASSERT_DEATH(non_supressed_assertf_line25(), "FAILED ceph_assertf"); +} + +int main(int argc, char **argv) { + + auto args = argv_to_vec(argc, argv); + auto cct = global_init( + nullptr, + args, + CEPH_ENTITY_TYPE_CLIENT, + CODE_ENVIRONMENT_UTILITY, + CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); + g_ceph_context->_conf.set_val( + "ceph_assert_supresssions", + fmt::format( + "{}:{}, {}:{}", __FILE__, /* LINE19 */19, __FILE__, /* LINE22 */22)); + common_init_finish(g_ceph_context); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}