Reland "Add memsets to the GrBlockAllocator unit tests."

This is a reland of 87bc83eaa6

Original change's description:
> Add memsets to the GrBlockAllocator unit tests.
>
> These will verify that our blocks are actually set up properly--if not,
> we'll stomp over a sentinel word and/or trip an ASAN poisoned byte,
> causing the test to fail.
>
> Change-Id: I2dcb5b913d00c408f70c71f2660c6ec6017b452c
> Bug: skia:10885
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332260
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
> Auto-Submit: John Stiles <johnstiles@google.com>

Bug: skia:10885
Change-Id: Ie1ffcfeffec14a016b50e6464fc23878b4dd2ccb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332716
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2020-11-06 11:22:16 -05:00 committed by Skia Commit-Bot
parent cf27b4f744
commit 7990e03d04

View File

@ -8,6 +8,8 @@
#include "src/gpu/GrBlockAllocator.h"
#include "tests/Test.h"
#include <cstring>
using Block = GrBlockAllocator::Block;
using GrowthPolicy = GrBlockAllocator::GrowthPolicy;
@ -112,6 +114,10 @@ DEF_TEST(GrBlockAllocatorAlloc, r) {
reinterpret_cast<uintptr_t>(prevBR->fBlock->ptr(prevBR->fEnd - 1));
REPORTER_ASSERT(r, pt > prevEnd);
}
// And make sure that the entire byte range is safe to write into (excluding the dead space
// between "start" and "aligned offset," which is just padding and is left poisoned)
std::memset(br.fBlock->ptr(br.fAlignedOffset), 0xFF, br.fEnd - br.fAlignedOffset);
};
auto p1 = pool->allocate<1>(14);
@ -169,11 +175,13 @@ DEF_TEST(GrBlockAllocatorResize, r) {
SkDEBUGCODE(pool->validate();)
// Fixed resize from 16 to 32
auto p = pool->allocate<4>(16);
GrBlockAllocator::ByteRange p = pool->allocate<4>(16);
REPORTER_ASSERT(r, p.fBlock->avail<4>() > 16);
REPORTER_ASSERT(r, p.fBlock->resize(p.fStart, p.fEnd, 16));
p.fEnd += 16;
std::memset(p.fBlock->ptr(p.fAlignedOffset), 0x11, p.fEnd - p.fAlignedOffset);
// Subsequent allocation is 32 bytes ahead of 'p' now, and 'p' cannot be resized further.
auto pNext = pool->allocate<4>(16);
REPORTER_ASSERT(r, reinterpret_cast<uintptr_t>(pNext.fBlock->ptr(pNext.fAlignedOffset)) -
@ -187,6 +195,8 @@ DEF_TEST(GrBlockAllocatorResize, r) {
REPORTER_ASSERT(r, p.fBlock->resize(p.fStart, p.fEnd, fillBlock));
p.fEnd += fillBlock;
std::memset(p.fBlock->ptr(p.fAlignedOffset), 0x22, p.fEnd - p.fAlignedOffset);
// Confirm that resizing when there's not enough room fails
REPORTER_ASSERT(r, p.fBlock->avail<4>() < fillBlock);
REPORTER_ASSERT(r, !p.fBlock->resize(p.fStart, p.fEnd, fillBlock));
@ -197,6 +207,8 @@ DEF_TEST(GrBlockAllocatorResize, r) {
p.fEnd += shrinkTo32;
REPORTER_ASSERT(r, p.fEnd - p.fStart == 32);
std::memset(p.fBlock->ptr(p.fAlignedOffset), 0x33, p.fEnd - p.fAlignedOffset);
pNext = pool->allocate<4>(16);
REPORTER_ASSERT(r, reinterpret_cast<uintptr_t>(pNext.fBlock->ptr(pNext.fAlignedOffset)) -
reinterpret_cast<uintptr_t>(pNext.fBlock->ptr(p.fAlignedOffset)) == 32);