Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 8c3636f

Browse files
committed
tests: move num_allocs to common
1 parent ff6f2c6 commit 8c3636f

7 files changed

Lines changed: 49 additions & 47 deletions

File tree

tests/common/unittest.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2-
/* Copyright 2018-2020, Intel Corporation */
2+
/* Copyright 2018-2021, Intel Corporation */
33

44
#ifndef LIBPMEMOBJ_CPP_UNITTEST_HPP
55
#define LIBPMEMOBJ_CPP_UNITTEST_HPP
@@ -19,6 +19,9 @@
1919
#include <sys/types.h>
2020
#include <type_traits>
2121

22+
#include <libpmemobj++/pool.hpp>
23+
#include <libpmemobj/iterator_base.h>
24+
2225
#ifndef _WIN32
2326
#define os_stat_t struct stat
2427
#define os_stat stat
@@ -192,4 +195,19 @@ run_test(std::function<void()> test)
192195
return 0;
193196
}
194197

198+
/* Returns number of objects allocated via pmemobj */
199+
static inline int
200+
num_allocs(pmem::obj::pool_base &pop)
201+
{
202+
auto oid = pmemobj_first(pop.handle());
203+
int num = 0;
204+
205+
while (!OID_IS_NULL(oid)) {
206+
num++;
207+
oid = pmemobj_next(oid);
208+
}
209+
210+
return num;
211+
}
212+
195213
#endif /* LIBPMEMOBJ_CPP_UNITTEST_HPP */

tests/concurrent_map_mt_gdb/concurrent_map_mt_gdb.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2-
/* Copyright 2020, Intel Corporation */
2+
/* Copyright 2020-2021, Intel Corporation */
33

44
/*
55
* concurrent_map.cpp -- pmem::obj::concurrent_map test
@@ -21,8 +21,6 @@
2121
#include <libpmemobj++/container/string.hpp>
2222
#include <libpmemobj++/experimental/concurrent_map.hpp>
2323

24-
#include <libpmemobj.h>
25-
2624
#define LAYOUT "concurrent_map"
2725

2826
namespace nvobj = pmem::obj;
@@ -83,20 +81,6 @@ gdb_sync_exit()
8381
static int loop_sync_1 = 1;
8482
static int loop_sync_2 = 1;
8583

86-
int
87-
num_allocs(nvobj::pool<root> &pop)
88-
{
89-
auto oid = pmemobj_first(pop.handle());
90-
int num = 0;
91-
92-
while (!OID_IS_NULL(oid)) {
93-
num++;
94-
oid = pmemobj_next(oid);
95-
}
96-
97-
return num;
98-
}
99-
10084
struct test_case {
10185
virtual void
10286
insert(nvobj::pool<root> &pop,

tests/external/libcxx/basic_string/string.cons/copy.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ run(pmem::obj::pool<root> &pop)
130130
} catch (std::exception &e) {
131131
UT_FATALexc(e);
132132
}
133-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
133+
UT_ASSERTeq(num_allocs(pop), 0);
134134
}
135135

136136
void

tests/radix_tree/radix_basic.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2-
/* Copyright 2020, Intel Corporation */
2+
/* Copyright 2020-2021, Intel Corporation */
33

44
#include "radix.hpp"
55

@@ -118,7 +118,7 @@ test_iterators(nvobj::pool<root> &pop)
118118
nvobj::delete_persistent<container_int>(r->radix_int);
119119
});
120120

121-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
121+
UT_ASSERTeq(num_allocs(pop), 0);
122122
}
123123

124124
void
@@ -261,7 +261,7 @@ test_find(nvobj::pool<root> &pop)
261261
r->radix_str);
262262
});
263263

264-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
264+
UT_ASSERTeq(num_allocs(pop), 0);
265265
}
266266

267267
{
@@ -297,7 +297,7 @@ test_find(nvobj::pool<root> &pop)
297297
r->radix_str);
298298
});
299299

300-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
300+
UT_ASSERTeq(num_allocs(pop), 0);
301301
}
302302

