• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #include "gtest/gtest.h"
17 #include "gtest/hwext/gtest-multithread.h"
18 
19 #include <vector>
20 #include "accesstoken_kit.h"
21 #include "ipc_skeleton.h"
22 #include "nativetoken_kit.h"
23 #include "notifier_mgr.h"
24 #include "plugin_mgr.h"
25 #include "res_common_util.h"
26 #include "res_sched_ipc_interface_code.h"
27 #include "res_sched_common_death_recipient.h"
28 #include "res_sched_service.h"
29 #include "res_sched_service_ability.h"
30 #include "res_sched_systemload_notifier_proxy.h"
31 #include "res_sched_systemload_notifier_stub.h"
32 #include "res_type.h"
33 #include "token_setproc.h"
34 
35 namespace OHOS {
36 namespace ResourceSchedule {
37 using namespace std;
38 using namespace testing::ext;
39 using namespace testing::mt;
40 using namespace Security::AccessToken;
41 class ResSchedServiceTest : public testing::Test {
42 public:
43     static void SetUpTestCase(void);
44     static void TearDownTestCase(void);
45     void SetUp();
46     void TearDown();
47 protected:
48     std::shared_ptr<ResSchedService> resSchedService_ = nullptr;
49     std::shared_ptr<ResSchedServiceAbility> resSchedServiceAbility_ = nullptr;
50 };
51 
52 class TestResSchedSystemloadListener : public ResSchedSystemloadNotifierStub {
53 public:
54     TestResSchedSystemloadListener() = default;
55 
OnSystemloadLevel(int32_t level)56     ErrCode OnSystemloadLevel(int32_t level)
57     {
58         testSystemloadLevel = level;
59         return ERR_OK;
60     }
61 
62     static int32_t testSystemloadLevel;
63 };
64 
65 int32_t TestResSchedSystemloadListener::testSystemloadLevel = 0;
66 
SetUpTestCase(void)67 void ResSchedServiceTest::SetUpTestCase(void)
68 {
69     static const char *perms[] = {
70         "ohos.permission.REPORT_RESOURCE_SCHEDULE_EVENT",
71         "ohos.permission.DUMP",
72     };
73     uint64_t tokenId;
74     NativeTokenInfoParams infoInstance = {
75         .dcapsNum = 0,
76         .permsNum = 2,
77         .aclsNum = 0,
78         .dcaps = nullptr,
79         .perms = perms,
80         .acls = nullptr,
81         .processName = "ResSchedServiceTest",
82         .aplStr = "system_core",
83     };
84     tokenId = GetAccessTokenId(&infoInstance);
85     SetSelfTokenID(tokenId);
86     AccessTokenKit::ReloadNativeTokenInfo();
87 }
88 
TearDownTestCase()89 void ResSchedServiceTest::TearDownTestCase() {}
90 
SetUp()91 void ResSchedServiceTest::SetUp()
92 {
93     /**
94      * @tc.setup: initialize the member variable resSchedServiceAbility_
95      */
96     resSchedService_ = make_shared<ResSchedService>();
97     resSchedServiceAbility_ = make_shared<ResSchedServiceAbility>();
98 }
99 
TearDown()100 void ResSchedServiceTest::TearDown()
101 {
102     /**
103      * @tc.teardown: clear resSchedServiceAbility_
104      */
105     resSchedService_ = nullptr;
106     resSchedServiceAbility_ = nullptr;
107 }
108 
109 /**
110  * @tc.name: ressched service dump 001
111  * @tc.desc: Verify if ressched service dump commonds is success.
112  * @tc.type: FUNC
113  * @tc.require: issueI5WWV3
114  * @tc.author:lice
115  */
116 HWTEST_F(ResSchedServiceTest, ServiceDump001, Function | MediumTest | Level0)
117 {
118     PluginMgr::GetInstance().Init();
119     std::string result;
120     resSchedService_->DumpAllInfo(result);
121     EXPECT_TRUE(!result.empty());
122 
123     result = "";
124     resSchedService_->DumpUsage(result);
125     EXPECT_TRUE(!result.empty());
126 
127     int32_t wrongFd = -1;
128     std::vector<std::u16string> argsNull;
129     int res = resSchedService_->Dump(wrongFd, argsNull);
130     EXPECT_NE(res, ERR_OK);
131 
132     int32_t correctFd = -1;
133     res = resSchedService_->Dump(correctFd, argsNull);
134 
135     std::vector<std::u16string> argsHelp = {to_utf16("-h")};
136     res = resSchedService_->Dump(correctFd, argsHelp);
137 
138     std::vector<std::u16string> argsAll = {to_utf16("-a")};
139     res = resSchedService_->Dump(correctFd, argsAll);
140 
141     std::vector<std::u16string> argsError = {to_utf16("-e")};
142     res = resSchedService_->Dump(correctFd, argsError);
143 
144     std::vector<std::u16string> argsPlugin = {to_utf16("-p")};
145     res = resSchedService_->Dump(correctFd, argsPlugin);
146 
147     std::vector<std::u16string> argsOnePlugin = {to_utf16("-p"), to_utf16("1")};
148     res = resSchedService_->Dump(correctFd, argsOnePlugin);
149 
150     std::vector<std::u16string> argsOnePlugin1 = {to_utf16("getRunningLockInfo")};
151     res = resSchedService_->Dump(correctFd, argsOnePlugin1);
152 
153     std::vector<std::u16string> argsOnePlugin2 = {to_utf16("getProcessEventInfo")};
154     res = resSchedService_->Dump(correctFd, argsOnePlugin2);
155 
156     std::vector<std::u16string> argsOnePlugin3 = {to_utf16("getProcessWindowInfo")};
157     res = resSchedService_->Dump(correctFd, argsOnePlugin3);
158 
159     std::vector<std::u16string> argsOnePlugin4 = {to_utf16("getSystemloadInfo")};
160     res = resSchedService_->Dump(correctFd, argsOnePlugin4);
161 
162     std::vector<std::u16string> argsOnePlugin5 = {to_utf16("sendDebugToExecutor")};
163     res = resSchedService_->Dump(correctFd, argsOnePlugin5);
164 }
165 
166 /**
167  * @tc.name: Ressched service ReportData 001
168  * @tc.desc: Verify if Ressched service ReportData is success.
169  * @tc.type: FUNC
170  * @tc.require: issueI5WWV3
171  * @tc.author:lice
172  */
173 HWTEST_F(ResSchedServiceTest, Report001, Function | MediumTest | Level0)
174 {
175     std::string payload;
176     EXPECT_TRUE(resSchedService_ != nullptr);
177     resSchedService_->ReportData(0, 0, payload);
178 }
179 
180 /**
181  * @tc.name: ReportSyncEvent
182  * @tc.desc: test func ReportSyncEvent.
183  * @tc.type: FUNC
184  * @tc.require: I9QN9E
185  */
186 HWTEST_F(ResSchedServiceTest, ReportSyncEvent, Function | MediumTest | Level0)
187 {
188     EXPECT_NE(resSchedService_, nullptr);
189     nlohmann::json payload({{"pid", 100}});
190     std::string reply;
191     int32_t ret;
192     resSchedService_->ReportSyncEvent(ResType::SYNC_RES_TYPE_THAW_ONE_APP, 0,
193         payload.dump(-1, ' ', false, nlohmann::detail::error_handler_t::replace),
194         reply, ret);
195     // 事件分发失败,返回err
196     EXPECT_NE(ret, 0);
197 }
198 
ReportTask()199 static void ReportTask()
200 {
201     std::shared_ptr<ResSchedService> resSchedService_ = make_shared<ResSchedService>();
202     std::string payload;
203     EXPECT_TRUE(resSchedService_ != nullptr);
204     resSchedService_->ReportData(0, 0, payload);
205 }
206 
207 /**
208  * @tc.name: Ressched service ReportData 002
209  * @tc.desc: Test Ressched service ReportData in multithreading.
210  * @tc.type: FUNC
211  * @tc.require: issueI7G8VT
212  * @tc.author: nizihao
213  */
214 HWTEST_F(ResSchedServiceTest, Report002, Function | MediumTest | Level0)
215 {
216     SET_THREAD_NUM(10);
217     GTEST_RUN_TASK(ReportTask);
218 }
219 
220 /**
221  * @tc.name: Ressched service KillProcess 001
222  * @tc.desc: test the interface service KillProcess
223  * @tc.type: FUNC
224  * @tc.require: issueI8VZVN
225  * @tc.author:z30053169
226  */
227 HWTEST_F(ResSchedServiceTest, KillProcess001, Function | MediumTest | Level0)
228 {
229     std::string payload;
230     int32_t t;
231     resSchedService_->KillProcess(payload, t);
232     EXPECT_EQ(t, -1);
233 }
234 
235 /**
236  * @tc.name: Ressched service TestResSchedSystemloadListener 001
237  * @tc.desc: test the interface service TestResSchedSystemloadListener
238  * @tc.type: FUNC
239  * @tc.require: issueI97M6C
240  * @tc.author:shanhaiyang
241  */
242 HWTEST_F(ResSchedServiceTest, TestResSchedSystemloadListener001, Function | MediumTest | Level0)
243 {
244     std::shared_ptr<ResSchedService> resSchedService_ = make_shared<ResSchedService>();
245     EXPECT_TRUE(resSchedService_ != nullptr);
246     sptr<IRemoteObject> notifier = new (std::nothrow) TestResSchedSystemloadListener();
247     EXPECT_TRUE(notifier != nullptr);
248     NotifierMgr::GetInstance().Init();
249     resSchedService_->RegisterSystemloadNotifier(notifier);
250     NotifierMgr::GetInstance().OnApplicationStateChange(2, IPCSkeleton::GetCallingPid());
251     resSchedService_->OnDeviceLevelChanged(0, 2);
252     sleep(1);
253     EXPECT_TRUE(TestResSchedSystemloadListener::testSystemloadLevel == 2);
254     resSchedService_->UnRegisterSystemloadNotifier();
255     NotifierMgr::GetInstance().OnApplicationStateChange(4, IPCSkeleton::GetCallingPid());
256     TestResSchedSystemloadListener::testSystemloadLevel = 0;
257 }
258 
259 /**
260  * @tc.name: Ressched service TestResSchedSystemloadListener 002
261  * @tc.desc: test the interface service TestResSchedSystemloadListener
262  * @tc.type: FUNC
263  * @tc.require: issueI97M6C
264  * @tc.author:shanhaiyang
265  */
266 HWTEST_F(ResSchedServiceTest, TestResSchedSystemloadListener002, Function | MediumTest | Level0)
267 {
268     std::shared_ptr<ResSchedService> resSchedService_ = make_shared<ResSchedService>();
269     EXPECT_TRUE(resSchedService_ != nullptr);
270     sptr<IRemoteObject> notifier = new (std::nothrow) TestResSchedSystemloadListener();
271     EXPECT_TRUE(notifier != nullptr);
272     NotifierMgr::GetInstance().Init();
273     resSchedService_->RegisterSystemloadNotifier(notifier);
274     resSchedService_->OnDeviceLevelChanged(0, 2);
275     sleep(1);
276     EXPECT_TRUE(TestResSchedSystemloadListener::testSystemloadLevel == 2);
277     resSchedService_->UnRegisterSystemloadNotifier();
278     TestResSchedSystemloadListener::testSystemloadLevel = 0;
279 }
280 
281 /**
282  * @tc.name: Ressched service TestResSchedSystemloadListener 003
283  * @tc.desc: test the interface service TestResSchedSystemloadListener
284  * @tc.type: FUNC
285  * @tc.require: issueI97M6C
286  * @tc.author:shanhaiyang
287  */
288 HWTEST_F(ResSchedServiceTest, TestResSchedSystemloadListener003, Function | MediumTest | Level0)
289 {
290     std::shared_ptr<ResSchedService> resSchedService_ = make_shared<ResSchedService>();
291     EXPECT_TRUE(resSchedService_ != nullptr);
292     sptr<IRemoteObject> notifier = new (std::nothrow) TestResSchedSystemloadListener();
293     EXPECT_TRUE(notifier != nullptr);
294     NotifierMgr::GetInstance().Init();
295     resSchedService_->RegisterSystemloadNotifier(notifier);
296     NotifierMgr::GetInstance().OnApplicationStateChange(2, 111111);
297     resSchedService_->OnDeviceLevelChanged(0, 2);
298     sleep(1);
299     EXPECT_TRUE(TestResSchedSystemloadListener::testSystemloadLevel == 2);
300     resSchedService_->UnRegisterSystemloadNotifier();
301     NotifierMgr::GetInstance().OnApplicationStateChange(4, 111111);
302     TestResSchedSystemloadListener::testSystemloadLevel = 0;
303 }
304 
305 /**
306  * @tc.name: Ressched service TestResSchedSystemloadListener 004
307  * @tc.desc: test the interface service TestResSchedSystemloadListener
308  * @tc.type: FUNC
309  * @tc.require: issueI97M6C
310  * @tc.author:shanhaiyang
311  */
312 HWTEST_F(ResSchedServiceTest, TestResSchedSystemloadListener004, Function | MediumTest | Level0)
313 {
314     std::shared_ptr<ResSchedService> resSchedService_ = make_shared<ResSchedService>();
315     EXPECT_TRUE(resSchedService_ != nullptr);
316     sptr<IRemoteObject> notifier = new (std::nothrow) TestResSchedSystemloadListener();
317     EXPECT_TRUE(notifier != nullptr);
318     NotifierMgr::GetInstance().Init();
319     std::string cbType = "systemLoadChange";
320     resSchedService_->RegisterSystemloadNotifier(notifier);
321     NotifierMgr::GetInstance().OnApplicationStateChange(2, IPCSkeleton::GetCallingPid());
322     NotifierMgr::GetInstance().OnRemoteNotifierDied(notifier);
323     resSchedService_->OnDeviceLevelChanged(0, 2);
324     sleep(1);
325     EXPECT_TRUE(TestResSchedSystemloadListener::testSystemloadLevel == 0);
326     resSchedService_->UnRegisterSystemloadNotifier();
327     NotifierMgr::GetInstance().OnApplicationStateChange(4, IPCSkeleton::GetCallingPid());
328     TestResSchedSystemloadListener::testSystemloadLevel = 0;
329 }
330 
331 /**
332  * @tc.name: Ressched service RegisterSystemloadNotifier 001
333  * @tc.desc: test the interface service RegisterSystemloadNotifier
334  * @tc.type: FUNC
335  * @tc.require: issueI97M6C
336  * @tc.author:shanhaiyang
337  */
338 HWTEST_F(ResSchedServiceTest, RegisterSystemloadNotifier001, Function | MediumTest | Level0)
339 {
340     std::shared_ptr<ResSchedService> resSchedService_ = make_shared<ResSchedService>();
341     EXPECT_TRUE(resSchedService_ != nullptr);
342     sptr<IRemoteObject> notifier = new (std::nothrow) TestResSchedSystemloadListener();
343     EXPECT_TRUE(notifier != nullptr);
344     NotifierMgr::GetInstance().Init();
345     resSchedService_->RegisterSystemloadNotifier(notifier);
346 }
347 
348 /**
349  * @tc.name: Ressched service RegisterSystemloadNotifier 002
350  * @tc.desc: test the interface service RegisterSystemloadNotifier
351  * @tc.type: FUNC
352  * @tc.require: issueI97M6C
353  * @tc.author:shanhaiyang
354  */
355 HWTEST_F(ResSchedServiceTest, RegisterSystemloadNotifier002, Function | MediumTest | Level0)
356 {
357     std::shared_ptr<ResSchedService> resSchedService_ = make_shared<ResSchedService>();
358     EXPECT_TRUE(resSchedService_ != nullptr);
359     sptr<IRemoteObject> notifier = new (std::nothrow) TestResSchedSystemloadListener();
360     EXPECT_TRUE(notifier != nullptr);
361     NotifierMgr::GetInstance().Init();
362     resSchedService_->RegisterSystemloadNotifier(notifier);
363     resSchedService_->RegisterSystemloadNotifier(notifier);
364 }
365 
366 /**
367  * @tc.name: Ressched service UnRegisterSystemloadNotifier 001
368  * @tc.desc: test the interface service UnRegisterSystemloadNotifier
369  * @tc.type: FUNC
370  * @tc.require: issueI97M6C
371  * @tc.author:shanhaiyang
372  */
373 HWTEST_F(ResSchedServiceTest, UnRegisterSystemloadNotifier001, Function | MediumTest | Level0)
374 {
375     std::shared_ptr<ResSchedService> resSchedService_ = make_shared<ResSchedService>();
376     EXPECT_TRUE(resSchedService_ != nullptr);
377     sptr<IRemoteObject> notifier = new (std::nothrow) TestResSchedSystemloadListener();
378     EXPECT_TRUE(notifier != nullptr);
379     NotifierMgr::GetInstance().Init();
380     resSchedService_->RegisterSystemloadNotifier(notifier);
381     resSchedService_->UnRegisterSystemloadNotifier();
382 }
383 
384 /**
385  * @tc.name: Ressched service UnRegisterSystemloadNotifier 002
386  * @tc.desc: test the interface service UnRegisterSystemloadNotifier
387  * @tc.type: FUNC
388  * @tc.require: issueI97M6C
389  * @tc.author:shanhaiyang
390  */
391 HWTEST_F(ResSchedServiceTest, UnRegisterSystemloadNotifier002, Function | MediumTest | Level0)
392 {
393     std::shared_ptr<ResSchedService> resSchedService_ = make_shared<ResSchedService>();
394     EXPECT_TRUE(resSchedService_ != nullptr);
395     sptr<IRemoteObject> notifier = new (std::nothrow) TestResSchedSystemloadListener();
396     EXPECT_TRUE(notifier != nullptr);
397     NotifierMgr::GetInstance().Init();
398     resSchedService_->UnRegisterSystemloadNotifier();
399 }
400 
401 /**
402  * @tc.name: Ressched service GetSystemloadLevel 001
403  * @tc.desc: test the interface service GetSystemloadLevel
404  * @tc.type: FUNC
405  * @tc.require: issueI97M6C
406  * @tc.author:shanhaiyang
407  */
408 HWTEST_F(ResSchedServiceTest, GetSystemloadLevel001, Function | MediumTest | Level0)
409 {
410     std::shared_ptr<ResSchedService> resSchedService_ = make_shared<ResSchedService>();
411     EXPECT_TRUE(resSchedService_ != nullptr);
412     sptr<IRemoteObject> notifier = new (std::nothrow) TestResSchedSystemloadListener();
413     EXPECT_TRUE(notifier != nullptr);
414     NotifierMgr::GetInstance().Init();
415     resSchedService_->OnDeviceLevelChanged(0, 0);
416     int32_t res;
417     resSchedService_->GetSystemloadLevel(res);
418     EXPECT_TRUE(res == 0);
419 }
420 
421 /**
422  * @tc.name: Ressched service GetSystemloadLevel 002
423  * @tc.desc: test the interface service GetSystemloadLevel
424  * @tc.type: FUNC
425  * @tc.require: issueI97M6C
426  * @tc.author:shanhaiyang
427  */
428 HWTEST_F(ResSchedServiceTest, GetSystemloadLevel002, Function | MediumTest | Level0)
429 {
430     std::shared_ptr<ResSchedService> resSchedService_ = make_shared<ResSchedService>();
431     EXPECT_TRUE(resSchedService_ != nullptr);
432     sptr<IRemoteObject> notifier = new (std::nothrow) TestResSchedSystemloadListener();
433     EXPECT_TRUE(notifier != nullptr);
434     NotifierMgr::GetInstance().Init();
435     resSchedService_->OnDeviceLevelChanged(0, 2);
436     resSchedService_->OnDeviceLevelChanged(1, 5);
437     int32_t res;
438     resSchedService_->GetSystemloadLevel(res);
439     EXPECT_TRUE(res == 2);
440 }
441 
442 /**
443  * @tc.name: Start ResSchedServiceAbility 001
444  * @tc.desc: Verify if ResSchedServiceAbility OnStart is success.
445  * @tc.type: FUNC
446  * @tc.require: issueI5WWV3
447  * @tc.author:lice
448  */
449 HWTEST_F(ResSchedServiceTest, OnStart001, Function | MediumTest | Level0)
450 {
451     resSchedServiceAbility_->OnStart();
452     EXPECT_TRUE(resSchedServiceAbility_->service_ != nullptr);
453 }
454 
OnStartTask()455 static void OnStartTask()
456 {
457     std::shared_ptr<ResSchedServiceAbility> resSchedServiceAbility_ = make_shared<ResSchedServiceAbility>();
458     resSchedServiceAbility_->OnStart();
459     EXPECT_TRUE(resSchedServiceAbility_->service_ != nullptr);
460 }
461 
462 /**
463  * @tc.name: Start ResSchedServiceAbility 002
464  * @tc.desc: Test ResSchedServiceAbility OnStart in multithreading.
465  * @tc.type: FUNC
466  * @tc.require: issueI7G8VT
467  * @tc.author: nizihao
468  */
469 HWTEST_F(ResSchedServiceTest, OnStart002, Function | MediumTest | Level0)
470 {
471     SET_THREAD_NUM(10);
472     GTEST_RUN_TASK(OnStartTask);
473 }
474 
475 /**
476  * @tc.name: ResSchedServiceAbility ChangeAbility 001
477  * @tc.desc: Verify if add and remove system ability is success.
478  * @tc.type: FUNC
479  * @tc.require: issueI5WWV3
480  * @tc.author:lice
481  */
482 HWTEST_F(ResSchedServiceTest, ChangeAbility001, Function | MediumTest | Level0)
483 {
484     std::string deviceId;
485     int32_t systemAbilityId = -1;
486     resSchedServiceAbility_->OnAddSystemAbility(systemAbilityId, deviceId);
487     resSchedServiceAbility_->OnRemoveSystemAbility(systemAbilityId, deviceId);
488     EXPECT_EQ(systemAbilityId, -1);
489 }
490 
ChangeAbilityTask()491 static void ChangeAbilityTask()
492 {
493     std::shared_ptr<ResSchedServiceAbility> resSchedServiceAbility_ = make_shared<ResSchedServiceAbility>();
494     std::string deviceId;
495     resSchedServiceAbility_->OnAddSystemAbility(-1, deviceId);
496     resSchedServiceAbility_->OnRemoveSystemAbility(-1, deviceId);
497 }
498 
499 /**
500  * @tc.name: ResSchedServiceAbility ChangeAbility 002
501  * @tc.desc: Test add and remove system ability in multithreading.
502  * @tc.type: FUNC
503  * @tc.require: issueI7G8VT
504  * @tc.author: nizihao
505  */
506 HWTEST_F(ResSchedServiceTest, ChangeAbility002, Function | MediumTest | Level0)
507 {
508     SET_THREAD_NUM(10);
509     GTEST_RUN_TASK(ChangeAbilityTask);
510 }
511 
512 class TestResSchedServiceStub : public ResSchedServiceStub {
513 public:
TestResSchedServiceStub()514     TestResSchedServiceStub() : ResSchedServiceStub() {}
515 
ReportData(uint32_t restype,int64_t value,const std::string & payload)516     ErrCode ReportData(uint32_t restype, int64_t value, const std::string& payload) override
517     {
518         return ERR_OK;
519     }
520 
ReportSyncEvent(uint32_t resType,int64_t value,const std::string & payload,std::string & reply,int32_t & resultValue)521     ErrCode ReportSyncEvent(uint32_t resType, int64_t value, const std::string& payload,
522         std::string& reply, int32_t& resultValue) override
523     {
524         return ERR_OK;
525     }
526 
KillProcess(const std::string & payload,int32_t & resultValue)527     ErrCode KillProcess(const std::string& payload, int32_t& resultValue) override
528     {
529         return ERR_OK;
530     }
531 
RegisterSystemloadNotifier(const sptr<IRemoteObject> & notifier)532     ErrCode RegisterSystemloadNotifier(const sptr<IRemoteObject>& notifier) override
533     {
534         return ERR_OK;
535     }
536 
UnRegisterSystemloadNotifier()537     ErrCode UnRegisterSystemloadNotifier() override
538     {
539         return ERR_OK;
540     }
541 
RegisterEventListener(const sptr<IRemoteObject> & listener,uint32_t eventType,uint32_t listenerGroup)542     ErrCode RegisterEventListener(const sptr<IRemoteObject>& listener, uint32_t eventType,
543         uint32_t listenerGroup) override
544     {
545         return ERR_OK;
546     }
547 
UnRegisterEventListener(uint32_t eventType,uint32_t listenerGroup)548     ErrCode UnRegisterEventListener(uint32_t eventType,
549         uint32_t listenerGroup) override
550     {
551         return ERR_OK;
552     }
553 
GetSystemloadLevel(int32_t & resultValue)554     ErrCode GetSystemloadLevel(int32_t& resultValue) override
555     {
556         return ERR_OK;
557     }
558 
IsAllowedAppPreload(const std::string & bundleName,int32_t preloadMode,bool & resultValue)559     ErrCode IsAllowedAppPreload(const std::string& bundleName, int32_t preloadMode, bool& resultValue) override
560     {
561         return ERR_OK;
562     }
563 
IsAllowedLinkJump(bool isAllowedLinkJump,int32_t & resultValue)564     ErrCode IsAllowedLinkJump(bool isAllowedLinkJump, int32_t& resultValue) override
565     {
566         return ERR_OK;
567     }
568 };
569 
570 /**
571  * @tc.name: ResSchedServicesStub RemoteRequest 001
572  * @tc.desc: Verify if resschedstub RemoteRequest is success.
573  * @tc.type: FUNC
574  * @tc.require: issueI5WWV3 issueI6D6BM
575  * @tc.author:lice
576  */
577 HWTEST_F(ResSchedServiceTest, RemoteRequest001, Function | MediumTest | Level0)
578 {
579     auto resSchedServiceStub_ = make_shared<TestResSchedServiceStub>();
580     MessageOption option;
581     MessageParcel reply;
582     int32_t res = resSchedServiceStub_->OnRemoteRequest(
583         static_cast<uint32_t>(IResSchedServiceIpcCode::COMMAND_REPORT_DATA), reply, reply, option);
584     EXPECT_TRUE(res);
585     res = resSchedServiceStub_->OnRemoteRequest(
586         static_cast<uint32_t>(IResSchedServiceIpcCode::COMMAND_REPORT_SYNC_EVENT), reply, reply, option);
587     EXPECT_TRUE(res);
588     res = resSchedServiceStub_->OnRemoteRequest(
589         static_cast<uint32_t>(IResSchedServiceIpcCode::COMMAND_KILL_PROCESS), reply, reply, option);
590     EXPECT_TRUE(res);
591     res = resSchedServiceStub_->OnRemoteRequest(0, reply, reply, option);
592     EXPECT_TRUE(res);
593     res = resSchedServiceStub_->OnRemoteRequest(
594         static_cast<uint32_t>(IResSchedServiceIpcCode::COMMAND_REGISTER_SYSTEMLOAD_NOTIFIER), reply, reply, option);
595     EXPECT_TRUE(res);
596     res = resSchedServiceStub_->OnRemoteRequest(
597         static_cast<uint32_t>(IResSchedServiceIpcCode::COMMAND_UN_REGISTER_SYSTEMLOAD_NOTIFIER), reply, reply, option);
598     EXPECT_TRUE(res);
599     res = resSchedServiceStub_->OnRemoteRequest(
600         static_cast<uint32_t>(IResSchedServiceIpcCode::COMMAND_GET_SYSTEMLOAD_LEVEL), reply, reply, option);
601     EXPECT_TRUE(res);
602 }
603 
RemoteRequestTask()604 static void RemoteRequestTask()
605 {
606     auto resSchedServiceStub_ = make_shared<TestResSchedServiceStub>();
607     MessageOption option;
608     MessageParcel reply;
609     int32_t res = resSchedServiceStub_->OnRemoteRequest(
610         static_cast<uint32_t>(IResSchedServiceIpcCode::COMMAND_REPORT_DATA), reply, reply, option);
611     EXPECT_TRUE(res);
612     res = resSchedServiceStub_->OnRemoteRequest(
613         static_cast<uint32_t>(IResSchedServiceIpcCode::COMMAND_KILL_PROCESS), reply, reply, option);
614     EXPECT_TRUE(res);
615     res = resSchedServiceStub_->OnRemoteRequest(0, reply, reply, option);
616     EXPECT_TRUE(res);
617     res = resSchedServiceStub_->OnRemoteRequest(
618         static_cast<uint32_t>(IResSchedServiceIpcCode::COMMAND_REGISTER_SYSTEMLOAD_NOTIFIER), reply, reply, option);
619     EXPECT_TRUE(res);
620     res = resSchedServiceStub_->OnRemoteRequest(
621         static_cast<uint32_t>(IResSchedServiceIpcCode::COMMAND_UN_REGISTER_SYSTEMLOAD_NOTIFIER), reply, reply, option);
622     EXPECT_TRUE(res);
623     res = resSchedServiceStub_->OnRemoteRequest(
624         static_cast<uint32_t>(IResSchedServiceIpcCode::COMMAND_GET_SYSTEMLOAD_LEVEL), reply, reply, option);
625     EXPECT_TRUE(res);
626 }
627 
628 /**
629  * @tc.name: ResSchedServicesStub RemoteRequest 002
630  * @tc.desc: Test resschedstub RemoteRequest in multithreading.
631  * @tc.type: FUNC
632  * @tc.require: issueI7G8VT
633  * @tc.author: nizihao
634  */
635 HWTEST_F(ResSchedServiceTest, RemoteRequest002, Function | MediumTest | Level0)
636 {
637     SET_THREAD_NUM(10);
638     GTEST_RUN_TASK(RemoteRequestTask);
639 }
640 } // namespace ResourceSchedule
641 } // namespace OHOS
642