diff options
| author | Dan Engelbrecht <[email protected]> | 2023-11-06 15:55:39 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-06 15:55:39 +0100 |
| commit | 5295c9618cbae2bb937e188c072f66a77d793eb5 (patch) | |
| tree | 6aeca701b20af5745eb7924c901c9708c098199b /src/zencore/testutils.cpp | |
| parent | statsd for cas (#511) (diff) | |
| download | zen-5295c9618cbae2bb937e188c072f66a77d793eb5.tar.xz zen-5295c9618cbae2bb937e188c072f66a77d793eb5.zip | |
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
Diffstat (limited to 'src/zencore/testutils.cpp')
| -rw-r--r-- | src/zencore/testutils.cpp | 42 |
1 files changed, 38 insertions, 4 deletions
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 <zencore/session.h> -#include "zencore/string.h" -#include <atomic> +#if ZEN_WITH_TESTS + +# include <zencore/session.h> +# include "zencore/string.h" + +# include <atomic> 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<uint64_t*>(Data.MutableData()); + while (Size > sizeof(uint64_t)) + { + *DataPtr++ = Next(Seed); + Size -= sizeof(uint64_t); + } + uint64_t ByteNext = Next(Seed); + uint8_t* ByteDataPtr = reinterpret_cast<uint8_t*>(DataPtr); + while (Size > 0) + { + *ByteDataPtr++ = static_cast<uint8_t>(ByteNext & 0xff); + ByteNext >>= 8; + Size--; + } + return Data; +}; + +} // namespace zen + +#endif // ZEN_WITH_TESTS |