summaryrefslogtreecommitdiff
path: root/tests/malloc_test.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2019-03-01 17:59:51 -0800
committerChristopher Ferris <cferris@google.com>2019-03-07 08:39:55 -0800
commit6c619a0da3f96a26d91c1db48fd3e3be156aabe5 (patch)
treeaa0802d01d19ed0891e6b77a732cc72ed5617dcc /tests/malloc_test.cpp
parent4e167f35d602f9dcede3b74ff3e09e88f3edb398 (diff)
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)
Diffstat (limited to 'tests/malloc_test.cpp')
-rw-r--r--tests/malloc_test.cpp62
1 files changed, 35 insertions, 27 deletions
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index 658f8bdc9..bc6a37b75 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 @@ TEST(malloc, malloc_info) {
auto root = doc.FirstChildElement();
ASSERT_NE(nullptr, root);
ASSERT_STREQ("malloc", root->Name());
- ASSERT_STREQ("jemalloc-1", root->Attribute("version"));
-
- 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));
-
- 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));
+ 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;
+
+ 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));
+ }
}
}
+ } 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
}