diff options
author | Bill Yi <byi@google.com> | 2018-11-28 18:34:20 -0800 |
---|---|---|
committer | Bill Yi <byi@google.com> | 2018-11-28 18:34:20 -0800 |
commit | 9dd0f2cfb1e696da77a76472dd63d1ca25b8b964 (patch) | |
tree | 4c03e4372ba0c8cc83880b65bb608d16442753e3 | |
parent | f33903d03a446fd2ccdf4c8ee169ca9420cb6d17 (diff) | |
parent | e77a930cda3ed425416694aaa87cebdedfb66d39 (diff) | |
download | perfetto-pie-cuttlefish-testing.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.cc | 2 | ||||
-rw-r--r-- | src/ftrace_reader/ftrace_procfs_unittest.cc | 36 |
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 |