diff options
author | Dan Albert <danalbert@google.com> | 2014-08-20 09:16:57 -0700 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2014-08-22 10:23:12 -0700 |
commit | 4caa1f09770ea3e5ca22afbe8aa0900810a0dbfe (patch) | |
tree | 2bda183c2c930871e73486ea3e9c54e80e500f95 /tests/malloc_test.cpp | |
parent | d5fbc37119ef6cd757ceb449cb071ee03c66590e (diff) |
Implement malloc_info(3).
Expose jemalloc stats through the malloc_info(3) interface.
Bug: 16874689
Change-Id: I4358ac283002e60ff161107028d1a3fb1e9afb0a
Diffstat (limited to 'tests/malloc_test.cpp')
-rw-r--r-- | tests/malloc_test.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp index 6b7a28b1c..b76625a7a 100644 --- a/tests/malloc_test.cpp +++ b/tests/malloc_test.cpp @@ -22,6 +22,8 @@ #include <malloc.h> #include <unistd.h> +#include <tinyxml2.h> + #include "private/bionic_config.h" TEST(malloc, malloc_std) { @@ -322,3 +324,51 @@ TEST(malloc, valloc_overflow) { ASSERT_EQ(NULL, valloc(SIZE_MAX)); } #endif + +TEST(malloc, malloc_info) { +#ifdef __BIONIC__ + char* buf; + size_t bufsize; + FILE* memstream = open_memstream(&buf, &bufsize); + ASSERT_NE(nullptr, memstream); + ASSERT_EQ(0, malloc_info(0, memstream)); + ASSERT_EQ(0, fclose(memstream)); + + tinyxml2::XMLDocument doc; + ASSERT_EQ(tinyxml2::XML_SUCCESS, doc.Parse(buf)); + + 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)); + } + } + } +#endif +} |