1fb299fa2Sopenharmony_ci/*
2fb299fa2Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3fb299fa2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fb299fa2Sopenharmony_ci * you may not use this file except in compliance with the License.
5fb299fa2Sopenharmony_ci * You may obtain a copy of the License at
6fb299fa2Sopenharmony_ci *
7fb299fa2Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8fb299fa2Sopenharmony_ci *
9fb299fa2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fb299fa2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fb299fa2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fb299fa2Sopenharmony_ci * See the License for the specific language governing permissions and
13fb299fa2Sopenharmony_ci * limitations under the License.
14fb299fa2Sopenharmony_ci */
15fb299fa2Sopenharmony_ci
16fb299fa2Sopenharmony_ci#include <fcntl.h>
17fb299fa2Sopenharmony_ci#include <gtest/gtest.h>
18fb299fa2Sopenharmony_ci#include <memory>
19fb299fa2Sopenharmony_ci#include <sys/ioctl.h>
20fb299fa2Sopenharmony_ci#include "log/log.h"
21fb299fa2Sopenharmony_ci#include "securec.h"
22fb299fa2Sopenharmony_ci#include "updater/hwfault_retry.h"
23fb299fa2Sopenharmony_ci#include "updater/updater.h"
24fb299fa2Sopenharmony_ci#include "updater/updater_const.h"
25fb299fa2Sopenharmony_ci#include "utils.h"
26fb299fa2Sopenharmony_ci
27fb299fa2Sopenharmony_ciusing namespace Updater;
28fb299fa2Sopenharmony_ciusing namespace std;
29fb299fa2Sopenharmony_ciusing namespace testing::ext;
30fb299fa2Sopenharmony_ci
31fb299fa2Sopenharmony_cinamespace {
32fb299fa2Sopenharmony_ciclass HwfaultRetryUnitTest : public testing::Test {
33fb299fa2Sopenharmony_cipublic:
34fb299fa2Sopenharmony_ci    HwfaultRetryUnitTest()
35fb299fa2Sopenharmony_ci    {
36fb299fa2Sopenharmony_ci        InitUpdaterLogger("UPDATER", TMP_LOG, TMP_STAGE_LOG, TMP_ERROR_CODE_PATH);
37fb299fa2Sopenharmony_ci    }
38fb299fa2Sopenharmony_ci    ~HwfaultRetryUnitTest() {}
39fb299fa2Sopenharmony_ci
40fb299fa2Sopenharmony_ci    static void SetUpTestCase(void) {}
41fb299fa2Sopenharmony_ci    static void TearDownTestCase(void) {}
42fb299fa2Sopenharmony_ci    void SetUp() {}
43fb299fa2Sopenharmony_ci    void TearDown()
44fb299fa2Sopenharmony_ci    {
45fb299fa2Sopenharmony_ci        (void)ClearMisc();
46fb299fa2Sopenharmony_ci    }
47fb299fa2Sopenharmony_ci    void TestBody() {}
48fb299fa2Sopenharmony_ci};
49fb299fa2Sopenharmony_ci
50fb299fa2Sopenharmony_ciHWTEST_F(HwfaultRetryUnitTest, VerifyFailRetry, TestSize.Level1)
51fb299fa2Sopenharmony_ci{
52fb299fa2Sopenharmony_ci    HwFaultRetry::GetInstance().SetFaultInfo(VERIFY_FAILED_REBOOT);
53fb299fa2Sopenharmony_ci    HwFaultRetry::GetInstance().SetRetryCount(0);
54fb299fa2Sopenharmony_ci    HwFaultRetry::GetInstance().DoRetryAction();
55fb299fa2Sopenharmony_ci
56fb299fa2Sopenharmony_ci    bool ret = Utils::CheckFaultInfo(VERIFY_FAILED_REBOOT);
57fb299fa2Sopenharmony_ci    EXPECT_EQ(ret, true);
58fb299fa2Sopenharmony_ci}
59fb299fa2Sopenharmony_ci
60fb299fa2Sopenharmony_ciHWTEST_F(HwfaultRetryUnitTest, IOFailRetry, TestSize.Level1)
61fb299fa2Sopenharmony_ci{
62fb299fa2Sopenharmony_ci    HwFaultRetry::GetInstance().SetFaultInfo(IO_FAILED_REBOOT);
63fb299fa2Sopenharmony_ci    HwFaultRetry::GetInstance().SetRetryCount(0);
64fb299fa2Sopenharmony_ci    HwFaultRetry::GetInstance().DoRetryAction();
65fb299fa2Sopenharmony_ci
66fb299fa2Sopenharmony_ci    bool ret = Utils::CheckFaultInfo(IO_FAILED_REBOOT);
67fb299fa2Sopenharmony_ci    EXPECT_EQ(ret, true);
68fb299fa2Sopenharmony_ci}
69fb299fa2Sopenharmony_ci
70fb299fa2Sopenharmony_ciHWTEST_F(HwfaultRetryUnitTest, RetryMoreThanMax, TestSize.Level1)
71fb299fa2Sopenharmony_ci{
72fb299fa2Sopenharmony_ci    HwFaultRetry::GetInstance().SetFaultInfo(IO_FAILED_REBOOT);
73fb299fa2Sopenharmony_ci    HwFaultRetry::GetInstance().SetRetryCount(MAX_RETRY_COUNT);
74fb299fa2Sopenharmony_ci    HwFaultRetry::GetInstance().DoRetryAction();
75fb299fa2Sopenharmony_ci
76fb299fa2Sopenharmony_ci    bool ret = Utils::CheckFaultInfo(IO_FAILED_REBOOT);
77fb299fa2Sopenharmony_ci    EXPECT_EQ(ret, false);
78fb299fa2Sopenharmony_ci}
79fb299fa2Sopenharmony_ci}