diff --git a/include/platform/pin_if.h b/include/platform/pin_if.h new file mode 100644 index 0000000000000000000000000000000000000000..74c816ac3f65efaab123ce887d4fe34a5e2fff85 --- /dev/null +++ b/include/platform/pin_if.h @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +/** + * @file pin_if.h + * + * @brief Declares the standard pin interface functions. + * + * @since 1.0 + */ + +#ifndef PIN_IF_H +#define PIN_IF_H + +#include "hdf_platform.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +/** + * @brief Enumerates pin pull types. + * + * @since 1.0 + */ +enum PinPullType { + PIN_PULL_NONE = 0, /*< SET PIN SUSPEND >*/ + PIN_PULL_UP = 1, /*< SET PIN RESISTANCE UP >*/ + PIN_PULL_DOWN = 2, /*< SET PIN RESISTANCE DOWN >*/ +}; +/** + * @brief Obtains the handle of a pin. + * + * You must call this function before setting a pin properties. + * + * @param pinName Indicates the pin which you want to setting properties. + * + * @return Returns the pointer to the {@link DevHandle} of the pin controller which to get a pin if the operation is successful; + * returns NULL otherwise. + * @since 1.0 + */ +DevHandle PinGet(const char *pinName); + +/** + * @brief Releases the handle of a pin. + * + * If you no longer need to access the pin, you should call this function to close its handle so as + * to release unused memory resources. + * + * @param handle Indicates the pointer to the device handle of the pin. + * + * @since 1.0 + */ +void PinPut(DevHandle handle); + +/** + * @brief Set the pin pullType configuration. + * + * You can call this function when you need to set the pin pull configuration. + * @param handle Indicates the pointer to the device handle of the pin. + * @param pullType Indicates the type of pin pull. + * + * @return Returns 0 if set the pin Pull configuration operation is successfully; Returns a negative value otherwise. + * @since 1.0 + */ +int32_t PinSetPull(DevHandle handle, enum PinPullType pullType); + +/** + * @brief Get the pin pullType configuration. + * + * You can call this function when you need to get the pin pull configuration. + * + * @param handle Indicates the pointer to the device handle of the pin. + * @param pullType Indicates the pointer of the Pin Pull Type. + * @return Returns 0 if get the pin Pull configuration operation is successfully; Returns a negative value otherwise. + * @since 1.0 + */ +int32_t PinGetPull(DevHandle handle, enum PinPullType *pullType); + +/** + * @brief Set the pin strength configuration. + * + * You can call this function when you need to set the pin strength configuration. + * @param handle Indicates the pointer to the device handle of the pin. + * @param strength Indicates the value of pin strength. + * + * @return Returns 0 if set the pin strength configuration operation is successfully; Returns a negative value otherwise. + * @since 1.0 + */ +int32_t PinSetStrength(DevHandle handle, uint32_t strength); + +/** + * @brief Get the pin strength configuration. + * + * You can call this function when you need to get the pin strength configuration. + * + * @param handle Indicates the pointer to the device handle of the pin. + * @param strength Indicates the pointer of the Pin strength value. + * @return Returns 0 if get the pin strength configuration operation is successfully; Returns a negative value otherwise. + * @since 1.0 + */ +int32_t PinGetStrength(DevHandle handle, uint32_t *strength); + +/** + * @brief Set the pin function configuration. + * + * You can call this function when you need to set the pin function configuration. + * + * @param handle Indicates the pointer to the device handle of the pin description. + * @param funcName Indicates the pointer of the pin function. + * @return Returns 0 if set the pin function configuration operation is successfully; returns a negative value otherwise. + * @since 1.0 + */ +int32_t PinSetFunc(DevHandle handle, const char *funcName); + +/** + * @brief Get the pin function configuration. + * + * You can call this function when you need to get the pin function configuration. + * + * @param handle Indicates the pointer to the device handle of the pin description. + * @param funcName Indicates the double pointer of the pin function. + * @return Returns 0 if get the pin function configuration operation is successfully; returns a negative value otherwise. + * @since 1.0 + */ +int32_t PinGetFunc(DevHandle handle, const char **funcName); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* PIN_IF_H */ diff --git a/support/platform/include/pin/pin_core.h b/support/platform/include/pin/pin_core.h new file mode 100644 index 0000000000000000000000000000000000000000..c90d811bf7b6c2e26ed8ec9a69c68f09700c1425 --- /dev/null +++ b/support/platform/include/pin/pin_core.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ +#ifndef PIN_CORE_H +#define PIN_CORE_H + +#include "hdf_base.h" +#include "hdf_device_desc.h" +#include "hdf_dlist.h" +#include "pin_if.h" +#include "osal_spinlock.h" +#include "osal_atomic.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +struct PinCntlr; +struct PinCntlrMethod; +struct PinDesc; + +struct PinDesc { + const char *pinName; + void *priv; +}; + +struct PinCntlr { + struct IDeviceIoService service; + struct HdfDeviceObject *device; + struct PinCntlrMethod *method; + struct DListHead list; + OsalSpinlock spin; + uint16_t number; + uint16_t pinCount; + struct PinDesc *pins; + void *priv; +}; + +struct PinCntlrMethod { + int32_t (*SetPinPull)(struct PinCntlr *cntlr, uint32_t index, enum PinPullType pullType); + int32_t (*GetPinPull)(struct PinCntlr *cntlr, uint32_t index, enum PinPullType *pullType); + int32_t (*SetPinStrength)(struct PinCntlr *cntlr, uint32_t index, uint32_t strength); + int32_t (*GetPinStrength)(struct PinCntlr *cntlr, uint32_t index, uint32_t *strength); + int32_t (*SetPinFunc)(struct PinCntlr *cntlr, uint32_t index, const char *funcName); + int32_t (*GetPinFunc)(struct PinCntlr *cntlr, uint32_t index, const char **funcName); +}; + +int32_t PinCntlrAdd(struct PinCntlr *cntlr); + +void PinCntlrRemove(struct PinCntlr *cntlr); + +struct PinDesc *PinCntlrGetPinDescByName(const char *pinName); + +struct PinCntlr *PinCntlrGetByNumber(uint16_t number); + +struct PinCntlr *PinCntlrGetByPin(struct PinDesc *desc); + +void PinCntlrPutPin(struct PinDesc *desc); + +int32_t PinCntlrSetPinPull(struct PinCntlr *cntlr, struct PinDesc *desc, enum PinPullType pullType); + +int32_t PinCntlrGetPinPull(struct PinCntlr *cntlr, struct PinDesc *desc, enum PinPullType *pullType); + +int32_t PinCntlrSetPinStrength(struct PinCntlr *cntlr, struct PinDesc *desc, uint32_t strength); + +int32_t PinCntlrGetPinStrength(struct PinCntlr *cntlr, struct PinDesc *desc, uint32_t *strength); + +int32_t PinCntlrSetPinFunc(struct PinCntlr *cntlr, struct PinDesc *desc, const char *funcName); + +int32_t PinCntlrGetPinFunc(struct PinCntlr *cntlr, struct PinDesc *desc, const char **funcName); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* PIN_CORE_H */ diff --git a/support/platform/src/pin/pin_core.c b/support/platform/src/pin/pin_core.c new file mode 100644 index 0000000000000000000000000000000000000000..4bfde118bee2f8c328c8bf6574847d9d9e23b369 --- /dev/null +++ b/support/platform/src/pin/pin_core.c @@ -0,0 +1,394 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "pin_core.h" +#include "hdf_device_desc.h" +#include "hdf_log.h" +#include "osal_mem.h" +#include "osal_sem.h" +#include "securec.h" + +#define HDF_LOG_TAG pin_core + +#define MAX_CNT_PER_CNTLR 20 + +static struct DListHead g_cntlrList; +static OsalSpinlock g_listLock; +static uint32_t g_irqSave; + +static struct DListHead *PinCntlrListGet(void) +{ + static struct DListHead *list = NULL; + uint32_t irqSave; + if (list == NULL) { + list = &g_cntlrList; + DListHeadInit(list); + OsalSpinInit(&g_listLock); + } + while (OsalSpinLockIrqSave(&g_listLock, &irqSave) != HDF_SUCCESS); + g_irqSave = irqSave; + return list; +} + +static void PinCntlrListPut(void) +{ + (void)OsalSpinUnlockIrqRestore(&g_listLock, &g_irqSave); +} + +int32_t PinCntlrAdd(struct PinCntlr *cntlr) +{ + struct DListHead *list = NULL; + + if (cntlr == NULL) { + HDF_LOGE("%s: invalid object cntlr is NULL!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (cntlr->method == NULL) { + HDF_LOGE("%s: no method supplied!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (cntlr->pinCount >= MAX_CNT_PER_CNTLR) { + HDF_LOGE("%s: invalid pinCount:%u", __func__, cntlr->pinCount); + return HDF_ERR_INVALID_PARAM; + } + + OsalSpinInit(&cntlr->spin); + + list = PinCntlrListGet(); + + DListHeadInit(&cntlr->list); + DListInsertTail(&cntlr->list, list); + PinCntlrListPut(); + + return HDF_SUCCESS; +} + +void PinCntlrRemove(struct PinCntlr *cntlr) +{ + if (cntlr == NULL) { + HDF_LOGE("%s: cntlr is NULL!", __func__); + return; + } + + (void)PinCntlrListGet(); + DListRemove(&cntlr->list); + PinCntlrListPut(); + (void)OsalSpinDestroy(&cntlr->spin); +} + +struct PinDesc *PinCntlrGetPinDescByName(const char *pinName) +{ + struct DListHead *list = NULL; + struct PinCntlr *cntlr = NULL; + struct PinCntlr *tmp = NULL; + int32_t num; + + list = PinCntlrListGet(); + + DLIST_FOR_EACH_ENTRY_SAFE(cntlr, tmp, list, struct PinCntlr, list) { + for (num = 0; num < cntlr->pinCount; num++) { + if (cntlr->pins[num].pinName == NULL) { + continue; + } + if (!strcmp(cntlr->pins[num].pinName, pinName)) { + PinCntlrListPut(); + HDF_LOGI("%s: cntlr->pins[%d].pinName is %s!", __func__, num, cntlr->pins[num].pinName); + return &cntlr->pins[num]; + } + } + } + PinCntlrListPut(); + HDF_LOGE("%s: pinName:%s doesn't matching!", __func__, pinName); + return NULL; +} + +struct PinCntlr *PinCntlrGetByNumber(uint16_t number) +{ + struct DListHead *list = NULL; + struct PinCntlr *cntlr = NULL; + struct PinCntlr *tmp = NULL; + list = PinCntlrListGet(); + + DLIST_FOR_EACH_ENTRY_SAFE(cntlr, tmp, list, struct PinCntlr, list) { + if(cntlr->number == number) { + PinCntlrListPut(); + HDF_LOGI("%s: get cntlr by number success!", __func__); + return cntlr; + } + } + PinCntlrListPut(); + HDF_LOGE("%s: get cntlr by number error!", __func__); + return NULL; +} + +struct PinCntlr *PinCntlrGetByPin(struct PinDesc *desc) +{ + struct DListHead *list = NULL; + struct PinCntlr *cntlr = NULL; + struct PinCntlr *tmp = NULL; + int32_t num; + + list = PinCntlrListGet(); + DLIST_FOR_EACH_ENTRY_SAFE(cntlr, tmp, list, struct PinCntlr, list) { + for (num = 0; num pinCount; num++) { + if (desc == &cntlr->pins[num]) { + PinCntlrListPut(); + HDF_LOGI("%s: get cntlr by desc success!", __func__); + return cntlr; + } + } + } + PinCntlrListPut(); + HDF_LOGE("%s: pinCtrl:%s not in any controllers!", __func__, desc->pinName); + return NULL; +} + +static int32_t GetPinIndex(struct PinCntlr *cntlr, struct PinDesc *desc) +{ + int32_t index, ret; + + for (index = 0; index < cntlr->pinCount; index++) { + if (cntlr->pins[index].pinName == NULL) { + HDF_LOGE("%s: cntlr->pin[index].pinName is NULL!", __func__); + break; + } + ret = strcmp(cntlr->pins[index].pinName, desc->pinName); + if (ret == 0) { + HDF_LOGI("%s: get pin index:%d success!", __func__, index); + return index; + } + } + HDF_LOGE("%s: get pin index failed!", __func__); + return HDF_ERR_INVALID_PARAM; +} + +void PinCntlrPutPin(struct PinDesc *desc) +{ + (void)desc; +} + +int32_t PinCntlrSetPinPull(struct PinCntlr *cntlr, struct PinDesc *desc, + enum PinPullType pullType) +{ + int32_t ret; + uint32_t index; + uint32_t irqSave; + + if (cntlr == NULL) { + HDF_LOGE("%s: invalid object cntlr is NULL!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (cntlr->method == NULL || cntlr->method->SetPinPull == NULL) { + HDF_LOGE("%s: method or SetPinPull is NULL", __func__); + return HDF_ERR_NOT_SUPPORT; + } + + if (desc == NULL) { + HDF_LOGE("%s: desc is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + index = (uint32_t)GetPinIndex(cntlr, desc); + if (index < HDF_SUCCESS) { + HDF_LOGE("%s: get pin index fail!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + (void)OsalSpinLockIrqSave(&cntlr->spin, &irqSave); + ret = cntlr->method->SetPinPull(cntlr, index, pullType); + (void)OsalSpinUnlockIrqRestore(&cntlr->spin, &irqSave); + return ret; +} + +int32_t PinCntlrGetPinPull(struct PinCntlr *cntlr, struct PinDesc *desc, + enum PinPullType *pullType) +{ + int32_t ret; + uint32_t index; + uint32_t irqSave; + if (cntlr == NULL) { + HDF_LOGE("%s: invalid object cntlr is NULL!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (cntlr->method == NULL || cntlr->method->GetPinPull == NULL) { + HDF_LOGE("%s: method or GetPinPull is NULL", __func__); + return HDF_ERR_NOT_SUPPORT; + } + + if (desc == NULL) { + HDF_LOGE("%s: desc is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (pullType == NULL) { + HDF_LOGE("%s: pullType is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + index = (uint32_t)GetPinIndex(cntlr, desc); + if (index < HDF_SUCCESS) { + HDF_LOGE("%s: get pin index failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + (void)OsalSpinLockIrqSave(&cntlr->spin, &irqSave); + ret = cntlr->method->GetPinPull(cntlr, index, pullType); + (void)OsalSpinUnlockIrqRestore(&cntlr->spin, &irqSave); + + return ret; +} + +int32_t PinCntlrSetPinStrength(struct PinCntlr *cntlr, struct PinDesc *desc, + uint32_t strength) +{ + int32_t ret; + uint32_t index; + uint32_t irqSave; + + if (cntlr == NULL) { + HDF_LOGE("%s: invalid object cntlr is NULL!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (cntlr->method == NULL || cntlr->method->SetPinStrength == NULL) { + HDF_LOGE("%s: method or SetStrength is NULL", __func__); + return HDF_ERR_NOT_SUPPORT; + } + + if (desc == NULL) { + HDF_LOGE("%s: desc is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + index = (uint32_t)GetPinIndex(cntlr, desc); + if (index < HDF_SUCCESS) { + HDF_LOGE("%s: get pin index fail!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + (void)OsalSpinLockIrqSave(&cntlr->spin, &irqSave); + ret = cntlr->method->SetPinStrength(cntlr, index, strength); + (void)OsalSpinUnlockIrqRestore(&cntlr->spin, &irqSave); + return ret; +} + +int32_t PinCntlrGetPinStrength(struct PinCntlr *cntlr, struct PinDesc *desc, + uint32_t *strength) +{ + int32_t ret; + uint32_t index; + uint32_t irqSave; + if (cntlr == NULL) { + HDF_LOGE("%s: invalid object cntlr is NULL!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (cntlr->method == NULL || cntlr->method->GetPinStrength == NULL) { + HDF_LOGE("%s: method or GetStrength is NULL", __func__); + return HDF_ERR_NOT_SUPPORT; + } + + if (desc == NULL) { + HDF_LOGE("%s: desc is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (strength == NULL) { + HDF_LOGE("%s: strength is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + index = (uint32_t)GetPinIndex(cntlr, desc); + if (index < HDF_SUCCESS) { + HDF_LOGE("%s: get pin index failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + (void)OsalSpinLockIrqSave(&cntlr->spin, &irqSave); + ret = cntlr->method->GetPinStrength(cntlr, index, strength); + (void)OsalSpinUnlockIrqRestore(&cntlr->spin, &irqSave); + + return ret; +} + +int32_t PinCntlrSetPinFunc(struct PinCntlr *cntlr, struct PinDesc *desc, + const char *funcName) +{ + int32_t ret; + uint32_t index; + uint32_t irqSave; + + if (cntlr == NULL) { + HDF_LOGE("%s: invalid object cntlr is NULL!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (cntlr->method == NULL || cntlr->method->SetPinFunc == NULL) { + HDF_LOGE("%s: method or SetPinFunc is NULL", __func__); + return HDF_ERR_NOT_SUPPORT; + } + + if (desc == NULL) { + HDF_LOGE("%s: desc is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + index = (uint32_t)GetPinIndex(cntlr, desc); + if (index < HDF_SUCCESS) { + HDF_LOGE("%s: get pin index failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + if (funcName == NULL) { + HDF_LOGE("%s: invalid funcName pointer", __func__); + return HDF_ERR_INVALID_PARAM; + } + + (void)OsalSpinLockIrqSave(&cntlr->spin, &irqSave); + ret = cntlr->method->SetPinFunc(cntlr, index, funcName); + (void)OsalSpinUnlockIrqRestore(&cntlr->spin, &irqSave); + return ret; +} + +int32_t PinCntlrGetPinFunc(struct PinCntlr *cntlr, struct PinDesc *desc, + const char **funcName) +{ + int32_t ret; + uint32_t index; + uint32_t irqSave; + + if (cntlr == NULL) { + HDF_LOGE("%s: invalid object cntlr is NULL!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + if (cntlr->method == NULL || cntlr->method->GetPinFunc == NULL) { + HDF_LOGE("%s: method or SetPinFunc is NULL", __func__); + return HDF_ERR_NOT_SUPPORT; + } + + if (desc == NULL) { + HDF_LOGE("%s: desc is NULL", __func__); + return HDF_ERR_INVALID_PARAM; + } + + index = (uint32_t)GetPinIndex(cntlr, desc); + if (index < HDF_SUCCESS) { + HDF_LOGE("%s: get pin index failed!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + (void)OsalSpinLockIrqSave(&cntlr->spin, &irqSave); + ret = cntlr->method->GetPinFunc(cntlr, index, funcName); + (void)OsalSpinUnlockIrqRestore(&cntlr->spin, &irqSave); + return ret; +} \ No newline at end of file diff --git a/support/platform/src/pin/pin_if.c b/support/platform/src/pin/pin_if.c new file mode 100644 index 0000000000000000000000000000000000000000..2f00840cc8cc6d8fe067a3cfc87a3fe55adf89b6 --- /dev/null +++ b/support/platform/src/pin/pin_if.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "pin_if.h" +#include "devsvc_manager_clnt.h" +#include "pin_core.h" +#include "hdf_base.h" +#include "hdf_log.h" + +#define HDF_LOG_TAG pin_if + +DevHandle PinGet(const char *pinName) +{ + return (DevHandle)PinCntlrGetPinDescByName(pinName); +} + +void PinPut(DevHandle handle) +{ + if (handle == NULL) { + HDF_LOGE("%s: handle is NULL!", __func__); + return; + } + return PinCntlrPutPin((struct PinDesc *)handle); +} + +int32_t PinSetPull(DevHandle handle, enum PinPullType pullType) +{ + struct PinCntlr *cntlr = NULL; + + if (handle == NULL) { + HDF_LOGE("%s: invalid handle!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + cntlr = PinCntlrGetByPin((struct PinDesc *)handle); + return PinCntlrSetPinPull(cntlr, (struct PinDesc *)handle, pullType); +} + +int32_t PinGetPull(DevHandle handle, enum PinPullType *pullType) +{ + struct PinCntlr *cntlr = NULL; + + if (handle == NULL) { + HDF_LOGE("%s: invalid handle!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + cntlr = PinCntlrGetByPin((struct PinDesc *)handle); + return PinCntlrGetPinPull(cntlr, (struct PinDesc *)handle, pullType); +} + +int32_t PinSetStrength(DevHandle handle, uint32_t strength) +{ + struct PinCntlr *cntlr = NULL; + + if (handle == NULL) { + HDF_LOGE("%s: invalid handle!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + cntlr = PinCntlrGetByPin((struct PinDesc *)handle); + return PinCntlrSetPinStrength(cntlr, (struct PinDesc *)handle, strength); +} + +int32_t PinGetStrength(DevHandle handle, uint32_t *strength) +{ + struct PinCntlr *cntlr = NULL; + + if (handle == NULL) { + HDF_LOGE("%s: invalid handle!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + cntlr = PinCntlrGetByPin((struct PinDesc *)handle); + return PinCntlrGetPinStrength(cntlr, (struct PinDesc *)handle, strength); +} + +int32_t PinSetFunc(DevHandle handle, const char *funcName) +{ + struct PinCntlr *cntlr = NULL; + + if (handle == NULL) { + HDF_LOGE("%s: invalid handle!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + cntlr = PinCntlrGetByPin((struct PinDesc *)handle); + return PinCntlrSetPinFunc(cntlr, (struct PinDesc *)handle, funcName); +} + +int32_t PinGetFunc(DevHandle handle, const char **funcName) +{ + struct PinCntlr *cntlr = NULL; + + if (handle == NULL) { + HDF_LOGE("%s: invalid handle!", __func__); + return HDF_ERR_INVALID_PARAM; + } + + cntlr = PinCntlrGetByPin((struct PinDesc *)handle); + return PinCntlrGetPinFunc(cntlr, (struct PinDesc *)handle, funcName); +} \ No newline at end of file diff --git a/support/platform/test/unittest/common/hdf_pin_test.cpp b/support/platform/test/unittest/common/hdf_pin_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..321b9b4605a3f25516d6381598b3a55437dd1ade --- /dev/null +++ b/support/platform/test/unittest/common/hdf_pin_test.cpp @@ -0,0 +1,135 @@ +/* Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "hdf_uhdf_test.h" +#include "hdf_io_service_if.h" +#include "pin_test.h" + +using namespace testing::ext; + +class HdfPinTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void HdfPinTest::SetUpTestCase() +{ + struct HdfTestMsg msg = {TEST_PAL_PIN_TYPE, PIN_TEST_CMD_SETUP_ALL, -1}; + HdfTestOpenService(); + HdfTestSendMsgToService(&msg); + +} + +void HdfPinTest::TearDownTestCase() +{ + struct HdfTestMsg msg = {TEST_PAL_PIN_TYPE, PIN_TEST_CMD_TEARDOWN_ALL, -1}; + HdfTestSendMsgToService(&msg); + HdfTestCloseService(); + +} + +void HdfPinTest::SetUp() +{ +} + +void HdfPinTest::TearDown() +{ +} + +/** + * @tc.name: PinTestSetGetPinPull001 + * @tc.desc: Pin set get pin Pull test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfPinTest, PinSetGetPull001, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_PIN_TYPE, PIN_TEST_CMD_SETGETPULL, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: PinTestGetPinPull001 + * @tc.desc: Pin get pin Pull test + * @tc.type: FUNC + * @tc.require: NA + */ +/*HWTEST_F(HdfPinTest, PinGetPull001, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_PIN_TYPE, PIN_TEST_CMD_GETPULL, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} +*/ +/** + * @tc.name: PinTestSetGetStrength001 + * @tc.desc: Pin set get pin Strength test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfPinTest, PinSetGetStrength001, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_PIN_TYPE, PIN_TEST_CMD_SETGETSTRENGTH, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: PinTestGetStrength001 + * @tc.desc: Pin get pin Strength test + * @tc.type: FUNC + * @tc.require: NA + */ +/*HWTEST_F(HdfPinTest, PinGetStrength001, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_PIN_TYPE, PIN_TEST_CMD_GETSTRENGTH, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} +*/ +/** + * @tc.name: PinSetGetPinFunc001 + * @tc.desc: Pin set get pin func test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfPinTest, PinSetGetPinFunc001, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_PIN_TYPE, PIN_TEST_CMD_SETGETFUNC, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: PinGetPinFunc001 + * @tc.desc: Pin getpinfunc test + * @tc.type: FUNC + * @tc.require: NA + */ +/*HWTEST_F(HdfPinTest, PinGetPinFunc001, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_PIN_TYPE, PIN_TEST_CMD_GETFUNC, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} +*/ +/** + * @tc.name: PinReliabilityTest001 + * @tc.desc: Pin function test + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HdfPinTest, PinReliabilityTest001, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_PIN_TYPE, PIN_TEST_CMD_RELIABILITY, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} \ No newline at end of file diff --git a/test/unittest/common/hdf_main_test.c b/test/unittest/common/hdf_main_test.c index 7a33d356a556be0089dcaf852f4c05d0879c8cc3..58119bc3101133d7ecca0120400bfad301a8d242 100644 --- a/test/unittest/common/hdf_main_test.c +++ b/test/unittest/common/hdf_main_test.c @@ -17,6 +17,9 @@ #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO) || defined(CONFIG_DRIVERS_HDF_PLATFORM_GPIO) #include "hdf_gpio_entry_test.h" #endif +#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PIN) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PIN) +#include "hdf_pin_entry_test.h" +#endif #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2C) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I2C) #include "hdf_i2c_entry_test.h" #endif @@ -80,6 +83,9 @@ HdfTestFuncList g_hdfTestFuncList[] = { #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO) || defined(CONFIG_DRIVERS_HDF_PLATFORM_GPIO) { TEST_PAL_GPIO_TYPE, HdfGpioTestEntry }, #endif +#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PIN) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PIN) + { TEST_PAL_PIN_TYPE, HdfPinTestEntry }, +#endif #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2C) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I2C) { TEST_PAL_I2C_TYPE, HdfI2cTestEntry }, #endif diff --git a/test/unittest/common/hdf_main_test.h b/test/unittest/common/hdf_main_test.h index 4c005a13140bb0a13e566a07f17b776ceb9233ec..fc4cd43eb2f48b9d41901e62061b340ee99834ef 100644 --- a/test/unittest/common/hdf_main_test.h +++ b/test/unittest/common/hdf_main_test.h @@ -38,7 +38,7 @@ typedef enum { TEST_PAL_I2C_TYPE = 0, TEST_PAL_SPI_TYPE = 1, TEST_PAL_GPIO_TYPE = 2, - TEST_PAL_PINCTRL_TYPE = 3, + TEST_PAL_PIN_TYPE = 3, TEST_PAL_CLOCK_TYPE = 4, TEST_PAL_REGULATOR_TYPE = 5, TEST_PAL_MIPI_DSI_TYPE = 6, diff --git a/test/unittest/include/hdf_uhdf_test.h b/test/unittest/include/hdf_uhdf_test.h index 73a762633881506ee53314245b1626024a0073a8..41f419f7af54d428363d3e88a3ef78059ba5e4b0 100644 --- a/test/unittest/include/hdf_uhdf_test.h +++ b/test/unittest/include/hdf_uhdf_test.h @@ -34,7 +34,7 @@ enum HdfTestSubModuleCmd { TEST_PAL_I2C_TYPE = 0, TEST_PAL_SPI_TYPE = 1, TEST_PAL_GPIO_TYPE = 2, - TEST_PAL_PINCTRL_TYPE = 3, + TEST_PAL_PIN_TYPE = 3, TEST_PAL_CLOCK_TYPE = 4, TEST_PAL_REGULATOR_TYPE = 5, TEST_PAL_MIPI_DSI_TYPE = 6, @@ -78,4 +78,4 @@ int HdfTestSendMsgToService(struct HdfTestMsg *msg); } #endif /* __cplusplus */ -#endif // HDF_UHDF_TEST_H \ No newline at end of file +#endif // HDF_UHDF_TEST_H diff --git a/test/unittest/platform/common/pin_driver_test.c b/test/unittest/platform/common/pin_driver_test.c new file mode 100644 index 0000000000000000000000000000000000000000..9f99572ef65cc30c84f3c10f5ab0a52de2e83d02 --- /dev/null +++ b/test/unittest/platform/common/pin_driver_test.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "pin_test.h" +#include "device_resource_if.h" +#include "hdf_base.h" +#include "hdf_device_desc.h" +#include "hdf_log.h" +#include "string.h" + +#define HDF_LOG_TAG pin_driver_test_c + +static struct PinTestConfig g_config; + +static int32_t PinTestDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + if (cmd == 0) { + if (reply == NULL) { + HDF_LOGE("%s: reply is null!", __func__); + return HDF_ERR_INVALID_PARAM; + } + if (!HdfSbufWriteBuffer(reply, &g_config, sizeof(g_config))) { + HDF_LOGE("%s: write reply failed", __func__); + return HDF_ERR_IO; + } + } else { + return HDF_ERR_NOT_SUPPORT; + } + + return HDF_SUCCESS; +} +static int32_t PinTestReadConfig(struct PinTestConfig *config, const struct DeviceResourceNode *node) +{ + int32_t ret; + const char *funcName = NULL; + struct DeviceResourceIface *drsOps = NULL; + + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetUint32 == NULL || drsOps->GetString == NULL) { + HDF_LOGE("%s: invalid drs ops", __func__); + return HDF_FAILURE; + } + ret = drsOps->GetString(node, "pinName", &config->pinName, 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read pinName failed", __func__); + return ret; + } + + ret = drsOps->GetUint32(node, "strengthNum", &config->strengthNum, 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read StrengthNum failed", __func__); + return ret; + } + + ret = drsOps->GetUint32(node, "PullTypeNum", &config->PullTypeNum, 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read PullTypeNum failed", __func__); + return ret; + } + + ret = drsOps->GetString(node, "funcName", &funcName, 0); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read funcName failed", __func__); + return ret; + } + stpcpy(config->funcNameBuf, funcName); + return HDF_SUCCESS; +} + +static int32_t PinTestBind(struct HdfDeviceObject *device) +{ + int32_t ret; + static struct IDeviceIoService service; + + if (device == NULL || device->property == NULL) { + HDF_LOGE("%s: device or config is null!", __func__); + return HDF_ERR_IO; + } + ret = PinTestReadConfig(&g_config, device->property); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read config failed", __func__); + return ret; + } + service.Dispatch = PinTestDispatch; + device->service = &service; + return HDF_SUCCESS; +} + +static int32_t PinTestInit(struct HdfDeviceObject *device) +{ + (void)device; + return HDF_SUCCESS; +} + +static void PinTestRelease(struct HdfDeviceObject *device) +{ + if (device != NULL) { + device->service = NULL; + } + HDF_LOGI("%s: Done!", __func__); + return; +} + +struct HdfDriverEntry g_pinTestEntry = { + .moduleVersion = 1, + .Bind = PinTestBind, + .Init = PinTestInit, + .Release = PinTestRelease, + .moduleName = "PLATFORM_PIN_TEST", +}; +HDF_INIT(g_pinTestEntry); \ No newline at end of file diff --git a/test/unittest/platform/common/pin_test.c b/test/unittest/platform/common/pin_test.c new file mode 100644 index 0000000000000000000000000000000000000000..4d3f652866de8b99d158be4c9f4395ae95289b5c --- /dev/null +++ b/test/unittest/platform/common/pin_test.c @@ -0,0 +1,372 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "pin_test.h" +#include "pin_if.h" +#include "hdf_base.h" +#include "hdf_io_service_if.h" +#include "hdf_log.h" +#include "securec.h" +#include "osal_mem.h" +#include "osal_time.h" + +#define HDF_LOG_TAG pin_test_c + +#define PIN_FUNC_NAME_LENGTH 30 + +struct PinCfgs { + enum PinPullType pullTypeNum; + uint32_t strengthNum; + const char *funcName; +} g_oldPinCfg; + +struct PinTestEntry { + int cmd; + int32_t (*func)(void); + const char *name; +}; + +static int32_t PinTestGetTestConfig(struct PinTestConfig *config) +{ + int32_t ret; + struct HdfSBuf *reply = NULL; + struct HdfIoService *service = NULL; + const void *buf = NULL; + uint32_t len; + + HDF_LOGD("%s: enter", __func__); + service = HdfIoServiceBind("PIN_TEST"); + if (service == NULL) { + return HDF_ERR_NOT_SUPPORT; + } + + reply = HdfSBufObtain(sizeof(*config) + sizeof(uint64_t)); + if (reply == NULL) { + HDF_LOGE("%s: Failed to obtain reply", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + ret = service->dispatcher->Dispatch(&service->object, 0, NULL, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: Remote dispatch failed", __func__); + return ret; + } + + if (!HdfSbufReadBuffer(reply, &buf, &len)) { + HDF_LOGE("%s: Read buf failed", __func__); + HdfSBufRecycle(reply); + return HDF_ERR_IO; + } + + if (len != sizeof(*config)) { + HDF_LOGE("%s: Config size:%zu, read size:%u", __func__, sizeof(*config), len); + HdfSBufRecycle(reply); + return HDF_ERR_IO; + } + + if (memcpy_s(config, sizeof(*config), buf, sizeof(*config)) != EOK) { + HDF_LOGE("%s: Memcpy buf failed", __func__); + HdfSBufRecycle(reply); + return HDF_ERR_IO; + } + HdfSBufRecycle(reply); + HDF_LOGD("%s: Done", __func__); + return HDF_SUCCESS; +} + +struct PinTester *PinTesterGet(void) +{ + int32_t ret; + static struct PinTester tester; + static bool hasInit = false; + + if (hasInit) { + return &tester; + } + HDF_LOGI("%s: enter", __func__); + if (hasInit) { + return &tester; + } + ret = PinTestGetTestConfig(&tester.config); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read config failed:%d", __func__, ret); + return NULL; + } + tester.handle = PinGet(tester.config.pinName); + if (tester.handle == NULL) { + HDF_LOGE("%s: open pin:%s failed", __func__, tester.config.pinName); + return NULL; + } + hasInit = true; + HDF_LOGD("%s: Done", __func__); + return &tester; +} + +static int32_t PinSetGetPullTest(void) +{ + struct PinTester *tester = NULL; + int32_t ret; + enum PinPullType getPullTypeNum; + + tester = PinTesterGet(); + if (tester == NULL) { + HDF_LOGE("%s: Get tester failed!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + ret = PinSetPull(tester->handle, tester->config.PullTypeNum); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: Pin set pull failed!, pinName:%s", __func__, tester->config.pinName); + return HDF_FAILURE; + } + HDF_LOGI("%s: Pin set pull success!, PullTypeNum:%d", __func__,tester->config.PullTypeNum); + ret = PinGetPull(tester->handle, &getPullTypeNum); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: Pin get pull failed!, pinName:%s", __func__, tester->config.pinName); + return HDF_FAILURE; + } + HDF_LOGI("%s: Pin get pull success!, PullTypeNum:%d", __func__,getPullTypeNum); + if (tester->config.PullTypeNum != getPullTypeNum) { + HDF_LOGE("%s: Pin set pull:%d, but Pin get pull:%u", __func__, tester->config.PullTypeNum, getPullTypeNum); + } + HDF_LOGD("%s: done", __func__); + return HDF_SUCCESS; +} + +static int32_t PinSetGetStrengthTest(void) +{ + struct PinTester *tester = NULL; + int32_t ret; + uint32_t getStrengthNum; + + tester = PinTesterGet(); + if (tester == NULL) { + HDF_LOGE("%s: Get tester failed!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + ret = PinSetStrength(tester->handle, tester->config.strengthNum); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: Pin set strength failed!, pinName:%s", __func__, tester->config.pinName); + return HDF_FAILURE; + } + HDF_LOGI("%s: Pin set strength success!,strengthNum:%d", __func__, tester->config.strengthNum); + ret = PinGetStrength(tester->handle, &getStrengthNum); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: Pin get pull failed!, pinName:%s", __func__, tester->config.pinName); + return HDF_FAILURE; + } + HDF_LOGI("%s: Pin get pull success!, strengthNum:%d", __func__, getStrengthNum); + if (tester->config.strengthNum != getStrengthNum) { + HDF_LOGE("%s: Pin set strength:%d, but Pin get strength:%d", __func__, tester->config.strengthNum, getStrengthNum); + } + HDF_LOGD("%s: done", __func__); + return HDF_SUCCESS; +} + +static int32_t PinSetGetFuncTest(void) +{ + struct PinTester *tester = NULL; + int32_t ret; + + tester = PinTesterGet(); + if (tester == NULL) { + HDF_LOGE("%s: Get tester failed!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + ret = PinSetFunc(tester->handle, (const char *)tester->config.funcNameBuf); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: Pin set function failed!, pinName:%s,functionName:%s", __func__, + tester->config.pinName, tester->config.funcNameBuf); + return HDF_FAILURE; + } + HDF_LOGI("%s: Pin set function success!, pinName:%s,functionName:%s", __func__, + tester->config.pinName, tester->config.funcNameBuf); + ret = PinGetFunc(tester->handle, &tester->config.funcName); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: Pin get function failed!, pinName:%s,functionName:%s", __func__, + tester->config.pinName, tester->config.funcName); + return HDF_FAILURE; + } + HDF_LOGI("%s: Pin get function success!, pinName:%s,functionName:%s", __func__, + tester->config.pinName, tester->config.funcName); + if (strcmp((const char *)tester->config.funcNameBuf, tester->config.funcName) != 0) { + HDF_LOGE("%s: Pin set function:%s, but Pin get function:%s", __func__, tester->config.funcNameBuf, tester->config.funcName); + } + HDF_LOGD("%s: done", __func__); + return HDF_SUCCESS; +} + +int32_t PinTestSetUpAll(void) +{ + int32_t ret; + struct PinTester *tester = NULL; + struct PinTestConfig *cfg = NULL; + + HDF_LOGD("%s: enter!", __func__); + tester = PinTesterGet(); + if (tester == NULL) { + HDF_LOGE("%s: get tester fail!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + tester->total = PIN_TEST_CMD_MAX; + tester->fails = 0; + + cfg = &tester->config; + HDF_LOGD("%s: test on pinName:%s, PullTypeNum:%d, strengthNum:%d", __func__, + cfg->pinName,cfg->PullTypeNum, cfg->strengthNum); + ret = PinGetPull(tester->handle , &g_oldPinCfg.pullTypeNum); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: get pullTypeNum failed!", __func__); + return ret; + } + ret = PinGetStrength(tester->handle, &g_oldPinCfg.strengthNum); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: get strengthNum failed!", __func__); + return ret; + } + g_oldPinCfg.funcName = (char *)OsalMemCalloc(PIN_FUNC_NAME_LENGTH * sizeof(char)); + if (g_oldPinCfg.funcName == NULL) { + HDF_LOGE("%s: alloc g_oldPinCfg.funcName failed", __func__); + return HDF_ERR_MALLOC_FAIL; + } + tester->config.funcName = (char *)OsalMemCalloc(PIN_FUNC_NAME_LENGTH * sizeof(char)); + if (tester->config.funcName == NULL) { + HDF_LOGE("%s: alloc tester->config.funcName failed", __func__); + return HDF_ERR_MALLOC_FAIL; + } + ret = PinGetFunc(tester->handle, &g_oldPinCfg.funcName); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: get funcName failed!", __func__); + return ret; + } + HDF_LOGI(":%s old funcName:%s", __func__, g_oldPinCfg.funcName); + HDF_LOGD("%s: exit!", __func__); + + return HDF_SUCCESS; +} + +int32_t PinTestTearDownAll(void) +{ + int32_t ret; + struct PinTester *tester = NULL; + + HDF_LOGD("%s: enter!", __func__); + tester = PinTesterGet(); + if (tester == NULL) { + HDF_LOGE("%s: get tester fail!", __func__); + return HDF_ERR_INVALID_OBJECT; + } + ret = PinSetPull(tester->handle , g_oldPinCfg.pullTypeNum); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: set pullTypeNum failed!", __func__); + return ret; + } + ret = PinSetStrength(tester->handle , g_oldPinCfg.strengthNum); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: set strengthNum failed!", __func__); + return ret; + } + ret = PinSetFunc(tester->handle , g_oldPinCfg.funcName); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: set funcName failed!", __func__); + return ret; + } + HDF_LOGD("%s: exit!", __func__); + + return HDF_SUCCESS; +} + +int32_t PinTestSetUpSingle(void) +{ + return HDF_SUCCESS; +} + +int32_t PinTestTearDownSingle(void) +{ + return HDF_SUCCESS; +} + +int32_t PinTestReliability(void) +{ + struct PinTester *tester = NULL; + + HDF_LOGI("%s: enter", __func__); + tester = PinTesterGet(); + if (tester == NULL || tester->handle == NULL) { + return HDF_ERR_INVALID_OBJECT; + } + HDF_LOGD("%s: test dfr for PinSetPull ...", __func__); + // invalid handle + (void)PinSetPull(NULL, tester->config.PullTypeNum); + (void)PinGetPull(NULL, &tester->config.PullTypeNum); + (void)PinSetStrength(NULL, tester->config.strengthNum); + (void)PinGetStrength(NULL, &tester->config.strengthNum); + (void)PinSetFunc(NULL, (const char *)tester->config.funcNameBuf); + (void)PinGetFunc(NULL, &tester->config.funcName); + // invalid strengthNum + (void)PinSetStrength(tester->handle, -1); + (void)PinGetStrength(tester->handle, NULL); + // invalid FuncName + (void)PinSetFunc(tester->handle, NULL); + HDF_LOGD("%s:test done.All completed!", __func__); + + return HDF_SUCCESS; +} + +static struct PinTestEntry g_entry[] = { + { PIN_TEST_CMD_SETGETPULL, PinSetGetPullTest, "PinSetGetPullTest" }, + { PIN_TEST_CMD_SETGETSTRENGTH, PinSetGetStrengthTest, "PinSetGetStrengthTest" }, + { PIN_TEST_CMD_SETGETFUNC, PinSetGetFuncTest, "PinSetGetFuncTest" }, + { PIN_TEST_CMD_RELIABILITY, PinTestReliability, "PinTestReliability" }, + { PIN_TEST_CMD_SETUP_ALL, PinTestSetUpAll, "PinTestSetUpAll" }, + { PIN_TEST_CMD_TEARDOWN_ALL, PinTestTearDownAll, "PinTestTearDownAll" }, +}; + +int32_t PinTestExecute(int cmd) +{ + uint32_t i; + int32_t ret = HDF_ERR_NOT_SUPPORT; + + if(cmd > PIN_TEST_CMD_MAX) { + HDF_LOGE("%s: invalid cmd:%d", __func__, cmd); + ret = HDF_ERR_NOT_SUPPORT; + goto __EXIT__; + } + + for (i = 0; i < sizeof(g_entry) / sizeof(g_entry[0]); i++) { + if (g_entry[i].cmd != cmd || g_entry[i].func == NULL) { + continue; + } + ret = g_entry[i].func(); + break; + } + +__EXIT__: + HDF_LOGE("[%s][======cmd:%d====ret:%d======]", __func__, cmd, ret); + return ret; +} + +void PinTestExecuteAll(void) +{ + int32_t i; + int32_t ret; + int32_t fails = 0; + + /* setup env for all test cases */ + (void)PinTestExecute(PIN_TEST_CMD_SETUP_ALL); + + for (i = 0; i < PIN_TEST_CMD_SETUP_ALL; i++) { + ret = PinTestExecute(i); + fails += (ret != HDF_SUCCESS) ? 1 : 0; + } + + /* teardown env for all test cases */ + (void)PinTestExecute(PIN_TEST_CMD_TEARDOWN_ALL); + + HDF_LOGI("%s: **********PASS:%d FAIL:%d************\n\n", + __func__, PIN_TEST_CMD_RELIABILITY + 1 - fails, fails); +} \ No newline at end of file diff --git a/test/unittest/platform/common/pin_test.h b/test/unittest/platform/common/pin_test.h new file mode 100644 index 0000000000000000000000000000000000000000..6dddb9abef6839fb0d343396a77d2798e07f68ba --- /dev/null +++ b/test/unittest/platform/common/pin_test.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef PIN_TEST_H +#define PIN_TEST_H + +#include "pin_if.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif /* __cplusplus */ + +struct PinTestConfig { + const char *pinName; + char funcNameBuf[30]; + const char *funcName; + enum PinPullType PullTypeNum; + uint32_t strengthNum; +}; + +struct PinTester { + struct PinTestConfig config; + DevHandle handle; + uint16_t total; + uint16_t fails; +}; + +enum PinTestCmd { + PIN_TEST_CMD_SETGETPULL = 0, + PIN_TEST_CMD_SETGETSTRENGTH = 1, + PIN_TEST_CMD_SETGETFUNC = 2, + PIN_TEST_CMD_RELIABILITY = 3, + PIN_TEST_CMD_SETUP_ALL = 4, + PIN_TEST_CMD_TEARDOWN_ALL = 5, + PIN_TEST_CMD_SETUP_SINGLE = 6, + PIN_TEST_CMD_TEARDOWN_SINGLE = 7, + PIN_TEST_CMD_MAX = 8, +}; + +int32_t PinTestExecute(int cmd); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif /* PIN_TEST_H */ diff --git a/test/unittest/platform/hdf_pin_entry_test.c b/test/unittest/platform/hdf_pin_entry_test.c new file mode 100644 index 0000000000000000000000000000000000000000..b159fcd3608bbd0c67ff7b461770b195974d5404 --- /dev/null +++ b/test/unittest/platform/hdf_pin_entry_test.c @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#include "hdf_pin_entry_test.h" +#include "hdf_log.h" +#include "pin_test.h" + +#define HDF_LOG_TAG hdf_pin_entry_test + +int32_t HdfPinTestEntry(HdfTestMsg *msg) +{ + HDF_LOGD("%s: enter", __func__); + + if (msg == NULL) { + return HDF_FAILURE; + } + + msg->result = PinTestExecute(msg->subCmd); + + return HDF_SUCCESS; +} \ No newline at end of file diff --git a/test/unittest/platform/hdf_pin_entry_test.h b/test/unittest/platform/hdf_pin_entry_test.h new file mode 100644 index 0000000000000000000000000000000000000000..eac3848cd785097ef293cc70d7667762a03fd22f --- /dev/null +++ b/test/unittest/platform/hdf_pin_entry_test.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * + * HDF is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * See the LICENSE file in the root of this repository for complete details. + */ + +#ifndef HDF_PIN_ENTRY_TEST_H +#define HDF_PIN_ENTRY_TEST_H + +#include "hdf_main_test.h" + +int32_t HdfPinTestEntry(HdfTestMsg *msg); + +#endif /* HDF_PIN_ENTRY_TEST_H */ \ No newline at end of file