summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt8
-rw-r--r--cmake/CMakeLists.txt18
-rw-r--r--doc/dlt_extended_network_trace.md8
-rw-r--r--include/dlt/dlt_user.h4
-rw-r--r--src/lib/dlt_user.c47
-rw-r--r--src/tests/dlt-test-user.c48
-rw-r--r--tests/gtest_dlt_daemon_offline_log.cpp1
-rw-r--r--tests/gtest_dlt_user.cpp4
8 files changed, 115 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bfc9058..a9c40cf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -182,6 +182,14 @@ add_definitions(-DCONFIGURATION_FILES_DIR="${CONFIGURATION_FILES_DIR}")
add_subdirectory(cmake)
+# Message queue
+if(HAVE_MQUEUE_H AND HAVE_FUNC_MQOPEN AND HAVE_FUNC_MQCLOSE AND
+ HAVE_FUNC_MQUNLINK AND HAVE_FUNC_MQSEND AND HAVE_FUNC_MQRECEIVE)
+ add_definitions(-DDLT_NETWORK_TRACE_ENABLE)
+else()
+ message(STATUS "Disable network trace interface since message queue is not supported")
+endif()
+
if(WITH_SYSTEMD OR WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD_JOURNAL)
find_package(PkgConfig REQUIRED)
execute_process(COMMAND pkg-config --modversion systemd OUTPUT_VARIABLE SYSTEMD_VERSION)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index d1a9a10..46b67e4 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -52,6 +52,7 @@ CHECK_INCLUDE_FILES( linux/stat.h HAVE_LINUXSTAT_H)
CHECK_INCLUDE_FILES( sys/uio.h HAVE_SYSUIO_H)
CHECK_INCLUDE_FILES( termios.h HAVE_TERMIOS_H)
CHECK_INCLUDE_FILES( unistd.h HAVE_UNISTD_H)
+CHECK_INCLUDE_FILES( mqueue.h HAVE_MQUEUE_H)
INCLUDE(CheckFunctionExists)
@@ -72,6 +73,23 @@ CHECK_FUNCTION_EXISTS( strerror HAVE_FUNC_STRERROR)
CHECK_FUNCTION_EXISTS( strstr HAVE_FUNC_STRSTR)
CHECK_FUNCTION_EXISTS( strtol HAVE_FUNC_STRTOL)
+# Message queue
+find_library(RT_LIBRARY rt)
+if(RT_LIBRARY)
+ include(CheckLibraryExists)
+ CHECK_LIBRARY_EXISTS( ${RT_LIBRARY} mq_open mqueue.h HAVE_FUNC_MQOPEN)
+ CHECK_LIBRARY_EXISTS( ${RT_LIBRARY} mq_close mqueue.h HAVE_FUNC_MQCLOSE)
+ CHECK_LIBRARY_EXISTS( ${RT_LIBRARY} mq_unlink mqueue.h HAVE_FUNC_MQUNLINK)
+ CHECK_LIBRARY_EXISTS( ${RT_LIBRARY} mq_send mqueue.h HAVE_FUNC_MQSEND)
+ CHECK_LIBRARY_EXISTS( ${RT_LIBRARY} mq_receive mqueue.h HAVE_FUNC_MQRECEIVE)
+else()
+ CHECK_FUNCTION_EXISTS( mq_open HAVE_FUNC_MQOPEN)
+ CHECK_FUNCTION_EXISTS( mq_close HAVE_FUNC_MQCLOSE)
+ CHECK_FUNCTION_EXISTS( mq_unlink HAVE_FUNC_MQUNLINK)
+ CHECK_FUNCTION_EXISTS( mq_send HAVE_FUNC_MQSEND)
+ CHECK_FUNCTION_EXISTS( mq_receive HAVE_FUNC_MQRECEIVE)
+endif()
+
if(WITH_CHECK_CONFIG_FILE)
configure_file(${PROJECT_SOURCE_DIR}/cmake/config.h.cmake ${PROJECT_BINARY_DIR}/include/dlt/config.h)
endif(WITH_CHECK_CONFIG_FILE)
diff --git a/doc/dlt_extended_network_trace.md b/doc/dlt_extended_network_trace.md
index bb2f09b..f46ce7d 100644
--- a/doc/dlt_extended_network_trace.md
+++ b/doc/dlt_extended_network_trace.md
@@ -5,7 +5,13 @@ Back to [README.md](../README.md)
## Introduction
The extended network trace allows the user to send or truncate network trace
-messages that are larger than the normal maximum size of a DLT message.
+messages that are larger than the normal maximum size of a DLT message. This
+interface will be enabled if following calls are supported on the target:
+- mq\_open
+- mq\_close
+- mq\_unlink
+- mq\_send
+- mq\_receive
## Protocol
diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h
index 97aa911..41484b6 100644
--- a/include/dlt/dlt_user.h
+++ b/include/dlt/dlt_user.h
@@ -74,7 +74,7 @@
\{
*/
-#ifndef __ANDROID_API__
+#ifdef DLT_NETWORK_TRACE_ENABLE
# include <mqueue.h>
#endif
@@ -197,7 +197,7 @@ typedef struct
char appID[DLT_ID_SIZE]; /**< Application ID */
int dlt_log_handle; /**< Handle to fifo of dlt daemon */
int dlt_user_handle; /**< Handle to own fifo */
-#ifndef __ANDROID_API__
+#ifdef DLT_NETWORK_TRACE_ENABLE
mqd_t dlt_segmented_queue_read_handle; /**< Handle message queue */
mqd_t dlt_segmented_queue_write_handle; /**< Handle message queue */
pthread_t dlt_segmented_nwt_handle; /**< thread handle of segmented sending */
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index 7188c05..901dc21 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -104,16 +104,21 @@ enum StringType
UTF8_STRING = 1
};
+#define DLT_UNUSED(x) (void)(x)
+
+/* Network trace */
+#ifdef DLT_NETWORK_TRACE_ENABLE
+#define DLT_USER_SEGMENTED_THREAD (1<<2)
+
/* Segmented Network Trace */
#define DLT_MAX_TRACE_SEGMENT_SIZE 1024
#define DLT_MESSAGE_QUEUE_NAME "/dlt_message_queue"
#define DLT_DELAYED_RESEND_INDICATOR_PATTERN 0xFFFF
-#define DLT_UNUSED(x) (void)(x)
-
/* Mutex to wait on while message queue is not initialized */
pthread_mutex_t mq_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t mq_init_condition;
+#endif /* DLT_NETWORK_TRACE_ENABLE */
void dlt_lock_mutex(pthread_mutex_t *mutex)
{
@@ -160,10 +165,6 @@ static DltReturnValue dlt_user_print_msg(DltMessage *msg, DltContextData *log);
static DltReturnValue dlt_user_log_check_user_message(void);
static void dlt_user_log_reattach_to_daemon(void);
static DltReturnValue dlt_user_log_send_overflow(void);
-#ifndef __ANDROID_API__
-static void dlt_user_trace_network_segmented_thread(void *unused);
-static void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data);
-#endif
static DltReturnValue dlt_user_log_out_error_handling(void *ptr1,
size_t len1,
void *ptr2,
@@ -174,6 +175,10 @@ static void dlt_user_cleanup_handler(void *arg);
static int dlt_start_threads();
static void dlt_stop_threads();
static void dlt_fork_child_fork_handler();
+#ifdef DLT_NETWORK_TRACE_ENABLE
+static void dlt_user_trace_network_segmented_thread(void *unused);
+static void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data);
+#endif
static DltReturnValue dlt_user_log_write_string_utils(DltContextData *log, const char *text,
const enum StringType type);
@@ -402,7 +407,7 @@ DltReturnValue dlt_init(void)
#endif
-#ifndef __ANDROID_API__
+#ifdef DLT_NETWORK_TRACE_ENABLE
/* These will be lazy initialized only when needed */
dlt_user.dlt_segmented_queue_read_handle = -1;
dlt_user.dlt_segmented_queue_write_handle = -1;
@@ -459,7 +464,7 @@ DltReturnValue dlt_init_file(const char *name)
return DLT_RETURN_OK;
}
-#ifndef __ANDROID_API__
+#ifdef DLT_NETWORK_TRACE_ENABLE
DltReturnValue dlt_init_message_queue(void)
{
dlt_lock_mutex(&mq_mutex);
@@ -524,7 +529,7 @@ DltReturnValue dlt_init_message_queue(void)
dlt_unlock_mutex(&mq_mutex);
return DLT_RETURN_OK;
}
-#endif /*__ANDROID_API__*/
+#endif /* DLT_NETWORK_TRACE_ENABLE */
DltReturnValue dlt_init_common(void)
{
@@ -940,7 +945,7 @@ DltReturnValue dlt_free(void)
dlt_env_free_ll_set(&dlt_user.initial_ll_set);
DLT_SEM_FREE();
-#ifndef __ANDROID_API__
+#ifdef DLT_NETWORK_TRACE_ENABLE
char queue_name[NAME_MAX];
snprintf(queue_name, NAME_MAX, "%s.%d", DLT_MESSAGE_QUEUE_NAME, getpid());
@@ -962,7 +967,7 @@ DltReturnValue dlt_free(void)
dlt_user.dlt_segmented_queue_read_handle = DLT_FD_INIT;
pthread_cond_destroy(&mq_init_condition);
-#endif /* ifndef __ANDROID_API__ */
+#endif /* DLT_NETWORK_TRACE_ENABLE */
sem_destroy(&dlt_mutex);
/* allow the user app to do dlt_init() again. */
@@ -2652,7 +2657,7 @@ DltReturnValue dlt_register_log_level_changed_callback(DltContext *handle,
* NW Trace related
*/
-
+#ifdef DLT_NETWORK_TRACE_ENABLE
int check_buffer(void)
{
int total_size, used_size;
@@ -2901,7 +2906,6 @@ DltReturnValue dlt_user_trace_network_segmented_end(uint32_t id, DltContext *han
return DLT_RETURN_OK;
}
-#ifndef __ANDROID_API__
void dlt_user_trace_network_segmented_thread(void *unused)
{
/* Unused on purpose. */
@@ -3201,7 +3205,7 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle,
return DLT_RETURN_OK;
}
-#endif /*__ANDROID_API__*/
+#endif /* DLT_NETWORK_TRACE_ENABLE */
DltReturnValue dlt_log_string(DltContext *handle, DltLogLevelType loglevel, const char *text)
{
@@ -3466,8 +3470,12 @@ DltReturnValue dlt_disable_local_print(void)
static void dlt_user_cleanup_handler(void *arg)
{
DLT_UNUSED(arg); /* Satisfy compiler */
+
+#ifdef DLT_NETWORK_TRACE_ENABLE
/* unlock the message queue */
dlt_unlock_mutex(&mq_mutex);
+#endif
+
/* unlock DLT (dlt_mutex) */
DLT_SEM_FREE();
}
@@ -4645,7 +4653,10 @@ void dlt_stop_threads()
#ifndef __ANDROID_API__
dlt_housekeeperthread_result = pthread_cancel(dlt_housekeeperthread_handle);
#else
+
+#ifdef DLT_NETWORK_TRACE_ENABLE
dlt_lock_mutex(&mq_mutex);
+#endif /* DLT_NETWORK_TRACE_ENABLE */
dlt_housekeeperthread_result = pthread_kill(dlt_housekeeperthread_handle, SIGKILL);
dlt_user_cleanup_handler(NULL);
#endif
@@ -4662,7 +4673,7 @@ void dlt_stop_threads()
strerror(dlt_housekeeperthread_result));
}
-#ifndef __ANDROID_API__
+#ifdef DLT_NETWORK_TRACE_ENABLE
int dlt_segmented_nwt_result = 0;
if (dlt_user.dlt_segmented_nwt_handle) {
@@ -4677,7 +4688,7 @@ void dlt_stop_threads()
"ERROR pthread_cancel(dlt_user.dlt_segmented_nwt_handle): %s\n",
strerror(dlt_segmented_nwt_result));
}
-#endif /* ifndef __ANDROID_API__ */
+#endif /* DLT_NETWORK_TRACE_ENABLE */
/* make sure that the threads really finished working */
if ((dlt_housekeeperthread_result == 0) && dlt_housekeeperthread_handle) {
joined = pthread_join(dlt_housekeeperthread_handle, NULL);
@@ -4690,7 +4701,7 @@ void dlt_stop_threads()
dlt_housekeeperthread_handle = 0; /* set to invalid */
}
-#ifndef __ANDROID_API__
+#ifdef DLT_NETWORK_TRACE_ENABLE
if ((dlt_segmented_nwt_result == 0) && dlt_user.dlt_segmented_nwt_handle) {
joined = pthread_join(dlt_user.dlt_segmented_nwt_handle, NULL);
@@ -4701,7 +4712,7 @@ void dlt_stop_threads()
dlt_user.dlt_segmented_nwt_handle = 0; /* set to invalid */
}
-#endif /* ifndef __ANDROID_API__ */
+#endif /* DLT_NETWORK_TRACE_ENABLE */
}
static void dlt_fork_child_fork_handler()
diff --git a/src/tests/dlt-test-user.c b/src/tests/dlt-test-user.c
index cd6224f..bde6f0f 100644
--- a/src/tests/dlt-test-user.c
+++ b/src/tests/dlt-test-user.c
@@ -560,6 +560,7 @@ int test6m(void)
int test7m(void)
{
+#ifdef DLT_NETWORK_TRACE_ENABLE
char buffer[32];
int num;
@@ -585,12 +586,18 @@ int test7m(void)
DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
sleep(2);
+#else
+ /* Test 7: (Macro IF) Test network trace */
+ printf("Test7m: (Macro IF) Test network trace: Network trace interface is not supported, skipping\n");
+ DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test 7: (Macro IF) Test network trace: Network trace interface is not supported, skipping");
+#endif
return 0;
}
int test8m(void)
{
+#ifdef DLT_NETWORK_TRACE_ENABLE
char buffer[1024 * 5];
int num;
@@ -616,12 +623,18 @@ int test8m(void)
DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
sleep(2);
+#else
+ /* Test 8: (Macro IF) Test truncated network trace*/
+ printf("Test8m: (Macro IF) Test truncated network trace: Network trace interface is not supported, skipping\n");
+ DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test 8: (Macro IF) Test truncated network trace: Network trace interface is not supported, skipping");
+#endif
return 0;
}
int test9m(void)
{
+#ifdef DLT_NETWORK_TRACE_ENABLE
char buffer[1024 * 5];
int num;
@@ -647,6 +660,11 @@ int test9m(void)
DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
sleep(2);
+#else
+ /* Test 9: (Macro IF) Test segmented network trace*/
+ printf("Test9m: (Macro IF) Test segmented network trace: Network trace interface is not supported, skipping\n");
+ DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test 9: (Macro IF) Test segmented network trace: Network trace interface is not supported, skipping");
+#endif
return 0;
}
@@ -1100,6 +1118,7 @@ int test6f(void)
int test7f(void)
{
+#ifdef DLT_NETWORK_TRACE_ENABLE
char buffer[32];
int num;
@@ -1133,12 +1152,22 @@ int test7f(void)
dlt_set_application_ll_ts_limit(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
sleep(2);
+#else
+ /* Test 7: (Function IF) Test network trace */
+ printf("Test7f: (Function IF) Test network trace: Network trace interface is not supported, skipping\n");
+
+ if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) {
+ dlt_user_log_write_string(&context_data, "Test 7: (Function IF) Test network trace: Network trace interface is not supported, skipping");
+ dlt_user_log_write_finish(&context_data);
+ }
+#endif
return 0;
}
int test8f(void)
{
+#ifdef DLT_NETWORK_TRACE_ENABLE
char buffer[1024 * 5];
int num;
@@ -1173,12 +1202,22 @@ int test8f(void)
dlt_set_application_ll_ts_limit(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
sleep(2);
+#else
+ /* Test 8: (Function IF) Test truncated network trace */
+ printf("Test8f: (Function IF) Test truncated network trace: Network trace interface is not supported, skipping\n");
+
+ if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) {
+ dlt_user_log_write_string(&context_data, "Test 8: (Function IF) Test truncated network trace: Network trace interface is not supported, skipping");
+ dlt_user_log_write_finish(&context_data);
+ }
+#endif
return 0;
}
int test9f(void)
{
+#ifdef DLT_NETWORK_TRACE_ENABLE
char buffer[1024 * 5];
int num;
@@ -1212,6 +1251,15 @@ int test9f(void)
dlt_set_application_ll_ts_limit(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
sleep(2);
+#else
+ /* Test 9: (Function IF) Test segmented network trace */
+ printf("Test9f: (Function IF) Test segmented network trace: Network trace interface is not supported, skipping\n");
+
+ if (dlt_user_log_write_start(&context_info, &context_data, DLT_LOG_INFO) > 0) {
+ dlt_user_log_write_string(&context_data, "Test 9: (Function IF) Test segmented network trace: Network trace interface is not supported, skipping");
+ dlt_user_log_write_finish(&context_data);
+ }
+#endif
return 0;
}
diff --git a/tests/gtest_dlt_daemon_offline_log.cpp b/tests/gtest_dlt_daemon_offline_log.cpp
index dd97c5a..aec3e96 100644
--- a/tests/gtest_dlt_daemon_offline_log.cpp
+++ b/tests/gtest_dlt_daemon_offline_log.cpp
@@ -26,6 +26,7 @@ extern "C"
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <fcntl.h>
}
#ifndef DLT_DAEMON_BLOCKING_TEST
diff --git a/tests/gtest_dlt_user.cpp b/tests/gtest_dlt_user.cpp
index 0728242..0f28b71 100644
--- a/tests/gtest_dlt_user.cpp
+++ b/tests/gtest_dlt_user.cpp
@@ -4170,7 +4170,7 @@ TEST(t_dlt_register_log_level_changed_callback, normal)
}
-
+#ifdef DLT_NETWORK_TRACE_ENABLE
/*/////////////////////////////////////// */
/* t_dlt_user_trace_network */
TEST(t_dlt_user_trace_network, normal)
@@ -4463,7 +4463,7 @@ TEST(t_dlt_user_trace_network_segmented, nullpointer)
EXPECT_LE(DLT_RETURN_OK, dlt_unregister_context(&context));
EXPECT_LE(DLT_RETURN_OK, dlt_unregister_app());
}
-
+#endif /* DLT_NETWORK_TRACE_ENABLE */
/*/////////////////////////////////////// */
/* t_dlt_set_log_mode */