diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 27 | ||||
-rw-r--r-- | tests/dlt_test_receiver.c | 2 | ||||
-rw-r--r-- | tests/gtest_common.h | 251 | ||||
-rw-r--r-- | tests/gtest_dlt_common.cpp | 33 | ||||
-rw-r--r-- | tests/gtest_dlt_daemon_common.cpp | 64 | ||||
-rw-r--r-- | tests/gtest_dlt_daemon_event_handler.cpp | 139 | ||||
-rw-r--r-- | tests/gtest_dlt_daemon_gateway.cpp | 85 | ||||
-rwxr-xr-x | tests/gtest_dlt_daemon_gateway.sh (renamed from tests/g_test_dlt_daemon_gateway.sh) | 128 | ||||
-rwxr-xr-x | tests/gtest_dlt_daemon_logstorage.sh | 57 | ||||
-rw-r--r-- | tests/gtest_dlt_daemon_offline_log.cpp | 852 | ||||
-rwxr-xr-x | tests/start_multinode_test.sh | 88 |
11 files changed, 1057 insertions, 669 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ab7ed9d..50cca4f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,6 +11,15 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x") configure_file(${CMAKE_SOURCE_DIR}/tests/testfile.dlt ${PROJECT_BINARY_DIR}/tests COPYONLY) configure_file(${CMAKE_SOURCE_DIR}/tests/testfilter.txt ${PROJECT_BINARY_DIR}/tests COPYONLY) +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(LIBRARIES gtest gtest_main) +else() + set(LIBRARIES gtest socket) +endif() + +set(DLT_LIBRARIES ${LIBRARIES} dlt) +set(DLT_DAEMON_LIBRARIES ${LIBRARIES} dlt_daemon) + add_executable(gtest_dlt_common gtest_dlt_common.cpp) add_executable(gtest_dlt_user gtest_dlt_user.cpp) add_executable(gtest_dlt_daemon_common gtest_dlt_daemon_common.cpp ../src/daemon/dlt_daemon_common.c) @@ -19,17 +28,19 @@ add_executable(dlt_env_ll_unit_test dlt_env_ll_unit_test.cpp) add_executable(dlt-test-preregister-context dlt-test-preregister-context.c) add_executable(gtest_dlt_daemon_gateway gtest_dlt_daemon_gateway.cpp) add_executable(gtest_dlt_daemon_event_handler gtest_dlt_daemon_event_handler.cpp) -target_link_libraries(gtest_dlt_common gtest gtest_main dlt) -target_link_libraries(gtest_dlt_user gtest gtest_main dlt) -target_link_libraries(gtest_dlt_daemon_common gtest gtest_main dlt) +add_executable(gtest_dlt_daemon_offline_log gtest_dlt_daemon_offline_log.cpp) +target_link_libraries(gtest_dlt_common ${DLT_LIBRARIES}) +target_link_libraries(gtest_dlt_user ${DLT_LIBRARIES}) +target_link_libraries(gtest_dlt_daemon_common ${DLT_LIBRARIES}) target_link_libraries(dlt_test_receiver dlt) -target_link_libraries(dlt_env_ll_unit_test gtest gtest_main dlt) -target_link_libraries(dlt-test-preregister-context gtest gtest_main dlt) -target_link_libraries(gtest_dlt_daemon_gateway gtest gtest_main dlt_daemon) -target_link_libraries(gtest_dlt_daemon_event_handler gtest gtest_main dlt_daemon) +target_link_libraries(dlt_env_ll_unit_test ${DLT_LIBRARIES}) +target_link_libraries(dlt-test-preregister-context ${DLT_LIBRARIES}) +target_link_libraries(gtest_dlt_daemon_gateway ${DLT_DAEMON_LIBRARIES}) +target_link_libraries(gtest_dlt_daemon_event_handler ${DLT_DAEMON_LIBRARIES}) +target_link_libraries(gtest_dlt_daemon_offline_log ${DLT_DAEMON_LIBRARIES}) if(${WITH_DLT_CXX11_EXT}) add_executable(dlt-test-cpp-extension dlt-test-cpp-extension.cpp) set_target_properties(dlt-test-cpp-extension PROPERTIES COMPILE_FLAGS "-std=gnu++0x") - target_link_libraries(dlt-test-cpp-extension gtest gtest_main dlt) + target_link_libraries(dlt-test-cpp-extension ${DLT_LIBRARIES}) endif() diff --git a/tests/dlt_test_receiver.c b/tests/dlt_test_receiver.c index 86147ec..e7abd83 100644 --- a/tests/dlt_test_receiver.c +++ b/tests/dlt_test_receiver.c @@ -82,8 +82,6 @@ #include "dlt_client.h" #include <zlib.h> -#define DLT_RECEIVE_TEXTBUFSIZE 10024 /* Size of buffer for text output */ - #define DLT_RECEIVE_ECU_ID "RECV" /* Function prototypes */ diff --git a/tests/gtest_common.h b/tests/gtest_common.h deleted file mode 100644 index 0ca9f7e..0000000 --- a/tests/gtest_common.h +++ /dev/null @@ -1,251 +0,0 @@ -/** - * @licence app begin@ - * Copyright (C) 2016 Advanced Driver Information Technology. - * This code is developed by Advanced Driver Information Technology. - * Copyright of Advanced Driver Information Technology, Bosch and DENSO. - * - * DLT gtest common header file. - * - * \copyright - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with - * this file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * - * \author Onkar Palkar <onkar.palkar@wipro.com> - * - * \file: gtest_common.h - * For further information see http://www.genivi.org/. - * @licence end@ - */ - -/******************************************************************************* - * ** - * SRC-MODULE: gtest_common.h ** - * ** - * TARGET : linux ** - * ** - * PROJECT : DLT ** - * ** - * AUTHOR : onkar.palkar@wipro.com ** - * PURPOSE : ** - * ** - * REMARKS : ** - * ** - * PLATFORM DEPENDANT [yes/no]: yes ** - * ** - * TO BE CHANGED BY USER [yes/no]: no ** - * ** - ******************************************************************************/ - -/******************************************************************************* -* Author Identity ** -******************************************************************************* -* ** -* Initials Name Company ** -* -------- ------------------------- ---------------------------------- ** -* op Onkar Palkar Wipro ** -*******************************************************************************/ -#ifndef GTEST_COMMON_H -#define GTEST_COMMON_H -int dlt_logstorage_split_key(char *key, char *appid, char *ctxid); -int dlt_logstorage_update_all_contexts(DltDaemon *daemon, - char *id, - int curr_log_level, - int cmp_flag, - int verbose); -int dlt_logstorage_update_context(DltDaemon *daemon, - char *apid, - char *ctxid, - char *ecuid, - int curr_log_level, - int verbose); -int dlt_logstorage_update_context_loglevel(DltDaemon *daemon, - char *key, - int curr_log_level, - int verbose); -void dlt_daemon_logstorage_reset_application_loglevel(DltDaemon *daemon, - int dev_num, - int max_device, - int verbose); -typedef struct { - char *key; /* The configuration key */ - int (*func)(DltLogStorage *handle, char *value); /* conf handler */ - int is_opt; /* If configuration is optional or not */ -} DltLogstorageGeneralConf; - -typedef enum { - DLT_LOGSTORAGE_GENERAL_CONF_BLOCKMODE = 0, - DLT_LOGSTORAGE_GENERAL_CONF_COUNT -} DltLogstorageGeneralConfType; - -typedef struct { - char *key; /* Configuration key */ - int (*func)(DltLogStorageFilterConfig *config, char *value); /* conf handler */ - int is_opt; /* If configuration is optional or not */ -} DltLogstorageFilterConf; - -typedef enum { - DLT_LOGSTORAGE_FILTER_CONF_LOGAPPNAME = 0, - DLT_LOGSTORAGE_FILTER_CONF_CONTEXTNAME, - DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL, - DLT_LOGSTORAGE_FILTER_CONF_FILE, - DLT_LOGSTORAGE_FILTER_CONF_FILESIZE, - DLT_LOGSTORAGE_FILTER_CONF_NOFILES, - DLT_LOGSTORAGE_FILTER_CONF_SYNCBEHAVIOR, - DLT_LOGSTORAGE_FILTER_CONF_ECUID, - DLT_LOGSTORAGE_FILTER_CONF_COUNT -} DltLogstorageFilterConfType; - - int dlt_logstorage_hash_create(int num_entries, - struct hsearch_data *htab); - int dlt_logstorage_hash_destroy(struct hsearch_data *htab); - int dlt_logstorage_hash_add(char *key, void *value, - struct hsearch_data *htab); - void *dlt_logstorage_hash_find(char *key, struct hsearch_data *htab); - int dlt_logstorage_count_ids(const char *str); - int dlt_logstorage_read_number(unsigned int *number, char *value); - int dlt_logstorage_read_list_of_names(char **names, char *value); - int dlt_logstorage_check_apids(DltLogStorageFilterConfig *config, char *value); - int dlt_logstorage_check_ctids(DltLogStorageFilterConfig *config, char *value); - int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig *config, char *value); - int dlt_logstorage_check_filename(DltLogStorageFilterConfig *config, char *value); - int dlt_logstorage_check_filesize(DltLogStorageFilterConfig *config, char *value); - int dlt_logstorage_check_nofiles(DltLogStorageFilterConfig *config, char *value); - int dlt_logstorage_check_sync_strategy(DltLogStorageFilterConfig *config, char *value); - int dlt_logstorage_check_ecuid(DltLogStorageFilterConfig *config, char *value); - int dlt_logstorage_check_param(DltLogStorageFilterConfig *config, - DltLogstorageFilterConfType ctype, - char *value); - int dlt_logstorage_check_blockmode(DltLogStorage *handle, - char *value); - int dlt_logstorage_check_general_param(DltLogStorage *handle, - DltLogstorageGeneralConfType ctype, - char *value); - int dlt_daemon_setup_general_properties(DltLogStorage *handle, - DltConfigFile *config_file, - char *sec_name); - int dlt_logstorage_store_filters(DltLogStorage *handle, - char *config_file_name); - void dlt_logstorage_free(DltLogStorage *handle, int reason); - int dlt_logstorage_create_keys(char *appids, - char *ctxids, - char **keys, - int *num_keys); - int dlt_logstorage_prepare_table(DltLogStorage *handle, - DltLogStorageFilterConfig *data); - int dlt_logstorage_validate_filter_name(char *name); - void dlt_logstorage_filter_set_strategy(DltLogStorageFilterConfig *config, - int strategy); - int dlt_logstorage_load_config(DltLogStorage *handle); - int dlt_logstorage_filter(DltLogStorage *handle, - DltLogStorageFilterConfig **config, - char *apid, - char *ctid, - char *ecuid, - int log_level); -void dlt_logstorage_log_file_name(char *log_file_name, - DltLogStorageUserConfig *file_config, - char *name, - int idx); -void dlt_logstorage_sort_file_name(DltLogStorageFileList **head); -void dlt_logstorage_rearrange_file_name(DltLogStorageFileList **head); -unsigned int dlt_logstorage_get_idx_of_log_file( - DltLogStorageUserConfig *file_config, - char *file); -int dlt_logstorage_storage_dir_info(DltLogStorageUserConfig *file_config, - char *path, - DltLogStorageFilterConfig *config); -int dlt_logstorage_open_log_file(DltLogStorageFilterConfig *config, - DltLogStorageUserConfig *file_config, - char *dev_path, - int msg_size); -/* gtest_dlt_daemon_gateway */ -typedef enum { - GW_CONF_IP_ADDRESS = 0, - GW_CONF_PORT, - GW_CONF_ECUID, - GW_CONF_CONNECT, - GW_CONF_TIMEOUT, - GW_CONF_SEND_CONTROL, - GW_CONF_SEND_PERIODIC_CONTROL, - GW_CONF_SEND_SERIAL_HEADER, - GW_CONF_COUNT -} DltGatewayConfType; -int enable_all(DltServiceIdFlag *flags); -int init_flags(DltServiceIdFlag *flags); -int set_bit(DltServiceIdFlag *flags, int id); -int bit(DltServiceIdFlag *flags, int id); -int dlt_daemon_filter_name(DltMessageFilter *mf, - DltFilterConfiguration *config, - char *value); -int dlt_daemon_filter_level(DltMessageFilter *mf, - DltFilterConfiguration *config, - char *value); -int dlt_daemon_filter_control_mask(DltMessageFilter *mf, - DltFilterConfiguration *config, - char *value); -int dlt_daemon_filter_client_mask(DltMessageFilter *mf, - DltFilterConfiguration *config, - char *value); -int dlt_daemon_filter_injections(DltMessageFilter *mf, - DltFilterConfiguration *config, - char *value); -int dlt_daemon_set_injection_service_ids(int **ids, - int *num, - char *value); -DltInjectionConfig *dlt_daemon_filter_find_injection_by_name( - DltInjectionConfig *injections, - char *name); -int dlt_daemon_injection_name(DltMessageFilter *mf, - DltInjectionConfig *config, - char *value); -int dlt_daemon_injection_apid(DltMessageFilter *mf, - DltInjectionConfig *config, - char *value); -int dlt_daemon_injection_ctid(DltMessageFilter *mf, - DltInjectionConfig *config, - char *value); -int dlt_daemon_injection_ecu_id(DltMessageFilter *mf, - DltInjectionConfig *config, - char *value); -int dlt_daemon_injection_service_id(DltMessageFilter *mf, - DltInjectionConfig *config, - char *value); -int dlt_daemon_get_name(DltMessageFilter *mf, char *val); -int dlt_daemon_get_default_level(DltMessageFilter *mf, char *val); -int dlt_daemon_get_backend(DltMessageFilter *mf, char *val); -int dlt_daemon_setup_filter_section(DltMessageFilter *mf, - DltConfigFile *config, - char *sec_name); -int dlt_daemon_setup_filter_properties(DltMessageFilter *mf, - DltConfigFile *config, - char *sec_name); -void dlt_daemon_filter_backend_level_changed(unsigned int level, - void *ptr1, - void *ptr2); -int dlt_gateway_check_ip(DltGatewayConnection *con, char *value); -int dlt_gateway_check_port(DltGatewayConnection *con, char *value); -int dlt_gateway_check_ecu(DltGatewayConnection *con, char *value); -int dlt_gateway_check_connect_trigger(DltGatewayConnection *con, - char *value); -int dlt_gateway_check_timeout(DltGatewayConnection *con, char *value); -int dlt_gateway_check_send_serial(DltGatewayConnection *con, char *value); -int dlt_gateway_allocate_control_messages(DltGatewayConnection *con); -int dlt_gateway_check_control_messages(DltGatewayConnection *con, - char *value); -int dlt_gateway_check_periodic_control_messages(DltGatewayConnection *con, - char *value); -int dlt_gateway_check_param(DltGateway *gateway, - DltGatewayConnection *con, - DltGatewayConfType ctype, - char *value); -int dlt_gateway_configure(DltGateway *gateway, char *config_file, int verbose); -int dlt_gateway_store_connection(DltGateway *gateway, - DltGatewayConnection *tmp, - int verbose); -int dlt_gateway_parse_get_log_info(DltDaemon *daemon, - char *ecu, - DltMessage *msg, - int verbose); -#endif diff --git a/tests/gtest_dlt_common.cpp b/tests/gtest_dlt_common.cpp index d7c6d9c..27831d3 100644 --- a/tests/gtest_dlt_common.cpp +++ b/tests/gtest_dlt_common.cpp @@ -261,7 +261,7 @@ TEST(t_dlt_buffer_reset, normal) // Normal Use-Case. expect 0 EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(0, dlt_buffer_reset(&buf)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); + } TEST(t_dlt_buffer_reset, abnormal) { @@ -812,15 +812,15 @@ TEST(t_dlt_buffer_copy, nullpointer) int size = sizeof(DltUserHeader); // NULL-Pointer, expected -1 - EXPECT_LE(-1, dlt_buffer_copy(NULL,NULL,size)); - EXPECT_LE(-1, dlt_buffer_copy(NULL,NULL,0)); - EXPECT_LE(-1, dlt_buffer_copy(NULL,(unsigned char *)&header,size)); - EXPECT_LE(-1, dlt_buffer_copy(NULL,(unsigned char *)&header,0)); + EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(NULL,NULL,size)); + EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(NULL,NULL,0)); + EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(NULL,(unsigned char *)&header,size)); + EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(NULL,(unsigned char *)&header,0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(-1, dlt_buffer_copy(&buf,NULL,size)); + EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(&buf,NULL,size)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); - EXPECT_LE(-1, dlt_buffer_copy(&buf,NULL,0)); + EXPECT_LE(DLT_RETURN_WRONG_PARAMETER, dlt_buffer_copy(&buf,NULL,0)); EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } /* End Method: dlt_common::dlt_buffer_copy */ @@ -1238,7 +1238,6 @@ TEST(t_dlt_buffer_info, normal) // Normal Use-Case EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_info(&buf)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } TEST(t_dlt_buffer_info, abnormal) { @@ -1263,7 +1262,6 @@ TEST(t_dlt_buffer_status, normal) // Normal Use-Case EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_NO_THROW(dlt_buffer_status(&buf)); - EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); } TEST(t_dlt_buffer_status, abnormal) { @@ -3094,8 +3092,7 @@ TEST(t_dlt_message_read, normal) EXPECT_LE(DLT_RETURN_ERROR, dlt_message_read(&file.msg,(unsigned char*) buffer,255,0,1)); } EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_close(&file, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); + EXPECT_LE(DLT_RETURN_OK, dlt_buffer_init_dynamic(&buf, DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)); EXPECT_LE(DLT_RETURN_OK, dlt_file_init(&file, 0)); EXPECT_LE(DLT_RETURN_OK, dlt_file_open(&file, openfile, 0)); @@ -3106,8 +3103,6 @@ TEST(t_dlt_message_read, normal) EXPECT_LE(DLT_RETURN_ERROR, dlt_message_read(&file.msg,(unsigned char *) buffer,255,1,1)); } EXPECT_LE(DLT_RETURN_OK, dlt_buffer_free_dynamic(&buf)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_close(&file, 0)); - EXPECT_LE(DLT_RETURN_OK, dlt_file_free(&file, 0)); } TEST(t_dlt_message_read, abnormal) { @@ -3130,9 +3125,9 @@ TEST(t_dlt_message_read, nullpointer) // NULL_Pointer, expected -1 EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read(NULL, NULL, 0,0,0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read(NULL, (u_int8_t *)&buf, 0,0,0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read(NULL, (uint8_t *)&buf, 0,0,0)); EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read(&file.msg, NULL, 0,0,0)); - EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read(&file.msg, (u_int8_t *)&buf, 0,0,0)); + EXPECT_GE(DLT_RETURN_ERROR, dlt_message_read(&file.msg, (uint8_t *)&buf, 0,0,0)); } /* End Method:dlt_common::dlt_message_read */ @@ -3340,16 +3335,11 @@ TEST(t_dlt_log_init, normal) // Normal Use-Case, exptect 0-3 EXPECT_NO_THROW(dlt_log_init(DLT_LOG_TO_CONSOLE)); - EXPECT_NO_THROW(dlt_log_free()); EXPECT_NO_THROW(dlt_log_init(DLT_LOG_TO_SYSLOG)); - EXPECT_NO_THROW(dlt_log_free()); EXPECT_NO_THROW(dlt_log_set_filename("/tmp/dlt.log")); EXPECT_NO_THROW(dlt_log_init(DLT_LOG_TO_FILE)); - EXPECT_NO_THROW(dlt_log_free()); EXPECT_NO_THROW(dlt_log_init(DLT_LOG_TO_FILE)); - EXPECT_NO_THROW(dlt_log_free()); EXPECT_NO_THROW(dlt_log_init(DLT_LOG_DROPPED)); - EXPECT_NO_THROW(dlt_log_free()); } TEST(t_dlt_log_init, abnormal) { @@ -3377,11 +3367,8 @@ TEST(t_dlt_log_free, normal) // Normal Use-Case, expected 0 EXPECT_NO_THROW(dlt_log_init(DLT_LOG_TO_CONSOLE)); - EXPECT_NO_THROW(dlt_log_free()); EXPECT_NO_THROW(dlt_log_init(DLT_LOG_TO_SYSLOG)); - EXPECT_NO_THROW(dlt_log_free()); EXPECT_NO_THROW(dlt_log_init(DLT_LOG_DROPPED)); - EXPECT_NO_THROW(dlt_log_free()); } TEST(t_dlt_log_free, abnormal) { diff --git a/tests/gtest_dlt_daemon_common.cpp b/tests/gtest_dlt_daemon_common.cpp index 69cc940..5e22c2d 100644 --- a/tests/gtest_dlt_daemon_common.cpp +++ b/tests/gtest_dlt_daemon_common.cpp @@ -69,7 +69,7 @@ TEST(t_dlt_daemon_init_user_information, normal_one_list) DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } @@ -100,9 +100,9 @@ TEST(t_dlt_daemon_init_user_information, normal_multiple_lists) dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 1, 0)); EXPECT_EQ(3, daemon.num_user_lists); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); - EXPECT_STREQ(gateway.connections[0].ecuid, daemon.user_list[1].ecu); - EXPECT_STREQ(gateway.connections[1].ecuid, daemon.user_list[2].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); + EXPECT_EQ(DLT_RETURN_OK, strncmp(gateway.connections[0].ecuid, daemon.user_list[1].ecu, DLT_ID_SIZE)); + EXPECT_EQ(DLT_RETURN_OK, strncmp(gateway.connections[1].ecuid, daemon.user_list[2].ecu, DLT_ID_SIZE)); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); free(gateway.connections); @@ -138,7 +138,7 @@ TEST(t_dlt_daemon_find_users_list, normal_one_list) user_list = dlt_daemon_find_users_list(&daemon, &ecu[0], 0); EXPECT_NE(user_list, nullptr); - EXPECT_STREQ(user_list->ecu, daemon.ecuid); + EXPECT_EQ(DLT_RETURN_OK, strncmp(user_list->ecu, daemon.ecuid, DLT_ID_SIZE)); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } @@ -194,21 +194,21 @@ TEST(t_dlt_daemon_find_users_list, normal_multiple_lists) dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 1, 0)); EXPECT_EQ(3, daemon.num_user_lists); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); - EXPECT_STREQ(gateway.connections[0].ecuid, daemon.user_list[1].ecu); - EXPECT_STREQ(gateway.connections[1].ecuid, daemon.user_list[2].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); + EXPECT_EQ(DLT_RETURN_OK, strncmp(gateway.connections[0].ecuid, daemon.user_list[1].ecu, DLT_ID_SIZE)); + EXPECT_EQ(DLT_RETURN_OK, strncmp(gateway.connections[1].ecuid, daemon.user_list[2].ecu, DLT_ID_SIZE)); user_list = dlt_daemon_find_users_list(&daemon, &ecu[0], 0); EXPECT_NE(user_list, nullptr); - EXPECT_STREQ(user_list->ecu, daemon.ecuid); + EXPECT_EQ(DLT_RETURN_OK, strncmp(user_list->ecu, daemon.ecuid, DLT_ID_SIZE)); user_list = dlt_daemon_find_users_list(&daemon, &ecu2[0], 0); EXPECT_NE(user_list, nullptr); - EXPECT_STREQ(user_list->ecu, gateway.connections[0].ecuid); + EXPECT_EQ(DLT_RETURN_OK, strncmp(user_list->ecu, gateway.connections[0].ecuid, DLT_ID_SIZE)); user_list = dlt_daemon_find_users_list(&daemon, &ecu3[0], 0); EXPECT_NE(user_list, nullptr); - EXPECT_STREQ(user_list->ecu, gateway.connections[1].ecuid); + EXPECT_EQ(DLT_RETURN_OK, strncmp(user_list->ecu, gateway.connections[1].ecuid, DLT_ID_SIZE)); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); free(gateway.connections); @@ -240,7 +240,7 @@ TEST(t_dlt_daemon_application_add, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, fd, ecu, 0); //printf("### APP: APID=%s DESCR=%s NUMCONTEXT=%i PID=%i USERHANDLE=%i\n", app->apid,app->application_description, app->num_contexts, app->pid, app->user_handle); @@ -344,7 +344,7 @@ TEST(t_dlt_daemon_application_del, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, fd, ecu, 0); EXPECT_LE(0, dlt_daemon_application_del(&daemon,app, ecu, 0)); EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, ecu, 0)); @@ -409,7 +409,7 @@ TEST(t_dlt_daemon_application_find, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, fd, ecu, 0); EXPECT_STREQ(apid, app->apid); EXPECT_STREQ(desc, app->application_description); @@ -474,7 +474,7 @@ TEST(t_dlt_daemon_applications_clear, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); EXPECT_LE((DltDaemonApplication *) 0, dlt_daemon_application_add(&daemon, (char *) "TES1", pid, (char *) "Test clear 1", fd, ecu, 0)); dlt_daemon_application_add(&daemon, (char *) "TES2", pid, (char *) "Test clear 2", fd, ecu, 0); EXPECT_LE(0, dlt_daemon_applications_clear(&daemon, ecu, 0)); @@ -520,7 +520,7 @@ TEST(t_dlt_daemon_applications_invalidate_fd, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, fd, ecu, 0); EXPECT_LE(0, dlt_daemon_applications_invalidate_fd(&daemon, ecu, app->user_handle, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); @@ -573,7 +573,7 @@ TEST(t_dlt_daemon_applications_save, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon,(char *) apid, pid, (char *) desc, fd, ecu, 0); EXPECT_LE(0, dlt_daemon_applications_save(&daemon, (char *) filename, 0)); EXPECT_LE(0, dlt_daemon_application_del(&daemon, app, ecu, 0)); @@ -633,7 +633,7 @@ TEST(t_dlt_daemon_applications_load, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); EXPECT_LE(0, dlt_daemon_applications_load(&daemon,(char *) filename, 0)); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } @@ -717,7 +717,7 @@ TEST(t_dlt_daemon_context_add, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); daecontext = dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, ecu, 0); @@ -749,7 +749,7 @@ TEST(t_dlt_daemon_context_add, abnormal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); DltLogLevelType DLT_LOG_NOT_EXIST = (DltLogLevelType) - 100; app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_NOT_EXIST,DLT_TRACE_STATUS_DEFAULT,0,0,desc,ecu,0); @@ -856,7 +856,7 @@ TEST(t_dlt_daemon_context_add, nullpointer) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); EXPECT_EQ((DltDaemonContext *) 0, dlt_daemon_context_add(NULL,NULL,NULL,0,0,0,0,NULL,NULL,0)); EXPECT_EQ((DltDaemonContext *) 0, dlt_daemon_context_add(NULL,NULL,NULL,0,0,0,0,desc,NULL,0)); EXPECT_EQ((DltDaemonContext *) 0, dlt_daemon_context_add(NULL,NULL,ctid,0,0,0,0,NULL,NULL,0)); @@ -895,7 +895,7 @@ TEST(t_dlt_daemon_context_del, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,ecu,0); EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); @@ -973,7 +973,7 @@ TEST(t_dlt_daemon_context_find, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,ecu,0); EXPECT_STREQ(apid, daecontext->apid); @@ -1003,7 +1003,7 @@ TEST(t_dlt_daemon_context_find, abnormal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); EXPECT_EQ((DltDaemonContext *) 0 ,dlt_daemon_context_find(&daemon, apid, ctid, ecu, 0)); // No apid @@ -1081,7 +1081,7 @@ TEST(t_dlt_daemon_contexts_clear, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,ecu,0); EXPECT_LE(0, dlt_daemon_context_del(&daemon, daecontext, ecu, 0)); @@ -1139,7 +1139,7 @@ TEST(t_dlt_daemon_contexts_invalidate_fd, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,ecu,0); EXPECT_LE(0, dlt_daemon_contexts_invalidate_fd(&daemon, ecu, app->user_handle, 0)); @@ -1200,7 +1200,7 @@ TEST(t_dlt_daemon_contexts_save, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,ecu,0); EXPECT_LE(0, dlt_daemon_contexts_save(&daemon, filename, 0)); @@ -1276,7 +1276,7 @@ TEST(t_dlt_daemon_contexts_load, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,0,desc,ecu,0); EXPECT_LE(0, dlt_daemon_contexts_load(&daemon, filename, 0)); @@ -1354,7 +1354,7 @@ TEST(t_dlt_daemon_user_send_all_log_state, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); EXPECT_NO_FATAL_FAILURE(dlt_daemon_user_send_all_log_state(&daemon, 0)); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } @@ -1383,7 +1383,7 @@ TEST(t_dlt_daemon_user_send_default_update, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); EXPECT_NO_FATAL_FAILURE(dlt_daemon_user_send_default_update(&daemon, 0)); EXPECT_EQ(0, dlt_daemon_free(&daemon, 0)); } @@ -1417,7 +1417,7 @@ TEST(t_dlt_daemon_user_send_log_level, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); app = dlt_daemon_application_add(&daemon, apid, 0, desc, fd, ecu, 0); daecontext = dlt_daemon_context_add(&daemon,apid,ctid,DLT_LOG_DEFAULT,DLT_TRACE_STATUS_DEFAULT,0,1,desc,ecu,0); EXPECT_LE(0, dlt_daemon_user_send_log_level(&daemon, daecontext, 0)); @@ -1493,7 +1493,7 @@ TEST(t_dlt_daemon_user_send_log_state, normal) EXPECT_EQ(0, dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, DLT_RUNTIME_DEFAULT_DIRECTORY,DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_STREQ(daemon.ecuid, daemon.user_list[0].ecu); + EXPECT_EQ(DLT_RETURN_OK, strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE)); // open(filename, O_RDWR |O_NONBLOCK); // dlt_daemon_init(&daemon, DLT_DAEMON_RINGBUFFER_MIN_SIZE, DLT_DAEMON_RINGBUFFER_MAX_SIZE, DLT_DAEMON_RINGBUFFER_STEP_SIZE, "",0); // app = dlt_daemon_application_add(&daemon, apid, pid, desc, 0); diff --git a/tests/gtest_dlt_daemon_event_handler.cpp b/tests/gtest_dlt_daemon_event_handler.cpp index e55d072..235b69e 100644 --- a/tests/gtest_dlt_daemon_event_handler.cpp +++ b/tests/gtest_dlt_daemon_event_handler.cpp @@ -56,50 +56,24 @@ *******************************************************************************/ #include <gtest/gtest.h> -#include <limits.h> -#include <syslog.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> int connectServer(void); 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 <stdlib.h> - #include <stdio.h> - #include <string.h> - #include <arpa/inet.h> - #include <sys/socket.h> - #include <netinet/in.h> #include <netdb.h> - #include <limits.h> - #include <errno.h> - #include "dlt_config_file_parser.h" - #include "dlt_common.h" - #include "dlt_daemon_client.h" + #include <netinet/in.h> + #include <sys/types.h> + #include <sys/socket.h> } /* Begin Method: dlt_daemon_event_handler::t_dlt_daemon_prepare_event_handling*/ TEST(t_dlt_daemon_prepare_event_handling, normal) { DltEventHandler ev; + EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_prepare_event_handling(&ev)); } @@ -165,8 +139,10 @@ TEST(t_dlt_daemon_add_connection, normal) connections1->receiver = &receiver; EXPECT_EQ(DLT_CONNECTION_CLIENT_MSG_SERIAL, ev1.connections->type); + dlt_daemon_add_connection(&ev1, connections1); head = (DltConnection*)ev1.connections->next; + EXPECT_EQ(DLT_CONNECTION_GATEWAY, head->type); free(ev1.connections); @@ -190,7 +166,6 @@ TEST(t_dlt_daemon_remove_connection, normal) memset(connections1, 0, sizeof(DltConnection)); connections1->next = 0; connections1->type = DLT_CONNECTION_GATEWAY; - DltReceiver receiver; connections1->receiver = &receiver; @@ -220,24 +195,21 @@ TEST(t_dlt_event_handler_cleanup_connections, normal) } /* Begin Method: dlt_daemon_event_handler::dlt_connection_check_activate*/ -/* TEST(t_dlt_connection_check_activate, normal) { int ret; DltEventHandler evhdl = {}; DltReceiver receiver = {}; DltConnection con = {}; - DltFilterConfiguration current = {}; - DltMessageFilter filter = {}; receiver.fd = 1; - filter.current = ¤t; con.receiver = &receiver; con.status = INACTIVE; con.type = DLT_CONNECTION_CLIENT_MSG_TCP; EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_prepare_event_handling(&evhdl)); - + + ret = dlt_connection_check_activate(&evhdl, &con, ACTIVATE); EXPECT_EQ(DLT_RETURN_OK, ret); ret = dlt_connection_check_activate(&evhdl, &con, DEACTIVATE); @@ -250,7 +222,7 @@ TEST(t_dlt_connection_check_activate, nullpointer) { EXPECT_EQ(DLT_RETURN_ERROR, dlt_connection_check_activate(NULL, NULL, DEACTIVATE)); } -*/ + /* Begin Method: dlt_daemon_event_handler::dlt_event_handler_register_connection*/ TEST(t_dlt_event_handler_register_connection, normal) { @@ -260,7 +232,6 @@ TEST(t_dlt_event_handler_register_connection, normal) DltEventHandler ev1 = {}; DltConnection *connections1 = nullptr; DltReceiver receiver = {}; - DltFilterConfiguration current = {}; EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_prepare_event_handling(&ev1)); @@ -270,7 +241,6 @@ TEST(t_dlt_event_handler_register_connection, normal) connections1->type = DLT_CONNECTION_GATEWAY; connections1->receiver = &receiver; - daemon_local.pFilter.current = ¤t; ret = dlt_event_handler_register_connection(&ev1, &daemon_local, @@ -298,7 +268,6 @@ TEST(t_dlt_event_handler_unregister_connection, normal) DltEventHandler ev1 = {}; DltConnection *connections1 = nullptr; DltReceiver receiver = {}; - DltFilterConfiguration current = {}; EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_prepare_event_handling(&ev1)); @@ -308,10 +277,7 @@ TEST(t_dlt_event_handler_unregister_connection, normal) connections1->next = 0; connections1->type = DLT_CONNECTION_GATEWAY; connections1->receiver = &receiver; - - receiver.fd = 1; - - daemon_local.pFilter.current = ¤t; + receiver.fd = 100; ret = dlt_event_handler_register_connection(&ev1, &daemon_local, @@ -320,7 +286,7 @@ TEST(t_dlt_event_handler_unregister_connection, normal) EXPECT_EQ(DLT_RETURN_OK, ret); EXPECT_EQ(DLT_CONNECTION_GATEWAY, ev1.connections->type); - ret = dlt_event_handler_unregister_connection(&ev1, &daemon_local, 1); + ret = dlt_event_handler_unregister_connection(&ev1, &daemon_local, receiver.fd); EXPECT_EQ(DLT_RETURN_OK, ret); free(ev1.pfd); @@ -329,13 +295,9 @@ TEST(t_dlt_event_handler_unregister_connection, normal) /* Begin Method: dlt_daemon_connections::dlt_connection_create*/ TEST(t_dlt_connection_create, normal) { - int fd = 1; + int fd = 100; int ret = 0; DltDaemonLocal daemon_local = {}; - DltFilterConfiguration current = {}; - - - daemon_local.pFilter.current = ¤t; EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_prepare_event_handling(&daemon_local.pEvent)); @@ -451,7 +413,6 @@ TEST(t_dlt_connection_send, normal_1) receiver.fd = connectServer(); EXPECT_NE(-1, receiver.fd); - conn.receiver = &receiver; conn.type = DLT_CONNECTION_CLIENT_MSG_TCP; @@ -470,6 +431,9 @@ TEST(t_dlt_connection_send, normal_1) ret = dlt_connection_send(&conn, data1, size1); EXPECT_EQ(DLT_RETURN_OK, ret); + + close(receiver.fd); + free(daemon_local.msg.databuffer); } TEST(t_dlt_connection_send, normal_2) @@ -481,10 +445,12 @@ TEST(t_dlt_connection_send, normal_2) receiver.fd = 1; conn.receiver = &receiver; conn.type = DLT_CONNECTION_CLIENT_MSG_SERIAL; + ret = dlt_connection_send(&conn, (void *)dltSerialHeader, sizeof(dltSerialHeader)); - EXPECT_EQ(sizeof(dltSerialHeader), ret); + + EXPECT_EQ(DLT_RETURN_OK, ret); } TEST(t_dlt_connection_send, abnormal) @@ -496,6 +462,7 @@ TEST(t_dlt_connection_send, abnormal) receiver.fd = -1; conn.receiver = &receiver; conn.type = DLT_CONNECTION_TYPE_MAX; + ret = dlt_connection_send(&conn, (void *)dltSerialHeader, sizeof(dltSerialHeader)); @@ -520,17 +487,44 @@ TEST(t_dlt_connection_send_multiple, normal_1) size2 = daemon_local.msg.datasize; receiver.fd = connectServer(); - EXPECT_NE(-1,receiver.fd); + EXPECT_NE(-1, receiver.fd); + conn.receiver = &receiver; conn.type = DLT_CONNECTION_CLIENT_MSG_TCP; + + daemon_local.msg.headersize = sizeof(DltStorageHeader) + + sizeof(DltStandardHeader) + + sizeof(DltStandardHeaderExtra) + + sizeof(DltExtendedHeader); + + memset(daemon_local.msg.headerbuffer, 0, daemon_local.msg.headersize); + + data1 = daemon_local.msg.headerbuffer + sizeof(DltStorageHeader); + size1 = daemon_local.msg.headersize - sizeof(DltStorageHeader); + + daemon_local.msg.databuffer = (uint8_t *)malloc(sizeof(uint8_t)); + if (daemon_local.msg.databuffer == NULL) + close(receiver.fd); + + EXPECT_NE((uint8_t *)NULL, daemon_local.msg.databuffer); + + memset(daemon_local.msg.databuffer, 0, sizeof(uint8_t)); + daemon_local.msg.datasize = sizeof(uint8_t); + + data2 = daemon_local.msg.databuffer; + size2 = daemon_local.msg.datasize; + ret = dlt_connection_send_multiple(&conn, data1, size1, data2, size2, 1); + EXPECT_EQ(DLT_RETURN_OK, ret); + close(receiver.fd); + free(daemon_local.msg.databuffer); } TEST(t_dlt_connection_send_multiple, normal_2) @@ -550,18 +544,44 @@ TEST(t_dlt_connection_send_multiple, normal_2) size2 = daemon_local.msg.datasize; receiver.fd = connectServer(); - EXPECT_NE(-1,receiver.fd); + EXPECT_NE(-1, receiver.fd); + conn.receiver = &receiver; conn.type = DLT_CONNECTION_CLIENT_MSG_TCP; + daemon_local.msg.headersize = sizeof(DltStorageHeader) + + sizeof(DltStandardHeader) + + sizeof(DltStandardHeaderExtra) + + sizeof(DltExtendedHeader); + + memset(daemon_local.msg.headerbuffer, 0, daemon_local.msg.headersize); + + data1 = daemon_local.msg.headerbuffer + sizeof(DltStorageHeader); + size1 = daemon_local.msg.headersize - sizeof(DltStorageHeader); + + daemon_local.msg.databuffer = (uint8_t *)malloc(sizeof(uint8_t)); + if (daemon_local.msg.databuffer == NULL) + close(receiver.fd); + + EXPECT_NE((uint8_t *)NULL, daemon_local.msg.databuffer); + + memset(daemon_local.msg.databuffer, 0, sizeof(uint8_t)); + daemon_local.msg.datasize = sizeof(uint8_t); + + data2 = daemon_local.msg.databuffer; + size2 = daemon_local.msg.datasize; + ret = dlt_connection_send_multiple(&conn, data1, size1, data2, size2, 0); + EXPECT_EQ(DLT_RETURN_OK, ret); + close(receiver.fd); + free(daemon_local.msg.databuffer); } TEST(t_dlt_connection_send_multiple, nullpointer) @@ -584,6 +604,7 @@ TEST(t_dlt_connection_send_multiple, nullpointer) data2, size2, 0); + EXPECT_EQ(DLT_RETURN_ERROR, ret); } @@ -615,6 +636,8 @@ int connectServer(void) return sockfd; } +#define GTEST_SOCKS_ACCEPTED 3 + int main(int argc, char **argv) { pid_t cpid = fork(); @@ -662,6 +685,7 @@ int main(int argc, char **argv) if(j == -1) { perror("Bind Error\n"); + close(sockfd); return -1; } @@ -682,8 +706,11 @@ int main(int argc, char **argv) bzero(buffer, 256); (void)(read(newsockfd[i - 1], buffer, 255) + 1); /* just ignore result */ i--; - close(newsockfd); } + + for(j = 0; j < GTEST_SOCKS_ACCEPTED; j++) + close(newsockfd[i]); + close(sockfd); } else @@ -691,7 +718,7 @@ int main(int argc, char **argv) ::testing::InitGoogleTest(&argc, argv); ::testing::FLAGS_gtest_break_on_failure = false; - //::testing::FLAGS_gtest_filter = "t_dlt_connection_send_multiple*"; +// ::testing::FLAGS_gtest_filter = "t_dlt_event_handler_register_connection*"; return RUN_ALL_TESTS(); } return 0; diff --git a/tests/gtest_dlt_daemon_gateway.cpp b/tests/gtest_dlt_daemon_gateway.cpp index f681243..d07c35d 100644 --- a/tests/gtest_dlt_daemon_gateway.cpp +++ b/tests/gtest_dlt_daemon_gateway.cpp @@ -62,7 +62,7 @@ extern "C" { #include "dlt_gateway.h" -#include "gtest_common.h" +#include "dlt_gateway_internal.h" } /* Begin Method: dlt_gateway::t_dlt_gateway_init*/ @@ -73,11 +73,12 @@ TEST(t_dlt_gateway_init, normal) 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.pfd = 0; + daemon_local.pEvent.nfds = 0; + daemon_local.pEvent.max_nfds = 0; daemon_local.pEvent.connections->receiver = &receiver; daemon_local.pEvent.connections->next = NULL; memset(daemon_local.flags.gatewayConfigFile,0,DLT_DAEMON_FLAG_MAX); @@ -90,8 +91,7 @@ TEST(t_dlt_gateway_init, normal) TEST(t_dlt_gateway_init, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_init(NULL, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_init(NULL, 0)); } /* Begin Method: dlt_gateway::t_dlt_gateway_send_control_message*/ @@ -99,14 +99,15 @@ 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; daemon_local.pGateway.connections = &connections; daemon_local.pEvent.connections = &connections1; daemon_local.pEvent.connections->next = NULL; + daemon_local.pEvent.pfd = 0; + daemon_local.pEvent.nfds = 0; + daemon_local.pEvent.max_nfds = 0; 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); @@ -120,15 +121,14 @@ TEST(t_dlt_gateway_send_control_message, Normal) TEST(t_dlt_gateway_send_control_message, nullpointer) { - //NULL-Pointer, expect -1 - dlt_gateway_send_control_message(NULL, NULL, NULL, 0); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_send_control_message(NULL, NULL, NULL, 0)); } /* Begin Method: dlt_gateway::t_dlt_gateway_store_connection*/ TEST(t_dlt_gateway_store_connection, normal) { char ip_address[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "10.113.100.100"; - char ecuid[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "1234"; + char ecuid[] = "1234"; DltGateway gateway; DltGatewayConnection tmp; DltGatewayConnection tmp1; @@ -152,11 +152,10 @@ TEST(t_dlt_gateway_store_connection, normal) 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)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_store_connection(NULL , NULL, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_store_connection(&gateway , NULL, 0)); } /* Begin Method: dlt_gateway::t_dlt_gateway_check_ip*/ @@ -172,8 +171,7 @@ TEST(t_dlt_gateway_check_ip, normal) TEST(t_dlt_gateway_check_ip, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_ip(NULL,NULL)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_check_ip(NULL, NULL)); } /* Begin Method: dlt_gateway::t_dlt_gateway_check_send_serial*/ @@ -189,8 +187,7 @@ TEST(t_dlt_gateway_check_send_serial, normal) TEST(t_dlt_gateway_check_send_serial, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_send_serial(NULL,NULL)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_check_send_serial(NULL, NULL)); } /* Begin Method: dlt_gateway::t_dlt_gateway_allocate_control_messages*/ @@ -205,7 +202,7 @@ TEST(t_dlt_gateway_allocate_control_messages, normal) TEST(t_dlt_gateway_allocate_control_messages, nullpointer) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_allocate_control_messages(NULL)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_allocate_control_messages(NULL)); } /* Begin Method: dlt_gateway::t_dlt_gateway_check_control_messages*/ @@ -221,8 +218,7 @@ TEST(t_dlt_gateway_check_control_messages, normal) TEST(t_dlt_gateway_check_control_messages, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_control_messages(NULL,NULL)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_check_control_messages(NULL, NULL)); } /* Begin Method: dlt_gateway::t_dlt_gateway_check_periodic_control_messages*/ @@ -238,7 +234,7 @@ TEST(t_dlt_gateway_check_periodic_control_messages, normal) TEST(t_dlt_gateway_check_periodic_control_messages, nullpointer) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_periodic_control_messages(NULL,NULL)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_check_periodic_control_messages(NULL, NULL)); } /* Begin Method: dlt_gateway::t_dlt_gateway_check_port*/ @@ -264,8 +260,7 @@ TEST(t_dlt_gateway_check_port, abnormal) TEST(t_dlt_gateway_check_port, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_port(NULL,NULL)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_check_port(NULL, NULL)); } /* Begin Method: dlt_gateway::t_dlt_gateway_check_ecu*/ @@ -281,8 +276,7 @@ TEST(t_dlt_gateway_check_ecu, normal) TEST(t_dlt_gateway_check_ecu, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_ecu(NULL,NULL)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_check_ecu(NULL, NULL)); } /* Begin Method: dlt_gateway::t_dlt_gateway_check_connect_trigger*/ @@ -308,8 +302,7 @@ TEST(t_dlt_gateway_check_connect_trigger, abnormal) TEST(t_dlt_gateway_check_connect_trigger, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_connect_trigger(NULL,NULL)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_check_connect_trigger(NULL, NULL)); } /* Begin Method: dlt_gateway::t_dlt_gateway_check_timeout*/ @@ -335,8 +328,7 @@ TEST(t_dlt_gateway_check_timeout, abnormal) TEST(t_dlt_gateway_check_timeout, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_timeout(NULL,NULL)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_check_timeout(NULL, NULL)); } /* Begin Method: dlt_gateway::t_dlt_gateway_establish_connections*/ @@ -355,8 +347,7 @@ TEST(t_dlt_gateway_establish_connections, normal) TEST(t_dlt_gateway_establish_connections, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_establish_connections(NULL,NULL,0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_establish_connections(NULL, NULL, 0)); } /* Begin Method: dlt_gateway::t_dlt_gateway_get_connection_receiver*/ @@ -393,7 +384,6 @@ TEST(t_dlt_gateway_get_connection_receiver, abnormal) TEST(t_dlt_gateway_get_connection_receiver, nullpointer) { - // NULL-Pointer, expect -1 DltReceiver *ret; ret = dlt_gateway_get_connection_receiver(NULL, 0); @@ -404,10 +394,11 @@ TEST(t_dlt_gateway_get_connection_receiver, nullpointer) TEST(t_dlt_gateway_parse_get_log_info, normal) { int32_t len; + int32_t ret = DLT_RETURN_ERROR; DltDaemon daemon; DltGateway gateway; DltMessage msg; - char ecuid[DLT_CONFIG_FILE_ENTRY_MAX_LEN] = "ECU2"; + char ecuid[] = "ECU2"; uint32_t sid = DLT_SERVICE_ID_GET_LOG_INFO; uint8_t status = 7; uint16_t count_app_ids = 1; @@ -422,15 +413,20 @@ TEST(t_dlt_gateway_parse_get_log_info, normal) 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); + + ret = strncmp(daemon.ecuid, daemon.user_list[0].ecu, DLT_ID_SIZE); + ASSERT_EQ(DLT_RETURN_OK, ret); /* create response message */ msg.datasize = sizeof(DltServiceGetLogInfoResponse) + sizeof(AppIDsType) + - sizeof(ContextIDsInfoType); + sizeof(ContextIDsInfoType) + + strlen(app_description) + + strlen(context_description); msg.databuffer = (uint8_t *) malloc(msg.datasize); msg.databuffersize = msg.datasize; memset(msg.databuffer, 0, msg.datasize); @@ -502,12 +498,12 @@ TEST(t_dlt_gateway_parse_get_log_info, normal) 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)); + EXPECT_EQ(DLT_RETURN_OK, dlt_gateway_parse_get_log_info(&daemon, ecuid, &msg, CONTROL_MESSAGE_NOT_REQUESTED, 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)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_parse_get_log_info(NULL, NULL, NULL, 0, 0)); } /* Begin Method: dlt_gateway::t_dlt_gateway_process_passive_node_messages*/ @@ -530,8 +526,7 @@ TEST(t_dlt_gateway_process_passive_node_messages, normal) TEST(t_dlt_gateway_process_passive_node_messages, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_process_passive_node_messages(NULL, NULL, NULL, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_process_passive_node_messages(NULL, NULL, NULL, 0)); } /* Begin Method: dlt_gateway::t_dlt_gateway_process_gateway_timer*/ @@ -560,8 +555,7 @@ TEST(t_dlt_gateway_process_gateway_timer, normal) TEST(t_dlt_gateway_process_gateway_timer, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_process_gateway_timer(NULL, NULL, NULL, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_process_gateway_timer(NULL, NULL, NULL, 0)); } /* Begin Method: dlt_gateway::t_dlt_gateway_process_on_demand_request*/ @@ -604,9 +598,8 @@ TEST(t_dlt_gateway_process_on_demand_request, abnormal) TEST(t_dlt_gateway_process_on_demand_request, nullpointer) { - // NULL-Pointer, expect -1 char node_id[DLT_ID_SIZE] = "123"; - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_process_on_demand_request(NULL, NULL, node_id, 1, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_process_on_demand_request(NULL, NULL, node_id, 1, 0)); } /* Begin Method: dlt_gateway::t_dlt_gateway_check_param*/ @@ -644,8 +637,7 @@ TEST(t_dlt_gateway_check_param, abnormal) TEST(t_dlt_gateway_check_param, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_check_param(NULL, NULL, GW_CONF_PORT, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_check_param(NULL, NULL, GW_CONF_PORT, 0)); } /* Begin Method: dlt_gateway::t_dlt_gateway_configure*/ @@ -663,8 +655,7 @@ TEST(t_dlt_gateway_configure, Normal) TEST(t_dlt_gateway_configure, nullpointer) { - // NULL-Pointer, expect -1 - EXPECT_EQ(DLT_RETURN_ERROR, dlt_gateway_configure(NULL, NULL, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_gateway_configure(NULL, NULL, 0)); } int main(int argc, char **argv) diff --git a/tests/g_test_dlt_daemon_gateway.sh b/tests/gtest_dlt_daemon_gateway.sh index 85f37db..21cc82e 100755 --- a/tests/g_test_dlt_daemon_gateway.sh +++ b/tests/gtest_dlt_daemon_gateway.sh @@ -24,9 +24,24 @@ #Description : gateway unit test preparation # #Author Name : Onkar Palkar +# Jeevan Ramakant Nagvekar #Email Id : onkar.palkar@wipro.com +# jeevan.nagvekar1@wipro.com # -#History : Last modified date : 29/07/2016 +#History : Last modified date : 31/07/2018 + +ipaddr=127.0.0.1 + +################################################################################ +# Function: -getOSname() +# +# Description -Retrieves OS name +# +getOSname() +{ + OS="`uname`" +} + ################################################################################ # # Function: -cleanup() @@ -38,24 +53,60 @@ # Return -Zero on success # -Non zero on failure # -ipaddr=127.0.0.1 - cleanup() { tmpPath=/tmp + + if [ "$OS" = "QNX" ] + then + PIDOF() + { + slay -p $1 > /dev/null + if [ $? -eq '0' ] + then + return 1 + else + return 0 + fi + } + KILLALL() + { + slay -9 -f $1 > /dev/null + if [ $? -eq '0' ] + then + return 1 + else + return 0 + fi + } + else + PIDOF() + { + pidof $1 > /dev/null + return $? + } + KILLALL() + { + killall $1 > /dev/null + return $? + } + fi + cd $tmpPath - pidof dlt-daemon > /dev/null + + PIDOF dlt-daemon if [ $? -eq '0' ] then - killall dlt-daemon + KILLALL dlt-daemon if [ $? -eq '1' ] then echo "Failed to kill daemons" return 1 fi fi - rm $tmpPath/dlt.conf - rm $tmpPath/idlt_gateway.conf + + rm -f $tmpPath/dlt.conf + rm -f $tmpPath/dlt_gateway.conf return 0 } # @@ -82,7 +133,7 @@ setupTest() return 1 fi echo "SendContextRegistration = 1" >>$tmpPath/dlt.conf - echo "ECUId = ECU1" >>$tmpPath/dlt.conf + echo "ECUId = ECU2" >>$tmpPath/dlt.conf echo "GatewayMode = 1" >>$tmpPath/dlt.conf echo "SharedMemorySize = 100000" >>$tmpPath/dlt.conf echo "LoggingMode = 0" >>$tmpPath/dlt.conf @@ -93,7 +144,7 @@ setupTest() echo "RingbufferMaxSize = 10000000" >>$tmpPath/dlt.conf echo "RingbufferStepSize = 500000" >>$tmpPath/dlt.conf echo "ControlSocketPath = /tmp/dlt-ctrl.sock" >>$tmpPath/dlt.conf - echo "GatewayConfigFile = /tmp/$tmpFolder/dlt_gateway.conf" >>$tmpPath/dlt.conf + echo "GatewayConfigFile = /tmp/dlt_gateway.conf" >>$tmpPath/dlt.conf touch $tmpPath/dlt_gateway.conf if [ $? -eq '1' ] then @@ -102,7 +153,7 @@ setupTest() fi echo "[PassiveNode1]" >>$tmpPath/dlt_gateway.conf echo "IPaddress=$ipaddr">>$tmpPath/dlt_gateway.conf - echo "Port=3495" >>$tmpPath/dlt_gateway.conf + echo "Port=3490" >>$tmpPath/dlt_gateway.conf echo "EcuID=ECU1" >>$tmpPath/dlt_gateway.conf echo "Connect=OnStartup" >>$tmpPath/dlt_gateway.conf echo "Timeout=10" >>$tmpPath/dlt_gateway.conf @@ -115,25 +166,76 @@ setupTest() # Function: -startDaemons() # # Description -Start dlt-daemon as passive node +# -Start dlt-daemon as gateway node # # Return -Zero on success # -Non zero on failure # startDaemons() { - dlt-daemon -p 3495 + tmpPath=/tmp + dlt-daemon -d + dlt-daemon -d -p 3495 -c $tmpPath/dlt.conf return 0 } + +# +# Function: -checkDaemonStart +# +# Description -Check if dlt-daemon instances started successfully +# +checkDaemonStart() +{ + if [ "$OS" = "QNX" ]; then + slay -p dlt-daemon > /dev/null + total=$? + else + total=`pgrep -c dlt-daemon` + fi + + if [ $total -ne '2' ]; then + echo "Initialization of dlt-daemon instances failed" + exit + fi +} + +help() +{ + echo "Usage: " + echo "sh ./gtest_dlt_daemon_gateway.sh" +} + +executeTests() +{ + echo "Execute: gtest_dlt_daemon_gateway unit test" +} + #main function ######################################################################################## + +getOSname + +echo "Cleaning up dlt-daemon instances" cleanup + if [ $? -ne '0' ] then -return 1 + help + exit fi + +echo "Initializing test" setupTest + if [ $? -ne '0' ] then -return 1 + help + exit fi + +echo "Restarting dlt-daemons" startDaemons + +checkDaemonStart + +executeTests diff --git a/tests/gtest_dlt_daemon_logstorage.sh b/tests/gtest_dlt_daemon_logstorage.sh new file mode 100755 index 0000000..704feb7 --- /dev/null +++ b/tests/gtest_dlt_daemon_logstorage.sh @@ -0,0 +1,57 @@ +#!/bin/sh +######################################################################################## +#file : g_test_dlt_daemon_logstorage.sh +# +#Description : logstorage unit test preparation +# +#Author Name : Onkar Palkar +#Email Id : onkar.palkar@wipro.com +# +#History : Last modified date : 02/09/2016 +######################################################################################## +# +# Function: -cleanup() +# +# Description -Delete dlt_logstorage.conf file from tmp folder if present +# +# Return -Zero on success +# -Non zero on failure +# + +cleanup() +{ + tmpPath=/tmp + cd $tmpPath + rm -rf $tmpPath/dlt_logstorage.conf + return 0 +} + +# +# Function: -setupTest() +# +# Description -create logstorage.conf file +# +# Return -Zero on success +# -Non zero on failure +# +setupTest() +{ + touch $tmpPath/dlt_logstorage.conf + if [ $? -eq '1' ] + then + echo "Error in creating dlt_logstorage.conf file" + return 1 + fi + echo "[FILTER1]" >>$tmpPath/dlt_logstorage.conf + echo "LogAppName=DLST" >>$tmpPath/dlt_logstorage.conf + echo "ContextName=.*" >>$tmpPath/dlt_logstorage.conf + echo "LogLevel=DLT_LOG_ERROR" >>$tmpPath/dlt_logstorage.conf + echo "File=Test" >>$tmpPath/dlt_logstorage.conf + echo "FileSize=1000000" >>$tmpPath/dlt_logstorage.conf + echo "NOFiles=1" >>$tmpPath/dlt_logstorage.conf + return 0 +} +#main function +######################################################################################## +cleanup +setupTest diff --git a/tests/gtest_dlt_daemon_offline_log.cpp b/tests/gtest_dlt_daemon_offline_log.cpp index 7711839..f2848a1 100644 --- a/tests/gtest_dlt_daemon_offline_log.cpp +++ b/tests/gtest_dlt_daemon_offline_log.cpp @@ -11,83 +11,129 @@ */ #include <gtest/gtest.h> +int connectServer(void); + extern "C" { #include "dlt_offline_logstorage.h" +#include "dlt_offline_logstorage_internal.h" #include "dlt_offline_logstorage_behavior.h" +#include "dlt_offline_logstorage_behavior_internal.h" #include "dlt_daemon_offline_logstorage.h" +#include "dlt_daemon_offline_logstorage_internal.h" #include "dlt_daemon_common_cfg.h" -#include "gtest_common.h" +#include <netdb.h> +#include <netinet/in.h> +#include <sys/types.h> +#include <sys/socket.h> } #ifndef DLT_DAEMON_BLOCKING_TEST #define DLT_DAEMON_BLOCKING_TEST 1 #endif -/* Begin Method: dlt_logstorage::t_dlt_logstorage_hash_create*/ -TEST(t_dlt_logstorage_hash_create, normal) +/* Begin Method: dlt_logstorage::t_dlt_logstorage_hash_add*/ +TEST(t_dlt_logstorage_hash_add, normal) { - struct hsearch_data htab; + DltLogStorageFilterList *list = NULL; + DltLogStorageFilterConfig *data = NULL; + char key = 1; + + data = (DltLogStorageFilterConfig *) calloc(1, sizeof(DltLogStorageFilterConfig)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&htab)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&htab)); + if (data != NULL) + { + dlt_logstorage_filter_set_strategy(data, DLT_LOGSTORAGE_SYNC_ON_MSG); + + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(&key, data, &list)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_destroy(&list, 0)); + } } -/* Begin Method: dlt_logstorage::t_dlt_logstorage_hash_add*/ -TEST(t_dlt_logstorage_hash_add, normal) +/* Begin Method: dlt_logstorage::t_dlt_logstorage_list_add_config*/ +TEST(t_dlt_logstorage_list_add_config, normal) { - struct hsearch_data htab; - char key = 1; - char value = 5; + DltLogStorageFilterConfig *data = NULL; + DltLogStorageFilterConfig *listdata = NULL; + + data = (DltLogStorageFilterConfig *) calloc(1, sizeof(DltLogStorageFilterConfig)); + listdata = (DltLogStorageFilterConfig *) calloc(1, sizeof(DltLogStorageFilterConfig)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&htab)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(&key, &value, &htab)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&htab)); + if ((data != NULL) && (listdata != NULL)) + { + dlt_logstorage_list_add_config(data, &listdata); + free(data); + free(listdata); + } } /* Begin Method: dlt_logstorage::t_dlt_logstorage_hash_destroy*/ TEST(t_dlt_logstorage_hash_destroy, normal) { - struct hsearch_data htab; + DltLogStorageFilterList *list = NULL; + DltLogStorageFilterConfig *data = NULL; char key = 1; - char value = 5; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&htab)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(&key, &value, &htab)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&htab)); + data = (DltLogStorageFilterConfig *) calloc(1, sizeof(DltLogStorageFilterConfig)); + + if (data != NULL) + { + dlt_logstorage_filter_set_strategy(data, DLT_LOGSTORAGE_SYNC_ON_MSG); + + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(&key, data, &list)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_destroy(&list, 0)); + } } /* Begin Method: dlt_logstorage::t_dlt_logstorage_hash_find*/ TEST(t_dlt_logstorage_hash_find, normal) { - struct hsearch_data htab; - char key = 1; - char value = 5; - char *retData; + DltLogStorageFilterList *list = NULL; + DltLogStorageFilterConfig *data = NULL; + DltLogStorageFilterConfig *retData; + char key[] = "1"; + char apid[] = "1234"; + char ctid[] = "5678"; + + data = (DltLogStorageFilterConfig *) calloc(1, sizeof(DltLogStorageFilterConfig)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&htab)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(&key, &value, &htab)); + if (data != NULL) + { + data->apids = strdup(apid); + data->ctids = strdup(ctid); + dlt_logstorage_filter_set_strategy(data, DLT_LOGSTORAGE_SYNC_ON_MSG); - retData = (char*)dlt_logstorage_hash_find(&key, &htab); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, data, &list)); - EXPECT_EQ(5, *retData); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&htab)); + retData = (DltLogStorageFilterConfig*)dlt_logstorage_list_find(key, &list); + EXPECT_NE((DltLogStorageFilterConfig *)NULL, retData); + + if (retData != NULL) + { + EXPECT_STREQ(apid, retData->apids); + EXPECT_STREQ(ctid, retData->ctids); + } + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_destroy(&list, 0)); + } } /* Begin Method: dlt_logstorage::t_dlt_logstorage_free*/ TEST(t_dlt_logstorage_free, normal) { char key = 1; - char value = 5; DltLogStorage handle; + DltLogStorageFilterConfig *data = NULL; int reason = 0; handle.num_configs = 0; - handle.filter_keys = (char *)calloc (1, sizeof(char)); - handle.configs = (DltLogStorageFilterConfig *)calloc (1, sizeof(DltLogStorageFilterConfig)); - if(handle.filter_keys != NULL && handle.configs != NULL) + handle.config_list = NULL; + + data = (DltLogStorageFilterConfig *) calloc(1, sizeof(DltLogStorageFilterConfig)); + + if(data != NULL) { - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&handle.config_htab)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(&key, &value, &handle.config_htab)); + dlt_logstorage_filter_set_strategy(data, DLT_LOGSTORAGE_SYNC_ON_MSG); + + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(&key, data, &handle.config_list)); dlt_logstorage_free(&handle, reason); } @@ -129,12 +175,13 @@ TEST(t_dlt_logstorage_create_keys, normal) DltLogStorageFilterConfig data; char *keys = NULL; int num_keys = 0; - char apids; - char ctids; - data.apids = &apids; - data.ctids = &ctids; + char apids[] = "1234"; + char ctids[] = "5678"; + char ecuid[] = "ECU1"; + data.apids = apids; + data.ctids = ctids; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_create_keys(data.apids, data.ctids, &keys, &num_keys)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_create_keys(data.apids, data.ctids, ecuid, &keys, &num_keys)); } /* Begin Method: dlt_logstorage::t_dlt_logstorage_prepare_table*/ @@ -144,20 +191,19 @@ TEST(t_dlt_logstorage_prepare_table, normal) DltLogStorageFilterConfig data; memset(&handle, 0, sizeof(DltLogStorage)); memset(&data, 0, sizeof(DltLogStorageFilterConfig)); - char apids; - char ctids; - char filter_keys; - data.apids = &apids; - data.ctids = &ctids; + char apids[] = "1234"; + char ctids[] = "5678"; + data.apids = apids; + data.ctids = ctids; handle.num_filter_keys = 1; data.records = NULL; data.log = NULL; data.cache = NULL; - handle.filter_keys = &filter_keys; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&handle.config_htab)); + dlt_logstorage_filter_set_strategy(&data, DLT_LOGSTORAGE_SYNC_ON_MSG); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_table(&handle, &data)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&handle.config_htab)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_destroy(&handle.config_list, 0)); } TEST(t_dlt_logstorage_prepare_table, null) @@ -343,7 +389,7 @@ TEST(t_dlt_logstorage_check_sync_strategy, abnormal) DltLogStorageFilterConfig config; config.sync = 0; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_check_sync_strategy(&config, value)); + EXPECT_EQ(DLT_RETURN_TRUE, dlt_logstorage_check_sync_strategy(&config, value)); EXPECT_EQ(DLT_LOGSTORAGE_SYNC_ON_MSG, config.sync); } @@ -399,18 +445,15 @@ TEST(t_dlt_logstorage_store_filters, normal) handle.write_errors = 0; handle.num_filter_keys = 0; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&(handle.config_htab))); - - handle.configs = NULL; - handle.filter_keys = NULL; + handle.config_list = NULL; EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_store_filters(&handle, config_file_name)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&handle.config_htab)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_destroy(&handle.config_list, 0)); } TEST(t_dlt_logstorage_store_filters, null) { - EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_store_filters(NULL, NULL)); + EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_store_filters(NULL, NULL)); } /* Begin Method: dlt_logstorage::t_dlt_logstorage_load_config*/ @@ -421,12 +464,11 @@ TEST(t_dlt_logstorage_load_config, normal) handle.config_status = 0; handle.write_errors = 0; handle.num_filter_keys = 0; - handle.configs = NULL; - handle.filter_keys = NULL; + handle.config_list = NULL; strncpy(handle.device_mount_point, "/tmp", DLT_MOUNT_PATH_MAX); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_load_config(&handle)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_destroy(&handle.config_htab)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_destroy(&handle.config_list, 0)); } TEST(t_dlt_logstorage_load_config, null) @@ -438,11 +480,14 @@ TEST(t_dlt_logstorage_load_config, null) TEST(t_dlt_logstorage_device_connected, normal) { DltLogStorage handle; - char mount_point[DLT_MOUNT_PATH_MAX] = "/tmp"; + handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED; handle.config_status = 0; - handle.connection_type = 0; + handle.write_errors = 0; + handle.num_filter_keys = 0; + handle.config_list = NULL; + strncpy(handle.device_mount_point, "/tmp", DLT_MOUNT_PATH_MAX); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_device_connected(&handle, mount_point)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_device_connected(&handle, handle.device_mount_point)); } TEST(t_dlt_logstorage_device_connected, null) @@ -469,17 +514,24 @@ TEST(t_dlt_logstorage_get_loglevel_by_key, normal) { char arr[] = "abc"; char *key = arr; - DltLogStorageFilterConfig config; + DltLogStorageFilterConfig* config = NULL; DltLogStorage handle; handle.config_status = 0; handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; + handle.config_list = NULL; + + config = (DltLogStorageFilterConfig *) calloc(1, sizeof(DltLogStorageFilterConfig)); - config.log_level = DLT_LOG_ERROR; + if (config != NULL) + { + config->log_level = DLT_LOG_ERROR; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5,&(handle.config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key, &config, &(handle.config_htab))); - EXPECT_GE(DLT_LOG_ERROR, dlt_logstorage_get_loglevel_by_key(&handle, key)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, config, &(handle.config_list))); + EXPECT_GE(DLT_LOG_ERROR, dlt_logstorage_get_loglevel_by_key(&handle, key)); + + free(config); + } } TEST(t_dlt_logstorage_get_loglevel_by_key, null) @@ -493,26 +545,28 @@ TEST(t_dlt_logstorage_get_config, normal) char apid[] = "1234"; char ctid[] = "5678"; char ecuid[] = "12"; + char file_name[] = "file_name"; int num_config = 0; DltLogStorageFilterConfig value; value.log_level = 0; value.apids = apid; value.ctids = ctid; value.ecuid = ecuid; - char key0[] = "1234:\000\000\000\000"; - char key1[] = ":5678\000\000\000\000"; - char key2[] = "1234:5678"; + value.file_name = file_name; + char key0[] = ":1234:\000\000\000\000"; + char key1[] = "::5678\000\000\000\000"; + char key2[] = ":1234:5678"; DltLogStorageFilterConfig *config[3] = {0}; DltLogStorage handle; handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; + handle.config_list = NULL; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5, &(handle.config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key0, &value, &(handle.config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key1, &value, &(handle.config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key2, &value, &(handle.config_htab))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, &value, &(handle.config_list))); - num_config = dlt_logstorage_get_config(&handle, config, apid, ctid); + num_config = dlt_logstorage_get_config(&handle, config, apid, ctid, ecuid); EXPECT_EQ(num_config, 3); } @@ -520,7 +574,7 @@ TEST(t_dlt_logstorage_get_config, normal) TEST(t_dlt_logstorage_get_config, null) { int num = -1; - num = dlt_logstorage_get_config(NULL, NULL, NULL, NULL); + num = dlt_logstorage_get_config(NULL, NULL, NULL, NULL, NULL); EXPECT_EQ(num, 0); } @@ -531,23 +585,26 @@ TEST(t_dlt_logstorage_filter, normal) char apid[] = "1234"; char ctid[] = "5678"; char ecuid[] = "12"; + char filename[] = "file_name"; int num = 1; DltLogStorageFilterConfig value; value.apids = apid; value.ctids = ctid; value.ecuid = ecuid; - char key0[] = "1234:\000\000\000\000"; - char key1[] = ":5678\000\000\000\000"; - char key2[] = "1234:5678"; - DltLogStorageFilterConfig *config[3] = {0}; + value.file_name = filename; + value.log_level = DLT_LOG_VERBOSE; + char key0[] = ":1234:\000\000\000\000"; + char key1[] = "::5678\000\000\000\000"; + char key2[] = ":1234:5678"; + DltLogStorageFilterConfig *config[DLT_OFFLINE_LOGSTORAGE_MAX_POSSIBLE_CONFIGS] = {0}; DltLogStorage handle; handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; + handle.config_list = NULL; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5, &(handle.config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key0, &value, &(handle.config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key1, &value, &(handle.config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key2, &value, &(handle.config_htab))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, &value, &(handle.config_list))); num = dlt_logstorage_filter(&handle, config, apid, ctid, ecuid, 0); @@ -558,7 +615,7 @@ TEST(t_dlt_logstorage_filter, null) { DltLogStorageFilterConfig *config[3] = {0}; int num = dlt_logstorage_filter(NULL, config, NULL, NULL, NULL, 0); - EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, num); + EXPECT_EQ(DLT_RETURN_ERROR, num); } /* Begin Method: dlt_logstorage::t_dlt_logstorage_write*/ @@ -567,6 +624,7 @@ TEST(t_dlt_logstorage_write, normal) char apid[] = "1234"; char ctid[] = "5678"; char ecuid[] = "12"; + char file_name[] = "file_name"; DltLogStorage handle; DltLogStorageUserConfig uconfig; unsigned char data1[] = "123"; @@ -577,18 +635,19 @@ TEST(t_dlt_logstorage_write, normal) int size3 = 3; handle.connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; handle.config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; + handle.config_list = NULL; DltLogStorageFilterConfig value; value.apids = apid; value.ctids = ctid; value.ecuid = ecuid; - char key0[] = "1234:\000\000\000\000"; - char key1[] = ":5678\000\000\000\000"; - char key2[] = "1234:5678"; - - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5, &(handle.config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key0, &value, &(handle.config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key1, &value, &(handle.config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key2, &value, &(handle.config_htab))); + value.file_name = file_name; + char key0[] = ":1234:\000\000\000\000"; + char key1[] = "::5678\000\000\000\000"; + char key2[] = ":1234:5678"; + + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, &value, &(handle.config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, &value, &(handle.config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write(&handle, &uconfig, data1, size1, data2, size2, data3, size3)); } @@ -603,15 +662,19 @@ TEST(t_dlt_logstorage_sync_caches, normal) char apid[] = "1234"; char ctid[] = "5678"; char ecuid[] = "12"; + char filename[] = "file_name"; + char key[] = "12:1234:5678"; DltLogStorage handle; handle.num_configs = 1; + handle.config_list = NULL; DltLogStorageFilterConfig configs; - handle.configs = &configs; configs.apids = apid; configs.ctids = ctid; configs.ecuid = ecuid; - dlt_logstorage_filter_set_strategy(handle.configs, DLT_LOGSTORAGE_SYNC_ON_MSG); + configs.file_name = filename; + dlt_logstorage_filter_set_strategy(&configs, DLT_LOGSTORAGE_SYNC_ON_MSG); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, &configs, &(handle.config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_caches(&handle)); } @@ -874,20 +937,23 @@ TEST(t_dlt_logstorage_write_on_msg, null) TEST(t_dlt_logstorage_sync_on_msg, normal) { DltLogStorageFilterConfig config; + DltLogStorageUserConfig file_config; char apids; char ctids; + memset(&config, 0, sizeof(DltLogStorageFilterConfig)); config.apids = &apids; config.ctids = &ctids; config.file_name = (char*)"Test"; config.records = NULL; config.log = NULL; + char *path = NULL; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_on_msg(&config, DLT_LOGSTORAGE_SYNC_ON_MSG)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_on_msg(&config, &file_config, path, DLT_LOGSTORAGE_SYNC_ON_MSG)); } TEST(t_dlt_logstorage_sync_on_msg, null) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_sync_on_msg(NULL, 0)); + EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_sync_on_msg(NULL,NULL,NULL, 0)); } /* Begin Method: dlt_logstorage::t_dlt_logstorage_prepare_msg_cache*/ @@ -909,6 +975,7 @@ TEST(t_dlt_logstorage_prepare_msg_cache, normal) config.log = NULL; config.cache = NULL; config.file_size = 0; + config.sync = DLT_LOGSTORAGE_SYNC_ON_DEMAND; g_logstorage_cache_max = 16; EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1)); @@ -950,58 +1017,75 @@ TEST(t_dlt_logstorage_write_msg_cache, null) /* Begin Method: dlt_logstorage::t_dlt_logstorage_split_key*/ TEST(t_dlt_logstorage_split_key, normal) { - char key[] = "dlt:1020"; - char appid[] = "2345"; - char ctxid[] = "6789"; + char key[] = "dlt:1020:"; + char appid[] = ":2345:"; + char ctxid[] = "::6789"; + char ecuid[] = "ECU1"; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_split_key(key, appid, ctxid)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_split_key(key, appid, ctxid, ecuid)); } TEST(t_dlt_logstorage_split_key, null) { - char key[] = "dlt:1020"; + char key[] = "dlt:1020:"; char appid[] = "2345"; char ctxid[] = "6789"; - EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_split_key(NULL, NULL, NULL)); - EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_split_key(NULL, appid, ctxid)); - EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_split_key(key, NULL, ctxid)); - EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_split_key(key, appid, NULL)); + char ecuid[] = "ECU1"; + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_split_key(NULL, NULL, NULL, NULL)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_split_key(NULL, appid, ctxid, ecuid)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_split_key(key, NULL, ctxid, ecuid)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_split_key(key, appid, NULL, ecuid)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_split_key(key, appid, ctxid, NULL)); } /* Begin Method: dlt_logstorage::t_dlt_logstorage_update_all_contexts*/ TEST(t_dlt_logstorage_update_all_contexts, normal) { DltDaemon daemon; - DltGateway gateway; + DltDaemonLocal daemon_local; memset(&daemon, 0, sizeof(DltDaemon)); - memset(&gateway, 0, sizeof(DltGateway)); + memset(&daemon_local.pGateway, 0, sizeof(DltGateway)); char ecu[] = "ECU1"; + char apid[] = "123"; + + daemon_local.RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE; + daemon_local.RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE; + daemon_local.RingbufferStepSize = DLT_DAEMON_RINGBUFFER_STEP_SIZE; EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, + daemon_local.RingbufferMinSize, + daemon_local.RingbufferMaxSize, + daemon_local.RingbufferStepSize, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); - EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_all_contexts(&daemon, ecu, 1, 1, 0)); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_all_contexts(&daemon, ecu, 0, 1, 0)); + EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_all_contexts(&daemon, &daemon_local, apid, 1, 1, ecu, 0)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_all_contexts(&daemon, &daemon_local, apid, 0, 1, ecu, 0)); } TEST(t_dlt_logstorage_update_all_contexts, null) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_update_all_contexts(NULL, NULL, 0, 0, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_update_all_contexts(NULL, NULL, NULL, 0, 0, NULL, 0)); } /* Begin Method: dlt_logstorage::t_dlt_logstorage_update_context*/ TEST(t_dlt_logstorage_update_context, normal) { DltDaemon daemon; - DltGateway gateway; + DltDaemonLocal daemon_local; DltDaemonContext *daecontext = NULL; + DltDaemonApplication *app = NULL; memset(&daemon, 0, sizeof(DltDaemon)); - memset(&gateway, 0, sizeof(DltGateway)); + memset(&daemon_local, 0, sizeof(DltDaemonLocal)); + memset(&daemon_local.pGateway, 0, sizeof(DltGateway)); + + int fd = connectServer(); + EXPECT_NE(-1, fd); + + daemon_local.RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE; + daemon_local.RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE; + daemon_local.RingbufferStepSize = DLT_DAEMON_RINGBUFFER_STEP_SIZE; char apid[] = "123"; char ctid[] = "456"; @@ -1009,139 +1093,166 @@ TEST(t_dlt_logstorage_update_context, normal) char ecu[] = "ECU1"; EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, + daemon_local.RingbufferMinSize, + daemon_local.RingbufferMaxSize, + daemon_local.RingbufferStepSize, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); - EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); + EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); + app = dlt_daemon_application_add(&daemon, apid, getpid() , desc, fd, ecu, 0); daecontext = dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, daemon.ecuid, 0); - EXPECT_EQ((DltDaemonContext*)(NULL), daecontext); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_context(&daemon, apid, ctid, 1, 0)); + DLT_TRACE_STATUS_DEFAULT, 0, app->user_handle, desc, daemon.ecuid, 0); + EXPECT_NE((DltDaemonContext*)(NULL), daecontext); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_context(&daemon, &daemon_local, apid, ctid, ecu, 1, 0)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_context(&daemon, &daemon_local, apid, ctid, ecu, 0, 0)); } TEST(t_dlt_logstorage_update_context, null) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_update_context(NULL, NULL, NULL, 0, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_update_context(NULL, NULL, NULL, NULL, NULL, 0, 0)); } /* Begin Method: dlt_logstorage::t_dlt_logstorage_update_context_loglevel*/ TEST(t_dlt_logstorage_update_context_loglevel, normal) { DltDaemon daemon; - DltGateway gateway; + DltDaemonLocal daemon_local; DltDaemonContext *daecontext = NULL; + DltDaemonApplication *app = NULL; memset(&daemon, 0, sizeof(DltDaemon)); - memset(&gateway, 0, sizeof(DltGateway)); + memset(&daemon_local, 0, sizeof(DltDaemonLocal)); + memset(&daemon_local.pGateway, 0, sizeof(DltGateway)); + + int fd = connectServer(); + EXPECT_NE(-1, fd); + + daemon_local.RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE; + daemon_local.RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE; + daemon_local.RingbufferStepSize = DLT_DAEMON_RINGBUFFER_STEP_SIZE; char apid[] = "123"; char ctid[] = "456"; - char key[] = "123:456"; - char desc[255] = "TEST dlt_logstorage_update_context"; + char key[] = ":123:456"; + char desc[255] = "TEST dlt_logstorage_update_context_loglevel"; char ecu[] = "ECU1"; EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, + daemon_local.RingbufferMinSize, + daemon_local.RingbufferMaxSize, + daemon_local.RingbufferStepSize, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); - EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - + EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); + app = dlt_daemon_application_add(&daemon, apid, getpid(), desc, fd, ecu, 0); daecontext = dlt_daemon_context_add(&daemon, apid, ctid, DLT_LOG_DEFAULT, - DLT_TRACE_STATUS_DEFAULT, 0, 0, desc, daemon.ecuid, 0); - - EXPECT_EQ((DltDaemonContext*)(NULL), daecontext); + DLT_TRACE_STATUS_DEFAULT, 0, app->user_handle, desc, daemon.ecuid, 0); + EXPECT_NE((DltDaemonContext*)(NULL), daecontext); EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_update_context_loglevel - (&daemon, key, 1, 0)); + (&daemon, &daemon_local, key, 1, 0)); } TEST(t_dlt_logstorage_update_context_loglevel, null) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_update_context_loglevel(NULL, NULL, 0, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_update_context_loglevel(NULL, NULL, NULL, 0, 0)); } /* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_reset_application_loglevel*/ TEST(t_dlt_daemon_logstorage_reset_application_loglevel, normal) { DltDaemon daemon; - DltGateway gateway; + DltDaemonLocal daemon_local; memset(&daemon, 0, sizeof(DltDaemon)); - memset(&gateway, 0, sizeof(DltGateway)); + memset(&daemon_local, 0, sizeof(daemon_local)); + memset(&daemon_local.pGateway, 0, sizeof(DltGateway)); + + daemon_local.RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE; + daemon_local.RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE; + daemon_local.RingbufferStepSize = DLT_DAEMON_RINGBUFFER_STEP_SIZE; + char ecu[] = "ECU1"; int device_index = 0; + EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, + daemon_local.RingbufferMinSize, + daemon_local.RingbufferMaxSize, + daemon_local.RingbufferStepSize, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); - EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); - EXPECT_NO_THROW(dlt_daemon_logstorage_reset_application_loglevel(&daemon, device_index, 1, 0)); + EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); + EXPECT_NO_THROW(dlt_daemon_logstorage_reset_application_loglevel(&daemon, &daemon_local, device_index, 1, 0)); } TEST(t_dlt_daemon_logstorage_reset_application_loglevel, null) { - EXPECT_NO_THROW(dlt_daemon_logstorage_reset_application_loglevel(NULL, 0, 0, 0)); + EXPECT_NO_THROW(dlt_daemon_logstorage_reset_application_loglevel(NULL, NULL, 0, 0, 0)); } -/* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_update_application_loglevel*/ -TEST(t_dlt_daemon_logstorage_update_application_loglevel, normal) +/* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_get_loglevel*/ +TEST(t_dlt_daemon_logstorage_get_loglevel, normal) { char ecu[] = "ECU1"; + char apid[] = "1234"; + char ctid[] = "5678"; + char key[] = "ECU1:1234:5678"; int device_index = 0; DltDaemon daemon; - DltGateway gateway; + DltDaemonLocal daemon_local; memset(&daemon, 0, sizeof(DltDaemon)); - memset(&gateway, 0, sizeof(DltGateway)); + memset(&daemon_local, 0, sizeof(DltDaemonLocal)); + memset(&daemon_local.pGateway, 0, sizeof(DltGateway)); DltLogStorageFilterConfig value; - value.log_level = 5; + value.log_level = 4; + value.apids = apid; + value.ctids = ctid; + value.ecuid = ecu; DltLogStorage storage_handle; + daemon_local.RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE; + daemon_local.RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE; + daemon_local.RingbufferStepSize = DLT_DAEMON_RINGBUFFER_STEP_SIZE; + EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, + daemon_local.RingbufferMinSize, + daemon_local.RingbufferMaxSize, + daemon_local.RingbufferStepSize, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); - EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); + EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); daemon.storage_handle = &storage_handle; daemon.storage_handle->connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; daemon.storage_handle->num_filter_keys = 1; daemon.storage_handle->config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; - daemon.storage_handle->filter_keys = (char*)calloc( - DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, sizeof(char)); - strncpy(daemon.storage_handle->filter_keys, "key:1020", - DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); + daemon.storage_handle->config_list = NULL; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5, &(daemon.storage_handle->config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(daemon.storage_handle->filter_keys, &value, &(daemon.storage_handle->config_htab))); - EXPECT_NO_THROW(dlt_daemon_logstorage_update_application_loglevel(&daemon, device_index, 0)); - free(daemon.storage_handle->filter_keys); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, &value, &(daemon.storage_handle->config_list))); + EXPECT_NO_THROW(dlt_daemon_logstorage_update_application_loglevel(&daemon, &daemon_local, device_index, 0)); + + EXPECT_EQ(4, dlt_daemon_logstorage_get_loglevel(&daemon, 1, apid, ctid)); } -TEST(t_dlt_daemon_logstorage_update_application_loglevel, null) +TEST(t_dlt_daemon_logstorage_get_loglevel, null) { - EXPECT_NO_THROW(dlt_daemon_logstorage_update_application_loglevel(NULL, 0, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_daemon_logstorage_get_loglevel(NULL, 0, NULL, NULL)); } -/* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_get_loglevel*/ -TEST(t_dlt_daemon_logstorage_get_loglevel, normal) +/* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_update_application_loglevel*/ +TEST(t_dlt_daemon_logstorage_update_application_loglevel, normal) { - char ecu[] = "ECU1"; + char ecu[] = "key"; char apid[] = "1234"; char ctid[] = "5678"; + char key[] = "key:1234:5678"; int device_index = 0; DltDaemon daemon; - DltGateway gateway; + DltDaemonLocal daemon_local; memset(&daemon, 0, sizeof(DltDaemon)); - memset(&gateway, 0, sizeof(DltGateway)); + memset(&daemon_local, 0, sizeof(DltDaemonLocal)); + memset(&daemon_local.pGateway, 0, sizeof(DltGateway)); DltLogStorageFilterConfig value; value.log_level = 5; value.apids = apid; @@ -1149,36 +1260,32 @@ TEST(t_dlt_daemon_logstorage_get_loglevel, normal) value.ecuid = ecu; DltLogStorage storage_handle; + daemon_local.RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE; + daemon_local.RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE; + daemon_local.RingbufferStepSize = DLT_DAEMON_RINGBUFFER_STEP_SIZE; + EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, + daemon_local.RingbufferMinSize, + daemon_local.RingbufferMaxSize, + daemon_local.RingbufferStepSize, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); dlt_set_id(daemon.ecuid, ecu); - EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); + EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); daemon.storage_handle = &storage_handle; daemon.storage_handle->connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; daemon.storage_handle->num_filter_keys = 1; daemon.storage_handle->config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; - daemon.storage_handle->filter_keys = (char*)calloc( - DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN, sizeof(char)); - strncpy(daemon.storage_handle->filter_keys, "1234:5678", - DLT_OFFLINE_LOGSTORAGE_MAX_KEY_LEN); - - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5, &(daemon.storage_handle->config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(daemon.storage_handle-> - filter_keys, &value, &(daemon.storage_handle->config_htab))); - EXPECT_NO_THROW(dlt_daemon_logstorage_update_application_loglevel(&daemon, device_index, 0)); + daemon.storage_handle->config_list = NULL; - EXPECT_EQ(5, dlt_daemon_logstorage_get_loglevel(&daemon, 1, apid, ctid)); - free(daemon.storage_handle->filter_keys); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, &value, &(daemon.storage_handle->config_list))); + EXPECT_NO_THROW(dlt_daemon_logstorage_update_application_loglevel(&daemon, &daemon_local, device_index, 0)); } -TEST(t_dlt_daemon_logstorage_get_loglevel, null) +TEST(t_dlt_daemon_logstorage_update_application_loglevel, null) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_daemon_logstorage_get_loglevel(NULL, 0, NULL, NULL)); + EXPECT_NO_THROW(dlt_daemon_logstorage_update_application_loglevel(NULL, NULL, 0, 0)); } /* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_write*/ @@ -1215,6 +1322,7 @@ TEST(t_dlt_daemon_logstorage_write, normal) int size = 10 * sizeof(uint32_t);; daemon.storage_handle->connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED; daemon.storage_handle->config_status = DLT_OFFLINE_LOGSTORAGE_CONFIG_DONE; + daemon.storage_handle->config_list = NULL; DltLogStorageFilterConfig value; value.apids = apid; value.ctids = ctid; @@ -1222,17 +1330,10 @@ TEST(t_dlt_daemon_logstorage_write, normal) char key0[] = "1234:\000\000\000\000"; char key1[] = ":5678\000\000\000\000"; char key2[] = "1234:5678"; - DltLogStorageFilterConfig configs; - daemon.storage_handle->configs = &configs; - daemon.storage_handle->configs->apids = apid; - daemon.storage_handle->configs->ctids = ctid; - daemon.storage_handle->configs->ecuid = ecuid; - daemon.storage_handle->configs->log_level = 5; - - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_create(5, &(daemon.storage_handle->config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key0, &value, &(daemon.storage_handle->config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key1, &value, &(daemon.storage_handle->config_htab))); - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_hash_add(key2, &value, &(daemon.storage_handle->config_htab))); + + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key0, &value, &(daemon.storage_handle->config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key1, &value, &(daemon.storage_handle->config_list))); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key2, &value, &(daemon.storage_handle->config_list))); EXPECT_NO_THROW(dlt_daemon_logstorage_write(&daemon, &uconfig, data1, size, data2, size, data3, size)); } @@ -1245,29 +1346,37 @@ TEST(t_dlt_daemon_logstorage_write, null) TEST(t_dlt_daemon_logstorage_setup_internal_storage, normal) { DltDaemon daemon; - DltGateway gateway; + DltDaemonLocal daemon_local; memset(&daemon, 0, sizeof(DltDaemon)); - memset(&gateway, 0, sizeof(DltGateway)); + memset(&daemon_local, 0, sizeof(DltDaemonLocal)); + memset(&daemon_local.pGateway, 0, sizeof(DltGateway)); + + daemon_local.RingbufferMinSize = DLT_DAEMON_RINGBUFFER_MIN_SIZE; + daemon_local.RingbufferMaxSize = DLT_DAEMON_RINGBUFFER_MAX_SIZE; + daemon_local.RingbufferStepSize = DLT_DAEMON_RINGBUFFER_STEP_SIZE; char ecu[] = "ECU1"; char path[] = "/tmp"; + EXPECT_EQ(0, dlt_daemon_init(&daemon, - DLT_DAEMON_RINGBUFFER_MIN_SIZE, - DLT_DAEMON_RINGBUFFER_MAX_SIZE, - DLT_DAEMON_RINGBUFFER_STEP_SIZE, + daemon_local.RingbufferMinSize, + daemon_local.RingbufferMaxSize, + daemon_local.RingbufferStepSize, DLT_RUNTIME_DEFAULT_DIRECTORY, DLT_LOG_INFO, DLT_TRACE_STATUS_OFF,0,0)); + dlt_set_id(daemon.ecuid, ecu); - EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &gateway, 0, 0)); + EXPECT_EQ(0, dlt_daemon_init_user_information(&daemon, &daemon_local.pGateway, 0, 0)); DltLogStorage storage_handle; daemon.storage_handle = &storage_handle; daemon.storage_handle->config_status = 0; daemon.storage_handle->connection_type = DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED; - EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_logstorage_setup_internal_storage(&daemon, path, 1, 0)); + daemon.storage_handle->config_list = NULL; + EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_logstorage_setup_internal_storage(&daemon, &daemon_local, path, 1)); } TEST(t_dlt_daemon_logstorage_setup_internal_storage, null) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_daemon_logstorage_setup_internal_storage(NULL, NULL, 0, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_daemon_logstorage_setup_internal_storage(NULL, NULL, NULL, 0)); } /* Begin Method: dlt_logstorage::dlt_daemon_logstorage_set_logstorage_cache_size*/ @@ -1290,7 +1399,7 @@ TEST(t_dlt_daemon_logstorage_cleanup, normal) TEST(t_dlt_daemon_logstorage_cleanup, null) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_daemon_logstorage_cleanup(NULL, NULL, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_daemon_logstorage_cleanup(NULL, NULL, 0)); } /* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_sync_cache*/ @@ -1306,20 +1415,25 @@ TEST(t_dlt_daemon_logstorage_sync_cache, normal) char apid[] = "1234"; char ctid[] = "5678"; char ecuid[] = "12"; + char file_name[] = "file_name"; + char key[] = "12:1234:5678"; daemon.storage_handle->num_configs = 1; + daemon.storage_handle->config_list = NULL; + strncpy(daemon.storage_handle->device_mount_point, "/tmp", 5); DltLogStorageFilterConfig configs; - daemon.storage_handle->configs = &configs; configs.apids = apid; configs.ctids = ctid; configs.ecuid = ecuid; - dlt_logstorage_filter_set_strategy(daemon.storage_handle->configs, DLT_LOGSTORAGE_SYNC_ON_MSG); + configs.file_name = file_name; + dlt_logstorage_filter_set_strategy(&configs, DLT_LOGSTORAGE_SYNC_ON_MSG); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_list_add(key, &configs, &(daemon.storage_handle->config_list))); EXPECT_EQ(DLT_RETURN_OK, dlt_daemon_logstorage_sync_cache(&daemon, &daemon_local, path, 0)); } TEST(t_dlt_daemon_logstorage_sync_cache, null) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_daemon_logstorage_sync_cache(NULL, NULL, NULL, 0)); + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_daemon_logstorage_sync_cache(NULL, NULL, NULL, 0)); } /* Begin Method: dlt_logstorage::t_dlt_daemon_logstorage_get_device*/ @@ -1342,34 +1456,328 @@ TEST(t_dlt_daemon_logstorage_get_device, null) EXPECT_EQ((DltLogStorage *)NULL, dlt_daemon_logstorage_get_device(NULL, NULL, NULL, 0)); } -/* Begin Method: dlt_logstorage::t_dlt_logstorage_sync_msg_cache*/ -TEST(t_dlt_logstorage_sync_msg_cache, normal) +/* Begin Method: dlt_logstorage::t_dlt_logstorage_find_dlt_header*/ +TEST(t_dlt_logstorage_find_dlt_header, normal) { + char data[] = {'a','b','D','L','T',0x01}; DltLogStorageFilterConfig config; memset(&config, 0, sizeof(DltLogStorageFilterConfig)); - config.sync = 1; - config.log = fopen("/tmp/test.log", "a+"); - if(config.log != NULL) + config.cache = calloc(1, sizeof(data)); + if (config.cache != NULL) { - config.cache = calloc(1, 1 + sizeof(DltLogStorageCacheFooter)); - if(config.cache != NULL) + strncpy((char *)config.cache, data, sizeof(data)); + /* DLT header starts from index 2 */ + EXPECT_EQ(2, dlt_logstorage_find_dlt_header(config.cache, 0,sizeof(data))); + free(config.cache); + } + +} + +TEST(t_dlt_logstorage_find_dlt_header, null) +{ + char data[] = {'N','o','H','e','a','d','e','r'}; + DltLogStorageFilterConfig config; + memset(&config, 0, sizeof(DltLogStorageFilterConfig)); + config.cache = calloc(1, sizeof(data)); + if (config.cache != NULL) + { + /* config.cache =(void *) "a,b,D,L,T,0x01"; */ + strncpy((char *)config.cache, data, sizeof(data)); + EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_find_dlt_header(config.cache, 0,sizeof(data))); + free(config.cache); + } +} + +/* Begin Method: dlt_logstorage::t_dlt_logstorage_sync_create_new_file*/ +TEST(t_dlt_logstorage_sync_create_new_file, normal) +{ + DltLogStorageUserConfig file_config; + memset(&file_config, 0, sizeof(DltLogStorageUserConfig)); + file_config.logfile_timestamp =191132; + file_config.logfile_delimiter = {'_'}; + file_config.logfile_maxcounter = 5; + file_config.logfile_counteridxlen = 2; + char *path = (char*)"/tmp"; + DltLogStorageFilterConfig config; + memset(&config, 0, sizeof(DltLogStorageFilterConfig)); + char apids; + char ctids; + config.apids = &apids; + config.ctids = &ctids; + config.file_name = (char*)"Test"; + config.records = NULL; + config.log = NULL; + config.cache = NULL; + config.file_size = 50; + config.sync = DLT_LOGSTORAGE_SYNC_ON_DEMAND; + config.num_files = 5; + g_logstorage_cache_max = 16; + unsigned int size = 10; + unsigned char data1[10] = "dlt_data1"; + unsigned char data2[10] = "dlt_data2"; + unsigned char data3[10] = "dlt_data3"; + DltLogStorageCacheFooter *footer = NULL; + + config.cache = calloc(1, 50 + sizeof(DltLogStorageCacheFooter)); + if(config.cache != NULL) + { + footer = (DltLogStorageCacheFooter *)(config.cache + 50); + if (footer != NULL) { - config.file_size = 1; - EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_msg_cache(&config, 1)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_msg_cache(&config, data1, size, data2, size, data3, size)); + footer->offset = 0; + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_create_new_file(&config, &file_config, path, 0)); free(config.cache); config.cache = NULL; } } + +} + +TEST(t_dlt_logstorage_sync_create_new_file, null) +{ + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_sync_create_new_file(NULL, NULL, NULL, 0)); +} + +/* Begin Method: dlt_logstorage::t_dlt_logstorage_sync_to_file*/ +TEST(t_dlt_logstorage_sync_to_file, normal) +{ + DltLogStorageUserConfig file_config; + memset(&file_config, 0, sizeof(DltLogStorageUserConfig)); + file_config.logfile_timestamp =191132; + file_config.logfile_delimiter = {'_'}; + file_config.logfile_maxcounter = 6; + file_config.logfile_counteridxlen = 2; + char *path = (char*)"/tmp"; + DltLogStorageFilterConfig config; + memset(&config, 0, sizeof(DltLogStorageFilterConfig)); + char apids; + char ctids; + config.apids = &apids; + config.ctids = &ctids; + config.file_name = (char*)"Test"; + config.records = NULL; + config.log = NULL; + config.cache = NULL; + config.file_size = 0; + config.sync = DLT_LOGSTORAGE_SYNC_ON_DEMAND; + config.num_files = 6; + config.file_size = 50; + g_logstorage_cache_max = 16; + unsigned int size = 10; + unsigned char data1[10] = "dlt_data0"; + unsigned char data2[10] = "dlt_data1"; + unsigned char data3[10] = "dlt_data2"; + + config.cache = calloc(1, 50 + sizeof(DltLogStorageCacheFooter)); + if(config.cache != NULL) + { + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_msg_cache(&config, data1, size, data2, size, data3, size)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_to_file(&config, &file_config, path)); + free(config.cache); + config.cache = NULL; + + } +} + +TEST(t_dlt_logstorage_sync_to_file, null) +{ + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_sync_to_file(NULL, NULL, NULL)); +} + +/* Begin Method: dlt_logstorage::t_dlt_logstorage_sync_capable_data_to_file*/ +TEST(t_dlt_logstorage_sync_capable_data_to_file, normal) +{ + DltLogStorageUserConfig file_config; + memset(&file_config, 0, sizeof(DltLogStorageUserConfig)); + file_config.logfile_timestamp =191132; + file_config.logfile_delimiter = {'_'}; + file_config.logfile_maxcounter = 7; + file_config.logfile_counteridxlen = 2; + char *path = (char*)"/tmp"; + DltLogStorageFilterConfig config; + memset(&config, 0, sizeof(DltLogStorageFilterConfig)); + char apids; + char ctids; + config.apids = &apids; + config.ctids = &ctids; + config.file_name = (char*)"Test"; + config.records = NULL; + config.log = NULL; + config.cache = NULL; + config.file_size = 0; + config.sync = DLT_LOGSTORAGE_SYNC_ON_DEMAND; + config.num_files = 7; + config.file_size = 50; + g_logstorage_cache_max = 16; + unsigned int size = 10; + unsigned char data1[10] = "Dlt_data0"; + unsigned char data2[10] = "Dlt_data1"; + unsigned char data3[10] = "Dlt_data2"; + + config.cache = calloc(1, 50 + sizeof(DltLogStorageCacheFooter)); + if(config.cache != NULL) + { + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_msg_cache(&config, data1, size, data2, size, data3, size)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_capable_data_to_file(&config, 0)); + free(config.cache); + config.cache = NULL; + } + +} + +TEST(t_dlt_logstorage_sync_capable_data_to_file, null) +{ + EXPECT_EQ(DLT_RETURN_WRONG_PARAMETER, dlt_logstorage_sync_capable_data_to_file(NULL, 0)); +} + +/* Begin Method: dlt_logstorage::t_dlt_logstorage_sync_msg_cache*/ +TEST(t_dlt_logstorage_sync_msg_cache, normal) +{ + + DltLogStorageUserConfig file_config; + memset(&file_config, 0, sizeof(DltLogStorageUserConfig)); + file_config.logfile_timestamp =191132; + file_config.logfile_delimiter = {'_'}; + file_config.logfile_maxcounter = 8; + file_config.logfile_counteridxlen = 2; + char *path = (char*)"/tmp"; + + DltLogStorageFilterConfig config; + memset(&config, 0, sizeof(DltLogStorageFilterConfig)); + char apids; + char ctids; + config.apids = &apids; + config.ctids = &ctids; + config.file_name = (char*)"Test"; + config.records = NULL; + config.log = NULL; + config.cache = NULL; + config.file_size = 50; + config.sync = DLT_LOGSTORAGE_SYNC_ON_DEMAND; + config.num_files = 8; + g_logstorage_cache_max = 16; + + unsigned int size = 10; + unsigned char data1[10] = "dlt_dataA"; + unsigned char data2[10] = "dlt_dataB"; + unsigned char data3[10] = "dlt_dataC"; + + config.cache = calloc(1, 50 + sizeof(DltLogStorageCacheFooter)); + if(config.cache != NULL) + { + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_prepare_msg_cache(&config, &file_config, path, 1)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_write_msg_cache(&config, data1, size, data2, size, data3, size)); + EXPECT_EQ(DLT_RETURN_OK, dlt_logstorage_sync_msg_cache(&config, &file_config, path, DLT_LOGSTORAGE_SYNC_ON_DEMAND)); + free(config.cache); + config.cache = NULL; + } + } TEST(t_dlt_logstorage_sync_msg_cache, null) { - EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_sync_msg_cache(NULL, 0)); + EXPECT_EQ(DLT_RETURN_ERROR, dlt_logstorage_sync_msg_cache(NULL, NULL, NULL, 0)); +} + +int connectServer(void) +{ + int sockfd, portno; + struct sockaddr_in serv_addr; + struct hostent *server; + portno = 8080; + sockfd = socket(AF_INET, SOCK_STREAM, 0); + server = gethostbyname("127.0.0.1"); + bzero((char *) &serv_addr, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + bcopy((char *)server->h_addr, + (char *)&serv_addr.sin_addr.s_addr, + server->h_length); + serv_addr.sin_port = htons(portno); + if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) + { + printf("Error: %s (%d) occured in connect socket\n", strerror(errno), errno); + close(sockfd); + return -1; + } + return sockfd; } +#define GTEST_SOCKS_ACCEPTED 2 + int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - ::testing::FLAGS_gtest_break_on_failure = true; - return RUN_ALL_TESTS(); + pid_t cpid; + cpid = fork(); + if(cpid == -1) + { + printf("fork fail\n"); + return -1; + } + if (cpid) + { + int i = GTEST_SOCKS_ACCEPTED; + int j, optval = 1; + char buffer[256]; + int sockfd, newsockfd[GTEST_SOCKS_ACCEPTED], portno; + socklen_t clilen; + struct sockaddr_in serv_addr, cli_addr; + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if(sockfd == -1) + { + printf("Error in creating socket\n"); + return -1; + } + bzero((char *) &serv_addr, sizeof(serv_addr)); + portno = 8080; + + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = INADDR_ANY; + serv_addr.sin_port = htons(portno); + + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) { + perror("setsockopt"); + close(sockfd); + exit(1); + } + + j = bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)); + if(j == -1) + { + perror("Bind Error\n"); + close(sockfd); + return -1; + } + listen(sockfd, 5); + while(i) + { + clilen = sizeof(cli_addr); + newsockfd[i-1] = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); + if(newsockfd[i-1] == -1) + { + printf("Error in accept"); + return -1; + } + bzero(buffer, 256); + (void)(read(newsockfd[i-1], buffer, 255) + 1); /* just ignore result */ + i--; + } + + for(j = 0; j < GTEST_SOCKS_ACCEPTED; j++) + close(newsockfd[i]); + + close(sockfd); + } + else + { + + ::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(); + } + return 0; } diff --git a/tests/start_multinode_test.sh b/tests/start_multinode_test.sh index f152056..54a58b5 100755 --- a/tests/start_multinode_test.sh +++ b/tests/start_multinode_test.sh @@ -24,14 +24,25 @@ #Description : Smoke testing for multinode feature of DLT # #Author Name : Onkar Palkar +# Jeevan Ramakant Nagvekar #Email Id : onkar.palkar@wipro.com +# jeevan.nagvekar1@wipro.com # -#History : 8/06/2016 +#History : 31/07/2018 ################################################################################ ipaddr=127.0.0.1 # +# Function: -getOSname() +# +# Description -Retrieves OS name +# +getOSname() +{ + OS="`uname`" +} +# # Function: -cleanup() # # Description -Delete the dlt_test folder if it already present @@ -50,38 +61,74 @@ cleanup() tmpPassiveDIR=tmpPassive tmpLogFile=log_multinode.txt tmpLogAsciFile=log_multinode_a.txt + + if [ "$OS" = "QNX" ] + then + PIDOF() + { + slay -p $1 > /dev/null + if [ $? -eq '0' ] + then + return 1 + else + return 0 + fi + } + KILLALL() + { + slay -9 -f $1 > /dev/null + if [ $? -eq '0' ] + then + return 1 + else + return 0 + fi + } + else + PIDOF() + { + pidof $1 > /dev/null + return $? + } + KILLALL() + { + killall $1 > /dev/null + return $? + } + fi + cd $tmpPath - rm -rf $tmpPath/$tmpFolder - pidof dlt-daemon > /dev/null + PIDOF "dlt-daemon" if [ $? -eq '0' ] then - killall dlt-daemon + KILLALL "dlt-daemon" if [ $? -ne '0' ] then echo "Failed to kill daemons" return 1 fi fi - pidof dlt-receive > /dev/null + PIDOF "dlt-receive" if [ $? -eq '0' ] then - killall dlt-receive + KILLALL "dlt-receive" if [ $? -ne '0' ] then echo "Failed to kill dlt-receive" return 1 fi fi - pidof dlt-convert > /dev/null + PIDOF "dlt-convert" if [ $? -eq '0' ] then - killall dlt-convert + KILLALL "dlt-convert" if [ $? -ne '0' ] then echo "Failed to kill dlt-convert" return 1 fi fi + rm -rf $tmpPath/$tmpFolder >/dev/null return 0 } # @@ -96,6 +143,13 @@ cleanup() # setupTest() { + if [ "$OS" = "QNX" ] + then + MESSAGE_FILTER_CONF="/etc/dlt_message_filter.conf" + else + MESSAGE_FILTER_CONF="/etc/dlt_message_filter_ald.conf" + fi + which dlt-daemon > /dev/null if [ $? -ne '0' ] then @@ -114,13 +168,13 @@ setupTest() echo "dlt-receive is not available" return 1 fi - mkdir $tmpPath/$tmpFolder + mkdir -p $tmpPath/$tmpFolder if [ $? -ne '0' ] then echo "Error in creating dlt_test folder" return 1 fi - mkdir $tmpPath/$tmpFolder/$gatewayFolderName + mkdir -p $tmpPath/$tmpFolder/$gatewayFolderName if [ $? -ne '0' ] then echo "Error in creating gateway folder" @@ -145,6 +199,7 @@ setupTest() echo "RingbufferStepSize = 500000" >>$tmpPath/$tmpFolder/$gatewayFolderName/dlt.conf echo "ControlSocketPath = /tmp/dlt-ctrl.sock" >>$tmpPath/$tmpFolder/$gatewayFolderName/dlt.conf echo "GatewayConfigFile = $tmpPath/$tmpFolder/$gatewayFolderName/dlt_gateway.conf" >> $tmpPath/$tmpFolder/$gatewayFolderName/dlt.conf + echo "MessageFilterConfigFile = $MESSAGE_FILTER_CONF" >> $tmpPath/$tmpFolder/$gatewayFolderName/dlt.conf touch $tmpPath/$tmpFolder/$gatewayFolderName/dlt_gateway.conf if [ $? -ne '0' ] then @@ -158,7 +213,7 @@ setupTest() echo "Connect=OnStartup" >>$tmpPath/$tmpFolder/$gatewayFolderName/dlt_gateway.conf echo "Timeout=10" >>$tmpPath/$tmpFolder/$gatewayFolderName/dlt_gateway.conf echo "NOFiles=1" >>$tmpPath/$tmpFolder/$gatewayFolderName/dlt_gateway.conf - mkdir $tmpPath/$tmpFolder/$passiveFolderName + mkdir -p $tmpPath/$tmpFolder/$passiveFolderName if [ $? -ne '0' ] then echo "Error in creating passive folder" @@ -181,7 +236,8 @@ setupTest() echo "RingbufferMaxSize = 10000000" >>$tmpPath/$tmpFolder/$passiveFolderName/dlt.conf echo "RingbufferStepSize = 500000" >>$tmpPath/$tmpFolder/$passiveFolderName/dlt.conf echo "ControlSocketPath = /tmp/dlt-ctrl.sock" >>$tmpPath/$tmpFolder/$passiveFolderName/dlt.conf - mkdir $tmpPath/$tmpFolder/$tmpPassiveDIR + echo "MessageFilterConfigFile = $MESSAGE_FILTER_CONF" >> $tmpPath/$tmpFolder/$passiveFolderName/dlt.conf + mkdir -p $tmpPath/$tmpFolder/$tmpPassiveDIR if [ $? -ne '0' ] then echo "Error while creating tempPassive folder" @@ -243,7 +299,8 @@ startReceive() verifyTest() { dlt-convert -a $tmpPath/$tmpFolder/$tmpLogFile > $tmpPath/$tmpFolder/$tmpLogAsciFile - cat $tmpPath/$tmpFolder/$tmpLogAsciFile | grep -w "ECU2" > /dev/null + cat $tmpPath/$tmpFolder/$tmpLogAsciFile | grep -F "ECU2" > /dev/null + if [ $? -eq '0' ] then return 0 @@ -253,6 +310,7 @@ verifyTest() } #main function ######################################################################################## +getOSname cleanup if [ $? -ne '0' ] then @@ -282,7 +340,7 @@ then return 1 fi #wait for 1 sec before starting dlt-receive to start dlt-example-user application properly -sleep 1s +sleep 1 startReceive if [ $? -ne '0' ] then @@ -291,7 +349,7 @@ then return 1 fi #Wait for 1 sec to collect messages sent by application at gateway -sleep 1s +sleep 1 verifyTest if [ $? -eq '0' ] then |