diff --git a/support/platform/src/pwm_core.c b/support/platform/src/pwm_core.c index 98b2347be96b7dd91de36b011c2cbdff8d7683ff..1f77085da88dbc518ae6f478dd991993b9ee6840 100644 --- a/support/platform/src/pwm_core.c +++ b/support/platform/src/pwm_core.c @@ -6,13 +6,12 @@ * See the LICENSE file in the root of this repository for complete details. */ +#include "pwm_core.h" #include "hdf_log.h" #include "osal_mem.h" -#include "pwm_core.h" -#include "pwm_if.h" #include "securec.h" -#define HDF_LOG_TAG PWM_CORE +#define HDF_LOG_TAG pwm_core #define PWM_NAME_LEN 32 static struct PwmDev *PwmGetDevByNum(uint32_t num) @@ -91,6 +90,7 @@ int32_t PwmSetConfig(DevHandle handle, struct PwmConfig *config) int32_t ret; struct PwmDev *pwm = NULL; + HDF_LOGI("%s: enter.", __func__); if (handle == NULL) { HDF_LOGE("%s: handle is NULL", __func__); return HDF_ERR_INVALID_OBJECT; @@ -108,12 +108,16 @@ int32_t PwmSetConfig(DevHandle handle, struct PwmConfig *config) HDF_LOGE("%s: setConfig is not support", __func__); return HDF_ERR_NOT_SUPPORT; } + HDF_LOGI("%s: set PwmConfig: number %u, period %u, duty %u, polarity %u, enable %u.", __func__, + config->number, config->period, config->duty, config->polarity, config->status); ret = pwm->method->setConfig(pwm, config); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: failed, ret %d", __func__, ret); return ret; } pwm->cfg = *config; + HDF_LOGI("%s: success.", __func__); + return HDF_SUCCESS; } @@ -121,6 +125,7 @@ int32_t PwmGetConfig(DevHandle handle, struct PwmConfig *config) { struct PwmDev *pwm = NULL; + HDF_LOGI("%s: enter.", __func__); if (handle == NULL) { HDF_LOGE("%s: handle is NULL", __func__); return HDF_ERR_INVALID_OBJECT; @@ -131,6 +136,7 @@ int32_t PwmGetConfig(DevHandle handle, struct PwmConfig *config) } pwm = (struct PwmDev *)handle; *config = pwm->cfg; + HDF_LOGI("%s: success.", __func__); return HDF_SUCCESS; } @@ -138,57 +144,96 @@ int32_t PwmGetConfig(DevHandle handle, struct PwmConfig *config) int32_t PwmEnable(DevHandle handle) { struct PwmConfig config; + uint32_t curValue; + int32_t ret; + HDF_LOGI("%s: enter.", __func__); if (PwmGetConfig(handle, &config) != HDF_SUCCESS) { return HDF_FAILURE; } + curValue = config.status; config.status = PWM_ENABLE_STATUS; - return PwmSetConfig(handle, &config); + ret = PwmSetConfig(handle, &config); + if (ret == HDF_SUCCESS) { + HDF_LOGI("%s: success. enable: %d -> %d.", __func__, curValue, config.status); + } + return ret; } int32_t PwmDisable(DevHandle handle) { struct PwmConfig config; + uint32_t curValue; + int32_t ret; + HDF_LOGI("%s: enter.", __func__); if (PwmGetConfig(handle, &config) != HDF_SUCCESS) { return HDF_FAILURE; } + curValue = config.status; config.status = PWM_DISABLE_STATUS; - return PwmSetConfig(handle, &config); + ret = PwmSetConfig(handle, &config); + if (ret == HDF_SUCCESS) { + HDF_LOGI("%s: success. enable: %d -> %d.", __func__, curValue, config.status); + } + return ret; } int32_t PwmSetPeriod(DevHandle handle, uint32_t period) { struct PwmConfig config; + uint32_t curValue; + int32_t ret; + HDF_LOGI("%s: enter.", __func__); if (PwmGetConfig(handle, &config) != HDF_SUCCESS) { return HDF_FAILURE; } + curValue = config.period; config.period = period; - return PwmSetConfig(handle, &config); + ret = PwmSetConfig(handle, &config); + if (ret == HDF_SUCCESS) { + HDF_LOGI("%s: success. period: %d -> %d.", __func__, curValue, config.period); + } + return ret; } int32_t PwmSetDuty(DevHandle handle, uint32_t duty) { struct PwmConfig config; + uint32_t curValue; + int32_t ret; + HDF_LOGI("%s: enter.", __func__); if (PwmGetConfig(handle, &config) != HDF_SUCCESS) { return HDF_FAILURE; } + curValue = config.duty; config.duty = duty; - return PwmSetConfig(handle, &config); + ret = PwmSetConfig(handle, &config); + if (ret == HDF_SUCCESS) { + HDF_LOGI("%s: success. duty: %d -> %d.", __func__, curValue, config.duty); + } + return ret; } int32_t PwmSetPolarity(DevHandle handle, uint8_t polarity) { struct PwmConfig config; + uint32_t curValue; + int32_t ret; + HDF_LOGI("%s: enter.", __func__); if (PwmGetConfig(handle, &config) != HDF_SUCCESS) { return HDF_FAILURE; } + curValue = config.polarity; config.polarity = polarity; - config.duty = config.period - config.duty; - return PwmSetConfig(handle, &config); + ret = PwmSetConfig(handle, &config); + if (ret == HDF_SUCCESS) { + HDF_LOGI("%s: success. polarity: %d -> %d.", __func__, curValue, config.polarity); + } + return ret; } int32_t PwmSetPriv(struct PwmDev *pwm, void *priv) diff --git a/support/platform/test/unittest/common/hdf_pwm_test.cpp b/support/platform/test/unittest/common/hdf_pwm_test.cpp index 3a439a5eacf35a633739fab2eb4f7a8bad25f16e..c7c787dfa5c2cff4fa5500b25db7dac98cede39d 100644 --- a/support/platform/test/unittest/common/hdf_pwm_test.cpp +++ b/support/platform/test/unittest/common/hdf_pwm_test.cpp @@ -6,13 +6,7 @@ * 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" using namespace testing::ext; diff --git a/test/unittest/platform/common/pwm_test.c b/test/unittest/platform/common/pwm_test.c index 6c291326a82c374e21d7a1f70fe32f6e418d8b20..57ab34a3b7e8e0d106f7d07e6ec70fae377d5a2c 100644 --- a/test/unittest/platform/common/pwm_test.c +++ b/test/unittest/platform/common/pwm_test.c @@ -6,14 +6,17 @@ * See the LICENSE file in the root of this repository for complete details. */ +#include "pwm_test.h" #include "device_resource_if.h" #include "hdf_base.h" #include "hdf_log.h" -#include "osal_mem.h" #include "osal_time.h" -#include "pwm_test.h" -#define HDF_LOG_TAG pwm_test_c +#define HDF_LOG_TAG pwm_test +#define SEQ_OUTPUT_DELAY 100 /* Delay time of sequential output, unit: ms */ +#define OUTPUT_WAVES_DELAY 1 /* Delay time of waves output, unit: second */ +#define TEST_WAVES_NUMBER 10 /* The number of waves for test. */ + struct PwmTestFunc { enum PwmTestCmd type; int32_t (*Func)(struct PwmTest *test); @@ -27,7 +30,7 @@ static DevHandle PwmTestGetHandle(struct PwmTest *test) static void PwmTestReleaseHandle(DevHandle handle) { if (handle == NULL) { - HDF_LOGE("%s: pwm handle is null", __func__); + HDF_LOGE("%s: pwm handle is null.", __func__); return; } PwmClose(handle); @@ -37,23 +40,36 @@ static int32_t PwmSetConfigTest(struct PwmTest *test) { int32_t ret; struct PwmConfig cfg = {0}; + uint32_t number; + HDF_LOGI("%s: enter. Test [PwmSetConfig].", __func__); + number = test->cfg.number; + test->cfg.number = (number > 0) ? 0: TEST_WAVES_NUMBER; + HDF_LOGI("%s: Set number %u.", __func__, test->cfg.number); + ret = PwmSetConfig(test->handle, &(test->cfg)); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [PwmSetConfig] failed, ret %d.", __func__, ret); + return HDF_FAILURE; + } + OsalSleep(OUTPUT_WAVES_DELAY); + test->cfg.number = number; + HDF_LOGI("%s: Set number %u.", __func__, test->cfg.number); ret = PwmSetConfig(test->handle, &(test->cfg)); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmSetConfig] failed, ret %d.", __func__, ret); return HDF_FAILURE; } ret = PwmGetConfig(test->handle, &cfg); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmGetConfig] failed, ret %d.", __func__, ret); return HDF_FAILURE; } if (memcmp(&cfg, &(test->cfg), sizeof(cfg)) != 0) { - HDF_LOGE("%s: failed", __func__); + HDF_LOGE("%s: [memcmp] failed.", __func__); return HDF_FAILURE; } - HDF_LOGE("============= %s: success =============", __func__); + HDF_LOGI("%s: success.", __func__); return ret; } @@ -62,12 +78,13 @@ static int32_t PwmGetConfigTest(struct PwmTest *test) int32_t ret; struct PwmConfig cfg = {0}; + HDF_LOGI("%s: enter. Test [PwmGetConfig].", __func__); ret = PwmGetConfig(test->handle, &cfg); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmGetConfig] failed, ret %d.", __func__, ret); return HDF_FAILURE; } - HDF_LOGE("============= %s: success =============", __func__); + HDF_LOGI("%s: success.", __func__); return ret; } @@ -75,22 +92,25 @@ static int32_t PwmSetPeriodTest(struct PwmTest *test) { int32_t ret; struct PwmConfig cfg = {0}; + uint32_t period; - ret = PwmSetPeriod(test->handle, test->cfg.period); + period = test->cfg.period + test->originCfg.period; + HDF_LOGI("%s: enter. Test [PwmSetPeriod] period %u.", __func__, period); + ret = PwmSetPeriod(test->handle, period); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmSetPeriod] failed, ret %d.", __func__, ret); return HDF_FAILURE; } ret = PwmGetConfig(test->handle, &cfg); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmGetConfig] failed, ret %d.", __func__, ret); return HDF_FAILURE; } - if (cfg.period != test->cfg.period) { - HDF_LOGE("%s: failed", __func__); + if (cfg.period != period) { + HDF_LOGE("%s: failed.", __func__); return HDF_FAILURE; } - HDF_LOGE("============= %s: success =============", __func__); + HDF_LOGI("%s: success.", __func__); return ret; } @@ -98,22 +118,25 @@ static int32_t PwmSetDutyTest(struct PwmTest *test) { int32_t ret; struct PwmConfig cfg = {0}; + uint32_t duty; - ret = PwmSetDuty(test->handle, test->cfg.duty); + duty = test->cfg.duty + test->originCfg.duty; + HDF_LOGI("%s: enter. Test [PwmSetDuty] duty %u.", __func__, duty); + ret = PwmSetDuty(test->handle, duty); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmSetDuty] failed, ret %d.", __func__, ret); return HDF_FAILURE; } ret = PwmGetConfig(test->handle, &cfg); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmGetConfig] failed, ret %d.", __func__, ret); return HDF_FAILURE; } - if (cfg.duty != test->cfg.duty) { - HDF_LOGE("%s: failed", __func__); + if (cfg.duty != duty) { + HDF_LOGE("%s: failed.", __func__); return HDF_FAILURE; } - HDF_LOGE("============= %s: success =============", __func__); + HDF_LOGI("%s: success.", __func__); return ret; } @@ -122,21 +145,31 @@ static int32_t PwmSetPolarityTest(struct PwmTest *test) int32_t ret; struct PwmConfig cfg = {0}; + HDF_LOGI("%s: enter.", __func__); + test->cfg.polarity = PWM_NORMAL_POLARITY; + HDF_LOGI("%s: Test [PwmSetPolarity] polarity %u.", __func__, test->cfg.polarity); ret = PwmSetPolarity(test->handle, test->cfg.polarity); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmSetPolarity] failed, ret %d.", __func__, ret); + return HDF_FAILURE; + } + test->cfg.polarity = PWM_INVERTED_POLARITY; + HDF_LOGI("%s: Test [PwmSetPolarity] polarity %u.", __func__, test->cfg.polarity); + ret = PwmSetPolarity(test->handle, test->cfg.polarity); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [PwmSetPolarity] failed, ret %d.", __func__, ret); return HDF_FAILURE; } ret = PwmGetConfig(test->handle, &cfg); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmGetConfig] failed, ret %d.", __func__, ret); return HDF_FAILURE; } if (cfg.polarity != test->cfg.polarity) { - HDF_LOGE("%s: failed", __func__); + HDF_LOGE("%s: failed.", __func__); return HDF_FAILURE; } - HDF_LOGE("============= %s: success =============", __func__); + HDF_LOGI("%s: success.", __func__); return ret; } @@ -145,21 +178,28 @@ static int32_t PwmEnableTest(struct PwmTest *test) int32_t ret; struct PwmConfig cfg = {0}; + HDF_LOGI("%s: enter.", __func__); + ret = PwmDisable(test->handle); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [PwmDisable] failed, ret %d.", __func__, ret); + return HDF_FAILURE; + } + HDF_LOGI("%s: Test [PwmEnable] enable.", __func__); ret = PwmEnable(test->handle); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmEnable] failed, ret %d.", __func__, ret); return HDF_FAILURE; } ret = PwmGetConfig(test->handle, &cfg); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmGetConfig] failed, ret %d.", __func__, ret); return HDF_FAILURE; } - if (cfg.status == 0) { + if (cfg.status == PWM_DISABLE_STATUS) { HDF_LOGE("%s: failed", __func__); return HDF_FAILURE; } - HDF_LOGE("============= %s: success =============", __func__); + HDF_LOGI("%s: success.", __func__); return ret; } @@ -168,21 +208,28 @@ static int32_t PwmDisableTest(struct PwmTest *test) int32_t ret; struct PwmConfig cfg = {0}; + HDF_LOGI("%s: enter.", __func__); + ret = PwmEnable(test->handle); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [PwmEnable] failed, ret %d.", __func__, ret); + return HDF_FAILURE; + } + HDF_LOGI("%s: Test [PwmDisable] disable.", __func__); ret = PwmDisable(test->handle); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmDisable] failed, ret %d.", __func__, ret); return HDF_FAILURE; } ret = PwmGetConfig(test->handle, &cfg); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: error, ret %d", __func__, ret); + HDF_LOGE("%s: [PwmGetConfig] failed, ret %d.", __func__, ret); return HDF_FAILURE; } - if (cfg.status == 1) { - HDF_LOGE("%s: failed", __func__); + if (cfg.status == PWM_ENABLE_STATUS) { + HDF_LOGE("%s: failed.", __func__); return HDF_FAILURE; } - HDF_LOGE("============= %s: success =============", __func__); + HDF_LOGI("%s: success.", __func__); return ret; } @@ -212,7 +259,7 @@ static int32_t PwmReliabilityTest(struct PwmTest *test) (void)PwmDisable(test->handle); (void)PwmDisable(test->handle); - HDF_LOGE("============= %s: success =============", __func__); + HDF_LOGI("%s: success.", __func__); return HDF_SUCCESS; } @@ -254,7 +301,7 @@ static int32_t PwmTestAll(struct PwmTest *test) } total++; - HDF_LOGE("============= %s: Pwm Test Total %d Error %d =============", __func__, total, error); + HDF_LOGI("%s: Pwm Test Total %d Error %d.", __func__, total, error); return HDF_SUCCESS; } @@ -278,20 +325,34 @@ static int32_t PwmTestEntry(struct PwmTest *test, int32_t cmd) if (test == NULL) { return HDF_ERR_INVALID_OBJECT; } + OsalMSleep(SEQ_OUTPUT_DELAY); test->handle = PwmTestGetHandle(test); if (test->handle == NULL) { - HDF_LOGE("%s: spi test get handle fail", __func__); + HDF_LOGE("%s: pwm test get handle fail.", __func__); return HDF_FAILURE; } + // At first test case. + if (cmd == PWM_SET_PERIOD_TEST) { + ret = PwmGetConfig(test->handle, &(test->originCfg)); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: [PwmGetConfig] failed, ret %d.", __func__, ret); + return HDF_FAILURE; + } + } for (i = 0; i < sizeof(g_pwmTestFunc) / sizeof(g_pwmTestFunc[0]); i++) { if (cmd == g_pwmTestFunc[i].type && g_pwmTestFunc[i].Func != NULL) { ret = g_pwmTestFunc[i].Func(test); - HDF_LOGE("%s: cmd %d ret %d", __func__, cmd, ret); + HDF_LOGI("%s: cmd %d ret %d.", __func__, cmd, ret); break; } } - + // At last test case. + if (cmd == PWM_DISABLE_TEST) { + PwmSetConfig(test->handle, &(test->originCfg)); + } PwmTestReleaseHandle(test->handle); + OsalMSleep(SEQ_OUTPUT_DELAY); + return ret; } @@ -302,9 +363,9 @@ static int32_t PwmTestBind(struct HdfDeviceObject *device) if (device != NULL) { device->service = &test.service; } else { - HDF_LOGE("%s: device is NULL", __func__); + HDF_LOGE("%s: device is NULL.", __func__); } - HDF_LOGE("%s: success", __func__); + HDF_LOGE("%s: success.", __func__); return HDF_SUCCESS; } @@ -317,31 +378,31 @@ static int32_t PwmTestInitFromHcs(struct PwmTest *test, const struct DeviceResou face = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); if (face == NULL) { - HDF_LOGE("%s: face is null", __func__); + HDF_LOGE("%s: face is null.", __func__); return HDF_FAILURE; } if (face->GetUint32 == NULL) { - HDF_LOGE("%s: GetUint32 not support", __func__); + HDF_LOGE("%s: GetUint32 not support.", __func__); return HDF_ERR_NOT_SUPPORT; } ret = face->GetUint32(node, "num", &(test->num), 0); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read num fail", __func__); + HDF_LOGE("%s: read num fail.", __func__); return HDF_FAILURE; } ret = face->GetUint32(node, "period", &(test->cfg.period), 0); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read period fail", __func__); + HDF_LOGE("%s: read period fail.", __func__); return HDF_FAILURE; } ret = face->GetUint32(node, "duty", &(test->cfg.duty), 0); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read duty fail", __func__); + HDF_LOGE("%s: read duty fail.", __func__); return HDF_FAILURE; } ret = face->GetUint32(node, "polarity", &tmp, 0); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: read polarity fail", __func__); + HDF_LOGE("%s: read polarity fail.", __func__); return HDF_FAILURE; } test->cfg.polarity = tmp; @@ -359,14 +420,14 @@ static int32_t PwmTestInit(struct HdfDeviceObject *device) struct PwmTest *test = NULL; if (device == NULL || device->service == NULL || device->property == NULL) { - HDF_LOGE("%s: invalid parameter", __func__); + HDF_LOGE("%s: invalid parameter.", __func__); return HDF_ERR_INVALID_PARAM; } test = (struct PwmTest *)device->service; if (PwmTestInitFromHcs(test, device->property) != HDF_SUCCESS) { return HDF_FAILURE; } - HDF_LOGE("%s: success", __func__); + HDF_LOGE("%s: success.", __func__); test->TestEntry = PwmTestEntry; return HDF_SUCCESS; } @@ -374,7 +435,7 @@ static int32_t PwmTestInit(struct HdfDeviceObject *device) static void PwmTestRelease(struct HdfDeviceObject *device) { (void)device; - HDF_LOGE("%s: success", __func__); + HDF_LOGE("%s: success.", __func__); } struct HdfDriverEntry g_pwmTestEntry = { @@ -385,4 +446,3 @@ struct HdfDriverEntry g_pwmTestEntry = { .moduleName = "PLATFORM_PWM_TEST", }; HDF_INIT(g_pwmTestEntry); - diff --git a/test/unittest/platform/common/pwm_test.h b/test/unittest/platform/common/pwm_test.h index b82a8b3ed7c9e0d40d5e1b4eee9297b23cfb7c33..35cfddddd714d4051d79ec801e221c8b30c7fd53 100644 --- a/test/unittest/platform/common/pwm_test.h +++ b/test/unittest/platform/common/pwm_test.h @@ -10,7 +10,6 @@ #define PWM_TEST_H #include "hdf_device_desc.h" -#include "hdf_platform.h" #include "pwm_if.h" enum PwmTestCmd { @@ -31,6 +30,7 @@ struct PwmTest { int32_t (*TestEntry)(struct PwmTest *test, int32_t cmd); uint32_t num; struct PwmConfig cfg; + struct PwmConfig originCfg; DevHandle handle; }; diff --git a/test/unittest/platform/hdf_pwm_entry_test.c b/test/unittest/platform/hdf_pwm_entry_test.c index bb274ea2415f24b3e9616df4f1de9d9922423ea5..8bb761a7cdd3d89631728758a1ffdce9f0fbefd6 100644 --- a/test/unittest/platform/hdf_pwm_entry_test.c +++ b/test/unittest/platform/hdf_pwm_entry_test.c @@ -8,7 +8,6 @@ #include "hdf_pwm_entry_test.h" #include "hdf_log.h" -#include "pwm_if.h" #include "pwm_test.h" #define HDF_LOG_TAG hdf_pwm_entry_test @@ -18,13 +17,16 @@ int32_t HdfPwmUnitTestEntry(HdfTestMsg *msg) struct PwmTest *test = NULL; if (msg == NULL) { + HDF_LOGE("%s: msg is NULL!", __func__); return HDF_FAILURE; } test = GetPwmTest(); if (test == NULL || test->TestEntry == NULL) { + HDF_LOGE("%s: test or TestEntry is NULL!", __func__); msg->result = HDF_FAILURE; return HDF_FAILURE; } + HDF_LOGI("%s: call [TestEntry]", __func__); msg->result = test->TestEntry(test, msg->subCmd); return msg->result; }