diff options
author | Geir Storli <geirst@oath.com> | 2018-05-09 09:33:39 +0000 |
---|---|---|
committer | Geir Storli <geirst@oath.com> | 2018-05-09 09:33:39 +0000 |
commit | e9e26384e8d3a3c59a77abed04b6ad11260027aa (patch) | |
tree | a9c14389c2d9a7697f78293d8013700137eb4e85 /staging_vespalib/src/tests | |
parent | ffcdd640393978666c08e40ed02764d2fc3e8c42 (diff) |
Ensure correct behavior when epsilon is 0 and use constant for magic number.
Diffstat (limited to 'staging_vespalib/src/tests')
-rw-r--r-- | staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp b/staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp index 6210acb1f1a..45e75547fb2 100644 --- a/staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp +++ b/staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp @@ -13,6 +13,8 @@ using namespace vespalib; namespace { +constexpr uint64_t SIZE_EPSILON = 4095; + std::string toString(const ProcessMemoryStats &stats) { std::ostringstream os; @@ -27,7 +29,7 @@ std::string toString(const ProcessMemoryStats &stats) TEST("Simple stats") { - ProcessMemoryStats stats(ProcessMemoryStats::create(4096)); + ProcessMemoryStats stats(ProcessMemoryStats::create(SIZE_EPSILON)); std::cout << toString(stats) << std::endl; EXPECT_LESS(0u, stats.getMappedVirt()); EXPECT_LESS(0u, stats.getMappedRss()); @@ -37,7 +39,7 @@ TEST("Simple stats") TEST("grow anonymous memory") { - ProcessMemoryStats stats1(ProcessMemoryStats::create(4096)); + ProcessMemoryStats stats1(ProcessMemoryStats::create(SIZE_EPSILON)); std::cout << toString(stats1) << std::endl; size_t mapLen = 64 * 1024; void *mapAddr = mmap(nullptr, mapLen, PROT_READ | PROT_WRITE, @@ -48,7 +50,7 @@ TEST("grow anonymous memory") EXPECT_LESS_EQUAL(stats1.getAnonymousVirt() + mapLen, stats2.getAnonymousVirt()); memset(mapAddr, 1, mapLen); - ProcessMemoryStats stats3(ProcessMemoryStats::create(4096)); + ProcessMemoryStats stats3(ProcessMemoryStats::create(SIZE_EPSILON)); std::cout << toString(stats3) << std::endl; // Cannot check that resident grows if swap is enabled and system loaded munmap(mapAddr, mapLen); @@ -63,16 +65,16 @@ TEST("grow mapped memory") of.close(); int mapfileFileDescriptor = open("mapfile", O_RDONLY, 0666); EXPECT_LESS_EQUAL(0, mapfileFileDescriptor); - ProcessMemoryStats stats1(ProcessMemoryStats::create(4096)); + ProcessMemoryStats stats1(ProcessMemoryStats::create(SIZE_EPSILON)); std::cout << toString(stats1) << std::endl; void *mapAddr = mmap(nullptr, mapLen, PROT_READ, MAP_SHARED, mapfileFileDescriptor, 0); EXPECT_NOT_EQUAL(reinterpret_cast<void *>(-1), mapAddr); - ProcessMemoryStats stats2(ProcessMemoryStats::create(4096)); + ProcessMemoryStats stats2(ProcessMemoryStats::create(SIZE_EPSILON)); std::cout << toString(stats2) << std::endl; EXPECT_LESS_EQUAL(stats1.getMappedVirt() + mapLen, stats2.getMappedVirt()); EXPECT_EQUAL(0, memcmp(mapAddr, &buf[0], mapLen)); - ProcessMemoryStats stats3(ProcessMemoryStats::create(4096)); + ProcessMemoryStats stats3(ProcessMemoryStats::create(SIZE_EPSILON)); std::cout << toString(stats3) << std::endl; // Cannot check that resident grows if swap is enabled and system loaded munmap(mapAddr, mapLen); |