From 0c3b559653d011bd9f171c945de1570c66fb15fc Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Fri, 17 Mar 2017 17:55:46 +0000 Subject: [PATCH] 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 --- .../unittests/exception_handler_death_test.cc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/client/windows/unittests/exception_handler_death_test.cc b/src/client/windows/unittests/exception_handler_death_test.cc index 079ca3d6..30600d41 100644 --- a/src/client/windows/unittests/exception_handler_death_test.cc +++ b/src/client/windows/unittests/exception_handler_death_test.cc @@ -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());