Fix sporadic failure of InstructionPointerMemory test on Windows

If another memory region of interest (e.g. a thread stack) randomly happens
to lie immediately before the page allocated by this test, the memory
regions can be coalesced in the minidump generated.  Relax this test so it
correctly handles the case where the expected 256 bytes around the IP aren't
at the start of the minidump memory region.

Alternatively, that could be avoided by reserving the page before the page
used for this test, in which case this test is degenerate with
InstructionPointerMemoryMinBound and can be removed.

BUG=

Change-Id: Ib1bfb242b2c0acaa090df68334a02ac434ad880c
Reviewed-on: https://chromium-review.googlesource.com/456702
Reviewed-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
Jon Turney 2017-03-17 17:55:46 +00:00 committed by Mike Frysinger
parent 4bb0cd4743
commit 0c3b559653

View File

@ -357,8 +357,8 @@ TEST_F(ExceptionHandlerDeathTest, InstructionPointerMemory) {
// Read the minidump. Locate the exception record and the
// memory list, and then ensure that there is a memory region
// in the memory list that covers the instruction pointer from
// the exception record.
// in the memory list that covers at least 128 bytes on either
// side of the instruction pointer from the exception record.
{
Minidump minidump(minidump_filename);
ASSERT_TRUE(minidump.Read());
@ -379,18 +379,23 @@ TEST_F(ExceptionHandlerDeathTest, InstructionPointerMemory) {
memory_list->GetMemoryRegionForAddress(instruction_pointer);
ASSERT_TRUE(region);
EXPECT_EQ(kMemorySize, region->GetSize());
EXPECT_LE(kMemorySize, region->GetSize());
const uint8_t* bytes = region->GetMemory();
ASSERT_TRUE(bytes);
uint64_t ip_offset = instruction_pointer - region->GetBase();
EXPECT_GE(region->GetSize() - kOffset, ip_offset);
EXPECT_LE(kOffset, ip_offset);
uint8_t prefix_bytes[kOffset];
uint8_t suffix_bytes[kMemorySize - kOffset - sizeof(instructions)];
memset(prefix_bytes, 0, sizeof(prefix_bytes));
memset(suffix_bytes, 0, sizeof(suffix_bytes));
EXPECT_EQ(0, memcmp(bytes, prefix_bytes, sizeof(prefix_bytes)));
EXPECT_EQ(0, memcmp(bytes + kOffset, instructions, sizeof(instructions)));
EXPECT_EQ(0, memcmp(bytes + kOffset + sizeof(instructions),
suffix_bytes, sizeof(suffix_bytes)));
EXPECT_EQ(0, memcmp(bytes + ip_offset - kOffset, prefix_bytes,
sizeof(prefix_bytes)));
EXPECT_EQ(0, memcmp(bytes + ip_offset, instructions, sizeof(instructions)));
EXPECT_EQ(0, memcmp(bytes + ip_offset + sizeof(instructions), suffix_bytes,
sizeof(suffix_bytes)));
}
DeleteFileW(minidump_filename_wide.c_str());