summaryrefslogtreecommitdiffstats
path: root/ipc_unit_test
diff options
context:
space:
mode:
authorNaoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>2021-04-15 11:17:32 +0000
committerNaoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>2021-04-15 11:17:32 +0000
commit738c1d56adb80ac3623251a47a7c5f2d4db57193 (patch)
treeeba82b97376f605ba4ed92464fceeea71f4045cc /ipc_unit_test
Initial commit for AGL cluster ipc library
This source code is AGL instrument cluster common ipc library. Currently, this source code is missing author information, license and other. Will be add by author. Author: Nozomu Abe (nozo_abe@nippon-seiki.co.jp) Committed by Naoto Yamaguchi. Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
Diffstat (limited to 'ipc_unit_test')
-rw-r--r--ipc_unit_test/CMakeLists.txt20
-rw-r--r--ipc_unit_test/ipc_unit_test_client.c153
-rw-r--r--ipc_unit_test/ipc_unit_test_common.c83
-rw-r--r--ipc_unit_test/ipc_unit_test_common.h17
-rw-r--r--ipc_unit_test/ipc_unit_test_server.c201
5 files changed, 474 insertions, 0 deletions
diff --git a/ipc_unit_test/CMakeLists.txt b/ipc_unit_test/CMakeLists.txt
new file mode 100644
index 0000000..32d2118
--- /dev/null
+++ b/ipc_unit_test/CMakeLists.txt
@@ -0,0 +1,20 @@
+
+# Define project Targets
+set(TEST_CLIENT_NAME ipc_unit_test_client)
+set(TEST_SERVER_NAME ipc_unit_test_server)
+
+add_executable(${TEST_CLIENT_NAME} ipc_unit_test_client.c ipc_unit_test_common.c)
+target_link_libraries(${TEST_CLIENT_NAME} ${TARGET_NAME})
+target_include_directories(${TEST_CLIENT_NAME} PRIVATE
+ ./
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
+)
+
+add_executable(${TEST_SERVER_NAME} ipc_unit_test_server.c ipc_unit_test_common.c)
+target_link_libraries(${TEST_SERVER_NAME} ${TARGET_NAME})
+target_include_directories(${TEST_SERVER_NAME} PRIVATE
+ ./
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
+)
+
+
diff --git a/ipc_unit_test/ipc_unit_test_client.c b/ipc_unit_test/ipc_unit_test_client.c
new file mode 100644
index 0000000..4a49b22
--- /dev/null
+++ b/ipc_unit_test/ipc_unit_test_client.c
@@ -0,0 +1,153 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <ipc.h>
+
+#include "ipc_unit_test_common.h"
+
+IPC_DATA_IC_SERVICE_S g_dataIcService;
+
+static void changeNotifyCb(void* pData, signed int size, int kind);
+static void helpPrint(void);
+static void listPrint(void);
+
+int main(void)
+{
+ IPC_RET_E ret;
+ char command[10];
+ char dummy[10];
+ bool isRunning = true;
+ signed int size;
+ char *pRetStr;
+
+ memset(&g_dataIcService, 0, sizeof(g_dataIcService));
+
+ ret = ipcClientStart(IPC_USAGE_TYPE_IC_SERVICE);
+ if (ret != IPC_RET_OK) {
+ printf("ipcClientStart Error:%d\n", ret);
+ goto end;
+ }
+
+ ret = ipcRegisterCallback(IPC_USAGE_TYPE_IC_SERVICE, changeNotifyCb);
+ if (ret != IPC_RET_OK) {
+ printf("ipcRegisterCallback Error:%d\n", ret);
+ goto end;
+ }
+
+ while(isRunning) {
+ printf("command (h=help, q=quit):");
+ pRetStr = fgets(command, 10, stdin);
+ if (pRetStr == NULL) {
+ continue;
+ }
+ memcpy(dummy, command, 10);
+
+ while(strlen(dummy) == 9 && dummy[8] != '\n') {
+ pRetStr = fgets(dummy, 10, stdin);
+ if (pRetStr == NULL) {
+ break;
+ }
+ }
+
+ command[strlen(command)-1] = '\0';
+
+ switch(command[0]) {
+ case 'h':
+ helpPrint();
+ break;
+ case 'q':
+ isRunning = false;
+ break;
+ case 'r':
+ size = sizeof(g_dataIcService);
+ ret = ipcReadDataPool(IPC_USAGE_TYPE_IC_SERVICE, &g_dataIcService, &size);
+ printf("ipcReadDataPool return:%d\n", ret);
+ listPrint();
+ break;
+ default:
+ break;
+ }
+ }
+
+end:
+ ipcClientStop(IPC_USAGE_TYPE_IC_SERVICE);
+ printf("bye...\n");
+ sleep(1);
+
+ return 0;
+}
+
+static void changeNotifyCb(void* pData, signed int size, int kind)
+{
+ signed long longVal;
+ signed int intVal;
+ signed short shortVal;
+ signed char charVal;
+
+ printf("Enter %s\n", __func__);
+
+ switch(size) {
+ case 8:
+ longVal = *((signed long*)pData);
+ printf("kind = %d, size = %d, data=%ld\n", kind, size, longVal);
+ break;
+ case 4:
+ intVal = *((signed int*)pData);
+ printf("kind = %d, size = %d, data=%d\n", kind, size, intVal);
+ break;
+ case 2:
+ shortVal = *((signed short *)pData);
+ printf("kind = %d, size = %d, data=%d\n", kind, size, shortVal);
+ break;
+ default:
+ charVal = *((signed char *)pData);
+ printf("kind = %d, size = %d, data=%d\n", kind, size, charVal);
+ break;
+ }
+ printf("Leave %s\n", __func__);
+ return;
+}
+
+static void helpPrint(void)
+{
+ printf("\n-----------\n");
+ printf("'h' : help\n");
+ printf("'q' : quit\n");
+ printf("'r' : read from Client data pool\n");
+ printf("-----------\n\n");
+}
+
+static void listPrint(void)
+{
+ int i;
+ signed long longVal;
+ signed int intVal;
+ signed short shortVal;
+ signed char charVal;
+ void *pValue;
+
+ for (i = 0; i < IC_SERVICE_LIST_NUM; i++) {
+ pValue = (void *)&g_dataIcService + IcServiceList[i].offset;
+ switch(IcServiceList[i].size) {
+ case 8:
+ longVal = *((signed long*)pValue);
+ printf("%3d: %s(%d) = %ld\n", i, IcServiceList[i].name, IcServiceList[i].size, longVal);
+ break;
+ case 4:
+ intVal = *((signed int*)pValue);
+ printf("%3d: %s(%d) = %d\n", i, IcServiceList[i].name, IcServiceList[i].size, intVal);
+ break;
+ case 2:
+ shortVal = *((signed short *)pValue);
+ printf("%3d: %s(%d) = %d\n", i, IcServiceList[i].name, IcServiceList[i].size, shortVal);
+ break;
+ default:
+ charVal = *((signed char *)pValue);
+ printf("%3d: %s(%d) = %d\n", i, IcServiceList[i].name, IcServiceList[i].size, charVal);
+ break;
+ }
+ }
+}
+
diff --git a/ipc_unit_test/ipc_unit_test_common.c b/ipc_unit_test/ipc_unit_test_common.c
new file mode 100644
index 0000000..02416c2
--- /dev/null
+++ b/ipc_unit_test/ipc_unit_test_common.c
@@ -0,0 +1,83 @@
+#include <ipc.h>
+#include "ipc_unit_test_common.h"
+
+IPC_UNIT_TEST_DATA_LIST IcServiceList[] = {
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, turnR),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, turnL),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, brake),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, seatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, frontRightSeatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, frontCenterSeatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, frontLeftSeatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, mid1RightSeatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, mid1CenterSeatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, mid1LeftSeatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, mid2RightSeatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, mid2CenterSeatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, mid2LeftSeatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, rearRightSeatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, rearCenterSeatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, rearLeftSeatbelt),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, highbeam),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, door),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, frontRightDoor),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, frontLeftDoor),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, rearRightDoor),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, rearLeftDoor),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, trunkDoor),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, hoodDoor),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, eps),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, srsAirbag),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, abs),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, lowBattery),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, oilPress),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, engine),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, fuel),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, immobi),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, tmFail),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, espAct),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, espOff),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, adaptingLighting),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, autoStop),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, autoStopFail),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, parkingLights),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, frontFog),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, exteriorLightFault),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, accFail),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, ldwOff),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, hillDescent),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, autoHiBeamGreen),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, autoHiBeamAmber),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, sportsMode),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, ldwOperate),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, generalWarn),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, drivingPowerMode),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, hotTemp),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, lowTemp),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, gearAtVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, gearMtVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, spAnalogVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, spAnaDigUnitVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, taAnalogVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, trcomTripAVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, trcomTripBVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, trcomOdoVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, trcomUnitVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, avgSpeedAVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, avgSpeedBVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, hourAVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, hourBVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, minuteAVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, minuteBVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, secondAVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, secondBVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, oTempVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, oTempUnitVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, cruRangeVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, avgFuelAVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, avgFuelBVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, insFuelAVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, insFuelBVal),
+ DEFINE_STRUCT_DATA(IPC_DATA_IC_SERVICE_S, fuelEconomyUnitVal)
+};
+
diff --git a/ipc_unit_test/ipc_unit_test_common.h b/ipc_unit_test/ipc_unit_test_common.h
new file mode 100644
index 0000000..e4ad196
--- /dev/null
+++ b/ipc_unit_test/ipc_unit_test_common.h
@@ -0,0 +1,17 @@
+#ifndef IPC_UNIT_TEST_COMMON_H
+#define IPC_UNIT_TEST_COMMON_H
+#include <stddef.h>
+
+#define DEFINE_STRUCT_DATA(struct_name, member) \
+ {#member, offsetof(struct_name, member), sizeof(((struct_name *)0)->member)}
+#define IC_SERVICE_LIST_NUM (77)
+
+typedef struct {
+ const char *name;
+ int offset;
+ int size;
+} IPC_UNIT_TEST_DATA_LIST;
+
+extern IPC_UNIT_TEST_DATA_LIST IcServiceList[];
+
+#endif // IPC_UNIT_TEST_COMMON_H
diff --git a/ipc_unit_test/ipc_unit_test_server.c b/ipc_unit_test/ipc_unit_test_server.c
new file mode 100644
index 0000000..374cda6
--- /dev/null
+++ b/ipc_unit_test/ipc_unit_test_server.c
@@ -0,0 +1,201 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#include <ipc.h>
+
+#include "ipc_unit_test_common.h"
+
+static void helpPrint(void);
+static void helpWritePrint(void);
+static void listPrint(void);
+static void writeData(void);
+static void writeDataToStruct(int id, long value);
+
+IPC_DATA_IC_SERVICE_S g_dataIcService;
+
+int main(void)
+{
+ IPC_RET_E ret;
+ char command[10];
+ char dummy[10];
+ bool isRunning = true;
+ char *pRetStr;
+
+ memset(&g_dataIcService, 0, sizeof(g_dataIcService));
+
+ ret = ipcServerStart(IPC_USAGE_TYPE_IC_SERVICE);
+ if (ret != IPC_RET_OK) {
+ printf("ipcServerStart Error:%d\n", ret);
+ goto end;
+ }
+
+ while(isRunning) {
+ printf("command (h=help, q=quit):");
+ pRetStr = fgets(command, 10, stdin);
+ if (pRetStr == NULL) {
+ continue;
+ }
+ memcpy(dummy, command, 10);
+
+ while(strlen(dummy) == 9 && dummy[8] != '\n') {
+ pRetStr = fgets(dummy, 10, stdin);
+ if (pRetStr == NULL) {
+ break;
+ }
+ }
+
+ command[strlen(command)-1] = '\0';
+
+ switch(command[0]) {
+ case 'h':
+ helpPrint();
+ break;
+ case 'q':
+ isRunning = false;
+ break;
+ case 'l':
+ listPrint();
+ break;
+ case 'w':
+ writeData();
+ break;
+ case 's':
+ ret = ipcSendMessage(IPC_USAGE_TYPE_IC_SERVICE, (const void*)&g_dataIcService, sizeof(g_dataIcService));
+ printf("ipcSendMessage return:%d\n", ret);
+ break;
+ default:
+ break;
+ }
+ }
+
+end:
+ ipcServerStop(IPC_USAGE_TYPE_IC_SERVICE);
+ printf("bye...\n");
+ sleep(1);
+
+ return 0;
+}
+
+static void helpPrint(void)
+{
+ printf("\n-----------\n");
+ printf("'h' : help\n");
+ printf("'q' : quit\n");
+ printf("'l' : list of Server data\n");
+ printf("'w' : write to Server data\n");
+ printf("'s' : send data to Client\n");
+ printf("-----------\n\n");
+}
+
+static void listPrint(void)
+{
+ int i;
+ signed long longVal;
+ signed int intVal;
+ signed short shortVal;
+ signed char charVal;
+ void *pValue;
+
+ for (i = 0; i < IC_SERVICE_LIST_NUM; i++) {
+ pValue = (void *)&g_dataIcService + IcServiceList[i].offset;
+ switch(IcServiceList[i].size) {
+ case 8:
+ longVal = *((signed long*)pValue);
+ printf("%3d: %s(%d) = %ld\n", i, IcServiceList[i].name, IcServiceList[i].size, longVal);
+ break;
+ case 4:
+ intVal = *((signed int*)pValue);
+ printf("%3d: %s(%d) = %d\n", i, IcServiceList[i].name, IcServiceList[i].size, intVal);
+ break;
+ case 2:
+ shortVal = *((signed short *)pValue);
+ printf("%3d: %s(%d) = %d\n", i, IcServiceList[i].name, IcServiceList[i].size, shortVal);
+ break;
+ default:
+ charVal = *((signed char *)pValue);
+ printf("%3d: %s(%d) = %d\n", i, IcServiceList[i].name, IcServiceList[i].size, charVal);
+ break;
+ }
+ }
+}
+
+static void writeData(void)
+{
+ char command[40];
+ char dummy[40];
+ bool isRunning = true;
+ int i;
+
+ int id;
+ long value;
+
+ char *pRetStr;
+
+ while(isRunning) {
+ printf("write command (h=help q=goto main menu):");
+ pRetStr = fgets(command, 40, stdin);
+ if (pRetStr == NULL) {
+ continue;
+ }
+ memcpy(dummy, command, 40);
+
+ while(strlen(dummy) == 39 && dummy[38] != '\n') {
+ pRetStr = fgets(dummy, 40, stdin);
+ if (pRetStr == NULL) {
+ break;
+ }
+ }
+
+ command[strlen(command)-1] = '\0';
+ switch(command[0]) {
+ case 'h':
+ helpWritePrint();
+ break;
+ case 'q':
+ isRunning = false;
+ break;
+ case 'l':
+ listPrint();
+ break;
+ default:
+ // write data
+ id = (int)strtol(command, NULL, 0);
+ value = 0;
+ for (i = 0; i < strlen(command); i++) {
+ if (command[i] == ' ') {
+ value = (int)strtol(&command[i], NULL, 0);
+ }
+ }
+ writeDataToStruct(id, value);
+ }
+ }
+}
+
+static void helpWritePrint(void)
+{
+ printf("\n-----------\n");
+ printf("'h' : help\n");
+ printf("'q' : goto main menu\n");
+ printf("'l' : list of Server data\n");
+ printf("<ID> <value>: write data\n");
+ printf(" ex)\n");
+ printf(" write command 2 4\n");
+ printf(" -> 2: brake = 4\n");
+ printf("-----------\n\n");
+}
+
+static void writeDataToStruct(int id, long value)
+{
+ void *pValue;
+
+ if (id < 0 || IC_SERVICE_LIST_NUM < id) {
+ return;
+ }
+
+ pValue = (void *)&g_dataIcService + IcServiceList[id].offset;
+ memcpy(pValue, (void *)&value, IcServiceList[id].size);
+}
+