diff options
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | automotive-dlt-c++.pc.in | 3 | ||||
-rw-r--r-- | include/dlt/dlt_cpp_extension.hpp | 177 | ||||
-rw-r--r-- | include/dlt/dlt_user.h | 12 | ||||
-rw-r--r-- | src/console/dlt-logstorage-ctrl.c | 28 | ||||
-rw-r--r-- | src/console/dlt-receive.c | 16 | ||||
-rw-r--r-- | src/examples/dlt-example-user.c | 2 | ||||
-rw-r--r-- | src/lib/dlt_env_ll.c | 28 | ||||
-rw-r--r-- | src/lib/dlt_user.c | 258 | ||||
-rw-r--r-- | src/tests/dlt-test-fork-handler.c | 90 | ||||
-rw-r--r-- | tests/dlt-test-cpp-extension.cpp | 180 | ||||
-rw-r--r-- | tests/dlt-test-preregister-context.c | 48 | ||||
-rw-r--r-- | tests/dlt_env_ll_unit_test.cpp | 933 | ||||
-rw-r--r-- | tests/gtest_dlt_common.cpp | 2 |
14 files changed, 923 insertions, 858 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8497dc5..ae59698 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,8 +122,8 @@ configure_file(${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.pc.in ${PROJECT_BINARY_DIR}/$ install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT devel) if(${WITH_DLT_CXX11_EXT}) - configure_file(${CMAKE_SOURCE_DIR}/${PROJECT_NAME}-c++.pc.in ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-c++.pc @ONLY) - install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-c++.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT devel) + configure_file(${CMAKE_SOURCE_DIR}/${PROJECT_NAME}-c++.pc.in ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-c++.pc @ONLY) + install(FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-c++.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT devel) endif() IF(${CMAKE_INSTALL_PREFIX} STREQUAL "/usr") diff --git a/automotive-dlt-c++.pc.in b/automotive-dlt-c++.pc.in index 3e950ae..ef2eb22 100644 --- a/automotive-dlt-c++.pc.in +++ b/automotive-dlt-c++.pc.in @@ -5,5 +5,4 @@ Name: DLT C++ Description: Diagnostic Log and Trace C++ extensions Version: @DLTCPP_VERSION@ Requires: automotive-dlt -Cflags: -std=c++11 - +Cflags: -std=gnu++0x diff --git a/include/dlt/dlt_cpp_extension.hpp b/include/dlt/dlt_cpp_extension.hpp index 8949658..1eaf4d2 100644 --- a/include/dlt/dlt_cpp_extension.hpp +++ b/include/dlt/dlt_cpp_extension.hpp @@ -1,22 +1,28 @@ -/** +/* * @licence app begin@ - * Copyright (C) 2015 Intel Corporation + * SPDX license identifier: MPL-2.0 * - * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps. + * Copyright (C) 2015 Intel Corporation * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. * - * \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/. + * Mozilla Public License (MPL), 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/. * - * \file dlt_cpp_extension.hpp * For further information see http://www.genivi.org/. * @licence end@ */ +/*! + * \author Stefan Vacek <stefan.vacek@intel.com> Intel Corporation + * + * \copyright Copyright © 2015 Intel Corporation. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * + * \file dlt_cpp_extension.hpp +*/ #ifndef DLT_CPP_EXTENSION_HPP #define DLT_CPP_EXTENSION_HPP @@ -27,170 +33,158 @@ #include <list> #include <map> - template<typename T> int32_t logToDlt(DltContextData &log, T const &value) = delete; - template<> inline int32_t logToDlt(DltContextData &log, int8_t const &value) { - return dlt_user_log_write_int8(&log, value); + return dlt_user_log_write_int8(&log, value); } template<> inline int32_t logToDlt(DltContextData &log, int16_t const &value) { - return dlt_user_log_write_int16(&log, value); + return dlt_user_log_write_int16(&log, value); } template<> inline int32_t logToDlt(DltContextData &log, int32_t const &value) { - return dlt_user_log_write_int32(&log, value); + return dlt_user_log_write_int32(&log, value); } template<> inline int32_t logToDlt(DltContextData &log, int64_t const &value) { - return dlt_user_log_write_int64(&log, value); + return dlt_user_log_write_int64(&log, value); } template<> inline int32_t logToDlt(DltContextData &log, uint8_t const &value) { - return dlt_user_log_write_uint8(&log, value); + return dlt_user_log_write_uint8(&log, value); } template<> inline int32_t logToDlt(DltContextData &log, uint16_t const &value) { - return dlt_user_log_write_uint16(&log, value); + return dlt_user_log_write_uint16(&log, value); } template<> inline int32_t logToDlt(DltContextData &log, uint32_t const &value) { - return dlt_user_log_write_uint32(&log, value); + return dlt_user_log_write_uint32(&log, value); } template<> inline int32_t logToDlt(DltContextData &log, uint64_t const &value) { - return dlt_user_log_write_uint64(&log, value); + return dlt_user_log_write_uint64(&log, value); } template<> inline int32_t logToDlt(DltContextData &log, float32_t const &value) { - return dlt_user_log_write_float32(&log, value); + return dlt_user_log_write_float32(&log, value); } template<> inline int32_t logToDlt(DltContextData &log, double const &value) { - return dlt_user_log_write_float64(&log, value); + return dlt_user_log_write_float64(&log, value); } template<> inline int32_t logToDlt(DltContextData &log, bool const &value) { - return dlt_user_log_write_bool(&log, value); + return dlt_user_log_write_bool(&log, value); } static inline int32_t logToDlt(DltContextData &log, char const * const value) { - return dlt_user_log_write_utf8_string(&log, value); + return dlt_user_log_write_utf8_string(&log, value); } static inline int32_t logToDlt(DltContextData &log, char * const value) { - return dlt_user_log_write_utf8_string(&log, value); + return dlt_user_log_write_utf8_string(&log, value); } template<> inline int32_t logToDlt(DltContextData &log, std::string const &value) { - return dlt_user_log_write_utf8_string(&log, value.c_str()); + return dlt_user_log_write_utf8_string(&log, value.c_str()); } - /* stl types */ template<> int32_t logToDlt(DltContextData &log, std::string const &value); template<typename _Tp, typename _Alloc = std::allocator<_Tp>> -static inline int32_t logToDlt(DltContextData &log, std::vector<_Tp, _Alloc > const & value) +static inline int32_t logToDlt(DltContextData &log, std::vector<_Tp, _Alloc> const & value) { - int result = 0; + int result = 0; - for (auto elem: value) - { - result += logToDlt(log, elem); - } + for (auto elem : value) + result += logToDlt(log, elem); - if (result != 0) - { - result = -1; - } - return result; + if (result != 0) + result = -1; + + return result; } template<typename _Tp, typename _Alloc = std::allocator<_Tp>> -static inline int32_t logToDlt(DltContextData &log, std::list<_Tp, _Alloc > const & value) +static inline int32_t logToDlt(DltContextData &log, std::list<_Tp, _Alloc> const & value) { - int result = 0; + int result = 0; + + for (auto elem : value) + result += logToDlt(log, elem); - for (auto elem: value) - { - result += logToDlt(log, elem); - } + if (result != 0) + result = -1; - if (result != 0) - { - result = -1; - } - return result; + return result; } template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>, - typename _Alloc = std::allocator<std::pair<const _Key, _Tp> >> -static inline int32_t logToDlt(DltContextData &log, std::map<_Key, _Tp, _Compare, _Alloc > const & value) + typename _Alloc = std::allocator<std::pair<const _Key, _Tp>>> +static inline int32_t logToDlt(DltContextData &log, std::map<_Key, _Tp, _Compare, _Alloc> const & value) { - int result = 0; + int result = 0; - for (auto elem: value) - { - result += logToDlt(log, elem.first); - result += logToDlt(log, elem.second); - } + for (auto elem : value) + { + result += logToDlt(log, elem.first); + result += logToDlt(log, elem.second); + } - if (result != 0) - { - result = -1; - } - return result; -} + if (result != 0) + result = -1; + return result; +} //variadic functions using C11 standard template<typename First> static inline int32_t logToDltVariadic(DltContextData &log, First const &valueA) { - return logToDlt(log, valueA); + return logToDlt(log, valueA); } -template<typename First, typename... Rest> +template<typename First, typename ... Rest> static inline int32_t logToDltVariadic(DltContextData &log, First const &valueA, const Rest&... valueB) { - int result = logToDlt(log, valueA) + logToDltVariadic(log, valueB...); - if ( result != 0 ) - { - result = -1; - } - return result; -} + int result = logToDlt(log, valueA) + logToDltVariadic(log, valueB...); + if (result != 0) + result = -1; + + return result; +} /** * @brief macro to write a log message with variable number of arguments and without the need to specify the type of log data @@ -201,14 +195,16 @@ static inline int32_t logToDltVariadic(DltContextData &log, First const &valueA, * DLT_LOG_CXX(dltContext, DLT_LV_X, "text", valueA, valueB, ...) */ #define DLT_LOG_CXX(CONTEXT, LOGLEVEL, ...)\ - do{ \ - DltContextData log; \ - if (dlt_user_log_write_start(&CONTEXT,&log,LOGLEVEL)>0) \ - { \ - logToDltVariadic(log, ##__VA_ARGS__); \ - dlt_user_log_write_finish(&log); \ - } \ - } while(0) + do\ + {\ + DltContextData log;\ + if (dlt_user_log_write_start(&CONTEXT,&log,LOGLEVEL)>0)\ + {\ + logToDltVariadic(log, ##__VA_ARGS__);\ + dlt_user_log_write_finish(&log);\ + }\ + }\ + while(0) /** * @brief macro to write a log message with variable number of arguments and without the need to specify the type of log data. @@ -222,17 +218,16 @@ static inline int32_t logToDltVariadic(DltContextData &log, First const &valueA, * DLT_LOG_FCN_CXX(dltContext, DLT_LV_X, "text", valueA, valueB, ...) */ #define DLT_LOG_FCN_CXX(CONTEXT, LOGLEVEL, ...) \ - do { \ - DltContextData log; \ - if (dlt_user_log_write_start(&CONTEXT, &log, LOGLEVEL) > 0) \ - { \ - dlt_user_log_write_string(&log, __PRETTY_FUNCTION__); \ - logToDltVariadic(log, ##__VA_ARGS__); \ - dlt_user_log_write_finish(&log); \ - } \ - } while(0) - + do\ + {\ + DltContextData log;\ + if (dlt_user_log_write_start(&CONTEXT, &log, LOGLEVEL) > 0)\ + {\ + dlt_user_log_write_string(&log, __PRETTY_FUNCTION__);\ + logToDltVariadic(log, ##__VA_ARGS__);\ + dlt_user_log_write_finish(&log);\ + }\ + }\ + while(0) #endif /* DLT_CPP_EXTENSION_HPP */ - - diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h index baa5746..05bd6b9 100644 --- a/include/dlt/dlt_user.h +++ b/include/dlt/dlt_user.h @@ -176,11 +176,11 @@ typedef enum */ typedef struct { - char contextID[DLT_ID_SIZE]; /**< context id */ - int32_t log_level_pos; /**< offset in user-application context field */ - int8_t *log_level_ptr; /**< pointer to the log level */ - int8_t *trace_status_ptr; /**< pointer to the trace status */ - uint8_t mcnt; /**< message counter */ + char contextID[DLT_ID_SIZE]; /**< context id */ + int32_t log_level_pos; /**< offset in user-application context field */ + int8_t *log_level_ptr; /**< pointer to the log level */ + int8_t *trace_status_ptr; /**< pointer to the trace status */ + uint8_t mcnt; /**< message counter */ } DltContext; /** @@ -582,7 +582,7 @@ int dlt_register_context(DltContext *handle, const char *contextid, const char * * @param loglevel This is the log level to be pre-set for this context (DLT_LOG_DEFAULT is not allowed here) * @param tracestatus This is the trace status to be pre-set for this context - (DLT_TRACE_STATUS_DEFAULT is not allowed here) + (DLT_TRACE_STATUS_DEFAULT is not allowed here) * @return negative value if there was an error */ int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const char * description, int loglevel, int tracestatus); diff --git a/src/console/dlt-logstorage-ctrl.c b/src/console/dlt-logstorage-ctrl.c index 4e34c6f..24742f0 100644 --- a/src/console/dlt-logstorage-ctrl.c +++ b/src/console/dlt-logstorage-ctrl.c @@ -1,25 +1,31 @@ -/** +/* * @licence app begin@ + * SPDX license identifier: MPL-2.0 + * * Copyright (C) 2013 - 2015 Advanced Driver Information Technology. * This code is developed by Advanced Driver Information Technology. - * Copyright of Advanced Driver Information Technology, Bosch and DENSO. - * - * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps. + * Copyright of Advanced Driver Information Technology, Bosch and DENSO * + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. * - * \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/. - * + * Mozilla Public License (MPL), 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/. * + * For further information see http://www.genivi.org/. + * @licence end@ + */ + +/*! * \author Syed Hameed <shameed@jp.adit-jv.com> ADIT 2013 - 2015 * \author Christoph Lipka <clipka@jp.adit-jv.com> ADIT 2015 * + * \copyright Copyright © 2013-2015 Advanced Driver Information Technology. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * * \file dlt-logstorage-ctrl.c - * For further information see http://www.genivi.org/. - * @licence end@ - */ +*/ /******************************************************************************* ** ** diff --git a/src/console/dlt-receive.c b/src/console/dlt-receive.c index 071c1ba..99268e5 100644 --- a/src/console/dlt-receive.c +++ b/src/console/dlt-receive.c @@ -493,14 +493,14 @@ int main(int argc, char* argv[]) { if (dltdata.climit > -1) { - char tmp[256]; - snprintf(tmp, 256, "Using file size limit of %li bytes\n", dltdata.climit); - dlt_log(LOG_INFO, tmp); - dltdata.ohandle = dlt_receive_open_output_file(&dltdata); + char tmp[256]; + snprintf(tmp, 256, "Using file size limit of %li bytes\n", dltdata.climit); + dlt_log(LOG_INFO, tmp); + dltdata.ohandle = dlt_receive_open_output_file(&dltdata); } else /* in case no limit for the output file is given, we simply overwrite any existing file */ { - dltdata.ohandle = open(dltdata.ovalue, O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + dltdata.ohandle = open(dltdata.ovalue, O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); } if (dltdata.ohandle == -1) @@ -612,17 +612,21 @@ int dlt_receive_message_callback(DltMessage *message, void *data) if (dltdata->climit > -1) { int bytes_to_write = message->headersize + message->datasize; + if ((bytes_to_write + dltdata->totalbytes > dltdata->climit)) { - dlt_receive_close_output_file(dltdata); + dlt_receive_close_output_file(dltdata); + if (dlt_receive_open_output_file(dltdata) < 0) { printf("ERROR: dlt_receive_message_callback: Unable to open log when maximum filesize was reached!\n"); return -1; } + dltdata->totalbytes = 0; } } + bytes_written = writev(dltdata->ohandle, iov, 2); dltdata->totalbytes += bytes_written; diff --git a/src/examples/dlt-example-user.c b/src/examples/dlt-example-user.c index 5f4abc9..61550fc 100644 --- a/src/examples/dlt-example-user.c +++ b/src/examples/dlt-example-user.c @@ -269,7 +269,7 @@ int main(int argc, char* argv[]) if(mvalue) { printf("Set log mode to %d\n",atoi(mvalue)); - dlt_set_log_mode(atoi(mvalue)); + dlt_set_log_mode(atoi(mvalue)); } diff --git a/src/lib/dlt_env_ll.c b/src/lib/dlt_env_ll.c index d2ef7b1..a3e3a16 100644 --- a/src/lib/dlt_env_ll.c +++ b/src/lib/dlt_env_ll.c @@ -1,25 +1,29 @@ -/** +/* * @licence app begin@ - * Copyright (C) 2015 Intel Corporation + * SPDX license identifier: MPL-2.0 * - * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps. + * Copyright (C) 2015 Intel Corporation * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. * - * \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 Stefan Vacek <stefan.vacek@intel.com> Intel Corporation + * Mozilla Public License (MPL), 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/. * - * \file dlt_env_ll.c * For further information see http://www.genivi.org/. * @licence end@ */ +/*! + * \author Stefan Vacek <stefan.vacek@intel.com> Intel Corporation + * + * \copyright Copyright © 2015 Intel Corporation. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * + * \file dlt_env_ll.c +*/ + #include "dlt_user.h" #include <string.h> #include <stdlib.h> diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index b996726..9cf4070 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -83,22 +83,22 @@ pthread_cond_t mq_init_condition; void dlt_lock_mutex(pthread_mutex_t *mutex) { - int32_t lock_mutex_result = pthread_mutex_lock(mutex); - if (lock_mutex_result == EOWNERDEAD) - { - pthread_mutex_consistent(mutex); - lock_mutex_result = 0; - } - else if ( lock_mutex_result != 0 ) - { - snprintf(str,DLT_USER_BUFFER_LENGTH, "Mutex lock failed unexpected pid=%i with result %i!\n", getpid(), lock_mutex_result); - dlt_log(LOG_ERR, str); - } + int32_t lock_mutex_result = pthread_mutex_lock(mutex); + if (lock_mutex_result == EOWNERDEAD) + { + pthread_mutex_consistent(mutex); + lock_mutex_result = 0; + } + else if ( lock_mutex_result != 0 ) + { + snprintf(str,DLT_USER_BUFFER_LENGTH, "Mutex lock failed unexpected pid=%i with result %i!\n", getpid(), lock_mutex_result); + dlt_log(LOG_ERR, str); + } } inline void dlt_unlock_mutex(pthread_mutex_t *mutex) { - pthread_mutex_unlock(mutex); + pthread_mutex_unlock(mutex); } /* Structure to pass data to segmented thread */ @@ -286,14 +286,14 @@ int dlt_init(void) pthread_mutexattr_t attr; if (pthread_mutexattr_init(&attr) != 0) { - dlt_user_initialised = 0; - return -1; + dlt_user_initialised = 0; + return -1; } /* make mutex robust to prevent from deadlock when the segmented thread was cancelled, but held the mutex */ if ( pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST) != 0 ) { - dlt_user_initialised = 0; - return -1; + dlt_user_initialised = 0; + return -1; } pthread_mutex_init(&mq_mutex, &attr); @@ -302,8 +302,8 @@ int dlt_init(void) if (dlt_start_threads() < 0) { - dlt_user_initialised = 0; - return -1; + dlt_user_initialised = 0; + return -1; } // prepare for fork() call @@ -471,11 +471,11 @@ int dlt_init_common(void) env_initial_log_level = getenv("DLT_INITIAL_LOG_LEVEL"); if( env_initial_log_level != NULL ) { - if (dlt_env_extract_ll_set(&env_initial_log_level, &dlt_user.initial_ll_set) != 0) - { - snprintf(str, DLT_USER_BUFFER_LENGTH, "Unable to parse initial set of log-levels from environment! Env:\n%s\n", getenv("DLT_INITIAL_LOG_LEVEL")); - dlt_log(LOG_WARNING, str); - } + if (dlt_env_extract_ll_set(&env_initial_log_level, &dlt_user.initial_ll_set) != 0) + { + snprintf(str, DLT_USER_BUFFER_LENGTH, "Unable to parse initial set of log-levels from environment! Env:\n%s\n", getenv("DLT_INITIAL_LOG_LEVEL")); + dlt_log(LOG_WARNING, str); + } } /* Initialize LogLevel/TraceStatus field */ @@ -496,8 +496,8 @@ int dlt_init_common(void) if (atexit_registered == 0) { - atexit_registered = 1; - atexit(dlt_user_atexit_handler); + atexit_registered = 1; + atexit(dlt_user_atexit_handler); } #ifdef DLT_TEST_ENABLE @@ -3443,7 +3443,7 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype) ret = DLT_RETURN_OK; if((dlt_user.dlt_log_handle!=-1) && (dlt_user.appID[0]!='\0')) { - ret = dlt_user_log_resend_buffer(); + ret = dlt_user_log_resend_buffer(); } if((ret == DLT_RETURN_OK) && (dlt_user.appID[0] != '\0')) { @@ -3706,7 +3706,7 @@ int dlt_user_log_send_register_context(DltContextData *log) /* log to FIFO */ if (dlt_user.appID[0]!='\0') { - ret = dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgRegisterContext),log->context_description,usercontext.description_length); + ret = dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgRegisterContext),log->context_description,usercontext.description_length); } @@ -3727,7 +3727,7 @@ int dlt_user_log_send_register_context(DltContextData *log) DLT_SEM_FREE(); - if((dlt_user.appID[0] != '\0') && (dlt_user_queue_resend() < 0) && (dlt_user.dlt_log_handle >= 0)) + if ((dlt_user.appID[0] != '\0') && (dlt_user_queue_resend() < 0) && (dlt_user.dlt_log_handle >= 0)) { ;//dlt_log(LOG_WARNING, "dlt_user_log_send_register_context: Failed to queue resending.\n"); } @@ -4164,7 +4164,7 @@ int dlt_user_log_resend_buffer(void) if (dlt_user.appID[0]=='\0') { - return 0; + return 0; } /* Send content of ringbuffer */ @@ -4180,37 +4180,37 @@ int dlt_user_log_resend_buffer(void) if (size>0) { - DltUserHeader *userheader = (DltUserHeader*) (dlt_user.resend_buffer); - /* Add application id to the messages of needed*/ - if (dlt_user_check_userheader(userheader)) - { - switch (userheader->message) - { - case DLT_USER_MESSAGE_REGISTER_CONTEXT: - { - DltUserControlMsgRegisterContext *usercontext = (DltUserControlMsgRegisterContext*) (dlt_user.resend_buffer+sizeof(DltUserHeader)); - if ((usercontext != 0) && (usercontext->apid[0]=='\0')) + DltUserHeader *userheader = (DltUserHeader*) (dlt_user.resend_buffer); + /* Add application id to the messages of needed*/ + if (dlt_user_check_userheader(userheader)) { - dlt_set_id(usercontext->apid,dlt_user.appID); - } - break; - } - case DLT_USER_MESSAGE_LOG: - { - DltExtendedHeader * extendedHeader = (DltExtendedHeader *)(dlt_user.resend_buffer+sizeof(DltUserHeader)+ - sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra) - DLT_ID_SIZE); - if ((extendedHeader) != 0 && (extendedHeader->apid[0]=='\0')) - { // if application id is empty, add it - dlt_set_id(extendedHeader->apid,dlt_user.appID); + switch (userheader->message) + { + case DLT_USER_MESSAGE_REGISTER_CONTEXT: + { + DltUserControlMsgRegisterContext *usercontext = (DltUserControlMsgRegisterContext*) (dlt_user.resend_buffer+sizeof(DltUserHeader)); + if ((usercontext != 0) && (usercontext->apid[0]=='\0')) + { + dlt_set_id(usercontext->apid,dlt_user.appID); + } + break; + } + case DLT_USER_MESSAGE_LOG: + { + DltExtendedHeader * extendedHeader = (DltExtendedHeader *)(dlt_user.resend_buffer+sizeof(DltUserHeader)+ + sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra) - DLT_ID_SIZE); + if ((extendedHeader) != 0 && (extendedHeader->apid[0]=='\0')) + { // if application id is empty, add it + dlt_set_id(extendedHeader->apid,dlt_user.appID); + } + break; + } + default: + { + break; + } + } } - break; - } - default: - { - break; - } - } - } #ifdef DLT_SHM_ENABLE dlt_shm_push(&dlt_user.dlt_shm,dlt_user.resend_buffer+sizeof(DltUserHeader),size-sizeof(DltUserHeader),0,0,0,0); @@ -4377,101 +4377,107 @@ void dlt_user_test_corrupt_message_size(int enable,int16_t size) int dlt_start_threads() { - /* Start receiver thread */ - if (pthread_create(&(dlt_receiverthread_handle), - 0, - (void *) &dlt_user_receiverthread_function, - 0)!=0) - { - dlt_log(LOG_CRIT, "Can't create receiver thread!\n"); - return -1; - } + /* Start receiver thread */ + if (pthread_create(&(dlt_receiverthread_handle), + 0, + (void *) &dlt_user_receiverthread_function, + 0) != 0) + { + dlt_log(LOG_CRIT, "Can't create receiver thread!\n"); + return -1; + } - /* Start the segmented thread */ - if (pthread_create(&(dlt_user.dlt_segmented_nwt_handle), NULL, - (void *)dlt_user_trace_network_segmented_thread, NULL)) - { - dlt_log(LOG_CRIT, "Can't start segmented thread!\n"); - return -1; - } + /* Start the segmented thread */ + if (pthread_create(&(dlt_user.dlt_segmented_nwt_handle), NULL, + (void *) dlt_user_trace_network_segmented_thread, NULL)) + { + dlt_log(LOG_CRIT, "Can't start segmented thread!\n"); + return -1; + } - return 0; + return 0; } - void dlt_stop_threads() { - int dlt_receiverthread_result = 0; - int dlt_segmented_nwt_result = 0; - if (dlt_receiverthread_handle) - { - /* do not ignore return value */ - dlt_receiverthread_result = pthread_cancel(dlt_receiverthread_handle); - if (dlt_receiverthread_result != 0) + int dlt_receiverthread_result = 0; + int dlt_segmented_nwt_result = 0; + if (dlt_receiverthread_handle) { - snprintf(str,DLT_USER_BUFFER_LENGTH, "ERROR pthread_cancel(dlt_receiverthread_handle): %s\n", strerror(errno)); - dlt_log(LOG_ERR, str); + /* do not ignore return value */ + dlt_receiverthread_result = pthread_cancel(dlt_receiverthread_handle); + if (dlt_receiverthread_result != 0) + { + snprintf(str, DLT_USER_BUFFER_LENGTH, + "ERROR pthread_cancel(dlt_receiverthread_handle): %s\n", + strerror(errno)); + dlt_log(LOG_ERR, str); + } } - } - if (dlt_user.dlt_segmented_nwt_handle) - { - dlt_segmented_nwt_result = pthread_cancel(dlt_user.dlt_segmented_nwt_handle); - if (dlt_segmented_nwt_result != 0) + if (dlt_user.dlt_segmented_nwt_handle) { - snprintf(str,DLT_USER_BUFFER_LENGTH, "ERROR pthread_cancel(dlt_user.dlt_segmented_nwt_handle): %s\n", strerror(errno)); - dlt_log(LOG_ERR, str); + dlt_segmented_nwt_result = pthread_cancel(dlt_user.dlt_segmented_nwt_handle); + if (dlt_segmented_nwt_result != 0) + { + snprintf(str, DLT_USER_BUFFER_LENGTH, + "ERROR pthread_cancel(dlt_user.dlt_segmented_nwt_handle): %s\n", + strerror(errno)); + dlt_log(LOG_ERR, str); + } } - } - /* make sure that the threads really finished working */ - if ((dlt_receiverthread_result==0) && dlt_receiverthread_handle) - { - int joined = pthread_join(dlt_receiverthread_handle, NULL); - if (joined < 0) + /* make sure that the threads really finished working */ + if ((dlt_receiverthread_result == 0) && dlt_receiverthread_handle) { - snprintf(str,DLT_USER_BUFFER_LENGTH, "ERROR pthread_join(dlt_receiverthread_handle, NULL): %s\n", strerror(errno)); - dlt_log(LOG_ERR, str); + int joined = pthread_join(dlt_receiverthread_handle, NULL); + if (joined < 0) + { + snprintf(str, DLT_USER_BUFFER_LENGTH, + "ERROR pthread_join(dlt_receiverthread_handle, NULL): %s\n", + strerror(errno)); + dlt_log(LOG_ERR, str); + } + dlt_receiverthread_handle = 0; /* set to invalid */ } - dlt_receiverthread_handle = 0; /* set to invalid */ - } - if ((dlt_segmented_nwt_result==0) && dlt_user.dlt_segmented_nwt_handle) - { - int joined = pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL); - if (joined < 0) + if ((dlt_segmented_nwt_result == 0) && dlt_user.dlt_segmented_nwt_handle) { - snprintf(str,DLT_USER_BUFFER_LENGTH, "ERROR pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL): %s\n", strerror(errno)); - dlt_log(LOG_ERR, str); + int joined = pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL); + if (joined < 0) + { + snprintf(str, DLT_USER_BUFFER_LENGTH, + "ERROR pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL): %s\n", + strerror(errno)); + dlt_log(LOG_ERR, str); + } + dlt_user.dlt_segmented_nwt_handle = 0; /* set to invalid */ } - dlt_user.dlt_segmented_nwt_handle = 0; /* set to invalid */ - } } - static void dlt_fork_pre_fork_handler() { - dlt_stop_threads(); + dlt_stop_threads(); } - static void dlt_fork_parent_fork_handler() { - if (dlt_start_threads() < 0) - { - snprintf(str,DLT_USER_BUFFER_LENGTH,"Logging disabled, failed re-start thread after fork(pid=%i)!\n", getpid()); - dlt_log(LOG_WARNING, str); - /* cleanup is the only thing we can do here */ - dlt_log_free(); - dlt_free(); - } + if (dlt_start_threads() < 0) + { + snprintf(str, DLT_USER_BUFFER_LENGTH, + "Logging disabled, failed re-start thread after fork(pid=%i)!\n", + getpid()); + dlt_log(LOG_WARNING, str); + /* cleanup is the only thing we can do here */ + dlt_log_free(); + dlt_free(); + } } - static void dlt_fork_child_fork_handler() { - /* don't start anything else but cleanup everything and avoid blow-out of buffers*/ - dlt_log_free(); - dlt_free(); - /* the only thing that remains is the atexit-handler */ + /* don't start anything else but cleanup everything and avoid blow-out of buffers*/ + dlt_log_free(); + dlt_free(); + /* the only thing that remains is the atexit-handler */ } diff --git a/src/tests/dlt-test-fork-handler.c b/src/tests/dlt-test-fork-handler.c index d9c65e5..84685f9 100644 --- a/src/tests/dlt-test-fork-handler.c +++ b/src/tests/dlt-test-fork-handler.c @@ -1,8 +1,29 @@ -/** - * Copyright (C) 2015 Intel Corporation +/* + * @licence app begin@ + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2015 Intel Corporation + * + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. * + * This Source Code Form is subject to the terms of the + * Mozilla Public License (MPL), 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/. + * + * For further information see http://www.genivi.org/. + * @licence end@ */ +/*! + * \author Stefan Vacek <stefan.vacek@intel.com> Intel Corporation + * + * \copyright Copyright © 2015 Intel Corporation. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * + * \file dlt-test-fork-handler.c +*/ + #include <unistd.h> /* for fork() */ #include "dlt.h" @@ -12,36 +33,37 @@ */ int main() { - DltContext mainContext; - - DLT_REGISTER_APP("PRNT", "Parent application"); - DLT_REGISTER_CONTEXT(mainContext, "CTXP", "Parent context"); - DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message before fork")); - usleep(200000); - - pid_t pid = fork(); - if (pid == 0) /* child process */ - { - /* this message should not be visible */ - /* DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Child's first message after fork, pid: "), DLT_INT32(getpid())); */ - /* unfortunately, this message does arrive, I assume because it still has (locally) valid data ... */ - - DLT_REGISTER_APP("CHLD", "Child application"); - DLT_REGISTER_CONTEXT(mainContext, "CTXC", "Child context"); - DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Child's second message after fork, pid: "), DLT_INT32(getpid())); - usleep(400000); - } - else if (pid == -1) /* error in fork */ - { - return -1; - } - else /* parent */ - { - DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Parent's first message after fork, pid: "), DLT_INT32(getpid())); - usleep(500000); - } - - DLT_UNREGISTER_APP(); - - return 0; + DltContext mainContext; + + DLT_REGISTER_APP("PRNT", "Parent application"); + DLT_REGISTER_CONTEXT(mainContext, "CTXP", "Parent context"); + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message before fork")); + usleep(200000); + + pid_t pid = fork(); + if (pid == 0) /* child process */ + { + /* this message should not be visible */ + /* DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Child's first message after fork, pid: "), DLT_INT32(getpid())); */ + /* unfortunately, this message does arrive, I assume because it still has (locally) valid data ... */ + + DLT_REGISTER_APP("CHLD", "Child application"); + DLT_REGISTER_CONTEXT(mainContext, "CTXC", "Child context"); + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Child's second message after fork, pid: "), DLT_INT32(getpid())); + usleep(400000); + } + else if (pid == -1) /* error in fork */ + { + return -1; + } + else /* parent */ + { + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Parent's first message after fork, pid: "), DLT_INT32(getpid())); + usleep(500000); + } + + DLT_UNREGISTER_APP() + ; + + return 0; } diff --git a/tests/dlt-test-cpp-extension.cpp b/tests/dlt-test-cpp-extension.cpp index ce9f1db..c4cf70c 100644 --- a/tests/dlt-test-cpp-extension.cpp +++ b/tests/dlt-test-cpp-extension.cpp @@ -1,118 +1,122 @@ -/** +/* * @licence app begin@ - * Copyright (C) 2015 Intel Corporation + * SPDX license identifier: MPL-2.0 * - * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps. + * Copyright (C) 2015 Intel Corporation * - * Contributions are licensed to the GENIVI Alliance under one or more - * Contribution License Agreements. + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. * - * \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/. + * Mozilla Public License (MPL), 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/. * - * \file dlt-test-cpp-extension.cpp * For further information see http://www.genivi.org/. * @licence end@ */ +/*! + * \author Stefan Vacek <stefan.vacek@intel.com> Intel Corporation + * + * \copyright Copyright © 2015 Intel Corporation. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * + * \file dlt-test-cpp-extension.cpp +*/ + #include "dlt_cpp_extension.hpp" #include <stdio.h> #include <string.h> - struct MyStruct { - int64_t uuid; - int32_t interfaceId; - int32_t registrationState; + int64_t uuid; + int32_t interfaceId; + int32_t registrationState; }; - template<> inline int logToDlt(DltContextData & log, MyStruct const & value) { - int result = 0; - - result += dlt_user_log_write_string(&log, "("); - result += logToDlt(log, value.uuid); - result += dlt_user_log_write_string(&log, ","); - result += logToDlt(log, value.interfaceId); - result += dlt_user_log_write_string(&log, ","); - result += logToDlt(log, value.registrationState); - result += dlt_user_log_write_string(&log, ")"); - - if (result != 0) - { - result = -1; - } - - return result; + int result = 0; + + result += dlt_user_log_write_string(&log, "("); + result += logToDlt(log, value.uuid); + result += dlt_user_log_write_string(&log, ","); + result += logToDlt(log, value.interfaceId); + result += dlt_user_log_write_string(&log, ","); + result += logToDlt(log, value.registrationState); + result += dlt_user_log_write_string(&log, ")"); + + if (result != 0) + { + result = -1; + } + + return result; } - /** * Sample code to show usage of the cpp-extension * mainly the variadic templates */ int main() { - if (dlt_register_app("TCPP", "Test cpp extension") < 0) - { - printf("Failed to register application\n"); - return -1; - } - - DltContext ctx; - if (dlt_register_context_ll_ts(&ctx, "TCPP", "Test cpp extension", DLT_LOG_INFO, DLT_TRACE_STATUS_OFF) < 0) - { - printf("Failed to register context\n"); - return -1; - } - - dlt_enable_local_print(); - dlt_verbose_mode(); - - DLT_LOG(ctx, DLT_LOG_WARN, DLT_STRING("a message")); /* the classic way to go */ - - int an_int = 42; - float a_float = 22.7; - DLT_LOG_FCN_CXX(ctx, DLT_LOG_WARN, "Testing DLT_LOG_CXX_FCN", an_int, a_float); - DLT_LOG_CXX(ctx, DLT_LOG_WARN, 1.0, 65); - - /* Example for logging user-defined types */ - MyStruct myData = { 1u, 2u, 3u}; - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "MyStruct myData", myData); - - char * non_const_string = (char *)malloc(17); - memcpy(non_const_string, "non_const_string", 16); - non_const_string[16] = 0; - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "char *", non_const_string); - - std::string aString = "std::string"; - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "std::string", aString); - - std::vector<int> intVector; - intVector.push_back(0); - intVector.push_back(1); - intVector.push_back(2); - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "vector", intVector); - - std::vector<double> doubleList; - doubleList.push_back(10.); - doubleList.push_back(11.); - doubleList.push_back(12.); - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "list", doubleList); - - std::map<const char *, int> testMap; - testMap["apple"] = 100; - testMap["plum"] = 200; - testMap["orange"] = 300; - DLT_LOG_CXX(ctx, DLT_LOG_WARN, "map", testMap); - - dlt_unregister_context(&ctx); - dlt_unregister_app(); - - return 0; + if (dlt_register_app("TCPP", "Test cpp extension") < 0) + { + printf("Failed to register application\n"); + return -1; + } + + DltContext ctx; + if (dlt_register_context_ll_ts(&ctx, "TCPP", "Test cpp extension", DLT_LOG_INFO, DLT_TRACE_STATUS_OFF) < 0) + { + printf("Failed to register context\n"); + return -1; + } + + dlt_enable_local_print(); + dlt_verbose_mode(); + + DLT_LOG(ctx, DLT_LOG_WARN, DLT_STRING("a message")); /* the classic way to go */ + + int an_int = 42; + float a_float = 22.7; + DLT_LOG_FCN_CXX(ctx, DLT_LOG_WARN, "Testing DLT_LOG_CXX_FCN", an_int, a_float); + DLT_LOG_CXX(ctx, DLT_LOG_WARN, 1.0, 65); + + /* Example for logging user-defined types */ + MyStruct myData = { 1u, 2u, 3u }; + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "MyStruct myData", myData); + + char * non_const_string = (char *) malloc(17); + memcpy(non_const_string, "non_const_string", 16); + non_const_string[16] = 0; + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "char *", non_const_string); + + std::string aString = "std::string"; + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "std::string", aString); + + std::vector<int> intVector; + intVector.push_back(0); + intVector.push_back(1); + intVector.push_back(2); + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "vector", intVector); + + std::vector<double> doubleList; + doubleList.push_back(10.); + doubleList.push_back(11.); + doubleList.push_back(12.); + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "list", doubleList); + + std::map<const char *, int> testMap; + testMap["apple"] = 100; + testMap["plum"] = 200; + testMap["orange"] = 300; + DLT_LOG_CXX(ctx, DLT_LOG_WARN, "map", testMap); + + dlt_unregister_context(&ctx); + dlt_unregister_app(); + + return 0; } diff --git a/tests/dlt-test-preregister-context.c b/tests/dlt-test-preregister-context.c index ad10d6f..2f66347 100644 --- a/tests/dlt-test-preregister-context.c +++ b/tests/dlt-test-preregister-context.c @@ -1,8 +1,29 @@ -/** - * Copyright (C) 2015 Intel Corporation +/* + * @licence app begin@ + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2015 Intel Corporation + * + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. + * + * This Source Code Form is subject to the terms of the + * Mozilla Public License (MPL), 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/. * + * For further information see http://www.genivi.org/. + * @licence end@ */ +/*! + * \author Stefan Vacek <stefan.vacek@intel.com> Intel Corporation + * + * \copyright Copyright © 2015 Intel Corporation. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * + * \file dlt-test-preregister-context.c +*/ + #include <unistd.h> /* for fork() */ #include "dlt.h" @@ -12,21 +33,22 @@ */ int main() { - DltContext mainContext; - DLT_REGISTER_CONTEXT(mainContext, "CTXP", "main context"); + DltContext mainContext; + DLT_REGISTER_CONTEXT(mainContext, "CTXP", "main context"); - DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message before app registered")); - usleep(200000); + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message before app registered")); + usleep(200000); - DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Second message before app registered")); - usleep(200000); + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("Second message before app registered")); + usleep(200000); - DLT_REGISTER_APP("PRNT", "Sample pre-register application"); + DLT_REGISTER_APP("PRNT", "Sample pre-register application"); - DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message after app registered")); - usleep(200000); + DLT_LOG(mainContext, DLT_LOG_WARN, DLT_STRING("First message after app registered")); + usleep(200000); - DLT_UNREGISTER_APP(); + DLT_UNREGISTER_APP() + ; - return 0; + return 0; } diff --git a/tests/dlt_env_ll_unit_test.cpp b/tests/dlt_env_ll_unit_test.cpp index f50e603..10c8907 100644 --- a/tests/dlt_env_ll_unit_test.cpp +++ b/tests/dlt_env_ll_unit_test.cpp @@ -1,10 +1,28 @@ /* -@COPYRIGHT_TAG@ - */ -/** - * @file + * @licence app begin@ + * SPDX license identifier: MPL-2.0 + * + * Copyright (C) 2015 Intel Corporation + * + * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. + * + * This Source Code Form is subject to the terms of the + * Mozilla Public License (MPL), 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/. + * + * For further information see http://www.genivi.org/. + * @licence end@ */ +/*! + * \author Stefan Vacek <stefan.vacek@intel.com> Intel Corporation + * + * \copyright Copyright © 2015 Intel Corporation. \n + * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. + * + * \file dlt_env_ll_unit_test.cpp +*/ #include "gtest/gtest.h" #include "dlt_user.h" @@ -13,528 +31,515 @@ /* simply include the whole file to allow testing it */ #include "src/lib/dlt_env_ll.c" - int main(int argc, char* argv[]) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } - TEST(DltExtensionTests, extract_id) { - /* testing valid input */ - char id[4u]; - - char env0[] = "abcd:1234:3"; - char *tmp = &env0[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); - ASSERT_EQ(tmp - &env0[0], 4); // moved 4 bytes - ASSERT_EQ(id[0], 'a'); - ASSERT_EQ(id[1], 'b'); - ASSERT_EQ(id[2], 'c'); - ASSERT_EQ(id[3], 'd'); - - char env1[] = "abc:1234:3"; - tmp = &env1[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); - ASSERT_EQ(tmp - &env1[0], 3); // moved 3 bytes - ASSERT_EQ(id[0], 'a'); - ASSERT_EQ(id[1], 'b'); - ASSERT_EQ(id[2], 'c'); - ASSERT_EQ(id[3], 0); - - char env2[] = "ab:1234:3"; - tmp = &env2[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); - ASSERT_EQ(tmp - &env2[0], 2); // moved 2 bytes - ASSERT_EQ(id[0], 'a'); - ASSERT_EQ(id[1], 'b'); - ASSERT_EQ(id[2], 0); - ASSERT_EQ(id[3], 0); - - char env3[] = "a:1234:3"; - tmp = &env3[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); - ASSERT_EQ(tmp - &env3[0], 1); // moved 1 byte - ASSERT_EQ(id[0], 'a'); - ASSERT_EQ(id[1], 0); - ASSERT_EQ(id[2], 0); - ASSERT_EQ(id[3], 0); - - char env4[] = ":1234:3"; - tmp = &env4[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); - ASSERT_EQ(tmp - &env4[0], 0); // moved 1 byte - ASSERT_EQ(id[0], 0); - ASSERT_EQ(id[1], 0); - ASSERT_EQ(id[2], 0); - ASSERT_EQ(id[3], 0); - - char env5[] = "abcd:1234:3;"; - tmp = &env5[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); - ASSERT_EQ(tmp - &env5[0], 4); // moved 4 bytes - ASSERT_EQ(id[0], 'a'); - ASSERT_EQ(id[1], 'b'); - ASSERT_EQ(id[2], 'c'); - ASSERT_EQ(id[3], 'd'); - - - /* testing invalid input */ - /* - string too long: abcde: - * - string too short/missing end: abc - * - NULL string: <null> - */ - tmp = NULL; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); - - char env6[] = "abcd:1234:3"; - tmp = &env6[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, NULL), -1); - - char invalid0[] = ""; - tmp = &invalid0[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); - - char invalid1[] = "abcd"; /* missing delimiter */ - tmp = &invalid1[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); - - char invalid2[] = "abcde"; /* id too long */ - tmp = &invalid2[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); + /* testing valid input */ + char id[4u]; + + char env0[] = "abcd:1234:3"; + char *tmp = &env0[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); + ASSERT_EQ(tmp - &env0[0], 4); // moved 4 bytes + ASSERT_EQ(id[0], 'a'); + ASSERT_EQ(id[1], 'b'); + ASSERT_EQ(id[2], 'c'); + ASSERT_EQ(id[3], 'd'); + + char env1[] = "abc:1234:3"; + tmp = &env1[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); + ASSERT_EQ(tmp - &env1[0], 3); // moved 3 bytes + ASSERT_EQ(id[0], 'a'); + ASSERT_EQ(id[1], 'b'); + ASSERT_EQ(id[2], 'c'); + ASSERT_EQ(id[3], 0); + + char env2[] = "ab:1234:3"; + tmp = &env2[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); + ASSERT_EQ(tmp - &env2[0], 2); // moved 2 bytes + ASSERT_EQ(id[0], 'a'); + ASSERT_EQ(id[1], 'b'); + ASSERT_EQ(id[2], 0); + ASSERT_EQ(id[3], 0); + + char env3[] = "a:1234:3"; + tmp = &env3[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); + ASSERT_EQ(tmp - &env3[0], 1); // moved 1 byte + ASSERT_EQ(id[0], 'a'); + ASSERT_EQ(id[1], 0); + ASSERT_EQ(id[2], 0); + ASSERT_EQ(id[3], 0); + + char env4[] = ":1234:3"; + tmp = &env4[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); + ASSERT_EQ(tmp - &env4[0], 0); // moved 1 byte + ASSERT_EQ(id[0], 0); + ASSERT_EQ(id[1], 0); + ASSERT_EQ(id[2], 0); + ASSERT_EQ(id[3], 0); + + char env5[] = "abcd:1234:3;"; + tmp = &env5[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), 0); + ASSERT_EQ(tmp - &env5[0], 4); // moved 4 bytes + ASSERT_EQ(id[0], 'a'); + ASSERT_EQ(id[1], 'b'); + ASSERT_EQ(id[2], 'c'); + ASSERT_EQ(id[3], 'd'); + + /* testing invalid input */ + /* - string too long: abcde: + * - string too short/missing end: abc + * - NULL string: <null> + */ + tmp = NULL; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); + + char env6[] = "abcd:1234:3"; + tmp = &env6[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, NULL), -1); + + char invalid0[] = ""; + tmp = &invalid0[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); + + char invalid1[] = "abcd"; /* missing delimiter */ + tmp = &invalid1[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); + + char invalid2[] = "abcde"; /* id too long */ + tmp = &invalid2[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, id), -1); } - TEST(DltExtensionTests, extract_ll) { - /* testing valid input */ - int8_t ll; - - char env_1[] = "-1"; - char *tmp = &env_1[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env_1[0], 2); // moved 2 bytes - ASSERT_EQ(ll, -1); - - char env0[] = "0;"; - tmp = &env0[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env0[0], 1); // moved 1 byte - ASSERT_EQ(ll, 0); - - char env1[] = "1;"; - tmp = &env1[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env1[0], 1); // moved 1 byte - ASSERT_EQ(ll, 1); - - char env2[] = "2;"; - tmp = &env2[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env2[0], 1); // moved 1 byte - ASSERT_EQ(ll, 2); - - char env3[] = "3;"; - tmp = &env3[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env3[0], 1); // moved 1 byte - ASSERT_EQ(ll, 3); - - char env4[] = "4;"; - tmp = &env4[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env4[0], 1); // moved 1 byte - ASSERT_EQ(ll, 4); - - char env5[] = "5;"; - tmp = &env5[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env5[0], 1); // moved 1 byte - ASSERT_EQ(ll, 5); - - char env6[] = "6;"; - tmp = &env6[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); - ASSERT_EQ(tmp - &env6[0], 1); // moved 1 byte - ASSERT_EQ(ll, 6); - - /* testing invalid input */ - /* - number outside range, e.g. -2, 103 - * - missing delimiter - * - NULL string: <null> - */ - tmp = NULL; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); - - char env7[] = "abcd:1234:3"; - tmp = &env7[0]; - ASSERT_EQ(dlt_env_extract_id(&tmp, NULL), -1); - - char invalid0[] = ""; - tmp = &invalid0[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); - - char invalid1[] = "-2"; /* outside range */ - tmp = &invalid1[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); - - char invalid2[] = "8"; /* outside range */ - tmp = &invalid2[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); - - char invalid3[] = "1e"; /* missing delimiter */ - tmp = &invalid3[0]; - ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); + /* testing valid input */ + int8_t ll; + + char env_1[] = "-1"; + char *tmp = &env_1[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env_1[0], 2); // moved 2 bytes + ASSERT_EQ(ll, -1); + + char env0[] = "0;"; + tmp = &env0[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env0[0], 1); // moved 1 byte + ASSERT_EQ(ll, 0); + + char env1[] = "1;"; + tmp = &env1[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env1[0], 1); // moved 1 byte + ASSERT_EQ(ll, 1); + + char env2[] = "2;"; + tmp = &env2[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env2[0], 1); // moved 1 byte + ASSERT_EQ(ll, 2); + + char env3[] = "3;"; + tmp = &env3[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env3[0], 1); // moved 1 byte + ASSERT_EQ(ll, 3); + + char env4[] = "4;"; + tmp = &env4[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env4[0], 1); // moved 1 byte + ASSERT_EQ(ll, 4); + + char env5[] = "5;"; + tmp = &env5[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env5[0], 1); // moved 1 byte + ASSERT_EQ(ll, 5); + + char env6[] = "6;"; + tmp = &env6[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), 0); + ASSERT_EQ(tmp - &env6[0], 1); // moved 1 byte + ASSERT_EQ(ll, 6); + + /* testing invalid input */ + /* - number outside range, e.g. -2, 103 + * - missing delimiter + * - NULL string: <null> + */ + tmp = NULL; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); + + char env7[] = "abcd:1234:3"; + tmp = &env7[0]; + ASSERT_EQ(dlt_env_extract_id(&tmp, NULL), -1); + + char invalid0[] = ""; + tmp = &invalid0[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); + + char invalid1[] = "-2"; /* outside range */ + tmp = &invalid1[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); + + char invalid2[] = "8"; /* outside range */ + tmp = &invalid2[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); + + char invalid3[] = "1e"; /* missing delimiter */ + tmp = &invalid3[0]; + ASSERT_EQ(dlt_env_extract_ll(&tmp, &ll), -1); } - TEST(DltExtensionTests, extract_ll_item) { - /* testing valid input */ - dlt_env_ll_item item; - - char env0[] = "abcd:1234:3"; - char *tmp = &env0[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), 0); - ASSERT_EQ(tmp - &env0[0], 11); // moved 11 bytes - ASSERT_EQ(item.appId[0], 'a'); - ASSERT_EQ(item.appId[1], 'b'); - ASSERT_EQ(item.appId[2], 'c'); - ASSERT_EQ(item.appId[3], 'd'); - ASSERT_EQ(item.ctxId[0], '1'); - ASSERT_EQ(item.ctxId[1], '2'); - ASSERT_EQ(item.ctxId[2], '3'); - ASSERT_EQ(item.ctxId[3], '4'); - ASSERT_EQ(item.ll, 3); - - char env1[] = "::-1;"; - tmp = &env1[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), 0); - ASSERT_EQ(tmp - &env1[0], 4); // moved 4 bytes - ASSERT_EQ(item.appId[0], 0); - ASSERT_EQ(item.appId[1], 0); - ASSERT_EQ(item.appId[2], 0); - ASSERT_EQ(item.appId[3], 0); - ASSERT_EQ(item.ctxId[0], 0); - ASSERT_EQ(item.ctxId[1], 0); - ASSERT_EQ(item.ctxId[2], 0); - ASSERT_EQ(item.ctxId[3], 0); - ASSERT_EQ(item.ll, -1); - - /* testing invalid input */ - /* - string too long: abcde: - * - string too short/missing end: abc - * - NULL string: <null> - */ - tmp = NULL; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); - - char env2[] = "abcd:1234:3"; - tmp = &env2[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, NULL), -1); - - char invalid0[] = ""; - tmp = &invalid0[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); - - char invalid1[] = "abcd:1234:"; /* missing ll */ - tmp = &invalid1[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); - - char invalid2[] = "abcd:1234"; /* missing ll, missing delimiter in ctxId */ - tmp = &invalid2[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); - - char invalid3[] = "abcd:"; /* missing ll, missing delimiter in appId */ - tmp = &invalid3[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); - - char invalid4[] = "abcd"; /* missing ll, missing delimiter in appId */ - tmp = &invalid4[0]; - ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); + /* testing valid input */ + dlt_env_ll_item item; + + char env0[] = "abcd:1234:3"; + char *tmp = &env0[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), 0); + ASSERT_EQ(tmp - &env0[0], 11); // moved 11 bytes + ASSERT_EQ(item.appId[0], 'a'); + ASSERT_EQ(item.appId[1], 'b'); + ASSERT_EQ(item.appId[2], 'c'); + ASSERT_EQ(item.appId[3], 'd'); + ASSERT_EQ(item.ctxId[0], '1'); + ASSERT_EQ(item.ctxId[1], '2'); + ASSERT_EQ(item.ctxId[2], '3'); + ASSERT_EQ(item.ctxId[3], '4'); + ASSERT_EQ(item.ll, 3); + + char env1[] = "::-1;"; + tmp = &env1[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), 0); + ASSERT_EQ(tmp - &env1[0], 4); // moved 4 bytes + ASSERT_EQ(item.appId[0], 0); + ASSERT_EQ(item.appId[1], 0); + ASSERT_EQ(item.appId[2], 0); + ASSERT_EQ(item.appId[3], 0); + ASSERT_EQ(item.ctxId[0], 0); + ASSERT_EQ(item.ctxId[1], 0); + ASSERT_EQ(item.ctxId[2], 0); + ASSERT_EQ(item.ctxId[3], 0); + ASSERT_EQ(item.ll, -1); + + /* testing invalid input */ + /* - string too long: abcde: + * - string too short/missing end: abc + * - NULL string: <null> + */ + tmp = NULL; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); + + char env2[] = "abcd:1234:3"; + tmp = &env2[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, NULL), -1); + + char invalid0[] = ""; + tmp = &invalid0[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); + + char invalid1[] = "abcd:1234:"; /* missing ll */ + tmp = &invalid1[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); + + char invalid2[] = "abcd:1234"; /* missing ll, missing delimiter in ctxId */ + tmp = &invalid2[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); + + char invalid3[] = "abcd:"; /* missing ll, missing delimiter in appId */ + tmp = &invalid3[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); + + char invalid4[] = "abcd"; /* missing ll, missing delimiter in appId */ + tmp = &invalid4[0]; + ASSERT_EQ(dlt_env_extract_ll_item(&tmp, &item), -1); } - TEST(DltExtensionTests, basic_ll_set_handling) { - dlt_env_init_ll_set(NULL); // must not crash - dlt_env_free_ll_set(NULL); // must not crash - dlt_env_increase_ll_set(NULL); // must not crash - - dlt_env_ll_set ll_set; - dlt_env_init_ll_set(&ll_set); - EXPECT_TRUE(NULL != ll_set.item); - EXPECT_EQ(DLT_ENV_LL_SET_INCREASE, ll_set.array_size); - EXPECT_EQ(0, ll_set.num_elem); - - dlt_env_free_ll_set(&ll_set); - EXPECT_TRUE(NULL == ll_set.item); - EXPECT_EQ(0, ll_set.array_size); - EXPECT_EQ(0, ll_set.num_elem); - - dlt_env_init_ll_set(&ll_set); - for (int i = 0; i<DLT_ENV_LL_SET_INCREASE; ++i) - { - ll_set.item[i].ll = i; - } - dlt_env_increase_ll_set(&ll_set); - EXPECT_EQ(2 * DLT_ENV_LL_SET_INCREASE, ll_set.array_size); - for (int i = 0; i<DLT_ENV_LL_SET_INCREASE; ++i) - { - EXPECT_EQ(ll_set.item[i].ll, i); - } - dlt_env_free_ll_set(&ll_set); - EXPECT_TRUE(NULL == ll_set.item); - EXPECT_EQ(0, ll_set.array_size); - EXPECT_EQ(0, ll_set.num_elem); + dlt_env_init_ll_set(NULL); // must not crash + dlt_env_free_ll_set(NULL); // must not crash + dlt_env_increase_ll_set(NULL); // must not crash + + dlt_env_ll_set ll_set; + dlt_env_init_ll_set(&ll_set); + EXPECT_TRUE(NULL != ll_set.item); + EXPECT_EQ(DLT_ENV_LL_SET_INCREASE, ll_set.array_size); + EXPECT_EQ(0, ll_set.num_elem); + + dlt_env_free_ll_set(&ll_set); + EXPECT_TRUE(NULL == ll_set.item); + EXPECT_EQ(0, ll_set.array_size); + EXPECT_EQ(0, ll_set.num_elem); + + dlt_env_init_ll_set(&ll_set); + for (int i = 0; i < DLT_ENV_LL_SET_INCREASE; ++i) + { + ll_set.item[i].ll = i; + } + dlt_env_increase_ll_set(&ll_set); + EXPECT_EQ(2 * DLT_ENV_LL_SET_INCREASE, ll_set.array_size); + for (int i = 0; i < DLT_ENV_LL_SET_INCREASE; ++i) + { + EXPECT_EQ(ll_set.item[i].ll, i); + } + dlt_env_free_ll_set(&ll_set); + EXPECT_TRUE(NULL == ll_set.item); + EXPECT_EQ(0, ll_set.array_size); + EXPECT_EQ(0, ll_set.num_elem); } - TEST(DltExtensionTests, extract_ll_set) { - /* testing valid input */ - dlt_env_ll_set ll_set; - - char env0[] = "abcd:1234:3"; - char *tmp = &env0[0]; - - ASSERT_EQ(dlt_env_extract_ll_set(&tmp, &ll_set), 0); - EXPECT_EQ(ll_set.array_size, DLT_ENV_LL_SET_INCREASE); - EXPECT_EQ(ll_set.num_elem, 1); - EXPECT_EQ(ll_set.item[0].ll, 3); - - dlt_env_free_ll_set(&ll_set); - - /* force increasing the list */ - char env1[] = "abcd:0000:3;abcd:0001:3;abcd:0002:3;abcd:0003:3;abcd:0004:3;abcd:0005:3;abcd:0006:3;abcd:0007:3;abcd:0008:3;abcd:0009:3;abcd:0010:3"; - tmp = &env1[0]; - ASSERT_EQ(dlt_env_extract_ll_set(&tmp, &ll_set), 0); - EXPECT_EQ(ll_set.array_size, 2 * DLT_ENV_LL_SET_INCREASE); - EXPECT_EQ(ll_set.num_elem, 11); - for (size_t i = 0; i<ll_set.num_elem; ++i) - { - EXPECT_EQ(ll_set.item[i].ctxId[3], i%10 + '0'); - } - - dlt_env_free_ll_set(&ll_set); - - char env2[] = "SINA:SINC:FATAL"; - tmp = &env2[0]; - - ASSERT_EQ(dlt_env_extract_ll_set(&tmp, &ll_set), 0); - EXPECT_EQ(ll_set.array_size, DLT_ENV_LL_SET_INCREASE); - EXPECT_EQ(ll_set.num_elem, 1); - EXPECT_EQ(ll_set.item[0].ll, 1); - - dlt_env_free_ll_set(&ll_set); + /* testing valid input */ + dlt_env_ll_set ll_set; + + char env0[] = "abcd:1234:3"; + char *tmp = &env0[0]; + + ASSERT_EQ(dlt_env_extract_ll_set(&tmp, &ll_set), 0); + EXPECT_EQ(ll_set.array_size, DLT_ENV_LL_SET_INCREASE); + EXPECT_EQ(ll_set.num_elem, 1); + EXPECT_EQ(ll_set.item[0].ll, 3); + + dlt_env_free_ll_set(&ll_set); + + /* force increasing the list */ + char env1[] = + "abcd:0000:3;abcd:0001:3;abcd:0002:3;abcd:0003:3;abcd:0004:3;abcd:0005:3;abcd:0006:3;abcd:0007:3;abcd:0008:3;abcd:0009:3;abcd:0010:3"; + tmp = &env1[0]; + ASSERT_EQ(dlt_env_extract_ll_set(&tmp, &ll_set), 0); + EXPECT_EQ(ll_set.array_size, 2 * DLT_ENV_LL_SET_INCREASE); + EXPECT_EQ(ll_set.num_elem, 11); + for (size_t i = 0; i < ll_set.num_elem; ++i) + { + EXPECT_EQ(ll_set.item[i].ctxId[3], i % 10 + '0'); + } + + dlt_env_free_ll_set(&ll_set); + + char env2[] = "SINA:SINC:FATAL"; + tmp = &env2[0]; + + ASSERT_EQ(dlt_env_extract_ll_set(&tmp, &ll_set), 0); + EXPECT_EQ(ll_set.array_size, DLT_ENV_LL_SET_INCREASE); + EXPECT_EQ(ll_set.num_elem, 1); + EXPECT_EQ(ll_set.item[0].ll, 1); + + dlt_env_free_ll_set(&ll_set); } - TEST(DltExtensionTests, ids_match) { - ASSERT_EQ(1, dlt_env_ids_match("abcd", "abcd")); - ASSERT_EQ(0, dlt_env_ids_match("abcd", "abce")); - ASSERT_EQ(0, dlt_env_ids_match("abcd", "abee")); - ASSERT_EQ(0, dlt_env_ids_match("abcd", "aeee")); - ASSERT_EQ(0, dlt_env_ids_match("abcd", "eeee")); - - ASSERT_TRUE(dlt_env_ids_match("abcd", "abcd")); - ASSERT_FALSE(dlt_env_ids_match("abcd", "abce")); + ASSERT_EQ(1, dlt_env_ids_match("abcd", "abcd")); + ASSERT_EQ(0, dlt_env_ids_match("abcd", "abce")); + ASSERT_EQ(0, dlt_env_ids_match("abcd", "abee")); + ASSERT_EQ(0, dlt_env_ids_match("abcd", "aeee")); + ASSERT_EQ(0, dlt_env_ids_match("abcd", "eeee")); + + ASSERT_TRUE(dlt_env_ids_match("abcd", "abcd")); + ASSERT_FALSE(dlt_env_ids_match("abcd", "abce")); } - TEST(DltExtensionTests, get_matching_prio) { - char apid[5] = "ABCD"; - char ctid[5] = "1234"; + char apid[5] = "ABCD"; + char ctid[5] = "1234"; - dlt_env_ll_item test0; - dlt_set_id(test0.appId, ""); - dlt_set_id(test0.ctxId, ""); - ASSERT_EQ(1, dlt_env_ll_item_get_matching_prio(&test0, apid, ctid)); + dlt_env_ll_item test0; + dlt_set_id(test0.appId, ""); + dlt_set_id(test0.ctxId, ""); + ASSERT_EQ(1, dlt_env_ll_item_get_matching_prio(&test0, apid, ctid)); - dlt_set_id(test0.appId, ""); - dlt_set_id(test0.ctxId, ctid); - ASSERT_EQ(2, dlt_env_ll_item_get_matching_prio(&test0, apid, ctid)); + dlt_set_id(test0.appId, ""); + dlt_set_id(test0.ctxId, ctid); + ASSERT_EQ(2, dlt_env_ll_item_get_matching_prio(&test0, apid, ctid)); - dlt_set_id(test0.appId, apid); - dlt_set_id(test0.ctxId, ""); - ASSERT_EQ(3, dlt_env_ll_item_get_matching_prio(&test0, apid, ctid)); + dlt_set_id(test0.appId, apid); + dlt_set_id(test0.ctxId, ""); + ASSERT_EQ(3, dlt_env_ll_item_get_matching_prio(&test0, apid, ctid)); - dlt_set_id(test0.appId, apid); - dlt_set_id(test0.ctxId, ctid); - ASSERT_EQ(4, dlt_env_ll_item_get_matching_prio(&test0, apid, ctid)); + dlt_set_id(test0.appId, apid); + dlt_set_id(test0.ctxId, ctid); + ASSERT_EQ(4, dlt_env_ll_item_get_matching_prio(&test0, apid, ctid)); - dlt_set_id(test0.appId, "EFGH"); /* appId should not match */ - dlt_set_id(test0.ctxId, ctid); - ASSERT_EQ(0, dlt_env_ll_item_get_matching_prio(&test0, apid, ctid)); + dlt_set_id(test0.appId, "EFGH"); /* appId should not match */ + dlt_set_id(test0.ctxId, ctid); + ASSERT_EQ(0, dlt_env_ll_item_get_matching_prio(&test0, apid, ctid)); - ASSERT_EQ(-1, dlt_env_ll_item_get_matching_prio(NULL, apid, ctid)); - ASSERT_EQ(-1, dlt_env_ll_item_get_matching_prio(&test0, NULL, ctid)); - ASSERT_EQ(-1, dlt_env_ll_item_get_matching_prio(&test0, apid, NULL)); + ASSERT_EQ(-1, dlt_env_ll_item_get_matching_prio(NULL, apid, ctid)); + ASSERT_EQ(-1, dlt_env_ll_item_get_matching_prio(&test0, NULL, ctid)); + ASSERT_EQ(-1, dlt_env_ll_item_get_matching_prio(&test0, apid, NULL)); } - TEST(DltExtensionTests, adjust_ll_from_env) { - char apid[5] = "ABCD"; - char ctid[5] = "1234"; - int ll = 42; /* unrealistic value to see that the ll was not touched */ - - dlt_env_ll_set ll_set; - dlt_env_init_ll_set(&ll_set); - EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(NULL, apid, ctid, ll)); /* orig value in case of error */ - EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(&ll_set, NULL, ctid, ll)); /* orig value in case of error */ - EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(&ll_set, apid, NULL, ll)); /* orig value in case of error */ - - EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); /* an empty set should not match anything */ - - dlt_set_id(ll_set.item[0].appId, "DEAD"); /* not matching */ - dlt_set_id(ll_set.item[0].ctxId, "BEEF"); - ll_set.item[0].ll = 0; - ll_set.num_elem = 1; - EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); /* not matching anything */ - - dlt_set_id(ll_set.item[1].appId, ""); /* empty rule, weakest */ - dlt_set_id(ll_set.item[1].ctxId, ""); - ll_set.item[1].ll = 1; - ll_set.num_elem = 2; - EXPECT_EQ(1, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); - - dlt_set_id(ll_set.item[2].appId, ""); /* prio 2 */ - dlt_set_id(ll_set.item[2].ctxId, ctid); - ll_set.item[2].ll = 2; - ll_set.num_elem = 3; - EXPECT_EQ(2, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); - - dlt_set_id(ll_set.item[3].appId, apid); /* prio 3 */ - dlt_set_id(ll_set.item[3].ctxId, ""); - ll_set.item[3].ll = 3; - ll_set.num_elem = 4; - EXPECT_EQ(3, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); - - dlt_set_id(ll_set.item[4].appId, apid); /* prio 4 */ - dlt_set_id(ll_set.item[4].ctxId, ctid); - ll_set.item[4].ll = 4; - ll_set.num_elem = 5; - EXPECT_EQ(4, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); - - dlt_set_id(ll_set.item[5].appId, apid); /* does not matter item[4] will always match */ - dlt_set_id(ll_set.item[5].ctxId, ""); - ll_set.item[5].ll = 5; - ll_set.num_elem = 6; - EXPECT_EQ(4, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); /* remember, item[4] matches */ - - dlt_env_free_ll_set(&ll_set); + char apid[5] = "ABCD"; + char ctid[5] = "1234"; + int ll = 42; /* unrealistic value to see that the ll was not touched */ + + dlt_env_ll_set ll_set; + dlt_env_init_ll_set(&ll_set); + EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(NULL, apid, ctid, ll)); /* orig value in case of error */ + EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(&ll_set, NULL, ctid, ll)); /* orig value in case of error */ + EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(&ll_set, apid, NULL, ll)); /* orig value in case of error */ + + EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); /* an empty set should not match anything */ + + dlt_set_id(ll_set.item[0].appId, "DEAD"); /* not matching */ + dlt_set_id(ll_set.item[0].ctxId, "BEEF"); + ll_set.item[0].ll = 0; + ll_set.num_elem = 1; + EXPECT_EQ(ll, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); /* not matching anything */ + + dlt_set_id(ll_set.item[1].appId, ""); /* empty rule, weakest */ + dlt_set_id(ll_set.item[1].ctxId, ""); + ll_set.item[1].ll = 1; + ll_set.num_elem = 2; + EXPECT_EQ(1, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); + + dlt_set_id(ll_set.item[2].appId, ""); /* prio 2 */ + dlt_set_id(ll_set.item[2].ctxId, ctid); + ll_set.item[2].ll = 2; + ll_set.num_elem = 3; + EXPECT_EQ(2, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); + + dlt_set_id(ll_set.item[3].appId, apid); /* prio 3 */ + dlt_set_id(ll_set.item[3].ctxId, ""); + ll_set.item[3].ll = 3; + ll_set.num_elem = 4; + EXPECT_EQ(3, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); + + dlt_set_id(ll_set.item[4].appId, apid); /* prio 4 */ + dlt_set_id(ll_set.item[4].ctxId, ctid); + ll_set.item[4].ll = 4; + ll_set.num_elem = 5; + EXPECT_EQ(4, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); + + dlt_set_id(ll_set.item[5].appId, apid); /* does not matter item[4] will always match */ + dlt_set_id(ll_set.item[5].ctxId, ""); + ll_set.item[5].ll = 5; + ll_set.num_elem = 6; + EXPECT_EQ(4, dlt_env_adjust_ll_from_env(&ll_set, apid, ctid, ll)); /* remember, item[4] matches */ + + dlt_env_free_ll_set(&ll_set); } - // int dlt_env_helper_to_lower(char **env, char *result, int res_len) TEST(DltExtensionTests, dlt_env_helper_to_lower) { - // default behavior - char env0[] = "1238<><<>>>>#$//abcdABCDEDFGHIJKLMNOPQRSTUVWXYZpo;ABcd"; - char res0[] = "1238<><<>>>>#$//abcdabcdedfghijklmnopqrstuvwxyzpo"; - char *tmp0 = &env0[0]; - - char result0[sizeof(res0)]; - ASSERT_EQ(0, dlt_env_helper_to_lower(&tmp0, result0, sizeof(result0))); - ASSERT_EQ(';', *tmp0); // next char is ';' - ASSERT_STREQ(res0, result0); // stops at ';' and is correctly converted - - // default behavior with end of string - char env1[] = "1238<><<>>>>#$//abcdABCDEDFGHIJKLMNOPQRSTUVWXYZpo"; - char res1[] = "1238<><<>>>>#$//abcdabcdedfghijklmnopqrstuvwxyzpo"; - char *tmp1 = &env1[0]; - - char result1[sizeof(res1)]; - ASSERT_EQ(0, dlt_env_helper_to_lower(&tmp1, result1, sizeof(result1))); - ASSERT_EQ(0, *tmp1); // next char is void - ASSERT_STREQ(res1, result1); // stops at end-of-string and is correctly converted - - // result string too short - char env2[] = "2238<><<>>>>#$//abcdABCDEDFGHIJKLMNOPQRSTUVWXYZpo"; - char res2[] = "2238<><<>>>>#$//abcdabcdedfg"; - char *tmp2 = &env2[0]; - - char result2[sizeof(res2)]; - ASSERT_EQ(-1, dlt_env_helper_to_lower(&tmp2, result2, sizeof(result2))); - ASSERT_EQ('H', *tmp2); // next char is void - ASSERT_STREQ(res2, result2); // stops at end-of-string and is partially converted - - // input string shorter than result - char env3[] = "3338<><<>>>>#$//abcdABCDEDFGHIJKLMNOPQRSTUVWXYZpo"; - char res3[] = "3338<><<>>>>#$//abcdabcdedfghijklmnopqrstuvwxyzpo"; - char *tmp3 = &env3[0]; - - char result3[sizeof(res3)+5]; - ASSERT_EQ(0, dlt_env_helper_to_lower(&tmp3, result3, sizeof(result3))); - ASSERT_EQ(0, *tmp3); // next char is void - ASSERT_STREQ(res3, result3); // stops at end-of-string and is correctly converted + // default behavior + char env0[] = "1238<><<>>>>#$//abcdABCDEDFGHIJKLMNOPQRSTUVWXYZpo;ABcd"; + char res0[] = "1238<><<>>>>#$//abcdabcdedfghijklmnopqrstuvwxyzpo"; + char *tmp0 = &env0[0]; + + char result0[sizeof(res0)]; + ASSERT_EQ(0, dlt_env_helper_to_lower(&tmp0, result0, sizeof(result0))); + ASSERT_EQ(';', *tmp0); // next char is ';' + ASSERT_STREQ(res0, result0); // stops at ';' and is correctly converted + + // default behavior with end of string + char env1[] = "1238<><<>>>>#$//abcdABCDEDFGHIJKLMNOPQRSTUVWXYZpo"; + char res1[] = "1238<><<>>>>#$//abcdabcdedfghijklmnopqrstuvwxyzpo"; + char *tmp1 = &env1[0]; + + char result1[sizeof(res1)]; + ASSERT_EQ(0, dlt_env_helper_to_lower(&tmp1, result1, sizeof(result1))); + ASSERT_EQ(0, *tmp1); // next char is void + ASSERT_STREQ(res1, result1); // stops at end-of-string and is correctly converted + + // result string too short + char env2[] = "2238<><<>>>>#$//abcdABCDEDFGHIJKLMNOPQRSTUVWXYZpo"; + char res2[] = "2238<><<>>>>#$//abcdabcdedfg"; + char *tmp2 = &env2[0]; + + char result2[sizeof(res2)]; + ASSERT_EQ(-1, dlt_env_helper_to_lower(&tmp2, result2, sizeof(result2))); + ASSERT_EQ('H', *tmp2); // next char is void + ASSERT_STREQ(res2, result2); // stops at end-of-string and is partially converted + + // input string shorter than result + char env3[] = "3338<><<>>>>#$//abcdABCDEDFGHIJKLMNOPQRSTUVWXYZpo"; + char res3[] = "3338<><<>>>>#$//abcdabcdedfghijklmnopqrstuvwxyzpo"; + char *tmp3 = &env3[0]; + + char result3[sizeof(res3) + 5]; + ASSERT_EQ(0, dlt_env_helper_to_lower(&tmp3, result3, sizeof(result3))); + ASSERT_EQ(0, *tmp3); // next char is void + ASSERT_STREQ(res3, result3); // stops at end-of-string and is correctly converted } - // int dlt_env_extract_symbolic_ll(char **env, int8_t * ll) TEST(DltExtensionTests, dlt_env_extract_symbolic_ll) { - int8_t result; - - // correct behavior - char env0[] = "DEFAULT;off;fatal;error;warning;info;DeBuG;verbose"; - char *tmp0 = &env0[0]; - - ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); - ASSERT_EQ('o', *tmp0); - ASSERT_EQ(-1, result); + int8_t result; - ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); - ASSERT_EQ('f', *tmp0); - ASSERT_EQ(0, result); + // correct behavior + char env0[] = "DEFAULT;off;fatal;error;warning;info;DeBuG;verbose"; + char *tmp0 = &env0[0]; - ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); - ASSERT_EQ('e', *tmp0); - ASSERT_EQ(1, result); + ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); + ASSERT_EQ('o', *tmp0); + ASSERT_EQ(-1, result); - ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); - ASSERT_EQ('w', *tmp0); - ASSERT_EQ(2, result); + ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); + ASSERT_EQ('f', *tmp0); + ASSERT_EQ(0, result); - ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); - ASSERT_EQ('i', *tmp0); - ASSERT_EQ(3, result); + ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); + ASSERT_EQ('e', *tmp0); + ASSERT_EQ(1, result); - ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); - ASSERT_EQ('D', *tmp0); - ASSERT_EQ(4, result); + ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); + ASSERT_EQ('w', *tmp0); + ASSERT_EQ(2, result); - ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); - ASSERT_EQ('v', *tmp0); - ASSERT_EQ(5, result); + ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); + ASSERT_EQ('i', *tmp0); + ASSERT_EQ(3, result); - ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); - ASSERT_EQ(0, *tmp0); - ASSERT_EQ(6, result); + ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); + ASSERT_EQ('D', *tmp0); + ASSERT_EQ(4, result); + ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); + ASSERT_EQ('v', *tmp0); + ASSERT_EQ(5, result); - // incorrect behavior - char env1[] = "DEF"; - char *tmp1 = &env1[0]; + ASSERT_EQ(0, dlt_env_extract_symbolic_ll(&tmp0, &result)); + ASSERT_EQ(0, *tmp0); + ASSERT_EQ(6, result); - result = 18; - ASSERT_EQ(-1, dlt_env_extract_symbolic_ll(&tmp1, &result)); - ASSERT_EQ(NULL, *tmp1); - ASSERT_EQ(18, result); /* 'result' is not touched */ + // incorrect behavior + char env1[] = "DEF"; + char *tmp1 = &env1[0]; + result = 18; + ASSERT_EQ(-1, dlt_env_extract_symbolic_ll(&tmp1, &result)); + ASSERT_EQ(NULL, *tmp1); + ASSERT_EQ(18, result); /* 'result' is not touched */ - // incorrect behavior - char env2[] = "DEFaultingfBa"; - char *tmp2 = &env2[0]; + // incorrect behavior + char env2[] = "DEFaultingfBa"; + char *tmp2 = &env2[0]; - result = 28; - ASSERT_EQ(-1, dlt_env_extract_symbolic_ll(&tmp2, &result)); - ASSERT_EQ('i', *tmp2); - ASSERT_EQ(28, result); /* 'result' is not touched */ + result = 28; + ASSERT_EQ(-1, dlt_env_extract_symbolic_ll(&tmp2, &result)); + ASSERT_EQ('i', *tmp2); + ASSERT_EQ(28, result); /* 'result' is not touched */ } diff --git a/tests/gtest_dlt_common.cpp b/tests/gtest_dlt_common.cpp index 095f444..adf492c 100644 --- a/tests/gtest_dlt_common.cpp +++ b/tests/gtest_dlt_common.cpp @@ -343,7 +343,6 @@ TEST(t_dlt_buffer_push, abnormal) } TEST(t_dlt_buffer_push, nullpointer) { -// DltBuffer buf; char * test; int size = sizeof(test); @@ -587,7 +586,6 @@ TEST(t_dlt_buffer_push3, abnormal) } TEST(t_dlt_buffer_push3, nullpointer) { -// DltBuffer buf; char * test; int size = sizeof(test); |