From d66affcd1e121e3201ac6c7d439c2ddf8ff41a86 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 29 May 2026 09:04:48 -0400 Subject: [PATCH] xo-gc: utest: fix test regressions --- xo-gc/src/gc/DX1Collector.cpp | 1 + xo-gc/utest/Collector.test.cpp | 33 +++++++++++++++++++----------- xo-gc/utest/MockCollector.test.cpp | 2 +- xo-gc/utest/X1Collector.test.cpp | 8 +++++--- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/xo-gc/src/gc/DX1Collector.cpp b/xo-gc/src/gc/DX1Collector.cpp index 4421d342..a0a4ddc8 100644 --- a/xo-gc/src/gc/DX1Collector.cpp +++ b/xo-gc/src/gc/DX1Collector.cpp @@ -168,6 +168,7 @@ namespace xo { return accumulate_total_aux(*this, &DArena::reserved); } + // editor bait: size() size_type DX1Collector::size_total() const noexcept { diff --git a/xo-gc/utest/Collector.test.cpp b/xo-gc/utest/Collector.test.cpp index 26d1416e..3e94bd13 100644 --- a/xo-gc/utest/Collector.test.cpp +++ b/xo-gc/utest/Collector.test.cpp @@ -325,11 +325,12 @@ namespace xo { namespace { class Testcase { public: - Testcase(uint32_t ng, uint32_t ns, size_t gcz, uint32_t otz, bool dbg_flag) + Testcase(uint32_t ng, uint32_t ns, size_t gcz, uint32_t otz, uint32_t xotz, bool dbg_flag) : n_gen_{ng}, n_survive_{ns}, gc_halfspace_z_{gcz}, object_type_z_{otz}, + expect_object_type_z_{xotz}, debug_flag_{dbg_flag} {} @@ -340,7 +341,7 @@ namespace xo { uint32_t n_survive_ = 0; /** size of each generations' half-space, in bytes **/ size_t gc_halfspace_z_ = 0; - /** storage for object type array, in bytes + /** storage for object-type array, in bytes * one 8-byte facet pointer per type **/ uint32_t object_type_z_; @@ -348,6 +349,8 @@ namespace xo { /** size for error output arena **/ size_t error_size_ = 0; #endif + /** expected size of object-type array, in bytes, after orderly init **/ + uint32_t expect_object_type_z_ = 0; /** true to enable debug output for this test case **/ bool debug_flag_ = false; }; @@ -372,6 +375,7 @@ namespace xo { { auto gc = obj(&gc_); + // auto-install object types CollectorTypeRegistry::instance().install_types(gc); } @@ -381,14 +385,15 @@ namespace xo { static std::vector s_testcase_v = { /** - * debug_flag - * object_type_z | - * gc_halfspace_z | | - * n_survive | | | - * n_gen | | | | - * v v v v v + * debug_flag + * expect_object_type_z | + * object_type_z | | + * gc_halfspace_z | | | + * n_survive | | | | + * n_gen | | | | | + * v v v v v v **/ - Testcase(1, 2, 16 * 1024, 128, T), + Testcase(1, 2, 16 * 1024, 128, 96, T), }; # undef T @@ -443,7 +448,9 @@ namespace xo { Generation g0 = Generation::g0(); - REQUIRE(mm.allocated() == tc.object_type_z_); + // mm.allocated includes: { object-types, roots(=0), arenas(=0) } + // + REQUIRE(mm.allocated() == tc.expect_object_type_z_); REQUIRE(gc.allocated(g0, Role::to_space()) == 0); REQUIRE(gc.allocated(g0, Role::from_space()) == 0); @@ -478,7 +485,9 @@ namespace xo { + sizeof(DArray) + sizeof(obj)); { REQUIRE(z == 80); - REQUIRE(mm.allocated() == tc.object_type_z_ + z); + // cf earlier assertion on mm.allocated(); + // now adding cost of 3 specific objects + REQUIRE(mm.allocated() == tc.expect_object_type_z_ + z); REQUIRE(gc.allocated(g0, Role::to_space()) == z); REQUIRE(gc.allocated(g1, Role::to_space()) == 0); REQUIRE(gc.allocated(g0, Role::from_space()) == 0); @@ -494,7 +503,7 @@ namespace xo { REQUIRE(mm->contains(Role::from_space(), l1.data())); REQUIRE(!mm->contains_allocated(Role::from_space(), l1.data())); - REQUIRE(mm.allocated() == tc.object_type_z_ + z); + REQUIRE(mm.allocated() == tc.expect_object_type_z_ + z); REQUIRE(gc.allocated(g0, Role::to_space()) == z); REQUIRE(gc.allocated(g1, Role::to_space()) == 0); REQUIRE(gc.allocated(g0, Role::from_space()) == 0); diff --git a/xo-gc/utest/MockCollector.test.cpp b/xo-gc/utest/MockCollector.test.cpp index 9092d2b1..d45e42ab 100644 --- a/xo-gc/utest/MockCollector.test.cpp +++ b/xo-gc/utest/MockCollector.test.cpp @@ -39,7 +39,7 @@ namespace ut { constexpr uint32_t c_space_z = 64*1024; constexpr uint32_t c_n_gen = 1; - constexpr uint32_t c_n_survive = 0; + constexpr uint32_t c_n_survive = 1; X1VerifyStats verify_stats; GCObjectStoreConfig gcos_config{ArenaConfig() .with_name("gcos-arena-name-notused") diff --git a/xo-gc/utest/X1Collector.test.cpp b/xo-gc/utest/X1Collector.test.cpp index 481d1195..9fefcf75 100644 --- a/xo-gc/utest/X1Collector.test.cpp +++ b/xo-gc/utest/X1Collector.test.cpp @@ -273,11 +273,13 @@ namespace ut { REQUIRE(ok); REQUIRE(gc_o.name() == cfg.name_); - // nothing committed yet (?) - REQUIRE(gc_o.size() == cfg.object_types_z_); + // nothing committed yet, execept object types. + // committed memory will fit on 1 page + REQUIRE(gc_o.size() == getpagesize()); // no-op REQUIRE(gc_o.expand(0)); - REQUIRE(gc_o.size() == cfg.object_types_z_); + // committed memory will still fit on 1 page, + REQUIRE(gc_o.size() == getpagesize()); // x0_o will be added as gc root. x0_o_orig will not auto x0_o = DFloat::box(gc_o, 3.1415927);