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

Side by Side Diff: base/debug/activity_analyzer_unittest.cc

Issue 2566983009: Support storing information about what modules are loaded in the process. (Closed)
Patch Set: rebased Created 4 years 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/debug/activity_analyzer.h" 5 #include "base/debug/activity_analyzer.h"
6 6
7 #include <atomic> 7 #include <atomic>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 ASSERT_TRUE(ContainsKey(snapshot, "bool")); 314 ASSERT_TRUE(ContainsKey(snapshot, "bool"));
315 EXPECT_TRUE(snapshot.at("bool").GetBool()); 315 EXPECT_TRUE(snapshot.at("bool").GetBool());
316 ASSERT_TRUE(ContainsKey(snapshot, "ref")); 316 ASSERT_TRUE(ContainsKey(snapshot, "ref"));
317 EXPECT_EQ(string1, snapshot.at("ref").GetReference().data()); 317 EXPECT_EQ(string1, snapshot.at("ref").GetReference().data());
318 EXPECT_EQ(sizeof(string1), snapshot.at("ref").GetReference().size()); 318 EXPECT_EQ(sizeof(string1), snapshot.at("ref").GetReference().size());
319 ASSERT_TRUE(ContainsKey(snapshot, "sref")); 319 ASSERT_TRUE(ContainsKey(snapshot, "sref"));
320 EXPECT_EQ(string2, snapshot.at("sref").GetStringReference().data()); 320 EXPECT_EQ(string2, snapshot.at("sref").GetStringReference().data());
321 EXPECT_EQ(strlen(string2), snapshot.at("sref").GetStringReference().size()); 321 EXPECT_EQ(strlen(string2), snapshot.at("sref").GetStringReference().size());
322 } 322 }
323 323
324 TEST_F(ActivityAnalyzerTest, GlobalModulesTest) {
325 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3);
326
327 PersistentMemoryAllocator* allocator =
328 GlobalActivityTracker::Get()->allocator();
329 GlobalActivityAnalyzer global_analyzer(MakeUnique<PersistentMemoryAllocator>(
330 const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true));
331
332 GlobalActivityTracker::ModuleInfo info1;
333 info1.is_loaded = true;
334 info1.file = "anything";
335 info1.address = 0x12345678;
336 info1.size = 0xABCDEF;
337 info1.version = "1.2.3";
338 info1.identifier = "foo/bar";
339 info1.debug_file = "elsewhere";
340 info1.debug_identifier = "foo/baz";
341
342 GlobalActivityTracker::Get()->RecordModuleInfo(info1);
343 std::vector<GlobalActivityTracker::ModuleInfo> modules1;
344 modules1 = global_analyzer.GetModules();
345 ASSERT_EQ(1U, modules1.size());
346 GlobalActivityTracker::ModuleInfo& stored1a = modules1[0];
347 EXPECT_EQ(info1.is_loaded, stored1a.is_loaded);
348 EXPECT_EQ(info1.file, stored1a.file);
349 EXPECT_EQ(info1.address, stored1a.address);
350 EXPECT_EQ(info1.version, stored1a.version);
351 EXPECT_EQ(info1.size, stored1a.size);
352 EXPECT_EQ(info1.identifier, stored1a.identifier);
353 EXPECT_EQ(info1.debug_file, stored1a.debug_file);
354 EXPECT_EQ(info1.debug_identifier, stored1a.debug_identifier);
355
356 info1.is_loaded = false;
357 GlobalActivityTracker::Get()->RecordModuleInfo(info1);
358 modules1 = global_analyzer.GetModules();
359 ASSERT_EQ(1U, modules1.size());
360 GlobalActivityTracker::ModuleInfo& stored1b = modules1[0];
361 EXPECT_EQ(info1.is_loaded, stored1b.is_loaded);
362 EXPECT_EQ(info1.file, stored1b.file);
363 EXPECT_EQ(info1.address, stored1b.address);
364 EXPECT_EQ(info1.version, stored1b.version);
365 EXPECT_EQ(info1.size, stored1b.size);
366 EXPECT_EQ(info1.identifier, stored1b.identifier);
367 EXPECT_EQ(info1.debug_file, stored1b.debug_file);
368 EXPECT_EQ(info1.debug_identifier, stored1b.debug_identifier);
369
370 GlobalActivityTracker::ModuleInfo info2;
371 info2.is_loaded = true;
372 info2.file = "nothing";
373 info2.address = 0x87654321;
374 info2.size = 0xFEDCBA;
375 info2.version = "3.2.1";
376 info2.identifier = "fuar";
377 info2.debug_file = "farewell";
378 info2.debug_identifier = "fu/baz";
379
380 GlobalActivityTracker::Get()->RecordModuleInfo(info2);
381 std::vector<GlobalActivityTracker::ModuleInfo> modules2;
382 modules2 = global_analyzer.GetModules();
383 ASSERT_EQ(2U, modules2.size());
384 GlobalActivityTracker::ModuleInfo& stored2 = modules2[1];
385 EXPECT_EQ(info2.is_loaded, stored2.is_loaded);
386 EXPECT_EQ(info2.file, stored2.file);
387 EXPECT_EQ(info2.address, stored2.address);
388 EXPECT_EQ(info2.version, stored2.version);
389 EXPECT_EQ(info2.size, stored2.size);
390 EXPECT_EQ(info2.identifier, stored2.identifier);
391 EXPECT_EQ(info2.debug_file, stored2.debug_file);
392 EXPECT_EQ(info2.debug_identifier, stored2.debug_identifier);
393 }
394
324 TEST_F(ActivityAnalyzerTest, GlobalLogMessages) { 395 TEST_F(ActivityAnalyzerTest, GlobalLogMessages) {
325 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3); 396 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3);
326 397
327 PersistentMemoryAllocator* allocator = 398 PersistentMemoryAllocator* allocator =
328 GlobalActivityTracker::Get()->allocator(); 399 GlobalActivityTracker::Get()->allocator();
329 GlobalActivityAnalyzer analyzer(MakeUnique<PersistentMemoryAllocator>( 400 GlobalActivityAnalyzer analyzer(MakeUnique<PersistentMemoryAllocator>(
330 const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true)); 401 const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true));
331 402
332 GlobalActivityTracker::Get()->RecordLogMessage("hello world"); 403 GlobalActivityTracker::Get()->RecordLogMessage("hello world");
333 GlobalActivityTracker::Get()->RecordLogMessage("foo bar"); 404 GlobalActivityTracker::Get()->RecordLogMessage("foo bar");
334 405
335 std::vector<std::string> messages = analyzer.GetLogMessages(); 406 std::vector<std::string> messages = analyzer.GetLogMessages();
336 ASSERT_EQ(2U, messages.size()); 407 ASSERT_EQ(2U, messages.size());
337 EXPECT_EQ("hello world", messages[0]); 408 EXPECT_EQ("hello world", messages[0]);
338 EXPECT_EQ("foo bar", messages[1]); 409 EXPECT_EQ("foo bar", messages[1]);
339 } 410 }
340 411
341 } // namespace debug 412 } // namespace debug
342 } // namespace base 413 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698