MappedMemoryRegion::EXECUTE | MappedMemoryRegion::PRIVATE},
};
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
+ for (size_t i = 0; i < arraysize(kTestCases); ++i) {
SCOPED_TRACE(
base::StringPrintf("kTestCases[%zu] = %s", i, kTestCases[i].input));
}
TEST(ProcMapsTest, MissingFields) {
- static const char* kTestCases[] = {
+ static const char* const kTestCases[] = {
"00400000\n", // Missing end + beyond.
"00400000-0040b000\n", // Missing perms + beyond.
"00400000-0040b000 r-xp\n", // Missing offset + beyond.
}
TEST(ProcMapsTest, InvalidInput) {
- static const char* kTestCases[] = {
+ static const char* const kTestCases[] = {
"thisisal-0040b000 rwxp 00000000 fc:00 794418 /bin/cat\n",
"0040000d-linvalid rwxp 00000000 fc:00 794418 /bin/cat\n",
"00400000-0040b000 inpu 00000000 fc:00 794418 /bin/cat\n",
}
}
+TEST(ProcMapsTest, ParseProcMapsEmptyString) {
+ std::vector<MappedMemoryRegion> regions;
+ EXPECT_TRUE(ParseProcMaps("", ®ions));
+ EXPECT_EQ(0ULL, regions.size());
+}
+
+// Testing a couple of remotely possible weird things in the input:
+// - Line ending with \r\n or \n\r.
+// - File name contains quotes.
+// - File name has whitespaces.
+TEST(ProcMapsTest, ParseProcMapsWeirdCorrectInput) {
+ std::vector<MappedMemoryRegion> regions;
+ const std::string kContents =
+ "00400000-0040b000 r-xp 00000000 fc:00 2106562 "
+ " /bin/cat\r\n"
+ "7f53b7dad000-7f53b7f62000 r-xp 00000000 fc:00 263011 "
+ " /lib/x86_64-linux-gnu/libc-2.15.so\n\r"
+ "7f53b816d000-7f53b818f000 r-xp 00000000 fc:00 264284 "
+ " /lib/x86_64-linux-gnu/ld-2.15.so\n"
+ "7fff9c7ff000-7fff9c800000 r-xp 00000000 00:00 0 "
+ " \"vd so\"\n"
+ "ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 "
+ " [vsys call]\n";
+ EXPECT_TRUE(ParseProcMaps(kContents, ®ions));
+ EXPECT_EQ(5ULL, regions.size());
+ EXPECT_EQ("/bin/cat", regions[0].path);
+ EXPECT_EQ("/lib/x86_64-linux-gnu/libc-2.15.so", regions[1].path);
+ EXPECT_EQ("/lib/x86_64-linux-gnu/ld-2.15.so", regions[2].path);
+ EXPECT_EQ("\"vd so\"", regions[3].path);
+ EXPECT_EQ("[vsys call]", regions[4].path);
+}
+
} // namespace debug
} // namespace base