• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <hwext/gtest-ext.h>
17 #include <hwext/gtest-tag.h>
18 
19 #include "filter_filter.h"
20 #include "trace_data_cache.h"
21 #include "trace_streamer_filters.h"
22 
23 using namespace testing::ext;
24 using namespace SysTuning::TraceStreamer;
25 namespace SysTuning {
26 namespace TraceStreamer {
27 class FilterFilterTest : public ::testing::Test {
28 public:
SetUp()29     void SetUp()
30     {
31         streamFilters_.filterFilter_ = std::make_unique<FilterFilter>(&traceDataCache_, &streamFilters_);
32     }
33 
TearDown()34     void TearDown() {}
35 
36 public:
37     TraceStreamerFilters streamFilters_;
38     TraceDataCache traceDataCache_;
39 };
40 
41 /**
42  * @tc.name: AddCpuCounterFilter
43  * @tc.desc: Add cpu_counter_filter through AddFilter interface
44  * @tc.type: FUNC
45  */
46 HWTEST_F(FilterFilterTest, AddCpuCounterFilter, TestSize.Level1)
47 {
48     TS_LOGI("test6-1");
49     uint32_t filterId = streamFilters_.filterFilter_->AddFilter("cpu_counter_filter", "cpu1", 1);
50     EXPECT_EQ(filterId, static_cast<uint32_t>(0));
51 
52     filterId = streamFilters_.filterFilter_->AddFilter("cpu_counter_filter", "cpu2", 2);
53     EXPECT_EQ(filterId, static_cast<uint32_t>(1));
54 
55     Filter *filterTable = traceDataCache_.GetFilterData();
56     EXPECT_EQ(filterTable->Size(), static_cast<size_t>(2));
57 }
58 
59 /**
60  * @tc.name: AddThreadFilter
61  * @tc.desc: Add thread_counter_filter & thread_filter through AddFilter interface
62  * @tc.type: FUNC
63  */
64 HWTEST_F(FilterFilterTest, AddThreadFilter, TestSize.Level1)
65 {
66     TS_LOGI("test6-2");
67     uint32_t threadFilterId = streamFilters_.filterFilter_->AddFilter("thread_counter_filter", "threadCount1", 1);
68     EXPECT_EQ(threadFilterId, static_cast<uint32_t>(0));
69 
70     threadFilterId = streamFilters_.filterFilter_->AddFilter("thread_counter_filter", "threadCount2", 2);
71     EXPECT_EQ(threadFilterId, static_cast<uint32_t>(1));
72 
73     Filter *filterTable = traceDataCache_.GetFilterData();
74     EXPECT_EQ(filterTable->Size(), static_cast<size_t>(2));
75 
76     threadFilterId = streamFilters_.filterFilter_->AddFilter("thread_filter", "thread1", 1);
77     EXPECT_EQ(threadFilterId, static_cast<uint32_t>(2));
78 
79     threadFilterId = streamFilters_.filterFilter_->AddFilter("thread_filter", "thread2", 2);
80     EXPECT_EQ(threadFilterId, static_cast<uint32_t>(3));
81 
82     EXPECT_EQ(filterTable->Size(), static_cast<size_t>(4));
83 }
84 } // namespace TraceStreamer
85 } // namespace SysTuning
86