Lalit Maganti | f7a1a73 | 2020-10-12 15:42:34 +0100 | [diff] [blame] | 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/importers/proto/async_track_set_tracker.h" |
| 18 | |
Lalit Maganti | 8021d0a | 2020-12-07 17:41:34 +0000 | [diff] [blame^] | 19 | #include "src/trace_processor/importers/common/args_tracker.h" |
| 20 | #include "src/trace_processor/importers/common/global_args_tracker.h" |
Lalit Maganti | f7a1a73 | 2020-10-12 15:42:34 +0100 | [diff] [blame] | 21 | #include "src/trace_processor/importers/common/track_tracker.h" |
| 22 | #include "src/trace_processor/types/trace_processor_context.h" |
| 23 | #include "test/gtest_and_gmock.h" |
| 24 | |
| 25 | namespace perfetto { |
| 26 | namespace trace_processor { |
| 27 | namespace { |
| 28 | |
Lalit Maganti | 8021d0a | 2020-12-07 17:41:34 +0000 | [diff] [blame^] | 29 | class AsyncTrackSetTrackerUnittest : public testing::Test { |
Lalit Maganti | f7a1a73 | 2020-10-12 15:42:34 +0100 | [diff] [blame] | 30 | public: |
| 31 | AsyncTrackSetTrackerUnittest() { |
| 32 | context_.storage.reset(new TraceStorage()); |
Lalit Maganti | 8021d0a | 2020-12-07 17:41:34 +0000 | [diff] [blame^] | 33 | context_.global_args_tracker.reset(new GlobalArgsTracker(&context_)); |
| 34 | context_.args_tracker.reset(new ArgsTracker(&context_)); |
Lalit Maganti | f7a1a73 | 2020-10-12 15:42:34 +0100 | [diff] [blame] | 35 | context_.track_tracker.reset(new TrackTracker(&context_)); |
| 36 | context_.async_track_set_tracker.reset(new AsyncTrackSetTracker(&context_)); |
| 37 | |
| 38 | storage_ = context_.storage.get(); |
| 39 | tracker_ = context_.async_track_set_tracker.get(); |
| 40 | } |
| 41 | |
| 42 | protected: |
| 43 | TraceStorage* storage_ = nullptr; |
| 44 | AsyncTrackSetTracker* tracker_ = nullptr; |
| 45 | |
| 46 | private: |
| 47 | TraceProcessorContext context_; |
| 48 | }; |
| 49 | |
| 50 | TEST_F(AsyncTrackSetTrackerUnittest, Smoke) { |
| 51 | auto set_id = tracker_->InternAndroidSet(1, storage_->InternString("test")); |
| 52 | |
| 53 | auto begin = tracker_->Begin( |
| 54 | set_id, 1, |
Lalit Maganti | 8021d0a | 2020-12-07 17:41:34 +0000 | [diff] [blame^] | 55 | AsyncTrackSetTracker::NestingBehaviour::kLegacySaturatingUnnestable); |
Lalit Maganti | f7a1a73 | 2020-10-12 15:42:34 +0100 | [diff] [blame] | 56 | auto end = tracker_->End(set_id, 1); |
| 57 | |
| 58 | ASSERT_EQ(begin, end); |
| 59 | |
| 60 | uint32_t row = *storage_->process_track_table().id().IndexOf(begin); |
Lalit Maganti | 8021d0a | 2020-12-07 17:41:34 +0000 | [diff] [blame^] | 61 | ASSERT_EQ(storage_->process_track_table().upid()[row], 1u); |
Lalit Maganti | f7a1a73 | 2020-10-12 15:42:34 +0100 | [diff] [blame] | 62 | ASSERT_EQ(storage_->process_track_table().name()[row], |
| 63 | storage_->InternString("test")); |
| 64 | } |
| 65 | |
| 66 | TEST_F(AsyncTrackSetTrackerUnittest, EndFirst) { |
| 67 | auto set_id = tracker_->InternAndroidSet(1, storage_->InternString("test")); |
| 68 | auto end = tracker_->End(set_id, 1); |
| 69 | |
| 70 | uint32_t row = *storage_->process_track_table().id().IndexOf(end); |
Lalit Maganti | 8021d0a | 2020-12-07 17:41:34 +0000 | [diff] [blame^] | 71 | ASSERT_EQ(storage_->process_track_table().upid()[row], 1u); |
Lalit Maganti | f7a1a73 | 2020-10-12 15:42:34 +0100 | [diff] [blame] | 72 | ASSERT_EQ(storage_->process_track_table().name()[row], |
| 73 | storage_->InternString("test")); |
| 74 | } |
| 75 | |
| 76 | TEST_F(AsyncTrackSetTrackerUnittest, LegacySaturating) { |
| 77 | auto set_id = tracker_->InternAndroidSet(1, storage_->InternString("test")); |
| 78 | |
| 79 | auto begin = tracker_->Begin( |
| 80 | set_id, 1, |
Lalit Maganti | 8021d0a | 2020-12-07 17:41:34 +0000 | [diff] [blame^] | 81 | AsyncTrackSetTracker::NestingBehaviour::kLegacySaturatingUnnestable); |
Lalit Maganti | f7a1a73 | 2020-10-12 15:42:34 +0100 | [diff] [blame] | 82 | auto begin_2 = tracker_->Begin( |
| 83 | set_id, 1, |
Lalit Maganti | 8021d0a | 2020-12-07 17:41:34 +0000 | [diff] [blame^] | 84 | AsyncTrackSetTracker::NestingBehaviour::kLegacySaturatingUnnestable); |
Lalit Maganti | f7a1a73 | 2020-10-12 15:42:34 +0100 | [diff] [blame] | 85 | |
| 86 | ASSERT_EQ(begin, begin_2); |
| 87 | } |
| 88 | |
Lalit Maganti | 8021d0a | 2020-12-07 17:41:34 +0000 | [diff] [blame^] | 89 | TEST_F(AsyncTrackSetTrackerUnittest, Unnestable) { |
| 90 | auto set_id = tracker_->InternAndroidSet(1, storage_->InternString("test")); |
| 91 | |
| 92 | auto begin = tracker_->Begin( |
| 93 | set_id, 1, AsyncTrackSetTracker::NestingBehaviour::kUnnestable); |
| 94 | auto end = tracker_->End(set_id, 1); |
| 95 | auto begin_2 = tracker_->Begin( |
| 96 | set_id, 1, AsyncTrackSetTracker::NestingBehaviour::kUnnestable); |
| 97 | |
| 98 | ASSERT_EQ(begin, end); |
| 99 | ASSERT_EQ(begin, begin_2); |
| 100 | } |
| 101 | |
| 102 | TEST_F(AsyncTrackSetTrackerUnittest, UnnestableMultipleEndAfterBegin) { |
| 103 | auto set_id = tracker_->InternAndroidSet(1, storage_->InternString("test")); |
| 104 | |
| 105 | auto begin = tracker_->Begin( |
| 106 | set_id, 1, AsyncTrackSetTracker::NestingBehaviour::kUnnestable); |
| 107 | auto end = tracker_->End(set_id, 1); |
| 108 | auto end_2 = tracker_->End(set_id, 1); |
| 109 | |
| 110 | ASSERT_EQ(begin, end); |
| 111 | ASSERT_EQ(end, end_2); |
| 112 | } |
| 113 | |
Lalit Maganti | f7a1a73 | 2020-10-12 15:42:34 +0100 | [diff] [blame] | 114 | } // namespace |
| 115 | } // namespace trace_processor |
| 116 | } // namespace perfetto |