From 5295c9618cbae2bb937e188c072f66a77d793eb5 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Mon, 6 Nov 2023 15:55:39 +0100 Subject: gc v2 tests (#512) * set MaxBlockCount at init * properly calculate total size * basic blockstore compact blocks test * correct detection of block swap * Use one implementation for CreateRandomBlob * reduce some data sets to increase speed of tests * reduce test time * rename BlockStoreCompactState::AddBlock -> BlockStoreCompactState::IncludeBlock --- src/zencore/testutils.cpp | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'src/zencore/testutils.cpp') diff --git a/src/zencore/testutils.cpp b/src/zencore/testutils.cpp index dbc3ab5af..d4c8aeaef 100644 --- a/src/zencore/testutils.cpp +++ b/src/zencore/testutils.cpp @@ -1,10 +1,13 @@ // Copyright Epic Games, Inc. All Rights Reserved. #include "zencore/testutils.h" -#include -#include "zencore/string.h" -#include +#if ZEN_WITH_TESTS + +# include +# include "zencore/string.h" + +# include namespace zen { @@ -39,4 +42,35 @@ ScopedTemporaryDirectory::~ScopedTemporaryDirectory() std::filesystem::remove_all(m_RootPath, Ec); } -} // namespace zen \ No newline at end of file +IoBuffer +CreateRandomBlob(uint64_t Size) +{ + static uint64_t Seed{0x7CEBF54E45B9F5D1}; + auto Next = [](uint64_t& seed) { + uint64_t z = (seed += UINT64_C(0x9E3779B97F4A7C15)); + z = (z ^ (z >> 30)) * UINT64_C(0xBF58476D1CE4E5B9); + z = (z ^ (z >> 27)) * UINT64_C(0x94D049BB133111EB); + return z ^ (z >> 31); + }; + + IoBuffer Data(Size); + uint64_t* DataPtr = reinterpret_cast(Data.MutableData()); + while (Size > sizeof(uint64_t)) + { + *DataPtr++ = Next(Seed); + Size -= sizeof(uint64_t); + } + uint64_t ByteNext = Next(Seed); + uint8_t* ByteDataPtr = reinterpret_cast(DataPtr); + while (Size > 0) + { + *ByteDataPtr++ = static_cast(ByteNext & 0xff); + ByteNext >>= 8; + Size--; + } + return Data; +}; + +} // namespace zen + +#endif // ZEN_WITH_TESTS -- cgit v1.2.3