• 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 "update_image_block_test.h"
17 #include <cerrno>
18 #include <cstdio>
19 #include <fcntl.h>
20 #include <iostream>
21 #include <libgen.h>
22 #include <string>
23 #include <sys/mman.h>
24 #include <sys/mount.h>
25 #include <sys/stat.h>
26 #include <unistd.h>
27 #include <vector>
28 #include "applypatch/block_set.h"
29 #include "applypatch/store.h"
30 #include "fs_manager/mount.h"
31 #include "log.h"
32 #include "package/pkg_manager.h"
33 #include "script_instruction.h"
34 #include "script_manager.h"
35 #include "script_utils.h"
36 #include "unittest_comm.h"
37 #include "update_image_block.h"
38 #include "update_processor.h"
39 #include "utils.h"
40 
41 using namespace Updater;
42 using namespace testing::ext;
43 using namespace Uscript;
44 using namespace std;
45 using namespace Hpackage;
46 
47 namespace UpdaterUt {
SetUp()48 void UpdateImageBlockTest::SetUp()
49 {
50     cout << "Updater Unit UpdateBlockUnitTest Begin!" << endl;
51 
52     LoadSpecificFstab("/data/updater/applypatch/etc/fstab.ut.updater");
53 }
54 
TearDown()55 void UpdateImageBlockTest::TearDown()
56 {
57     cout << "Updater Unit UpdateBlockUnitTest End!" << endl;
58 }
59 
60 /* ota update, upd to base */
61 HWTEST_F(UpdateImageBlockTest, update_image_block_test_001, TestSize.Level1)
62 {
63     const string packagePath = "/data/updater/updater/updater_write_miscblock_img.zip";
64     int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName());
65     EXPECT_EQ(ret, 0);
66 }
67 
68 /* block diff update, hash check ok */
69 HWTEST_F(UpdateImageBlockTest, update_image_block_test_002, TestSize.Level1)
70 {
71     const string packagePath = "/data/updater/updater/updater_write_diff_miscblock_img.zip";
72     int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName());
73     EXPECT_EQ(ret, 0);
74 }
75 
76 /* block diff update, hash check fail */
77 HWTEST_F(UpdateImageBlockTest, update_image_block_test_003, TestSize.Level1)
78 {
79     const string packagePath = "/data/updater/updater/updater_write_diff_miscblock_img.zip";
80     int32_t ret = ProcessUpdater(false, STDOUT_FILENO, packagePath, GetTestCertName());
81     EXPECT_EQ(ret, USCRIPT_INVALID_PARAM);
82 }
83 }
84