mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 16:01:52 +00:00

PR-URL: https://github.com/nodejs/node/pull/49639 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
// Copyright 2021 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 "src/heap/cppgc/platform.h"
|
|
|
|
#include "src/base/logging.h"
|
|
#include "src/base/page-allocator.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace cppgc {
|
|
namespace internal {
|
|
|
|
TEST(FatalOutOfMemoryHandlerDeathTest, DefaultHandlerCrashes) {
|
|
FatalOutOfMemoryHandler handler;
|
|
EXPECT_DEATH_IF_SUPPORTED(handler(), "");
|
|
}
|
|
|
|
namespace {
|
|
|
|
constexpr uintptr_t kHeapNeedle = 0x14;
|
|
|
|
[[noreturn]] void CustomHandler(const std::string&, const SourceLocation&,
|
|
HeapBase* heap) {
|
|
if (heap == reinterpret_cast<HeapBase*>(kHeapNeedle)) {
|
|
GRACEFUL_FATAL("cust0m h4ndl3r with matching heap");
|
|
}
|
|
GRACEFUL_FATAL("cust0m h4ndl3r");
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST(FatalOutOfMemoryHandlerDeathTest, CustomHandlerCrashes) {
|
|
FatalOutOfMemoryHandler handler;
|
|
handler.SetCustomHandler(&CustomHandler);
|
|
EXPECT_DEATH_IF_SUPPORTED(handler(), "cust0m h4ndl3r");
|
|
}
|
|
|
|
TEST(FatalOutOfMemoryHandlerDeathTest, CustomHandlerWithHeapState) {
|
|
FatalOutOfMemoryHandler handler(reinterpret_cast<HeapBase*>(kHeapNeedle));
|
|
handler.SetCustomHandler(&CustomHandler);
|
|
EXPECT_DEATH_IF_SUPPORTED(handler(), "cust0m h4ndl3r with matching heap");
|
|
}
|
|
|
|
} // namespace internal
|
|
} // namespace cppgc
|