This is an automated email from the ASF dual-hosted git repository. szaszm pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit cf9f536dcd51c7c22298888f547ec07c36b40693 Author: Ferenc Gerlits <[email protected]> AuthorDate: Tue Jul 16 16:02:15 2024 +0000 MINIFICPP-2405 Fill the vector in MemoryUsageTest with increasing numbers Closes #1839 Signed-off-by: Marton Szasz <[email protected]> --- libminifi/test/unit/MemoryUsageTest.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/libminifi/test/unit/MemoryUsageTest.cpp b/libminifi/test/unit/MemoryUsageTest.cpp index 94fa35513..03cc52cfa 100644 --- a/libminifi/test/unit/MemoryUsageTest.cpp +++ b/libminifi/test/unit/MemoryUsageTest.cpp @@ -22,7 +22,6 @@ #include <iostream> #include <numeric> -#include <random> #include "utils/gsl.h" #include "utils/OsUtils.h" @@ -32,13 +31,9 @@ TEST_CASE("Test Physical memory usage", "[testphysicalmemoryusage]") { constexpr bool cout_enabled = true; - // make sure the compiler is not able to optimize out the vector - std::mt19937 gen(std::random_device{}()); - std::uniform_int_distribution dist(0, 255); - std::vector<uint8_t> large_random_vector(30'000'000); - for (size_t i = 0; i < 10; ++i) { - large_random_vector[dist(gen) * 100'000 + dist(gen) * 1000 + dist(gen)] = dist(gen); - } + std::vector<uint8_t> large_vector(30'000'000); + // fill the vector with mostly non-zero numbers to defeat memory compression + std::iota(begin(large_vector), end(large_vector), 1); const auto ram_usage_by_process = utils::OsUtils::getCurrentProcessPhysicalMemoryUsage(); const auto ram_usage_by_system = utils::OsUtils::getSystemPhysicalMemoryUsage(); @@ -49,11 +44,11 @@ TEST_CASE("Test Physical memory usage", "[testphysicalmemoryusage]") { std::cout << "Total Physical Memory in the system: " << ram_total << " bytes\n"; } - std::cout << "\nsum of the random numbers: " << std::accumulate(begin(large_random_vector), end(large_random_vector), uint32_t{}) << "\n"; + std::cout << "\nsum of the numbers in the large vector: " << std::accumulate(begin(large_vector), end(large_vector), uint32_t{}) << "\n"; - REQUIRE(ram_usage_by_process >= gsl::narrow<int64_t>(large_random_vector.size())); + REQUIRE(ram_usage_by_process >= gsl::narrow<int64_t>(large_vector.size())); // In the worst case scenario, building with coverage flags, the ram usage still should be under 4 times the vector's size - REQUIRE(gsl::narrow<int64_t>(large_random_vector.size() * 4) >= ram_usage_by_process); + REQUIRE(gsl::narrow<int64_t>(large_vector.size() * 4) >= ram_usage_by_process); REQUIRE(ram_usage_by_system >= ram_usage_by_process); REQUIRE(ram_total >= ram_usage_by_system); }
