1 /*
2 * Copyright (c) 2024-2024 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 #ifndef TEST_FUZZTEST_SOCPERF_FUZZ_MOCK_H
17 #define TEST_FUZZTEST_SOCPERF_FUZZ_MOCK_H
18
19 #include "accesstoken_kit.h"
20 #include "nativetoken_kit.h"
21 #include "soc_perf_stub.h"
22 #include "token_setproc.h"
23
24 namespace OHOS {
25 namespace SOCPERF {
26 class SocperfStubTest : public SocPerfStub {
27 public:
SocperfStubTest()28 SocperfStubTest() {}
PerfRequest(int32_t cmdId,const std::string & msg)29 ErrCode PerfRequest(int32_t cmdId, const std::string &msg) override
30 {
31 return ERR_OK;
32 }
PerfRequestEx(int32_t cmdId,bool onOffTag,const std::string & msg)33 ErrCode PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string &msg) override
34 {
35 return ERR_OK;
36 }
PowerLimitBoost(bool onOffTag,const std::string & msg)37 ErrCode PowerLimitBoost(bool onOffTag, const std::string &msg) override
38 {
39 return ERR_OK;
40 }
ThermalLimitBoost(bool onOffTag,const std::string & msg)41 ErrCode ThermalLimitBoost(bool onOffTag, const std::string &msg) override
42 {
43 return ERR_OK;
44 }
LimitRequest(int32_t clientId,const std::vector<int32_t> & tags,const std::vector<int64_t> & configs,const std::string & msg)45 ErrCode LimitRequest(int32_t clientId, const std::vector <int32_t> &tags, const std::vector <int64_t> &configs,
46 const std::string &msg) override
47 {
48 return ERR_OK;
49 }
SetRequestStatus(bool status,const std::string & msg)50 ErrCode SetRequestStatus(bool status, const std::string &msg) override
51 {
52 return ERR_OK;
53 }
SetThermalLevel(int32_t level)54 ErrCode SetThermalLevel(int32_t level) override
55 {
56 return ERR_OK;
57 }
RequestDeviceMode(const std::string & mode,bool status)58 ErrCode RequestDeviceMode(const std::string &mode, bool status) override
59 {
60 return ERR_OK;
61 }
RequestCmdIdCount(const std::string & msg,std::string & funcResult)62 ErrCode RequestCmdIdCount(const std::string& msg, std::string& funcResult) override
63 {
64 return ERR_OK;
65 }
66 };
MockProcess()67 void MockProcess()
68 {
69 static const char *perms[] = {
70 "ohos.permission.REPORT_RESOURCE_SCHEDULE_EVENT"
71 };
72 uint64_t tokenId;
73 NativeTokenInfoParams infoInstance = {
74 .dcapsNum = 0,
75 .permsNum = sizeof(perms) / sizeof(perms[0]),
76 .aclsNum = 0,
77 .dcaps = nullptr,
78 .perms = perms,
79 .acls = nullptr,
80 .processName = "socperf_test",
81 .aplStr = "system_core",
82 };
83 tokenId = GetAccessTokenId(&infoInstance);
84 SetSelfTokenID(tokenId);
85 OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
86 }
87 }
88 }
89 #endif