Skip to content

Commit 25f310e

Browse files
authored
Merge pull request ceph#62496 from aainscow/interval_set_reenable_assert
test/osd: Adapt strategy for testing asserts in interval_sets
2 parents 800825e + d700506 commit 25f310e

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/include/interval_set.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525

2626
#include "encoding.h"
2727

28+
/* strict_mode_assert is a standard ceph_assert() in product code. Some tests
29+
* (specifically test_interval_set.cc) can override this macro with an
30+
* exception.
31+
*/
32+
#ifndef strict_mode_assert
33+
#define strict_mode_assert(expr) ceph_assert(expr)
34+
#endif
35+
2836
/*
2937
* *** NOTE ***
3038
*
@@ -362,7 +370,7 @@ class interval_set {
362370

363371
auto start = std::max<T>(ps->first, pl->first);
364372
auto en = std::min<T>(ps->first + ps->second, offset);
365-
ceph_assert(en > start);
373+
strict_mode_assert(en > start);
366374
mi = m.emplace_hint(mi, start, en - start);
367375
_size += mi->second;
368376
if (ps->first + ps->second <= offset) {
@@ -556,7 +564,7 @@ class interval_set {
556564

557565
if (p->first + p->second != start) {
558566
//cout << "p is " << p->first << "~" << p->second << ", start is " << start << ", len is " << len << endl;
559-
ceph_abort();
567+
strict_mode_assert(false);
560568
}
561569

562570
p->second += len; // append to end
@@ -572,7 +580,7 @@ class interval_set {
572580
*plen = p->second;
573581
m.erase(n);
574582
} else {
575-
ceph_assert(n == m.end() || start + len < n->first);
583+
strict_mode_assert(n == m.end() || start + len < n->first);
576584
if (plen)
577585
*plen = p->second;
578586
}
@@ -586,7 +594,7 @@ class interval_set {
586594
m.erase(p);
587595
m[start] = len + psecond; // append to front
588596
} else {
589-
ceph_assert(p->first > start+len);
597+
strict_mode_assert(p->first > start+len);
590598
if (pstart)
591599
*pstart = start;
592600
if (plen)
@@ -677,11 +685,11 @@ class interval_set {
677685

678686
_size -= len;
679687

680-
ceph_assert(p != m.end());
681-
ceph_assert(p->first <= start);
688+
strict_mode_assert(p != m.end());
689+
strict_mode_assert(p->first <= start);
682690

683691
T before = start - p->first;
684-
ceph_assert(p->second >= before+len);
692+
strict_mode_assert(p->second >= before+len);
685693
T after = p->second - before - len;
686694
if (before) {
687695
if (claim && claim(p->first, before)) {
@@ -999,4 +1007,5 @@ struct denc_traits<interval_set<T, C>> {
9991007
template<typename T, template<typename, typename, typename ...> class C, bool strict>
10001008
struct fmt::is_range<interval_set<T, C, strict>, char> : std::false_type {};
10011009

1010+
#undef strict_mode_assert
10021011
#endif

src/test/common/test_interval_set.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
#include <gtest/gtest.h>
1818
#include <boost/container/flat_map.hpp>
1919

20+
/* This will override the strict_assert macro in interval set, but leave
21+
* all product-asserts as ceph_assert. These asserts are used when strict mode
22+
* is on to police some important restrictions.
23+
*/
24+
#define strict_mode_assert(expr) \
25+
do { \
26+
((expr)) \
27+
? _CEPH_ASSERT_VOID_CAST (0) : throw std::exception(); \
28+
} while (false)
29+
2030
#include "include/interval_set.h"
2131
#include "include/btree_map.h"
2232

@@ -26,10 +36,7 @@ using namespace ceph;
2636
* if (interval set has strict=true) expect that ceph will panic.
2737
* else expect that ceph will not panic and execute the second clause.
2838
*/
29-
// FIXME: The CI pipeline cannot cope with the core dumps that ASSERT_DEATH
30-
// creates, so we need to find a better approach. Disabling to unblock.
31-
//#define ASSERT_STRICT_DEATH(s, e) if constexpr (ISet::test_strict) ASSERT_DEATH(s, ""); else { s; e; }
32-
#define ASSERT_STRICT_DEATH(s, e) if constexpr (ISet::test_strict) GTEST_SKIP(); else { s; e; }
39+
#define ASSERT_STRICT_DEATH(s, e) if constexpr (ISet::test_strict) EXPECT_THROW(s, std::exception); else { s; e; }
3340

3441
typedef uint64_t IntervalValueType;
3542

0 commit comments

Comments
 (0)