1 /*
2  * Copyright (C) 2020 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/trace_processor/dynamic/experimental_counter_dur_generator.h"
18 
19 #include "test/gtest_and_gmock.h"
20 
21 namespace perfetto {
22 namespace trace_processor {
23 namespace {
24 
CounterRow(int64_t ts,uint32_t track_id)25 tables::CounterTable::Row CounterRow(int64_t ts, uint32_t track_id) {
26   tables::CounterTable::Row row;
27   row.ts = ts;
28   row.track_id = tables::TrackTable::Id{track_id};
29   return row;
30 }
31 
TEST(ExperimentalCounterDurGenerator,SmokeDur)32 TEST(ExperimentalCounterDurGenerator, SmokeDur) {
33   StringPool pool;
34   tables::CounterTable table(&pool, nullptr);
35 
36   table.Insert(CounterRow(100 /* ts */, 1 /* track_id */));
37   table.Insert(CounterRow(102 /* ts */, 2 /* track_id */));
38   table.Insert(CounterRow(105 /* ts */, 1 /* track_id */));
39   table.Insert(CounterRow(105 /* ts */, 3 /* track_id */));
40   table.Insert(CounterRow(105 /* ts */, 2 /* track_id */));
41   table.Insert(CounterRow(110 /* ts */, 2 /* track_id */));
42 
43   auto dur = ExperimentalCounterDurGenerator::ComputeDurColumn(table);
44   ASSERT_EQ(dur.size(), table.row_count());
45 
46   ASSERT_EQ(dur.GetNonNull(0), 5);
47   ASSERT_EQ(dur.GetNonNull(1), 3);
48   ASSERT_EQ(dur.GetNonNull(2), -1);
49   ASSERT_EQ(dur.GetNonNull(3), -1);
50   ASSERT_EQ(dur.GetNonNull(4), 5);
51   ASSERT_EQ(dur.GetNonNull(5), -1);
52 }
53 
54 }  // namespace
55 }  // namespace trace_processor
56 }  // namespace perfetto
57