[GWP-ASan] Use functions in backtrace test, not line numbers.

Summary:
There's no unwinding functionality on Android that allows for line
numbers to be retrieved in-process. As a result, we can't have
this backtrace test run on Android.

Cleanup the test to use optnone functions instead, which is more stable
than line numbers anyway.

Reviewers: eugenis

Reviewed By: eugenis

Subscribers: #sanitizers, morehouse, cferris

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D76807
This commit is contained in:
Mitch Phillips 2020-03-26 10:09:57 -07:00
parent 17e4c38739
commit 1216f4c0ea
1 changed files with 30 additions and 12 deletions

View File

@ -11,34 +11,52 @@
#include "gwp_asan/crash_handler.h" #include "gwp_asan/crash_handler.h"
#include "gwp_asan/tests/harness.h" #include "gwp_asan/tests/harness.h"
TEST_F(BacktraceGuardedPoolAllocator, DoubleFree) { // Optnone to ensure that the calls to these functions are not optimized away,
void *Ptr = GPA.allocate(1); // as we're looking for them in the backtraces.
__attribute((optnone)) void *
AllocateMemory(gwp_asan::GuardedPoolAllocator &GPA) {
return GPA.allocate(1);
}
__attribute((optnone)) void
DeallocateMemory(gwp_asan::GuardedPoolAllocator &GPA, void *Ptr) {
GPA.deallocate(Ptr); GPA.deallocate(Ptr);
}
__attribute((optnone)) void
DeallocateMemory2(gwp_asan::GuardedPoolAllocator &GPA, void *Ptr) {
GPA.deallocate(Ptr);
}
__attribute__((optnone)) void TouchMemory(void *Ptr) {
*(reinterpret_cast<volatile char *>(Ptr)) = 7;
}
TEST_F(BacktraceGuardedPoolAllocator, DoubleFree) {
void *Ptr = AllocateMemory(GPA);
DeallocateMemory(GPA, Ptr);
std::string DeathRegex = "Double Free.*"; std::string DeathRegex = "Double Free.*";
DeathRegex.append("backtrace\\.cpp:26.*"); DeathRegex.append("DeallocateMemory2.*");
DeathRegex.append("was deallocated.*"); DeathRegex.append("was deallocated.*");
DeathRegex.append("backtrace\\.cpp:16.*"); DeathRegex.append("DeallocateMemory.*");
DeathRegex.append("was allocated.*"); DeathRegex.append("was allocated.*");
DeathRegex.append("backtrace\\.cpp:15.*"); DeathRegex.append("AllocateMemory.*");
ASSERT_DEATH(GPA.deallocate(Ptr), DeathRegex); ASSERT_DEATH(DeallocateMemory2(GPA, Ptr), DeathRegex);
} }
TEST_F(BacktraceGuardedPoolAllocator, UseAfterFree) { TEST_F(BacktraceGuardedPoolAllocator, UseAfterFree) {
char *Ptr = static_cast<char *>(GPA.allocate(1)); void *Ptr = AllocateMemory(GPA);
GPA.deallocate(Ptr); DeallocateMemory(GPA, Ptr);
std::string DeathRegex = "Use After Free.*"; std::string DeathRegex = "Use After Free.*";
DeathRegex.append("backtrace\\.cpp:41.*"); DeathRegex.append("TouchMemory.*");
DeathRegex.append("was deallocated.*"); DeathRegex.append("was deallocated.*");
DeathRegex.append("backtrace\\.cpp:31.*"); DeathRegex.append("DeallocateMemory.*");
DeathRegex.append("was allocated.*"); DeathRegex.append("was allocated.*");
DeathRegex.append("backtrace\\.cpp:30.*"); DeathRegex.append("AllocateMemory.*");
ASSERT_DEATH({ *Ptr = 7; }, DeathRegex); ASSERT_DEATH(TouchMemory(Ptr), DeathRegex);
} }
TEST(Backtrace, Short) { TEST(Backtrace, Short) {