diff --git a/support/platform/test/unittest/common/hdf_can_test.cpp b/support/platform/test/unittest/common/hdf_can_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ac85a3724b7bb0f6d25e094928be88bf5e8fe35a --- /dev/null +++ b/support/platform/test/unittest/common/hdf_can_test.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2022 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 "can_test.h" +#include "hdf_uhdf_test.h" + +using namespace testing::ext; + +class HdfCanTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void HdfCanTest::SetUpTestCase() +{ + HdfTestOpenService(); +} + +void HdfCanTest::TearDownTestCase() +{ + HdfTestCloseService(); +} + +void HdfCanTest::SetUp() {} + +void HdfCanTest::TearDown() {} + +/** + * @tc.name: HdfCanTestr001 + * @tc.desc: can bus function test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfCanTest, HdfCanTest001_SendAndRead, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_CAN_TYPE, CAN_TEST_SEND_AND_READ, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: HdfCanTest002 + * @tc.desc: can bus function test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfCanTest, HdfCanTest002_ReadNoBlock, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_CAN_TYPE, CAN_TEST_NO_BLOCK_READ, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: HdfCanTest003 + * @tc.desc: can bus function test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfCanTest, HdfCanTest003_ReadBlock, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_CAN_TYPE, CAN_TEST_BLOCK_READ, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: HdfCanTest004 + * @tc.desc: can bus function test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfCanTest, HdfCanTest004_AddAndDelFilter, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_CAN_TYPE, CAN_TEST_ADD_DEL_FILTER, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: HdfCanTest005 + * @tc.desc: can bus function test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfCanTest, HdfCanTest005_AddNultiFilters, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_CAN_TYPE, CAN_TEST_ADD_MULTI_FILTER, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: HdfCanTest006 + * @tc.desc: can bus function test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfCanTest, HdfCanTest006_GetBusState, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_CAN_TYPE, CAN_TEST_GET_BUS_STATE, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: HdfCanTest007 + * @tc.desc: can bus function test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfCanTest, HdfCanTest007_ReadSameHandleInMultiThread, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_CAN_TYPE, CAN_TEST_MULTI_THREAD_READ_SAME_HANDLE, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: HdfCanTest008 + * @tc.desc: can bus function test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfCanTest, HdfCanTest008_ReadMultiHandleInMultiThread, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_CAN_TYPE, CAN_TEST_MULTI_THREAD_READ_MULTI_HANDLE, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: HdfCanTest009 + * @tc.desc: can bus function test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfCanTest, HdfCanTest009_WriteSameHandleInMultiThread, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_CAN_TYPE, CAN_TEST_MULTI_THREAD_SEND_SAME_HANDLE, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} + +/** + * @tc.name: HdfCanTest010 + * @tc.desc: can bus function test + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(HdfCanTest, HdfCanTest010_WriteMultiHandleInMultiThread, TestSize.Level1) +{ + struct HdfTestMsg msg = {TEST_PAL_CAN_TYPE, CAN_TEST_MULTI_THREAD_SEND_MULTI_HANDLE, -1}; + EXPECT_EQ(0, HdfTestSendMsgToService(&msg)); +} diff --git a/test/unittest/common/hdf_main_test.c b/test/unittest/common/hdf_main_test.c index a0e2bea24556ee2df28d69e88e08026f29c96adc..b7bf3a513c33b71cb4757190b819889b9a22fb4b 100644 --- a/test/unittest/common/hdf_main_test.c +++ b/test/unittest/common/hdf_main_test.c @@ -6,15 +6,16 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include "hcs_parser_test.h" +#include "hdf_main_test.h" + #include "hdf_base.h" #include "hdf_device_desc.h" #include "hdf_log.h" -#include "hdf_main_test.h" +#include "hcs_parser_test.h" #include "osal_test_entry.h" #if defined(LOSCFG_DRIVERS_HDF_PLATFORM) || defined(CONFIG_DRIVERS_HDF_PLATFORM) -#include "hdf_platform_core_entry_test.h" +#include "hdf_platform_entry_test.h" #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO) || defined(CONFIG_DRIVERS_HDF_PLATFORM_GPIO) #include "hdf_gpio_entry_test.h" #endif @@ -64,7 +65,7 @@ #include "hdf_mipi_csi_entry_test.h" #endif #if (defined(LOSCFG_STORAGE_EMMC) && defined(LOSCFG_DRIVERS_HDF_PLATFORM_EMMC)) || \ - defined(CONFIG_DRIVERS_HDF_PLATFORM_EMMC) + defined(CONFIG_DRIVERS_HDF_PLATFORM_EMMC) #include "hdf_emmc_entry_test.h" #endif #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PWM) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PWM) @@ -78,8 +79,8 @@ #include "hdf_wifi_test.h" #endif #if defined(LOSCFG_DRIVERS_HDF_AUDIO_TEST) || defined(CONFIG_DRIVERS_HDF_AUDIO_TEST) -#include "hdf_audio_test.h" #include "hdf_audio_driver_test.h" +#include "hdf_audio_test.h" #endif #if defined(LOSCFG_DRIVERS_HDF_USB_DDK_DEVICE) || defined(CONFIG_DRIVERS_HDF_USB_DDK_DEVICE) #include "hdf_usb_device_test.h" @@ -98,11 +99,12 @@ HdfTestFuncList g_hdfTestFuncList[] = { { TEST_PAL_DEVICE_TYPE, HdfPlatformDeviceTestEntry }, { TEST_PAL_MANAGER_TYPE, HdfPlatformManagerTestEntry }, { TEST_PAL_DUMPER_TYPE, HdfPlatformDumperTestEntry }, + { TEST_PAL_CAN_TYPE, HdfCanTestEntry }, #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_TRACE) || defined(CONFIG_DRIVERS_HDF_PLATFORM_TRACE) - { TEST_PAL_TRACE_TYPE, HdfPlatformTraceTestEntry }, + { TEST_PAL_TRACE_TYPE, HdfPlatformTraceTestEntry }, #endif #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PIN) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PIN) { TEST_PAL_PIN_TYPE, HdfPinTestEntry }, @@ -273,10 +275,10 @@ int HdfTestDriverInit(struct HdfDeviceObject *device) struct HdfDriverEntry g_hdfTestDevice = { .moduleVersion = 1, - .moduleName = "HDF_TEST", - .Bind = HdfTestDriverBind, - .Init = HdfTestDriverInit, - .Release = HdfTestDriverRelease, + .moduleName = "HDF_TEST", + .Bind = HdfTestDriverBind, + .Init = HdfTestDriverInit, + .Release = HdfTestDriverRelease, }; HDF_INIT(g_hdfTestDevice); diff --git a/test/unittest/common/hdf_main_test.h b/test/unittest/common/hdf_main_test.h index 183025614a9ab80cca5bde27c3367a154c72676b..ac4a8304037eb2818c82af71896622ed9fbb063e 100644 --- a/test/unittest/common/hdf_main_test.h +++ b/test/unittest/common/hdf_main_test.h @@ -18,7 +18,7 @@ typedef struct { int8_t result; } HdfTestMsg; -typedef int32_t (*TestFunc)(HdfTestMsg*); +typedef int32_t (*TestFunc)(HdfTestMsg *); typedef int32_t (*TestCaseFunc)(void); typedef struct { uint16_t cmd; // submodule command @@ -61,6 +61,7 @@ typedef enum { TEST_PAL_MIPI_CSI_TYPE = 23, TEST_PAL_DAC_TYPE = 24, TEST_PAL_TIMER_TYPE = 25, + TEST_PAL_CAN_TYPE = 26, TEST_PAL_MANAGER_TYPE = 194, TEST_PAL_DEVICE_TYPE = 195, TEST_PAL_QUEUE_TYPE = 196, diff --git a/test/unittest/include/hdf_uhdf_test.h b/test/unittest/include/hdf_uhdf_test.h index 41a4546912d89f2651ceb84444ddd8ec75913d87..d98f726b7910b6b13bf060f9a50d5705d450e6da 100644 --- a/test/unittest/include/hdf_uhdf_test.h +++ b/test/unittest/include/hdf_uhdf_test.h @@ -12,16 +12,17 @@ #include "hdf_base.h" #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* __cplusplus */ -#define HDF_TEST_SERVICE_NAME "HDF_TEST" -#define CHECK_TEST_NULL_PTR_RETURN(ptr) do { \ - if ((ptr) == NULL) { \ - printf("pointer is null and return\n\r"); \ - return HDF_FAILURE; \ - } \ -} while (0) +#define HDF_TEST_SERVICE_NAME "HDF_TEST" +#define CHECK_TEST_NULL_PTR_RETURN(ptr) \ + do { \ + if ((ptr) == NULL) { \ + printf("pointer is null and return\n\r"); \ + return HDF_FAILURE; \ + } \ + } while (0) struct HdfTestMsg { uint16_t cmd; // submodule command @@ -57,6 +58,7 @@ enum HdfTestSubModuleCmd { TEST_PAL_MIPI_CSI_TYPE = 23, TEST_PAL_DAC_TYPE = 24, TEST_PAL_TIMER_TYPE = 25, + TEST_PAL_CAN_TYPE = 26, TEST_PAL_MANAGER_TYPE = 194, TEST_PAL_DEVICE_TYPE = 195, TEST_PAL_QUEUE_TYPE = 196, diff --git a/test/unittest/platform/common/can_test.c b/test/unittest/platform/common/can_test.c new file mode 100644 index 0000000000000000000000000000000000000000..dc05414512db4724ee190f89b42786150cc672cd --- /dev/null +++ b/test/unittest/platform/common/can_test.c @@ -0,0 +1,489 @@ +/* + * Copyright (c) 2022 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 "can_test.h" +#include "can_if.h" +#include "device_resource_if.h" +#include "hdf_device_desc.h" +#include "hdf_io_service_if.h" +#include "hdf_log.h" +#include "osal_mem.h" +#include "osal_thread.h" +#include "osal_time.h" +#include "platform_assert.h" +#include "securec.h" + +#define HDF_LOG_TAG can_test +#define CAN_TEST_STACK_SIZE (1024 * 10) + +#define CAN_TEST_ID_A 0x15A +#define CAN_TEST_ID_B 0x2A5 +#define CAN_TEST_ID_C 0x555 +#define CAN_MASK_FULL 0x1FFFFFFF +#define CAN_TEST_DATA 0xAB + +#define CAN_TEST_TIMEOUT_20 20 +#define CAN_TEST_TIMEOUT_10 10 + +static struct HdfDeviceObject hdfDev = { + .service = NULL, + .property = NULL, + .priv = NULL, +}; + +struct HdfDriverEntry *CanVirtualGetEntry(void); +struct HdfDriverEntry *g_driverEntry = NULL; +static uint16_t g_busNum; +static DevHandle g_handle; +static struct CanMsg g_msgA; +static struct CanMsg g_msgB; +static struct CanMsg g_msgC; + +static struct CanFilter g_filterA = { + .rtr = 0, + .ide = 0, + .id = CAN_TEST_ID_A, + .rtrMask = 1, + .ideMask = 1, + .idMask = CAN_MASK_FULL, +}; + +static struct CanFilter g_filterB = { + .rtr = 0, + .ide = 0, + .id = CAN_TEST_ID_B, + .rtrMask = 1, + .ideMask = 1, + .idMask = CAN_MASK_FULL, +}; + +static void CanMsgInitByParms(struct CanMsg *msg, uint32_t id, uint32_t ide, uint32_t rtr, uint8_t data) +{ + msg->ide = ide; + msg->id = id; + msg->rtr = rtr; + if (memset_s(msg->data, sizeof(msg->data), data, sizeof(msg->data)) != EOK) { + HDF_LOGW("CanMsgInitByParms: init data failed"); + } + msg->dlc = sizeof(msg->data); + msg->error = 0; +} + +static int32_t CanTestGetConfig(struct CanTestConfig *config) +{ + int32_t ret; + struct HdfSBuf *reply = NULL; + struct HdfIoService *service = NULL; + const void *buf = NULL; + uint32_t len; + + HDF_LOGD("CanTestGetConfig: enter!"); + service = HdfIoServiceBind("CAN_TEST"); + if (service == NULL) { + return HDF_ERR_NOT_SUPPORT; + } + + reply = HdfSbufObtain(sizeof(*config) + sizeof(uint64_t)); + if (reply == NULL) { + HDF_LOGE("CanTestGetConfig: failed to obtain reply!"); + return HDF_ERR_MALLOC_FAIL; + } + + ret = service->dispatcher->Dispatch(&service->object, 0, NULL, reply); + if (ret != HDF_SUCCESS) { + HDF_LOGE("CanTestGetConfig: remote dispatch fail:%d", ret); + } + + if (!HdfSbufReadBuffer(reply, &buf, &len)) { + HDF_LOGE("CanTestGetConfig: read buf fail!"); + HdfSbufRecycle(reply); + return HDF_ERR_IO; + } + + if (len != sizeof(*config)) { + HDF_LOGE("CanTestGetConfig: config size:%u, but read size:%u!", sizeof(*config), len); + HdfSbufRecycle(reply); + return HDF_ERR_IO; + } + + if (memcpy_s(config, sizeof(*config), buf, sizeof(*config)) != EOK) { + HDF_LOGE("CanTestGetConfig: memcpy buf fail!"); + HdfSbufRecycle(reply); + return HDF_ERR_IO; + } + + HDF_LOGE("CanTestGetConfig: test on bus:0x%x, bitRate:%u, workMode:0x%x", config->busNum, config->bitRate, + config->workMode); + HdfSbufRecycle(reply); + HDF_LOGD("CanTestGetConfig: exit!"); + HdfIoServiceRecycle(service); + return HDF_SUCCESS; +} + +static int32_t CanTestSetUpByConfig(struct CanTestConfig *config) +{ + struct CanConfig cfg; + g_busNum = config->busNum; + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusOpen(g_busNum, &g_handle)); + CHECK_FALSE_RETURN(g_handle == NULL); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusGetCfg(g_handle, &cfg)); + cfg.speed = config->bitRate; + cfg.mode = config->workMode; + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusSetCfg(g_handle, &cfg)); + CanMsgInitByParms(&g_msgA, CAN_TEST_ID_A, 0, 0, CAN_TEST_DATA); + CanMsgInitByParms(&g_msgB, CAN_TEST_ID_B, 0, 0, CAN_TEST_DATA); + CanMsgInitByParms(&g_msgC, CAN_TEST_ID_C, 0, 0, CAN_TEST_DATA); + return HDF_SUCCESS; +} + +int32_t CanTestSetUpEveryCase(void) +{ + struct CanTestConfig config; + + if (CanTestGetConfig(&config) != HDF_SUCCESS) { + HDF_LOGW("CanTestSetUpEveryCase: get config failed, using default config..."); + config.bitRate = CAN_TEST_BIT_RATE; + config.workMode = CAN_TEST_WORK_MODE; + config.busNum = CAN_TEST_BUS_NUM; + g_driverEntry = CanVirtualGetEntry(); + CHECK_FALSE_RETURN(g_driverEntry == NULL); + LONGS_EQUAL_RETURN(HDF_SUCCESS, g_driverEntry->Init(&hdfDev)); + } + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanTestSetUpByConfig(&config)); + return HDF_SUCCESS; +} + +int32_t CanTestTearDownEveryCase(void) +{ + CanBusClose(g_handle); + if (g_driverEntry != NULL) { + g_driverEntry->Release(&hdfDev); + g_driverEntry = NULL; + } + return HDF_SUCCESS; +} + +static bool CanMsgEquals(const struct CanMsg *msgA, const struct CanMsg *msgB) +{ + int i; + if (msgA->ide != msgB->ide) { + return false; + } + if (msgA->id != msgB->id) { + return false; + } + if (msgA->rtr != msgB->rtr) { + return false; + } + if (msgA->dlc != msgB->dlc) { + return false; + } + for (i = 0; i < msgA->dlc; i++) { + if (msgA->data[i] != msgB->data[i]) { + return false; + } + } + return true; +} + +static bool CanBusCanNotReadMsg(DevHandle handle, struct CanMsg *msg) +{ + struct CanMsg msgGot; + LONGS_EQUAL_RETURN(HDF_ERR_TIMEOUT, CanBusReadMsg(handle, &msgGot, CAN_TEST_TIMEOUT_10)); + return true; +} + +static bool CanBusCanReadMsg(DevHandle handle, struct CanMsg *msg) +{ + struct CanMsg msgGot; + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusReadMsg(handle, &msgGot, CAN_TEST_TIMEOUT_10)); + CHECK_TRUE_RETURN(CanMsgEquals(msg, &msgGot)); + return true; +} + +static bool CanBusCanSendAndReadMsg(DevHandle handle, struct CanMsg *msg) +{ + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusSendMsg(handle, msg)); + return CanBusCanReadMsg(handle, msg); +} + +static int32_t CanTestSendAndRead(void) +{ + CHECK_TRUE_RETURN(CanBusCanSendAndReadMsg(g_handle, &g_msgA)); + return HDF_SUCCESS; +} + +static int32_t CanTestNoBlockRead(void) +{ + struct CanMsg msg; + CHECK_FALSE_RETURN(HDF_ERR_TIMEOUT == CanBusReadMsg(g_handle, &msg, 0)); + return HDF_SUCCESS; +} + +static int32_t CanTestBlockRead(void) +{ + struct CanMsg msg; + LONGS_EQUAL_RETURN(HDF_ERR_TIMEOUT, CanBusReadMsg(g_handle, &msg, CAN_TEST_TIMEOUT_10)); + return HDF_SUCCESS; +} + +static int32_t CanTestAddAndDelFilter(void) +{ + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusAddFilter(g_handle, &g_filterA)); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusSendMsg(g_handle, &g_msgA)); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusSendMsg(g_handle, &g_msgB)); + CHECK_TRUE_RETURN(CanBusCanReadMsg(g_handle, &g_msgA)); + CHECK_TRUE_RETURN(CanBusCanNotReadMsg(g_handle, &g_msgB)); // filter out ... + + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusDelFilter(g_handle, &g_filterA)); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusSendMsg(g_handle, &g_msgB)); + CHECK_TRUE_RETURN(CanBusCanReadMsg(g_handle, &g_msgB)); // filter out ... + return HDF_SUCCESS; +} + +static int32_t CanTestAddMultiFilter(void) +{ + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusAddFilter(g_handle, &g_filterA)); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusAddFilter(g_handle, &g_filterB)); + + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusSendMsg(g_handle, &g_msgA)); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusSendMsg(g_handle, &g_msgB)); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusSendMsg(g_handle, &g_msgC)); + + CHECK_TRUE_RETURN(CanBusCanReadMsg(g_handle, &g_msgA)); + CHECK_TRUE_RETURN(CanBusCanReadMsg(g_handle, &g_msgB)); + CHECK_TRUE_RETURN(CanBusCanNotReadMsg(g_handle, &g_msgC)); + + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusDelFilter(g_handle, &g_filterA)); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusDelFilter(g_handle, &g_filterB)); + + CHECK_TRUE_RETURN(CanBusCanSendAndReadMsg(g_handle, &g_msgC)); + return HDF_SUCCESS; +} + +static int32_t CanTestGetBusState(void) +{ + int32_t ret; + ret = CanBusGetState(g_handle); + if (ret == HDF_ERR_NOT_SUPPORT) { + return HDF_SUCCESS; + } + CHECK_TRUE_RETURN(ret >= CAN_BUS_RESET && ret < CAN_BUS_INVALID); + return HDF_SUCCESS; +} + +static struct OsalThread *CanTestStartTestThread(OsalThreadEntry entry, DevHandle handle) +{ + int32_t ret; + struct OsalThreadParam threadCfg; + struct OsalThread *thread = (struct OsalThread *)OsalMemCalloc(sizeof(*thread)); + + ret = OsalThreadCreate(thread, (OsalThreadEntry)entry, (void *)handle); + if (ret != HDF_SUCCESS) { + HDF_LOGE("create test thread fail:%d", ret); + return NULL; + } + + threadCfg.name = (char *)"CanTestPoller"; + threadCfg.priority = OSAL_THREAD_PRI_DEFAULT; + threadCfg.stackSize = CAN_TEST_STACK_SIZE; + + ret = OsalThreadStart(thread, &threadCfg); + if (ret != HDF_SUCCESS) { + (void)OsalThreadDestroy(thread); + HDF_LOGE("start test thread2 fail:%d", ret); + return NULL; + } + + return thread; +} + +static void CanTestStopTestThread(struct OsalThread *thread) +{ + if (thread == NULL) { + return; + } + (void)OsalThreadDestroy(thread); + OsalMemFree(thread); +} + +static int CanTestReaderFunc(void *param) +{ + struct CanMsg msg; + DevHandle handle = (DevHandle)param; + + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusReadMsg(handle, &msg, CAN_TEST_TIMEOUT_10)); + return HDF_SUCCESS; +} + +static int CanTestSenderFunc(void *param) +{ + DevHandle handle = (DevHandle)param; + + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusSendMsg(handle, &g_msgA)); + return HDF_SUCCESS; +} + +static int32_t CanTestMultiThreadReadSameHandle(void) +{ + struct CanMsg msgGot; + struct OsalThread *thread = NULL; + thread = CanTestStartTestThread(CanTestReaderFunc, g_handle); + CHECK_FALSE_RETURN(thread == NULL); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusSendMsg(g_handle, &g_msgA)); + OsalMSleep(CAN_TEST_TIMEOUT_20); + CHECK_FALSE_RETURN(CanBusReadMsg(g_handle, &msgGot, 0) == HDF_SUCCESS); + CanTestStopTestThread(thread); + return HDF_SUCCESS; +} + +static int32_t CanTestMultiThreadReadMultiHandle(void) +{ + struct CanMsg msgGot; + struct OsalThread *thread = NULL; + DevHandle handle = NULL; + + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusOpen(g_busNum, &handle)); + thread = CanTestStartTestThread(CanTestReaderFunc, handle); + CHECK_FALSE_RETURN(thread == NULL); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusSendMsg(g_handle, &g_msgA)); + OsalMSleep(CAN_TEST_TIMEOUT_20); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusReadMsg(g_handle, &msgGot, 0)); + CanTestStopTestThread(thread); + CanBusClose(handle); + return HDF_SUCCESS; +} + +static int32_t CanTestMultiThreadSendSameHandle(void) +{ + struct CanMsg msgGot; + struct OsalThread *thread = NULL; + + thread = CanTestStartTestThread(CanTestSenderFunc, g_handle); + CHECK_FALSE_RETURN(thread == NULL); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusReadMsg(g_handle, &msgGot, CAN_TEST_TIMEOUT_10)); + CanTestStopTestThread(thread); + return HDF_SUCCESS; +} + +static int32_t CanTestMultiThreadSendMultiHandle(void) +{ + struct CanMsg msgGot; + struct OsalThread *thread = NULL; + DevHandle handle = NULL; + + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusOpen(g_busNum, &handle)); + thread = CanTestStartTestThread(CanTestSenderFunc, g_handle); + CHECK_FALSE_RETURN(thread == NULL); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusReadMsg(handle, &msgGot, CAN_TEST_TIMEOUT_10)); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanBusReadMsg(g_handle, &msgGot, CAN_TEST_TIMEOUT_10)); + CanTestStopTestThread(thread); + CanBusClose(handle); + return HDF_SUCCESS; +} + +static int32_t CanTestReliability(void) +{ + int32_t ret; + struct CanMsg msg; + struct CanFilter filter; + struct CanConfig cfg; + DevHandle handle = g_handle; + + /* invalid device handle */ + ret = CanBusSendMsg(NULL, &msg); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusReadMsg(NULL, &msg, 0); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusReadMsg(NULL, &msg, 1); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusSetCfg(NULL, &cfg); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusGetCfg(NULL, &cfg); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusAddFilter(NULL, &filter); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusDelFilter(NULL, &filter); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusGetState(NULL); + CHECK_LT_RETURN(ret, 0, HDF_FAILURE); + + /* invalid parmas */ + ret = CanBusSendMsg(handle, NULL); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusReadMsg(handle, NULL, 0); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusReadMsg(handle, NULL, 1); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusSetCfg(handle, NULL); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusGetCfg(handle, NULL); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusAddFilter(handle, &filter); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + ret = CanBusDelFilter(handle, &filter); + CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE); + + return HDF_SUCCESS; +} + +struct CanTestEntry { + int cmd; + int32_t (*func)(void); + const char *name; +}; + +static struct CanTestEntry g_testEntry[] = { + { CAN_TEST_SEND_AND_READ, CanTestSendAndRead, "should_send_and_read_msg_success" }, + { CAN_TEST_NO_BLOCK_READ, CanTestNoBlockRead, "should_return_immediately_when_read_no_block" }, + { CAN_TEST_BLOCK_READ, CanTestBlockRead, "should_return_timeout_when_read_block" }, + { CAN_TEST_ADD_DEL_FILTER, CanTestAddAndDelFilter, "should_add_and_del_filter" }, + { CAN_TEST_ADD_MULTI_FILTER, CanTestAddMultiFilter, "should_add_multi_filter" }, + { CAN_TEST_GET_BUS_STATE, CanTestGetBusState, "should_get_bus_state_unless_not_supported" }, + { CAN_TEST_MULTI_THREAD_READ_SAME_HANDLE, CanTestMultiThreadReadSameHandle, + "should_read_success_in_another_thread_by_the_same_handle" }, + { CAN_TEST_MULTI_THREAD_READ_MULTI_HANDLE, CanTestMultiThreadReadMultiHandle, + "should_read_success_in_another_thread_by_another_handle" }, + { CAN_TEST_MULTI_THREAD_SEND_SAME_HANDLE, CanTestMultiThreadSendSameHandle, + "should_send_success_in_another_thread_by_the_same_handle" }, + { CAN_TEST_MULTI_THREAD_SEND_MULTI_HANDLE, CanTestMultiThreadSendMultiHandle, + "should_send_success_in_another_thread_by_another_handle" }, + { CAN_TEST_RELIABILITY, CanTestReliability, "CanTestReliability" }, +}; + +int32_t CanTestExecute(int cmd) +{ + int32_t ret; + uint32_t i; + struct CanTestEntry *entry = NULL; + + if (cmd >= CAN_TEST_CMD_MAX) { + HDF_LOGE("CanTestExecute: invalid cmd:%d", cmd); + return HDF_ERR_NOT_SUPPORT; + } + + for (i = 0; i < sizeof(g_testEntry) / sizeof(g_testEntry[0]); i++) { + if (g_testEntry[i].cmd != cmd || g_testEntry[i].func == NULL) { + continue; + } + entry = &g_testEntry[i]; + break; + } + + if (entry == NULL) { + HDF_LOGE("%s: no entry matched, cmd = %d", __func__, cmd); + return HDF_ERR_NOT_SUPPORT; + } + + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanTestSetUpEveryCase()); + ret = entry->func(); + LONGS_EQUAL_RETURN(HDF_SUCCESS, CanTestTearDownEveryCase()); + + HDF_LOGE("[CanTestExecute][======cmd:%d====ret:%d======]", cmd, ret); + return ret; +} diff --git a/test/unittest/platform/common/can_test.h b/test/unittest/platform/common/can_test.h new file mode 100644 index 0000000000000000000000000000000000000000..9323d8d1abcc6ca517b3f14beede709a6333efa5 --- /dev/null +++ b/test/unittest/platform/common/can_test.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 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 CAN_TEST_H +#define CAN_TEST_H + +#include "can_if.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define CAN_TEST_BUS_NUM 31 +#define CAN_TEST_BIT_RATE (1000 * 10) // 1K +#define CAN_TEST_WORK_MODE CAN_BUS_LOOPBACK + +int32_t CanTestExecute(int cmd); + +enum CanTestCmd { + CAN_TEST_SEND_AND_READ = 0, + CAN_TEST_NO_BLOCK_READ, + CAN_TEST_BLOCK_READ, + CAN_TEST_ADD_DEL_FILTER, + CAN_TEST_ADD_MULTI_FILTER, + CAN_TEST_GET_BUS_STATE, + CAN_TEST_MULTI_THREAD_READ_SAME_HANDLE, + CAN_TEST_MULTI_THREAD_READ_MULTI_HANDLE, + CAN_TEST_MULTI_THREAD_SEND_SAME_HANDLE, + CAN_TEST_MULTI_THREAD_SEND_MULTI_HANDLE, + CAN_TEST_RELIABILITY, + CAN_TEST_CMD_MAX, +}; + +struct CanTestConfig { + uint16_t busNum; + uint32_t bitRate; + uint8_t workMode; +}; + +struct CanTester { + struct CanTestConfig config; + DevHandle handle; + uint16_t total; + uint16_t fails; + bool readerFlag; + bool pollerFlag; + struct CanMsg msg; +}; + +#ifdef __cplusplus +} +#endif +#endif /* CAN_TEST_H */ diff --git a/test/unittest/platform/common/platform_assert.h b/test/unittest/platform/common/platform_assert.h index aead5b998c6568eb8d48dcdb8d21f7cbb9578474..92c9d27e64ff68e0c748c3c8a4edf0efb7a9c527 100644 --- a/test/unittest/platform/common/platform_assert.h +++ b/test/unittest/platform/common/platform_assert.h @@ -12,48 +12,75 @@ #include "platform_log.h" #define ERROR_AND_LOG(expr) \ -do { \ - PLAT_LOGE(__FILE__ "(line:%d): " #expr " is false!", __LINE__); \ -} while (0) - -#define CHECK(expr) \ -( { \ - if (!(expr)) { \ - ERROR_AND_LOG(expr); \ - } \ - (expr); \ -}) - -#define CHECK_EQ(a, b) CHECK((a) == (b)) -#define CHECK_NE(a, b) CHECK((a) != (b)) -#define CHECK_GE(a, b) CHECK((a) >= (b)) -#define CHECK_GT(a, b) CHECK((a) > (b)) -#define CHECK_LE(a, b) CHECK((a) <= (b)) -#define CHECK_LT(a, b) CHECK((a) < (b)) -#define CHECK_NULL(ptr) CHECK((ptr) == NULL) + do { \ + PLAT_LOGE(__FILE__ "(line:%d): " #expr " is false!", __LINE__); \ + } while (0) + +#define CHECK(expr) \ + ( { \ + if (!(expr)) { \ + ERROR_AND_LOG(expr); \ + } \ + (expr); \ + } ) + +#define CHECK_EQ(a, b) CHECK((a) == (b)) +#define CHECK_NE(a, b) CHECK((a) != (b)) +#define CHECK_GE(a, b) CHECK((a) >= (b)) +#define CHECK_GT(a, b) CHECK((a) > (b)) +#define CHECK_LE(a, b) CHECK((a) <= (b)) +#define CHECK_LT(a, b) CHECK((a) < (b)) +#define CHECK_NULL(ptr) CHECK((ptr) == NULL) #define CHECK_NOT_NULL(ptr) CHECK((ptr) != NULL) #define ERROR_AND_RETURN(expr, ret) \ -do { \ - PLAT_LOGE(__FILE__ "(line:%d): " #expr " is false!", __LINE__); \ - return ret; \ -} while (0) - -#define CHECK_AND_RETURN(expr, ret) \ -( { \ - if (!(expr)) { \ - ERROR_AND_RETURN(expr, (ret)); \ - } \ - (expr); \ -}) - -#define CHECK_EQ_RETURN(a, b, ret) CHECK_AND_RETURN((a) == (b), ret) -#define CHECK_NE_RETURN(a, b, ret) CHECK_AND_RETURN((a) != (b), ret) -#define CHECK_GE_RETURN(a, b, ret) CHECK_AND_RETURN((a) >= (b), ret) -#define CHECK_GT_RETURN(a, b, ret) CHECK_AND_RETURN((a) > (b), ret) -#define CHECK_LE_RETURN(a, b, ret) CHECK_AND_RETURN((a) <= (b), ret) -#define CHECK_LT_RETURN(a, b, ret) CHECK_AND_RETURN((a) < (b), ret) -#define CHECK_NULL_RETURN(ptr, ret) CHECK_AND_RETURN((ptr) == NULL, ret) + do { \ + PLAT_LOGE(__FILE__ "(line:%d): " #expr " is false!", __LINE__); \ + return ret; \ + } while (0) + +#define CHECK_AND_RETURN(expr, ret) \ + do { \ + if (!(expr)) { \ + ERROR_AND_RETURN(expr, (ret)); \ + } \ + } while (0) + +#define CHECK_EQ_RETURN(a, b, ret) CHECK_AND_RETURN((a) == (b), ret) +#define CHECK_NE_RETURN(a, b, ret) CHECK_AND_RETURN((a) != (b), ret) +#define CHECK_GE_RETURN(a, b, ret) CHECK_AND_RETURN((a) >= (b), ret) +#define CHECK_GT_RETURN(a, b, ret) CHECK_AND_RETURN((a) > (b), ret) +#define CHECK_LE_RETURN(a, b, ret) CHECK_AND_RETURN((a) <= (b), ret) +#define CHECK_LT_RETURN(a, b, ret) CHECK_AND_RETURN((a) < (b), ret) +#define CHECK_NULL_RETURN(ptr, ret) CHECK_AND_RETURN((ptr) == NULL, ret) #define CHECK_NOT_NULL_RETURN(ptr, ret) CHECK_AND_RETURN((ptr) != NULL, ret) +#define LONGS_EQUAL_RETURN(x, y) \ + do { \ + int xx = (x); \ + int yy = (y); \ + if (xx != yy) { \ + HDF_LOGE(__FILE__ "(line:%d): expect:%d->" #x ", got:%d->" #y, __LINE__, xx, yy); \ + return HDF_FAILURE; \ + } \ + } while (0) + +#define CHECK_TRUE_RETURN(cond) \ + do { \ + if (cond) { \ + break; \ + } \ + HDF_LOGE(__FILE__ "(line:%d): " #cond " is false!", __LINE__); \ + return HDF_FAILURE; \ + } while (0) + +#define CHECK_FALSE_RETURN(cond) \ + do { \ + if (!(cond)) { \ + break; \ + } \ + HDF_LOGE(__FILE__ "(line:%d): " #cond " is true!", __LINE__); \ + return HDF_FAILURE; \ + } while (0) + #endif /* PLATFORM_ASSERT_H */ diff --git a/test/unittest/platform/config/can_test_config.c b/test/unittest/platform/config/can_test_config.c new file mode 100644 index 0000000000000000000000000000000000000000..d02ce22f3fb7392f406983b1219a8448dd048b35 --- /dev/null +++ b/test/unittest/platform/config/can_test_config.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2022 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 "can_test.h" +#include "device_resource_if.h" +#include "hdf_base.h" +#include "hdf_device_desc.h" +#include "hdf_log.h" + +static struct CanTestConfig g_config; + +static int32_t CanTestDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + HDF_LOGD("%s: enter!", __func__); + + if (cmd != 0) { + return HDF_ERR_NOT_SUPPORT; + } + + 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; + } + + return HDF_SUCCESS; +} + +static void CanTestSetDftConfig(struct CanTestConfig *config) +{ + config->busNum = CAN_TEST_BUS_NUM; + config->bitRate = CAN_TEST_BIT_RATE; + config->workMode = CAN_TEST_WORK_MODE; +} + +static int32_t CanTestReadConfig(struct CanTestConfig *config, const struct DeviceResourceNode *node) +{ + int32_t ret; + struct DeviceResourceIface *drsOps = NULL; + + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL) { + HDF_LOGE("%s: invalid drs ops", __func__); + return HDF_FAILURE; + } + + ret = drsOps->GetUint16(node, "bus_num", &config->busNum, CAN_TEST_BUS_NUM); + if (ret != HDF_SUCCESS) { + HDF_LOGW("%s: read bus num failed, using default ...", __func__); + } + + ret = drsOps->GetUint32(node, "bit_rate", &config->bitRate, CAN_TEST_BIT_RATE); + if (ret != HDF_SUCCESS) { + HDF_LOGW("%s: read bit rate failed, using default ...", __func__); + } + + ret = drsOps->GetUint8(node, "work_mode", &config->workMode, CAN_TEST_WORK_MODE); + if (ret != HDF_SUCCESS) { + HDF_LOGW("%s: read reg len failed, using default ...", __func__); + } + + return HDF_SUCCESS; +} + +static int32_t CanTestBind(struct HdfDeviceObject *device) +{ + int32_t ret; + static struct IDeviceIoService service; + + if (device == NULL) { + HDF_LOGE("%s: device or config is null!", __func__); + return HDF_ERR_IO; + } + + if (device->property == NULL) { + HDF_LOGI("%s: property not configed, using default", __func__); + CanTestSetDftConfig(&g_config); + } else { + ret = CanTestReadConfig(&g_config, device->property); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: read config failed", __func__); + return ret; + } + } + + service.Dispatch = CanTestDispatch; + device->service = &service; + return HDF_SUCCESS; +} + +static int32_t CanTestInit(struct HdfDeviceObject *device) +{ + (void)device; + return HDF_SUCCESS; +} + +static void CanTestRelease(struct HdfDeviceObject *device) +{ + if (device != NULL) { + device->service = NULL; + } + return; +} + +struct HdfDriverEntry g_canTestEntry = { + .moduleVersion = 1, + .Bind = CanTestBind, + .Init = CanTestInit, + .Release = CanTestRelease, + .moduleName = "PLATFORM_CAN_TEST", +}; +HDF_INIT(g_canTestEntry); diff --git a/test/unittest/platform/entry/hdf_platform_core_entry_test.c b/test/unittest/platform/entry/hdf_platform_entry_test.c similarity index 68% rename from test/unittest/platform/entry/hdf_platform_core_entry_test.c rename to test/unittest/platform/entry/hdf_platform_entry_test.c index f2c9864b7299649e5a80c00fd676a0c2d1f409e3..c6902ac1b32ba46d89d7bde723d0d3f3cbf4bb26 100644 --- a/test/unittest/platform/entry/hdf_platform_core_entry_test.c +++ b/test/unittest/platform/entry/hdf_platform_entry_test.c @@ -6,16 +6,20 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include "hdf_platform_core_entry_test.h" +#include "hdf_platform_entry_test.h" + +#include "can_test.h" #include "hdf_log.h" +#include "platform_device_test.h" +#include "platform_dumper_test.h" #include "platform_event_test.h" +#include "platform_manager_test.h" +#include "platform_queue_test.h" #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE) || defined(CONFIG_DRIVERS_HDF_PLATFORM_TRACE) #include "platform_trace_test.h" #endif -#include "platform_queue_test.h" -#include "platform_dumper_test.h" -#define HDF_LOG_TAG hdf_platform_core_entry_test +#define HDF_LOG_TAG hdf_platform_entry_test int32_t HdfPlatformEventTestEntry(HdfTestMsg *msg) { @@ -33,33 +37,51 @@ int32_t HdfPlatformQueueTestEntry(HdfTestMsg *msg) return HDF_SUCCESS; } -#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE) || defined(CONFIG_DRIVERS_HDF_PLATFORM_TRACE) -int32_t HdfPlatformTraceTestEntry(HdfTestMsg *msg) +int32_t HdfPlatformDeviceTestEntry(HdfTestMsg *msg) { - HDF_LOGD("HdfPlatformTraceTestEntry enter:"); if (msg != NULL) { - msg->result = PlatformTraceTestExecute(msg->subCmd); + msg->result = PlatformDeviceTestExecute(msg->subCmd); } return HDF_SUCCESS; } -#endif -int32_t HdfPlatformDeviceTestEntry(HdfTestMsg *msg) +int32_t HdfPlatformManagerTestEntry(HdfTestMsg *msg) { - msg->result = HDF_SUCCESS; + if (msg != NULL) { + msg->result = PlatformManagerTestExecute(msg->subCmd); + } return HDF_SUCCESS; } -int32_t HdfPlatformManagerTestEntry(HdfTestMsg *msg) +// Platform DFX Modules +int32_t HdfPlatformDumperTestEntry(HdfTestMsg *msg) { - msg->result = HDF_SUCCESS; + if (msg != NULL) { + msg->result = PlatformDumperTestExecute(msg->subCmd); + } return HDF_SUCCESS; } -int32_t HdfPlatformDumperTestEntry(HdfTestMsg *msg) +#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE) || defined(CONFIG_DRIVERS_HDF_PLATFORM_TRACE) +int32_t HdfPlatformTraceTestEntry(HdfTestMsg *msg) { + HDF_LOGD("HdfPlatformTraceTestEntry enter:"); if (msg != NULL) { - msg->result = PlatformDumperTestExecute(msg->subCmd); + msg->result = PlatformTraceTestExecute(msg->subCmd); + } + return HDF_SUCCESS; +} +#endif + +// Platform Bussiness Modules +int32_t HdfCanTestEntry(HdfTestMsg *msg) +{ + if (msg != NULL) { +#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_CAN) || defined(CONFIG_DRIVERS_HDF_PLATFORM_CAN) + msg->result = CanTestExecute(msg->subCmd); +#else + msg->result = HDF_SUCCESS; +#endif } return HDF_SUCCESS; } diff --git a/test/unittest/platform/entry/hdf_platform_core_entry_test.h b/test/unittest/platform/entry/hdf_platform_entry_test.h similarity index 86% rename from test/unittest/platform/entry/hdf_platform_core_entry_test.h rename to test/unittest/platform/entry/hdf_platform_entry_test.h index ed17129e56ec345a45cda5fea33a347f7888705b..baf0a3778c4194f4dc074acb4978cefaa08c1bd5 100644 --- a/test/unittest/platform/entry/hdf_platform_core_entry_test.h +++ b/test/unittest/platform/entry/hdf_platform_entry_test.h @@ -11,17 +11,23 @@ #include "hdf_main_test.h" +// Platform Common Models int32_t HdfPlatformEventTestEntry(HdfTestMsg *msg); int32_t HdfPlatformQueueTestEntry(HdfTestMsg *msg); -#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE) || defined(CONFIG_DRIVERS_HDF_PLATFORM_TRACE) -int32_t HdfPlatformTraceTestEntry(HdfTestMsg *msg); -#endif - int32_t HdfPlatformDeviceTestEntry(HdfTestMsg *msg); int32_t HdfPlatformManagerTestEntry(HdfTestMsg *msg); +// Platform DFX Models int32_t HdfPlatformDumperTestEntry(HdfTestMsg *msg); + +#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_TRACE) || defined(CONFIG_DRIVERS_HDF_PLATFORM_TRACE) +int32_t HdfPlatformTraceTestEntry(HdfTestMsg *msg); +#endif + +// Platform Bussiness Modules +int32_t HdfCanTestEntry(HdfTestMsg *msg); + #endif // HDF_PLATFORM_CORE_ENTRY_TEST_H