chromium/v8/test/cctest/test-allocation.cc

// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdlib.h>
#include <string.h>

#if V8_OS_POSIX
#include <setjmp.h>
#include <signal.h>
#include <unistd.h>
#endif

#include "src/init/v8.h"

#include "test/cctest/cctest.h"

AccountingAllocator;

IdleTask;
Isolate;
Task;

#include "src/utils/allocation.h"
#include "src/zone/accounting-allocator.h"

// ASAN isn't configured to return nullptr, so skip all of these tests.
#if !defined(V8_USE_ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER) && \
    !defined(THREAD_SANITIZER)

namespace {

// Implementation of v8::Platform that can register OOM callbacks.
class AllocationPlatform : public TestPlatform {};

AllocationPlatform* AllocationPlatform::current_platform =;

bool DidCallOnCriticalMemoryPressure() {}

// No OS should be able to malloc/new this number of bytes. Generate enough
// random values in the address space to get a very large fraction of it. Using
// even larger values is that overflow from rounding or padding can cause the
// allocations to succeed somehow.
size_t GetHugeMemoryAmount() {}

void OnMallocedOperatorNewOOM(const char* location, const char* message) {}

void OnNewArrayOOM(const char* location, const char* message) {}

void OnAlignedAllocOOM(const char* location, const char* message) {}

}  // namespace

TEST_WITH_PLATFORM(AccountingAllocatorOOM, AllocationPlatform) {}

// We use |AllocateAtLeast| in the accounting allocator, so we check only that
// we have _at least_ the expected amount of memory allocated.
TEST_WITH_PLATFORM(AccountingAllocatorCurrentAndMax, AllocationPlatform) {}

TEST_WITH_PLATFORM(MallocedOperatorNewOOM, AllocationPlatform) {}

TEST_WITH_PLATFORM(NewArrayOOM, AllocationPlatform) {}

TEST_WITH_PLATFORM(AlignedAllocOOM, AllocationPlatform) {}

TEST_WITH_PLATFORM(AllocVirtualMemoryOOM, AllocationPlatform) {}

TEST_WITH_PLATFORM(AlignedAllocVirtualMemoryOOM, AllocationPlatform) {}

#endif  // !defined(V8_USE_ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER) &&
        // !defined(THREAD_SANITIZER)