Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(866)

Side by Side Diff: components/tracing/common/process_metrics_memory_dump_provider_unittest.cc

Issue 2753723003: Fix crash in InvokeOnMemoryDump when tracing (Closed)
Patch Set: fix for comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/tracing/common/process_metrics_memory_dump_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/tracing/common/process_metrics_memory_dump_provider.h" 5 #include "components/tracing/common/process_metrics_memory_dump_provider.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
Primiano Tucci (use gerrit) 2017/03/15 15:18:14 nit: IWYU (include what you use) can you add #incl
10 10
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/process/process_metrics.h" 13 #include "base/process/process_metrics.h"
14 #include "base/trace_event/memory_dump_manager.h"
14 #include "base/trace_event/process_memory_dump.h" 15 #include "base/trace_event/process_memory_dump.h"
15 #include "base/trace_event/process_memory_maps.h" 16 #include "base/trace_event/process_memory_maps.h"
16 #include "base/trace_event/process_memory_totals.h" 17 #include "base/trace_event/process_memory_totals.h"
17 #include "base/trace_event/trace_event_argument.h" 18 #include "base/trace_event/trace_event_argument.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 #if defined(OS_MACOSX) 21 #if defined(OS_MACOSX)
21 #include <libgen.h> 22 #include <libgen.h>
22 #include <mach-o/dyld.h> 23 #include <mach-o/dyld.h>
23 #endif 24 #endif
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 }); 387 });
387 uint64_t last_address = 0; 388 uint64_t last_address = 0;
388 for (const VMRegion& region : regions) { 389 for (const VMRegion& region : regions) {
389 EXPECT_GE(region.start_address, last_address); 390 EXPECT_GE(region.start_address, last_address);
390 last_address = region.start_address + region.size_in_bytes; 391 last_address = region.start_address + region.size_in_bytes;
391 } 392 }
392 } 393 }
393 394
394 #endif // defined(OS_MACOSX) 395 #endif // defined(OS_MACOSX)
395 396
397 class MockMemoryDumpProvider : public ProcessMetricsMemoryDumpProvider {
398 public:
399 MockMemoryDumpProvider(base::ProcessId process);
400 ~MockMemoryDumpProvider() override;
401 };
402
403 std::unordered_set<MockMemoryDumpProvider*> g_live_mocks;
404 std::unordered_set<MockMemoryDumpProvider*> g_dead_mocks;
405
406 MockMemoryDumpProvider::MockMemoryDumpProvider(base::ProcessId process)
407 : ProcessMetricsMemoryDumpProvider(process) {
408 g_live_mocks.insert(this);
409 }
410
411 MockMemoryDumpProvider::~MockMemoryDumpProvider() {
412 g_live_mocks.erase(this);
413 g_dead_mocks.insert(this);
414 }
415
416 TEST(ProcessMetricsMemoryDumpProviderTest, DoubleRegister) {
417 auto factory = [](base::ProcessId process) {
418 return std::unique_ptr<ProcessMetricsMemoryDumpProvider>(
419 new MockMemoryDumpProvider(process));
420 };
421 ProcessMetricsMemoryDumpProvider::factory_for_testing = factory;
422 ProcessMetricsMemoryDumpProvider::RegisterForProcess(1);
423 ProcessMetricsMemoryDumpProvider::RegisterForProcess(1);
424 ASSERT_EQ(1u, g_live_mocks.size());
425 ASSERT_EQ(1u, g_dead_mocks.size());
426 auto* manager = base::trace_event::MemoryDumpManager::GetInstance();
427 MockMemoryDumpProvider* live_mock = *g_live_mocks.begin();
428 EXPECT_TRUE(manager->IsDumpProviderRegisteredForTesting(live_mock));
429 auto* dead_mock = *g_dead_mocks.begin();
430 EXPECT_FALSE(manager->IsDumpProviderRegisteredForTesting(dead_mock));
431 ProcessMetricsMemoryDumpProvider::UnregisterForProcess(1);
432 g_live_mocks.clear();
433 g_dead_mocks.clear();
434 }
435
396 } // namespace tracing 436 } // namespace tracing
OLDNEW
« no previous file with comments | « components/tracing/common/process_metrics_memory_dump_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698