From d515020fa1bcb5d874084a68c9de9434dc9d994e Mon Sep 17 00:00:00 2001 From: Manikandan C Date: Mon, 29 Oct 2018 16:32:17 +0100 Subject: Gateway Improvements -Support to send and parse periodic control messages -add application/contexts to passive ECU list -Refactor dlt_gateway_send_control_message -Gateway issues with corrupted data and on demand connection -Unit Test update Signed-off-by: Saya Sugiura ssugiura@jp.adit-jv.com Signed-off-by: Christoph Lipka clipka@jp.adit-jv.com Signed-off-by: S. Hameed shameed@jp.adit-jv.com Signed-off-by: ManikandanC Manikandan.Chockalingam@in.bosch.com --- tests/gtest_dlt_daemon_gateway.cpp | 266 +++++++++++++++++++++++++------------ 1 file changed, 184 insertions(+), 82 deletions(-) (limited to 'tests/gtest_dlt_daemon_gateway.cpp') diff --git a/tests/gtest_dlt_daemon_gateway.cpp b/tests/gtest_dlt_daemon_gateway.cpp index 950f260..f681243 100644 --- a/tests/gtest_dlt_daemon_gateway.cpp +++ b/tests/gtest_dlt_daemon_gateway.cpp @@ -61,35 +61,8 @@ extern "C" { -#include "dlt-daemon.h" -#include "dlt_user.h" -#include "dlt_user_shared.h" -#include "dlt_user_shared_cfg.h" -#include "dlt_user_cfg.h" -#include "dlt-daemon_cfg.h" -#include "dlt_version.h" #include "dlt_gateway.h" -#include "dlt_daemon_common.h" -#include "dlt_daemon_connection_types.h" -#include "dlt_daemon_event_handler.h" -#include "dlt_daemon_connection.h" -#include "dlt_daemon_event_handler_types.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "dlt_config_file_parser.h" -#include "dlt_common.h" -#include "dlt-daemon_cfg.h" -#include "dlt_daemon_event_handler.h" -#include "dlt_daemon_connection.h" -#include "dlt_daemon_client.h" +#include "gtest_common.h" } /* Begin Method: dlt_gateway::t_dlt_gateway_init*/ @@ -99,17 +72,20 @@ TEST(t_dlt_gateway_init, normal) DltGatewayConnection connections; daemon_local.pGateway.connections = &connections; daemon_local.pGateway.num_connections = 1; - + daemon_local.flags.lflag = 0; + DltFilterConfiguration current; + daemon_local.pFilter.current = ¤t; DltConnection connections1; DltReceiver receiver; daemon_local.pEvent.connections = &connections1; daemon_local.pEvent.connections->receiver = &receiver; daemon_local.pEvent.connections->next = NULL; - memset(daemon_local.flags.gatewayConfigFile,0,DLT_DAEMON_FLAG_MAX); strncpy(daemon_local.flags.gatewayConfigFile, "/tmp/dlt_gateway.conf", DLT_DAEMON_FLAG_MAX - 1); EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_init(&daemon_local, 1)); + + dlt_gateway_deinit(&daemon_local.pGateway, 0); } TEST(t_dlt_gateway_init, nullpointer) @@ -123,6 +99,8 @@ TEST(t_dlt_gateway_send_control_message, Normal) { int ret = 0; DltDaemonLocal daemon_local; + DltFilterConfiguration current; + daemon_local.pFilter.current = ¤t; DltGatewayConnection connections; DltConnection connections1; DltReceiver receiver1; @@ -132,11 +110,12 @@ TEST(t_dlt_gateway_send_control_message, Normal) daemon_local.pEvent.connections->receiver = &receiver1; memset(daemon_local.flags.gatewayConfigFile,0,DLT_DAEMON_FLAG_MAX); strncpy(daemon_local.flags.gatewayConfigFile, "/tmp/dlt_gateway.conf", DLT_DAEMON_FLAG_MAX - 1); - ret = dlt_gateway_init(&daemon_local, 0); + EXPECT_EQ(DLT_RETURN_OK, ret); - dlt_gateway_send_control_message(daemon_local.pGateway.connections, &daemon_local.pGateway, &daemon_local, 0); + dlt_gateway_send_control_message(daemon_local.pGateway.connections, daemon_local.pGateway.connections->p_control_msgs, NULL, 0); + dlt_gateway_deinit(&daemon_local.pGateway, 0); } TEST(t_dlt_gateway_send_control_message, nullpointer) @@ -153,11 +132,9 @@ TEST(t_dlt_gateway_store_connection, normal) DltGateway gateway; DltGatewayConnection tmp; DltGatewayConnection tmp1; - gateway.num_connections = 1; gateway.connections = &tmp1; gateway.connections->status = DLT_GATEWAY_UNINITIALIZED; - tmp.ip_address = ip_address; tmp.ecuid = ecuid; tmp.sock_domain = 1; @@ -168,12 +145,18 @@ TEST(t_dlt_gateway_store_connection, normal) tmp.timeout = 500; EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_store_connection(&gateway, &tmp, 0)); + EXPECT_EQ(gateway.connections->sock_domain, tmp.sock_domain); + EXPECT_EQ(gateway.connections->sock_type, tmp.sock_type); + EXPECT_EQ(gateway.connections->port, tmp.port); } TEST(t_dlt_gateway_store_connection, nullpointer) { // NULL-Pointer, expect -1 + DltGateway gateway; + EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_store_connection(NULL , NULL, 0)); + EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_store_connection(&gateway , NULL, 0)); } /* Begin Method: dlt_gateway::t_dlt_gateway_check_ip*/ @@ -200,6 +183,7 @@ TEST(t_dlt_gateway_check_send_serial, normal) DltGatewayConnection *con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "134dltgatway"; con = &tmp; + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_send_serial(con, value)); } @@ -209,14 +193,29 @@ TEST(t_dlt_gateway_check_send_serial, nullpointer) EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_send_serial(NULL,NULL)); } +/* Begin Method: dlt_gateway::t_dlt_gateway_allocate_control_messages*/ +TEST(t_dlt_gateway_allocate_control_messages, normal) +{ + DltGatewayConnection tmp; + DltGatewayConnection *con; + tmp.p_control_msgs = NULL; + con = &tmp; + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_allocate_control_messages(con)); +} + +TEST(t_dlt_gateway_allocate_control_messages, nullpointer) +{ + EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_allocate_control_messages(NULL)); +} + /* Begin Method: dlt_gateway::t_dlt_gateway_check_control_messages*/ TEST(t_dlt_gateway_check_control_messages, normal) { DltGatewayConnection tmp; DltGatewayConnection *con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "1,2,3,4,5"; + tmp.p_control_msgs = NULL; con = &tmp; - con->control_msgs[0] = DLT_SERVICE_ID_LAST_ENTRY; EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_control_messages(con, value)); } @@ -226,6 +225,22 @@ TEST(t_dlt_gateway_check_control_messages, nullpointer) EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_control_messages(NULL,NULL)); } +/* Begin Method: dlt_gateway::t_dlt_gateway_check_periodic_control_messages*/ +TEST(t_dlt_gateway_check_periodic_control_messages, normal) +{ + DltGatewayConnection tmp; + DltGatewayConnection *con; + char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "1:5,2:10"; + tmp.p_control_msgs = NULL; + con = &tmp; + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_periodic_control_messages(con, value)); +} + +TEST(t_dlt_gateway_check_periodic_control_messages, nullpointer) +{ + EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_periodic_control_messages(NULL,NULL)); +} + /* Begin Method: dlt_gateway::t_dlt_gateway_check_port*/ TEST(t_dlt_gateway_check_port, normal) { @@ -233,6 +248,7 @@ TEST(t_dlt_gateway_check_port, normal) DltGatewayConnection *con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "3490"; con = &tmp; + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_port(con, value)); } @@ -242,6 +258,7 @@ TEST(t_dlt_gateway_check_port, abnormal) DltGatewayConnection *con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "9999999999"; con = &tmp; + EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_port(con, value)); } @@ -258,6 +275,7 @@ TEST(t_dlt_gateway_check_ecu, normal) DltGatewayConnection *con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "ECU2"; con = &tmp; + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_ecu(con, value)); } @@ -274,6 +292,7 @@ TEST(t_dlt_gateway_check_connect_trigger, normal) DltGatewayConnection *con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "OnStartup"; con = &tmp; + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_connect_trigger(con, value)); } @@ -283,6 +302,7 @@ TEST(t_dlt_gateway_check_connect_trigger, abnormal) DltGatewayConnection *con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "wrong_parameter"; con = &tmp; + EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_connect_trigger(con, value)); } @@ -299,6 +319,7 @@ TEST(t_dlt_gateway_check_timeout, normal) DltGatewayConnection *con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "10"; con = &tmp; + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_check_timeout(con, value)); } @@ -308,6 +329,7 @@ TEST(t_dlt_gateway_check_timeout, abnormal) DltGatewayConnection *con; char value[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "0"; con = &tmp; + EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_timeout(con, value)); } @@ -325,7 +347,9 @@ TEST(t_dlt_gateway_establish_connections, normal) DltGatewayConnection connections; gateway->num_connections = 1; gateway->connections = &connections; - gateway->connections->status = DLT_GATEWAY_CONNECTED; + gateway->connections->status = DLT_GATEWAY_INITIALIZED; + gateway->connections->trigger = DLT_GATEWAY_ON_STARTUP; + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_establish_connections(gateway, &daemon_local, 0)); } @@ -348,6 +372,7 @@ TEST(t_dlt_gateway_get_connection_receiver, normal) gateway.connections->client.receiver.fd = 12; gateway.connections->status = DLT_GATEWAY_CONNECTED; ret = dlt_gateway_get_connection_receiver(&gateway, fd); + EXPECT_EQ(12, ret->fd); } @@ -362,6 +387,7 @@ TEST(t_dlt_gateway_get_connection_receiver, abnormal) gateway.connections->client.sock = fd; gateway.connections->client.receiver.fd = 12; ret = dlt_gateway_get_connection_receiver(&gateway, fd); + EXPECT_EQ(NULL, ret); } @@ -370,9 +396,120 @@ TEST(t_dlt_gateway_get_connection_receiver, nullpointer) // NULL-Pointer, expect -1 DltReceiver *ret; ret = dlt_gateway_get_connection_receiver(NULL, 0); + EXPECT_EQ(NULL, ret); } +/* Begin Method: dlt_gateway::t_dlt_gateway_parse_get_log_info*/ +TEST(t_dlt_gateway_parse_get_log_info, normal) +{ + int32_t len; + DltDaemon daemon; + DltGateway gateway; + DltMessage msg; + char ecuid[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "ECU2"; + uint32_t sid = DLT_SERVICE_ID_GET_LOG_INFO; + uint8_t status = 7; + uint16_t count_app_ids = 1; + uint16_t count_context_ids = 1; + const char *apid = "LOG"; + const char *ctid = "TEST"; + const char *com = "remo"; + char app_description[] = "Test Application for Logging"; + char context_description[] = "Test Context for Logging"; + uint16_t len_app = 0; + uint16_t len_con = 0; + int8_t log_level = -1; + int8_t trace_status = -1;; + int offset = 0; + memset(&daemon, 0, sizeof(DltDaemon)); + dlt_set_id(daemon.ecuid, ecuid); + EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); + EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + + /* create response message */ + msg.datasize = sizeof(DltServiceGetLogInfoResponse) + + sizeof(AppIDsType) + + sizeof(ContextIDsInfoType); + msg.databuffer = (uint8_t *) malloc(msg.datasize); + msg.databuffersize = msg.datasize; + memset(msg.databuffer, 0, msg.datasize); + + memcpy(msg.databuffer, &sid, sizeof(uint32_t)); + offset += sizeof(uint32_t); + + memcpy(msg.databuffer + offset, &status, sizeof(int8_t)); + offset += sizeof(int8_t); + + memcpy(msg.databuffer + offset, &count_app_ids, sizeof(uint16_t)); + offset += sizeof(uint16_t); + + dlt_set_id((char*)(msg.databuffer + offset), apid); + offset += sizeof(ID4); + + memcpy(msg.databuffer + offset, &count_context_ids, sizeof(uint16_t)); + offset += sizeof(uint16_t); + + dlt_set_id((char*)(msg.databuffer + offset), ctid); + offset += sizeof(ID4); + + memcpy(msg.databuffer + offset, &log_level, sizeof(int8_t)); + offset += sizeof(int8_t); + + memcpy(msg.databuffer + offset, &trace_status, sizeof(int8_t)); + offset += sizeof(int8_t); + + len_con = strlen(context_description); + memcpy(msg.databuffer + offset, &len_con, sizeof(uint16_t)); + offset += sizeof(uint16_t); + + memcpy(msg.databuffer + offset, context_description, strlen(context_description)); + offset += strlen(context_description); + + len_app = strlen(app_description); + memcpy(msg.databuffer + offset, &len_app, sizeof(uint16_t)); + offset += sizeof(uint16_t); + + memcpy(msg.databuffer + offset, app_description, strlen(app_description)); + offset += strlen(app_description); + + dlt_set_id((char*)(msg.databuffer + offset), com); + + msg.storageheader = (DltStorageHeader*)msg.headerbuffer; + dlt_set_storageheader(msg.storageheader, ""); + + msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader)); + msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1 ; + msg.standardheader->mcnt = 0; + + dlt_set_id(msg.headerextra.ecu, ecuid); + msg.headerextra.tmsp = dlt_uptime(); + dlt_message_set_extraparameters(&msg, 0); + + msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer + + sizeof(DltStorageHeader) + + sizeof(DltStandardHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp) ); + msg.extendedheader->msin = DLT_MSIN_CONTROL_RESPONSE; + msg.extendedheader->noar = 1; + dlt_set_id(msg.extendedheader->apid, ""); + dlt_set_id(msg.extendedheader->ctid, ""); + + msg.headersize = sizeof(DltStorageHeader) + + sizeof(DltStandardHeader) + + sizeof(DltExtendedHeader) + + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp); + len = msg.headersize - sizeof(DltStorageHeader) + msg.datasize; + msg.standardheader->len = DLT_HTOBE_16(len); + + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_parse_get_log_info(&daemon, ecuid, &msg, 0)); +} + +TEST(t_dlt_gateway_parse_get_log_info, nullpointer) +{ + EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_parse_get_log_info(NULL, NULL, NULL, 0)); +} + /* Begin Method: dlt_gateway::t_dlt_gateway_process_passive_node_messages*/ TEST(t_dlt_gateway_process_passive_node_messages, normal) { @@ -380,9 +517,14 @@ TEST(t_dlt_gateway_process_passive_node_messages, normal) DltDaemonLocal daemon_local; DltReceiver receiver; DltGatewayConnection connections; + memset(&daemon, 0, sizeof(DltDaemon)); + memset(&daemon_local, 0, sizeof(DltDaemonLocal)); + memset(&receiver, 0, sizeof(DltReceiver)); + memset(&connections, 0, sizeof(DltGatewayConnection)); daemon_local.pGateway.connections = &connections; daemon_local.pGateway.num_connections = 1; daemon_local.pGateway.connections->status = DLT_GATEWAY_CONNECTED; + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_process_passive_node_messages(&daemon,&daemon_local,&receiver,1)); } @@ -404,13 +546,13 @@ TEST(t_dlt_gateway_process_gateway_timer, normal) daemon_local.pGateway.connections = &connections; daemon_local.pGateway.num_connections = 1; DltLogStorage storage_handle; - daemon_local.pGateway.connections->status = DLT_GATEWAY_CONNECTED; + daemon_local.pGateway.connections->status = DLT_GATEWAY_INITIALIZED; + daemon_local.pGateway.connections->trigger = DLT_GATEWAY_ON_STARTUP; daemon_local.pEvent.connections = &connections1; daemon_local.pEvent.connections->receiver = &receiver; daemon.ECUVersionString = ECUVersionString; daemon.storage_handle = &storage_handle; - daemon_local.pEvent.connections->receiver->fd = -1; EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_process_gateway_timer(&daemon,&daemon_local,daemon_local.pEvent.connections->receiver,1)); @@ -427,12 +569,12 @@ TEST(t_dlt_gateway_process_on_demand_request, normal) { char node_id[DLT_ID_SIZE] = "123"; uint32_t connection_status = 1; - DltDaemonLocal daemon_local; DltGatewayConnection connections; daemon_local.pGateway.connections = &connections; daemon_local.pGateway.num_connections = 1; connections.status = DLT_GATEWAY_CONNECTED; + connections.trigger = DLT_GATEWAY_ON_STARTUP; connections.ecuid = node_id; EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_process_on_demand_request(&daemon_local.pGateway, @@ -446,7 +588,6 @@ TEST(t_dlt_gateway_process_on_demand_request, abnormal) { char node_id[DLT_ID_SIZE] = "123"; uint32_t connection_status = 1; - DltDaemonLocal daemon_local; DltGatewayConnection connections; daemon_local.pGateway.connections = &connections; @@ -491,7 +632,6 @@ TEST(t_dlt_gateway_check_param, normal) TEST(t_dlt_gateway_check_param, abnormal) { char value_1[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "10.11.22.33"; - DltGateway gateway; DltGatewayConnection tmp; gateway.connections = &tmp; @@ -516,7 +656,8 @@ TEST(t_dlt_gateway_configure, Normal) gateway.connections = &tmp; gateway.num_connections = 1; char gatewayConfigFile[DLT_DAEMON_FLAG_MAX]; - strncpy(gatewayConfigFile, DLT_GATEWAY_CONFIG_PATH, DLT_DAEMON_FLAG_MAX - 1); + strncpy(gatewayConfigFile, "/tmp/dlt_gateway.conf", DLT_DAEMON_FLAG_MAX - 1); + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_configure(&gateway, gatewayConfigFile, 0)); } @@ -526,49 +667,10 @@ TEST(t_dlt_gateway_configure, nullpointer) EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_configure(NULL, NULL, 0)); } -/* Begin Method: dlt_gateway::t_dlt_gateway_forward_control_message*/ -TEST(t_dlt_gateway_forward_control_message, normal) -{ - int ret = 0; - char ecu[DLT_ID_SIZE] = {'E', 'C', 'U', '1'}; - DltDaemonLocal daemon_local; - DltGatewayConnection connections; - DltConnection connections1; - DltReceiver receiver1; - - daemon_local.pGateway.connections = &connections; - daemon_local.pEvent.connections = &connections1; - daemon_local.pEvent.connections->receiver = &receiver1; - daemon_local.pEvent.connections->receiver->fd = 1; - daemon_local.pEvent.connections->next = NULL; - daemon_local.pGateway.num_connections = 1; - daemon_local.pEvent.connections->type = DLT_CONNECTION_CLIENT_MSG_TCP; - - DltMessage msg; - memset(daemon_local.flags.gatewayConfigFile,0,DLT_DAEMON_FLAG_MAX); - strncpy(daemon_local.flags.gatewayConfigFile, "/tmp/dlt_gateway.conf", DLT_DAEMON_FLAG_MAX - 1); - - ret = dlt_gateway_init(&daemon_local, 0); - EXPECT_EQ(DLT_RETURN_OK, ret); - - ret = dlt_gateway_forward_control_message(&daemon_local.pGateway, - &daemon_local, - &msg, - ecu, - 0); - EXPECT_EQ(DLT_RETURN_OK, ret); -} - -TEST(t_dlt_gateway_forward_control_message, nullpointer) -{ - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_forward_control_message(NULL, NULL, NULL, NULL, 0)); -} - int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); // ::testing::FLAGS_gtest_break_on_failure = true; -// ::testing::FLAGS_gtest_filter = "t_dlt_gateway_forward_control_message*"; +// ::testing::FLAGS_gtest_filter = "t_dlt_gateway_process_passive_node_messages*"; return RUN_ALL_TESTS(); } -- cgit v1.2.1