303303
{
@@ -397,7 +397,7 @@ test_find(nvobj::pool<root> &pop)
397397
r->radix_str);
398398
});
399399

400-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
400+
UT_ASSERTeq(num_allocs(pop), 0);
401401
}
402402
}
403403

@@ -531,7 +531,7 @@ test_compression(nvobj::pool<root> &pop)
531531
nvobj::delete_persistent<container_string>(r->radix_str);
532532
});
533533

534-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
534+
UT_ASSERTeq(num_allocs(pop), 0);
535535
}
536536

537537
/* Tests some corner cases (not covered by libcxx erase tests). */
@@ -587,7 +587,7 @@ test_erase(nvobj::pool<root> &pop)
587587
nvobj::delete_persistent<container_string>(r->radix_str);
588588
});
589589

590-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
590+
UT_ASSERTeq(num_allocs(pop), 0);
591591
}
592592

593593
/* This test inserts elements in range [0:2:2 * numeric_limits<uint16_t>::max()]
@@ -647,7 +647,7 @@ test_binary_keys(nvobj::pool<root> &pop)
647647

648648
its = {};
649649

650-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
650+
UT_ASSERTeq(num_allocs(pop), 0);
651651

652652
nvobj::transaction::run(pop, [&] {
653653
r->radix_int_int = nvobj::make_persistent<container_int_int>();
@@ -687,7 +687,7 @@ test_binary_keys(nvobj::pool<root> &pop)
687687
nvobj::delete_persistent<container_int_int>(r->radix_int_int);
688688
});
689689

690-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
690+
UT_ASSERTeq(num_allocs(pop), 0);
691691
}
692692

693693
void
@@ -763,7 +763,7 @@ test_pre_post_fixes(nvobj::pool<root> &pop)
763763
nvobj::delete_persistent<container_string>(r->radix_str);
764764
});
765765

766-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
766+
UT_ASSERTeq(num_allocs(pop), 0);
767767
}
768768

769769
void
@@ -791,7 +791,7 @@ test_assign_inline_string(nvobj::pool<root> &pop)
791791
nvobj::delete_persistent<container_string>(r->radix_str);
792792
});
793793

794-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
794+
UT_ASSERTeq(num_allocs(pop), 0);
795795
}
796796

797797
void
@@ -844,7 +844,7 @@ test_inline_string_u8t_key(nvobj::pool<root> &pop)
844844
r->radix_inline_s_u8t);
845845
});
846846

847-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
847+
UT_ASSERTeq(num_allocs(pop), 0);
848848
}
849849

850850
void
@@ -932,7 +932,7 @@ test_remove_inserted(nvobj::pool<root> &pop)
932932
nvobj::delete_persistent<container_string>(r->radix_str);
933933
});
934934

935-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
935+
UT_ASSERTeq(num_allocs(pop), 0);
936936
}
937937

938938
static void

tests/radix_tree/radix_large.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2-
/* Copyright 2020, Intel Corporation */
2+
/* Copyright 2020-2021, Intel Corporation */
33

44
#include "unittest.hpp"
55

@@ -59,7 +59,7 @@ test_long_string(nvobj::pool<root> &pop)
5959
nvobj::delete_persistent<nvobj::string>(r->str);
6060
});
6161

62-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
62+
UT_ASSERTeq(num_allocs(pop), 0);
6363
}
6464

6565
static void

tests/radix_tree/radix_tx_abort.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2-
/* Copyright 2020, Intel Corporation */
2+
/* Copyright 2020-2021, Intel Corporation */
33

44
#include "radix.hpp"
55

@@ -43,7 +43,7 @@ test_emplace(nvobj::pool<root> &pop, nvobj::persistent_ptr<Container> &ptr)
4343
nvobj::transaction::run(
4444
pop, [&] { nvobj::delete_persistent<Container>(ptr); });
4545

46-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
46+
UT_ASSERTeq(num_allocs(pop), 0);
4747
}
4848

4949
template <typename Container, int ValueRepeats>
@@ -87,7 +87,7 @@ test_try_emplace(nvobj::pool<root> &pop, nvobj::persistent_ptr<Container> &ptr)
8787
nvobj::transaction::run(
8888
pop, [&] { nvobj::delete_persistent<Container>(ptr); });
8989

