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

Side by Side Diff: components/browser_watcher/postmortem_report_collector_unittest.cc

Issue 2554423002: Collect log messages from stability files (Closed)
Patch Set: Enum fixup 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 "components/browser_watcher/postmortem_report_collector.h" 5 #include "components/browser_watcher/postmortem_report_collector.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 const uint64_t kTaskSequenceNum = 42; 332 const uint64_t kTaskSequenceNum = 42;
333 const uintptr_t kTaskOrigin = 1000U; 333 const uintptr_t kTaskOrigin = 1000U;
334 const uintptr_t kLockAddress = 1001U; 334 const uintptr_t kLockAddress = 1001U;
335 const uintptr_t kEventAddress = 1002U; 335 const uintptr_t kEventAddress = 1002U;
336 const int kThreadId = 43; 336 const int kThreadId = 43;
337 const int kProcessId = 44; 337 const int kProcessId = 44;
338 const int kAnotherThreadId = 45; 338 const int kAnotherThreadId = 45;
339 339
340 } // namespace 340 } // namespace
341 341
342 // Sets up a file backed thread tracker for direct access. A
343 // GlobalActivityTracker is not created, meaning there is no risk of
344 // the instrumentation interfering with the file's content.
342 class PostmortemReportCollectorCollectionTest : public testing::Test { 345 class PostmortemReportCollectorCollectionTest : public testing::Test {
343 public: 346 public:
344 // Create a proper debug file. 347 // Create a proper debug file.
345 void SetUp() override { 348 void SetUp() override {
346 testing::Test::SetUp(); 349 testing::Test::SetUp();
347 350
348 // Create a file backed allocator. 351 // Create a file backed allocator.
349 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 352 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
350 debug_file_path_ = temp_dir_.GetPath().AppendASCII("debug_file.pma"); 353 debug_file_path_ = temp_dir_.GetPath().AppendASCII("debug_file.pma");
351 allocator_ = CreateAllocator(); 354 allocator_ = CreateAllocator();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 EXPECT_EQ(Activity::ACT_THREAD_JOIN, activity.type()); 479 EXPECT_EQ(Activity::ACT_THREAD_JOIN, activity.type());
477 EXPECT_EQ(kThreadId, activity.thread_id()); 480 EXPECT_EQ(kThreadId, activity.thread_id());
478 } 481 }
479 { 482 {
480 const Activity& activity = thread_state.activities(4); 483 const Activity& activity = thread_state.activities(4);
481 EXPECT_EQ(Activity::ACT_PROCESS_WAIT, activity.type()); 484 EXPECT_EQ(Activity::ACT_PROCESS_WAIT, activity.type());
482 EXPECT_EQ(kProcessId, activity.process_id()); 485 EXPECT_EQ(kProcessId, activity.process_id());
483 } 486 }
484 } 487 }
485 488
489 class PostmortemReportCollectorCollectionFromGlobalTrackerTest
490 : public testing::Test {
491 public:
492 const int kMemorySize = 1 << 20; // 1MiB
493
494 PostmortemReportCollectorCollectionFromGlobalTrackerTest() {}
495 ~PostmortemReportCollectorCollectionFromGlobalTrackerTest() override {
496 GlobalActivityTracker* global_tracker = GlobalActivityTracker::Get();
497 if (global_tracker) {
498 global_tracker->ReleaseTrackerForCurrentThreadForTesting();
499 delete global_tracker;
500 }
501 }
502
503 void SetUp() override {
504 testing::Test::SetUp();
505
506 // Set up a debug file path.
507 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
508 debug_file_path_ = temp_dir_.GetPath().AppendASCII("debug.pma");
509 }
510
511 const base::FilePath& debug_file_path() { return debug_file_path_; }
512
513 protected:
514 base::ScopedTempDir temp_dir_;
515 base::FilePath debug_file_path_;
516 };
517
518 TEST_F(PostmortemReportCollectorCollectionFromGlobalTrackerTest,
519 LogCollection) {
520 // Record some log messages.
521 GlobalActivityTracker::CreateWithFile(debug_file_path(), kMemorySize, 0ULL,
522 "", 3);
523 GlobalActivityTracker::Get()->RecordLogMessage("hello world");
524 GlobalActivityTracker::Get()->RecordLogMessage("foo bar");
525
526 // Collect the stability report.
527 PostmortemReportCollector collector(kProductName, kVersionNumber,
528 kChannelName);
529 std::unique_ptr<StabilityReport> report;
530 ASSERT_EQ(PostmortemReportCollector::SUCCESS,
531 collector.Collect(debug_file_path(), &report));
532 ASSERT_NE(nullptr, report);
533
534 // Validate the report's log content.
535 ASSERT_EQ(2, report->log_messages_size());
536 ASSERT_EQ("hello world", report->log_messages(0));
537 ASSERT_EQ("foo bar", report->log_messages(1));
538 }
539
486 } // namespace browser_watcher 540 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698