xo-arena: + DArena.expand utest
This commit is contained in:
parent
63a568f3a7
commit
49c0904a4a
4 changed files with 36 additions and 2 deletions
|
|
@ -6,7 +6,7 @@
|
|||
#include "xo/alloc2/Allocator.hpp"
|
||||
#include "xo/alloc2/alloc/IAllocator_Xfer.hpp"
|
||||
#include "xo/alloc2/arena/IAllocator_DArena.hpp"
|
||||
#include "xo/alloc2/print.hpp"
|
||||
#include "xo/arena/print.hpp"
|
||||
#include "xo/arena/padding.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
|
|
|
|||
|
|
@ -105,6 +105,10 @@ namespace xo {
|
|||
* This is the amount of memory guaranteed to be usable for future allocs from this arena.
|
||||
**/
|
||||
size_type available() const noexcept { return limit_ - free_; }
|
||||
/** VM page size for this arena (likely 4KB) **/
|
||||
size_type page_z() const noexcept { return page_z_; }
|
||||
/** Last error encountered by this arena **/
|
||||
const AllocError & last_error() const noexcept { return last_error_; }
|
||||
|
||||
/** True iff address @p addr is owned by this arena,
|
||||
* i.e. falls within [@ref lo_, @ref hi_)
|
||||
|
|
|
|||
|
|
@ -3,12 +3,15 @@
|
|||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include "xo/arena/DArena.hpp"
|
||||
#include "DArena.hpp"
|
||||
#include "print.hpp"
|
||||
#include <xo/indentlog/print/tag.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::DArena;
|
||||
using xo::mm::ArenaConfig;
|
||||
using xo::xtag;
|
||||
using std::byte;
|
||||
|
||||
namespace ut {
|
||||
|
|
@ -98,6 +101,33 @@ namespace xo {
|
|||
REQUIRE(arena2.committed_z_ == committed_z);
|
||||
}
|
||||
|
||||
TEST_CASE("arena-expand-1", "[arena][DArena]")
|
||||
{
|
||||
/* typed allocator a1o */
|
||||
ArenaConfig cfg { .name_ = "testarena",
|
||||
.size_ = 1,
|
||||
.debug_flag_ = false };
|
||||
DArena arena = DArena::map(cfg);
|
||||
|
||||
REQUIRE(arena.available() == 0);
|
||||
REQUIRE(arena.allocated() == 0);
|
||||
|
||||
size_t z2 = 512;
|
||||
bool ok = arena.expand(z2);
|
||||
|
||||
INFO(xtag("last_error", arena.last_error()));
|
||||
|
||||
REQUIRE(ok);
|
||||
|
||||
REQUIRE(arena.reserved() % arena.page_z() == 0);
|
||||
REQUIRE(arena.committed() >= z2);
|
||||
REQUIRE(arena.committed() % arena.page_z() == 0);
|
||||
REQUIRE(arena.available() >= z2);
|
||||
REQUIRE(arena.available() == arena.committed());
|
||||
REQUIRE(arena.allocated() == 0);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue