Refactor the malloc_info code.
malloc_info needs to be per native allocator, but the code treated it
like a global function that doesn't depend on the native memory allocator.
Update malloc debug to dump the actual pointers that it has been tracking.
Test: bionic-unit-tests pass.
Test: malloc debug tests pass.
Test: malloc hook tests pass.
Change-Id: I3b0d4d748489dd84c16d16933479dc8b8d79013e
Merged-In: I3b0d4d748489dd84c16d16933479dc8b8d79013e
(cherry picked from commit a3656a98b10d2a4a6194a5d9705ad9c2cc5877b0)
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index 658f8bd..bc6a37b 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -19,6 +19,7 @@
#include <elf.h>
#include <limits.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <unistd.h>
@@ -348,35 +349,42 @@
auto root = doc.FirstChildElement();
ASSERT_NE(nullptr, root);
ASSERT_STREQ("malloc", root->Name());
- ASSERT_STREQ("jemalloc-1", root->Attribute("version"));
+ if (std::string(root->Attribute("version")) == "jemalloc-1") {
+ // Verify jemalloc version of this data.
+ ASSERT_STREQ("jemalloc-1", root->Attribute("version"));
- auto arena = root->FirstChildElement();
- for (; arena != nullptr; arena = arena->NextSiblingElement()) {
- int val;
+ auto arena = root->FirstChildElement();
+ for (; arena != nullptr; arena = arena->NextSiblingElement()) {
+ int val;
- ASSERT_STREQ("heap", arena->Name());
- ASSERT_EQ(tinyxml2::XML_SUCCESS, arena->QueryIntAttribute("nr", &val));
- ASSERT_EQ(tinyxml2::XML_SUCCESS,
- arena->FirstChildElement("allocated-large")->QueryIntText(&val));
- ASSERT_EQ(tinyxml2::XML_SUCCESS,
- arena->FirstChildElement("allocated-huge")->QueryIntText(&val));
- ASSERT_EQ(tinyxml2::XML_SUCCESS,
- arena->FirstChildElement("allocated-bins")->QueryIntText(&val));
- ASSERT_EQ(tinyxml2::XML_SUCCESS,
- arena->FirstChildElement("bins-total")->QueryIntText(&val));
+ ASSERT_STREQ("heap", arena->Name());
+ ASSERT_EQ(tinyxml2::XML_SUCCESS, arena->QueryIntAttribute("nr", &val));
+ ASSERT_EQ(tinyxml2::XML_SUCCESS,
+ arena->FirstChildElement("allocated-large")->QueryIntText(&val));
+ ASSERT_EQ(tinyxml2::XML_SUCCESS,
+ arena->FirstChildElement("allocated-huge")->QueryIntText(&val));
+ ASSERT_EQ(tinyxml2::XML_SUCCESS,
+ arena->FirstChildElement("allocated-bins")->QueryIntText(&val));
+ ASSERT_EQ(tinyxml2::XML_SUCCESS,
+ arena->FirstChildElement("bins-total")->QueryIntText(&val));
- auto bin = arena->FirstChildElement("bin");
- for (; bin != nullptr; bin = bin ->NextSiblingElement()) {
- if (strcmp(bin->Name(), "bin") == 0) {
- ASSERT_EQ(tinyxml2::XML_SUCCESS, bin->QueryIntAttribute("nr", &val));
- ASSERT_EQ(tinyxml2::XML_SUCCESS,
- bin->FirstChildElement("allocated")->QueryIntText(&val));
- ASSERT_EQ(tinyxml2::XML_SUCCESS,
- bin->FirstChildElement("nmalloc")->QueryIntText(&val));
- ASSERT_EQ(tinyxml2::XML_SUCCESS,
- bin->FirstChildElement("ndalloc")->QueryIntText(&val));
+ auto bin = arena->FirstChildElement("bin");
+ for (; bin != nullptr; bin = bin ->NextSiblingElement()) {
+ if (strcmp(bin->Name(), "bin") == 0) {
+ ASSERT_EQ(tinyxml2::XML_SUCCESS, bin->QueryIntAttribute("nr", &val));
+ ASSERT_EQ(tinyxml2::XML_SUCCESS,
+ bin->FirstChildElement("allocated")->QueryIntText(&val));
+ ASSERT_EQ(tinyxml2::XML_SUCCESS,
+ bin->FirstChildElement("nmalloc")->QueryIntText(&val));
+ ASSERT_EQ(tinyxml2::XML_SUCCESS,
+ bin->FirstChildElement("ndalloc")->QueryIntText(&val));
+ }
}
}
+ } else {
+ // Only verify that this is debug-malloc-1, the malloc debug unit tests
+ // verify the output.
+ ASSERT_STREQ("debug-malloc-1", root->Attribute("version"));
}
#endif
}