Commit f4d6b677 authored by Anton Bikineev's avatar Anton Bikineev Committed by Commit Bot

heap: Move test utilities into a separate lib

This also moves IncrementalMarkingTestDriver to heap_test_utilities.

Change-Id: I17e0dc40d71925b7ff701c37ce6a6ef502f518fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1798671Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Anton Bikineev <bikineev@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695951}
parent a1ddaae3
...@@ -1650,6 +1650,7 @@ jumbo_static_library("test_support") { ...@@ -1650,6 +1650,7 @@ jumbo_static_library("test_support") {
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
"//skia", "//skia",
"//third_party/blink/renderer/platform/blob:test_support", "//third_party/blink/renderer/platform/blob:test_support",
"//third_party/blink/renderer/platform/heap:test_support",
"//third_party/blink/renderer/platform/loader:test_support", "//third_party/blink/renderer/platform/loader:test_support",
"//third_party/blink/renderer/platform/network:test_support", "//third_party/blink/renderer/platform/network:test_support",
"//third_party/blink/renderer/platform/scheduler:test_support", "//third_party/blink/renderer/platform/scheduler:test_support",
......
...@@ -87,6 +87,19 @@ blink_platform_sources("heap") { ...@@ -87,6 +87,19 @@ blink_platform_sources("heap") {
] ]
} }
jumbo_source_set("test_support") {
testonly = true
sources = [
"heap_test_utilities.cc",
"heap_test_utilities.h",
]
deps = [
"//testing/gtest",
]
}
test("blink_heap_unittests") { test("blink_heap_unittests") {
deps = [ deps = [
":blink_heap_unittests_sources", ":blink_heap_unittests_sources",
...@@ -112,8 +125,6 @@ jumbo_source_set("blink_heap_unittests_sources") { ...@@ -112,8 +125,6 @@ jumbo_source_set("blink_heap_unittests_sources") {
"heap_compact_test.cc", "heap_compact_test.cc",
"heap_stats_collector_test.cc", "heap_stats_collector_test.cc",
"heap_test.cc", "heap_test.cc",
"heap_test_utilities.cc",
"heap_test_utilities.h",
"heap_thread_test.cc", "heap_thread_test.cc",
"heap_traits_test.cc", "heap_traits_test.cc",
"incremental_marking_test.cc", "incremental_marking_test.cc",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/platform/heap/heap_test_utilities.h" #include "third_party/blink/renderer/platform/heap/heap_test_utilities.h"
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/heap_compact.h"
namespace blink { namespace blink {
...@@ -42,4 +43,48 @@ void TestSupportingGC::CompleteSweepingIfNeeded() { ...@@ -42,4 +43,48 @@ void TestSupportingGC::CompleteSweepingIfNeeded() {
ThreadState::Current()->CompleteSweep(); ThreadState::Current()->CompleteSweep();
} }
IncrementalMarkingTestDriver::~IncrementalMarkingTestDriver() {
if (thread_state_->IsIncrementalMarking())
FinishGC();
}
void IncrementalMarkingTestDriver::Start() {
thread_state_->IncrementalMarkingStart(
BlinkGC::GCReason::kForcedGCForTesting);
}
bool IncrementalMarkingTestDriver::SingleStep(BlinkGC::StackState stack_state) {
CHECK(thread_state_->IsIncrementalMarking());
if (thread_state_->GetGCState() ==
ThreadState::kIncrementalMarkingStepScheduled) {
thread_state_->IncrementalMarkingStep(stack_state);
return true;
}
return false;
}
void IncrementalMarkingTestDriver::FinishSteps(
BlinkGC::StackState stack_state) {
CHECK(thread_state_->IsIncrementalMarking());
while (SingleStep(stack_state)) {
}
}
void IncrementalMarkingTestDriver::FinishGC(bool complete_sweep) {
CHECK(thread_state_->IsIncrementalMarking());
FinishSteps(BlinkGC::StackState::kNoHeapPointersOnStack);
CHECK_EQ(ThreadState::kIncrementalMarkingFinalizeScheduled,
thread_state_->GetGCState());
thread_state_->RunScheduledGC(BlinkGC::StackState::kNoHeapPointersOnStack);
CHECK(!thread_state_->IsIncrementalMarking());
if (complete_sweep) {
thread_state_->CompleteSweep();
}
}
size_t IncrementalMarkingTestDriver::GetHeapCompactLastFixupCount() const {
HeapCompact* compaction = ThreadState::Current()->Heap().Compaction();
return compaction->LastFixupCountForTesting();
}
} // namespace blink } // namespace blink
...@@ -141,6 +141,27 @@ class LinkedObject : public GarbageCollected<LinkedObject> { ...@@ -141,6 +141,27 @@ class LinkedObject : public GarbageCollected<LinkedObject> {
Member<LinkedObject> next_; Member<LinkedObject> next_;
}; };
// Test driver for incremental marking. Assumes that no stack handling is
// required.
class IncrementalMarkingTestDriver {
public:
explicit IncrementalMarkingTestDriver(ThreadState* thread_state)
: thread_state_(thread_state) {}
~IncrementalMarkingTestDriver();
void Start();
bool SingleStep(BlinkGC::StackState stack_state =
BlinkGC::StackState::kNoHeapPointersOnStack);
void FinishSteps(BlinkGC::StackState stack_state =
BlinkGC::StackState::kNoHeapPointersOnStack);
void FinishGC(bool complete_sweep = true);
size_t GetHeapCompactLastFixupCount() const;
private:
ThreadState* const thread_state_;
};
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_TEST_UTILITIES_H_ #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_HEAP_TEST_UTILITIES_H_
...@@ -1482,60 +1482,6 @@ TEST_F(IncrementalMarkingTest, OverrideAfterMixinConstruction) { ...@@ -1482,60 +1482,6 @@ TEST_F(IncrementalMarkingTest, OverrideAfterMixinConstruction) {
// Tests that execute complete incremental garbage collections. ================ // Tests that execute complete incremental garbage collections. ================
// ============================================================================= // =============================================================================
// Test driver for incremental marking. Assumes that no stack handling is
// required.
class IncrementalMarkingTestDriver {
public:
explicit IncrementalMarkingTestDriver(ThreadState* thread_state)
: thread_state_(thread_state) {}
~IncrementalMarkingTestDriver() {
if (thread_state_->IsIncrementalMarking())
FinishGC();
}
void Start() {
thread_state_->IncrementalMarkingStart(
BlinkGC::GCReason::kForcedGCForTesting);
}
bool SingleStep(BlinkGC::StackState stack_state =
BlinkGC::StackState::kNoHeapPointersOnStack) {
CHECK(thread_state_->IsIncrementalMarking());
if (thread_state_->GetGCState() ==
ThreadState::kIncrementalMarkingStepScheduled) {
thread_state_->IncrementalMarkingStep(stack_state);
return true;
}
return false;
}
void FinishSteps(BlinkGC::StackState stack_state =
BlinkGC::StackState::kNoHeapPointersOnStack) {
CHECK(thread_state_->IsIncrementalMarking());
while (SingleStep(stack_state)) {
}
}
void FinishGC(bool complete_sweep = true) {
CHECK(thread_state_->IsIncrementalMarking());
FinishSteps(BlinkGC::StackState::kNoHeapPointersOnStack);
CHECK_EQ(ThreadState::kIncrementalMarkingFinalizeScheduled,
thread_state_->GetGCState());
thread_state_->RunScheduledGC(BlinkGC::StackState::kNoHeapPointersOnStack);
CHECK(!thread_state_->IsIncrementalMarking());
if (complete_sweep)
thread_state_->CompleteSweep();
}
size_t GetHeapCompactLastFixupCount() {
HeapCompact* compaction = ThreadState::Current()->Heap().Compaction();
return compaction->LastFixupCountForTesting();
}
private:
ThreadState* const thread_state_;
};
TEST_F(IncrementalMarkingTest, TestDriver) { TEST_F(IncrementalMarkingTest, TestDriver) {
IncrementalMarkingTestDriver driver(ThreadState::Current()); IncrementalMarkingTestDriver driver(ThreadState::Current());
driver.Start(); driver.Start();
......
...@@ -57,7 +57,6 @@ namespace blink { ...@@ -57,7 +57,6 @@ namespace blink {
namespace incremental_marking_test { namespace incremental_marking_test {
class IncrementalMarkingScope; class IncrementalMarkingScope;
class IncrementalMarkingTestDriver;
} // namespace incremental_marking_test } // namespace incremental_marking_test
class CancelableTaskScheduler; class CancelableTaskScheduler;
...@@ -593,7 +592,7 @@ class PLATFORM_EXPORT ThreadState final { ...@@ -593,7 +592,7 @@ class PLATFORM_EXPORT ThreadState final {
friend class BlinkGCObserver; friend class BlinkGCObserver;
friend class incremental_marking_test::IncrementalMarkingScope; friend class incremental_marking_test::IncrementalMarkingScope;
friend class incremental_marking_test::IncrementalMarkingTestDriver; friend class IncrementalMarkingTestDriver;
friend class HeapAllocator; friend class HeapAllocator;
template <typename T> template <typename T>
friend class PrefinalizerRegistration; friend class PrefinalizerRegistration;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment