]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test: add unit test for bypassing abort in ceph_assert
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Wed, 12 Mar 2025 22:41:45 +0000 (22:41 +0000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 18 Mar 2025 20:46:51 +0000 (20:46 +0000)
Fixes: https://tracker.ceph.com/issues/70476
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/test/CMakeLists.txt
src/test/ceph_assert.cc [new file with mode: 0644]

index 4d27794033317dbd1c9ce859f32dcb0d3b3e2d22..76e93052df7dac3243b4c9b3e72b168484cbc8d7 100644 (file)
@@ -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 (file)
index 0000000..63d3c3f
--- /dev/null
@@ -0,0 +1,51 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include <fmt/format.h>
+
+#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();
+}