xo-arena: + DArena.expand utest
This commit is contained in:
parent
b5b83dcf1f
commit
d7491bfe8e
3 changed files with 69 additions and 1 deletions
|
|
@ -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_)
|
||||
|
|
|
|||
34
include/xo/arena/print.hpp
Normal file
34
include/xo/arena/print.hpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/** @file print.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AllocError.hpp"
|
||||
#include <xo/indentlog/print/tag.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
inline std::ostream &
|
||||
operator<<(std::ostream & os, const error & x) {
|
||||
os << AllocError::error_description(x);
|
||||
return os;
|
||||
}
|
||||
|
||||
inline std::ostream &
|
||||
operator<<(std::ostream & os, const AllocError & x) {
|
||||
os << "<AllocError"
|
||||
<< xtag("error", x.error_)
|
||||
<< xtag("seq", x.error_seq_)
|
||||
<< xtag("req_z", x.request_z_)
|
||||
<< xtag("commit_z", x.committed_z_)
|
||||
<< xtag("resv_z", x.reserved_z_)
|
||||
<< ">";
|
||||
return os;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* end print.hpp */
|
||||
|
|
@ -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