49c507dc99
Remove cctest's ability to run multiple tests (which has long been deprecated and mostly broken). We can then make platform & V8 initialisation be part of running the test's Run method. In particular, this allows us to inject custom logic into the platform initialisation, like setting up a platform wrapper. Add a TEST_WITH_PLATFORM which exercises this by registering a platform factory on the test, and wrapping the default platform using this factory. This allows these tests to guarantee that the lifetime of the platform is longer than the lifetime of the isolate. As a result of this, we can also remove the complexity around draining platform state in the TestPlatform (since it will now have a longer lifetime than the Isolate using it), and as a drive-by clean up the TestPlaform to use a CcTest-global "default platform" instead of trying to scope over the "current" platform. As another drive-by, change the linked-list of CcTests and the linear search through it into an std::map of tests. Change-Id: I610f6312fe042f29f45cc4dfba311e4184bc7759 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3569223 Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Leszek Swirski <leszeks@chromium.org> Cr-Commit-Position: refs/heads/main@{#79772}
63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
// Copyright 2018 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 <vector>
|
|
|
|
#include "src/heap/heap.h"
|
|
#include "src/heap/memory-allocator.h"
|
|
#include "src/init/v8.h"
|
|
#include "test/cctest/cctest.h"
|
|
#include "test/cctest/heap/heap-utils.h"
|
|
|
|
using v8::IdleTask;
|
|
using v8::Task;
|
|
using v8::Isolate;
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
namespace heap {
|
|
|
|
class MockPlatformForUnmapper : public TestPlatform {
|
|
public:
|
|
~MockPlatformForUnmapper() override {
|
|
for (auto& task : worker_tasks_) {
|
|
CcTest::default_platform()->CallOnWorkerThread(std::move(task));
|
|
}
|
|
worker_tasks_.clear();
|
|
}
|
|
|
|
void CallOnWorkerThread(std::unique_ptr<Task> task) override {
|
|
worker_tasks_.push_back(std::move(task));
|
|
}
|
|
|
|
bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; }
|
|
|
|
private:
|
|
std::vector<std::unique_ptr<Task>> worker_tasks_;
|
|
};
|
|
|
|
UNINITIALIZED_TEST(EagerUnmappingInCollectAllAvailableGarbage) {
|
|
FLAG_stress_concurrent_allocation = false; // For SimulateFullSpace.
|
|
MockPlatformForUnmapper platform;
|
|
v8::Isolate::CreateParams create_params;
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
|
|
{
|
|
v8::HandleScope handle_scope(isolate);
|
|
v8::Local<v8::Context> context = CcTest::NewContext(isolate);
|
|
v8::Context::Scope context_scope(context);
|
|
Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
Heap* heap = i_isolate->heap();
|
|
i::heap::SimulateFullSpace(heap->old_space());
|
|
CcTest::CollectAllAvailableGarbage(i_isolate);
|
|
CHECK_EQ(0, heap->memory_allocator()->unmapper()->NumberOfChunks());
|
|
}
|
|
isolate->Dispose();
|
|
}
|
|
|
|
} // namespace heap
|
|
} // namespace internal
|
|
} // namespace v8
|