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

Unified Diff: base/trace_event/process_memory_dump_unittest.cc

Issue 2006943003: [tracing] Sanitize process memory dumps for background mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@whitelist_mdp
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: base/trace_event/process_memory_dump_unittest.cc
diff --git a/base/trace_event/process_memory_dump_unittest.cc b/base/trace_event/process_memory_dump_unittest.cc
index 3a93b2c489ddc1821a551fa4caa91e544c6f3405..bf18b8652fe64c615136010964a1c953fc3e01ec 100644
--- a/base/trace_event/process_memory_dump_unittest.cc
+++ b/base/trace_event/process_memory_dump_unittest.cc
@@ -23,7 +23,8 @@ TracedValue* GetHeapDump(const ProcessMemoryDump& pmd, const char* name) {
} // namespace
TEST(ProcessMemoryDumpTest, Clear) {
- std::unique_ptr<ProcessMemoryDump> pmd1(new ProcessMemoryDump(nullptr));
+ std::unique_ptr<ProcessMemoryDump> pmd1(
+ new ProcessMemoryDump(nullptr, MemoryDumpLevelOfDetail::DETAILED));
pmd1->CreateAllocatorDump("mad1");
pmd1->CreateAllocatorDump("mad2");
ASSERT_FALSE(pmd1->allocator_dumps().empty());
@@ -83,7 +84,8 @@ TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) {
TracedValue* heap_dumps_ptr[4];
std::unique_ptr<TracedValue> heap_dump;
- std::unique_ptr<ProcessMemoryDump> pmd1(new ProcessMemoryDump(nullptr));
+ std::unique_ptr<ProcessMemoryDump> pmd1(
+ new ProcessMemoryDump(nullptr, MemoryDumpLevelOfDetail::DETAILED));
auto mad1_1 = pmd1->CreateAllocatorDump("pmd1/mad1");
auto mad1_2 = pmd1->CreateAllocatorDump("pmd1/mad2");
pmd1->AddOwnershipEdge(mad1_1->guid(), mad1_2->guid());
@@ -94,7 +96,8 @@ TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) {
heap_dumps_ptr[1] = heap_dump.get();
pmd1->AddHeapDump("pmd1/heap_dump2", std::move(heap_dump));
- std::unique_ptr<ProcessMemoryDump> pmd2(new ProcessMemoryDump(nullptr));
+ std::unique_ptr<ProcessMemoryDump> pmd2(
+ new ProcessMemoryDump(nullptr, MemoryDumpLevelOfDetail::DETAILED));
auto mad2_1 = pmd2->CreateAllocatorDump("pmd2/mad1");
auto mad2_2 = pmd2->CreateAllocatorDump("pmd2/mad2");
pmd2->AddOwnershipEdge(mad2_1->guid(), mad2_2->guid());
@@ -154,7 +157,8 @@ TEST(ProcessMemoryDumpTest, TakeAllDumpsFrom) {
}
TEST(ProcessMemoryDumpTest, Suballocations) {
- std::unique_ptr<ProcessMemoryDump> pmd(new ProcessMemoryDump(nullptr));
+ std::unique_ptr<ProcessMemoryDump> pmd(
+ new ProcessMemoryDump(nullptr, MemoryDumpLevelOfDetail::DETAILED));
const std::string allocator_dump_name = "fakealloc/allocated_objects";
pmd->CreateAllocatorDump(allocator_dump_name);
@@ -198,7 +202,8 @@ TEST(ProcessMemoryDumpTest, Suballocations) {
}
TEST(ProcessMemoryDumpTest, GlobalAllocatorDumpTest) {
- std::unique_ptr<ProcessMemoryDump> pmd(new ProcessMemoryDump(nullptr));
+ std::unique_ptr<ProcessMemoryDump> pmd(
+ new ProcessMemoryDump(nullptr, MemoryDumpLevelOfDetail::DETAILED));
MemoryAllocatorDumpGuid shared_mad_guid(1);
auto shared_mad1 = pmd->CreateWeakSharedGlobalAllocatorDump(shared_mad_guid);
ASSERT_EQ(shared_mad_guid, shared_mad1->guid());
@@ -221,6 +226,56 @@ TEST(ProcessMemoryDumpTest, GlobalAllocatorDumpTest) {
ASSERT_EQ(MemoryAllocatorDump::Flags::DEFAULT, shared_mad1->flags());
}
+TEST(ProcessMemoryDumpTest, BackgroundModeTest) {
+ std::unique_ptr<ProcessMemoryDump> pmd(
+ new ProcessMemoryDump(nullptr, MemoryDumpLevelOfDetail::BACKGROUND));
+ pmd->whitelisted_name_for_testing_ = "WhitelistedTestName";
+ MemoryAllocatorDump* dummy_mad = pmd->dummy_mad_.get();
+
+ // Invalid dump names.
+ EXPECT_EQ(dummy_mad, pmd->CreateAllocatorDump("NotWhitelistedTestName"));
+ EXPECT_EQ(dummy_mad, pmd->CreateAllocatorDump("TestName"));
+ EXPECT_EQ(dummy_mad, pmd->CreateAllocatorDump("Whitelisted/Test"));
+ EXPECT_EQ(dummy_mad, pmd->CreateAllocatorDump("Not/Whitelisted/TestName"));
+ EXPECT_EQ(dummy_mad, pmd->CreateAllocatorDump("Whitelisted/TestName/Google"));
+ EXPECT_EQ(dummy_mad,
+ pmd->CreateAllocatorDump("Whitelisted/TestName/0x1a2Google"));
+ EXPECT_EQ(dummy_mad,
+ pmd->CreateAllocatorDump("Whitelisted/TestName/__12/Google"));
+
+ // Global dumps.
+ MemoryAllocatorDumpGuid guid(1);
+ EXPECT_EQ(dummy_mad, pmd->CreateSharedGlobalAllocatorDump(guid));
+ EXPECT_EQ(dummy_mad, pmd->CreateWeakSharedGlobalAllocatorDump(guid));
+ EXPECT_EQ(dummy_mad, pmd->GetSharedGlobalAllocatorDump(guid));
+
+ // Suballocations.
+ pmd->AddSuballocation(guid, "malloc/allocated_objects");
+ EXPECT_EQ(0u, pmd->allocator_dumps_edges_.size());
+ EXPECT_EQ(0u, pmd->allocator_dumps_.size());
+
+ // Valid dump names.
+ EXPECT_NE(dummy_mad, pmd->CreateAllocatorDump("WhitelistedTestName"));
+ EXPECT_NE(dummy_mad, pmd->CreateAllocatorDump("Whitelisted/TestName/0xA1b2"));
+ EXPECT_NE(dummy_mad,
+ pmd->CreateAllocatorDump("Whitelisted/TestName_123/0xab"));
+ EXPECT_NE(dummy_mad,
+ pmd->CreateAllocatorDump("Whitelisted_12/0xaB/TestName"));
+
+ // GetAllocatorDump is consistent.
+ EXPECT_EQ(dummy_mad, pmd->GetAllocatorDump("NotWhitelistedTestName"));
+ auto mad = pmd->GetAllocatorDump("WhitelistedTestName");
+ EXPECT_NE(dummy_mad, mad);
+
+ // String attributes are disabled in MAD.
+ mad->AddString("url", "text", "google");
+ std::string out;
+ mad->attributes_for_testing()->AppendAsTraceFormat(&out);
+ EXPECT_EQ("{}", out);
+
+ pmd->whitelisted_name_for_testing_ = nullptr;
+}
+
#if defined(COUNT_RESIDENT_BYTES_SUPPORTED)
TEST(ProcessMemoryDumpTest, CountResidentBytes) {
const size_t page_size = ProcessMemoryDump::GetSystemPageSize();

Powered by Google App Engine
This is Rietveld 408576698