xo-gc stack: coverage improvement + related tidying
This commit is contained in:
parent
9b84ef8a7f
commit
42e09dd21e
8 changed files with 130 additions and 47 deletions
|
|
@ -6,6 +6,7 @@ set(UTEST_SRCS
|
|||
alloc2_utest_main.cpp
|
||||
objectmodel.test.cpp
|
||||
arena.test.cpp
|
||||
IAllocator_Any.test.cpp
|
||||
DArenaIterator.test.cpp
|
||||
# Collector.test.cpp
|
||||
# DX1CollectorIterator.test.cpp
|
||||
|
|
|
|||
29
utest/IAllocator_Any.test.cpp
Normal file
29
utest/IAllocator_Any.test.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/** @file IAllocator_Any.test.cpp
|
||||
*
|
||||
* @author Roland Conybeare, May 2026
|
||||
**/
|
||||
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AAllocator;
|
||||
|
||||
namespace ut {
|
||||
|
||||
TEST_CASE("IAllocator_Any", "[alloc2][death]")
|
||||
{
|
||||
// null allocator
|
||||
obj<AAllocator> alloc_any;
|
||||
|
||||
// NOTE: tried using a fork() strategy to verify termination,
|
||||
// but child process doesn't get measured by gcov
|
||||
}
|
||||
|
||||
} /*namespace ut*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IAllocator_Any.test.cpp */
|
||||
|
|
@ -97,6 +97,8 @@ namespace xo {
|
|||
//obj<AAllocator, DArena> a1o{&arena};
|
||||
auto a1o = with_facet<AAllocator>::mkobj(&arena);
|
||||
|
||||
REQUIRE(!a1o._has_null_vptr());
|
||||
|
||||
REQUIRE(a1o);
|
||||
REQUIRE(a1o.iface() != nullptr);
|
||||
REQUIRE(a1o.data() != nullptr);
|
||||
|
|
@ -110,6 +112,12 @@ namespace xo {
|
|||
REQUIRE(a1o.size() == 0);
|
||||
REQUIRE(a1o.committed() == 0);
|
||||
REQUIRE(a1o.allocated() == 0);
|
||||
|
||||
a1o._drop();
|
||||
{
|
||||
REQUIRE(a1o.allocated() == 0);
|
||||
REQUIRE(a1o.committed() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("allocator-expand-1", "[alloc2][AAllocator]")
|
||||
|
|
@ -122,6 +130,8 @@ namespace xo {
|
|||
//obj<AAllocator, DArena> a1o{&arena};
|
||||
auto a1o = with_facet<AAllocator>::mkobj(&arena);
|
||||
|
||||
REQUIRE(!a1o._has_null_vptr());
|
||||
|
||||
REQUIRE(a1o.available() == 0);
|
||||
REQUIRE(a1o.allocated() == 0);
|
||||
|
||||
|
|
@ -141,6 +151,11 @@ namespace xo {
|
|||
REQUIRE(a1o.available() == a1o.committed());
|
||||
REQUIRE(a1o.allocated() == 0);
|
||||
|
||||
a1o._drop();
|
||||
{
|
||||
REQUIRE(a1o.allocated() == 0);
|
||||
REQUIRE(a1o.committed() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("allocator-alloc-1", "[alloc2][AAllocator]")
|
||||
|
|
@ -152,6 +167,8 @@ namespace xo {
|
|||
DArena arena = DArena::map(cfg);
|
||||
auto a1o = with_facet<AAllocator>::mkobj(&arena);
|
||||
|
||||
REQUIRE(!a1o._has_null_vptr());
|
||||
|
||||
REQUIRE(a1o.reserved() >= cfg.size_);
|
||||
REQUIRE(a1o.committed() == 0);
|
||||
REQUIRE(a1o.available() == 0);
|
||||
|
|
@ -180,6 +197,12 @@ namespace xo {
|
|||
REQUIRE(a1o.allocated() <= a1o.committed());
|
||||
REQUIRE(a1o.allocated() + a1o.available() == a1o.committed());
|
||||
REQUIRE(a1o.committed() <= a1o.reserved());
|
||||
|
||||
a1o._drop();
|
||||
{
|
||||
REQUIRE(a1o.allocated() == 0);
|
||||
REQUIRE(a1o.committed() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("allocator-alloc-2", "[alloc2][Allocator]")
|
||||
|
|
@ -202,6 +225,8 @@ namespace xo {
|
|||
//obj<AAllocator, DArena> a1o{&arena};
|
||||
auto a1o = with_facet<AAllocator>::mkobj(&arena);
|
||||
|
||||
REQUIRE(!a1o._has_null_vptr());
|
||||
|
||||
REQUIRE(a1o.reserved() >= cfg.size_);
|
||||
REQUIRE(a1o.committed() == 0);
|
||||
REQUIRE(a1o.available() == 0);
|
||||
|
|
@ -244,19 +269,26 @@ namespace xo {
|
|||
}
|
||||
|
||||
a1o.clear();
|
||||
{
|
||||
// allocated size got reset
|
||||
REQUIRE(a1o.allocated() == 0);
|
||||
// committed size unchanged
|
||||
REQUIRE(a1o.committed() == committed0_z);
|
||||
REQUIRE(a1o.last_error().error_ == error::ok);
|
||||
REQUIRE(a1o.last_error().error_seq_ == 0);
|
||||
|
||||
// allocated size got reset
|
||||
REQUIRE(a1o.allocated() == 0);
|
||||
// committed size unchanged
|
||||
REQUIRE(a1o.committed() == committed0_z);
|
||||
REQUIRE(a1o.last_error().error_ == error::ok);
|
||||
REQUIRE(a1o.last_error().error_seq_ == 0);
|
||||
// allocator no longer contains m0 (now points to unallocated but committed memory
|
||||
// (not exposed via AAllocator!
|
||||
// REQUIRE(a1o.contains_allocated(m0) == false);
|
||||
|
||||
// allocator no longer contains m0 (now points to unallocated but committed memory
|
||||
// (not exposed via AAllocator!
|
||||
// REQUIRE(a1o.contains_allocated(m0) == false);
|
||||
REQUIRE(a1o.contains(m0));
|
||||
}
|
||||
|
||||
REQUIRE(a1o.contains(m0));
|
||||
a1o._drop();
|
||||
{
|
||||
REQUIRE(a1o.allocated() == 0);
|
||||
REQUIRE(a1o.committed() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("allocator-alloc-3", "[alloc2][Allocator]")
|
||||
|
|
@ -279,6 +311,8 @@ namespace xo {
|
|||
//obj<AAllocator, DArena> a1o{&arena};
|
||||
auto a1o = with_facet<AAllocator>::mkobj(&arena);
|
||||
|
||||
REQUIRE(!a1o._has_null_vptr());
|
||||
|
||||
REQUIRE(a1o.reserved() >= cfg.size_);
|
||||
REQUIRE(a1o.committed() == 0);
|
||||
REQUIRE(a1o.available() == 0);
|
||||
|
|
@ -301,23 +335,30 @@ namespace xo {
|
|||
header_type* header = (header_type*)(m0 - sizeof(header_type));
|
||||
size_t pad = padding::with_padding(z0) - z0;
|
||||
byte * guard1 = m0 + z0 + pad;
|
||||
{
|
||||
REQUIRE(a1o.contains(guard0));
|
||||
REQUIRE(a1o.contains(header));
|
||||
REQUIRE(cfg.header_.size(*header) == padding::with_padding(z0));
|
||||
//REQUIRE(((*header) & cfg.header_size_mask_) == padding::with_padding(z0));
|
||||
|
||||
REQUIRE(a1o.contains(guard0));
|
||||
REQUIRE(a1o.contains(header));
|
||||
REQUIRE(cfg.header_.size(*header) == padding::with_padding(z0));
|
||||
//REQUIRE(((*header) & cfg.header_size_mask_) == padding::with_padding(z0));
|
||||
REQUIRE(a1o.last_error().error_ == error::ok);
|
||||
REQUIRE(a1o.last_error().error_seq_ == 0);
|
||||
|
||||
REQUIRE(a1o.last_error().error_ == error::ok);
|
||||
REQUIRE(a1o.last_error().error_seq_ == 0);
|
||||
REQUIRE(a1o.allocated() == (cfg.header_.guard_z_
|
||||
+ sizeof(header_type)
|
||||
+ z0
|
||||
+ pad
|
||||
+ cfg.header_.guard_z_));
|
||||
REQUIRE(a1o.allocated() <= a1o.committed());
|
||||
REQUIRE(a1o.allocated() + a1o.available() == a1o.committed());
|
||||
REQUIRE(a1o.committed() <= a1o.reserved());
|
||||
}
|
||||
|
||||
REQUIRE(a1o.allocated() == (cfg.header_.guard_z_
|
||||
+ sizeof(header_type)
|
||||
+ z0
|
||||
+ pad
|
||||
+ cfg.header_.guard_z_));
|
||||
REQUIRE(a1o.allocated() <= a1o.committed());
|
||||
REQUIRE(a1o.allocated() + a1o.available() == a1o.committed());
|
||||
REQUIRE(a1o.committed() <= a1o.reserved());
|
||||
a1o._drop();
|
||||
{
|
||||
REQUIRE(a1o.allocated() == 0);
|
||||
REQUIRE(a1o.committed() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("allocator-fail-1", "[alloc2][AAllocator]")
|
||||
|
|
@ -332,6 +373,8 @@ namespace xo {
|
|||
|
||||
REQUIRE(cfg.size_ <= cfg.hugepage_z_);
|
||||
|
||||
REQUIRE(!a1o._has_null_vptr());
|
||||
|
||||
REQUIRE(a1o.reserved() >= cfg.size_);
|
||||
REQUIRE(a1o.committed() == 0);
|
||||
REQUIRE(a1o.available() == 0);
|
||||
|
|
@ -339,17 +382,22 @@ namespace xo {
|
|||
|
||||
size_t z0 = cfg.hugepage_z_ + 1;
|
||||
byte * m0 = a1o.alloc(typeseq::sentinel(), z0);
|
||||
|
||||
REQUIRE(!m0);
|
||||
|
||||
AllocError err = a1o.last_error();
|
||||
{
|
||||
REQUIRE(!m0);
|
||||
REQUIRE(err.error_ == error::reserve_exhausted);
|
||||
REQUIRE(err.error_seq_ == 1);
|
||||
REQUIRE(err.request_z_ >= z0);
|
||||
REQUIRE(err.request_z_ < z0 + padding::c_alloc_alignment);
|
||||
REQUIRE(err.committed_z_ == 0);
|
||||
REQUIRE(err.reserved_z_ == arena.reserved());
|
||||
}
|
||||
|
||||
REQUIRE(err.error_ == error::reserve_exhausted);
|
||||
REQUIRE(err.error_seq_ == 1);
|
||||
REQUIRE(err.request_z_ >= z0);
|
||||
REQUIRE(err.request_z_ < z0 + padding::c_alloc_alignment);
|
||||
REQUIRE(err.committed_z_ == 0);
|
||||
REQUIRE(err.reserved_z_ == arena.reserved());
|
||||
a1o._drop();
|
||||
{
|
||||
REQUIRE(a1o.allocated() == 0);
|
||||
REQUIRE(a1o.committed() == 0);
|
||||
}
|
||||
}
|
||||
} /*namespace ut*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue