1 /* 2 * Copyright (c) 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 <fcntl.h> 17 #include <gtest/gtest.h> 18 #include <memory> 19 #include <sys/ioctl.h> 20 #include "log/log.h" 21 #include "securec.h" 22 #include "updater/hwfault_retry.h" 23 #include "updater/updater.h" 24 #include "updater/updater_const.h" 25 #include "utils.h" 26 27 using namespace Updater; 28 using namespace std; 29 using namespace testing::ext; 30 31 namespace { 32 class HwfaultRetryUnitTest : public testing::Test { 33 public: HwfaultRetryUnitTest()34 HwfaultRetryUnitTest() 35 { 36 InitUpdaterLogger("UPDATER", TMP_LOG, TMP_STAGE_LOG, TMP_ERROR_CODE_PATH); 37 } ~HwfaultRetryUnitTest()38 ~HwfaultRetryUnitTest() {} 39 SetUpTestCase(void)40 static void SetUpTestCase(void) {} TearDownTestCase(void)41 static void TearDownTestCase(void) {} SetUp()42 void SetUp() {} TearDown()43 void TearDown() 44 { 45 (void)ClearMisc(); 46 } TestBody()47 void TestBody() {} 48 }; 49 50 HWTEST_F(HwfaultRetryUnitTest, VerifyFailRetry, TestSize.Level1) 51 { 52 HwFaultRetry::GetInstance().SetFaultInfo(VERIFY_FAILED_REBOOT); 53 HwFaultRetry::GetInstance().SetRetryCount(0); 54 HwFaultRetry::GetInstance().DoRetryAction(); 55 56 bool ret = Utils::CheckFaultInfo(VERIFY_FAILED_REBOOT); 57 EXPECT_EQ(ret, true); 58 } 59 60 HWTEST_F(HwfaultRetryUnitTest, IOFailRetry, TestSize.Level1) 61 { 62 HwFaultRetry::GetInstance().SetFaultInfo(IO_FAILED_REBOOT); 63 HwFaultRetry::GetInstance().SetRetryCount(0); 64 HwFaultRetry::GetInstance().DoRetryAction(); 65 66 bool ret = Utils::CheckFaultInfo(IO_FAILED_REBOOT); 67 EXPECT_EQ(ret, true); 68 } 69 70 HWTEST_F(HwfaultRetryUnitTest, RetryMoreThanMax, TestSize.Level1) 71 { 72 HwFaultRetry::GetInstance().SetFaultInfo(IO_FAILED_REBOOT); 73 HwFaultRetry::GetInstance().SetRetryCount(MAX_RETRY_COUNT); 74 HwFaultRetry::GetInstance().DoRetryAction(); 75 76 bool ret = Utils::CheckFaultInfo(IO_FAILED_REBOOT); 77 EXPECT_EQ(ret, false); 78 } 79 }