Remove static constructors from libmeminfo
This CL changes libmeminfo's API to be less picky about the types of
its inputs and outputs and exposes the list of default memory types as
a constexpr std::array that doesn't need to be constructed as
dlopen time.
Test: tests pass; device boots
Bug: 140456977
Change-Id: Ice45a5400cc77540fb13352bba1adb7737877bcb
diff --git a/libmeminfo/libmeminfo_test.cpp b/libmeminfo/libmeminfo_test.cpp
index 4c2be91..00e139f 100644
--- a/libmeminfo/libmeminfo_test.cpp
+++ b/libmeminfo/libmeminfo_test.cpp
@@ -585,10 +585,10 @@
SysMemInfo mi;
std::string zram_mmstat_dir = exec_dir + "/testdata1/";
- EXPECT_EQ(mi.mem_zram_kb(zram_mmstat_dir), 30504);
+ EXPECT_EQ(mi.mem_zram_kb(zram_mmstat_dir.c_str()), 30504);
std::string zram_memused_dir = exec_dir + "/testdata2/";
- EXPECT_EQ(mi.mem_zram_kb(zram_memused_dir), 30504);
+ EXPECT_EQ(mi.mem_zram_kb(zram_memused_dir.c_str()), 30504);
}
enum {
@@ -660,15 +660,16 @@
ASSERT_TRUE(tf.fd != -1);
ASSERT_TRUE(::android::base::WriteStringToFd(meminfo, tf.fd));
std::string file = std::string(tf.path);
- std::vector<uint64_t> mem(MEMINFO_COUNT);
- std::vector<std::string> tags(SysMemInfo::kDefaultSysMemInfoTags);
+ std::vector<uint64_t> mem;
+ std::vector<std::string_view> tags(SysMemInfo::kDefaultSysMemInfoTags.begin(),
+ SysMemInfo::kDefaultSysMemInfoTags.end());
auto it = tags.begin();
tags.insert(it + MEMINFO_ZRAM_TOTAL, "Zram:");
SysMemInfo mi;
// Read system memory info
- EXPECT_TRUE(mi.ReadMemInfo(tags, &mem, file));
-
+ mem.resize(tags.size());
+ EXPECT_TRUE(mi.ReadMemInfo(tags.size(), tags.data(), mem.data(), file.c_str()));
EXPECT_EQ(mem[MEMINFO_TOTAL], 3019740);
EXPECT_EQ(mem[MEMINFO_FREE], 1809728);
EXPECT_EQ(mem[MEMINFO_BUFFERS], 54736);
@@ -697,7 +698,7 @@
ASSERT_TRUE(::android::base::WriteStringToFd(vmallocinfo, tf.fd));
std::string file = std::string(tf.path);
- EXPECT_EQ(ReadVmallocInfo(file), 0);
+ EXPECT_EQ(ReadVmallocInfo(file.c_str()), 0);
}
TEST(SysMemInfo, TestVmallocInfoKernel) {
@@ -709,7 +710,7 @@
ASSERT_TRUE(::android::base::WriteStringToFd(vmallocinfo, tf.fd));
std::string file = std::string(tf.path);
- EXPECT_EQ(ReadVmallocInfo(file), getpagesize());
+ EXPECT_EQ(ReadVmallocInfo(file.c_str()), getpagesize());
}
TEST(SysMemInfo, TestVmallocInfoModule) {
@@ -721,7 +722,7 @@
ASSERT_TRUE(::android::base::WriteStringToFd(vmallocinfo, tf.fd));
std::string file = std::string(tf.path);
- EXPECT_EQ(ReadVmallocInfo(file), 6 * getpagesize());
+ EXPECT_EQ(ReadVmallocInfo(file.c_str()), 6 * getpagesize());
}
TEST(SysMemInfo, TestVmallocInfoAll) {
@@ -738,7 +739,7 @@
ASSERT_TRUE(::android::base::WriteStringToFd(vmallocinfo, tf.fd));
std::string file = std::string(tf.path);
- EXPECT_EQ(ReadVmallocInfo(file), 7 * getpagesize());
+ EXPECT_EQ(ReadVmallocInfo(file.c_str()), 7 * getpagesize());
}
int main(int argc, char** argv) {