diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/dlt_user.c | 47 | ||||
-rw-r--r-- | src/tests/dlt-test-user.c | 48 |
2 files changed, 77 insertions, 18 deletions
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; } |