1 /*
2 * Copyright (C) 2022 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/prelude/table_functions/ancestor.h"
18
19 #include "src/trace_processor/prelude/table_functions/tables_py.h"
20 #include "test/gtest_and_gmock.h"
21
22 namespace perfetto {
23 namespace trace_processor {
24 namespace {
25
TEST(Ancestor,SliceTableNullConstraint)26 TEST(Ancestor, SliceTableNullConstraint) {
27 // Insert a row to make sure that we are not returning an empty table just
28 // because the source is empty.
29 TraceStorage storage;
30 storage.mutable_slice_table()->Insert({});
31
32 Ancestor generator{Ancestor::Type::kSlice, &storage};
33
34 // Check that if we pass start_id = NULL as a constraint, we correctly return
35 // an empty table.
36 std::unique_ptr<Table> res;
37 Constraint c{tables::AncestorSliceTable::ColumnIndex::start_id, FilterOp::kEq,
38 SqlValue()};
39 base::Status status = generator.ComputeTable({c}, {}, BitVector(), res);
40 ASSERT_TRUE(status.ok());
41 ASSERT_EQ(res->row_count(), 0u);
42 }
43
TEST(Ancestor,CallsiteTableNullConstraint)44 TEST(Ancestor, CallsiteTableNullConstraint) {
45 // Insert a row to make sure that we are not returning an empty table just
46 // because the source is empty.
47 TraceStorage storage;
48 storage.mutable_stack_profile_callsite_table()->Insert({});
49
50 Ancestor generator{Ancestor::Type::kStackProfileCallsite, &storage};
51
52 // Check that if we pass start_id = NULL as a constraint, we correctly return
53 // an empty table.
54 std::unique_ptr<Table> res;
55 Constraint c{tables::AncestorStackProfileCallsiteTable::ColumnIndex::start_id,
56 FilterOp::kEq, SqlValue()};
57 base::Status status = generator.ComputeTable({c}, {}, BitVector(), res);
58 ASSERT_TRUE(status.ok());
59 ASSERT_EQ(res->row_count(), 0u);
60 }
61
TEST(Ancestor,SliceByStackTableNullConstraint)62 TEST(Ancestor, SliceByStackTableNullConstraint) {
63 // Insert a row to make sure that we are not returning an empty table just
64 // because the source is empty.
65 TraceStorage storage;
66 storage.mutable_slice_table()->Insert({});
67
68 Ancestor generator{Ancestor::Type::kSliceByStack, &storage};
69
70 // Check that if we pass start_id = NULL as a constraint, we correctly return
71 // an empty table.
72 std::unique_ptr<Table> res;
73 Constraint c{tables::AncestorSliceTable::ColumnIndex::start_id, FilterOp::kEq,
74 SqlValue()};
75 base::Status status = generator.ComputeTable({c}, {}, BitVector(), res);
76 ASSERT_TRUE(status.ok());
77 ASSERT_EQ(res->row_count(), 0u);
78 }
79
80 } // namespace
81 } // namespace trace_processor
82 } // namespace perfetto
83