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

Commit aced3aa5 authored by Florian Mayer's avatar Florian Mayer
Browse files

Add tests for android_replace_crash_detail_[name|data]

Bug: 155462331
Change-Id: I1ca4ae6d700dfbaf0bc4e511da0788edd969fca3
parent 5fa66634
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -967,6 +967,52 @@ TEST_F(CrasherTest, crash_detail_single) {
  ASSERT_MATCH(result, R"(CRASH_DETAIL_NAME: 'crash_detail_value')");
}

TEST_F(CrasherTest, crash_detail_replace_data) {
  int intercept_result;
  unique_fd output_fd;
  StartProcess([]() {
    auto *cd = android_register_crash_detail_strs("CRASH_DETAIL_NAME", "original_data");
    android_replace_crash_detail_data(cd, "new_data", strlen("new_data"));
    abort();
  });
  StartIntercept(&output_fd);
  FinishCrasher();
  AssertDeath(SIGABRT);
  FinishIntercept(&intercept_result);

  ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";

  std::string result;
  ConsumeFd(std::move(output_fd), &result);
  ASSERT_MATCH(result, R"(CRASH_DETAIL_NAME: 'new_data')");
  // Ensure the old one no longer shows up, i.e. that we actually replaced
  // it, not added a new one.
  ASSERT_NOT_MATCH(result, R"(CRASH_DETAIL_NAME: 'original_data')");
}

TEST_F(CrasherTest, crash_detail_replace_name) {
  int intercept_result;
  unique_fd output_fd;
  StartProcess([]() {
    auto *cd = android_register_crash_detail_strs("old_name", g_crash_detail_value);
    android_replace_crash_detail_name(cd, "new_name", strlen("new_name"));
    abort();
  });
  StartIntercept(&output_fd);
  FinishCrasher();
  AssertDeath(SIGABRT);
  FinishIntercept(&intercept_result);

  ASSERT_EQ(1, intercept_result) << "tombstoned reported failure";

  std::string result;
  ConsumeFd(std::move(output_fd), &result);
  ASSERT_MATCH(result, R"(new_name: 'crash_detail_value')");
  // Ensure the old one no longer shows up, i.e. that we actually replaced
  // it, not added a new one.
  ASSERT_NOT_MATCH(result, R"(old_name: 'crash_detail_value')");
}

TEST_F(CrasherTest, crash_detail_single_byte_name) {
  int intercept_result;
  unique_fd output_fd;