Split ArenaAlloc test into separate tests with narrower scope.

The tests themselves are the same, just split up into their logical
groupings. http://go/unit-testing-overview#properties

"Focused. Above all, unit tests are narrow in scope, validating the
correctness of individual pieces of code rather than the correctness of
the system as a whole."

Change-Id: I6149536e84763abc98dfe243d4090bb25a555525
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/553592
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
John Stiles 2022-06-28 13:19:01 -04:00 committed by SkCQ
parent 4780d97065
commit 280987977c

View File

@ -30,6 +30,7 @@ DEF_TEST(ArenaAlloc, r) {
char buf[10];
};
// Check construction/destruction counts from SkArenaAlloc.
created = 0;
destroyed = 0;
{
@ -55,6 +56,7 @@ DEF_TEST(ArenaAlloc, r) {
REPORTER_ASSERT(r, created == 11);
REPORTER_ASSERT(r, destroyed == 11);
// Check construction/destruction counts from SkSTArenaAlloc.
created = 0;
destroyed = 0;
{
@ -80,6 +82,7 @@ DEF_TEST(ArenaAlloc, r) {
REPORTER_ASSERT(r, created == 11);
REPORTER_ASSERT(r, destroyed == 11);
// Check construction/destruction counts from SkArenaAlloc when passed an initial block.
created = 0;
destroyed = 0;
{
@ -105,17 +108,19 @@ DEF_TEST(ArenaAlloc, r) {
}
REPORTER_ASSERT(r, created == 11);
REPORTER_ASSERT(r, destroyed == 11);
}
{
SkSTArenaAllocWithReset<64> arena;
arena.makeArrayDefault<char>(256);
arena.reset();
arena.reset();
}
DEF_TEST(ArenaAllocReset, r) {
SkSTArenaAllocWithReset<64> arena;
arena.makeArrayDefault<char>(256);
arena.reset();
arena.reset();
}
DEF_TEST(ArenaAllocWithMultipleBlocks, r) {
// Make sure that multiple blocks are handled correctly.
created = 0;
destroyed = 0;
static int created = 0,
destroyed = 0;
{
struct Node {
Node(Node* n) : next(n) { created++; }
@ -132,11 +137,13 @@ DEF_TEST(ArenaAlloc, r) {
}
REPORTER_ASSERT(r, created == 128);
REPORTER_ASSERT(r, destroyed == 128);
}
DEF_TEST(ArenaAllocDestructionOrder, r) {
// Make sure that objects and blocks are destroyed in the correct order. If they are not,
// then there will be a use after free error in asan.
created = 0;
destroyed = 0;
static int created = 0,
destroyed = 0;
{
struct Node {
Node(Node* n) : next(n) { created++; }
@ -167,15 +174,15 @@ DEF_TEST(ArenaAlloc, r) {
REPORTER_ASSERT(r, a[i] == (int)i);
}
}
}
{
SkArenaAlloc arena(4096);
// Move to a 1 character boundary.
arena.make<char>();
// Allocate something with interesting alignment.
void* ptr = arena.makeBytesAlignedTo(4081, 8);
REPORTER_ASSERT(r, ((intptr_t)ptr & 7) == 0);
}
DEF_TEST(ArenaAllocUnusualAlignment, r) {
SkArenaAlloc arena(4096);
// Move to a 1 character boundary.
arena.make<char>();
// Allocate something with interesting alignment.
void* ptr = arena.makeBytesAlignedTo(4081, 8);
REPORTER_ASSERT(r, ((intptr_t)ptr & 7) == 0);
}
DEF_TEST(SkFibBlockSizes, r) {