Merge changes from topics "crashapi2", "crashapi3" into main

* changes:
  use new location of crash_detail API
  Add tests for android_replace_crash_detail_[name|data]
This commit is contained in:
Treehugger Robot 2024-02-21 07:42:42 +00:00 committed by Gerrit Code Review
commit acafa40d82
2 changed files with 52 additions and 5 deletions

View file

@ -37,6 +37,7 @@
#include <string>
#include <thread>
#include <android/crash_detail.h>
#include <android/dlext.h>
#include <android/fdsan.h>
#include <android/set_abort_message.h>
@ -945,7 +946,7 @@ static char g_crash_detail_value2[] = "crash_detail_value2";
inline crash_detail_t* _Nullable android_register_crash_detail_strs(const char* _Nonnull name,
const char* _Nonnull data) {
return android_register_crash_detail(name, strlen(name), data, strlen(data));
return android_crash_detail_register(name, strlen(name), data, strlen(data));
}
TEST_F(CrasherTest, crash_detail_single) {
@ -967,6 +968,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_crash_detail_replace_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_crash_detail_replace_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;
@ -991,7 +1038,7 @@ TEST_F(CrasherTest, crash_detail_single_bytes) {
int intercept_result;
unique_fd output_fd;
StartProcess([]() {
android_register_crash_detail("CRASH_DETAIL_NAME", strlen("CRASH_DETAIL_NAME"), "\1",
android_crash_detail_register("CRASH_DETAIL_NAME", strlen("CRASH_DETAIL_NAME"), "\1",
sizeof("\1"));
abort();
});
@ -1035,7 +1082,7 @@ TEST_F(CrasherTest, crash_detail_many) {
std::string name = "CRASH_DETAIL_NAME" + std::to_string(i);
std::string value = "CRASH_DETAIL_VALUE" + std::to_string(i);
auto* h = android_register_crash_detail_strs(name.data(), value.data());
android_unregister_crash_detail(h);
android_crash_detail_unregister(h);
}
android_register_crash_detail_strs("FINAL_NAME", "FINAL_VALUE");
@ -1103,7 +1150,7 @@ TEST_F(CrasherTest, crash_detail_remove) {
unique_fd output_fd;
StartProcess([]() {
auto* detail1 = android_register_crash_detail_strs("CRASH_DETAIL_NAME", g_crash_detail_value);
android_unregister_crash_detail(detail1);
android_crash_detail_unregister(detail1);
android_register_crash_detail_strs("CRASH_DETAIL_NAME2", g_crash_detail_value2);
abort();
});

View file

@ -51,7 +51,7 @@
#include <android/set_abort_message.h>
#include <bionic/macros.h>
#include <bionic/reserved_signals.h>
#include <bionic/set_abort_message_internal.h>
#include <bionic/crash_detail_internal.h>
#include <log/log.h>
#include <log/log_read.h>
#include <log/logprint.h>