Commit 06ba28c9 authored by Nico Weber's avatar Nico Weber Committed by Commit Bot

Attempt to get SharedSamplerTest.PhysicalMemory passing with libc++.

Currently fails on the libc++ bot with

../../chrome/browser/task_manager/sampling/shared_sampler_win_unittest.cc(144):
    error: Expected: (physical_bytes()) >= (initial_value + allocated_size),
             actual: 15224832 vs 19419136

The reason seems to be that memory use is only counted if the memory is
referenced, and with libc++ the compiler is apparently able to optimize away
the memory's initialization.  Add some reading code to make sure the
memory references remain.

Bug: 801780
Change-Id: I8edef2eda4be8b4344ebc934768ecd58ee39496b
Reviewed-on: https://chromium-review.googlesource.com/956571
Commit-Queue: Nico Weber <thakis@chromium.org>
Reviewed-by: default avatarHans Wennborg <hans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542225}
parent 77904f25
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <windows.h> #include <windows.h>
#include <memory> #include <memory>
#include <numeric>
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -133,10 +134,17 @@ TEST_F(SharedSamplerTest, PhysicalMemory) { ...@@ -133,10 +134,17 @@ TEST_F(SharedSamplerTest, PhysicalMemory) {
int64_t initial_value = physical_bytes(); int64_t initial_value = physical_bytes();
// Allocate a large continuos block of memory. // Allocate a large continuous block of memory.
const int allocated_size = 4 * 1024 * 1024; const int allocated_size = 4 * 1024 * 1024;
std::vector<uint8_t> memory_block(allocated_size); std::vector<uint8_t> memory_block(allocated_size);
// It appears the allocation is not counted when allocated, but when actually
// accessed. vector's constructor does access the memory to initialize it,
// but if the memory then isn't read the compiler might optimize away the
// initialization. So read the memory to prevent that.
uint8_t sum = std::accumulate(memory_block.begin(), memory_block.end(), 0);
EXPECT_EQ(0, sum);
StartRefresh(REFRESH_TYPE_PHYSICAL_MEMORY); StartRefresh(REFRESH_TYPE_PHYSICAL_MEMORY);
WaitUntilRefreshDone(); WaitUntilRefreshDone();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment