chromium/base/metrics/persistent_memory_allocator_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "base/metrics/persistent_memory_allocator.h"

#include <memory>

#include "base/containers/heap_array.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_span.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/memory/shared_memory_mapping.h"
#include "base/memory/writable_shared_memory_region.h"
#include "base/metrics/histogram.h"
#include "base/rand_util.h"
#include "base/strings/safe_sprintf.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "base/test/gtest_util.h"
#include "base/threading/simple_thread.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace base {

namespace {

const uint32_t TEST_MEMORY_SIZE =;   // 1 MiB
const uint32_t TEST_MEMORY_PAGE =;  // 64 KiB
const uint32_t TEST_ID =;
const char TEST_NAME[] =;

void SetFileLength(const base::FilePath& path, size_t length) {}

}  // namespace

Reference;

class PersistentMemoryAllocatorTest : public testing::Test {};

TEST_F(PersistentMemoryAllocatorTest, AllocateAndIterate) {}

TEST_F(PersistentMemoryAllocatorTest, PageTest) {}

// A simple thread that takes an allocator and repeatedly allocates random-
// sized chunks from it until no more can be done.
class AllocatorThread : public SimpleThread {};

// Test parallel allocation/iteration and ensure consistency across all
// instances.
TEST_F(PersistentMemoryAllocatorTest, ParallelismTest) {}

// A simple thread that makes all objects passed iterable.
class MakeIterableThread : public SimpleThread {};

// Verifies that multiple threads making the same objects iterable doesn't cause
// any problems.
TEST_F(PersistentMemoryAllocatorTest, MakeIterableSameRefsTest) {}

// A simple thread that counts objects by iterating through an allocator.
class CounterThread : public SimpleThread {};

// Ensure that parallel iteration returns the same number of objects as
// single-threaded iteration.
TEST_F(PersistentMemoryAllocatorTest, IteratorParallelismTest) {}

TEST_F(PersistentMemoryAllocatorTest, DelayedAllocationTest) {}

// This test doesn't verify anything other than it doesn't crash. Its goal
// is to find coding errors that aren't otherwise tested for, much like a
// "fuzzer" would.
// This test is suppsoed to fail on TSAN bot (crbug.com/579867).
#if defined(THREAD_SANITIZER)
#define MAYBE_CorruptionTest
#else
#define MAYBE_CorruptionTest
#endif
TEST_F(PersistentMemoryAllocatorTest, MAYBE_CorruptionTest) {}

// Attempt to cause crashes or loops by expressly creating dangerous conditions.
TEST_F(PersistentMemoryAllocatorTest, MaliciousTest) {}


//----- LocalPersistentMemoryAllocator -----------------------------------------

TEST(LocalPersistentMemoryAllocatorTest, CreationTest) {}

//----- {Writable,ReadOnly}SharedPersistentMemoryAllocator ---------------------

TEST(SharedPersistentMemoryAllocatorTest, CreationTest) {}

#if !BUILDFLAG(IS_NACL)
//----- FilePersistentMemoryAllocator ------------------------------------------

TEST(FilePersistentMemoryAllocatorTest, CreationTest) {}

TEST(FilePersistentMemoryAllocatorTest, ExtendTest) {}

TEST(FilePersistentMemoryAllocatorTest, AcceptableTest) {}

TEST_F(PersistentMemoryAllocatorTest, TruncateTest) {}

#endif  // !BUILDFLAG(IS_NACL)

}  // namespace base