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

Commit 9c4b0eee authored by Christopher Ferris's avatar Christopher Ferris
Browse files

Fix potential flaky debuggerd tests.

Some of the tests rely on the fact that a map created for the test
will be listed in the maps part of a tombstone as distinct. However,
if there was an unnamed map that starts right before the test map,
it appears in the tombstone map list as a single larger map and
causes tests to fail. To fix this, name the maps with prctl to
guarantee that these are distinct and will not result in a
combined map in the tombstone.

Bug: 395295765

Test: All unit tests pass.
Change-Id: Ib8a7c6dbfbc810f67fe5e5b9cb7802bbbec2cbba
parent be8bfea0
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -2788,6 +2788,10 @@ TEST_F(CrasherTest, fault_address_between_maps) {
  void* start_ptr =
      mmap(nullptr, 3 * getpagesize(), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  ASSERT_NE(MAP_FAILED, start_ptr);
  // Add a name to guarantee that this map is distinct and not combined in the map listing.
  EXPECT_EQ(
      prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, start_ptr, 3 * getpagesize(), "debuggerd map start"),
      0);
  // Unmap the page in the middle.
  void* middle_ptr =
      reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(start_ptr) + getpagesize());
@@ -2834,6 +2838,8 @@ TEST_F(CrasherTest, fault_address_in_map) {
  // Create a map before the fork so it will be present in the child.
  void* ptr = mmap(nullptr, getpagesize(), 0, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  ASSERT_NE(MAP_FAILED, ptr);
  // Add a name to guarantee that this map is distinct and not combined in the map listing.
  EXPECT_EQ(prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, ptr, getpagesize(), "debuggerd map"), 0);

  StartProcess([ptr]() {
    ASSERT_EQ(0, crash_call(reinterpret_cast<uintptr_t>(ptr)));
@@ -2905,7 +2911,7 @@ TEST_F(CrasherTest, verify_dex_pc_with_function_name) {
        mmap(nullptr, sizeof(kDexData), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
    ASSERT_TRUE(ptr != MAP_FAILED);
    memcpy(ptr, kDexData, sizeof(kDexData));
    prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, ptr, sizeof(kDexData), "dex");
    EXPECT_EQ(prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, ptr, sizeof(kDexData), "dex"), 0);

    JITCodeEntry dex_entry = {.symfile_addr = reinterpret_cast<uintptr_t>(ptr),
                              .symfile_size = sizeof(kDexData)};
@@ -3006,12 +3012,18 @@ TEST_F(CrasherTest, verify_map_format) {
  // Create multiple maps to make sure that the map data is formatted properly.
  void* none_map = mmap(nullptr, getpagesize(), 0, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  ASSERT_NE(MAP_FAILED, none_map);
  // Add names to guarantee that the maps are distinct and not combined in the map listing.
  EXPECT_EQ(prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, none_map, getpagesize(), "debuggerd map none"),
            0);
  void* r_map = mmap(nullptr, getpagesize(), PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  ASSERT_NE(MAP_FAILED, r_map);
  EXPECT_EQ(prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, r_map, getpagesize(), "debuggerd map r"), 0);
  void* w_map = mmap(nullptr, getpagesize(), PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  EXPECT_EQ(prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, w_map, getpagesize(), "debuggerd map w"), 0);
  ASSERT_NE(MAP_FAILED, w_map);
  void* x_map = mmap(nullptr, getpagesize(), PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  ASSERT_NE(MAP_FAILED, x_map);
  EXPECT_EQ(prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, x_map, getpagesize(), "debuggerd map x"), 0);

  TemporaryFile tf;
  ASSERT_EQ(0x2000, lseek(tf.fd, 0x2000, SEEK_SET));
@@ -3046,7 +3058,7 @@ TEST_F(CrasherTest, verify_map_format) {
  std::string match_str;
  // Verify none.
  match_str = android::base::StringPrintf(
      "    %s-%s ---         0      %x\\n",
      "    %s-%s ---         0      %x  \\[anon:debuggerd map none\\]\\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(),
      getpagesize());
@@ -3054,7 +3066,7 @@ TEST_F(CrasherTest, verify_map_format) {

  // Verify read-only.
  match_str = android::base::StringPrintf(
      "    %s-%s r--         0      %x\\n",
      "    %s-%s r--         0      %x  \\[anon:debuggerd map r\\]\\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(),
      getpagesize());
@@ -3062,7 +3074,7 @@ TEST_F(CrasherTest, verify_map_format) {

  // Verify write-only.
  match_str = android::base::StringPrintf(
      "    %s-%s -w-         0      %x\\n",
      "    %s-%s -w-         0      %x  \\[anon:debuggerd map w\\]\\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(),
      getpagesize());
@@ -3070,7 +3082,7 @@ TEST_F(CrasherTest, verify_map_format) {

  // Verify exec-only.
  match_str = android::base::StringPrintf(
      "    %s-%s --x         0      %x\\n",
      "    %s-%s --x         0      %x  \\[anon:debuggerd map 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(),
      getpagesize());