aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Yi <byi@google.com>2018-11-28 18:34:20 -0800
committerBill Yi <byi@google.com>2018-11-28 18:34:20 -0800
commit9dd0f2cfb1e696da77a76472dd63d1ca25b8b964 (patch)
tree4c03e4372ba0c8cc83880b65bb608d16442753e3
parentf33903d03a446fd2ccdf4c8ee169ca9420cb6d17 (diff)
parente77a930cda3ed425416694aaa87cebdedfb66d39 (diff)
downloadperfetto-pie-platform-release.tar.gz
Merge pi-qpr1-release PQ1A.181105.017.A1 to pi-platform-releasepie-platform-releasepie-cuttlefish-testing
Change-Id: I9efa98649f303c655eea58ea87dcc70fe2d58e6d
-rw-r--r--src/ftrace_reader/ftrace_procfs.cc2
-rw-r--r--src/ftrace_reader/ftrace_procfs_unittest.cc36
2 files changed, 38 insertions, 0 deletions
diff --git a/src/ftrace_reader/ftrace_procfs.cc b/src/ftrace_reader/ftrace_procfs.cc
index 70aa050e0..bcc255748 100644
--- a/src/ftrace_reader/ftrace_procfs.cc
+++ b/src/ftrace_reader/ftrace_procfs.cc
@@ -170,6 +170,8 @@ std::set<std::string> FtraceProcfs::AvailableClocks() {
end = s.find(' ', start);
if (end == std::string::npos)
end = s.size();
+ while (end > start && s[end - 1] == '\n')
+ end--;
if (start == end)
break;
diff --git a/src/ftrace_reader/ftrace_procfs_unittest.cc b/src/ftrace_reader/ftrace_procfs_unittest.cc
index bccf2e052..6c86339dc 100644
--- a/src/ftrace_reader/ftrace_procfs_unittest.cc
+++ b/src/ftrace_reader/ftrace_procfs_unittest.cc
@@ -56,8 +56,44 @@ TEST(FtraceProcfsTest, ParseAvailableClocks) {
EXPECT_THAT(ftrace.GetClock(), "global");
EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock"))
+ .WillOnce(Return("local global [boot]"));
+ EXPECT_THAT(ftrace.GetClock(), "boot");
+
+ EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock"))
.WillOnce(Return(""));
EXPECT_THAT(ftrace.AvailableClocks(), IsEmpty());
+
+ // trace_clock text may end in a new line:
+ EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock"))
+ .WillOnce(Return("[local] global boot\n"));
+ EXPECT_THAT(ftrace.AvailableClocks(),
+ UnorderedElementsAre("local", "global", "boot"));
+
+ EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock"))
+ .WillOnce(Return("local global [boot]\n"));
+ EXPECT_THAT(ftrace.AvailableClocks(),
+ UnorderedElementsAre("local", "global", "boot"));
+
+ EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock"))
+ .WillOnce(Return("local global [boot]\n"));
+ EXPECT_THAT(ftrace.GetClock(), "boot");
+
+ EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock"))
+ .WillOnce(Return("\n"));
+ EXPECT_THAT(ftrace.AvailableClocks(), IsEmpty());
+
+ // We should handle many newlines (just in case):
+ EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock"))
+ .WillOnce(Return("local global [boot]\n\n\n"));
+ EXPECT_THAT(ftrace.GetClock(), "boot");
+
+ EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock"))
+ .WillOnce(Return("local global [boot]\n\n"));
+ EXPECT_THAT(ftrace.GetClock(), "boot");
+
+ EXPECT_CALL(ftrace, ReadFileIntoString("/root/trace_clock"))
+ .WillOnce(Return("\n\n\n\n"));
+ EXPECT_THAT(ftrace.AvailableClocks(), IsEmpty());
}
} // namespace