chromium/v8/test/unittests/heap/cppgc/marking-verifier-unittest.cc

// Copyright 2020 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/marking-verifier.h"

#include "include/cppgc/allocation.h"
#include "include/cppgc/member.h"
#include "include/cppgc/persistent.h"
#include "include/cppgc/prefinalizer.h"
#include "src/heap/cppgc/heap-object-header.h"
#include "src/heap/cppgc/heap.h"
#include "test/unittests/heap/cppgc/tests.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cppgc {
namespace internal {

namespace {

class MarkingVerifierTest : public testing::TestWithHeap {};

class GCed : public GarbageCollected<GCed> {};

template <typename T>
V8_NOINLINE T access(volatile const T& t) {}

bool MarkHeader(HeapObjectHeader& header) {}

}  // namespace

// Following tests should not crash.

TEST_F(MarkingVerifierTest, DoesNotDieOnMarkedOnStackReference) {}

TEST_F(MarkingVerifierTest, DoesNotDieOnMarkedMember) {}

TEST_F(MarkingVerifierTest, DoesNotDieOnMarkedWeakMember) {}

namespace {

class GCedWithCallback : public GarbageCollected<GCedWithCallback> {};

}  // namespace

TEST_F(MarkingVerifierTest, DoesNotDieOnInConstructionOnObject) {}

namespace {
class GCedWithCallbackAndChild final
    : public GarbageCollected<GCedWithCallbackAndChild> {};

template <typename T>
struct Holder : public GarbageCollected<Holder<T>> {};
}  // namespace

TEST_F(MarkingVerifierTest, DoesntDieOnInConstructionObjectWithWriteBarrier) {}

// Death tests.

namespace {

class MarkingVerifierDeathTest : public MarkingVerifierTest {};

}  // namespace

TEST_F(MarkingVerifierDeathTest, DieOnUnmarkedOnStackReference) {}

TEST_F(MarkingVerifierDeathTest, DieOnUnmarkedMember) {}

TEST_F(MarkingVerifierDeathTest, DieOnUnmarkedWeakMember) {}

#ifdef CPPGC_VERIFY_HEAP

TEST_F(MarkingVerifierDeathTest, DieOnUnexpectedLiveByteCount) {}

#endif  // CPPGC_VERIFY_HEAP

namespace {

template <template <typename T> class Reference>
class ResurrectingPreFinalizer
    : public GarbageCollected<ResurrectingPreFinalizer<Reference>> {};

}  // namespace

template <template <typename T> class Reference>
void MarkingVerifierDeathTest::TestResurrectingPreFinalizer() {}

#if CPPGC_VERIFY_HEAP

TEST_F(MarkingVerifierDeathTest, DiesOnResurrectedMember) {}

TEST_F(MarkingVerifierDeathTest, DiesOnResurrectedWeakMember) {}

#endif  // CPPGC_VERIFY_HEAP

}  // namespace internal
}  // namespace cppgc