LCOV - code coverage report
Current view: top level - test/cctest/heap - test-unmapper.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 25 29 86.2 %
Date: 2019-04-18 Functions: 7 10 70.0 %

          Line data    Source code
       1             : // Copyright 2018 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/v8.h"
       6             : 
       7             : #include "src/heap/spaces.h"
       8             : #include "test/cctest/cctest.h"
       9             : #include "test/cctest/heap/heap-utils.h"
      10             : 
      11             : using v8::IdleTask;
      12             : using v8::Task;
      13             : using v8::Isolate;
      14             : 
      15             : namespace v8 {
      16             : namespace internal {
      17             : namespace heap {
      18             : 
      19             : class MockPlatformForUnmapper : public TestPlatform {
      20             :  public:
      21           5 :   MockPlatformForUnmapper()
      22          10 :       : task_(nullptr), old_platform_(i::V8::GetCurrentPlatform()) {
      23             :     // Now that it's completely constructed, make this the current platform.
      24           5 :     i::V8::SetPlatformForTesting(this);
      25           5 :   }
      26          15 :   ~MockPlatformForUnmapper() override {
      27           5 :     delete task_;
      28           5 :     i::V8::SetPlatformForTesting(old_platform_);
      29         128 :     for (auto& task : worker_tasks_) {
      30         369 :       old_platform_->CallOnWorkerThread(std::move(task));
      31             :     }
      32           5 :     worker_tasks_.clear();
      33           5 :   }
      34             : 
      35           0 :   void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override {
      36           0 :     task_ = task;
      37           0 :   }
      38             : 
      39         123 :   void CallOnWorkerThread(std::unique_ptr<Task> task) override {
      40         123 :     worker_tasks_.push_back(std::move(task));
      41         123 :   }
      42             : 
      43           0 :   bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; }
      44             : 
      45           9 :   int NumberOfWorkerThreads() override {
      46           9 :     return old_platform_->NumberOfWorkerThreads();
      47             :   }
      48             : 
      49             :  private:
      50             :   Task* task_;
      51             :   std::vector<std::unique_ptr<Task>> worker_tasks_;
      52             :   v8::Platform* old_platform_;
      53             : };
      54             : 
      55       26661 : TEST(EagerUnmappingInCollectAllAvailableGarbage) {
      56           5 :   CcTest::InitializeVM();
      57          10 :   MockPlatformForUnmapper platform;
      58           5 :   Heap* heap = CcTest::heap();
      59           5 :   i::heap::SimulateFullSpace(heap->old_space());
      60           5 :   CcTest::CollectAllAvailableGarbage();
      61           5 :   CHECK_EQ(0, heap->memory_allocator()->unmapper()->NumberOfChunks());
      62           5 : }
      63             : 
      64             : }  // namespace heap
      65             : }  // namespace internal
      66       79968 : }  // namespace v8

Generated by: LCOV version 1.10