117 lines
3.8 KiB
C++
117 lines
3.8 KiB
C++
/** @file X1Collector.test.cpp
|
|
*
|
|
* @author Roland Conybeare, Dec 2025
|
|
**/
|
|
|
|
#include <xo/gc/Collector.hpp>
|
|
#include <xo/gc/DX1Collector.hpp>
|
|
#include <catch2/catch.hpp>
|
|
|
|
namespace ut {
|
|
using xo::mm::DX1Collector;
|
|
using xo::mm::DArena;
|
|
using xo::mm::CollectorConfig;
|
|
using xo::mm::ArenaConfig;
|
|
using xo::mm::generation;
|
|
using xo::mm::role;
|
|
|
|
namespace {
|
|
struct testcase_x1 {
|
|
testcase_x1(std::size_t nz,
|
|
std::size_t tz,
|
|
std::size_t n_gct,
|
|
std::size_t t_gct)
|
|
: nursery_z_{nz},
|
|
tenured_z_{tz},
|
|
incr_gc_threshold_{n_gct},
|
|
full_gc_threshold_{t_gct} {}
|
|
|
|
std::size_t nursery_z_;
|
|
std::size_t tenured_z_;
|
|
std::size_t incr_gc_threshold_;
|
|
std::size_t full_gc_threshold_;
|
|
};
|
|
|
|
std::vector<testcase_x1>
|
|
s_testcase_v = {
|
|
// n_gct: nursery gc threshold
|
|
// t_gct: tenured gc threshold
|
|
//
|
|
// nz tz n_gct t_gct
|
|
testcase_x1(4096, 8192, 1024, 1024)
|
|
};
|
|
}
|
|
|
|
TEST_CASE("x1", "[gc][x1]")
|
|
{
|
|
for (std::size_t i_tc = 0, n_tc = s_testcase_v.size(); i_tc < n_tc; ++i_tc) {
|
|
try {
|
|
const testcase_x1 & tc = s_testcase_v[i_tc];
|
|
|
|
CollectorConfig cfg{
|
|
.name_ = "x1_test",
|
|
.arena_config_ = ArenaConfig{
|
|
.size_ = tc.tenured_z_,
|
|
.store_header_flag_ = true},
|
|
.object_types_z_ = 16384,
|
|
.gc_trigger_v_{{
|
|
tc.incr_gc_threshold_,
|
|
tc.full_gc_threshold_}},
|
|
};
|
|
|
|
DX1Collector gc(cfg);
|
|
|
|
{
|
|
REQUIRE(gc.name() == "x1_test");
|
|
|
|
const DArena * otypes = gc.get_object_types();
|
|
|
|
REQUIRE(otypes != nullptr);
|
|
REQUIRE(otypes->reserved() >= cfg.object_types_z_);
|
|
REQUIRE(otypes->reserved() < cfg.object_types_z_ + otypes->page_z_);
|
|
|
|
DArena * from_0 = gc.get_space(role::from_space(), generation{0});
|
|
|
|
REQUIRE(from_0 != nullptr);
|
|
REQUIRE(from_0->reserved() >= tc.tenured_z_);
|
|
REQUIRE(from_0->reserved() < tc.tenured_z_ + from_0->page_z_);
|
|
REQUIRE(from_0->reserved() % from_0->page_z_ == 0);
|
|
|
|
DArena * from_1 = gc.get_space(role::from_space(), generation{1});
|
|
|
|
REQUIRE(from_1 != nullptr);
|
|
REQUIRE(from_1->reserved() == from_0->reserved());
|
|
|
|
DArena * to_0 = gc.get_space(role::to_space(), generation{0});
|
|
|
|
REQUIRE(to_0 != nullptr);
|
|
REQUIRE(to_0->reserved() == from_0->reserved());
|
|
|
|
DArena * to_1 = gc.get_space(role::to_space(), generation{1});
|
|
|
|
REQUIRE(to_1 != nullptr);
|
|
REQUIRE(to_1->reserved() == to_0->reserved());
|
|
|
|
DArena * from_2 = gc.get_space(role::from_space(), generation{2});
|
|
|
|
REQUIRE(from_2 == nullptr);
|
|
|
|
DArena * to_2 = gc.get_space(role::to_space(), generation{2});
|
|
|
|
REQUIRE(to_2 == nullptr);
|
|
|
|
REQUIRE(gc.reserved_total()
|
|
== otypes->reserved() + 4 * from_0->reserved());
|
|
}
|
|
|
|
/* attempt allocation */
|
|
|
|
} catch (std::exception & ex) {
|
|
std::cerr << "caught exception: " << ex.what() << std::endl;
|
|
REQUIRE(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/* end X1Collector.test.cpp */
|