diff options
Diffstat (limited to 'test/client_test')
-rw-r--r-- | test/client_test/CMakeLists.txt | 41 | ||||
-rw-r--r-- | test/client_test/client_main.c | 47 | ||||
-rw-r--r-- | test/client_test/client_test_common.c | 101 | ||||
-rw-r--r-- | test/client_test/client_test_common.h | 24 | ||||
-rw-r--r-- | test/client_test/client_test_init_term.c | 69 | ||||
-rw-r--r-- | test/client_test/client_test_register_notify.c | 480 | ||||
-rw-r--r-- | test/client_test/client_test_shiftposition.c | 31 | ||||
-rw-r--r-- | test/client_test/client_test_speed.c | 32 | ||||
-rw-r--r-- | test/client_test/client_test_suites.h | 13 | ||||
-rw-r--r-- | test/client_test/client_test_tacho.c | 30 | ||||
-rw-r--r-- | test/client_test/client_test_telltale.c | 132 | ||||
-rw-r--r-- | test/client_test/client_test_tripcomputer.c | 68 | ||||
-rw-r--r-- | test/client_test/dummy_server.c | 176 |
13 files changed, 1244 insertions, 0 deletions
diff --git a/test/client_test/CMakeLists.txt b/test/client_test/CMakeLists.txt new file mode 100644 index 0000000..940326b --- /dev/null +++ b/test/client_test/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 2.8) + +pkg_check_modules(IPC REQUIRED ipc) + +# use the variable <RESULTNAME>_INCLUDE_DIRS to get include paths +include_directories( + ${IPC_INCLUDE_DIRS} + ../../include + ) + +# Define project Targets +set(CLIENT_TEST_BINARY_NAME client_test) +add_executable(${CLIENT_TEST_BINARY_NAME} + client_main.c + client_test_common.c + client_test_init_term.c + client_test_telltale.c + client_test_shiftposition.c + client_test_speed.c + client_test_tacho.c + client_test_tripcomputer.c + client_test_register_notify.c + ) + +# use the variable <RESULTNAME>_LIBRARIES to get library paths +target_link_libraries(${CLIENT_TEST_BINARY_NAME} + ${IPC_LIBRARIES} + ${TARGET_NAME} + pthread + cunit + ) + +# Define project Targets +set(DUMMY_SERVER_BINARY_NAME dummy_server) +add_executable(${DUMMY_SERVER_BINARY_NAME} dummy_server.c) + +target_link_libraries(${DUMMY_SERVER_BINARY_NAME} + ${IPC_LIBRARIES} + pthread + ) + diff --git a/test/client_test/client_main.c b/test/client_test/client_main.c new file mode 100644 index 0000000..aca9d55 --- /dev/null +++ b/test/client_test/client_main.c @@ -0,0 +1,47 @@ +// Test program for IC-service IPC inplementation +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <CUnit/CUnit.h> +#include <CUnit/Console.h> + +#include <ipc.h> +#include <cluster_api.h> + +#include "client_test_common.h" +#include "client_test_suites.h" + +int main(int argc, char *argv[]) +{ + pid_t child; + + setenv(IPC_ENV_DOMAIN_SOCKET_PATH, IPC_TEST_DOMAIN_PATH, 1); + + setExeFilePath(argv[0]); + if ((child = fork()) < 0) { + fprintf(stderr, "client_main:%d Failed to fork() : %d\n", __LINE__, child); + exit(EXIT_FAILURE); + } + + startDummyServer(child); + connectToDummyServer(); + + CU_initialize_registry(); + + SetTestSuiteInitAndTerm(); + SetTestSuiteTelltale(); + SetTestSuiteShiftPosition(); + SetTestSuiteSpeed(); + SetTestSuiteTacho(); + SetTestSuiteTripComputer(); + SetTestSuiteRegisterAndNotify(); + + CU_console_run_tests(); + + CU_cleanup_registry(); + + stopDummyServer(); + + return 0; +} diff --git a/test/client_test/client_test_common.c b/test/client_test/client_test_common.c new file mode 100644 index 0000000..5b71630 --- /dev/null +++ b/test/client_test/client_test_common.c @@ -0,0 +1,101 @@ +#include <stdio.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/un.h> + +#include <cluster_api.h> + +#include "client_test_common.h" + +#define CLUSTER_TEST_WAIT_TIME (10000) + +static int g_dummyServerFd = -1; +static char g_dummyServerExeFilePath[256]; + +void setExeFilePath(const char *exeFilePath) +{ + char *pCh; + + // dummy_server in the same path as client_test. + strcpy(g_dummyServerExeFilePath, exeFilePath); + pCh = strrchr(g_dummyServerExeFilePath, '/'); + pCh = pCh != NULL ? pCh + 1: g_dummyServerExeFilePath; + strcpy(pCh, "dummy_server"); +} + +void startDummyServer(pid_t child) +{ + if (child == 0) { + int rc; + char *argv[2] = {NULL, NULL}; + + argv[0] = g_dummyServerExeFilePath; + + rc = execv(argv[0], argv); + if (rc < 0) { + ERRNO_LOG(execv); + } + } + else { + usleep(CLUSTER_TEST_WAIT_TIME); + } +} + +void stopDummyServer(void) +{ + if (g_dummyServerFd >= 0) { + shutdown(g_dummyServerFd, SHUT_RDWR); + close(g_dummyServerFd); + } + unlink(CLUSTER_TEST_SENDDATA_FILE); + sleep(1); +} + +void connectToDummyServer(void) +{ + int rc; + int fd; + struct sockaddr_un unixAddr; + int len; + + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) { + ERRNO_LOG(socket); + return; + } + unixAddr.sun_family = AF_UNIX; + strcpy(unixAddr.sun_path, CLUSTER_TEST_DOMAIN_PATH); + len = sizeof(unixAddr.sun_family)+strlen(unixAddr.sun_path); + rc = connect(fd, (struct sockaddr *)&unixAddr, len); + if (rc != 0) { + ERRNO_LOG(connect); + shutdown(fd, SHUT_RDWR); + close(fd); + return; + } + + g_dummyServerFd = fd; +} + +void requestSendData(IPC_DATA_IC_SERVICE_S *pSendData) +{ + FILE *fp = NULL; + int dummy = 1; + int size; + + fp = fopen(CLUSTER_TEST_SENDDATA_FILE, "wb"); + if (fp != NULL) { + size = fwrite(pSendData, 1, sizeof(IPC_DATA_IC_SERVICE_S), fp); + if (size < sizeof(IPC_DATA_IC_SERVICE_S)) { + ERRNO_LOG(fwrite); + } + fclose(fp); + + size = write(g_dummyServerFd, &dummy, sizeof(dummy)); + if (size < 0) { + ERRNO_LOG(write); + } + usleep(CLUSTER_TEST_WAIT_TIME); + } +} + diff --git a/test/client_test/client_test_common.h b/test/client_test/client_test_common.h new file mode 100644 index 0000000..36a990f --- /dev/null +++ b/test/client_test/client_test_common.h @@ -0,0 +1,24 @@ +#ifndef CLIENT_TEST_COMMON_H +#define CLIENT_TEST_COMMON_H + +#include <unistd.h> +#include <ipc.h> + +#define IPC_TEST_DOMAIN_PATH "./" + +#define CLUSTER_TEST_DOMAIN_PATH "cluster_test_domain" +#define CLUSTER_TEST_SENDDATA_FILE "cluster_test.dat" + +#define ERRNO_LOG(func) \ + do { \ + perror(#func "()"); \ + fprintf(stderr, "%s:%d Failed to %s()\n", __FILE__, __LINE__, #func); \ + }while(0) + +void setExeFilePath(const char *exeFilePath); +void startDummyServer(pid_t child); +void stopDummyServer(void); +void connectToDummyServer(void); +void requestSendData(IPC_DATA_IC_SERVICE_S *pSendData); + +#endif // CLIENT_TEST_COMMON_H diff --git a/test/client_test/client_test_init_term.c b/test/client_test/client_test_init_term.c new file mode 100644 index 0000000..00f2f13 --- /dev/null +++ b/test/client_test/client_test_init_term.c @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <CUnit/CUnit.h> + +#include <cluster_api.h> + +#include "client_test_common.h" + +// OK case. Calling the APIs of Init and Term while the server is already started. +static void TestInitAndTermOK(void) +{ + CU_ASSERT(clusterInit() == true); + CU_ASSERT(clusterTerm() == true); +} + +// NG case. Call the API of Init function twice. +static void TestInitAndTermNG1(void) +{ + CU_ASSERT(clusterInit() == true); + CU_ASSERT(clusterInit() == false); + CU_ASSERT(clusterTerm() == true); +} + +// NG case. Call the API of Term function twice. +static void TestInitAndTermNG2(void) +{ + CU_ASSERT(clusterInit() == true); + CU_ASSERT(clusterTerm() == true); + CU_ASSERT(clusterTerm() == false); +} + +// NG case. Call the API of Term only. +static void TestInitAndTermNG3(void) +{ + CU_ASSERT(clusterTerm() == false); +} + +// NG case. Server is not ready. +static void TestInitAndTermNG4(void) +{ + pid_t child; + + stopDummyServer(); + CU_ASSERT(clusterInit() == false); + CU_ASSERT(clusterTerm() == false); + + if ((child = fork()) < 0) { + fprintf(stderr, "%s:%d Failed to fork() : %d\n", __FILE__, __LINE__, child); + exit(EXIT_FAILURE); + } + + startDummyServer(child); + connectToDummyServer(); +} + +void SetTestSuiteInitAndTerm(void) +{ + CU_pSuite testSuite; + + testSuite = CU_add_suite("InitAndTerm", NULL, NULL); + CU_add_test(testSuite, "InitAndTerm_OK", TestInitAndTermOK); + CU_add_test(testSuite, "InitAndTerm_NG_1", TestInitAndTermNG1); + CU_add_test(testSuite, "InitAndTerm_NG_2", TestInitAndTermNG2); + CU_add_test(testSuite, "InitAndTerm_NG_3", TestInitAndTermNG3); + CU_add_test(testSuite, "InitAndTerm_NG_4", TestInitAndTermNG4); +} + diff --git a/test/client_test/client_test_register_notify.c b/test/client_test/client_test_register_notify.c new file mode 100644 index 0000000..2458e73 --- /dev/null +++ b/test/client_test/client_test_register_notify.c @@ -0,0 +1,480 @@ +#include <string.h> +#include <stdbool.h> + +#include <CUnit/CUnit.h> + +#include <cluster_api.h> + +#include "client_test_common.h" + +typedef struct { + IC_HMI_ON_OFF value; + bool isCallbacked; + const unsigned long long flag; + const char *name; +} CLUSTER_TEST_CB_STORE_TABLE_S; + +#define CLUSTER_TEST_DECLARE_STORE_UNIT(flag) \ + {IC_HMI_OFF, false, flag, #flag} + +static CLUSTER_TEST_CB_STORE_TABLE_S g_cbStoreTable[] = { + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_TURN_R), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_TURN_L), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_BRAKE), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_SEATBELT), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_HIGHBEAM), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_DOOR), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_EPS), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_SRS_AIRBAG), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_ABS), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_LOW_BATTERY), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_OIL_PRESS), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_ENGINE), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_FUEL), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_IMMOBI), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_TM_FAIL), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_ESP_ACT), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_ESP_OFF), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_ADAPTING_LIGHTING), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_AUTO_STOP), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_AUTO_STOP_FAIL), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_PARKING_LIGHTS), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_FRONT_FOG), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_EXTERIOR_LIGHT_FAULT), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_ACC_FAIL), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_LDW_OFF), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_HILL_DESCENT), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_AUTO_HI_BEAM_GREEN), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_AUTO_HI_BEAM_AMBER), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_LDW_OPERATE), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_GENERAL_WARN), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_SPORTS_MODE), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_DRIVING_POWER_MODE), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_HOT_TEMP), + CLUSTER_TEST_DECLARE_STORE_UNIT(IC_HMI_TT_LOW_TEMP) +}; + +static bool g_isCalledCallback = false; + +#define CLUSTER_TEST_STORE_TABLE_SIZE (sizeof(g_cbStoreTable)/sizeof(g_cbStoreTable[0])) + +static void cleanStoreTable(void) +{ + int i; + + for (i = 0; i < CLUSTER_TEST_STORE_TABLE_SIZE; i++) { + g_cbStoreTable[i].value = 0; + g_cbStoreTable[i].isCallbacked = false; + } +} + +static bool checkValueFromStoreTable(const unsigned long long flag, + const bool expectedIsCallbacked, + const IC_HMI_ON_OFF expectedOnOff) +{ + bool ret = true; + int i; + + for (i = 0; i < CLUSTER_TEST_STORE_TABLE_SIZE; i++) { + if (flag == g_cbStoreTable[i].flag) { + if (g_cbStoreTable[i].isCallbacked != expectedIsCallbacked) { + ret = false; + fprintf(stderr, "%s:%d [%s] isCallbacked == %d is false\n", __FILE__, __LINE__, g_cbStoreTable[i].name, expectedIsCallbacked); + } + + if (expectedIsCallbacked == true && g_cbStoreTable[i].value != expectedOnOff) { + ret = false; + fprintf(stderr, "%s:%d [%s] value == %d is false\n", __FILE__, __LINE__, g_cbStoreTable[i].name, expectedOnOff); + } + return ret; + } + } + + return false; +} + +static void sendDataAllSet(IPC_DATA_IC_SERVICE_S *pSendData, IC_HMI_ON_OFF onOff) +{ + pSendData->turnR = onOff; + pSendData->turnL = onOff; + pSendData->brake = onOff; + pSendData->seatbelt = onOff; + pSendData->highbeam = onOff; + pSendData->door = onOff; + pSendData->eps = onOff; + pSendData->srsAirbag = onOff; + pSendData->abs = onOff; + pSendData->lowBattery = onOff; + pSendData->oilPress = onOff; + pSendData->engine = onOff; + pSendData->fuel = onOff; + pSendData->immobi = onOff; + pSendData->tmFail = onOff; + pSendData->espAct = onOff; + pSendData->espOff = onOff; + pSendData->adaptingLighting = onOff; + pSendData->autoStop = onOff; + pSendData->autoStopFail = onOff; + pSendData->parkingLights = onOff; + pSendData->frontFog = onOff; + pSendData->exteriorLightFault = onOff; + pSendData->accFail = onOff; + pSendData->ldwOff = onOff; + pSendData->hillDescent = onOff; + pSendData->autoHiBeamGreen = onOff; + pSendData->autoHiBeamAmber = onOff; + pSendData->ldwOperate = onOff; + pSendData->generalWarn = onOff; + pSendData->sportsMode = onOff; + pSendData->drivingPowerMode = onOff; + pSendData->hotTemp = onOff; + pSendData->lowTemp = onOff; +} + +static void notifyIcHmi(unsigned long long arg_1, IC_HMI_ON_OFF arg_2) +{ + int i; + + g_isCalledCallback = true; + + for (i = 0; i < sizeof(g_cbStoreTable) / sizeof(g_cbStoreTable[0]); i++) { + if ((arg_1 & g_cbStoreTable[i].flag) == g_cbStoreTable[i].flag) { + g_cbStoreTable[i].value = arg_2; + g_cbStoreTable[i].isCallbacked = true; + } + } +} + +static void TestregisterIcHmi_ALL_DifferentData() { + unsigned long long arg_1; + IPC_DATA_IC_SERVICE_S sendData; + int i; + + CU_ASSERT(clusterInit() == true); + + cleanStoreTable(); + g_isCalledCallback = false; + + arg_1 = IC_HMI_TT_ALL; + CU_ASSERT(registerIcHmi(arg_1, notifyIcHmi) == true); + + CU_ASSERT(g_isCalledCallback == false); + + memset(&sendData, 0x00, sizeof(sendData)); + sendDataAllSet(&sendData, IC_HMI_ON); + requestSendData(&sendData); + + CU_ASSERT(g_isCalledCallback == true); + for (i = 0; i < CLUSTER_TEST_STORE_TABLE_SIZE; i++) { + CU_ASSERT(checkValueFromStoreTable(g_cbStoreTable[i].flag, true, IC_HMI_ON) == true); + } + + g_isCalledCallback = false; + sendDataAllSet(&sendData, IC_HMI_OFF); + requestSendData(&sendData); + + CU_ASSERT(g_isCalledCallback == true); + for (i = 0; i < CLUSTER_TEST_STORE_TABLE_SIZE; i++) { + CU_ASSERT(checkValueFromStoreTable(g_cbStoreTable[i].flag, true, IC_HMI_OFF) == true); + } + + CU_ASSERT(clusterTerm() == true); +} + +static void TestregisterIcHmi_ALL_SameData() { + unsigned long long arg_1; + IPC_DATA_IC_SERVICE_S sendData; + + CU_ASSERT(clusterInit() == true); + + cleanStoreTable(); + g_isCalledCallback = false; + + arg_1 = IC_HMI_TT_ALL; + CU_ASSERT(registerIcHmi(arg_1, notifyIcHmi) == true); + + CU_ASSERT(g_isCalledCallback == false); + + // Send the data "different" from initial value. + memset(&sendData, 0x00, sizeof(sendData)); + sendDataAllSet(&sendData, IC_HMI_OFF); + requestSendData(&sendData); + + CU_ASSERT(g_isCalledCallback == false); + + g_isCalledCallback = false; + sendDataAllSet(&sendData, IC_HMI_OFF); + requestSendData(&sendData); + + CU_ASSERT(g_isCalledCallback == false); + + CU_ASSERT(clusterTerm() == true); +} + +static void TestregisterIcHmi_NullFunc() { + unsigned long long arg_1; + + CU_ASSERT(clusterInit() == true); + + arg_1 = IC_HMI_TT_ALL; + CU_ASSERT(registerIcHmi(arg_1, NULL) == false); + + CU_ASSERT(clusterTerm() == true); +} + +static void TestregisterIcHmi_ALL_OFF() { + unsigned long long arg_1; + IPC_DATA_IC_SERVICE_S sendData; + + CU_ASSERT(clusterInit() == true); + + cleanStoreTable(); + g_isCalledCallback = false; + + arg_1 = 0ULL; + CU_ASSERT(registerIcHmi(arg_1, notifyIcHmi) == true); + + CU_ASSERT(g_isCalledCallback == false); + + memset(&sendData, 0x00, sizeof(sendData)); + sendDataAllSet(&sendData, IC_HMI_ON); + requestSendData(&sendData); + + CU_ASSERT(g_isCalledCallback == false); + + g_isCalledCallback = false; + sendDataAllSet(&sendData, IC_HMI_OFF); + requestSendData(&sendData); + + CU_ASSERT(g_isCalledCallback == false); + + CU_ASSERT(clusterTerm() == true); +} + +static void TestregisterIcHmi_ALL_UnrelatedParams(void) +{ + unsigned long long arg_1; + IPC_DATA_IC_SERVICE_S sendData; + + CU_ASSERT(clusterInit() == true); + + cleanStoreTable(); + g_isCalledCallback = false; + + arg_1 = IC_HMI_TT_ALL; + CU_ASSERT(registerIcHmi(arg_1, notifyIcHmi) == true); + + CU_ASSERT(g_isCalledCallback == false); + + memset(&sendData, 0x01, sizeof(sendData)); + sendDataAllSet(&sendData, IC_HMI_OFF); + requestSendData(&sendData); + + CU_ASSERT(g_isCalledCallback == false); + + g_isCalledCallback = false; + memset(&sendData, 0x00, sizeof(sendData)); + sendDataAllSet(&sendData, IC_HMI_OFF); + requestSendData(&sendData); + + CU_ASSERT(g_isCalledCallback == false); + + CU_ASSERT(clusterTerm() == true); +} + +static void TestregisterIcHmi_Set_UnusedFlag(void) +{ + unsigned long long arg_1; + IPC_DATA_IC_SERVICE_S sendData; + int i; + + CU_ASSERT(clusterInit() == true); + + cleanStoreTable(); + g_isCalledCallback = false; + + arg_1 = IC_HMI_TT_ALL; + for (i = 0; i < CLUSTER_TEST_STORE_TABLE_SIZE; i++) { + arg_1 &= ~(g_cbStoreTable[i].flag); + } + CU_ASSERT(registerIcHmi(arg_1, notifyIcHmi) == true); + + CU_ASSERT(g_isCalledCallback == false); + + memset(&sendData, 0x00, sizeof(sendData)); + sendDataAllSet(&sendData, IC_HMI_ON); + requestSendData(&sendData); + + CU_ASSERT(g_isCalledCallback == false); + + g_isCalledCallback = false; + sendDataAllSet(&sendData, IC_HMI_OFF); + requestSendData(&sendData); + + CU_ASSERT(g_isCalledCallback == false); + + CU_ASSERT(clusterTerm() == true); +} + +#define REGISTER_NOTIFY_TEST_FUNC(flag, param) \ + static void TestregisterIcHmi_ON_ ##flag(void) \ + { \ + unsigned long long arg_1; \ + IPC_DATA_IC_SERVICE_S sendData; \ + \ + CU_ASSERT(clusterInit() == true); \ + \ + cleanStoreTable(); \ + g_isCalledCallback = false; \ + \ + arg_1 = IC_HMI_ ##flag; \ + CU_ASSERT(registerIcHmi(arg_1, notifyIcHmi) == true); \ + \ + CU_ASSERT(g_isCalledCallback == false); \ + \ + memset(&sendData, 0x00, sizeof(sendData)); \ + sendDataAllSet(&sendData, IC_HMI_ON); \ + sendData.param = IC_HMI_OFF; \ + requestSendData(&sendData); \ + \ + CU_ASSERT(g_isCalledCallback == false); \ + \ + g_isCalledCallback = false; \ + sendData.param = IC_HMI_ON; \ + requestSendData(&sendData); \ + \ + CU_ASSERT(g_isCalledCallback == true); \ + CU_ASSERT(checkValueFromStoreTable(IC_HMI_ ##flag, true, IC_HMI_ON) == true); \ + \ + g_isCalledCallback = false; \ + sendData.param = IC_HMI_OFF; \ + requestSendData(&sendData); \ + \ + CU_ASSERT(g_isCalledCallback == true); \ + CU_ASSERT(checkValueFromStoreTable(IC_HMI_ ##flag, true, IC_HMI_OFF) == true); \ + \ + CU_ASSERT(clusterTerm() == true); \ + } \ + static void TestregisterIcHmi_OFF_ ##flag(void) \ + { \ + unsigned long long arg_1; \ + IPC_DATA_IC_SERVICE_S sendData; \ + \ + CU_ASSERT(clusterInit() == true); \ + \ + cleanStoreTable(); \ + g_isCalledCallback = false; \ + \ + arg_1 = IC_HMI_TT_ALL & ~IC_HMI_ ##flag; \ + CU_ASSERT(registerIcHmi(arg_1, notifyIcHmi) == true); \ + \ + CU_ASSERT(g_isCalledCallback == false); \ + \ + memset(&sendData, 0x00, sizeof(sendData)); \ + sendDataAllSet(&sendData, IC_HMI_OFF); \ + sendData.param = IC_HMI_ON; \ + requestSendData(&sendData); \ + \ + CU_ASSERT(g_isCalledCallback == false); \ + \ + g_isCalledCallback = false; \ + sendData.param = IC_HMI_OFF; \ + requestSendData(&sendData); \ + \ + CU_ASSERT(g_isCalledCallback == false); \ + \ + g_isCalledCallback = false; \ + sendDataAllSet(&sendData, IC_HMI_ON); \ + requestSendData(&sendData); \ + \ + CU_ASSERT(g_isCalledCallback == true); \ + CU_ASSERT(checkValueFromStoreTable(IC_HMI_ ##flag, false, IC_HMI_OFF) == true); \ + \ + CU_ASSERT(clusterTerm() == true); \ + } + +#define REGISTER_NOTIFY_ADD_TEST(testSuite, flag) \ + CU_add_test(testSuite, "registerIcHmi_ON_" #flag, TestregisterIcHmi_ON_ ##flag); \ + CU_add_test(testSuite, "registerIcHmi_OFF_" #flag, TestregisterIcHmi_OFF_ ##flag) + +REGISTER_NOTIFY_TEST_FUNC(TT_TURN_R, turnR) +REGISTER_NOTIFY_TEST_FUNC(TT_TURN_L, turnL) +REGISTER_NOTIFY_TEST_FUNC(TT_BRAKE, brake) +REGISTER_NOTIFY_TEST_FUNC(TT_SEATBELT, seatbelt) +REGISTER_NOTIFY_TEST_FUNC(TT_HIGHBEAM, highbeam) +REGISTER_NOTIFY_TEST_FUNC(TT_DOOR, door) +REGISTER_NOTIFY_TEST_FUNC(TT_EPS, eps) +REGISTER_NOTIFY_TEST_FUNC(TT_SRS_AIRBAG, srsAirbag) +REGISTER_NOTIFY_TEST_FUNC(TT_ABS, abs) +REGISTER_NOTIFY_TEST_FUNC(TT_LOW_BATTERY, lowBattery) +REGISTER_NOTIFY_TEST_FUNC(TT_OIL_PRESS, oilPress) +REGISTER_NOTIFY_TEST_FUNC(TT_ENGINE, engine) +REGISTER_NOTIFY_TEST_FUNC(TT_FUEL, fuel) +REGISTER_NOTIFY_TEST_FUNC(TT_IMMOBI, immobi) +REGISTER_NOTIFY_TEST_FUNC(TT_TM_FAIL, tmFail) +REGISTER_NOTIFY_TEST_FUNC(TT_ESP_ACT, espAct) +REGISTER_NOTIFY_TEST_FUNC(TT_ESP_OFF, espOff) +REGISTER_NOTIFY_TEST_FUNC(TT_ADAPTING_LIGHTING, adaptingLighting) +REGISTER_NOTIFY_TEST_FUNC(TT_AUTO_STOP, autoStop) +REGISTER_NOTIFY_TEST_FUNC(TT_AUTO_STOP_FAIL, autoStopFail) +REGISTER_NOTIFY_TEST_FUNC(TT_PARKING_LIGHTS, parkingLights) +REGISTER_NOTIFY_TEST_FUNC(TT_FRONT_FOG, frontFog) +REGISTER_NOTIFY_TEST_FUNC(TT_EXTERIOR_LIGHT_FAULT, exteriorLightFault) +REGISTER_NOTIFY_TEST_FUNC(TT_ACC_FAIL, accFail) +REGISTER_NOTIFY_TEST_FUNC(TT_LDW_OFF, ldwOff) +REGISTER_NOTIFY_TEST_FUNC(TT_HILL_DESCENT, hillDescent) +REGISTER_NOTIFY_TEST_FUNC(TT_AUTO_HI_BEAM_GREEN, autoHiBeamGreen) +REGISTER_NOTIFY_TEST_FUNC(TT_AUTO_HI_BEAM_AMBER, autoHiBeamAmber) +REGISTER_NOTIFY_TEST_FUNC(TT_LDW_OPERATE, ldwOperate) +REGISTER_NOTIFY_TEST_FUNC(TT_GENERAL_WARN, generalWarn) +REGISTER_NOTIFY_TEST_FUNC(TT_SPORTS_MODE, sportsMode) +REGISTER_NOTIFY_TEST_FUNC(TT_DRIVING_POWER_MODE, drivingPowerMode) +REGISTER_NOTIFY_TEST_FUNC(TT_HOT_TEMP, hotTemp) +REGISTER_NOTIFY_TEST_FUNC(TT_LOW_TEMP, lowTemp) + +void SetTestSuiteRegisterAndNotify(void) +{ + CU_pSuite testSuite; + + testSuite = CU_add_suite("RegisterAndNotify", NULL, NULL); + CU_add_test(testSuite, "registerIcHmi_ALL_DifferentData", TestregisterIcHmi_ALL_DifferentData); + CU_add_test(testSuite, "registerIcHmi_ALL_SameData", TestregisterIcHmi_ALL_SameData); + CU_add_test(testSuite, "registerIcHmi_ALL_UnrelatedParams", TestregisterIcHmi_ALL_UnrelatedParams); + CU_add_test(testSuite, "registerIcHmi_ALL_OFF", TestregisterIcHmi_ALL_OFF); + CU_add_test(testSuite, "registerIcHmi_Set_UnusedFlag", TestregisterIcHmi_Set_UnusedFlag); + CU_add_test(testSuite, "registerIcHmi_NullFunc", TestregisterIcHmi_NullFunc); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_TURN_R); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_TURN_L); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_BRAKE); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_SEATBELT); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_HIGHBEAM); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_DOOR); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_EPS); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_SRS_AIRBAG); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_ABS); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_LOW_BATTERY); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_OIL_PRESS); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_ENGINE); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_FUEL); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_IMMOBI); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_TM_FAIL); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_ESP_ACT); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_ESP_OFF); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_ADAPTING_LIGHTING); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_AUTO_STOP); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_AUTO_STOP_FAIL); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_PARKING_LIGHTS); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_FRONT_FOG); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_EXTERIOR_LIGHT_FAULT); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_ACC_FAIL); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_LDW_OFF); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_HILL_DESCENT); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_AUTO_HI_BEAM_GREEN); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_AUTO_HI_BEAM_AMBER); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_LDW_OPERATE); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_GENERAL_WARN); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_SPORTS_MODE); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_DRIVING_POWER_MODE); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_HOT_TEMP); + REGISTER_NOTIFY_ADD_TEST(testSuite, TT_LOW_TEMP); +} diff --git a/test/client_test/client_test_shiftposition.c b/test/client_test/client_test_shiftposition.c new file mode 100644 index 0000000..ead199c --- /dev/null +++ b/test/client_test/client_test_shiftposition.c @@ -0,0 +1,31 @@ +#include <CUnit/CUnit.h> + +#include <cluster_api.h> + +#include "client_test_common.h" + +#define SHIFTPOSITION_TEST_FUNC(func, param, value) \ + static void Test ##func() { \ + IPC_DATA_IC_SERVICE_S sendData; \ + CU_ASSERT(clusterInit() == true); \ + memset(&sendData, 0x00, sizeof(sendData)); \ + sendData.param = value; \ + requestSendData(&sendData); \ + CU_ASSERT(func() == value); \ + CU_ASSERT(clusterTerm() == true); \ + } + +#define SHIFTPOSITION_ADD_TEST(testSuite, func) \ + CU_add_test(testSuite, #func, Test ##func) + +SHIFTPOSITION_TEST_FUNC(getGearAtVal, gearAtVal, IC_HMI_AT_UNUSED) +SHIFTPOSITION_TEST_FUNC(getGearMtVal, gearMtVal, IC_HMI_MT_EIGHTTH) + +void SetTestSuiteShiftPosition(void) +{ + CU_pSuite testSuite; + + testSuite = CU_add_suite("ShiftPosition", NULL, NULL); + SHIFTPOSITION_ADD_TEST(testSuite, getGearAtVal); + SHIFTPOSITION_ADD_TEST(testSuite, getGearMtVal); +} diff --git a/test/client_test/client_test_speed.c b/test/client_test/client_test_speed.c new file mode 100644 index 0000000..c30e2e2 --- /dev/null +++ b/test/client_test/client_test_speed.c @@ -0,0 +1,32 @@ +#include <CUnit/CUnit.h> + +#include <cluster_api.h> + +#include "client_test_common.h" + +#define SPEED_TEST_FUNC(func, param, value) \ + static void Test ##func() { \ + IPC_DATA_IC_SERVICE_S sendData; \ + CU_ASSERT(clusterInit() == true); \ + memset(&sendData, 0x00, sizeof(sendData)); \ + sendData.param = value; \ + requestSendData(&sendData); \ + CU_ASSERT(func() == value); \ + CU_ASSERT(clusterTerm() == true); \ + } + +#define SPEED_ADD_TEST(testSuite, func) \ + CU_add_test(testSuite, #func, Test ##func) + +SPEED_TEST_FUNC(getSpAnalogVal, spAnalogVal, 0x00007530) +SPEED_TEST_FUNC(getSpAnaDigUnitVal, spAnaDigUnitVal, IC_HMI_SP_MPH) + +void SetTestSuiteSpeed(void) +{ + CU_pSuite testSuite; + + testSuite = CU_add_suite("Speed", NULL, NULL); + SPEED_ADD_TEST(testSuite, getSpAnalogVal); + SPEED_ADD_TEST(testSuite, getSpAnaDigUnitVal); +} + diff --git a/test/client_test/client_test_suites.h b/test/client_test/client_test_suites.h new file mode 100644 index 0000000..8306944 --- /dev/null +++ b/test/client_test/client_test_suites.h @@ -0,0 +1,13 @@ +#ifndef CLIENT_TEST_SUITES_H +#define CLIENT_TEST_SUITES_H + +void SetTestSuiteInitAndTerm(void); +void SetTestSuiteTelltale(void); +void SetTestSuiteShiftPosition(void); +void SetTestSuiteSpeed(void); +void SetTestSuiteTacho(void); +void SetTestSuiteTripComputer(void); +void SetTestSuiteRegisterAndNotify(void); + +#endif // CLIENT_TEST_SUITES_H + diff --git a/test/client_test/client_test_tacho.c b/test/client_test/client_test_tacho.c new file mode 100644 index 0000000..97b39e5 --- /dev/null +++ b/test/client_test/client_test_tacho.c @@ -0,0 +1,30 @@ +#include <CUnit/CUnit.h> + +#include <cluster_api.h> + +#include "client_test_common.h" + +#define TACHO_TEST_FUNC(func, param, value) \ + static void Test ##func() { \ + IPC_DATA_IC_SERVICE_S sendData; \ + CU_ASSERT(clusterInit() == true); \ + memset(&sendData, 0x00, sizeof(sendData)); \ + sendData.param = value; \ + requestSendData(&sendData); \ + CU_ASSERT(func() == value); \ + CU_ASSERT(clusterTerm() == true); \ + } + +#define TACHO_ADD_TEST(testSuite, func) \ + CU_add_test(testSuite, #func, Test ##func) + +TACHO_TEST_FUNC(getTaAnalogVal, taAnalogVal, 0x00004E20) + +void SetTestSuiteTacho(void) +{ + CU_pSuite testSuite; + + testSuite = CU_add_suite("Tacho", NULL, NULL); + TACHO_ADD_TEST(testSuite, getTaAnalogVal); +} + diff --git a/test/client_test/client_test_telltale.c b/test/client_test/client_test_telltale.c new file mode 100644 index 0000000..b5dd14a --- /dev/null +++ b/test/client_test/client_test_telltale.c @@ -0,0 +1,132 @@ +#include <CUnit/CUnit.h> + +#include <cluster_api.h> + +#include "client_test_common.h" + +#define TELLTALE_TEST_FUNC(func, param) \ + static void Test ##func() { \ + IPC_DATA_IC_SERVICE_S sendData; \ + CU_ASSERT(clusterInit() == true); \ + memset(&sendData, 0x00, sizeof(sendData)); \ + sendData.param = IC_HMI_ON; \ + requestSendData(&sendData); \ + CU_ASSERT(func() == IC_HMI_ON); \ + CU_ASSERT(clusterTerm() == true); \ + } + +#define TELLTALE_ADD_TEST(testSuite, func) \ + CU_add_test(testSuite, #func, Test ##func) + +TELLTALE_TEST_FUNC(getTurnR, turnR) +TELLTALE_TEST_FUNC(getTurnL, turnL) +TELLTALE_TEST_FUNC(getBrake, brake) +TELLTALE_TEST_FUNC(getSeatbelt, seatbelt) +TELLTALE_TEST_FUNC(getFrontRightSeatbelt, frontRightSeatbelt) +TELLTALE_TEST_FUNC(getFrontCenterSeatbelt, frontCenterSeatbelt) +TELLTALE_TEST_FUNC(getFrontLeftSeatbelt, frontLeftSeatbelt) +TELLTALE_TEST_FUNC(getMid1RightSeatbelt, mid1RightSeatbelt) +TELLTALE_TEST_FUNC(getMid1CenterSeatbelt, mid1CenterSeatbelt) +TELLTALE_TEST_FUNC(getMid1LeftSeatbelt, mid1LeftSeatbelt) +TELLTALE_TEST_FUNC(getMid2RightSeatbelt, mid2RightSeatbelt) +TELLTALE_TEST_FUNC(getMid2CenterSeatbelt, mid2CenterSeatbelt) +TELLTALE_TEST_FUNC(getMid2LeftSeatbelt, mid2LeftSeatbelt) +TELLTALE_TEST_FUNC(getRearRightSeatbelt, rearRightSeatbelt) +TELLTALE_TEST_FUNC(getRearCenterSeatbelt, rearCenterSeatbelt) +TELLTALE_TEST_FUNC(getRearLeftSeatbelt, rearLeftSeatbelt) +TELLTALE_TEST_FUNC(getHighbeam, highbeam) +TELLTALE_TEST_FUNC(getDoor, door) +TELLTALE_TEST_FUNC(getFrontRightDoor, frontRightDoor) +TELLTALE_TEST_FUNC(getFrontLeftDoor, frontLeftDoor) +TELLTALE_TEST_FUNC(getRearRightDoor, rearRightDoor) +TELLTALE_TEST_FUNC(getRearLeftDoor, rearLeftDoor) +TELLTALE_TEST_FUNC(getTrunkDoor, trunkDoor) +TELLTALE_TEST_FUNC(getHoodDoor, hoodDoor) +TELLTALE_TEST_FUNC(getEps, eps) +TELLTALE_TEST_FUNC(getSrsAirbag, srsAirbag) +TELLTALE_TEST_FUNC(getAbs, abs) +TELLTALE_TEST_FUNC(getLowBattery, lowBattery) +TELLTALE_TEST_FUNC(getOilPress, oilPress) +TELLTALE_TEST_FUNC(getEngine, engine) +TELLTALE_TEST_FUNC(getFuel, fuel) +TELLTALE_TEST_FUNC(getImmobi, immobi) +TELLTALE_TEST_FUNC(getTMFail, tmFail) +TELLTALE_TEST_FUNC(getEspAct, espAct) +TELLTALE_TEST_FUNC(getEspOff, espOff) +TELLTALE_TEST_FUNC(getAdaptingLighting, adaptingLighting) +TELLTALE_TEST_FUNC(getAutoStop, autoStop) +TELLTALE_TEST_FUNC(getAutoStopFail, autoStopFail) +TELLTALE_TEST_FUNC(getParkingLights, parkingLights) +TELLTALE_TEST_FUNC(getFrontFog, frontFog) +TELLTALE_TEST_FUNC(getExteriorLightFault, exteriorLightFault) +TELLTALE_TEST_FUNC(getAccFail, accFail) +TELLTALE_TEST_FUNC(getLdwOff, ldwOff) +TELLTALE_TEST_FUNC(getHillDescent, hillDescent) +TELLTALE_TEST_FUNC(getAutoHiBeamGreen, autoHiBeamGreen) +TELLTALE_TEST_FUNC(getAutoHiBeamAmber, autoHiBeamAmber) +TELLTALE_TEST_FUNC(getSportsMode, sportsMode) +TELLTALE_TEST_FUNC(getLdwOperate, ldwOperate) +TELLTALE_TEST_FUNC(getGeneralWarn, generalWarn) +TELLTALE_TEST_FUNC(getDriverPowerMode, drivingPowerMode) +TELLTALE_TEST_FUNC(getHotTemp, hotTemp) +TELLTALE_TEST_FUNC(getLowTemp, lowTemp) + +void SetTestSuiteTelltale(void) +{ + CU_pSuite testSuite; + + testSuite = CU_add_suite("Telltale", NULL, NULL); + TELLTALE_ADD_TEST(testSuite, getTurnR); + TELLTALE_ADD_TEST(testSuite, getTurnL); + TELLTALE_ADD_TEST(testSuite, getBrake); + TELLTALE_ADD_TEST(testSuite, getSeatbelt); + TELLTALE_ADD_TEST(testSuite, getFrontRightSeatbelt); + TELLTALE_ADD_TEST(testSuite, getFrontCenterSeatbelt); + TELLTALE_ADD_TEST(testSuite, getFrontLeftSeatbelt); + TELLTALE_ADD_TEST(testSuite, getMid1RightSeatbelt); + TELLTALE_ADD_TEST(testSuite, getMid1CenterSeatbelt); + TELLTALE_ADD_TEST(testSuite, getMid1LeftSeatbelt); + TELLTALE_ADD_TEST(testSuite, getMid2RightSeatbelt); + TELLTALE_ADD_TEST(testSuite, getMid2CenterSeatbelt); + TELLTALE_ADD_TEST(testSuite, getMid2LeftSeatbelt); + TELLTALE_ADD_TEST(testSuite, getRearRightSeatbelt); + TELLTALE_ADD_TEST(testSuite, getRearCenterSeatbelt); + TELLTALE_ADD_TEST(testSuite, getRearLeftSeatbelt); + TELLTALE_ADD_TEST(testSuite, getHighbeam); + TELLTALE_ADD_TEST(testSuite, getDoor); + TELLTALE_ADD_TEST(testSuite, getFrontRightDoor); + TELLTALE_ADD_TEST(testSuite, getFrontLeftDoor); + TELLTALE_ADD_TEST(testSuite, getRearRightDoor); + TELLTALE_ADD_TEST(testSuite, getRearLeftDoor); + TELLTALE_ADD_TEST(testSuite, getTrunkDoor); + TELLTALE_ADD_TEST(testSuite, getHoodDoor); + TELLTALE_ADD_TEST(testSuite, getEps); + TELLTALE_ADD_TEST(testSuite, getSrsAirbag); + TELLTALE_ADD_TEST(testSuite, getAbs); + TELLTALE_ADD_TEST(testSuite, getLowBattery); + TELLTALE_ADD_TEST(testSuite, getOilPress); + TELLTALE_ADD_TEST(testSuite, getEngine); + TELLTALE_ADD_TEST(testSuite, getFuel); + TELLTALE_ADD_TEST(testSuite, getImmobi); + TELLTALE_ADD_TEST(testSuite, getTMFail); + TELLTALE_ADD_TEST(testSuite, getEspAct); + TELLTALE_ADD_TEST(testSuite, getEspOff); + TELLTALE_ADD_TEST(testSuite, getAdaptingLighting); + TELLTALE_ADD_TEST(testSuite, getAutoStop); + TELLTALE_ADD_TEST(testSuite, getAutoStopFail); + TELLTALE_ADD_TEST(testSuite, getParkingLights); + TELLTALE_ADD_TEST(testSuite, getFrontFog); + TELLTALE_ADD_TEST(testSuite, getExteriorLightFault); + TELLTALE_ADD_TEST(testSuite, getAccFail); + TELLTALE_ADD_TEST(testSuite, getLdwOff); + TELLTALE_ADD_TEST(testSuite, getHillDescent); + TELLTALE_ADD_TEST(testSuite, getAutoHiBeamGreen); + TELLTALE_ADD_TEST(testSuite, getAutoHiBeamAmber); + TELLTALE_ADD_TEST(testSuite, getSportsMode); + TELLTALE_ADD_TEST(testSuite, getLdwOperate); + TELLTALE_ADD_TEST(testSuite, getGeneralWarn); + TELLTALE_ADD_TEST(testSuite, getDriverPowerMode); + TELLTALE_ADD_TEST(testSuite, getHotTemp); + TELLTALE_ADD_TEST(testSuite, getLowTemp); +} + diff --git a/test/client_test/client_test_tripcomputer.c b/test/client_test/client_test_tripcomputer.c new file mode 100644 index 0000000..a352230 --- /dev/null +++ b/test/client_test/client_test_tripcomputer.c @@ -0,0 +1,68 @@ +#include <CUnit/CUnit.h> + +#include <cluster_api.h> + +#include "client_test_common.h" + +#define TRIPCOMPUTER_TEST_FUNC(func, param, value) \ + static void Test ##func() { \ + IPC_DATA_IC_SERVICE_S sendData; \ + CU_ASSERT(clusterInit() == true); \ + memset(&sendData, 0x00, sizeof(sendData)); \ + sendData.param = value; \ + requestSendData(&sendData); \ + CU_ASSERT(func() == value); \ + CU_ASSERT(clusterTerm() == true); \ + } + +#define TRIPCOMPUTER_ADD_TEST(testSuite, func) \ + CU_add_test(testSuite, #func, Test ##func) + +TRIPCOMPUTER_TEST_FUNC(getTrcomTripAVal, trcomTripAVal, 0x0001869F) +TRIPCOMPUTER_TEST_FUNC(getTrcomTripBVal, trcomTripBVal, 0x0001869F) +TRIPCOMPUTER_TEST_FUNC(getTrcomOdoVal, trcomOdoVal, 0x000F423F) +TRIPCOMPUTER_TEST_FUNC(getTrcomUnitVal, trcomUnitVal, IC_HMI_TRCOM_MILE) +TRIPCOMPUTER_TEST_FUNC(getAvgSpeedAVal, avgSpeedAVal, 0x012C) +TRIPCOMPUTER_TEST_FUNC(getAvgSpeedBVal, avgSpeedBVal, 0x012C) +TRIPCOMPUTER_TEST_FUNC(getHourAVal, hourAVal, 0x03E7) +TRIPCOMPUTER_TEST_FUNC(getHourBVal, hourBVal, 0x03E7) +TRIPCOMPUTER_TEST_FUNC(getMinuteAVal, minuteAVal, 0x3B) +TRIPCOMPUTER_TEST_FUNC(getMinuteBVal, minuteBVal, 0x3B) +TRIPCOMPUTER_TEST_FUNC(getSecondAVal, secondAVal, 0x3B) +TRIPCOMPUTER_TEST_FUNC(getSecondBVal, secondBVal, 0x3B) +TRIPCOMPUTER_TEST_FUNC(getOTempVal, oTempVal, (signed short)0xFFD8) +TRIPCOMPUTER_TEST_FUNC(getOTempUnitVal, oTempUnitVal, IC_HMI_OTEMP_UNIT_K) +TRIPCOMPUTER_TEST_FUNC(getCruRangeVal, cruRangeVal, 0x064A) +TRIPCOMPUTER_TEST_FUNC(getAvgFuelAVal, avgFuelAVal, 0x07CF) +TRIPCOMPUTER_TEST_FUNC(getAvgFuelBVal, avgFuelBVal, 0x07CF) +TRIPCOMPUTER_TEST_FUNC(getInsFuelAVal, insFuelAVal, 0x07CF) +TRIPCOMPUTER_TEST_FUNC(getInsFuelBVal, insFuelBVal, 0x07CF) +TRIPCOMPUTER_TEST_FUNC(getFuelEconomyUnitVal, fuelEconomyUnitVal, IC_HMI_FUEL_KWH_100KM) + +void SetTestSuiteTripComputer(void) +{ + CU_pSuite testSuite; + + testSuite = CU_add_suite("TripComputer", NULL, NULL); + TRIPCOMPUTER_ADD_TEST(testSuite, getTrcomTripAVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getTrcomTripBVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getTrcomOdoVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getTrcomUnitVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getAvgSpeedAVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getAvgSpeedBVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getHourAVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getHourBVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getMinuteAVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getMinuteBVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getSecondAVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getSecondBVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getOTempVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getOTempUnitVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getCruRangeVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getAvgFuelAVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getAvgFuelBVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getInsFuelAVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getInsFuelBVal); + TRIPCOMPUTER_ADD_TEST(testSuite, getFuelEconomyUnitVal); +} + diff --git a/test/client_test/dummy_server.c b/test/client_test/dummy_server.c new file mode 100644 index 0000000..987552a --- /dev/null +++ b/test/client_test/dummy_server.c @@ -0,0 +1,176 @@ +#include "client_test_common.h" + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <stdbool.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/epoll.h> + +#include <ipc.h> + +#define CLUSTER_TEST_EPOLL_WAIT_NUM (2) + +int createEpoll(int waitNum) +{ + int fd = -1; + + fd = epoll_create(waitNum); + if (fd < 0) { + ERRNO_LOG(epoll_create); + return -1; + } + + return fd; +} + +int createSocket(int epollFd, int *pOutTestFd) +{ + int rc; + int fd = -1; + int testFd = -1; + struct sockaddr_un unixAddr; + int len; + struct epoll_event epollEv; + + fd = socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) { + ERRNO_LOG(socket); + return -1; + } + + unixAddr.sun_family = AF_UNIX; + strcpy(unixAddr.sun_path, CLUSTER_TEST_DOMAIN_PATH); + len = sizeof(unixAddr.sun_family)+strlen(unixAddr.sun_path); + rc = bind(fd, (struct sockaddr *)&unixAddr, len); + if (rc < 0) { + ERRNO_LOG(bind); + goto err; + } + + rc = listen(fd, 1); + if (rc < 0) { + ERRNO_LOG(listen); + goto err; + } + + testFd = accept(fd, (struct sockaddr*)&unixAddr, (socklen_t *)&len); + if (testFd < 0) { + ERRNO_LOG(accept); + goto err; + } + + memset(&epollEv, 0, sizeof(epollEv)); + epollEv.events = EPOLLIN; + epollEv.data.fd = fd; + epoll_ctl(epollFd, EPOLL_CTL_ADD, epollEv.data.fd, &epollEv); + + epollEv.events = EPOLLIN | EPOLLRDHUP; + epollEv.data.fd = testFd; + epoll_ctl(epollFd, EPOLL_CTL_ADD, epollEv.data.fd, &epollEv); + + *pOutTestFd = testFd; + + return fd; +err: + shutdown(fd, SHUT_RDWR); + close(fd); + unlink(CLUSTER_TEST_DOMAIN_PATH); + return -1; +} + +void sendMessageLoop(void) +{ + int epollFd = -1; + int socketFd = -1; + int testFd = -1; + int fdNum; + int i; + struct epoll_event epEvents[CLUSTER_TEST_EPOLL_WAIT_NUM]; + bool isRunning = true; + int dummyData; + FILE *fp; + IPC_DATA_IC_SERVICE_S sendData; + IPC_RET_E rc; + int size; + + epollFd = createEpoll(CLUSTER_TEST_EPOLL_WAIT_NUM); + if (epollFd < 0) { + goto end; + } + + socketFd = createSocket(epollFd, &testFd); + if (socketFd < 0) { + goto end; + } + + while(isRunning == true) { + fdNum = epoll_wait(epollFd, epEvents, CLUSTER_TEST_EPOLL_WAIT_NUM, -1); + + for (i = 0; i < fdNum; i++) { + if (epEvents[i].events & EPOLLRDHUP) { + isRunning = false; + break; + } + else if (epEvents[i].events & EPOLLIN) { + size = read(epEvents[i].data.fd, &dummyData, sizeof(dummyData)); + if (size < 0) { + ERRNO_LOG(read); + } + fp = fopen(CLUSTER_TEST_SENDDATA_FILE, "rb"); + if (fp != NULL) { + size = fread(&sendData, 1, sizeof(sendData), fp); + if (size < sizeof(sendData) && ferror(fp)) { + ERRNO_LOG(fread); + } + fclose(fp); + rc = ipcSendMessage(IPC_USAGE_TYPE_IC_SERVICE, &sendData, sizeof(sendData)); + if (rc != IPC_RET_OK) { + fprintf(stderr, "dummy_server:%d Failed to ipcSendMessage() : %d\n", __LINE__, rc); + } + } + } + } + } + +end: + if (testFd >= 0) { + shutdown(testFd, SHUT_RDWR); + close(testFd); + } + + if (socketFd >= 0) { + shutdown(socketFd, SHUT_RDWR); + close(socketFd); + unlink(CLUSTER_TEST_DOMAIN_PATH); + } + + if (epollFd >= 0) { + close(epollFd); + } +} + +int main(void) +{ + IPC_RET_E ret; + + setenv(IPC_ENV_DOMAIN_SOCKET_PATH, IPC_TEST_DOMAIN_PATH, 1); + + ret = ipcServerStart(IPC_USAGE_TYPE_IC_SERVICE); + if (ret != IPC_RET_OK) { + fprintf(stderr, "dummy_server:%d Failed to ipcServerStart() : %d\n", __LINE__, ret); + exit(EXIT_FAILURE); + } + + sendMessageLoop(); + + ret = ipcServerStop(IPC_USAGE_TYPE_IC_SERVICE); + if (ret != IPC_RET_OK) { + fprintf(stderr, "dummy_server:%d Failed to ipcServerStop() : %d\n", __LINE__, ret); + exit(EXIT_FAILURE); + } + + return 0; +} + |