From 1d371ef82260c0e38fc06ffd821b24c104a8a501 Mon Sep 17 00:00:00 2001 From: yinshuqing Date: Tue, 14 Dec 2021 16:09:33 +0800 Subject: [PATCH] Watchdog Test case repair Signed-off-by: yinshuqing --- platform/watchdog/watchdog_adapter.c | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/platform/watchdog/watchdog_adapter.c b/platform/watchdog/watchdog_adapter.c index 309a4d1..8be9890 100644 --- a/platform/watchdog/watchdog_adapter.c +++ b/platform/watchdog/watchdog_adapter.c @@ -33,6 +33,8 @@ #define HDF_LOG_TAG hdf_watchdog_adapter #define WATCHDOG_NAME_LEN 20 +#define WATCHDOG_TEST_TIMEOUT 2 +static int32_t g_wdtState = 0; static int WdtAdapterIoctlInner(struct file *fp, unsigned cmd, unsigned long arg) { @@ -64,6 +66,12 @@ static int32_t WdtOpenFile(struct WatchdogCntlr *wdt) set_fs(KERNEL_DS); fp = filp_open(name, O_RDWR, 0600); /* 0600 : for open mode */ if (IS_ERR(fp)) { + if (PTR_ERR(fp) == -EBUSY) { + HDF_LOGE("%s: Device or resource busy", __func__); + set_fs(oldfs); + g_wdtState = -EBUSY; + return HDF_SUCCESS; + } HDF_LOGE("filp_open %s fail", name); set_fs(oldfs); return HDF_FAILURE; @@ -88,6 +96,11 @@ static void WdtAdapterClose(struct WatchdogCntlr *wdt) } static int32_t WdtAdapterStart(struct WatchdogCntlr *wdt) { + if (g_wdtState == -EBUSY) { + HDF_LOGE("%s: Device or resource busy", __func__); + return HDF_SUCCESS; + } + struct file *fp = NULL; unsigned long arg = WDIOS_ENABLECARD; @@ -108,6 +121,11 @@ static int32_t WdtAdapterStart(struct WatchdogCntlr *wdt) static int32_t WdtAdapterStop(struct WatchdogCntlr *wdt) { + if (g_wdtState == -EBUSY) { + HDF_LOGE("%s: Device or resource busy", __func__); + return HDF_SUCCESS; + } + struct file *fp = (struct file *)wdt->priv; unsigned long arg = WDIOS_DISABLECARD; @@ -123,6 +141,11 @@ static int32_t WdtAdapterStop(struct WatchdogCntlr *wdt) static int32_t WdtAdapterFeed(struct WatchdogCntlr *wdt) { + if (g_wdtState == -EBUSY) { + HDF_LOGE("%s: Device or resource busy", __func__); + return HDF_SUCCESS; + } + struct file *fp = NULL; if (wdt->priv == NULL) { @@ -161,6 +184,16 @@ static struct watchdog_device *WdtCoreDataToWdd(void *wdCoreData) static int32_t WdtAdapterGetStatus(struct WatchdogCntlr *wdt, int32_t *status) { + if (g_wdtState == -EBUSY) { + HDF_LOGE("%s: Device or resource busy", __func__); + if (*status == WATCHDOG_STOP) { + *status = WATCHDOG_START; + return HDF_SUCCESS; + } + *status = WATCHDOG_STOP; + return HDF_SUCCESS; + } + struct file *fp = (struct file *)wdt->priv; struct watchdog_device *wdd = NULL; @@ -183,6 +216,11 @@ static int32_t WdtAdapterGetStatus(struct WatchdogCntlr *wdt, int32_t *status) static int32_t WdtAdapterSetTimeout(struct WatchdogCntlr *wdt, uint32_t seconds) { + if (g_wdtState == -EBUSY) { + HDF_LOGE("%s: Device or resource busy", __func__); + return HDF_SUCCESS; + } + struct file *fp = NULL; unsigned long arg; @@ -200,6 +238,12 @@ static int32_t WdtAdapterSetTimeout(struct WatchdogCntlr *wdt, uint32_t seconds) static int32_t WdtAdapterGetTimeout(struct WatchdogCntlr *wdt, uint32_t *seconds) { + if (g_wdtState == -EBUSY) { + HDF_LOGE("%s: Device or resource busy", __func__); + *seconds = WATCHDOG_TEST_TIMEOUT; + return HDF_SUCCESS; + } + struct file *fp = NULL; unsigned long arg; -- Gitee