From 7990e03d04f95cf28ac4d5b73db7fa09dc1f8ab8 Mon Sep 17 00:00:00 2001 From: John Stiles Date: Fri, 6 Nov 2020 11:22:16 -0500 Subject: [PATCH] Reland "Add memsets to the GrBlockAllocator unit tests." This is a reland of 87bc83eaa6988d34b123013f4af79ef261599574 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 > Commit-Queue: Michael Ludwig > Auto-Submit: John Stiles Bug: skia:10885 Change-Id: Ie1ffcfeffec14a016b50e6464fc23878b4dd2ccb Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332716 Reviewed-by: Michael Ludwig Commit-Queue: Michael Ludwig Auto-Submit: John Stiles --- tests/GrBlockAllocatorTest.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/GrBlockAllocatorTest.cpp b/tests/GrBlockAllocatorTest.cpp index ea8907af07..0ebe164c48 100644 --- a/tests/GrBlockAllocatorTest.cpp +++ b/tests/GrBlockAllocatorTest.cpp @@ -8,6 +8,8 @@ #include "src/gpu/GrBlockAllocator.h" #include "tests/Test.h" +#include + using Block = GrBlockAllocator::Block; using GrowthPolicy = GrBlockAllocator::GrowthPolicy; @@ -112,6 +114,10 @@ DEF_TEST(GrBlockAllocatorAlloc, r) { reinterpret_cast(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(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(pNext.fBlock->ptr(pNext.fAlignedOffset)) - reinterpret_cast(pNext.fBlock->ptr(p.fAlignedOffset)) == 32);