1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "src/traced/probes/ftrace/cpu_stats_parser.h"
18 
19 #include "src/traced/probes/ftrace/ftrace_controller.h"
20 #include "src/traced/probes/ftrace/ftrace_stats.h"
21 #include "test/gtest_and_gmock.h"
22 
23 namespace perfetto {
24 namespace {
25 
TEST(CpuStatsParserTest,DumpCpu)26 TEST(CpuStatsParserTest, DumpCpu) {
27   std::string text = R"(entries: 1
28 overrun: 2
29 commit overrun: 3
30 bytes: 4
31 oldest event ts:     5123.000
32 now ts:  6123.123
33 dropped events	 	:7
34 read events: 8
35 )";
36 
37   FtraceCpuStats stats{};
38   EXPECT_TRUE(DumpCpuStats(text, &stats));
39 
40   EXPECT_EQ(stats.entries, 1u);
41   EXPECT_EQ(stats.overrun, 2u);
42   EXPECT_EQ(stats.commit_overrun, 3u);
43   EXPECT_EQ(stats.bytes_read, 4u);
44   EXPECT_DOUBLE_EQ(stats.oldest_event_ts, 5123.0);
45   EXPECT_DOUBLE_EQ(stats.now_ts, 6123.123);
46   EXPECT_EQ(stats.dropped_events, 7u);
47   EXPECT_EQ(stats.read_events, 8u);
48 }
49 
50 }  // namespace
51 }  // namespace perfetto
52