90-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
90+
UT_ASSERTeq(num_allocs(pop), 0);
9191
}
9292

9393
template <typename Container, int ValueRepeats>
@@ -152,7 +152,7 @@ test_insert_or_assign(nvobj::pool<root> &pop,
152152
nvobj::transaction::run(
153153
pop, [&] { nvobj::delete_persistent<Container>(ptr); });
154154

155-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
155+
UT_ASSERTeq(num_allocs(pop), 0);
156156
}
157157

158158
template <typename Container, int ValueRepeats>
@@ -199,7 +199,7 @@ test_insert(nvobj::pool<root> &pop, nvobj::persistent_ptr<Container> &ptr)
199199
nvobj::transaction::run(
200200
pop, [&] { nvobj::delete_persistent<Container>(ptr); });
201201

202-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
202+
UT_ASSERTeq(num_allocs(pop), 0);
203203
}
204204

205205
template <typename Container, int ValueRepeats>
@@ -266,7 +266,7 @@ test_assign(nvobj::pool<root> &pop, nvobj::persistent_ptr<Container> &ptr)
266266
nvobj::transaction::run(
267267
pop, [&] { nvobj::delete_persistent<Container>(ptr); });
268268

269-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
269+
UT_ASSERTeq(num_allocs(pop), 0);
270270
}
271271

272272
template <typename Container, int ValueRepeats>
@@ -334,7 +334,7 @@ test_assign_internal_leaf(nvobj::pool<root> &pop,
334334
nvobj::transaction::run(
335335
pop, [&] { nvobj::delete_persistent<Container>(ptr); });
336336

337-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
337+
UT_ASSERTeq(num_allocs(pop), 0);
338338
}
339339

340340
template <typename Container, int ValueRepeats>
@@ -377,7 +377,7 @@ test_assign_root(nvobj::pool<root> &pop, nvobj::persistent_ptr<Container> &ptr)
377377
nvobj::transaction::run(
378378
pop, [&] { nvobj::delete_persistent<Container>(ptr); });
379379

380-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
380+
UT_ASSERTeq(num_allocs(pop), 0);
381381
}
382382

383383
template <typename Container, int ValueRepeats>
@@ -422,7 +422,7 @@ test_erase(nvobj::pool<root> &pop, nvobj::persistent_ptr<Container> &ptr)
422422
nvobj::transaction::run(
423423
pop, [&] { nvobj::delete_persistent<Container>(ptr); });
424424

425-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
425+
UT_ASSERTeq(num_allocs(pop), 0);
426426
}
427427

428428
template <typename Container, int ValueRepeats>
@@ -463,7 +463,7 @@ test_erase_internal(nvobj::pool<root> &pop,
463463
nvobj::transaction::run(
464464
pop, [&] { nvobj::delete_persistent<Container>(ptr); });
465465

466-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
466+
UT_ASSERTeq(num_allocs(pop), 0);
467467
}
468468
}
469469

tests/string/string_modifiers.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2-
/* Copyright 2019-2020, Intel Corporation */
2+
/* Copyright 2019-2021, Intel Corporation */
33

44
#include "unittest.hpp"
55

@@ -429,7 +429,7 @@ check_tx_abort(pmem::obj::pool<struct root> &pop, const char *str,
429429
nvobj::delete_persistent<S>(r->str);
430430
nvobj::delete_persistent<S>(r->str2);
431431
});
432-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
432+
UT_ASSERTeq(num_allocs(pop), 0);
433433
}
434434

435435
static void
@@ -462,7 +462,7 @@ test(int argc, char *argv[])
462462
"0123456789012345678901234567890123456789"
463463
"0123456789",
464464
true);
465-
UT_ASSERT(OID_IS_NULL(pmemobj_first(pop.handle())));
465+
UT_ASSERTeq(num_allocs(pop), 0);
466466
pop.close();
467467
}
468468

0 commit comments

Comments
 (0)