Commit ec09a823 authored by Michael Lippautz's avatar Michael Lippautz Committed by V8 LUCI CQ

heap: Convert embedder tracing tests to unittests

test-embedder-tracing.cc -> embedder-tracing-unittest.cc

In addition
- Add heap helpers
- CHECK -> EXPECT macros

Bug: v8:12781
Change-Id: Ibd17a4e6d527c963170af54c57f6abc51cb08808
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3576127Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79883}
parent 5fbea96a
...@@ -144,7 +144,6 @@ v8_source_set("cctest_sources") { ...@@ -144,7 +144,6 @@ v8_source_set("cctest_sources") {
"heap/test-compaction.cc", "heap/test-compaction.cc",
"heap/test-concurrent-allocation.cc", "heap/test-concurrent-allocation.cc",
"heap/test-concurrent-marking.cc", "heap/test-concurrent-marking.cc",
"heap/test-embedder-tracing.cc",
"heap/test-external-string-tracker.cc", "heap/test-external-string-tracker.cc",
"heap/test-heap.cc", "heap/test-heap.cc",
"heap/test-incremental-marking.cc", "heap/test-incremental-marking.cc",
......
This diff is collapsed.
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "src/base/macros.h" #include "src/base/macros.h"
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/heap/heap.h"
#include "test/unittests/test-utils.h" #include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -29,6 +30,14 @@ class WithHeapInternals : public TMixin, HeapInternalsBase { ...@@ -29,6 +30,14 @@ class WithHeapInternals : public TMixin, HeapInternalsBase {
heap()->CollectGarbage(space, i::GarbageCollectionReason::kTesting); heap()->CollectGarbage(space, i::GarbageCollectionReason::kTesting);
} }
void FullGC() {
heap()->CollectGarbage(OLD_SPACE, i::GarbageCollectionReason::kTesting);
}
void YoungGC() {
heap()->CollectGarbage(NEW_SPACE, i::GarbageCollectionReason::kTesting);
}
Heap* heap() const { return this->i_isolate()->heap(); } Heap* heap() const { return this->i_isolate()->heap(); }
void SimulateIncrementalMarking(bool force_completion = true) { void SimulateIncrementalMarking(bool force_completion = true) {
...@@ -45,6 +54,20 @@ using TestWithHeapInternals = // ...@@ -45,6 +54,20 @@ using TestWithHeapInternals = //
WithDefaultPlatformMixin< // WithDefaultPlatformMixin< //
::testing::Test>>>>>; ::testing::Test>>>>>;
using TestWithHeapInternalsAndContext = //
WithContextMixin< //
TestWithHeapInternals>;
inline void FullGC(v8::Isolate* isolate) {
reinterpret_cast<i::Isolate*>(isolate)->heap()->CollectAllGarbage(
i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting);
}
inline void YoungGC(v8::Isolate* isolate) {
reinterpret_cast<i::Isolate*>(isolate)->heap()->CollectGarbage(
i::NEW_SPACE, i::GarbageCollectionReason::kTesting);
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -83,5 +83,23 @@ SaveFlags::~SaveFlags() { ...@@ -83,5 +83,23 @@ SaveFlags::~SaveFlags() {
#undef FLAG_MODE_APPLY #undef FLAG_MODE_APPLY
} }
ManualGCScope::ManualGCScope(i::Isolate* isolate) {
// Some tests run threaded (back-to-back) and thus the GC may already be
// running by the time a ManualGCScope is created. Finalizing existing marking
// prevents any undefined/unexpected behavior.
if (isolate && isolate->heap()->incremental_marking()->IsMarking()) {
isolate->heap()->CollectGarbage(i::OLD_SPACE,
i::GarbageCollectionReason::kTesting);
}
i::FLAG_concurrent_marking = false;
i::FLAG_concurrent_sweeping = false;
i::FLAG_stress_incremental_marking = false;
i::FLAG_stress_concurrent_allocation = false;
// Parallel marking has a dependency on concurrent marking.
i::FLAG_parallel_marking = false;
i::FLAG_detect_ineffective_gcs_near_heap_limit = false;
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -314,6 +314,16 @@ inline void PrintTo(Smi o, ::std::ostream* os) { ...@@ -314,6 +314,16 @@ inline void PrintTo(Smi o, ::std::ostream* os) {
*os << reinterpret_cast<void*>(o.ptr()); *os << reinterpret_cast<void*>(o.ptr());
} }
// ManualGCScope allows for disabling GC heuristics. This is useful for tests
// that want to check specific corner cases around GC.
//
// The scope will finalize any ongoing GC on the provided Isolate.
class V8_NODISCARD ManualGCScope final : private SaveFlags {
public:
explicit ManualGCScope(i::Isolate* isolate);
~ManualGCScope() = default;
};
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
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