[sanitizer] added a test for a bug in allocator discovered by Sergey Matveev (uint32 overflow in GetBlockBegin)

llvm-svn: 181984
This commit is contained in:
Kostya Serebryany 2013-05-16 05:22:50 +00:00
parent 37dc92eb4c
commit ad9971d793
1 changed files with 30 additions and 1 deletions

View File

@ -176,11 +176,40 @@ TEST(SanitizerCommon, SizeClassAllocator64MetadataStress) {
TEST(SanitizerCommon, SizeClassAllocator64CompactMetadataStress) {
SizeClassAllocatorMetadataStress<Allocator64Compact>();
}
#endif
#endif // SANITIZER_WORDSIZE == 64
TEST(SanitizerCommon, SizeClassAllocator32CompactMetadataStress) {
SizeClassAllocatorMetadataStress<Allocator32Compact>();
}
template <class Allocator>
void SizeClassAllocatorGetBlockBeginStress() {
Allocator *a = new Allocator;
a->Init();
SizeClassAllocatorLocalCache<Allocator> cache;
memset(&cache, 0, sizeof(cache));
cache.Init(0);
uptr max_size_class = Allocator::kNumClasses - 1;
uptr size = Allocator::SizeClassMapT::Size(max_size_class);
u64 G8 = 1ULL << 33;
for (size_t i = 0; i <= G8 / size; i++) {
void *x = cache.Allocate(a, max_size_class);
void *beg = a->GetBlockBegin(x);
if ((i & (i - 1)) == 0)
fprintf(stderr, "[%zd] %p %p\n", i, x, beg);
EXPECT_EQ(x, beg);
}
a->TestOnlyUnmap();
delete a;
}
#if SANITIZER_WORDSIZE == 64
TEST(SanitizerCommon, DISABLED_SizeClassAllocator64GetBlockBegin) {
SizeClassAllocatorGetBlockBeginStress<Allocator64>();
}
#endif // SANITIZER_WORDSIZE == 64
struct TestMapUnmapCallback {
static int map_count, unmap_count;
void OnMap(uptr p, uptr size) const { map_count++; }