summaryrefslogtreecommitdiffstats
path: root/test/client_test/client_test_common.c
diff options
context:
space:
mode:
authorNaoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>2021-04-15 10:48:30 +0000
committerNaoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>2021-04-15 10:48:30 +0000
commitb3e72c7944a738fe9201c406332cbcd878df65e3 (patch)
tree0d7c76f916859893832b0c9ed24650ac06bf3acf /test/client_test/client_test_common.c
Initial commit for AGL cluster api library
This source code is AGL instrument cluster common API 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 'test/client_test/client_test_common.c')
-rw-r--r--test/client_test/client_test_common.c101
1 files changed, 101 insertions, 0 deletions
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);
+ }
+}
+