|
| 1 | +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
| 2 | +// vim: ts=8 sw=2 smarttab |
| 3 | + |
| 4 | +#include <fmt/format.h> |
| 5 | + |
| 6 | +#include "common/ceph_argparse.h" |
| 7 | +#include "common/ceph_context.h" |
| 8 | +#include "global/global_context.h" |
| 9 | +#include "global/global_init.h" |
| 10 | + |
| 11 | +#include "include/ceph_assert.h" |
| 12 | + |
| 13 | +#include "gtest/gtest.h" |
| 14 | + |
| 15 | +static void non_supressed_assert_line16() { |
| 16 | + ceph_assert(42 == 41); // LINE16 |
| 17 | +} |
| 18 | +static void supressed_assert_line19() { |
| 19 | + ceph_assert(42 == 40); // LINE19 |
| 20 | +} |
| 21 | +static void supressed_assertf_line22() { |
| 22 | + ceph_assertf(42 == 39, "FAILED ceph_assertf"); // LINE22 |
| 23 | +} |
| 24 | +static void non_supressed_assertf_line25() { |
| 25 | + ceph_assertf(42 == 38, "FAILED ceph_assertf"); // LINE25 |
| 26 | +} |
| 27 | + |
| 28 | +TEST(CephAssertDeathTest, ceph_assert_supresssions) { |
| 29 | + ASSERT_DEATH(non_supressed_assert_line16(), "FAILED ceph_assert"); |
| 30 | + supressed_assert_line19(); |
| 31 | + supressed_assertf_line22(); |
| 32 | + ASSERT_DEATH(non_supressed_assertf_line25(), "FAILED ceph_assertf"); |
| 33 | +} |
| 34 | + |
| 35 | +int main(int argc, char **argv) { |
| 36 | + |
| 37 | + auto args = argv_to_vec(argc, argv); |
| 38 | + auto cct = global_init( |
| 39 | + nullptr, |
| 40 | + args, |
| 41 | + CEPH_ENTITY_TYPE_CLIENT, |
| 42 | + CODE_ENVIRONMENT_UTILITY, |
| 43 | + CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); |
| 44 | + g_ceph_context->_conf.set_val( |
| 45 | + "ceph_assert_supresssions", |
| 46 | + fmt::format( |
| 47 | + "{}:{}, {}:{}", __FILE__, /* LINE19 */19, __FILE__, /* LINE22 */22)); |
| 48 | + common_init_finish(g_ceph_context); |
| 49 | + testing::InitGoogleTest(&argc, argv); |
| 50 | + return RUN_ALL_TESTS(); |
| 51 | +} |
0 commit comments