llvm/libc/test/src/__support/block_test.cpp

//===-- Unittests for a block of memory -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include <stddef.h>

#include "src/__support/CPP/array.h"
#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/span.h"
#include "src/__support/block.h"
#include "src/string/memcpy.h"
#include "test/UnitTest/Test.h"

// Block types.
LargeOffsetBlock;
SmallOffsetBlock;

// For each of the block types above, we'd like to run the same tests since
// they should work independently of the parameter sizes. Rather than re-writing
// the same test for each case, let's instead create a custom test framework for
// each test case that invokes the actual testing function for each block type.
//
// It's organized this way because the ASSERT/EXPECT macros only work within a
// `Test` class due to those macros expanding to `test` methods.
#define TEST_FOR_EACH_BLOCK_TYPE(TestCase)

array;
bit_ceil;
byte;
span;

TEST_FOR_EACH_BLOCK_TYPE(CanCreateSingleAlignedBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CanCreateUnalignedSingleBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CannotCreateTooSmallBlock) {}

// This test specifically checks that we cannot allocate a block with a size
// larger than what can be held by the offset type, we don't need to test with
// multiple block types for this particular check, so we use the normal TEST
// macro and not the custom framework.
TEST(LlvmLibcBlockTest, CannotCreateTooLargeBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CanSplitBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CanSplitBlockUnaligned) {}

TEST_FOR_EACH_BLOCK_TYPE(CanSplitMidBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CannotSplitTooSmallBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CannotSplitBlockWithoutHeaderSpace) {}

TEST_FOR_EACH_BLOCK_TYPE(CannotMakeBlockLargerInSplit) {}

TEST_FOR_EACH_BLOCK_TYPE(CannotMakeSecondBlockLargerInSplit) {}

TEST_FOR_EACH_BLOCK_TYPE(CannotMakeZeroSizeFirstBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CanMakeMinimalSizeFirstBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CanMakeMinimalSizeSecondBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CanMarkBlockUsed) {}

TEST_FOR_EACH_BLOCK_TYPE(CannotSplitUsedBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CanMergeWithNextBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CannotMergeWithFirstOrLastBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CannotMergeUsedBlock) {}

TEST_FOR_EACH_BLOCK_TYPE(CanGetBlockFromUsableSpace) {}

TEST_FOR_EACH_BLOCK_TYPE(CanGetConstBlockFromUsableSpace) {}

TEST_FOR_EACH_BLOCK_TYPE(CanAllocate) {}

TEST_FOR_EACH_BLOCK_TYPE(AllocateAlreadyAligned) {}

TEST_FOR_EACH_BLOCK_TYPE(AllocateNeedsAlignment) {}

TEST_FOR_EACH_BLOCK_TYPE(PreviousBlockMergedIfNotFirst) {}

TEST_FOR_EACH_BLOCK_TYPE(CanRemergeBlockAllocations) {}