chromium/base/allocator/partition_allocator/src/partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc_unittest.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc.h"

#include <cstdlib>
#include <cstring>

#include "partition_alloc/build_config.h"
#include "partition_alloc/buildflags.h"
#include "partition_alloc/partition_alloc_base/compiler_specific.h"
#include "partition_alloc/partition_alloc_base/memory/page_size.h"
#include "partition_alloc/partition_alloc_constants.h"
#include "testing/gtest/include/gtest/gtest.h"

#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS)
#include <malloc.h>
#endif

#if PA_BUILDFLAG(IS_APPLE)
#include <malloc/malloc.h>
#endif

#if !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) && \
    PA_BUILDFLAG(USE_PARTITION_ALLOC)
namespace allocator_shim::internal {

#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)

// Platforms on which we override weak libc symbols.
#if PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS)

PA_NOINLINE void FreeForTest(void* data) {}

TEST(PartitionAllocAsMalloc, Mallinfo) {}

#endif  // PA_BUILDFLAG(IS_LINUX) || PA_BUILDFLAG(IS_CHROMEOS)

#endif  // PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)

// Note: the tests below are quite simple, they are used as simple smoke tests
// for PartitionAlloc-Everywhere. Most of these directly dispatch to
// PartitionAlloc, which has much more extensive tests.
TEST(PartitionAllocAsMalloc, Simple) {}

TEST(PartitionAllocAsMalloc, MallocUnchecked) {}

TEST(PartitionAllocAsMalloc, Calloc) {}

TEST(PartitionAllocAsMalloc, Memalign) {}

TEST(PartitionAllocAsMalloc, AlignedAlloc) {}

TEST(PartitionAllocAsMalloc, AlignedRealloc) {}

TEST(PartitionAllocAsMalloc, Realloc) {}

// crbug.com/1141752
TEST(PartitionAllocAsMalloc, Alignment) {}

#if PA_BUILDFLAG(IS_APPLE) && PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
// Make sure that a sequence a "good sizes" grows fast enough. This is
// implicitly required by CoreFoundation, and to match Apple's implementation.
// Non-regression test for crbug.com/1501312
TEST(PartitionAllocAsMalloc, GoodSize) {
  size_t size = 1;
  int iterations = 0;
  while (size < 256 * 1024) {
    iterations++;
    size = malloc_good_size(size + 1);
  }
  EXPECT_LT(iterations, 100);
}
#endif  // PA_BUILDFLAG(IS_APPLE) && PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)

}  // namespace allocator_shim::internal
#endif  // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) &&
        // PA_BUILDFLAG(USE_PARTITION_ALLOC)