v8_shared_memory_dump_provider_unittest.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2019 The Chromium 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. #include "gin/v8_shared_memory_dump_provider.h"
  5. #include <memory>
  6. #include "base/trace_event/process_memory_dump.h"
  7. #include "base/trace_event/trace_event.h"
  8. #include "gin/test/v8_test.h"
  9. namespace gin {
  10. typedef V8Test V8SharedMemoryDumpProviderTest;
  11. // Checks if the dump provider runs without crashing and dumps root objects.
  12. TEST_F(V8SharedMemoryDumpProviderTest, DumpStatistics) {
  13. V8SharedMemoryDumpProvider provider;
  14. base::trace_event::MemoryDumpArgs dump_args = {
  15. base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
  16. std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
  17. new base::trace_event::ProcessMemoryDump(dump_args));
  18. provider.OnMemoryDump(dump_args, process_memory_dump.get());
  19. const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap&
  20. allocator_dumps = process_memory_dump->allocator_dumps();
  21. bool did_dump_shared_memory_stats = false;
  22. bool did_dump_read_only_space = false;
  23. for (const auto& name_dump : allocator_dumps) {
  24. const std::string& name = name_dump.first;
  25. if (name.find("v8/shared") != std::string::npos) {
  26. did_dump_shared_memory_stats = true;
  27. }
  28. if (name.find("v8/shared/read_only_space") != std::string::npos) {
  29. did_dump_read_only_space = true;
  30. }
  31. }
  32. ASSERT_TRUE(did_dump_shared_memory_stats);
  33. ASSERT_TRUE(did_dump_read_only_space);
  34. }
  35. } // namespace gin