1 /*
2 * Copyright (c) 2022 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 <gtest/gtest.h>
17 #include "ressched_utils.h"
18
19 using namespace testing::ext;
20 namespace OHOS {
21 namespace ResourceSchedule {
22 class ResschedUtilsTest : public testing::Test {
23 public:
24 static void SetUpTestCase(void);
25 static void TearDownTestCase(void);
26 void SetUp();
27 void TearDown();
28 };
29
SetUpTestCase(void)30 void ResschedUtilsTest::SetUpTestCase(void)
31 {
32 }
33
TearDownTestCase(void)34 void ResschedUtilsTest::TearDownTestCase(void)
35 {
36 }
37
SetUp(void)38 void ResschedUtilsTest::SetUp(void)
39 {
40 }
41
TearDown(void)42 void ResschedUtilsTest::TearDown(void)
43 {
44 }
45
46 /**
47 * @tc.name: ResschedUtilsTest_CheckTidIsInPid_001
48 * @tc.desc: check tid is in pid or not
49 * @tc.type: FUNC
50 * @tc.require: issueI9BPMB
51 * @tc.desc:z30053169
52 */
53 HWTEST_F(ResschedUtilsTest, ProcessGroupSubTest_SchedPolicyType_001, Function | MediumTest | Level0)
54 {
55 EXPECT_EQ(ResSchedUtils::GetInstance().CheckTidIsInPid(0, 0), false);
56 }
57
58 /**
59 * @tc.name: ResschedUtilsTest_CheckTidIsInPid_002
60 * @tc.desc: check tid is in pid or not
61 * @tc.type: FUNC
62 * @tc.require: issueI9BPMB
63 * @tc.desc:z30053169
64 */
65 HWTEST_F(ResschedUtilsTest, ProcessGroupSubTest_SchedPolicyType_002, Function | MediumTest | Level0)
66 {
67 EXPECT_EQ(ResSchedUtils::GetInstance().CheckTidIsInPid(1, 1), false);
68 }
69
70 /**
71 * @tc.name: ResschedUtilsTest_UtilTest_001
72 * @tc.desc: Get Fork Process File Path
73 * @tc.type: FUNC
74 * @tc.require: issueI9TPCH
75 * @tc.desc:
76 */
77 HWTEST_F(ResschedUtilsTest, ResschedUtilsTest_UtilTest_001, Function | MediumTest | Level1)
78 {
79 std::string targetPath = "/dev/pids/100/com.example.myapplication/app_5973/cgroup.procs";
80 int ret = mkdir(targetPath.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
81 if (ret < 0) {
82 return;
83 }
84 std::string path = ResSchedUtils::GetInstance().GetProcessFilePath(20150111, "com.example.myapplication", 5973);
85 EXPECT_TRUE(path == targetPath);
86 }
87 }
88 }