1 /* 2 * Copyright (c) 2022-2023 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 <osal_mem.h> 18 #include <unistd.h> 19 #include "hdf_log.h" 20 #include "idevmgr_hdi.h" 21 #include "v1_0/ipartition_slot.h" 22 23 using namespace testing; 24 using namespace testing::ext; 25 using namespace OHOS::HDI::Partitionslot::V1_0; 26 using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; 27 28 class StartupPartitionSlotTest : public testing::Test { 29 public: SetUpTestCase()30 static void SetUpTestCase() 31 { 32 auto devmgr = IDeviceManager::Get(); 33 if (devmgr != nullptr) { 34 devmgr->LoadDevice("partition_slot_service"); 35 } else { 36 std::cout << "Get devmgr failed" << std::endl; 37 } 38 } TearDownTestCase()39 static void TearDownTestCase() 40 { 41 auto devmgr = IDeviceManager::Get(); 42 if (devmgr != nullptr) { 43 devmgr->UnloadDevice("partition_slot_service"); 44 } else { 45 std::cout << "Get devmgr failed" << std::endl; 46 } 47 } SetUp()48 void SetUp() {} TearDown()49 void TearDown() {} 50 }; 51 52 /** 53 * @tc.number: StartupPartitionSlotTest_001 54 * @tc.name: testGetCurrentSlotFun001 55 * @tc.desc: NA 56 */ 57 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_001, Function | MediumTest | Level1) { 58 std::cout << "begin get currentslot by service" << std::endl; 59 int numOfSlots = 0; 60 int currentSlot = -1; 61 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 62 ASSERT_TRUE(partitionslot != nullptr); 63 ASSERT_TRUE(partitionslot->GetCurrentSlot(currentSlot, numOfSlots) == 0); 64 } 65 /** 66 * @tc.number: StartupPartitionSlotTest_002 67 * @tc.name: testGetCurrentSlotFun002 68 * @tc.desc: NA 69 */ 70 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_002, Function | MediumTest | Level1) 71 { 72 std::cout << "begin get currentslot by service" << std::endl; 73 int numOfSlots = 1; 74 int currentSlot = 0; 75 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 76 ASSERT_TRUE(partitionslot != nullptr); 77 ASSERT_TRUE(partitionslot->GetCurrentSlot(currentSlot, numOfSlots) == 0); 78 } 79 /** 80 * @tc.number: StartupPartitionSlotTest_003 81 * @tc.name: testGetCurrentSlotFun003 82 * @tc.desc: NA 83 */ 84 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_003, Function | MediumTest | Level1) 85 { 86 std::cout << "begin get currentslot by service" << std::endl; 87 int numOfSlots = 1; 88 int currentSlot = 1; 89 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 90 ASSERT_TRUE(partitionslot != nullptr); 91 ASSERT_TRUE(partitionslot->GetCurrentSlot(currentSlot, numOfSlots) == 0); 92 } 93 /** 94 * @tc.number: StartupPartitionSlotTest_004 95 * @tc.name: testGetCurrentSlotFun004 96 * @tc.desc: NA 97 */ 98 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_004, Function | MediumTest | Level1) 99 { 100 std::cout << "begin get currentslot by service" << std::endl; 101 int numOfSlots = 2; 102 int currentSlot = 2; 103 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 104 ASSERT_TRUE(partitionslot != nullptr); 105 ASSERT_TRUE(partitionslot->GetCurrentSlot(currentSlot, numOfSlots) == 0); 106 } 107 /** 108 * @tc.number: StartupPartitionSlotTest_005 109 * @tc.name: testGetCurrentSlotFun005 110 * @tc.desc: NA 111 */ 112 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_005, Function | MediumTest | Level1) 113 { 114 std::cout << "begin get currentslot by service" << std::endl; 115 int numOfSlots = 3; 116 int currentSlot = 3; 117 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 118 ASSERT_TRUE(partitionslot != nullptr); 119 ASSERT_TRUE(partitionslot->GetCurrentSlot(currentSlot, numOfSlots) == 0); 120 } 121 /** 122 * @tc.number: StartupPartitionSlotTest_006 123 * @tc.name: testGetSlotSuffixFun001 124 * @tc.desc: NA 125 */ 126 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_006, Function | MediumTest | Level1) 127 { 128 std::cout << "begin get suffix by service" << std::endl; 129 std::string suffix = ""; 130 int slot = -1; 131 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 132 ASSERT_TRUE(partitionslot != nullptr); 133 ASSERT_TRUE(partitionslot->GetSlotSuffix(slot, suffix) == 0); 134 } 135 /** 136 * @tc.number: StartupPartitionSlotTest_007 137 * @tc.name: testGetSlotSuffixFun002 138 * @tc.desc: NA 139 */ 140 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_007, Function | MediumTest | Level1) 141 { 142 std::cout << "begin get suffix by service" << std::endl; 143 std::string suffix = ""; 144 int slot = 0; 145 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 146 ASSERT_TRUE(partitionslot != nullptr); 147 ASSERT_TRUE(partitionslot->GetSlotSuffix(slot, suffix) == 0); 148 } 149 /** 150 * @tc.number: StartupPartitionSlotTest_008 151 * @tc.name: testGetSlotSuffixFun003 152 * @tc.desc: NA 153 */ 154 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_008, Function | MediumTest | Level1) 155 { 156 std::cout << "begin get suffix by service" << std::endl; 157 std::string suffix = ""; 158 int slot = 1; 159 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 160 ASSERT_TRUE(partitionslot != nullptr); 161 ASSERT_TRUE(partitionslot->GetSlotSuffix(slot, suffix) == 0); 162 } 163 /** 164 * @tc.number: StartupPartitionSlotTest_002 165 * @tc.name: testGetSlotSuffixFun004 166 * @tc.desc: NA 167 */ 168 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_009, Function | MediumTest | Level1) { 169 std::cout << "begin get suffix by service" << std::endl; 170 std::string suffix = ""; 171 int slot = 2; 172 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 173 ASSERT_TRUE(partitionslot != nullptr); 174 ASSERT_TRUE(partitionslot->GetSlotSuffix(slot, suffix) == 0); 175 } 176 /** 177 * @tc.number: StartupPartitionSlotTest_010 178 * @tc.name: testGetSlotSuffixFun005 179 * @tc.desc: NA 180 */ 181 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_010, Function | MediumTest | Level1) 182 { 183 std::cout << "begin get suffix by service" << std::endl; 184 std::string suffix = ""; 185 int slot = 3; 186 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 187 ASSERT_TRUE(partitionslot != nullptr); 188 ASSERT_TRUE(partitionslot->GetSlotSuffix(slot, suffix) == 0); 189 } 190 /** 191 * @tc.number: StartupPartitionSlotTest_011 192 * @tc.name: testGetCurrentSlotFun001 193 * @tc.desc: NA 194 */ 195 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_011, Function | MediumTest | Level1) 196 { 197 std::cout << "begin set active slot by service" << std::endl; 198 int numOfSlots = 0; 199 int currentSlot = -1; 200 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 201 ASSERT_TRUE(partitionslot != nullptr); 202 partitionslot->GetCurrentSlot(currentSlot, numOfSlots); 203 ASSERT_TRUE(partitionslot->SetActiveSlot(-1) != 0); 204 partitionslot->SetActiveSlot(currentSlot); 205 } 206 /** 207 * @tc.number: StartupPartitionSlotTest_012 208 * @tc.name: testGetCurrentSlotFun002 209 * @tc.desc: NA 210 */ 211 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_012, Function | MediumTest | Level1) { 212 std::cout << "begin set active slot by service" << std::endl; 213 int numOfSlots = 0; 214 int currentSlot = 0; 215 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 216 ASSERT_TRUE(partitionslot != nullptr); 217 partitionslot->GetCurrentSlot(currentSlot, numOfSlots); 218 ASSERT_TRUE(partitionslot->SetActiveSlot(0) == 0); 219 partitionslot->SetActiveSlot(currentSlot); 220 } 221 /** 222 * @tc.number: StartupPartitionSlotTest_013 223 * @tc.name: testGetCurrentSlotFun003 224 * @tc.desc: NA 225 */ 226 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_013, Function | MediumTest | Level1) 227 { 228 std::cout << "begin set active slot by service" << std::endl; 229 int numOfSlots = 1; 230 int currentSlot = 0; 231 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 232 ASSERT_TRUE(partitionslot != nullptr); 233 partitionslot->GetCurrentSlot(currentSlot, numOfSlots); 234 ASSERT_TRUE(partitionslot->SetActiveSlot(1) == 0); 235 partitionslot->SetActiveSlot(currentSlot); 236 } 237 /** 238 * @tc.number: StartupPartitionSlotTest_014 239 * @tc.name: testGetCurrentSlotFun004 240 * @tc.desc: NA 241 */ 242 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_014, Function | MediumTest | Level1) 243 { 244 std::cout << "begin set active slot by service" << std::endl; 245 int numOfSlots = 2; 246 int currentSlot = 0; 247 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 248 ASSERT_TRUE(partitionslot != nullptr); 249 partitionslot->GetCurrentSlot(currentSlot, numOfSlots); 250 ASSERT_TRUE(partitionslot->SetActiveSlot(2) == 0); 251 partitionslot->SetActiveSlot(currentSlot); 252 } 253 /** 254 * @tc.number: StartupPartitionSlotTest_015 255 * @tc.name: testGetCurrentSlotFun005 256 * @tc.desc: NA 257 */ 258 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_015, Function | MediumTest | Level1) 259 { 260 std::cout << "begin set active slot by service" << std::endl; 261 int numOfSlots = 3; 262 int currentSlot = 0; 263 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 264 ASSERT_TRUE(partitionslot != nullptr); 265 partitionslot->GetCurrentSlot(currentSlot, numOfSlots); 266 ASSERT_TRUE(partitionslot->SetActiveSlot(3) == 0); 267 partitionslot->SetActiveSlot(currentSlot); 268 } 269 /** 270 * @tc.number: StartupPartitionSlotTest_016 271 * @tc.name: testSetSlotUnbootableFun001 272 * @tc.desc: NA 273 */ 274 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_016, Function | MediumTest | Level1) { 275 std::cout << "begin set unbootable slot by service" << std::endl; 276 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 277 ASSERT_TRUE(partitionslot != nullptr); 278 ASSERT_TRUE(partitionslot->SetSlotUnbootable(-1) != 0); 279 } 280 /** 281 * @tc.number: StartupPartitionSlotTest_017 282 * @tc.name: testSetSlotUnbootableFun002 283 * @tc.desc: NA 284 */ 285 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_017, Function | MediumTest | Level1) 286 { 287 std::cout << "begin set unbootable slot by service" << std::endl; 288 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 289 ASSERT_TRUE(partitionslot != nullptr); 290 ASSERT_TRUE(partitionslot->SetSlotUnbootable(0) == 0); 291 } 292 /** 293 * @tc.number: StartupPartitionSlotTest_018 294 * @tc.name: testSetSlotUnbootableFun003 295 * @tc.desc: NA 296 */ 297 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_018, Function | MediumTest | Level1) 298 { 299 std::cout << "begin set unbootable slot by service" << std::endl; 300 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 301 ASSERT_TRUE(partitionslot != nullptr); 302 ASSERT_TRUE(partitionslot->SetSlotUnbootable(1) == 0); 303 } 304 /** 305 * @tc.number: StartupPartitionSlotTest_019 306 * @tc.name: testSetSlotUnbootableFun004 307 * @tc.desc: NA 308 */ 309 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_019, Function | MediumTest | Level1) 310 { 311 std::cout << "begin set unbootable slot by service" << std::endl; 312 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 313 ASSERT_TRUE(partitionslot != nullptr); 314 ASSERT_TRUE(partitionslot->SetSlotUnbootable(2) == 0); 315 } 316 /** 317 * @tc.number: StartupPartitionSlotTest_020 318 * @tc.name: testSetSlotUnbootableFun005 319 * @tc.desc: NA 320 */ 321 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_020, Function | MediumTest | Level1) 322 { 323 std::cout << "begin set unbootable slot by service" << std::endl; 324 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 325 ASSERT_TRUE(partitionslot != nullptr); 326 ASSERT_TRUE(partitionslot->SetSlotUnbootable(3) == 0); 327 }