geopro/tests/render/test_brick_pager.cpp

37 lines
1.6 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "render/source/BrickPager.hpp"
#include "data/store/ChunkedVolumeStore.hpp"
#include "core/algo/GprVolumeBuilder.hpp"
#include <gtest/gtest.h>
#include <filesystem>
using namespace geopro;
namespace {
data::ChunkedVolumeStore makeStore(const std::string& dir){
geopro::core::BuiltI16 b; b.vol=geopro::core::ScalarVolumeI16(128,128,128);
for(auto& v: b.vol.data()) v=3;
b.quant={1.0,0.0}; b.origin={{0,0,0}}; b.spacing={{1,1,1}}; b.vminPhys=0; b.vmaxPhys=3;
data::ChunkedVolumeStore::write(dir, b, 64); // 2×2×2=8 个 brick(level0)
return data::ChunkedVolumeStore(dir);
}
}
TEST(BrickPager, BoundedMemoryLruEviction){
auto dir=(std::filesystem::temp_directory_path()/"gpr_pager").string();
std::filesystem::remove_all(dir);
auto store = makeStore(dir);
render::BrickPager pager(store, 4);
EXPECT_EQ(pager.budget(), 4u);
EXPECT_EQ(pager.residentCount(), 0u);
std::vector<render::BrickId> six = {
{0,0,0,0},{0,1,0,0},{0,0,1,0},{0,1,1,0},{0,0,0,1},{0,1,0,1} };
pager.requestVisible(six);
EXPECT_EQ(pager.residentCount(), 4u); // 恒定 ≤ budget
EXPECT_EQ(pager.get(six[0]), nullptr); // 最早请求→已淘汰
EXPECT_EQ(pager.get(six[1]), nullptr);
ASSERT_NE(pager.get(six[5]), nullptr); // 最近请求→驻留
EXPECT_EQ(pager.get(six[5])->size(), 64u*64*64);
// 再请求一个已驻留 + 一个新的,验证 LRU 更新与恒定驻留
pager.requestVisible({ six[5], {0,1,1,1} });
EXPECT_LE(pager.residentCount(), 4u);
EXPECT_NE(pager.get(six[5]), nullptr); // 刚 touch,仍在
std::filesystem::remove_all(dir);
}