• 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 #include <gtest/gtest.h>
16 #include "dump_common_utils.h"
17 using namespace std;
18 using namespace testing::ext;
19 using namespace OHOS;
20 using namespace OHOS::HiviewDFX;
21 namespace OHOS {
22 namespace HiviewDFX {
23 class DumpCommonUtilsTest : public testing::Test {
24 public:
25     static void SetUpTestCase(void);
26     static void TearDownTestCase(void);
27     void SetUp();
28     void TearDown();
29 };
30 
SetUpTestCase(void)31 void DumpCommonUtilsTest::SetUpTestCase(void)
32 {
33 }
34 
TearDownTestCase(void)35 void DumpCommonUtilsTest::TearDownTestCase(void)
36 {
37 }
38 
SetUp(void)39 void DumpCommonUtilsTest::SetUp(void)
40 {
41 }
42 
TearDown(void)43 void DumpCommonUtilsTest::TearDown(void)
44 {
45 }
46 
47 /**
48  * @tc.name: FindFdClusterStartIndexTest
49  * @tc.desc: Output the FD path of clustering rules.
50  * @tc.type: FUNC
51  */
52 HWTEST_F(DumpCommonUtilsTest, FindFdClusterStartIndexTest, TestSize.Level3)
53 {
54     const string fdLinkPath1 = "/data/storage/el2/testFd/1/mockfdLinkPath";
55     int index1 = DumpCommonUtils::FindFdClusterStartIndex(fdLinkPath1);
56     std::string targetPath1(fdLinkPath1, 0, index1);
57     printf("targetPath1 %s\n", targetPath1.c_str());
58     ASSERT_TRUE(targetPath1 == "/data/storage/el2/testFd/");
59 
60     const string fdLinkPath2 = "/data/storage/el2/testFd/a/mockfdLinkPath";
61     int index2 = DumpCommonUtils::FindFdClusterStartIndex(fdLinkPath2);
62     std::string targetPath2(fdLinkPath2, 0, index2);
63     printf("targetPath2 %s\n", targetPath2.c_str());
64     ASSERT_TRUE(targetPath2 == "/data/storage/el2/testFd/a/mockfdLinkPath");
65 }
66 
67 /**
68  * @tc.name: FindNoSandBoxPathIndexTest
69  * @tc.desc: Output the sandbox path of clustering rules.
70  * @tc.type: FUNC
71  */
72 HWTEST_F(DumpCommonUtilsTest, FindNonSandBoxPathIndexTest, TestSize.Level3)
73 {
74     const string fdLinkPath1 = "/data/storage/ela/testFd/1/mockfdLinkPath";
75     int index1 = DumpCommonUtils::FindNonSandBoxPathIndex(fdLinkPath1);
76     std::string targetPath1(fdLinkPath1, 0, index1);
77     printf("targetPath1 %s\n", targetPath1.c_str());
78     ASSERT_TRUE(targetPath1 == "/data/storage/ela/testFd/");
79 
80     const string fdLinkPath2 = "/data/storage/ela/testFd/a/mockfdLinkPath";
81     int index2 = DumpCommonUtils::FindNonSandBoxPathIndex(fdLinkPath2);
82     std::string targetPath2(fdLinkPath2, 0, index2);
83     printf("targetPath2 %s\n", targetPath2.c_str());
84     ASSERT_TRUE(targetPath2 == "/data/storage/ela/testFd/a/mockfdLinkPath");
85 }
86 } // namespace HiviewDFX
87 } // namespace OHOS