• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <cstdio>
17 #include <cstring>
18 #include <fcntl.h>
19 #include <gmock/gmock.h>
20 #include <gtest/gtest.h>
21 #include <iostream>
22 #include <memory>
23 #include <sys/mman.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include "cJSON.h"
27 #include "if_system_ability_manager.h"
28 #include "ipc_types.h"
29 #include "iservice_registry.h"
30 #include "iupdate_callback.h"
31 #include "iupdate_service.h"
32 #include "parameters.h"
33 #include "unittest_comm.h"
34 #include "update_callback.h"
35 #include "update_callback_proxy.h"
36 #include "update_helper.h"
37 #include "update_service.h"
38 #include "update_service_kits_impl.h"
39 #include "update_service_proxy.h"
40 
41 using namespace std;
42 using namespace testing::ext;
43 using namespace OHOS;
44 using namespace OHOS::update_engine;
45 static const int32_t DLNOW_10 = 10;
46 static const int32_t DLNOW_20 = 20;
47 static const int32_t DLNOW_50 = 50;
48 static const int32_t DLNOW_70 = 70;
49 static const int32_t DLNOW_80 = 80;
50 static const int32_t DLTOTAL_NUM = 100;
51 static const int32_t UPGRADE_INTERVAL_2 = 2222;
52 static const int32_t UPGRADE_INTERVAL_3 = 3333;
53 static const int32_t JSON_MAX_SIZE = 4096;
54 #define UNUSED(x) (void)(x)
GetUpdateService()55 static UpdateService *GetUpdateService()
56 {
57     static UpdateService *updateServer = nullptr;
58     if (updateServer == nullptr) {
59         updateServer = new UpdateService(0, true);
60     }
61     return updateServer;
62 }
63 
64 class UpdateServerTest : public ::testing::Test {
65 public:
UpdateServerTest()66     UpdateServerTest()
67     {
68         updateServer_ = GetUpdateService();
69         updateCallBack_ = new UpdateCallback();
70     }
~UpdateServerTest()71     virtual ~UpdateServerTest()
72     {
73         delete updateCallBack_;
74         updateCallBack_ = nullptr;
75     }
76 
SetUp()77     void SetUp() {}
TearDown()78     void TearDown() {}
TestBody()79     void TestBody() {}
80 
TestRegisterCallback()81     int TestRegisterCallback()
82     {
83         return 0;
84     }
85 
TestCheckNewVersion()86     int TestCheckNewVersion()
87     {
88         ENGINE_CHECK(updateServer_ != nullptr, return -1, "Can not find server");
89         MessageParcel inData;
90         MessageParcel reply;
91         MessageOption msgOption;
92         updateServer_->OnRemoteRequest(IUpdateService::CHECK_VERSION, inData, reply, msgOption);
93         return 0;
94     }
95 
TestDownload()96     int TestDownload()
97     {
98         ENGINE_CHECK(updateServer_ != nullptr, return -1, "Can not find server");
99         MessageParcel inData;
100         MessageParcel reply;
101         MessageOption msgOption;
102         updateServer_->OnRemoteRequest(IUpdateService::DOWNLOAD, inData, reply, msgOption);
103         EXPECT_EQ(0, reply.ReadInt32());
104         sleep(1);
105         updateServer_->OnRemoteRequest(IUpdateService::CANCEL, inData, reply, msgOption);
106         return 0;
107     }
108 
TestDoUpdate()109     int TestDoUpdate()
110     {
111         ENGINE_CHECK(updateServer_ != nullptr, return -1, "Can not find server");
112         MessageParcel inData;
113         MessageParcel reply;
114         MessageOption msgOption;
115         updateServer_->OnRemoteRequest(IUpdateService::UPGRADE, inData, reply, msgOption);
116         EXPECT_EQ(-1, reply.ReadInt32());
117         sptr<IUpdateCallback> callback_ {};
118         UpdateContext ctx {};
119         ctx.upgradeFile = "/data/ota_package/updater.zip";
120         UpdateService *updateServer = new UpdateService(0, true);
121         int ret = updateServer->RegisterUpdateCallback(ctx, callback_);
122         EXPECT_EQ(0, ret);
123         EXPECT_NE(updateServer, nullptr);
124         updateServer->DoUpdate();
125         ret = updateServer->UnregisterUpdateCallback();
126         EXPECT_EQ(0, ret);
127         delete updateServer;
128         return 0;
129     }
130 
TestGetUpdatePolicy(UpdatePolicy & policy)131     int TestGetUpdatePolicy(UpdatePolicy &policy)
132     {
133         MessageParcel inData;
134         MessageParcel reply;
135         MessageOption msgOption;
136         updateServer_->OnRemoteRequest(IUpdateService::GET_POLICY, inData, reply, msgOption);
137         UpdateHelper::ReadUpdatePolicy(reply, policy);
138         return 0;
139     }
140 
TestUpdatePolicy()141     int TestUpdatePolicy()
142     {
143         ENGINE_CHECK(updateServer_ != nullptr, return -1, "Can not find server");
144         UpdatePolicy policy;
145         policy.autoDownload = true;
146         policy.autoDownloadNet = true;
147         policy.mode = INSTALLMODE_AUTO;
148         policy.autoUpgradeInterval[0] = UPGRADE_INTERVAL_2;
149         policy.autoUpgradeInterval[1] = UPGRADE_INTERVAL_3;
150         MessageParcel inData;
151         UpdateHelper::WriteUpdatePolicy(inData, policy);
152         MessageParcel reply;
153         MessageOption msgOption;
154         updateServer_->OnRemoteRequest(IUpdateService::SET_POLICY, inData, reply, msgOption);
155         UpdatePolicy policy2;
156         (void)TestGetUpdatePolicy(policy2);
157         EXPECT_EQ(policy.autoUpgradeInterval[0], policy2.autoUpgradeInterval[0]);
158         return 0;
159     }
160 
TestGetNewVersion()161     int TestGetNewVersion()
162     {
163         VersionInfo versionInfo;
164         MessageParcel inData;
165         MessageParcel reply;
166         MessageOption msgOption;
167         updateServer_->OnRemoteRequest(IUpdateService::GET_NEW_VERSION, inData, reply, msgOption);
168         UpdateHelper::ReadVersionInfo(reply, versionInfo);
169         EXPECT_EQ(versionInfo.status, HAS_NEW_VERSION);
170         return 0;
171     }
172 
TestGetUpgradeStatus()173     int TestGetUpgradeStatus()
174     {
175         UpgradeInfo info;
176         MessageParcel inData;
177         MessageParcel reply;
178         MessageOption msgOption;
179         updateServer_->OnRemoteRequest(IUpdateService::GET_STATUS, inData, reply, msgOption);
180         UpdateHelper::ReadUpgradeInfo(reply, info);
181         return 0;
182     }
183 
TestRebootAndClean()184     int TestRebootAndClean()
185     {
186         VersionInfo versionInfo;
187         MessageParcel inData;
188         MessageParcel reply;
189         MessageOption msgOption;
190         updateServer_->OnRemoteRequest(IUpdateService::REBOOT_CLEAN, inData, reply, msgOption);
191         EXPECT_EQ(reply.ReadInt32(), 0);
192         return 0;
193     }
194 
TestRebootAndInstall()195     int TestRebootAndInstall()
196     {
197         VersionInfo versionInfo;
198         MessageParcel inData;
199         MessageParcel reply;
200         MessageOption msgOption;
201         updateServer_->OnRemoteRequest(IUpdateService::REBOOT_INSTALL, inData, reply, msgOption);
202         EXPECT_EQ(reply.ReadInt32(), 0);
203         return 0;
204     }
205 
TestRegisterUpdateCallback()206     int TestRegisterUpdateCallback()
207     {
208         VersionInfo versionInfo;
209         MessageParcel inData;
210         MessageParcel reply;
211         MessageOption msgOption;
212         updateServer_->OnRemoteRequest(IUpdateService::REGISTER_CALLBACK, inData, reply, msgOption);
213         EXPECT_EQ(reply.ReadInt32(), -1);
214         return 0;
215     }
216 
TestUnRegisterUpdateCallback()217     int TestUnRegisterUpdateCallback()
218     {
219         VersionInfo versionInfo;
220         MessageParcel inData;
221         MessageParcel reply;
222         MessageOption msgOption;
223         updateServer_->OnRemoteRequest(IUpdateService::UNREGISTER_CALLBACK, inData, reply, msgOption);
224         EXPECT_EQ(reply.ReadInt32(), 0);
225         return 0;
226     }
227 
TestReadCheckVersiondescriptInfo()228     int TestReadCheckVersiondescriptInfo()
229     {
230         cJSON *temp = cJSON_CreateObject();
231         EXPECT_NE(temp, nullptr);
232         cJSON_AddStringToObject(temp, "descriptPackageId", "descriptPackageId1");
233         cJSON_AddStringToObject(temp, "content", "content1");
234         cJSON_AddNumberToObject(temp, "id", 1);
235         cJSON* array = cJSON_CreateArray();
236         EXPECT_NE(array, nullptr);
237         cJSON_AddItemToArray(array, temp);
238 
239         VersionInfo info {};
240         updateServer_->ReadCheckVersiondescriptInfo(array, info);
241         EXPECT_STREQ(info.descriptInfo[0].descriptPackageId.c_str(), "descriptPackageId1");
242         EXPECT_STREQ(info.descriptInfo[0].content.c_str(), "content1");
243         return 0;
244     }
245 
TestUpdateServiceProxy()246     int TestUpdateServiceProxy()
247     {
248         sptr<ISystemAbilityManager> systemMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
249         EXPECT_NE(systemMgr, nullptr);
250         sptr<IRemoteObject> remoteObj = systemMgr->GetSystemAbility(UPDATE_DISTRIBUTED_SERVICE_ID);
251         EXPECT_NE(remoteObj, nullptr);
252         UpdateServiceProxy *proxy = new UpdateServiceProxy(remoteObj);
253         UpdateCallbackProxy *updateCallBack = new UpdateCallbackProxy(remoteObj);
254         std::string miscFile = "/dev/block/by-name/misc";
255         std::string packageName = "/data/ota_package/updater.zip";
256         const std::string cmd = "--update_package=/data/ota_package/updater.zip";
257         VersionInfo info {};
258         Progress progress {};
259         UpdateContext ctx {};
260         updateCallBack->OnCheckVersionDone(info);
261         updateCallBack->OnDownloadProgress(progress);
262         updateCallBack->OnUpgradeProgress(progress);
263         proxy->RegisterUpdateCallback(ctx, updateCallBack);
264         proxy->UnregisterUpdateCallback();
265         proxy->DoUpdate();
266         proxy->RebootAndClean(miscFile, cmd);
267         proxy->RebootAndInstall(miscFile, packageName);
268         EXPECT_EQ(info.status, HAS_NEW_VERSION);
269         EXPECT_EQ(progress.status, UPDATE_STATE_INIT);
270         delete proxy;
271         return 0;
272     }
273 
TestUpdateCallbackCheckNewVersion()274     int TestUpdateCallbackCheckNewVersion()
275     {
276         MessageParcel inData;
277         MessageParcel reply;
278         MessageOption msgOption;
279         updateCallBack_->OnRemoteRequest(IUpdateService::CHECK_VERSION, inData, reply, msgOption);
280         EXPECT_EQ(reply.ReadInt32(), 0);
281         return 0;
282     }
283 
TestUpdateCallbackDownload()284     int TestUpdateCallbackDownload()
285     {
286         MessageParcel inData;
287         MessageParcel reply;
288         MessageOption msgOption;
289         updateCallBack_->OnRemoteRequest(IUpdateService::DOWNLOAD, inData, reply, msgOption);
290         EXPECT_EQ(reply.ReadInt32(), 0);
291         return 0;
292     }
293 
TestUpdateCallbackUpgrade()294     int TestUpdateCallbackUpgrade()
295     {
296         MessageParcel inData;
297         MessageParcel reply;
298         MessageOption msgOption;
299         updateCallBack_->OnRemoteRequest(IUpdateService::UPGRADE, inData, reply, msgOption);
300         EXPECT_EQ(reply.ReadInt32(), 0);
301         return 0;
302     }
GetServerIp(std::string & ip)303     void GetServerIp(std::string &ip)
304     {
305         ip = OHOS::system::GetParameter("update.serverip", "127.0.0.1");
306     }
307 
TestDownLoadProgress()308     int TestDownLoadProgress()
309     {
310         DownloadThread *download = new DownloadThread(
311             [&](const std::string &filaName, const Progress &progress) -> int {
312             return 0;
313         });
314         EXPECT_EQ(download == 0, 0);
315         std::string serverAddr;
316         GetServerIp(serverAddr);
317         std::string url = "http://";
318         url += serverAddr;
319         url += "/updater.zip";
320         download->StartDownload("updater.zip", url);
321         DownloadThread::DownloadProgress(download, DLTOTAL_NUM, DLNOW_10, 0, 0);
322         DownloadThread::DownloadProgress(download, DLTOTAL_NUM, DLNOW_20, 0, 0);
323         DownloadThread::DownloadProgress(download, DLTOTAL_NUM, DLNOW_50, 0, 0);
324         DownloadThread::DownloadProgress(download, DLTOTAL_NUM, DLNOW_70, 0, 0);
325         download->StopDownload();
326         DownloadThread::DownloadProgress(download, DLTOTAL_NUM, DLNOW_80, 0, 0);
327         DownloadThread::DownloadProgress(download, DLTOTAL_NUM, DLTOTAL_NUM, 0, 0);
328 
329         // get file
330         std::string jsonFileName = TEST_PATH_FROM;
331         jsonFileName += "packageInfos.json";
332         size_t length = DownloadThread::GetLocalFileLength(jsonFileName);
333         // write file
334         FILE *downloadFile = fopen("packageInfos.json", "ab+");
335         if (downloadFile != nullptr) {
336             VersionInfo versionInfo {};
337             std::vector<char> buffer(JSON_MAX_SIZE);
338             fread(buffer.data(), 1, JSON_MAX_SIZE, downloadFile);
339             UpdateService::ParseJsonFile(buffer, versionInfo);
340             DownloadThread::WriteFunc(reinterpret_cast<void *>buffer.data(), length, 1, downloadFile);
341         }
342         delete download;
343         return 0;
344     }
345 
TestNewUpdateService()346     int TestNewUpdateService()
347     {
348         UpdateService *updateServer = new UpdateService(0, true);
349         updateServer->OnStart();
350         updateServer->OnStop();
351         delete updateServer;
352         return 0;
353     }
354 
355 private:
356     UpdateService *updateServer_ = nullptr;
357     UpdateCallback *updateCallBack_ = nullptr;
358 };
359 
360 class MockUpdateServiceKits : public UpdateServiceKits {
361 public:
362     MockUpdateServiceKits() = default;
363     virtual ~MockUpdateServiceKits() = default;
364 
RegisterUpdateCallback(const UpdateContext & ctx,const UpdateCallbackInfo & cb)365     int32_t RegisterUpdateCallback(const UpdateContext &ctx, const UpdateCallbackInfo &cb) override
366     {
367         UNUSED(ctx);
368         UNUSED(cb);
369         return 0;
370     }
371 
UnregisterUpdateCallback()372     int32_t UnregisterUpdateCallback() override
373     {
374         return 0;
375     }
376 
CheckNewVersion()377     int32_t CheckNewVersion() override
378     {
379         return 0;
380     }
381 
DownloadVersion()382     int32_t DownloadVersion() override
383     {
384         return 0;
385     }
386 
DoUpdate()387     int32_t DoUpdate() override
388     {
389         return 0;
390     }
391 
GetNewVersion(VersionInfo & versionInfo)392     int32_t GetNewVersion(VersionInfo &versionInfo) override
393     {
394         UNUSED(versionInfo);
395         return 0;
396     }
397 
GetUpgradeStatus(UpgradeInfo & info)398     int32_t GetUpgradeStatus(UpgradeInfo &info) override
399     {
400         UNUSED(info);
401         return 0;
402     }
403 
SetUpdatePolicy(const UpdatePolicy & policy)404     int32_t SetUpdatePolicy(const UpdatePolicy &policy) override
405     {
406         UNUSED(policy);
407         return 0;
408     }
409 
GetUpdatePolicy(UpdatePolicy & policy)410     int32_t GetUpdatePolicy(UpdatePolicy &policy) override
411     {
412         UNUSED(policy);
413         return 0;
414     }
415 
Cancel(int32_t service)416     int32_t Cancel(int32_t service) override
417     {
418         return service;
419     }
420 
RebootAndClean(const std::string & miscFile,const std::string & cmd)421     virtual int32_t RebootAndClean(const std::string &miscFile, const std::string &cmd)
422     {
423         UNUSED(miscFile);
424         UNUSED(cmd);
425         return 0;
426     }
427 
RebootAndInstall(const std::string & miscFile,const std::string & packageName)428     virtual int32_t RebootAndInstall(const std::string &miscFile, const std::string &packageName)
429     {
430         UNUSED(miscFile);
431         UNUSED(packageName);
432         return 0;
433     }
434 };
435 
436 HWTEST_F(UpdateServerTest, TestDownload, TestSize.Level1)
437 {
438     UpdateServerTest test;
439     (void)test.TestCheckNewVersion();
440     (void)test.TestDownload();
441 }
442 
443 HWTEST_F(UpdateServerTest, TestDoUpdate, TestSize.Level1)
444 {
445     UpdateServerTest test;
446     (void)test.TestDoUpdate();
447 }
448 
449 HWTEST_F(UpdateServerTest, TestGetNewVersion, TestSize.Level1)
450 {
451     UpdateServerTest test;
452     (void)test.TestCheckNewVersion();
453     (void)test.TestGetNewVersion();
454 }
455 
456 HWTEST_F(UpdateServerTest, TestUpdatePolicy, TestSize.Level1)
457 {
458     UpdateServerTest test;
459     (void)test.TestUpdatePolicy();
460 }
461 
462 HWTEST_F(UpdateServerTest, TestGetUpgradeStatus, TestSize.Level1)
463 {
464     UpdateServerTest test;
465     (void)test.TestGetUpgradeStatus();
466 }
467 
468 HWTEST_F(UpdateServerTest, TestRebootAndClean, TestSize.Level1)
469 {
470     UpdateServerTest test;
471     (void)test.TestRebootAndClean();
472 }
473 
474 HWTEST_F(UpdateServerTest, TestRebootAndInstall, TestSize.Level1)
475 {
476     UpdateServerTest test;
477     (void)test.TestRebootAndInstall();
478 }
479 
480 HWTEST_F(UpdateServerTest, TestRegisterUpdateCallback, TestSize.Level1)
481 {
482     UpdateServerTest test;
483     (void)test.TestRegisterUpdateCallback();
484 }
485 
486 HWTEST_F(UpdateServerTest, TestUnRegisterUpdateCallback, TestSize.Level1)
487 {
488     UpdateServerTest test;
489     (void)test.TestUnRegisterUpdateCallback();
490 }
491 
492 HWTEST_F(UpdateServerTest, TestReadCheckVersiondescriptInfo, TestSize.Level1)
493 {
494     UpdateServerTest test;
495     (void)test.TestReadCheckVersiondescriptInfo();
496 }
497 
498 HWTEST_F(UpdateServerTest, TestUpdateCallbackCheckNewVersion, TestSize.Level1)
499 {
500     UpdateServerTest test;
501     (void)test.TestUpdateCallbackCheckNewVersion();
502 }
503 
504 HWTEST_F(UpdateServerTest, TestUpdateCallbackDownload, TestSize.Level1)
505 {
506     UpdateServerTest test;
507     (void)test.TestUpdateCallbackDownload();
508 }
509 
510 HWTEST_F(UpdateServerTest, TestUpdateCallbackUpgrade, TestSize.Level1)
511 {
512     UpdateServerTest test;
513     (void)test.TestUpdateCallbackUpgrade();
514 }
515 
516 HWTEST_F(UpdateServerTest, TestDownLoadProgress, TestSize.Level1)
517 {
518     UpdateServerTest test;
519     (void)test.TestDownLoadProgress();
520 }
521 
522 HWTEST_F(UpdateServerTest, TestNewUpdateService, TestSize.Level1)
523 {
524     UpdateServerTest test;
525     (void)test.TestNewUpdateService();
526 }
527 
528 HWTEST_F(UpdateServerTest, TestUpdateServiceProxy, TestSize.Level1)
529 {
530     UpdateServerTest test;
531     (void)test.TestUpdateServiceProxy();
532 }
533 
534 HWTEST_F(UpdateServerTest, TestKitsResetService, TestSize.Level1)
535 {
536     sptr<ISystemAbilityManager> systemMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
537     EXPECT_NE(systemMgr, nullptr);
538     sptr<IRemoteObject> remoteObj = systemMgr->GetSystemAbility(UPDATE_DISTRIBUTED_SERVICE_ID);
539     EXPECT_NE(remoteObj, nullptr);
540     sptr<IRemoteObject::DeathRecipient> deathRecipient = new UpdateServiceKitsImpl::DeathRecipient();
541     EXPECT_NE(deathRecipient, nullptr);
542     deathRecipient->OnRemoteDied(remoteObj);
543     UpdateService *saServer = new (std::nothrow)UpdateService(0, true);
544     EXPECT_NE(saServer, nullptr);
545     const std::string miscFile = "/dev/block/by-name/misc";
546     const std::string packageName = "--update_package=/data/ota_package/updater.zip";
547     int32_t ret = saServer->RebootAndInstall(miscFile, packageName);
548     EXPECT_EQ(ret, 0);
549     delete saServer;
550 }
551 
552 HWTEST_F(UpdateServerTest, TestKitsRemoteCallbackOnCheckVersionDone, TestSize.Level1)
553 {
554     VersionInfo info {};
555     UpdateCallbackInfo callBackFun {};
556     sptr<UpdateServiceKitsImpl::RemoteUpdateCallback> remoteCallBack =
557         new (std::nothrow)UpdateServiceKitsImpl::RemoteUpdateCallback(callBackFun);
558     EXPECT_NE(remoteCallBack, nullptr);
559     remoteCallBack->OnCheckVersionDone(info);
560 }
561 
562 HWTEST_F(UpdateServerTest, TestKitsRemoteCallbackOnDownloadProgress, TestSize.Level1)
563 {
564     Progress progress {};
565     UpdateCallbackInfo callBackFun {};
566     sptr<UpdateServiceKitsImpl::RemoteUpdateCallback> remoteCallBack =
567         new (std::nothrow)UpdateServiceKitsImpl::RemoteUpdateCallback(callBackFun);
568     EXPECT_NE(remoteCallBack, nullptr);
569     remoteCallBack->OnDownloadProgress(progress);
570 }
571 
572 HWTEST_F(UpdateServerTest, TestKitsRemoteCallbackOnUpgradeProgress, TestSize.Level1)
573 {
574     Progress progress {};
575     UpdateCallbackInfo callBackFun {};
576     sptr<UpdateServiceKitsImpl::RemoteUpdateCallback> remoteCallBack =
577         new (std::nothrow)UpdateServiceKitsImpl::RemoteUpdateCallback(callBackFun);
578     EXPECT_NE(remoteCallBack, nullptr);
579     remoteCallBack->OnUpgradeProgress(progress);
580 }
581 
582 HWTEST_F(UpdateServerTest, TestKitsRegisterUpdateCallback, TestSize.Level1)
583 {
584     UpdateCallbackInfo callBackFun {};
585     UpdateContext ctx {};
586     int ret = UpdateServiceKits::GetInstance().RegisterUpdateCallback(ctx, callBackFun);
587     EXPECT_EQ(ret, 0);
588     ret = UpdateServiceKits::GetInstance().UnregisterUpdateCallback();
589     EXPECT_EQ(ret, 0);
590 }
591 
592 HWTEST_F(UpdateServerTest, TestKitsDoUpdate, TestSize.Level1)
593 {
594     int ret = UpdateServiceKits::GetInstance().DoUpdate();
595     EXPECT_EQ(ret, 0);
596 }
597 
598 HWTEST_F(UpdateServerTest, TestKitsCancel, TestSize.Level1)
599 {
600     int32_t service = 0;
601     int ret = UpdateServiceKits::GetInstance().Cancel(service);
602     EXPECT_EQ(ret, 0);
603 }
604 
605 HWTEST_F(UpdateServerTest, TestKitsRebootAndClean, TestSize.Level1)
606 {
607     const std::string miscFile = "/dev/block/by-name/misc";
608     const std::string cmd = "--update_package=/data/ota_package/updater.zip";
609     int ret = UpdateServiceKits::GetInstance().RebootAndClean(miscFile, cmd);
610     EXPECT_NE(ret, 0);
611 }
612 
613 HWTEST_F(UpdateServerTest, TestKitsReadDataFromSSL, TestSize.Level1)
614 {
615     int32_t engineSocket = 10;
616     UpdateService *updateServer = new (std::nothrow)UpdateService(0, true);
617     EXPECT_NE(updateServer, nullptr);
618     updateServer->ReadDataFromSSL(engineSocket);
619     delete updateServer;
620 }
621 
622 HWTEST_F(UpdateServerTest, TestKits, TestSize.Level1)
623 {
624     UpdateServiceKits *kit = new (std::nothrow)MockUpdateServiceKits();
625     EXPECT_NE(kit, nullptr);
626     delete kit;
627 }
628 
629 HWTEST_F(UpdateServerTest, TestUpdateServiceKitsImpl, TestSize.Level1)
630 {
631     std::string miscFile = "/dev/block/by-name/misc";
632     std::string packageName = "/data/ota_package/updater.zip";
633     int ret = UpdateServiceKits::GetInstance().RebootAndInstall(miscFile, packageName);
634     printf("RebootAndInstall: %d\n", ret);
635 }
636 
637 HWTEST_F(UpdateServerTest, TestUpdateServiceRegisterUpdateCallback, TestSize.Level1)
638 {
639     UpdateContext ctx {};
640     UpdateService *updateServer = new (std::nothrow)UpdateService(0, true);
641     EXPECT_NE(updateServer, nullptr);
642     updateServer->RegisterUpdateCallback(ctx, nullptr);
643     delete updateServer;
644 }
645 
646 HWTEST_F(UpdateServerTest, TestVerifyDownloadPkg, TestSize.Level1)
647 {
648     Progress downloadProgress {};
649     std::string path = "/data/ota_package/test.txt";
650     UpdateService *updateServer = new (std::nothrow)UpdateService(0, true);
651     EXPECT_NE(updateServer, nullptr);
652     updateServer->VerifyDownloadPkg(path, downloadProgress);
653     delete updateServer;
654 }
655