• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
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 <cstring>
17 #include <gtest/gtest.h>
18 #include "dfx_test_util.h"
19 #include "lperf_events.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 class LperfEventsTest : public testing::Test {
27 public:
28     static void SetUpTestCase();
29     static void TearDownTestCase();
30     void SetUp();
31     void TearDown();
32 };
33 
SetUpTestCase()34 void LperfEventsTest::SetUpTestCase()
35 {}
36 
TearDownTestCase()37 void LperfEventsTest::TearDownTestCase()
38 {}
39 
SetUp()40 void LperfEventsTest::SetUp()
41 {}
42 
TearDown()43 void LperfEventsTest::TearDown()
44 {}
45 
46 /**
47  * @tc.name: LperfEventsTestTest002
48  * @tc.desc: test LperfEvents invalid tids
49  * @tc.type: FUNC
50  */
51 HWTEST_F(LperfEventsTest, LperfEventsTestTest002, TestSize.Level2)
52 {
53     GTEST_LOG_(INFO) << "LperfEventsTestTest002: start.";
54     if (IsLinuxKernel()) {
55         return;
56     }
57     LperfEvents lperfEvents_;
58     lperfEvents_.SetTid({});
59     lperfEvents_.SetTimeOut(100);
60     lperfEvents_.SetSampleFrequency(5000);
61     EXPECT_EQ(lperfEvents_.PrepareRecord(), -1);
62     GTEST_LOG_(INFO) << "LperfEventsTestTest002: end.";
63 }
64 
65 /**
66  * @tc.name: LperfEventsTestTest003
67  * @tc.desc: test LperfEvents invalid freq
68  * @tc.type: FUNC
69  */
70 HWTEST_F(LperfEventsTest, LperfEventsTestTest003, TestSize.Level2)
71 {
72     GTEST_LOG_(INFO) << "LperfEventsTestTest003: start.";
73     if (IsLinuxKernel()) {
74         return;
75     }
76     LperfEvents lperfEvents_;
77     lperfEvents_.SetTid({getpid()});
78     lperfEvents_.SetTimeOut(2000);
79     lperfEvents_.SetSampleFrequency(5000);
80     EXPECT_EQ(lperfEvents_.PrepareRecord(), -1);
81     GTEST_LOG_(INFO) << "LperfEventsTestTest003: end.";
82 }
83 
84 /**
85  * @tc.name: LperfEventsTestTest004
86  * @tc.desc: test LperfEvents invalid freq -1
87  * @tc.type: FUNC
88  */
89 HWTEST_F(LperfEventsTest, LperfEventsTestTest004, TestSize.Level2)
90 {
91     GTEST_LOG_(INFO) << "LperfEventsTestTest004: start.";
92     if (IsLinuxKernel()) {
93         return;
94     }
95     LperfEvents lperfEvents_;
96     lperfEvents_.SetTid({getpid()});
97     lperfEvents_.SetTimeOut(5000);
98     lperfEvents_.SetSampleFrequency(-1);
99     EXPECT_EQ(lperfEvents_.PrepareRecord(), -1);
100     GTEST_LOG_(INFO) << "LperfEventsTestTest004: end.";
101 }
102 
103 /**
104  * @tc.name: LperfEventsTestTest005
105  * @tc.desc: test LperfEvents invalid time
106  * @tc.type: FUNC
107  */
108 HWTEST_F(LperfEventsTest, LperfEventsTestTest005, TestSize.Level2)
109 {
110     GTEST_LOG_(INFO) << "LperfEventsTestTest005: start.";
111     if (IsLinuxKernel()) {
112         return;
113     }
114     LperfEvents lperfEvents_;
115     lperfEvents_.SetTid({getpid()});
116     lperfEvents_.SetTimeOut(20000);
117     lperfEvents_.SetSampleFrequency(100);
118     EXPECT_EQ(lperfEvents_.PrepareRecord(), -1);
119     GTEST_LOG_(INFO) << "LperfEventsTestTest005: end.";
120 }
121 } // namespace HiviewDFX
122 } // namespace OHOS
123