3 * Copyright (C) 2012 BMW AG
5 * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
7 * Contributions are licensed to the GENIVI Alliance under one or more
8 * Contribution License Agreements.
11 * This Source Code Form is subject to the terms of the
12 * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
13 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
16 * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011-2012
18 * \file dlt-test-user.c
19 * For further information see http://www.genivi.org/.
24 /*******************************************************************************
26 ** SRC-MODULE: dlt-test-user.c **
32 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
39 ** PLATFORM DEPENDANT [yes/no]: yes **
41 ** TO BE CHANGED BY USER [yes/no]: no **
43 *******************************************************************************/
45 /*******************************************************************************
47 ********************************************************************************
49 ** Initials Name Company **
50 ** -------- ------------------------- ---------------------------------- **
51 ** aw Alexander Wenzel BMW **
52 ** mk Markus Klein Fraunhofer ESK **
53 *******************************************************************************/
55 /*******************************************************************************
56 ** Revision Control History **
57 *******************************************************************************/
60 * $LastChangedRevision: 1670 $
61 * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
67 #include <stdio.h> /* for printf() and fprintf() */
69 #include <stdlib.h> /* for atoi(), abort() */
70 #include <string.h> /* for memset() */
71 #include <ctype.h> /* for isprint() */
75 #define DLT_TEST_NUM_CONTEXT 9
77 /* Test functions... */
79 /* for macro interface */
90 /* for function interface */
101 /* Declaration of callback functions */
102 int test_injection_macro_callback(uint32_t service_id, void *data, uint32_t length);
103 int test_injection_function_callback(uint32_t service_id, void *data, uint32_t length);
105 /* Context declaration.. */
106 DLT_DECLARE_CONTEXT(context_info);
108 /* for macro interface */
109 DLT_DECLARE_CONTEXT(context_macro_callback);
110 DLT_DECLARE_CONTEXT(context_macro_test[DLT_TEST_NUM_CONTEXT]);
112 /* for function interface */
113 DltContext context_function_callback;
114 DltContext context_function_test[DLT_TEST_NUM_CONTEXT];
116 DltContextData context_data;
119 * Print usage information of tool.
125 dlt_get_version(version);
127 printf("Usage: dlt-test-user [options]\n");
128 printf("Test user application providing several Tests.\n");
129 printf("%s \n", version);
130 printf("Options:\n");
131 printf(" -v Verbose mode\n");
132 printf(" -f filename Use local log file instead of sending to daemon\n");
133 printf(" -n count Repeats of tests (Default: 1)\n");
135 printf(" 1m: (Macro IF) Test all log levels\n");
136 printf(" 2m: (Macro IF) Test all variable types (verbose) \n");
137 printf(" 3m: (Macro IF) Test all variable types (non-verbose) \n");
138 printf(" 4m: (Macro IF) Test different message sizes\n");
139 printf(" 5m: (Macro IF) Test high-level API\n");
140 printf(" 6m: (Macro IF) Test local printing\n");
141 printf(" 7m: (Macro IF) Test network trace\n");
142 printf(" 8m: (Macro IF) Test truncated network trace\n");
143 printf(" 9m: (Macro IF) Test segmented network trace\n");
144 printf(" 1f: (Function IF) Test all log levels\n");
145 printf(" 2f: (Function IF) Test all variable types (verbose) \n");
146 printf(" 3f: (Function IF) Test all variable types (non-verbose) \n");
147 printf(" 4f: (Function IF) Test different message sizes\n");
148 printf(" 5f: (Function IF) Test high-level API\n");
149 printf(" 6f: (Function IF) Test local printing\n");
150 printf(" 7f: (Function IF) Test network trace\n");
151 printf(" 8f: (Function IF) Test truncated network trace\n");
152 printf(" 9f: (Function IF) Test segmented network trace\n");
156 * Main function of tool.
158 int main(int argc, char* argv[])
167 char ctid[4], ctdesc[255];
173 while ((c = getopt (argc, argv, "vf:n:")) != -1)
194 if (optopt == 'd' || optopt == 'f' || optopt == 'n')
196 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
198 else if (isprint (optopt))
200 fprintf (stderr, "Unknown option `-%c'.\n", optopt);
204 fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt);
206 /* unknown or wrong option used, show usage information and terminate */
213 return -1;//for parasoft
220 /* DLT is intialised automatically, except another output target will be used */
221 if (dlt_init_file(fvalue)<0) /* log to file */
229 maxnum = atoi(nvalue);
237 DLT_REGISTER_APP("DIFT","DLT Interface Test");
239 /* Register CONTEXTS... */
240 DLT_REGISTER_CONTEXT(context_info,"INFO","Information context");
242 /* used for macro interface tests */
243 DLT_REGISTER_CONTEXT(context_macro_callback,"CBM","Callback Test context for macro interface");
244 for (i=0;i<DLT_TEST_NUM_CONTEXT;i++)
246 snprintf(ctid,4,"TM%d",i+1);
247 snprintf(ctdesc,255,"Test %d context for macro interface",i+1);
248 DLT_REGISTER_CONTEXT(context_macro_test[i],ctid,ctdesc);
251 /* used for function interface tests */
252 dlt_register_context(&context_function_callback,"CBF","Callback Test context for function interface");
253 for (i=0;i<DLT_TEST_NUM_CONTEXT;i++)
255 snprintf(ctid,4,"TF%d",i+1);
256 snprintf(ctdesc,255,"Test %d context for function interface",i+1);
257 dlt_register_context(&(context_function_test[i]),ctid,ctdesc);
260 /* Register callbacks... */
262 /* with macro interface */
263 DLT_LOG(context_macro_callback,DLT_LOG_INFO,DLT_STRING("Register callback (Macro Interface) for Injection ID: 0xFFF"));
264 DLT_REGISTER_INJECTION_CALLBACK(context_macro_callback, 0xFFF, test_injection_macro_callback);
266 /* with function interface */
267 if (dlt_user_log_write_start(&context_function_callback,&context_data,DLT_LOG_INFO)>0)
269 dlt_user_log_write_string(&context_data,"Register callback (Function Interface) for Injection ID: 0xFFF");
270 dlt_user_log_write_finish(&context_data);
272 dlt_register_injection_callback(&context_function_callback, 0xFFF, test_injection_function_callback);
275 printf("Tests starting\n");
276 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Tests starting"));
278 /* wait 3 seconds before starting */
281 for (num=0;num<maxnum;num++)
283 /* Execute tests... */
285 /* with macro interface */
296 /* with function interface */
307 /* wait 1 second before next repeat of tests */
312 printf("Tests finished\n");
313 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Tests finished"));
315 /* wait 3 seconds before terminating application */
318 /* Unregister CONTEXTS... */
319 DLT_UNREGISTER_CONTEXT(context_info);
321 /* used for macro interface tests */
322 for (i=0;i<DLT_TEST_NUM_CONTEXT;i++)
324 DLT_UNREGISTER_CONTEXT(context_macro_test[i]);
326 DLT_UNREGISTER_CONTEXT(context_macro_callback);
328 /* used for function interface tests */
329 for (i=0;i<DLT_TEST_NUM_CONTEXT;i++)
331 dlt_unregister_context(&(context_function_test[i]));
333 dlt_unregister_context(&context_function_callback);
336 DLT_UNREGISTER_APP();
349 /* Test 1: (Macro IF) Test all log levels */
350 printf("Test1m: (Macro IF) Test all log levels\n");
351 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test1: (Macro IF) Test all log levels"));
353 DLT_LOG(context_macro_test[0],DLT_LOG_FATAL,DLT_STRING("fatal"));
354 DLT_LOG(context_macro_test[0],DLT_LOG_ERROR,DLT_STRING("error"));
355 DLT_LOG(context_macro_test[0],DLT_LOG_WARN,DLT_STRING("warn"));
356 DLT_LOG(context_macro_test[0],DLT_LOG_INFO,DLT_STRING("info"));
357 DLT_LOG(context_macro_test[0],DLT_LOG_DEBUG,DLT_STRING("debug"));
358 DLT_LOG(context_macro_test[0],DLT_LOG_VERBOSE,DLT_STRING("verbose"));
360 /* wait 2 second before next test */
362 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test1: (Macro IF) finished"));
372 /* Test 2: (Macro IF) Test all variable types (verbose) */
373 printf("Test2m: (Macro IF) Test all variable types (verbose)\n");
374 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test2: (Macro IF) Test all variable types (verbose)"));
376 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("string"),DLT_STRING("Hello world"));
377 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("utf8"),DLT_UTF8("Hello world"));
378 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("bool"),DLT_BOOL(1));
379 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("int"),DLT_INT(INT32_MIN)); /* (-2147483647-1) */
380 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("int8"),DLT_INT8(INT8_MIN)); /* (-128) */
381 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("int16"),DLT_INT16(INT16_MIN)); /* (-32767-1) */
382 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("int32"),DLT_INT32(INT32_MIN)); /* (-2147483647-1) */
383 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("int64"),DLT_INT64(INT64_MIN)); /* (-__INT64_C(9223372036854775807)-1) */
384 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("uint"),DLT_UINT(UINT32_MAX)); /* (4294967295U) */
385 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("uint8"),DLT_UINT8(UINT8_MAX)); /* (255) */
386 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("uint16"),DLT_UINT16(UINT16_MAX)); /* (65535) */
387 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("uint32"),DLT_UINT32(UINT32_MAX)); /* (4294967295U) */
388 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("uint64"),DLT_UINT64(UINT64_MAX)); /* (__UINT64_C(18446744073709551615)) */
389 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("float32"),DLT_FLOAT32(FLT_MIN),DLT_FLOAT32(FLT_MAX));
390 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("float64"),DLT_FLOAT64(DBL_MIN),DLT_FLOAT64(DBL_MAX));
392 for(num2=0;num2<10;num2++)
397 DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("raw"),DLT_RAW(buffer,10));
399 /* wait 2 second before next test */
401 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test2: (Macro IF) finished"));
411 /* Test 3: (Macro IF) Test all variable types (non-verbose) */
412 printf("Test3m: (Macro IF) Test all variable types (non-verbose)\n");
413 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test3: (Macro IF) Test all variable types (non-verbose)"));
415 DLT_NONVERBOSE_MODE();
417 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,1,DLT_STRING("string"),DLT_STRING("Hello world"));
418 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,2,DLT_STRING("utf8"),DLT_UTF8("Hello world"));
419 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,3,DLT_STRING("bool"),DLT_BOOL(1));
420 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,4,DLT_STRING("int"),DLT_INT(INT32_MIN)); /* (-2147483647-1) */
421 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,5,DLT_STRING("int8"),DLT_INT8(INT8_MIN)); /* (-128) */
422 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,6,DLT_STRING("int16"),DLT_INT16(INT16_MIN)); /* (-32767-1) */
423 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,7,DLT_STRING("int32"),DLT_INT32(INT32_MIN)); /* (-2147483647-1) */
424 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,8,DLT_STRING("int64"),DLT_INT64(INT64_MIN)); /* (-__INT64_C(9223372036854775807)-1) */
425 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,9,DLT_STRING("uint"),DLT_UINT(UINT32_MAX)); /* (4294967295U) */
426 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,10,DLT_STRING("uint8"),DLT_UINT8(UINT8_MAX)); /* (255) */
427 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,11,DLT_STRING("uint16"),DLT_UINT16(UINT16_MAX)); /* (65535) */
428 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,12,DLT_STRING("uint32"),DLT_UINT32(UINT32_MAX)); /* (4294967295U) */
429 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,13,DLT_STRING("uint64"),DLT_UINT64(UINT64_MAX)); /* (__UINT64_C(18446744073709551615)) */
430 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,14,DLT_STRING("float32"),DLT_FLOAT32(FLT_MIN),DLT_FLOAT32(FLT_MAX));
431 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,15,DLT_STRING("float64"),DLT_FLOAT64(DBL_MIN),DLT_FLOAT64(DBL_MAX));
434 for(num2=0;num2<10;num2++)
438 DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,14,DLT_STRING("raw"),DLT_RAW(buffer,10));
442 /* wait 2 second before next test */
444 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test3: (Macro IF) finished"));
454 for(num=0;num<1024;num++)
459 /* Test 4: (Macro IF) Message size test */
460 printf("Test4m: (Macro IF) Test different message sizes\n");
461 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test4: (Macro IF) Test different message sizes"));
463 DLT_LOG(context_macro_test[3],DLT_LOG_INFO,DLT_STRING("1"),DLT_RAW(buffer,1));
464 DLT_LOG(context_macro_test[3],DLT_LOG_INFO,DLT_STRING("16"),DLT_RAW(buffer,16));
465 DLT_LOG(context_macro_test[3],DLT_LOG_INFO,DLT_STRING("256"),DLT_RAW(buffer,256));
466 DLT_LOG(context_macro_test[3],DLT_LOG_INFO,DLT_STRING("1024"),DLT_RAW(buffer,1024));
468 /* wait 2 second before next test */
470 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test4: (Macro IF) finished"));
480 for(num=0;num<32;num++)
485 /* Test 5: (Macro IF) Test high-level API */
486 printf("Test5m: (Macro IF) Test high-level API\n");
487 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test5: (Macro IF) Test high-level API"));
489 DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_INT"));
490 DLT_LOG_INT(context_macro_test[4], DLT_LOG_INFO, -42);
492 DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_UINT"));
493 DLT_LOG_UINT(context_macro_test[4], DLT_LOG_INFO, 42);
495 DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_STRING"));
496 DLT_LOG_STRING(context_macro_test[4], DLT_LOG_INFO, "String output");
498 DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_RAW"));
499 DLT_LOG_RAW(context_macro_test[4],DLT_LOG_INFO, buffer,16);
501 DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_STRING_INT"));
502 DLT_LOG_STRING_INT(context_macro_test[4], DLT_LOG_INFO, "String output: ", -42);
504 DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_STRING_UINT"));
505 DLT_LOG_STRING_UINT(context_macro_test[4], DLT_LOG_INFO,"String output: ", 42);
507 /* wait 2 second before next test */
509 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test5: (Macro IF) finished"));
516 /* Test 6: (Macro IF) Test local printing */
517 printf("Test6m: (Macro IF) Test local printing\n");
518 DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test 6: (Macro IF) Test local printing");
520 DLT_ENABLE_LOCAL_PRINT();
521 DLT_LOG_STRING(context_macro_test[5], DLT_LOG_INFO, "Message (visible: locally printed)");
523 DLT_DISABLE_LOCAL_PRINT();
524 DLT_LOG_STRING(context_macro_test[5], DLT_LOG_INFO, "Message (invisible: not locally printed)");
526 /* wait 2 second before next test */
528 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test6: (Macro IF) finished"));
538 for(num=0;num<32;num++)
543 /* Show all log messages and traces */
544 DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON);
546 /* Test 7: (Macro IF) Test network trace */
547 printf("Test7m: (Macro IF) Test network trace\n");
548 DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test 7: (Macro IF) Test network trace");
550 /* Dummy messages: 16 byte header, 32 byte payload */
551 DLT_TRACE_NETWORK(context_macro_test[6], DLT_NW_TRACE_IPC, 16, buffer, 32, buffer);
552 DLT_TRACE_NETWORK(context_macro_test[6], DLT_NW_TRACE_CAN, 16, buffer, 32, buffer);
553 DLT_TRACE_NETWORK(context_macro_test[6], DLT_NW_TRACE_FLEXRAY, 16, buffer, 32, buffer);
554 DLT_TRACE_NETWORK(context_macro_test[6], DLT_NW_TRACE_MOST, 16, buffer, 32, buffer);
556 /* wait 2 second before next test */
558 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test7: (Macro IF) finished"));
560 DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
571 for(num=0;num<1024*5;num++)
576 /* Show all log messages and traces */
577 DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON);
579 /* Test 8: (Macro IF) Test truncated network trace*/
580 printf("Test8m: (Macro IF) Test truncated network trace\n");
581 DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test 8: (Macro IF) Test truncated network trace");
583 /* Dummy messages: 16 byte header, 5k payload */
584 DLT_TRACE_NETWORK_TRUNCATED(context_macro_test[7], DLT_NW_TRACE_IPC, 16, buffer, 1024*5, buffer);
585 DLT_TRACE_NETWORK_TRUNCATED(context_macro_test[7], DLT_NW_TRACE_CAN, 16, buffer, 1024*5, buffer);
586 DLT_TRACE_NETWORK_TRUNCATED(context_macro_test[7], DLT_NW_TRACE_FLEXRAY, 16, buffer, 1024*5, buffer);
587 DLT_TRACE_NETWORK_TRUNCATED(context_macro_test[7], DLT_NW_TRACE_MOST, 16, buffer, 1024*5, buffer);
589 /* wait 2 second before next test */
591 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test8: (Macro IF) finished"));
593 DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
604 for(num=0;num<1024*5;num++)
609 /* Show all log messages and traces */
610 DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON);
612 /* Test 9: (Macro IF) Test segmented network trace*/
613 printf("Test9m: (Macro IF) Test segmented network trace\n");
614 DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test 9: (Macro IF) Test segmented network trace");
616 /* Dummy messages: 16 byte header, 5k payload */
617 DLT_TRACE_NETWORK_SEGMENTED(context_macro_test[8], DLT_NW_TRACE_IPC, 16, buffer, 1024*5, buffer);
618 DLT_TRACE_NETWORK_SEGMENTED(context_macro_test[8], DLT_NW_TRACE_CAN, 16, buffer, 1024*5, buffer);
619 DLT_TRACE_NETWORK_SEGMENTED(context_macro_test[8], DLT_NW_TRACE_FLEXRAY, 16, buffer, 1024*5, buffer);
620 DLT_TRACE_NETWORK_SEGMENTED(context_macro_test[8], DLT_NW_TRACE_MOST, 16, buffer, 1024*5, buffer);
622 /* wait 2 second before next test */
624 DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test9: (Macro IF) finished"));
626 DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
634 /* Test 1: (Function IF) Test all log levels */
635 printf("Test1f: (Function IF) Test all log levels\n");
636 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
638 dlt_user_log_write_string(&context_data,"Test1: (Function IF) Test all log levels");
639 dlt_user_log_write_finish(&context_data);
642 if (dlt_user_log_write_start(&(context_function_test[0]),&context_data,DLT_LOG_FATAL)>0)
644 dlt_user_log_write_string(&context_data,"fatal");
645 dlt_user_log_write_finish(&context_data);
647 if (dlt_user_log_write_start(&(context_function_test[0]),&context_data,DLT_LOG_ERROR)>0)
649 dlt_user_log_write_string(&context_data,"error");
650 dlt_user_log_write_finish(&context_data);
652 if (dlt_user_log_write_start(&(context_function_test[0]),&context_data,DLT_LOG_WARN)>0)
654 dlt_user_log_write_string(&context_data,"warn");
655 dlt_user_log_write_finish(&context_data);
657 if (dlt_user_log_write_start(&(context_function_test[0]),&context_data,DLT_LOG_INFO)>0)
659 dlt_user_log_write_string(&context_data,"info");
660 dlt_user_log_write_finish(&context_data);
662 if (dlt_user_log_write_start(&(context_function_test[0]),&context_data,DLT_LOG_DEBUG)>0)
664 dlt_user_log_write_string(&context_data,"debug");
665 dlt_user_log_write_finish(&context_data);
667 if (dlt_user_log_write_start(&(context_function_test[0]),&context_data,DLT_LOG_VERBOSE)>0)
669 dlt_user_log_write_string(&context_data,"verbose");
670 dlt_user_log_write_finish(&context_data);
673 /* wait 2 second before next test */
675 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
677 dlt_user_log_write_string(&context_data,"Test1: (Function IF) finished");
678 dlt_user_log_write_finish(&context_data);
689 /* Test 2: (Function IF) Test all variable types (verbose) */
690 printf("Test2f: (Function IF) Test all variable types (verbose)\n");
691 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
693 dlt_user_log_write_string(&context_data,"Test2: (Function IF) Test all variable types (verbose)");
694 dlt_user_log_write_finish(&context_data);
697 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
699 dlt_user_log_write_string(&context_data,"bool");
700 dlt_user_log_write_bool(&context_data,1);
701 dlt_user_log_write_finish(&context_data);
704 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
706 dlt_user_log_write_string(&context_data,"int");
707 dlt_user_log_write_int(&context_data,INT32_MIN); /* (-2147483647-1) */
708 dlt_user_log_write_finish(&context_data);
710 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
712 dlt_user_log_write_string(&context_data,"int8");
713 dlt_user_log_write_int8(&context_data,INT8_MIN); /* (-128) */
714 dlt_user_log_write_finish(&context_data);
716 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
718 dlt_user_log_write_string(&context_data,"int16");
719 dlt_user_log_write_int16(&context_data,INT16_MIN); /* (-32767-1) */
720 dlt_user_log_write_finish(&context_data);
722 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
724 dlt_user_log_write_string(&context_data,"int32");
725 dlt_user_log_write_int32(&context_data,INT32_MIN); /* (-2147483647-1) */
726 dlt_user_log_write_finish(&context_data);
728 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
730 dlt_user_log_write_string(&context_data,"int64");
731 dlt_user_log_write_int64(&context_data,INT64_MIN); /* (-__INT64_C(9223372036854775807)-1) */
732 dlt_user_log_write_finish(&context_data);
735 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
737 dlt_user_log_write_string(&context_data,"uint");
738 dlt_user_log_write_uint(&context_data,UINT32_MAX); /* (4294967295U) */
739 dlt_user_log_write_finish(&context_data);
741 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
743 dlt_user_log_write_string(&context_data,"uint8");
744 dlt_user_log_write_uint8(&context_data,UINT8_MAX); /* (255) */
745 dlt_user_log_write_finish(&context_data);
747 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
749 dlt_user_log_write_string(&context_data,"uint16");
750 dlt_user_log_write_uint16(&context_data,UINT16_MAX); /* (65535) */
751 dlt_user_log_write_finish(&context_data);
753 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
755 dlt_user_log_write_string(&context_data,"uint32");
756 dlt_user_log_write_uint32(&context_data,UINT32_MAX); /* (4294967295U) */
757 dlt_user_log_write_finish(&context_data);
759 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
761 dlt_user_log_write_string(&context_data,"uint64");
762 dlt_user_log_write_uint64(&context_data,UINT64_MAX); /* (__UINT64_C(18446744073709551615)) */
763 dlt_user_log_write_finish(&context_data);
766 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
768 dlt_user_log_write_string(&context_data,"float32");
769 dlt_user_log_write_float32(&context_data,FLT_MIN);
770 dlt_user_log_write_float32(&context_data,FLT_MAX);
771 dlt_user_log_write_finish(&context_data);
773 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
775 dlt_user_log_write_string(&context_data,"float64");
776 dlt_user_log_write_float64(&context_data,DBL_MIN);
777 dlt_user_log_write_float64(&context_data,DBL_MAX);
778 dlt_user_log_write_finish(&context_data);
781 for(num2=0;num2<10;num2++)
786 if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO)>0)
788 dlt_user_log_write_string(&context_data,"raw");
789 dlt_user_log_write_raw(&context_data,buffer,10);
790 dlt_user_log_write_finish(&context_data);
793 /* wait 2 second before next test */
795 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
797 dlt_user_log_write_string(&context_data,"Test2: (Function IF) finished");
798 dlt_user_log_write_finish(&context_data);
809 /* Test 3: (Function IF) Test all variable types (non-verbose) */
810 printf("Test3f: (Function IF) Test all variable types (non-verbose)\n");
811 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
813 dlt_user_log_write_string(&context_data,"Test3: (Function IF) Test all variable types (non-verbose)");
814 dlt_user_log_write_finish(&context_data);
817 dlt_nonverbose_mode();
819 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,1)>0) // bug mb: we have to compare against >0. in case of error -1 is returned!
821 dlt_user_log_write_string(&context_data,"bool");
822 dlt_user_log_write_bool(&context_data,1);
823 dlt_user_log_write_finish(&context_data);
826 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,2)>0)
828 dlt_user_log_write_string(&context_data,"int");
829 dlt_user_log_write_int(&context_data,INT32_MIN); /* (-2147483647-1) */
830 dlt_user_log_write_finish(&context_data);
832 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,3)>0)
834 dlt_user_log_write_string(&context_data,"int8");
835 dlt_user_log_write_int8(&context_data,INT8_MIN); /* (-128) */
836 dlt_user_log_write_finish(&context_data);
838 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,4)>0)
840 dlt_user_log_write_string(&context_data,"int16");
841 dlt_user_log_write_int16(&context_data,INT16_MIN); /* (-32767-1) */
842 dlt_user_log_write_finish(&context_data);
844 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,5)>0)
846 dlt_user_log_write_string(&context_data,"int32");
847 dlt_user_log_write_int32(&context_data,INT32_MIN); /* (-2147483647-1) */
848 dlt_user_log_write_finish(&context_data);
850 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,6)>0)
852 dlt_user_log_write_string(&context_data,"int64");
853 dlt_user_log_write_int64(&context_data,INT64_MIN); /* (-__INT64_C(9223372036854775807)-1) */
854 dlt_user_log_write_finish(&context_data);
857 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,7)>0)
859 dlt_user_log_write_string(&context_data,"uint");
860 dlt_user_log_write_uint(&context_data,UINT32_MAX); /* (4294967295U) */
861 dlt_user_log_write_finish(&context_data);
863 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,8)>0)
865 dlt_user_log_write_string(&context_data,"uint8");
866 dlt_user_log_write_uint8(&context_data,UINT8_MAX); /* (255) */
867 dlt_user_log_write_finish(&context_data);
869 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,9)>0)
871 dlt_user_log_write_string(&context_data,"uint16");
872 dlt_user_log_write_uint16(&context_data,UINT16_MAX); /* (65535) */
873 dlt_user_log_write_finish(&context_data);
875 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,10)>0)
877 dlt_user_log_write_string(&context_data,"uint32");
878 dlt_user_log_write_uint32(&context_data,UINT32_MAX); /* (4294967295U) */
879 dlt_user_log_write_finish(&context_data);
881 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,11)>0)
883 dlt_user_log_write_string(&context_data,"uint64");
884 dlt_user_log_write_uint64(&context_data,UINT64_MAX); /* (__UINT64_C(18446744073709551615)) */
885 dlt_user_log_write_finish(&context_data);
888 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,12)>0)
890 dlt_user_log_write_string(&context_data,"float32");
891 dlt_user_log_write_float32(&context_data,FLT_MIN);
892 dlt_user_log_write_float32(&context_data,FLT_MAX);
893 dlt_user_log_write_finish(&context_data);
895 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,13)>0)
897 dlt_user_log_write_string(&context_data,"float64");
898 dlt_user_log_write_float64(&context_data,DBL_MIN);
899 dlt_user_log_write_float64(&context_data,DBL_MAX);
900 dlt_user_log_write_finish(&context_data);
903 for(num2=0;num2<10;num2++)
908 if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,14)>0)
910 dlt_user_log_write_string(&context_data,"raw");
911 dlt_user_log_write_raw(&context_data,buffer,10);
912 dlt_user_log_write_finish(&context_data);
917 /* wait 2 second before next test */
919 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
921 dlt_user_log_write_string(&context_data,"Test3: (Function IF) finished");
922 dlt_user_log_write_finish(&context_data);
933 for(num=0;num<1024;num++)
938 /* Test 4: (Function IF) Message size test */
939 printf("Test4f: (Function IF) Test different message sizes\n");
940 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
942 dlt_user_log_write_string(&context_data,"Test4: (Function IF) Test different message sizes");
943 dlt_user_log_write_finish(&context_data);
946 if (dlt_user_log_write_start(&(context_function_test[3]),&context_data,DLT_LOG_INFO)>0)
948 dlt_user_log_write_string(&context_data,"1");
949 dlt_user_log_write_raw(&context_data,buffer,1);
950 dlt_user_log_write_finish(&context_data);
952 if (dlt_user_log_write_start(&(context_function_test[3]),&context_data,DLT_LOG_INFO)>0)
954 dlt_user_log_write_string(&context_data,"16");
955 dlt_user_log_write_raw(&context_data,buffer,16);
956 dlt_user_log_write_finish(&context_data);
958 if (dlt_user_log_write_start(&(context_function_test[3]),&context_data,DLT_LOG_INFO)>0)
960 dlt_user_log_write_string(&context_data,"256");
961 dlt_user_log_write_raw(&context_data,buffer,256);
962 dlt_user_log_write_finish(&context_data);
964 if (dlt_user_log_write_start(&(context_function_test[3]),&context_data,DLT_LOG_INFO)>0)
966 dlt_user_log_write_string(&context_data,"1024");
967 dlt_user_log_write_raw(&context_data,buffer,1024);
968 dlt_user_log_write_finish(&context_data);
971 /* wait 2 second before next test */
973 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
975 dlt_user_log_write_string(&context_data,"Test4: (Function IF) finished");
976 dlt_user_log_write_finish(&context_data);
987 for(num=0;num<32;num++)
992 /* Test 5: (Function IF) Test high-level API */
993 printf("Test5f: (Function IF) Test high-level API\n");
994 dlt_log_string(&context_info,DLT_LOG_INFO,"Test5: (Function IF) Test high-level API");
996 dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO,"Next line: dlt_log_int()");
997 dlt_log_int(&(context_function_test[4]),DLT_LOG_INFO, -42);
999 dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO,"Next line: dlt_log_uint()");
1000 dlt_log_uint(&(context_function_test[4]),DLT_LOG_INFO, 42);
1002 dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO,"Next line: dlt_log_string()");
1003 dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO, "String output");
1005 dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO,"Next line: dlt_log_raw()");
1006 dlt_log_raw(&(context_function_test[4]),DLT_LOG_INFO, buffer,16);
1008 dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO,"Next line: dlt_log_string_int()");
1009 dlt_log_string_int(&(context_function_test[4]), DLT_LOG_INFO, "String output: ", -42);
1011 dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO,"Next line: dlt_log_string_uint()");
1012 dlt_log_string_uint(&(context_function_test[4]), DLT_LOG_INFO,"String output: ", 42);
1014 /* wait 2 second before next test */
1016 dlt_log_string(&context_info,DLT_LOG_INFO,"Test5: (Function IF) finished");
1023 /* Test 6: (Function IF) Test local printing */
1024 printf("Test6f: (Function IF) Test local printing\n");
1025 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
1027 dlt_user_log_write_string(&context_data,"Test 6: (Function IF) Test local printing");
1028 dlt_user_log_write_finish(&context_data);
1031 dlt_enable_local_print();
1032 if (dlt_user_log_write_start(&(context_function_test[5]),&context_data,DLT_LOG_INFO)>0)
1034 dlt_user_log_write_string(&context_data,"Message (visible: locally printed)");
1035 dlt_user_log_write_finish(&context_data);
1038 dlt_disable_local_print();
1039 if (dlt_user_log_write_start(&(context_function_test[5]),&context_data,DLT_LOG_INFO)>0)
1041 dlt_user_log_write_string(&context_data,"Message (invisible: not locally printed)");
1042 dlt_user_log_write_finish(&context_data);
1045 /* wait 2 second before next test */
1047 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
1049 dlt_user_log_write_string(&context_data,"Test6: (Function IF) finished");
1050 dlt_user_log_write_finish(&context_data);
1061 for(num=0;num<32;num++)
1066 /* Show all log messages and traces */
1067 dlt_set_application_ll_ts_limit(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON);
1069 /* Test 7: (Function IF) Test network trace */
1070 printf("Test7f: (Function IF) Test network trace\n");
1071 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
1073 dlt_user_log_write_string(&context_data,"Test 7: (Function IF) Test network trace");
1074 dlt_user_log_write_finish(&context_data);
1077 /* Dummy message: 16 byte header, 32 byte payload */
1078 dlt_user_trace_network(&(context_function_test[6]), DLT_NW_TRACE_IPC, 16, buffer, 32, buffer);
1079 dlt_user_trace_network(&(context_function_test[6]), DLT_NW_TRACE_CAN, 16, buffer, 32, buffer);
1080 dlt_user_trace_network(&(context_function_test[6]), DLT_NW_TRACE_FLEXRAY, 16, buffer, 32, buffer);
1081 dlt_user_trace_network(&(context_function_test[6]), DLT_NW_TRACE_MOST, 16, buffer, 32, buffer);
1083 /* wait 2 second before next test */
1085 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
1087 dlt_user_log_write_string(&context_data,"Test7: (Function IF) finished");
1088 dlt_user_log_write_finish(&context_data);
1091 dlt_set_application_ll_ts_limit(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
1099 char buffer[1024*5];
1102 for(num=0;num<1024*5;num++)
1107 /* Show all log messages and traces */
1108 dlt_set_application_ll_ts_limit(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON);
1110 /* Test 8: (Function IF) Test truncated network trace */
1111 printf("Test8f: (Function IF) Test truncated network trace\n");
1112 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
1114 dlt_user_log_write_string(&context_data,"Test 8: (Function IF) Test truncated network trace");
1115 dlt_user_log_write_finish(&context_data);
1118 /* Dummy message: 16 byte header, 32 byte payload */
1119 dlt_user_trace_network_truncated(&(context_function_test[7]), DLT_NW_TRACE_IPC, 16, buffer, 1024*5, buffer, 1);
1120 dlt_user_trace_network_truncated(&(context_function_test[7]), DLT_NW_TRACE_CAN, 16, buffer, 1024*5, buffer, 1);
1121 dlt_user_trace_network_truncated(&(context_function_test[7]), DLT_NW_TRACE_FLEXRAY, 16, buffer, 1024*5, buffer, 1);
1122 dlt_user_trace_network_truncated(&(context_function_test[7]), DLT_NW_TRACE_MOST, 16, buffer, 1024*5, buffer, 1);
1124 /* wait 2 second before next test */
1126 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
1128 dlt_user_log_write_string(&context_data,"Test8: (Function IF) finished");
1129 dlt_user_log_write_finish(&context_data);
1132 dlt_set_application_ll_ts_limit(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
1140 char buffer[1024*5];
1143 for(num=0;num<1024*5;num++)
1148 /* Show all log messages and traces */
1149 dlt_set_application_ll_ts_limit(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON);
1151 /* Test 9: (Function IF) Test segmented network trace */
1152 printf("Test9f: (Function IF) Test segmented network trace\n");
1153 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
1155 dlt_user_log_write_string(&context_data,"Test 9: (Function IF) Test segmented network trace");
1156 dlt_user_log_write_finish(&context_data);
1159 /* Dummy message: 16 byte header, 5k payload */
1160 dlt_user_trace_network_segmented(&(context_function_test[8]), DLT_NW_TRACE_IPC, 16, buffer, 1024*5, buffer);
1161 dlt_user_trace_network_segmented(&(context_function_test[8]), DLT_NW_TRACE_CAN, 16, buffer, 1024*5, buffer);
1162 dlt_user_trace_network_segmented(&(context_function_test[8]), DLT_NW_TRACE_FLEXRAY, 16, buffer, 1024*5, buffer);
1163 dlt_user_trace_network_segmented(&(context_function_test[8]), DLT_NW_TRACE_MOST, 16, buffer, 1024*5, buffer);
1165 /* wait 2 second before next test */
1167 if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO)>0)
1169 dlt_user_log_write_string(&context_data,"Test9: (Function IF) finished");
1170 dlt_user_log_write_finish(&context_data);
1173 dlt_set_application_ll_ts_limit(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
1179 int test_injection_macro_callback(uint32_t service_id, void *data, uint32_t length)
1183 memset(text,0,1024);
1184 snprintf(text,1024,"Injection received (macro IF). ID: 0x%.4x, Length: %d",service_id,length);
1185 printf("%s \n", text);
1186 DLT_LOG(context_macro_callback, DLT_LOG_INFO, DLT_STRING("Injection received (macro IF). ID: "), DLT_UINT32(service_id),DLT_STRING("Data:"),DLT_STRING(text));
1187 memset(text,0,1024);
1191 dlt_print_mixed_string(text,1024,data,length,0);
1192 printf("%s \n", text);
1198 int test_injection_function_callback(uint32_t service_id, void *data, uint32_t length)
1202 memset(text,0,1024);
1204 snprintf(text,1024,"Injection received (function IF). ID: 0x%.4x, Length: %d",service_id,length);
1205 printf("%s \n", text);
1206 DLT_LOG(context_function_callback, DLT_LOG_INFO, DLT_STRING("Injection received (function IF). ID: "), DLT_UINT32(service_id),DLT_STRING("Data:"),DLT_STRING(text));
1207 memset(text,0,1024);
1211 dlt_print_mixed_string(text,1024,data,length,0);
1212 printf("%s \n", text);