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/db/table.h"
18 #include "perfetto/ext/base/optional.h"
19 #include "src/trace_processor/db/typed_column.h"
20 #include "src/trace_processor/tables/macros.h"
21 
22 #include "test/gtest_and_gmock.h"
23 
24 namespace perfetto {
25 namespace trace_processor {
26 namespace {
27 
28 constexpr uint32_t kColumnCount = 1024;
29 
Column()30 std::unique_ptr<NullableVector<int64_t>> Column() {
31   auto c =
32       std::unique_ptr<NullableVector<int64_t>>(new NullableVector<int64_t>());
33   for (int64_t i = 0; i < kColumnCount; ++i)
34     c->Append(i);
35   return c;
36 }
37 
Flags()38 uint32_t Flags() {
39   return TypedColumn<int64_t>::default_flags();
40 }
41 
42 #define PERFETTO_TP_TEST_EVENT_TABLE_DEF(NAME, PARENT, C) \
43   NAME(TestEventTable, "event")                           \
44   PARENT(PERFETTO_TP_ROOT_TABLE_PARENT_DEF, C)            \
45   C(int64_t, ts, Column::Flag::kSorted)                   \
46   C(int64_t, arg_set_id)
47 PERFETTO_TP_TABLE(PERFETTO_TP_TEST_EVENT_TABLE_DEF);
48 
49 TestEventTable::~TestEventTable() = default;
50 
TEST(TableTest,ExtendingTableTwice)51 TEST(TableTest, ExtendingTableTwice) {
52   StringPool pool;
53   TestEventTable table{&pool, nullptr};
54 
55   for (uint32_t i = 0; i < kColumnCount; ++i)
56     table.Insert(TestEventTable::Row(i));
57 
58   Table filtered_table;
59   {
60     filtered_table = table.ExtendWithColumn("a", Column(), Flags())
61                          .ExtendWithColumn("b", Column(), Flags())
62                          .Filter({});
63   }
64   ASSERT_TRUE(filtered_table.GetColumnByName("a")->Max().has_value());
65   ASSERT_TRUE(filtered_table.GetColumnByName("b")->Max().has_value());
66 }
67 
68 }  // namespace
69 }  // namespace trace_processor
70 }  // namespace perfetto
71