Clean up usage of 32 bit/64 bit checks.
Rather than have to create a number of #if defines for the memory
dumping parts of the tombstone, create a single function to generate
these strings for the memory tests.
Make CrasherTest.smoke use a regex that passes on 32 bit and 64 bit.
Make the tests page size agnostic.
Bug: 339017792
Test: Treehugger.
Test: Ran 32 bit and 64 bit versions of tests on a real device.
Test: Ran on the aosp_cf_x86_64_phone_pgagnostic-trunk_staging-userdebug
Change-Id: If9365061b85de23b00a1bf947d85923cde06c068
diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp
index e4e2f99..baddf65 100644
--- a/debuggerd/debuggerd_test.cpp
+++ b/debuggerd/debuggerd_test.cpp
@@ -332,12 +332,7 @@
std::string result;
ConsumeFd(std::move(output_fd), &result);
-#ifdef __LP64__
- ASSERT_MATCH(result,
- R"(signal 11 \(SIGSEGV\), code 1 \(SEGV_MAPERR\), fault addr 0x000000000000dead)");
-#else
- ASSERT_MATCH(result, R"(signal 11 \(SIGSEGV\), code 1 \(SEGV_MAPERR\), fault addr 0x0000dead)");
-#endif
+ ASSERT_MATCH(result, R"(signal 11 \(SIGSEGV\), code 1 \(SEGV_MAPERR\), fault addr 0x0+dead)");
if (mte_supported()) {
// Test that the default TAGGED_ADDR_CTRL value is set.
@@ -1829,10 +1824,14 @@
"Use After Free, 0 bytes into a 7-byte allocation"},
{/* alloc_size */ 15, /* free_before_access */ true, /* access_offset */ 1,
"Use After Free, 1 byte into a 15-byte allocation"},
- {/* alloc_size */ 4096, /* free_before_access */ false, /* access_offset */ 4098,
- "Buffer Overflow, 2 bytes right of a 4096-byte allocation"},
- {/* alloc_size */ 4096, /* free_before_access */ false, /* access_offset */ -1,
- "Buffer Underflow, 1 byte left of a 4096-byte allocation"},
+ {/* alloc_size */ static_cast<size_t>(getpagesize()), /* free_before_access */ false,
+ /* access_offset */ getpagesize() + 2,
+ android::base::StringPrintf("Buffer Overflow, 2 bytes right of a %d-byte allocation",
+ getpagesize())},
+ {/* alloc_size */ static_cast<size_t>(getpagesize()), /* free_before_access */ false,
+ /* access_offset */ -1,
+ android::base::StringPrintf("Buffer Underflow, 1 byte left of a %d-byte allocation",
+ getpagesize())},
};
INSTANTIATE_TEST_SUITE_P(
@@ -2977,30 +2976,34 @@
std::string match_str;
// Verify none.
match_str = android::base::StringPrintf(
- " %s-%s --- 0 1000\\n",
+ " %s-%s --- 0 %x\\n",
format_map_pointer(reinterpret_cast<uintptr_t>(none_map)).c_str(),
- format_map_pointer(reinterpret_cast<uintptr_t>(none_map) + getpagesize() - 1).c_str());
+ format_map_pointer(reinterpret_cast<uintptr_t>(none_map) + getpagesize() - 1).c_str(),
+ getpagesize());
ASSERT_MATCH(result, match_str);
// Verify read-only.
match_str = android::base::StringPrintf(
- " %s-%s r-- 0 1000\\n",
+ " %s-%s r-- 0 %x\\n",
format_map_pointer(reinterpret_cast<uintptr_t>(r_map)).c_str(),
- format_map_pointer(reinterpret_cast<uintptr_t>(r_map) + getpagesize() - 1).c_str());
+ format_map_pointer(reinterpret_cast<uintptr_t>(r_map) + getpagesize() - 1).c_str(),
+ getpagesize());
ASSERT_MATCH(result, match_str);
// Verify write-only.
match_str = android::base::StringPrintf(
- " %s-%s -w- 0 1000\\n",
+ " %s-%s -w- 0 %x\\n",
format_map_pointer(reinterpret_cast<uintptr_t>(w_map)).c_str(),
- format_map_pointer(reinterpret_cast<uintptr_t>(w_map) + getpagesize() - 1).c_str());
+ format_map_pointer(reinterpret_cast<uintptr_t>(w_map) + getpagesize() - 1).c_str(),
+ getpagesize());
ASSERT_MATCH(result, match_str);
// Verify exec-only.
match_str = android::base::StringPrintf(
- " %s-%s --x 0 1000\\n",
+ " %s-%s --x 0 %x\\n",
format_map_pointer(reinterpret_cast<uintptr_t>(x_map)).c_str(),
- format_map_pointer(reinterpret_cast<uintptr_t>(x_map) + getpagesize() - 1).c_str());
+ format_map_pointer(reinterpret_cast<uintptr_t>(x_map) + getpagesize() - 1).c_str(),
+ getpagesize());
ASSERT_MATCH(result, match_str);
// Verify file map with non-zero offset and a name.