diff options
author | Bui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com> | 2019-06-04 13:53:07 +0700 |
---|---|---|
committer | Saya Sugiura <ssugiura@jp.adit-jv.com> | 2019-06-10 17:47:34 +0900 |
commit | c99d58871e21cf6518e6c80055c967c30e7c28e4 (patch) | |
tree | 8c348652b7bd48885b25271f168b96b265db0547 | |
parent | 514717f210dd190c297f5880bf8f0dd89479849b (diff) | |
download | DLT-daemon-c99d58871e21cf6518e6c80055c967c30e7c28e4.tar.gz |
Unit test fix
- Initialize variables in gtest_dlt_daemon_gateway.cpp to avoid
unexpected error
- Support FIFO mode in connectServer() in gtest_dlt_daemon_offline_log
- Do not fork a child process in gtest_dlt_daemon_offline_log
if DLT_IPC is not UNIX_SOCKET
Signed-off-by: Bui Nguyen Quoc Thanh <thanh.buinguyenquoc@vn.bosch.com>
-rw-r--r-- | tests/gtest_dlt_daemon_gateway.cpp | 12 | ||||
-rw-r--r-- | tests/gtest_dlt_daemon_offline_log.cpp | 17 |
2 files changed, 28 insertions, 1 deletions
diff --git a/tests/gtest_dlt_daemon_gateway.cpp b/tests/gtest_dlt_daemon_gateway.cpp index af9d865..f8c24d4 100644 --- a/tests/gtest_dlt_daemon_gateway.cpp +++ b/tests/gtest_dlt_daemon_gateway.cpp @@ -337,6 +337,8 @@ TEST(t_dlt_gateway_check_timeout, nullpointer) /* Begin Method: dlt_gateway::t_dlt_gateway_establish_connections*/ TEST(t_dlt_gateway_establish_connections, normal) { + char ip[] = "127.0.0.1"; + int port = 3491; DltDaemonLocal daemon_local; DltGateway *gateway = &daemon_local.pGateway; DltGatewayConnection connections; @@ -344,6 +346,10 @@ TEST(t_dlt_gateway_establish_connections, normal) gateway->connections = &connections; gateway->connections->status = DLT_GATEWAY_INITIALIZED; gateway->connections->trigger = DLT_GATEWAY_ON_STARTUP; + gateway->connections->client.mode = DLT_CLIENT_MODE_TCP; + gateway->connections->client.servIP = ip; + gateway->connections->client.port = port; + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_establish_connections(gateway, &daemon_local, 0)); } @@ -536,6 +542,8 @@ TEST(t_dlt_gateway_process_passive_node_messages, nullpointer) TEST(t_dlt_gateway_process_gateway_timer, normal) { char ECUVersionString[] = "12.34"; + char ip[] = "127.0.0.1"; + int port = 3491; DltDaemon daemon; DltDaemonLocal daemon_local; DltReceiver receiver; @@ -546,6 +554,10 @@ TEST(t_dlt_gateway_process_gateway_timer, normal) DltLogStorage storage_handle; daemon_local.pGateway.connections->status = DLT_GATEWAY_INITIALIZED; daemon_local.pGateway.connections->trigger = DLT_GATEWAY_ON_STARTUP; + daemon_local.pGateway.connections->client.mode = DLT_CLIENT_MODE_TCP; + daemon_local.pGateway.connections->client.servIP = ip; + daemon_local.pGateway.connections->client.port = port; + daemon_local.pEvent.connections = &connections1; daemon_local.pEvent.connections->receiver = &receiver; diff --git a/tests/gtest_dlt_daemon_offline_log.cpp b/tests/gtest_dlt_daemon_offline_log.cpp index 4d086dd..43d0917 100644 --- a/tests/gtest_dlt_daemon_offline_log.cpp +++ b/tests/gtest_dlt_daemon_offline_log.cpp @@ -1684,6 +1684,7 @@ TEST(t_dlt_logstorage_sync_msg_cache, null) int connectServer(void) { +#ifdef DLT_USE_UNIX_SOCKET_IPC int sockfd, portno; struct sockaddr_in serv_addr; struct hostent *server; @@ -1702,6 +1703,17 @@ int connectServer(void) close(sockfd); return -1; } +#else + char filename[1024]; + int sockfd; + snprintf(filename, 1024, "/tmp/dltpipes/dlt%d", getpid()); + /* Try to delete existing pipe, ignore result of unlink */ + unlink(filename); + + mkfifo(filename, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP); + chmod(filename, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP); + sockfd = open(filename, O_RDWR | O_CLOEXEC); +#endif return sockfd; } @@ -1710,6 +1722,7 @@ int connectServer(void) int main(int argc, char **argv) { +#ifdef DLT_USE_UNIX_SOCKET_IPC pid_t cpid; cpid = fork(); @@ -1775,12 +1788,14 @@ int main(int argc, char **argv) close(sockfd); } else { - +#endif ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_break_on_failure = false; /* ::testing::FLAGS_gtest_filter = "t_dlt_event_handler_register_connection*"; */ return RUN_ALL_TESTS(); +#ifdef DLT_USE_UNIX_SOCKET_IPC } +#endif return 0; } |