Commit 63af265f authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[test] Fix missing GC in SingleThreadedDefaultPlatformTest

Bug: v8:12781
Change-Id: I7dfddd886571a16a180bffb8f9fc7a946d5667bc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3576113
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79851}
parent 8306599e
...@@ -34,21 +34,20 @@ class WithSingleThreadedDefaultPlatformMixin : public TMixin { ...@@ -34,21 +34,20 @@ class WithSingleThreadedDefaultPlatformMixin : public TMixin {
}; };
class SingleThreadedDefaultPlatformTest class SingleThreadedDefaultPlatformTest
: public WithContextMixin< // : public WithIsolateScopeMixin< //
WithIsolateScopeMixin< //
WithIsolateMixin< // WithIsolateMixin< //
WithSingleThreadedDefaultPlatformMixin< // WithSingleThreadedDefaultPlatformMixin< //
::testing::Test>>>> { ::testing::Test>>> {
public: public:
static void SetUpTestSuite() { static void SetUpTestSuite() {
CHECK_NULL(save_flags_); CHECK_NULL(save_flags_);
save_flags_ = new i::SaveFlags(); save_flags_ = new i::SaveFlags();
v8::V8::SetFlagsFromString("--single-threaded"); v8::V8::SetFlagsFromString("--single-threaded");
WithContextMixin::SetUpTestSuite(); WithIsolateScopeMixin::SetUpTestSuite();
} }
static void TearDownTestSuite() { static void TearDownTestSuite() {
WithContextMixin::TearDownTestSuite(); WithIsolateScopeMixin::TearDownTestSuite();
CHECK_NOT_NULL(save_flags_); CHECK_NOT_NULL(save_flags_);
delete save_flags_; delete save_flags_;
save_flags_ = nullptr; save_flags_ = nullptr;
...@@ -62,6 +61,11 @@ class SingleThreadedDefaultPlatformTest ...@@ -62,6 +61,11 @@ class SingleThreadedDefaultPlatformTest
i::SaveFlags* SingleThreadedDefaultPlatformTest::save_flags_; i::SaveFlags* SingleThreadedDefaultPlatformTest::save_flags_;
TEST_F(SingleThreadedDefaultPlatformTest, SingleThreadedDefaultPlatform) { TEST_F(SingleThreadedDefaultPlatformTest, SingleThreadedDefaultPlatform) {
{
i::HandleScope scope(i_isolate());
v8::Local<Context> env = Context::New(isolate());
v8::Context::Scope context_scope(env);
RunJS( RunJS(
"function f() {" "function f() {"
" for (let i = 0; i < 10; i++)" " for (let i = 0; i < 10; i++)"
...@@ -69,6 +73,10 @@ TEST_F(SingleThreadedDefaultPlatformTest, SingleThreadedDefaultPlatform) { ...@@ -69,6 +73,10 @@ TEST_F(SingleThreadedDefaultPlatformTest, SingleThreadedDefaultPlatform) {
" return 0;" " return 0;"
"}" "}"
"f();"); "f();");
}
CollectGarbage(i::NEW_SPACE);
CollectAllAvailableGarbage();
} }
} // namespace v8 } // namespace v8
...@@ -101,7 +101,48 @@ class WithIsolateScopeMixin : public TMixin { ...@@ -101,7 +101,48 @@ class WithIsolateScopeMixin : public TMixin {
return reinterpret_cast<v8::internal::Isolate*>(this->v8_isolate()); return reinterpret_cast<v8::internal::Isolate*>(this->v8_isolate());
} }
Local<Value> RunJS(const char* source) {
return RunJS(
v8::String::NewFromUtf8(this->v8_isolate(), source).ToLocalChecked());
}
Local<Value> RunJS(v8::String::ExternalOneByteStringResource* source) {
return RunJS(v8::String::NewExternalOneByte(this->v8_isolate(), source)
.ToLocalChecked());
}
void CollectGarbage(i::AllocationSpace space) {
i_isolate()->heap()->CollectGarbage(space,
i::GarbageCollectionReason::kTesting);
}
void CollectAllGarbage() {
i_isolate()->heap()->CollectAllGarbage(
i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting);
}
void CollectAllAvailableGarbage() {
i_isolate()->heap()->CollectAllAvailableGarbage(
i::GarbageCollectionReason::kTesting);
}
void PreciseCollectAllGarbage() {
i_isolate()->heap()->PreciseCollectAllGarbage(
i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting);
}
v8::Local<v8::String> NewString(const char* string) {
return v8::String::NewFromUtf8(this->v8_isolate(), string).ToLocalChecked();
}
private: private:
Local<Value> RunJS(Local<String> source) {
auto context = this->v8_isolate()->GetCurrentContext();
Local<Script> script =
v8::Script::Compile(context, source).ToLocalChecked();
return script->Run(context).ToLocalChecked();
}
v8::Isolate::Scope isolate_scope_; v8::Isolate::Scope isolate_scope_;
v8::HandleScope handle_scope_; v8::HandleScope handle_scope_;
}; };
...@@ -117,35 +158,14 @@ class WithContextMixin : public TMixin { ...@@ -117,35 +158,14 @@ class WithContextMixin : public TMixin {
const Local<Context>& context() const { return v8_context(); } const Local<Context>& context() const { return v8_context(); }
const Local<Context>& v8_context() const { return context_; } const Local<Context>& v8_context() const { return context_; }
Local<Value> RunJS(const char* source) {
return RunJS(
v8::String::NewFromUtf8(this->v8_isolate(), source).ToLocalChecked());
}
Local<Value> RunJS(v8::String::ExternalOneByteStringResource* source) {
return RunJS(v8::String::NewExternalOneByte(this->v8_isolate(), source)
.ToLocalChecked());
}
v8::Local<v8::String> NewString(const char* string) {
return v8::String::NewFromUtf8(this->v8_isolate(), string).ToLocalChecked();
}
void SetGlobalProperty(const char* name, v8::Local<v8::Value> value) { void SetGlobalProperty(const char* name, v8::Local<v8::Value> value) {
CHECK(v8_context() CHECK(v8_context()
->Global() ->Global()
->Set(v8_context(), NewString(name), value) ->Set(v8_context(), TMixin::NewString(name), value)
.FromJust()); .FromJust());
} }
private: private:
Local<Value> RunJS(Local<String> source) {
auto context = this->v8_isolate()->GetCurrentContext();
Local<Script> script =
v8::Script::Compile(context, source).ToLocalChecked();
return script->Run(context).ToLocalChecked();
}
v8::Local<v8::Context> context_; v8::Local<v8::Context> context_;
v8::Context::Scope context_scope_; v8::Context::Scope context_scope_;
}; };
......
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