Commit 3615ae69 authored by Feng Yu's avatar Feng Yu Committed by V8 LUCI CQ

[test] Migrate cctest/test-global-handles to unittests/

Bug: v8:12781
Change-Id: If7681564f3e0c087e3347557a3f9169625b51607
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3817621Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82633}
parent ce9b1b2a
......@@ -182,7 +182,6 @@ v8_source_set("cctest_sources") {
"test-disasm-regex-helper.h",
"test-field-type-tracking.cc",
"test-func-name-inference.cc",
"test-global-handles.cc",
"test-heap-profiler.cc",
"test-icache.cc",
"test-ignition-statistics-extension.cc",
......
......@@ -522,7 +522,6 @@
'test-bignum-dtoa/*': [SKIP],
'test-cpu-profiler/*': [SKIP],
'test-debug/*': [SKIP],
'test-global-handles/*': [SKIP],
'test-heap-profiler/*': [SKIP],
'test-heap/*': [SKIP],
'test-inobject-slack-tracking/*': [SKIP],
......@@ -977,13 +976,6 @@
'test-embedder-tracing/V8RegisteringEmbedderReference': [SKIP],
'test-external-string-tracker/ExternalString_ExternalBackingStoreSizeIncreasesAfterExternalization': [SKIP],
'test-external-string-tracker/ExternalString_ExternalBackingStoreSizeIncreasesMarkCompact': [SKIP],
'test-global-handles/FinalizerDiesAndKeepsPhantomAliveOnMarkCompact': [SKIP],
'test-global-handles/FinalizerWeakness': [SKIP],
'test-global-handles/GCFromWeakCallbacks': [SKIP],
'test-global-handles/PhantomHandlesWithoutCallbacks': [SKIP],
'test-global-handles/SecondPassPhantomCallbacks': [SKIP],
'test-global-handles/WeakHandleToUnmodifiedJSApiObjectDiesOnMarkCompact': [SKIP],
'test-global-handles/WeakHandleToUnmodifiedJSObjectDiesOnMarkCompact': [SKIP],
'test-heap-profiler/HeapSnapshotDeleteDuringTakeSnapshot': [SKIP],
'test-heap-profiler/HeapSnapshotObjectsStats': [SKIP],
'test-heap-profiler/SamplingHeapProfilerPretenuredInlineAllocations': [SKIP],
......
......@@ -378,6 +378,7 @@ v8_source_set("unittests_sources") {
"heap/embedder-tracing-unittest.cc",
"heap/gc-idle-time-handler-unittest.cc",
"heap/gc-tracer-unittest.cc",
"heap/global-handles-unittest.cc",
"heap/global-safepoint-unittest.cc",
"heap/heap-controller-unittest.cc",
"heap/heap-unittest.cc",
......
......@@ -39,9 +39,7 @@ class ApiWasmTest : public TestWithIsolate {
// value is irrelevant.
Local<Promise> promise =
Local<Promise>::Cast(RunJS("WebAssembly.compileStreaming(null)"));
while (platform::PumpMessageLoop(platform(), isolate())) {
}
EmptyMessageQueues();
CHECK_EQ(expected_state, promise->State());
}
};
......
......@@ -498,23 +498,6 @@ void ConstructJSApiObject(v8::Isolate* isolate, v8::Local<v8::Context> context,
EXPECT_FALSE(global->IsEmpty());
}
namespace {
bool InCorrectGeneration(HeapObject object) {
return FLAG_single_generation ? !i::Heap::InYoungGeneration(object)
: i::Heap::InYoungGeneration(object);
}
template <typename GlobalOrPersistent>
bool InCorrectGeneration(v8::Isolate* isolate,
const GlobalOrPersistent& global) {
v8::HandleScope scope(isolate);
auto tmp = global.Get(isolate);
return InCorrectGeneration(*v8::Utils::OpenHandle(*tmp));
}
} // namespace
enum class SurvivalMode { kSurvives, kDies };
template <typename ModifierFunction, typename ConstructTracedReferenceFunction,
......@@ -532,7 +515,7 @@ void TracedReferenceTest(v8::Isolate* isolate,
const size_t initial_count = global_handles->handles_count();
auto handle = std::make_unique<v8::TracedReference<v8::Object>>();
construct_function(isolate, context, handle.get());
ASSERT_TRUE(InCorrectGeneration(isolate, *handle));
ASSERT_TRUE(IsNewObjectInCorrectGeneration(isolate, *handle));
modifier_function(*handle);
const size_t after_modification_count = global_handles->handles_count();
gc_function();
......@@ -983,7 +966,8 @@ V8_NOINLINE void StackToHeapTest(v8::Isolate* v8_isolate,
v8::HandleScope scope(v8_isolate);
v8::Local<v8::Object> to_object(ConstructTraceableJSApiObject(
v8_isolate->GetCurrentContext(), nullptr, nullptr));
EXPECT_TRUE(InCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
EXPECT_TRUE(
IsNewObjectInCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
if (!FLAG_single_generation &&
target_handling == TargetHandling::kInitializedOldGen) {
FullGC(v8_isolate);
......@@ -1034,7 +1018,8 @@ V8_NOINLINE void HeapToStackTest(v8::Isolate* v8_isolate,
v8::HandleScope scope(v8_isolate);
v8::Local<v8::Object> to_object(ConstructTraceableJSApiObject(
v8_isolate->GetCurrentContext(), nullptr, nullptr));
EXPECT_TRUE(InCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
EXPECT_TRUE(
IsNewObjectInCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
if (!FLAG_single_generation &&
target_handling == TargetHandling::kInitializedOldGen) {
FullGC(v8_isolate);
......@@ -1074,7 +1059,8 @@ V8_NOINLINE void StackToStackTest(v8::Isolate* v8_isolate,
v8::HandleScope scope(v8_isolate);
v8::Local<v8::Object> to_object(ConstructTraceableJSApiObject(
v8_isolate->GetCurrentContext(), nullptr, nullptr));
EXPECT_TRUE(InCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
EXPECT_TRUE(
IsNewObjectInCorrectGeneration(*v8::Utils::OpenHandle(*to_object)));
if (!FLAG_single_generation &&
target_handling == TargetHandling::kInitializedOldGen) {
FullGC(v8_isolate);
......
......@@ -220,5 +220,10 @@ std::vector<Handle<FixedArray>> HeapInternalsBase::CreatePadding(
return handles;
}
bool IsNewObjectInCorrectGeneration(HeapObject object) {
return FLAG_single_generation ? !i::Heap::InYoungGeneration(object)
: i::Heap::InYoungGeneration(object);
}
} // namespace internal
} // namespace v8
......@@ -99,6 +99,22 @@ class WithHeapInternals : public TMixin, HeapInternalsBase {
}
};
class V8_NODISCARD TemporaryEmbedderHeapTracerScope {
public:
TemporaryEmbedderHeapTracerScope(v8::Isolate* isolate,
v8::EmbedderHeapTracer* tracer)
: isolate_(isolate) {
isolate_->SetEmbedderHeapTracer(tracer);
}
~TemporaryEmbedderHeapTracerScope() {
isolate_->SetEmbedderHeapTracer(nullptr);
}
private:
v8::Isolate* const isolate_;
};
using TestWithHeapInternals = //
WithHeapInternals< //
WithInternalIsolateMixin< //
......@@ -121,6 +137,24 @@ inline void YoungGC(v8::Isolate* isolate) {
i::NEW_SPACE, i::GarbageCollectionReason::kTesting);
}
template <typename GlobalOrPersistent>
bool InYoungGeneration(v8::Isolate* isolate, const GlobalOrPersistent& global) {
CHECK(!FLAG_single_generation);
v8::HandleScope scope(isolate);
auto tmp = global.Get(isolate);
return i::Heap::InYoungGeneration(*v8::Utils::OpenHandle(*tmp));
}
bool IsNewObjectInCorrectGeneration(HeapObject object);
template <typename GlobalOrPersistent>
bool IsNewObjectInCorrectGeneration(v8::Isolate* isolate,
const GlobalOrPersistent& global) {
v8::HandleScope scope(isolate);
auto tmp = global.Get(isolate);
return IsNewObjectInCorrectGeneration(*v8::Utils::OpenHandle(*tmp));
}
} // namespace internal
} // namespace v8
......
......@@ -211,6 +211,12 @@ class WithIsolateScopeMixin : public TMixin {
return v8::String::NewFromUtf8(this->v8_isolate(), string).ToLocalChecked();
}
void EmptyMessageQueues() {
while (v8::platform::PumpMessageLoop(internal::V8::GetCurrentPlatform(),
this->v8_isolate())) {
}
}
private:
Local<Value> RunJS(Local<String> source) {
return TryRunJS(source).ToLocalChecked();
......
......@@ -203,6 +203,13 @@
# Performs GC
'APIExceptionTest.ExceptionMessageDoesNotKeepContextAlive': [SKIP],
'GlobalHandlesTest.FinalizerDiesAndKeepsPhantomAliveOnMarkCompact': [SKIP],
'GlobalHandlesTest.FinalizerWeakness': [SKIP],
'GlobalHandlesTest.GCFromWeakCallbacks': [SKIP],
'GlobalHandlesTest.PhantomHandlesWithoutCallbacks': [SKIP],
'GlobalHandlesTest.SecondPassPhantomCallbacks': [SKIP],
'GlobalHandlesTest.WeakHandleToUnmodifiedJSApiObjectDiesOnMarkCompact': [SKIP],
'GlobalHandlesTest.WeakHandleToUnmodifiedJSObjectDiesOnMarkCompact': [SKIP],
'LocalHeapTest.GCEpilogue': [SKIP],
'UnifiedHeapDetachedTest.AllocationBeforeConfigureHeap': [SKIP],
'UnifiedHeapTest.FindingV8ToBlinkReference': [SKIP],
......@@ -283,6 +290,7 @@
'BignumDtoaTest.*': [SKIP],
'DtoaTest.*': [SKIP],
'DeclsTest.*': [SKIP],
'GlobalHandlesTest.*': [SKIP],
}], # variant == no_wasm_traps
##############################################################################
......
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