13fc297bdSopenharmony_ci/*
23fc297bdSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
33fc297bdSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
43fc297bdSopenharmony_ci * you may not use this file except in compliance with the License.
53fc297bdSopenharmony_ci * You may obtain a copy of the License at
63fc297bdSopenharmony_ci *
73fc297bdSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
83fc297bdSopenharmony_ci *
93fc297bdSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
103fc297bdSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
113fc297bdSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123fc297bdSopenharmony_ci * See the License for the specific language governing permissions and
133fc297bdSopenharmony_ci * limitations under the License.
143fc297bdSopenharmony_ci */
153fc297bdSopenharmony_ci
163fc297bdSopenharmony_ci#define private public
173fc297bdSopenharmony_ci#define protected public
183fc297bdSopenharmony_ci
193fc297bdSopenharmony_ci#include <gtest/gtest.h>
203fc297bdSopenharmony_ci#include <gtest/hwext/gtest-multithread.h>
213fc297bdSopenharmony_ci#include "socperf_config.h"
223fc297bdSopenharmony_ci#include "socperf_ipc_interface_code.h"
233fc297bdSopenharmony_ci#include "socperf_server.h"
243fc297bdSopenharmony_ci#include "socperf_stub.h"
253fc297bdSopenharmony_ci#include "socperf.h"
263fc297bdSopenharmony_ci
273fc297bdSopenharmony_ciusing namespace testing::ext;
283fc297bdSopenharmony_ciusing namespace testing::mt;
293fc297bdSopenharmony_ci
303fc297bdSopenharmony_cinamespace OHOS {
313fc297bdSopenharmony_cinamespace SOCPERF {
323fc297bdSopenharmony_ciclass SocPerfServerTest : public testing::Test {
333fc297bdSopenharmony_cipublic:
343fc297bdSopenharmony_ci    static void SetUpTestCase(void);
353fc297bdSopenharmony_ci    static void TearDownTestCase(void);
363fc297bdSopenharmony_ci    void SetUp();
373fc297bdSopenharmony_ci    void TearDown();
383fc297bdSopenharmony_ciprivate:
393fc297bdSopenharmony_ci    std::shared_ptr<SocPerfServer> socPerfServer_ = DelayedSingleton<SocPerfServer>::GetInstance();
403fc297bdSopenharmony_ci};
413fc297bdSopenharmony_ci
423fc297bdSopenharmony_civoid SocPerfServerTest::SetUpTestCase(void)
433fc297bdSopenharmony_ci{
443fc297bdSopenharmony_ci}
453fc297bdSopenharmony_ci
463fc297bdSopenharmony_civoid SocPerfServerTest::TearDownTestCase(void)
473fc297bdSopenharmony_ci{
483fc297bdSopenharmony_ci}
493fc297bdSopenharmony_ci
503fc297bdSopenharmony_civoid SocPerfServerTest::SetUp(void)
513fc297bdSopenharmony_ci{
523fc297bdSopenharmony_ci}
533fc297bdSopenharmony_ci
543fc297bdSopenharmony_civoid SocPerfServerTest::TearDown(void)
553fc297bdSopenharmony_ci{
563fc297bdSopenharmony_ci}
573fc297bdSopenharmony_ci
583fc297bdSopenharmony_ci/*
593fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_Init_Config_001
603fc297bdSopenharmony_ci * @tc.desc: test init config
613fc297bdSopenharmony_ci * @tc.type FUNC
623fc297bdSopenharmony_ci * @tc.require: issueI78T3V
633fc297bdSopenharmony_ci */
643fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_Init_Config_001, Function | MediumTest | Level0)
653fc297bdSopenharmony_ci{
663fc297bdSopenharmony_ci    socPerfServer_->OnStart();
673fc297bdSopenharmony_ci    sleep(1);
683fc297bdSopenharmony_ci    EXPECT_TRUE(socPerfServer_->socPerf.enabled_);
693fc297bdSopenharmony_ci}
703fc297bdSopenharmony_ci
713fc297bdSopenharmony_ci/*
723fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SocPerfAPI_001
733fc297bdSopenharmony_ci * @tc.desc: test socperf api
743fc297bdSopenharmony_ci * @tc.type FUNC
753fc297bdSopenharmony_ci * @tc.require: issueI78T3V
763fc297bdSopenharmony_ci */
773fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SocPerfAPI_001, Function | MediumTest | Level0)
783fc297bdSopenharmony_ci{
793fc297bdSopenharmony_ci    std::string msg = "testBoost";
803fc297bdSopenharmony_ci    socPerfServer_->socPerf.PerfRequest(10000, msg);
813fc297bdSopenharmony_ci    socPerfServer_->socPerf.PerfRequestEx(10000, true, msg);
823fc297bdSopenharmony_ci    socPerfServer_->socPerf.PerfRequestEx(10000, false, msg);
833fc297bdSopenharmony_ci    socPerfServer_->socPerf.PerfRequestEx(10028, true, msg);
843fc297bdSopenharmony_ci    socPerfServer_->socPerf.PerfRequestEx(10028, false, msg);
853fc297bdSopenharmony_ci    socPerfServer_->socPerf.LimitRequest(ActionType::ACTION_TYPE_POWER, {1001}, {999000}, msg);
863fc297bdSopenharmony_ci    socPerfServer_->socPerf.LimitRequest(ActionType::ACTION_TYPE_THERMAL, {1001}, {999000}, msg);
873fc297bdSopenharmony_ci    socPerfServer_->socPerf.LimitRequest(ActionType::ACTION_TYPE_POWER, {1001}, {1325000}, msg);
883fc297bdSopenharmony_ci    socPerfServer_->socPerf.LimitRequest(ActionType::ACTION_TYPE_THERMAL, {1001}, {1325000}, msg);
893fc297bdSopenharmony_ci    socPerfServer_->socPerf.PowerLimitBoost(true, msg);
903fc297bdSopenharmony_ci    socPerfServer_->socPerf.ThermalLimitBoost(true, msg);
913fc297bdSopenharmony_ci    EXPECT_EQ(msg, "testBoost");
923fc297bdSopenharmony_ci    std::string id = "1000";
933fc297bdSopenharmony_ci    std::string name = "lit_cpu_freq";
943fc297bdSopenharmony_ci    std::string pair = "1001";
953fc297bdSopenharmony_ci    std::string mode = "1";
963fc297bdSopenharmony_ci    std::string persisMode = "1";
973fc297bdSopenharmony_ci    std::string configFile = "";
983fc297bdSopenharmony_ci    bool ret = socPerfServer_->socPerf.socPerfConfig_.CheckResourceTag(id.c_str(),
993fc297bdSopenharmony_ci        name.c_str(), pair.c_str(), mode.c_str(),
1003fc297bdSopenharmony_ci        persisMode.c_str(), configFile.c_str());
1013fc297bdSopenharmony_ci    EXPECT_TRUE(ret);
1023fc297bdSopenharmony_ci    ret = socPerfServer_->socPerf.socPerfConfig_.CheckResourceTag(nullptr, name.c_str(), pair.c_str(), mode.c_str(),
1033fc297bdSopenharmony_ci        persisMode.c_str(), configFile.c_str());
1043fc297bdSopenharmony_ci    EXPECT_FALSE(ret);
1053fc297bdSopenharmony_ci}
1063fc297bdSopenharmony_ci
1073fc297bdSopenharmony_ci/*
1083fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SocPerfServerAPI_000
1093fc297bdSopenharmony_ci * @tc.desc: test socperf server api
1103fc297bdSopenharmony_ci * @tc.type FUNC
1113fc297bdSopenharmony_ci * @tc.require: issueI78T3V
1123fc297bdSopenharmony_ci */
1133fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SocPerfServerAPI_000, Function | MediumTest | Level0)
1143fc297bdSopenharmony_ci{
1153fc297bdSopenharmony_ci    std::string msg = "testBoost";
1163fc297bdSopenharmony_ci    socPerfServer_->PerfRequest(10000, msg);
1173fc297bdSopenharmony_ci    socPerfServer_->PerfRequestEx(10000, true, msg);
1183fc297bdSopenharmony_ci    socPerfServer_->PerfRequestEx(10000, false, msg);
1193fc297bdSopenharmony_ci    socPerfServer_->LimitRequest(ActionType::ACTION_TYPE_POWER, {1001}, {1364000}, msg);
1203fc297bdSopenharmony_ci    socPerfServer_->LimitRequest(ActionType::ACTION_TYPE_POWER, {11001}, {2}, msg);
1213fc297bdSopenharmony_ci    socPerfServer_->LimitRequest(ActionType::ACTION_TYPE_MAX, {11001}, {2}, msg);
1223fc297bdSopenharmony_ci    socPerfServer_->PowerLimitBoost(true, msg);
1233fc297bdSopenharmony_ci    socPerfServer_->LimitRequest(ActionType::ACTION_TYPE_THERMAL, {1001}, {1364000}, msg);
1243fc297bdSopenharmony_ci    socPerfServer_->ThermalLimitBoost(true, msg);
1253fc297bdSopenharmony_ci    socPerfServer_->PowerLimitBoost(false, msg);
1263fc297bdSopenharmony_ci    socPerfServer_->ThermalLimitBoost(false, msg);
1273fc297bdSopenharmony_ci    bool allowDump = socPerfServer_->AllowDump();
1283fc297bdSopenharmony_ci    EXPECT_TRUE(allowDump);
1293fc297bdSopenharmony_ci    int32_t fd = -1;
1303fc297bdSopenharmony_ci    std::vector<std::u16string> args = {to_utf16("1"), to_utf16("2"), to_utf16("3"), to_utf16("-a"), to_utf16("-h")};
1313fc297bdSopenharmony_ci    socPerfServer_->Dump(fd, args);
1323fc297bdSopenharmony_ci    socPerfServer_->OnStop();
1333fc297bdSopenharmony_ci    EXPECT_EQ(msg, "testBoost");
1343fc297bdSopenharmony_ci}
1353fc297bdSopenharmony_ci
1363fc297bdSopenharmony_ci/*
1373fc297bdSopenharmony_ci * @tc.name: SocPerfSubTest_RequestCmdIdCount_001
1383fc297bdSopenharmony_ci * @tc.desc: RequestCmdIdCount
1393fc297bdSopenharmony_ci * @tc.type FUNC
1403fc297bdSopenharmony_ci * @tc.require: issueI9H4NS
1413fc297bdSopenharmony_ci */
1423fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfSubTest_RequestCmdIdCount_001, Function | MediumTest | Level0)
1433fc297bdSopenharmony_ci{
1443fc297bdSopenharmony_ci    int firstCheckColdStartNum = 0;
1453fc297bdSopenharmony_ci    int secondCheckColdStartNum = 0;
1463fc297bdSopenharmony_ci    map<int, int> myMap;
1473fc297bdSopenharmony_ci    char colon, comma;
1483fc297bdSopenharmony_ci    int key, value;
1493fc297bdSopenharmony_ci
1503fc297bdSopenharmony_ci    std::string ret = socPerfServer_->socPerf.RequestCmdIdCount("");
1513fc297bdSopenharmony_ci    std::stringstream ssfirst(ret);
1523fc297bdSopenharmony_ci    while (ssfirst >> key >> colon >> value >> comma) {
1533fc297bdSopenharmony_ci        myMap[key] = value;
1543fc297bdSopenharmony_ci    }
1553fc297bdSopenharmony_ci    ssfirst >> key >> colon >> value;
1563fc297bdSopenharmony_ci    myMap[key] = value;
1573fc297bdSopenharmony_ci    firstCheckColdStartNum = myMap[10000];
1583fc297bdSopenharmony_ci
1593fc297bdSopenharmony_ci    sleep(1);
1603fc297bdSopenharmony_ci    std::string msg = "testBoost";
1613fc297bdSopenharmony_ci    socPerfServer_->PerfRequest(10000, msg);
1623fc297bdSopenharmony_ci
1633fc297bdSopenharmony_ci    ret = socPerfServer_->socPerf.RequestCmdIdCount("");
1643fc297bdSopenharmony_ci    std::stringstream sssecond(ret);
1653fc297bdSopenharmony_ci    while (sssecond >> key >> colon >> value >> comma) {
1663fc297bdSopenharmony_ci        myMap[key] = value;
1673fc297bdSopenharmony_ci    }
1683fc297bdSopenharmony_ci    sssecond >> key >> colon >> value;
1693fc297bdSopenharmony_ci    myMap[key] = value;
1703fc297bdSopenharmony_ci    secondCheckColdStartNum = myMap[10000];
1713fc297bdSopenharmony_ci
1723fc297bdSopenharmony_ci    EXPECT_TRUE(secondCheckColdStartNum == firstCheckColdStartNum + 1);
1733fc297bdSopenharmony_ci}
1743fc297bdSopenharmony_ci
1753fc297bdSopenharmony_ci/*
1763fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SocPerfServerAPI_001
1773fc297bdSopenharmony_ci * @tc.desc: test socperf server api
1783fc297bdSopenharmony_ci * @tc.type FUNC
1793fc297bdSopenharmony_ci * @tc.require: issueI78T3V
1803fc297bdSopenharmony_ci */
1813fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SocPerfServerAPI_001, Function | MediumTest | Level0)
1823fc297bdSopenharmony_ci{
1833fc297bdSopenharmony_ci    std::string msg = "";
1843fc297bdSopenharmony_ci    socPerfServer_->SetRequestStatus(false, msg);
1853fc297bdSopenharmony_ci    socPerfServer_->socPerf.ClearAllAliveRequest();
1863fc297bdSopenharmony_ci    EXPECT_FALSE(socPerfServer_->socPerf.perfRequestEnable_);
1873fc297bdSopenharmony_ci#ifdef SOCPERF_ADAPTOR_FFRT
1883fc297bdSopenharmony_ci    auto socPerfThreadWrap = std::make_shared<SocPerfThreadWrap>();
1893fc297bdSopenharmony_ci#else
1903fc297bdSopenharmony_ci    auto runner = AppExecFwk::EventRunner::Create("socperf#");
1913fc297bdSopenharmony_ci    auto socPerfThreadWrap = std::make_shared<SocPerfThreadWrap>(runner);
1923fc297bdSopenharmony_ci#endif
1933fc297bdSopenharmony_ci    socPerfThreadWrap->ClearAllAliveRequest();
1943fc297bdSopenharmony_ci    for (const std::pair<int32_t, std::shared_ptr<ResStatus>>& item : socPerfThreadWrap->resStatusInfo_) {
1953fc297bdSopenharmony_ci        if (item.second == nullptr) {
1963fc297bdSopenharmony_ci            continue;
1973fc297bdSopenharmony_ci        }
1983fc297bdSopenharmony_ci        std::list<std::shared_ptr<ResAction>>& resActionList = item.second->resActionList[ACTION_TYPE_PERF];
1993fc297bdSopenharmony_ci        EXPECT_TRUE(resActionList.empty());
2003fc297bdSopenharmony_ci    }
2013fc297bdSopenharmony_ci}
2023fc297bdSopenharmony_ci
2033fc297bdSopenharmony_ci/*
2043fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SocPerfServerAPI_002
2053fc297bdSopenharmony_ci * @tc.desc: test socperf server api
2063fc297bdSopenharmony_ci * @tc.type FUNC
2073fc297bdSopenharmony_ci * @tc.require: issueI78T3V
2083fc297bdSopenharmony_ci */
2093fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SocPerfServerAPI_002, Function | MediumTest | Level0)
2103fc297bdSopenharmony_ci{
2113fc297bdSopenharmony_ci    std::string msg = "test";
2123fc297bdSopenharmony_ci    socPerfServer_->RequestDeviceMode(msg, true);
2133fc297bdSopenharmony_ci    auto iter = socPerfServer_->socPerf.recordDeviceMode_.find(msg);
2143fc297bdSopenharmony_ci    EXPECT_TRUE(iter != socPerfServer_->socPerf.recordDeviceMode_.end());
2153fc297bdSopenharmony_ci
2163fc297bdSopenharmony_ci    socPerfServer_->RequestDeviceMode(msg, false);
2173fc297bdSopenharmony_ci    auto iter2 = socPerfServer_->socPerf.recordDeviceMode_.find(msg);
2183fc297bdSopenharmony_ci    EXPECT_TRUE(iter2 == socPerfServer_->socPerf.recordDeviceMode_.end());
2193fc297bdSopenharmony_ci
2203fc297bdSopenharmony_ci    std::string msgEmpty = "";
2213fc297bdSopenharmony_ci    socPerfServer_->RequestDeviceMode("", true);
2223fc297bdSopenharmony_ci    auto iter3 = socPerfServer_->socPerf.recordDeviceMode_.find(msgEmpty);
2233fc297bdSopenharmony_ci    EXPECT_TRUE(iter3 == socPerfServer_->socPerf.recordDeviceMode_.end());
2243fc297bdSopenharmony_ci
2253fc297bdSopenharmony_ci    std::string msgMax = "ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHZ";
2263fc297bdSopenharmony_ci    socPerfServer_->RequestDeviceMode(msgMax, true);
2273fc297bdSopenharmony_ci    auto iter4 = socPerfServer_->socPerf.recordDeviceMode_.find(msgMax);
2283fc297bdSopenharmony_ci    EXPECT_TRUE(iter4 == socPerfServer_->socPerf.recordDeviceMode_.end());
2293fc297bdSopenharmony_ci}
2303fc297bdSopenharmony_ci
2313fc297bdSopenharmony_ci/*
2323fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SocperfMatchCmd_001
2333fc297bdSopenharmony_ci * @tc.desc: test socperf MatchDeviceModeCmd func
2343fc297bdSopenharmony_ci * @tc.type FUNC
2353fc297bdSopenharmony_ci * @tc.require: issueI9GCD8
2363fc297bdSopenharmony_ci */
2373fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SocperfMatchDeviceCmd_001, Function | MediumTest | Level0)
2383fc297bdSopenharmony_ci{
2393fc297bdSopenharmony_ci    std::string modeStr = "displayMain";
2403fc297bdSopenharmony_ci    int32_t cmdTest = 10000;
2413fc297bdSopenharmony_ci    socPerfServer_->RequestDeviceMode(modeStr, true);
2423fc297bdSopenharmony_ci    auto iter = socPerfServer_->socPerf.recordDeviceMode_.find(modeStr);
2433fc297bdSopenharmony_ci    EXPECT_TRUE(iter != socPerfServer_->socPerf.recordDeviceMode_.end());
2443fc297bdSopenharmony_ci    auto it_actions = socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_.find(cmdTest);
2453fc297bdSopenharmony_ci    if (it_actions == socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_.end()) {
2463fc297bdSopenharmony_ci        EXPECT_EQ(modeStr, "displayMain");
2473fc297bdSopenharmony_ci        return;
2483fc297bdSopenharmony_ci    }
2493fc297bdSopenharmony_ci    std::shared_ptr<Actions> actions = socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_[cmdTest];
2503fc297bdSopenharmony_ci    if (actions->modeMap.empty()) {
2513fc297bdSopenharmony_ci        actions->modeMap.insert(std::pair<std::string, int32_t>(modeStr, cmdTest));
2523fc297bdSopenharmony_ci    }
2533fc297bdSopenharmony_ci
2543fc297bdSopenharmony_ci    // case : normal match
2553fc297bdSopenharmony_ci    int32_t ret = socPerfServer_->socPerf.MatchDeviceModeCmd(cmdTest, false);
2563fc297bdSopenharmony_ci    auto iter_match = actions->modeMap.find(modeStr);
2573fc297bdSopenharmony_ci    if (iter_match != actions->modeMap.end()) {
2583fc297bdSopenharmony_ci        EXPECT_EQ(ret, iter_match->second);
2593fc297bdSopenharmony_ci    } else {
2603fc297bdSopenharmony_ci        EXPECT_EQ(ret, cmdTest);
2613fc297bdSopenharmony_ci    }
2623fc297bdSopenharmony_ci
2633fc297bdSopenharmony_ci    // case : match cmdid is not exist branch
2643fc297bdSopenharmony_ci    int32_t cmdInvaild = 60000;
2653fc297bdSopenharmony_ci    auto iter_invaild = socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_.find(cmdInvaild);
2663fc297bdSopenharmony_ci    if (iter_invaild != socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_.end()) {
2673fc297bdSopenharmony_ci        EXPECT_EQ(cmdInvaild, 60000);
2683fc297bdSopenharmony_ci    } else {
2693fc297bdSopenharmony_ci        auto iter_mode = actions->modeMap.find(modeStr);
2703fc297bdSopenharmony_ci        if (iter_mode == actions->modeMap.end()) {
2713fc297bdSopenharmony_ci            EXPECT_EQ(cmdInvaild, 60000);
2723fc297bdSopenharmony_ci        } else {
2733fc297bdSopenharmony_ci            iter_mode->second = cmdInvaild;
2743fc297bdSopenharmony_ci            int32_t retInvaild = socPerfServer_->socPerf.MatchDeviceModeCmd(cmdTest, false);
2753fc297bdSopenharmony_ci            EXPECT_EQ(retInvaild, cmdTest);
2763fc297bdSopenharmony_ci        }
2773fc297bdSopenharmony_ci    }
2783fc297bdSopenharmony_ci
2793fc297bdSopenharmony_ci    // case : no match mode
2803fc297bdSopenharmony_ci    std::string modeInvaild = "test";
2813fc297bdSopenharmony_ci    socPerfServer_->RequestDeviceMode(modeStr, false);
2823fc297bdSopenharmony_ci    socPerfServer_->RequestDeviceMode(modeInvaild, true);
2833fc297bdSopenharmony_ci    int32_t retModeInvaild = socPerfServer_->socPerf.MatchDeviceModeCmd(cmdTest, false);
2843fc297bdSopenharmony_ci    EXPECT_EQ(retModeInvaild, cmdTest);
2853fc297bdSopenharmony_ci}
2863fc297bdSopenharmony_ci
2873fc297bdSopenharmony_ci/*
2883fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SocperfMatchCmd_002
2893fc297bdSopenharmony_ci * @tc.desc: test socperf MatchDeviceModeCmd func
2903fc297bdSopenharmony_ci * @tc.type FUNC
2913fc297bdSopenharmony_ci * @tc.require: issueI9GCD8
2923fc297bdSopenharmony_ci */
2933fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SocperfMatchCmd_002, Function | MediumTest | Level0)
2943fc297bdSopenharmony_ci{
2953fc297bdSopenharmony_ci    std::string modeStr = "displayMainTest";
2963fc297bdSopenharmony_ci    int32_t cmdTest = 10000;
2973fc297bdSopenharmony_ci    int32_t cmdMatch = 10001;
2983fc297bdSopenharmony_ci
2993fc297bdSopenharmony_ci    auto it_actions = socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_.find(cmdTest);
3003fc297bdSopenharmony_ci    if (it_actions == socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_.end()) {
3013fc297bdSopenharmony_ci        EXPECT_EQ(modeStr, "displayMainTest");
3023fc297bdSopenharmony_ci        return;
3033fc297bdSopenharmony_ci    }
3043fc297bdSopenharmony_ci    std::shared_ptr<Actions> actions = socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_[cmdTest];
3053fc297bdSopenharmony_ci    actions->isLongTimePerf = false;
3063fc297bdSopenharmony_ci    actions->modeMap.insert(std::pair<std::string, int32_t>(modeStr, cmdMatch));
3073fc297bdSopenharmony_ci
3083fc297bdSopenharmony_ci    auto it_match = socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_.find(cmdMatch);
3093fc297bdSopenharmony_ci    if (it_match == socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_.end()) {
3103fc297bdSopenharmony_ci        EXPECT_EQ(modeStr, "displayMainTest");
3113fc297bdSopenharmony_ci        return;
3123fc297bdSopenharmony_ci    }
3133fc297bdSopenharmony_ci
3143fc297bdSopenharmony_ci    // case : match cmdid is long time perf branch
3153fc297bdSopenharmony_ci    std::shared_ptr<Actions> actionsMatch = socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_[cmdMatch];
3163fc297bdSopenharmony_ci    actionsMatch->isLongTimePerf = true;
3173fc297bdSopenharmony_ci    int32_t retInvaild = socPerfServer_->socPerf.MatchDeviceModeCmd(cmdTest, true);
3183fc297bdSopenharmony_ci    EXPECT_EQ(retInvaild, cmdTest);
3193fc297bdSopenharmony_ci}
3203fc297bdSopenharmony_ci
3213fc297bdSopenharmony_ci/*
3223fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SocperfMatchCmd_003
3233fc297bdSopenharmony_ci * @tc.desc: test socperf MatchDeviceModeCmd func
3243fc297bdSopenharmony_ci * @tc.type FUNC
3253fc297bdSopenharmony_ci * @tc.require: issueI9GCD8
3263fc297bdSopenharmony_ci */
3273fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SocperfMatchCmd_003, Function | MediumTest | Level0)
3283fc297bdSopenharmony_ci{
3293fc297bdSopenharmony_ci    std::string modeStr = "displayMainTest";
3303fc297bdSopenharmony_ci    int32_t cmdTest = 10002;
3313fc297bdSopenharmony_ci
3323fc297bdSopenharmony_ci    auto it_actions = socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_.find(cmdTest);
3333fc297bdSopenharmony_ci    if (it_actions == socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_.end()) {
3343fc297bdSopenharmony_ci        EXPECT_EQ(modeStr, "displayMainTest");
3353fc297bdSopenharmony_ci        return;
3363fc297bdSopenharmony_ci    }
3373fc297bdSopenharmony_ci
3383fc297bdSopenharmony_ci    std::shared_ptr<Actions> actions = socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_[cmdTest];
3393fc297bdSopenharmony_ci    actions->modeMap.insert(std::pair<std::string, int32_t>(modeStr, cmdTest));
3403fc297bdSopenharmony_ci    socPerfServer_->socPerf.recordDeviceMode_.clear();
3413fc297bdSopenharmony_ci
3423fc297bdSopenharmony_ci    // case : match device mode is empty branch
3433fc297bdSopenharmony_ci    int32_t retInvaild = socPerfServer_->socPerf.MatchDeviceModeCmd(cmdTest, true);
3443fc297bdSopenharmony_ci    EXPECT_EQ(retInvaild, cmdTest);
3453fc297bdSopenharmony_ci}
3463fc297bdSopenharmony_ci
3473fc297bdSopenharmony_ci/*
3483fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SocperfParseModeCmd_001
3493fc297bdSopenharmony_ci * @tc.desc: test socperf ParseModeCmd func
3503fc297bdSopenharmony_ci * @tc.type FUNC
3513fc297bdSopenharmony_ci * @tc.require: issueI78T3V
3523fc297bdSopenharmony_ci */
3533fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SocperfParseModeCmd_001, Function | MediumTest | Level0)
3543fc297bdSopenharmony_ci{
3553fc297bdSopenharmony_ci    const char modePairInvaild[] = "parseTest";
3563fc297bdSopenharmony_ci    const char modeNumberInvaild[] = "parseTest=abc";
3573fc297bdSopenharmony_ci    const char modeCmdInvaild[] = "=12345";
3583fc297bdSopenharmony_ci    const char modeSame[] = "parseTest=12345|parseTest=23456";
3593fc297bdSopenharmony_ci    std::string cfgFile = "bootest.xml";
3603fc297bdSopenharmony_ci    int32_t cmdTest = 10002;
3613fc297bdSopenharmony_ci    int32_t exceptSame = 23456;
3623fc297bdSopenharmony_ci    std::string deviceMode = "parseTest";
3633fc297bdSopenharmony_ci
3643fc297bdSopenharmony_ci    auto it_actions = socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_.find(cmdTest);
3653fc297bdSopenharmony_ci    if (it_actions == socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_.end()) {
3663fc297bdSopenharmony_ci        EXPECT_EQ(cmdTest, 10002);
3673fc297bdSopenharmony_ci        return;
3683fc297bdSopenharmony_ci    }
3693fc297bdSopenharmony_ci
3703fc297bdSopenharmony_ci    std::shared_ptr<Actions> actions = socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_[cmdTest];
3713fc297bdSopenharmony_ci    socPerfServer_->socPerf.socPerfConfig_.ParseModeCmd(modePairInvaild, cfgFile, actions);
3723fc297bdSopenharmony_ci    EXPECT_TRUE(actions->modeMap.find(deviceMode) == actions->modeMap.end());
3733fc297bdSopenharmony_ci
3743fc297bdSopenharmony_ci    socPerfServer_->socPerf.socPerfConfig_.ParseModeCmd(modeNumberInvaild, cfgFile, actions);
3753fc297bdSopenharmony_ci    EXPECT_TRUE(actions->modeMap.find(deviceMode) == actions->modeMap.end());
3763fc297bdSopenharmony_ci
3773fc297bdSopenharmony_ci    socPerfServer_->socPerf.socPerfConfig_.ParseModeCmd(modeCmdInvaild, cfgFile, actions);
3783fc297bdSopenharmony_ci    EXPECT_TRUE(actions->modeMap.find(deviceMode) == actions->modeMap.end());
3793fc297bdSopenharmony_ci
3803fc297bdSopenharmony_ci    int32_t size = actions->modeMap.size();
3813fc297bdSopenharmony_ci    socPerfServer_->socPerf.socPerfConfig_.ParseModeCmd(modeSame, cfgFile, actions);
3823fc297bdSopenharmony_ci    EXPECT_EQ(size + 1, actions->modeMap.size());
3833fc297bdSopenharmony_ci    auto iterSame = actions->modeMap.find(deviceMode);
3843fc297bdSopenharmony_ci    ASSERT_TRUE(iterSame != actions->modeMap.end());
3853fc297bdSopenharmony_ci    EXPECT_EQ(exceptSame, iterSame->second);
3863fc297bdSopenharmony_ci
3873fc297bdSopenharmony_ci    int32_t sizeBefore = actions->modeMap.size();
3883fc297bdSopenharmony_ci    const char *modeNullInvaild = nullptr;
3893fc297bdSopenharmony_ci    socPerfServer_->socPerf.socPerfConfig_.ParseModeCmd(modeNullInvaild, cfgFile, actions);
3903fc297bdSopenharmony_ci    EXPECT_EQ(sizeBefore, actions->modeMap.size());
3913fc297bdSopenharmony_ci}
3923fc297bdSopenharmony_ci
3933fc297bdSopenharmony_ci/*
3943fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SocperfThreadWrapp_001
3953fc297bdSopenharmony_ci * @tc.desc: test log switch func
3963fc297bdSopenharmony_ci * @tc.type FUNC
3973fc297bdSopenharmony_ci * @tc.require: issueI78T3V
3983fc297bdSopenharmony_ci */
3993fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SocperfThreadWrapp_001, Function | MediumTest | Level0)
4003fc297bdSopenharmony_ci{
4013fc297bdSopenharmony_ci    std::string msg = "";
4023fc297bdSopenharmony_ci#ifdef SOCPERF_ADAPTOR_FFRT
4033fc297bdSopenharmony_ci    auto socPerfThreadWrap = std::make_shared<SocPerfThreadWrap>();
4043fc297bdSopenharmony_ci#else
4053fc297bdSopenharmony_ci    auto runner = AppExecFwk::EventRunner::Create("socperf#");
4063fc297bdSopenharmony_ci    auto socPerfThreadWrap = std::make_shared<SocPerfThreadWrap>(runner);
4073fc297bdSopenharmony_ci#endif
4083fc297bdSopenharmony_ci    socPerfThreadWrap->PostDelayTask(1000, nullptr);
4093fc297bdSopenharmony_ci    socPerfThreadWrap->InitResourceNodeInfo(nullptr);
4103fc297bdSopenharmony_ci    socPerfThreadWrap->socPerfConfig_.InitPerfFunc(nullptr, nullptr);
4113fc297bdSopenharmony_ci    socPerfThreadWrap->socPerfConfig_.InitPerfFunc(nullptr, msg.c_str());
4123fc297bdSopenharmony_ci    socPerfThreadWrap->socPerfConfig_.InitPerfFunc(msg.c_str(), nullptr);
4133fc297bdSopenharmony_ci    socPerfThreadWrap->socPerfConfig_.InitPerfFunc(msg.c_str(), msg.c_str());
4143fc297bdSopenharmony_ci    socPerfThreadWrap->DoFreqActionPack(nullptr);
4153fc297bdSopenharmony_ci    socPerfThreadWrap->UpdateLimitStatus(0, nullptr, 0);
4163fc297bdSopenharmony_ci    socPerfThreadWrap->DoFreqAction(0, nullptr);
4173fc297bdSopenharmony_ci    socPerfThreadWrap->DoFreqAction(1000, nullptr);
4183fc297bdSopenharmony_ci    EXPECT_NE(msg.c_str(), "-1");
4193fc297bdSopenharmony_ci    bool ret = false;
4203fc297bdSopenharmony_ci    int inValidResId = 9999;
4213fc297bdSopenharmony_ci    ret = socPerfThreadWrap->socPerfConfig_.IsValidResId(inValidResId);
4223fc297bdSopenharmony_ci    EXPECT_FALSE(ret);
4233fc297bdSopenharmony_ci    ret = socPerfThreadWrap->socPerfConfig_.IsGovResId(inValidResId);
4243fc297bdSopenharmony_ci    EXPECT_FALSE(ret);
4253fc297bdSopenharmony_ci    int32_t level = 10;
4263fc297bdSopenharmony_ci    int64_t value = 0;
4273fc297bdSopenharmony_ci    ret = socPerfThreadWrap->GetResValueByLevel(inValidResId, level, value);
4283fc297bdSopenharmony_ci    EXPECT_FALSE(ret);
4293fc297bdSopenharmony_ci}
4303fc297bdSopenharmony_ci
4313fc297bdSopenharmony_ciclass SocperfStubTest : public SocPerfStub {
4323fc297bdSopenharmony_cipublic:
4333fc297bdSopenharmony_ci    SocperfStubTest() {}
4343fc297bdSopenharmony_ci    void PerfRequest(int32_t cmdId, const std::string& msg) override {}
4353fc297bdSopenharmony_ci    void PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg) override {}
4363fc297bdSopenharmony_ci    void PowerLimitBoost(bool onOffTag, const std::string& msg) override {}
4373fc297bdSopenharmony_ci    void ThermalLimitBoost(bool onOffTag, const std::string& msg) override {}
4383fc297bdSopenharmony_ci    void LimitRequest(int32_t clientId,
4393fc297bdSopenharmony_ci        const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg) override {}
4403fc297bdSopenharmony_ci    void SetRequestStatus(bool status, const std::string& msg) override {};
4413fc297bdSopenharmony_ci    void SetThermalLevel(int32_t level) override {};
4423fc297bdSopenharmony_ci    void RequestDeviceMode(const std::string& mode, bool status) override {};
4433fc297bdSopenharmony_ci    std::string RequestCmdIdCount(const std::string& msg) override
4443fc297bdSopenharmony_ci    {
4453fc297bdSopenharmony_ci        return "";
4463fc297bdSopenharmony_ci    }
4473fc297bdSopenharmony_ci};
4483fc297bdSopenharmony_ci
4493fc297bdSopenharmony_ci/*
4503fc297bdSopenharmony_ci * @tc.name: SocPerfStubTest_SocPerfServerAPI_001
4513fc297bdSopenharmony_ci * @tc.desc: test socperf stub api
4523fc297bdSopenharmony_ci * @tc.type FUNC
4533fc297bdSopenharmony_ci * @tc.require: issueI78T3V
4543fc297bdSopenharmony_ci */
4553fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfStubTest_SocPerfServerAPI_001, Function | MediumTest | Level0)
4563fc297bdSopenharmony_ci{
4573fc297bdSopenharmony_ci    SocperfStubTest socPerfStub;
4583fc297bdSopenharmony_ci    MessageParcel data;
4593fc297bdSopenharmony_ci    data.WriteInterfaceToken(SocPerfStub::GetDescriptor());
4603fc297bdSopenharmony_ci    data.WriteInt32(10000);
4613fc297bdSopenharmony_ci    data.WriteString("");
4623fc297bdSopenharmony_ci    MessageParcel reply;
4633fc297bdSopenharmony_ci    MessageOption option;
4643fc297bdSopenharmony_ci    uint32_t requestIpcId = static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_PERF_REQUEST);
4653fc297bdSopenharmony_ci    int32_t ret = socPerfStub.OnRemoteRequest(requestIpcId, data, reply, option);
4663fc297bdSopenharmony_ci    EXPECT_EQ(ret, ERR_OK);
4673fc297bdSopenharmony_ci}
4683fc297bdSopenharmony_ci
4693fc297bdSopenharmony_ci/*
4703fc297bdSopenharmony_ci * @tc.name: SocPerfStubTest_SocPerfServerAPI_002
4713fc297bdSopenharmony_ci * @tc.desc: test socperf stub api
4723fc297bdSopenharmony_ci * @tc.type FUNC
4733fc297bdSopenharmony_ci * @tc.require: issueI78T3V
4743fc297bdSopenharmony_ci */
4753fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfStubTest_SocPerfServerAPI_002, Function | MediumTest | Level0)
4763fc297bdSopenharmony_ci{
4773fc297bdSopenharmony_ci    SocperfStubTest socPerfStub;
4783fc297bdSopenharmony_ci    MessageParcel data;
4793fc297bdSopenharmony_ci    data.WriteInterfaceToken(SocPerfStub::GetDescriptor());
4803fc297bdSopenharmony_ci    data.WriteInt32(10000);
4813fc297bdSopenharmony_ci    data.WriteBool(true);
4823fc297bdSopenharmony_ci    data.WriteString("");
4833fc297bdSopenharmony_ci    MessageParcel reply;
4843fc297bdSopenharmony_ci    MessageOption option;
4853fc297bdSopenharmony_ci    uint32_t requestExIpcId = static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_PERF_REQUEST_EX);
4863fc297bdSopenharmony_ci    int32_t ret = socPerfStub.OnRemoteRequest(requestExIpcId, data, reply, option);
4873fc297bdSopenharmony_ci    EXPECT_EQ(ret, ERR_OK);
4883fc297bdSopenharmony_ci}
4893fc297bdSopenharmony_ci
4903fc297bdSopenharmony_ci/*
4913fc297bdSopenharmony_ci * @tc.name: SocPerfStubTest_SocPerfServerAPI_003
4923fc297bdSopenharmony_ci * @tc.desc: test socperf stub api
4933fc297bdSopenharmony_ci * @tc.type FUNC
4943fc297bdSopenharmony_ci * @tc.require: issueI78T3V
4953fc297bdSopenharmony_ci */
4963fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfStubTest_SocPerfServerAPI_003, Function | MediumTest | Level0)
4973fc297bdSopenharmony_ci{
4983fc297bdSopenharmony_ci    SocperfStubTest socPerfStub;
4993fc297bdSopenharmony_ci    MessageParcel data;
5003fc297bdSopenharmony_ci    data.WriteInterfaceToken(SocPerfStub::GetDescriptor());
5013fc297bdSopenharmony_ci    data.WriteInt32(1);
5023fc297bdSopenharmony_ci    std::vector<int32_t> tags = {1001};
5033fc297bdSopenharmony_ci    data.WriteInt32Vector(tags);
5043fc297bdSopenharmony_ci    std::vector<int64_t> configs = {1416000};
5053fc297bdSopenharmony_ci    data.WriteInt64Vector(configs);
5063fc297bdSopenharmony_ci    data.WriteString("");
5073fc297bdSopenharmony_ci    MessageParcel reply;
5083fc297bdSopenharmony_ci    MessageOption option;
5093fc297bdSopenharmony_ci    uint32_t powerLimitId = static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_LIMIT_REQUEST);
5103fc297bdSopenharmony_ci    int32_t ret = socPerfStub.OnRemoteRequest(powerLimitId, data, reply, option);
5113fc297bdSopenharmony_ci    EXPECT_EQ(ret, ERR_OK);
5123fc297bdSopenharmony_ci}
5133fc297bdSopenharmony_ci
5143fc297bdSopenharmony_ci/*
5153fc297bdSopenharmony_ci * @tc.name: SocPerfStubTest_SocPerfServerAPI_004
5163fc297bdSopenharmony_ci * @tc.desc: test socperf stub api
5173fc297bdSopenharmony_ci * @tc.type FUNC
5183fc297bdSopenharmony_ci * @tc.require: issueI78T3V
5193fc297bdSopenharmony_ci */
5203fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfStubTest_SocPerfServerAPI_004, Function | MediumTest | Level0)
5213fc297bdSopenharmony_ci{
5223fc297bdSopenharmony_ci    SocperfStubTest socPerfStub;
5233fc297bdSopenharmony_ci    MessageParcel data;
5243fc297bdSopenharmony_ci    data.WriteInterfaceToken(SocPerfStub::GetDescriptor());
5253fc297bdSopenharmony_ci    data.WriteBool(true);
5263fc297bdSopenharmony_ci    data.WriteString("");
5273fc297bdSopenharmony_ci    MessageParcel reply;
5283fc297bdSopenharmony_ci    MessageOption option;
5293fc297bdSopenharmony_ci    uint32_t powerLimitIpcId = static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_POWER_LIMIT_BOOST_FREQ);
5303fc297bdSopenharmony_ci    int32_t ret = socPerfStub.OnRemoteRequest(powerLimitIpcId, data, reply, option);
5313fc297bdSopenharmony_ci    EXPECT_EQ(ret, ERR_OK);
5323fc297bdSopenharmony_ci}
5333fc297bdSopenharmony_ci
5343fc297bdSopenharmony_ci/*
5353fc297bdSopenharmony_ci * @tc.name: SocPerfStubTest_SocPerfServerAPI_005
5363fc297bdSopenharmony_ci * @tc.desc: test socperf stub api
5373fc297bdSopenharmony_ci * @tc.type FUNC
5383fc297bdSopenharmony_ci * @tc.require: issueI78T3V
5393fc297bdSopenharmony_ci */
5403fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfStubTest_SocPerfServerAPI_005, Function | MediumTest | Level0)
5413fc297bdSopenharmony_ci{
5423fc297bdSopenharmony_ci    SocperfStubTest socPerfStub;
5433fc297bdSopenharmony_ci    MessageParcel data;
5443fc297bdSopenharmony_ci    data.WriteInterfaceToken(SocPerfStub::GetDescriptor());
5453fc297bdSopenharmony_ci    data.WriteBool(true);
5463fc297bdSopenharmony_ci    data.WriteString("");
5473fc297bdSopenharmony_ci    MessageParcel reply;
5483fc297bdSopenharmony_ci    MessageOption option;
5493fc297bdSopenharmony_ci    uint32_t thermalLimitIpcId = static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_THERMAL_LIMIT_BOOST_FREQ);
5503fc297bdSopenharmony_ci    int32_t ret = socPerfStub.OnRemoteRequest(thermalLimitIpcId, data, reply, option);
5513fc297bdSopenharmony_ci    EXPECT_EQ(ret, ERR_OK);
5523fc297bdSopenharmony_ci}
5533fc297bdSopenharmony_ci
5543fc297bdSopenharmony_ci/*
5553fc297bdSopenharmony_ci * @tc.name: SocPerfStubTest_SocPerfServerAPI_006
5563fc297bdSopenharmony_ci * @tc.desc: test socperf stub api
5573fc297bdSopenharmony_ci * @tc.type FUNC
5583fc297bdSopenharmony_ci * @tc.require: issueI78T3V
5593fc297bdSopenharmony_ci */
5603fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfStubTest_SocPerfServerAPI_006, Function | MediumTest | Level0)
5613fc297bdSopenharmony_ci{
5623fc297bdSopenharmony_ci    SocperfStubTest socPerfStub;
5633fc297bdSopenharmony_ci    MessageParcel data;
5643fc297bdSopenharmony_ci    data.WriteInterfaceToken(SocPerfStub::GetDescriptor());
5653fc297bdSopenharmony_ci    data.WriteBool(true);
5663fc297bdSopenharmony_ci    MessageParcel reply;
5673fc297bdSopenharmony_ci    MessageOption option;
5683fc297bdSopenharmony_ci    uint32_t ipcId = 0x000f;
5693fc297bdSopenharmony_ci    int32_t ret = socPerfStub.OnRemoteRequest(ipcId, data, reply, option);
5703fc297bdSopenharmony_ci    EXPECT_NE(ret, ERR_OK);
5713fc297bdSopenharmony_ci}
5723fc297bdSopenharmony_ci
5733fc297bdSopenharmony_ci/*
5743fc297bdSopenharmony_ci * @tc.name: SocPerfStubTest_SocPerfServerAPI_007
5753fc297bdSopenharmony_ci * @tc.desc: test socperf stub api
5763fc297bdSopenharmony_ci * @tc.type FUNC
5773fc297bdSopenharmony_ci * @tc.require: issueI78T3V
5783fc297bdSopenharmony_ci */
5793fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfStubTest_SocPerfServerAPI_007, Function | MediumTest | Level0)
5803fc297bdSopenharmony_ci{
5813fc297bdSopenharmony_ci    SocperfStubTest socPerfStub;
5823fc297bdSopenharmony_ci    MessageParcel data;
5833fc297bdSopenharmony_ci    data.WriteInterfaceToken(SocPerfStub::GetDescriptor());
5843fc297bdSopenharmony_ci    data.WriteBool(false);
5853fc297bdSopenharmony_ci    data.WriteString("");
5863fc297bdSopenharmony_ci    MessageParcel reply;
5873fc297bdSopenharmony_ci    MessageOption option;
5883fc297bdSopenharmony_ci    uint32_t ipcId = static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_SET_STATUS);
5893fc297bdSopenharmony_ci    int32_t ret = socPerfStub.OnRemoteRequest(ipcId, data, reply, option);
5903fc297bdSopenharmony_ci    EXPECT_EQ(ret, ERR_OK);
5913fc297bdSopenharmony_ci
5923fc297bdSopenharmony_ci    MessageParcel dataPerf;
5933fc297bdSopenharmony_ci    dataPerf.WriteInterfaceToken(SocPerfStub::GetDescriptor());
5943fc297bdSopenharmony_ci    dataPerf.WriteInt32(10000);
5953fc297bdSopenharmony_ci    dataPerf.WriteString("");
5963fc297bdSopenharmony_ci    MessageParcel replyPerf;
5973fc297bdSopenharmony_ci    MessageOption optionPerf;
5983fc297bdSopenharmony_ci    uint32_t requestPerfIpcId = static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_PERF_REQUEST);
5993fc297bdSopenharmony_ci    ret = socPerfStub.OnRemoteRequest(requestPerfIpcId, dataPerf, replyPerf, optionPerf);
6003fc297bdSopenharmony_ci    EXPECT_EQ(ret, ERR_OK);
6013fc297bdSopenharmony_ci
6023fc297bdSopenharmony_ci    MessageParcel dataLimit;
6033fc297bdSopenharmony_ci    dataLimit.WriteInterfaceToken(SocPerfStub::GetDescriptor());
6043fc297bdSopenharmony_ci    dataLimit.WriteInt32(1);
6053fc297bdSopenharmony_ci    std::vector<int32_t> tags = {1001};
6063fc297bdSopenharmony_ci    dataLimit.WriteInt32Vector(tags);
6073fc297bdSopenharmony_ci    std::vector<int64_t> configs = {1416000};
6083fc297bdSopenharmony_ci    dataLimit.WriteInt64Vector(configs);
6093fc297bdSopenharmony_ci    dataLimit.WriteString("");
6103fc297bdSopenharmony_ci    MessageParcel replyLimit;
6113fc297bdSopenharmony_ci    MessageOption optionLimit;
6123fc297bdSopenharmony_ci    uint32_t powerLimitId = static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_LIMIT_REQUEST);
6133fc297bdSopenharmony_ci    ret = socPerfStub.OnRemoteRequest(powerLimitId, dataLimit, reply, option);
6143fc297bdSopenharmony_ci    EXPECT_EQ(ret, ERR_OK);
6153fc297bdSopenharmony_ci}
6163fc297bdSopenharmony_ci
6173fc297bdSopenharmony_ci
6183fc297bdSopenharmony_ci/*
6193fc297bdSopenharmony_ci * @tc.name: SocPerfStubTest_SocPerfServerAPI_008
6203fc297bdSopenharmony_ci * @tc.desc: test socperf requet device mode stub api
6213fc297bdSopenharmony_ci * @tc.type FUNC
6223fc297bdSopenharmony_ci * @tc.require: issue#I95U8S
6233fc297bdSopenharmony_ci */
6243fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfStubTest_SocPerfServerAPI_008, Function | MediumTest | Level0)
6253fc297bdSopenharmony_ci{
6263fc297bdSopenharmony_ci    SocperfStubTest socPerfStub;
6273fc297bdSopenharmony_ci    MessageParcel data;
6283fc297bdSopenharmony_ci    data.WriteInterfaceToken(SocPerfStub::GetDescriptor());
6293fc297bdSopenharmony_ci    data.WriteString("test");
6303fc297bdSopenharmony_ci    data.WriteBool(true);
6313fc297bdSopenharmony_ci    MessageParcel reply;
6323fc297bdSopenharmony_ci    MessageOption option;
6333fc297bdSopenharmony_ci    uint32_t ipcId = static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_SET_DEVICE_MODE);
6343fc297bdSopenharmony_ci    int32_t ret = socPerfStub.OnRemoteRequest(ipcId, data, reply, option);
6353fc297bdSopenharmony_ci    EXPECT_EQ(ret, ERR_OK);
6363fc297bdSopenharmony_ci}
6373fc297bdSopenharmony_ci
6383fc297bdSopenharmony_ci/*
6393fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SetThermalLevel_001
6403fc297bdSopenharmony_ci * @tc.desc: perf request lvl server API
6413fc297bdSopenharmony_ci * @tc.type FUNC
6423fc297bdSopenharmony_ci * @tc.require: issue#I95U8S
6433fc297bdSopenharmony_ci */
6443fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SetThermalLevel_Server_001, Function | MediumTest | Level0)
6453fc297bdSopenharmony_ci{
6463fc297bdSopenharmony_ci    SocperfStubTest socPerfStub;
6473fc297bdSopenharmony_ci    MessageParcel data;
6483fc297bdSopenharmony_ci    data.WriteInterfaceToken(SocPerfStub::GetDescriptor());
6493fc297bdSopenharmony_ci    data.WriteInt32(3);
6503fc297bdSopenharmony_ci    MessageParcel reply;
6513fc297bdSopenharmony_ci    MessageOption option;
6523fc297bdSopenharmony_ci    uint32_t ipcId = static_cast<uint32_t>(SocPerfInterfaceCode::TRANS_IPC_ID_SET_THERMAL_LEVEL);
6533fc297bdSopenharmony_ci    int32_t ret = socPerfStub.OnRemoteRequest(ipcId, data, reply, option);
6543fc297bdSopenharmony_ci    EXPECT_EQ(ret, ERR_OK);
6553fc297bdSopenharmony_ci}
6563fc297bdSopenharmony_ci
6573fc297bdSopenharmony_ci/*
6583fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SetThermalLevel_Server_002
6593fc297bdSopenharmony_ci * @tc.desc: perf request lvl server API
6603fc297bdSopenharmony_ci * @tc.type FUNC
6613fc297bdSopenharmony_ci * @tc.require: issue#I95U8S
6623fc297bdSopenharmony_ci */
6633fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SetThermalLevel_Server_002, Function | MediumTest | Level0)
6643fc297bdSopenharmony_ci{
6653fc297bdSopenharmony_ci    socPerfServer_->SetThermalLevel(3);
6663fc297bdSopenharmony_ci    EXPECT_EQ(socPerfServer_->socPerf.thermalLvl_, 3);
6673fc297bdSopenharmony_ci}
6683fc297bdSopenharmony_ci
6693fc297bdSopenharmony_ci/*
6703fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SetThermalLevel_Server_003
6713fc297bdSopenharmony_ci * @tc.desc: perf request lvl server API
6723fc297bdSopenharmony_ci * @tc.type FUNC
6733fc297bdSopenharmony_ci * @tc.require: issue#I95U8S
6743fc297bdSopenharmony_ci */
6753fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SetThermalLevel_Server_003, Function | MediumTest | Level0)
6763fc297bdSopenharmony_ci{
6773fc297bdSopenharmony_ci    const int32_t appColdStartCmdId = 10000;
6783fc297bdSopenharmony_ci    const int32_t appWarmStartCmdId = 10001;
6793fc297bdSopenharmony_ci    if (socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_[appColdStartCmdId] == nullptr ||
6803fc297bdSopenharmony_ci        socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_[appWarmStartCmdId] == nullptr) {
6813fc297bdSopenharmony_ci        SUCCEED();
6823fc297bdSopenharmony_ci        return;
6833fc297bdSopenharmony_ci    }
6843fc297bdSopenharmony_ci    std::shared_ptr<Actions> appColdStartActions =
6853fc297bdSopenharmony_ci        socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_[appColdStartCmdId];
6863fc297bdSopenharmony_ci    std::list<std::shared_ptr<Action>>  appColdStartActionList = appColdStartActions->actionList;
6873fc297bdSopenharmony_ci    for (auto item : appColdStartActionList) {
6883fc297bdSopenharmony_ci        item->thermalCmdId_ = 88888;
6893fc297bdSopenharmony_ci        bool ret = socPerfServer_->socPerf.DoPerfRequestThremalLvl(appColdStartCmdId, item, EVENT_INVALID);
6903fc297bdSopenharmony_ci        EXPECT_FALSE(ret);
6913fc297bdSopenharmony_ci
6923fc297bdSopenharmony_ci        item->thermalCmdId_ = appWarmStartCmdId;
6933fc297bdSopenharmony_ci        ret = socPerfServer_->socPerf.DoPerfRequestThremalLvl(appColdStartCmdId, item, EVENT_INVALID);
6943fc297bdSopenharmony_ci        EXPECT_TRUE(ret);
6953fc297bdSopenharmony_ci    }
6963fc297bdSopenharmony_ci    SUCCEED();
6973fc297bdSopenharmony_ci}
6983fc297bdSopenharmony_ci
6993fc297bdSopenharmony_ci/*
7003fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SetThermalLevel_Server_004
7013fc297bdSopenharmony_ci * @tc.desc: perf request lvl server API
7023fc297bdSopenharmony_ci * @tc.type FUNC
7033fc297bdSopenharmony_ci * @tc.require: issue#I95U8S
7043fc297bdSopenharmony_ci */
7053fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SetThermalLevel_Server_004, Function | MediumTest | Level0)
7063fc297bdSopenharmony_ci{
7073fc297bdSopenharmony_ci    const int32_t appColdStartCmdId = 10000;
7083fc297bdSopenharmony_ci    const int32_t appWarmStartCmdId = 10001;
7093fc297bdSopenharmony_ci    if (socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_[appColdStartCmdId] == nullptr ||
7103fc297bdSopenharmony_ci        socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_[appWarmStartCmdId] == nullptr) {
7113fc297bdSopenharmony_ci        SUCCEED();
7123fc297bdSopenharmony_ci        return;
7133fc297bdSopenharmony_ci    }
7143fc297bdSopenharmony_ci    std::shared_ptr<Actions> appWarmStartActions =
7153fc297bdSopenharmony_ci        socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_[appWarmStartCmdId];
7163fc297bdSopenharmony_ci    std::shared_ptr<Actions> appColdStartActions =
7173fc297bdSopenharmony_ci        socPerfServer_->socPerf.socPerfConfig_.perfActionsInfo_[appColdStartCmdId];
7183fc297bdSopenharmony_ci    std::list<std::shared_ptr<Action>> appWarmStartActionList = appWarmStartActions->actionList;
7193fc297bdSopenharmony_ci    int32_t minThermalLvl = 3;
7203fc297bdSopenharmony_ci    for (auto item : appWarmStartActionList) {
7213fc297bdSopenharmony_ci        (*item).thermalLvl_ = minThermalLvl;
7223fc297bdSopenharmony_ci        minThermalLvl++;
7233fc297bdSopenharmony_ci    }
7243fc297bdSopenharmony_ci    std::list<std::shared_ptr<Action>>  appColdStartActionList = appColdStartActions->actionList;
7253fc297bdSopenharmony_ci    for (auto item : appColdStartActionList) {
7263fc297bdSopenharmony_ci        (*item).thermalCmdId_ = appWarmStartCmdId;
7273fc297bdSopenharmony_ci        socPerfServer_->SetThermalLevel(1);
7283fc297bdSopenharmony_ci        bool ret = socPerfServer_->socPerf.DoPerfRequestThremalLvl(appColdStartCmdId, item, EVENT_INVALID);
7293fc297bdSopenharmony_ci        EXPECT_FALSE(ret);
7303fc297bdSopenharmony_ci
7313fc297bdSopenharmony_ci        socPerfServer_->SetThermalLevel(3);
7323fc297bdSopenharmony_ci        ret = socPerfServer_->socPerf.DoPerfRequestThremalLvl(appColdStartCmdId, item, EVENT_INVALID);
7333fc297bdSopenharmony_ci        EXPECT_TRUE(ret);
7343fc297bdSopenharmony_ci
7353fc297bdSopenharmony_ci        socPerfServer_->SetThermalLevel(99);
7363fc297bdSopenharmony_ci        ret = socPerfServer_->socPerf.DoPerfRequestThremalLvl(appColdStartCmdId, item, EVENT_INVALID);
7373fc297bdSopenharmony_ci        EXPECT_TRUE(ret);
7383fc297bdSopenharmony_ci    }
7393fc297bdSopenharmony_ci}
7403fc297bdSopenharmony_ci
7413fc297bdSopenharmony_ci/*
7423fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_SetThermalLevel_Server_005
7433fc297bdSopenharmony_ci * @tc.desc: perf request lvl server API
7443fc297bdSopenharmony_ci * @tc.type FUNC
7453fc297bdSopenharmony_ci * @tc.require: issue#I95U8S
7463fc297bdSopenharmony_ci */
7473fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_SetThermalLevel_Server_005, Function | MediumTest | Level0)
7483fc297bdSopenharmony_ci{
7493fc297bdSopenharmony_ci    int32_t litCpuMinFreq = 1000;
7503fc297bdSopenharmony_ci    int32_t litCpuMaxFreq = 1001;
7513fc297bdSopenharmony_ci    std::shared_ptr<SocPerfThreadWrap> socPerfThreadWrap = socPerfServer_->socPerf.socperfThreadWrap_;
7523fc297bdSopenharmony_ci    socPerfThreadWrap->resStatusInfo_[litCpuMinFreq]->candidatesValue[ACTION_TYPE_PERFLVL] = 1000;
7533fc297bdSopenharmony_ci    bool ret = socPerfThreadWrap->ArbitratePairResInPerfLvl(litCpuMinFreq);
7543fc297bdSopenharmony_ci    EXPECT_TRUE(ret);
7553fc297bdSopenharmony_ci
7563fc297bdSopenharmony_ci    socPerfThreadWrap->resStatusInfo_[litCpuMinFreq]->candidatesValue[ACTION_TYPE_PERFLVL] = INVALID_VALUE;
7573fc297bdSopenharmony_ci    socPerfThreadWrap->resStatusInfo_[litCpuMaxFreq]->candidatesValue[ACTION_TYPE_PERFLVL] = 1000;
7583fc297bdSopenharmony_ci    ret = socPerfThreadWrap->ArbitratePairResInPerfLvl(litCpuMinFreq);
7593fc297bdSopenharmony_ci    EXPECT_TRUE(ret);
7603fc297bdSopenharmony_ci
7613fc297bdSopenharmony_ci    socPerfThreadWrap->resStatusInfo_[litCpuMinFreq]->candidatesValue[ACTION_TYPE_PERFLVL] = INVALID_VALUE;
7623fc297bdSopenharmony_ci    socPerfThreadWrap->resStatusInfo_[litCpuMaxFreq]->candidatesValue[ACTION_TYPE_PERFLVL] = INVALID_VALUE;
7633fc297bdSopenharmony_ci    ret = socPerfThreadWrap->ArbitratePairResInPerfLvl(litCpuMinFreq);
7643fc297bdSopenharmony_ci    EXPECT_FALSE(ret);
7653fc297bdSopenharmony_ci}
7663fc297bdSopenharmony_ci
7673fc297bdSopenharmony_ci/*
7683fc297bdSopenharmony_ci * @tc.name: SocPerfServerTest_End_001
7693fc297bdSopenharmony_ci * @tc.desc: perf end
7703fc297bdSopenharmony_ci * @tc.type FUNC
7713fc297bdSopenharmony_ci * @tc.require: issue#I95U8S
7723fc297bdSopenharmony_ci */
7733fc297bdSopenharmony_ciHWTEST_F(SocPerfServerTest, SocPerfServerTest_End_001, Function | MediumTest | Level0)
7743fc297bdSopenharmony_ci{
7753fc297bdSopenharmony_ci    sleep(5);
7763fc297bdSopenharmony_ci    EXPECT_TRUE(socPerfServer_->socPerf.enabled_);
7773fc297bdSopenharmony_ci}
7783fc297bdSopenharmony_ci} // namespace SOCPERF
7793fc297bdSopenharmony_ci} // namespace OHOS