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 "hctest.h"
17 #include "hota_updater.h"
18
19 #define ERRORCALLBACK 0
20 #define STATUSCALLBACK 0
21 #define USE_HOS_PKG 1
22 #define NOT_HOS_PKG 0
23 #define ERR_PAK_FALG 2
24 #define DATA_LENGTH 190
25 #define READ_LENGTH 0
26 #define ERR_LENGTH 9
27 #define DATA_OFFSET 0
28
29 /**
30 * @tc.desc : register a test suite, this suite is used to test basic flow and interface dependency
31 * @param : subsystem name is ota
32 * @param : module name is otalite
33 * @param : test suit name is OtaFuncTestSuite
34 */
35 LITE_TEST_SUIT(ota, otalite, OtaFuncTestSuite);
36
37 /**
38 * @tc.setup : setup for all testcases
39 * @return : setup result, TRUE is success, FALSE is fail
40 */
OtaFuncTestSuiteSetUp(void)41 static BOOL OtaFuncTestSuiteSetUp(void)
42 {
43 return TRUE;
44 }
45
46 /**
47 * @tc.teardown : teardown for all testcases
48 * @return : teardown result, TRUE is success, FALSE is fail
49 */
OtaFuncTestSuiteTearDown(void)50 static BOOL OtaFuncTestSuiteTearDown(void)
51 {
52 printf("+-------------------------------------------+\n");
53 return TRUE;
54 }
55
56 /**
57 * @tc.number : SUB_Upgrade_API_0100
58 * @tc.name : Initializes the OTA module
59 * @tc.desc : [C- SOFTWARE -0100]
60 */
61 LITE_TEST_CASE(OtaFuncTestSuite, subUpgradeAPI0100, Function | MediumTest | Level1)
62 {
63 unsigned int ret;
64 ret = HotaInit(ERRORCALLBACK, STATUSCALLBACK);
65 printf("HotaInit return = %d\r\n", ret);
66 TEST_ASSERT_EQUAL_INT(OHOS_SUCCESS, ret);
67 };
68
69 /**
70 * @tc.number : SUB_Upgrade_API_0200
71 * @tc.name : Sets the switch for using the default upgrade package format
72 * @tc.desc : [C- SOFTWARE -0100]
73 */
74 LITE_TEST_CASE(OtaFuncTestSuite, subUpgradeAPI0200, Function | MediumTest | Level1)
75 {
76 unsigned int ret;
77 ret = HotaSetPackageType(USE_HOS_PKG);
78 printf("use package flag = %d\r\n, return = %d\r\n", USE_HOS_PKG, ret);
79 TEST_ASSERT_EQUAL_INT(OHOS_SUCCESS, ret);
80 ret = HotaSetPackageType(NOT_HOS_PKG);
81 printf("use package flag = %d\r\n, return = %d\r\n", NOT_HOS_PKG, ret);
82 TEST_ASSERT_EQUAL_INT(OHOS_SUCCESS, ret);
83 };
84
85 /**
86 * @tc.number : SUB_Upgrade_API_0300
87 * @tc.name : Obtains the index of the A or B partition to be upgraded
88 * @tc.desc : [C- SOFTWARE -0100]
89 */
90 LITE_TEST_CASE(OtaFuncTestSuite, subUpgradeAPI0300, Function | MediumTest | Level1)
91 {
92 unsigned int ret;
93 unsigned int index = 0;
94 ret = HotaGetUpdateIndex(&index);
95 printf("index = %d\r\n, get index return = %d\r\n", index, ret);
96 TEST_ASSERT_EQUAL_INT(OHOS_SUCCESS, ret);
97 };
98
99 /**
100 * @tc.number : SUB_Upgrade_API_0800
101 * @tc.name : Sets the switch for using the default upgrade package format fail
102 * @tc.desc : [C-L1-310] MUST NOT alter JS API behavior.
103 * @tc.size : MEDIUM
104 * @tc.type : FUNC
105 * @tc.level : Level 1
106 */
107 LITE_TEST_CASE(OtaFuncTestSuite, subUpgradeAPI0800, Function | MediumTest | Level1)
108 {
109 unsigned int ret;
110 ret = HotaSetPackageType(ERR_PAK_FALG);
111 printf("use package flag = %d, return = %d\r\n", ERR_PAK_FALG, ret);
112 TEST_ASSERT_EQUAL_INT(OHOS_FAILURE, ret);
113 };
114
115 /**
116 * @tc.number : SUB_Upgrade_API_1000
117 * @tc.name : Writes specified data into flash memory fail
118 * @tc.desc : [C-L1-310] MUST NOT alter JS API behavior.
119 * @tc.size : MEDIUM
120 * @tc.type : FUNC
121 * @tc.level : Level 1
122 */
123 LITE_TEST_CASE(OtaFuncTestSuite, subUpgradeAPI1000, Function | MediumTest | Level1)
124 {
125 unsigned int ret;
126 unsigned int index = 0;
127 ret = HotaGetUpdateIndex(&index);
128 printf("index = %d, get index return = %d\r\n", index, ret);
129 ret = HotaSetPackageType(USE_HOS_PKG);
130 printf("use package flag = %d\r\n, return = %d\r\n", USE_HOS_PKG, ret);
131 unsigned char buffer[DATA_LENGTH] = {0};
132 ret = HotaWrite(buffer, DATA_OFFSET, DATA_LENGTH);
133 printf("Hota write return =%d\r\n", ret);
134 TEST_ASSERT_EQUAL_INT(OHOS_FAILURE, ret);
135 HotaCancel();
136 };
137
138 /**
139 * @tc.number : SUB_Upgrade_API_1100
140 * @tc.name : Reads the data that has been written into flash memory fail
141 * @tc.desc : [C-L1-310] MUST NOT alter JS API behavior.
142 * @tc.size : MEDIUM
143 * @tc.type : FUNC
144 * @tc.level : Level 1
145 */
146 LITE_TEST_CASE(OtaFuncTestSuite, subUpgradeAPI1100, Function | MediumTest | Level1)
147 {
148 unsigned int ret;
149 unsigned int index = 0;
150 ret = HotaGetUpdateIndex(&index);
151 printf("index = %d, get index return = %d\r\n", index, ret);
152 ret = HotaSetPackageType(NOT_HOS_PKG);
153 printf("use package flag = %d\r\n, return = %d\r\n", NOT_HOS_PKG, ret);
154 unsigned char buffer[DATA_LENGTH] = {0};
155 ret = HotaWrite(buffer, DATA_OFFSET, DATA_LENGTH);
156 printf("Hota write return =%d\r\n", ret);
157 unsigned char bufferread[DATA_LENGTH] = {0};
158 ret = HotaRead(DATA_OFFSET, DATA_LENGTH, bufferread);
159 printf("Hota read return =%d\r\n", ret);
160 TEST_ASSERT_EQUAL_INT(OHOS_FAILURE, ret);
161 HotaCancel();
162 };
163
164 /**
165 * @tc.number : SUB_Upgrade_API_1200
166 * @tc.name : Cancels an upgrade fail
167 * @tc.desc : [C-L1-310] MUST NOT alter JS API behavior.
168 * @tc.size : MEDIUM
169 * @tc.type : FUNC
170 * @tc.level : Level 1
171 */
172 LITE_TEST_CASE(OtaFuncTestSuite, subUpgradeAPI1200, Function | MediumTest | Level1)
173 {
174 unsigned int ret;
175 ret = HotaCancel();
176 printf("Hota Cancel return = %d\r\n", ret);
177 TEST_ASSERT_EQUAL_INT(OHOS_FAILURE, ret);
178 };
179
180 RUN_TEST_SUITE(OtaFuncTestSuite);
181