Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6049a297 authored by Andreas Gampe's avatar Andreas Gampe Committed by android-build-merger
Browse files

Merge "Base: Hand complete log message to aborter" am: 0d762648

am: e082ce82

Change-Id: I0705e17a8250791fa5a8af2af9ca2c93316aee6d
parents 04819403 e082ce82
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -415,6 +415,8 @@ LogMessage::~LogMessage() {
        msg[nl] = '\0';
        LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetId(),
                data_->GetSeverity(), &msg[i]);
        // Undo the zero-termination so we can give the complete message to the aborter.
        msg[nl] = '\n';
        i = nl + 1;
      }
    }
+24 −0
Original line number Diff line number Diff line
@@ -606,3 +606,27 @@ TEST(logging, LOG_FATAL_NOOP_ABORTER) {

  ASSERT_DEATH({SuppressAbortUI(); LOG(FATAL) << "foobar";}, "foobar");
}

struct CountLineAborter {
  static void CountLineAborterFunction(const char* msg) {
    while (*msg != 0) {
      if (*msg == '\n') {
        newline_count++;
      }
      msg++;
    }
  }
  static size_t newline_count;
};
size_t CountLineAborter::newline_count = 0;

TEST(logging, LOG_FATAL_ABORTER_MESSAGE) {
  CountLineAborter::newline_count = 0;
  android::base::SetAborter(CountLineAborter::CountLineAborterFunction);

  android::base::ScopedLogSeverity sls(android::base::ERROR);
  CapturedStderr cap;
  LOG(FATAL) << "foo\nbar";

  EXPECT_EQ(CountLineAborter::newline_count, 1U + 1U);  // +1 for final '\n'.
}