Changed license from LGPL to MPLv2.0
[profile/ivi/dlt-daemon.git] / src / tests / dlt-test-user.c
1 /**\r
2  * @licence app begin@\r
3  * Copyright (C) 2012  BMW AG\r
4  *\r
5  * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.\r
6  *\r
7  * Contributions are licensed to the GENIVI Alliance under one or more\r
8  * Contribution License Agreements.\r
9  *\r
10  * \copyright\r
11  * This Source Code Form is subject to the terms of the\r
12  * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed with\r
13  * this file, You can obtain one at http://mozilla.org/MPL/2.0/.\r
14  *\r
15  *\r
16  * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011-2012\r
17  *\r
18  * \file dlt-test-user.c\r
19  * For further information see http://www.genivi.org/.\r
20  * @licence end@\r
21  */\r
22 \r
23 \r
24 /*******************************************************************************\r
25 **                                                                            **\r
26 **  SRC-MODULE: dlt-test-user.c                                               **\r
27 **                                                                            **\r
28 **  TARGET    : linux                                                         **
29 **                                                                            **
30 **  PROJECT   : DLT                                                           **
31 **                                                                            **
32 **  AUTHOR    : Alexander Wenzel Alexander.AW.Wenzel@bmw.de                   **
33 **              Markus Klein                                                  **
34 **                                                                            **
35 **  PURPOSE   :                                                               **
36 **                                                                            **
37 **  REMARKS   :                                                               **
38 **                                                                            **
39 **  PLATFORM DEPENDANT [yes/no]: yes                                          **
40 **                                                                            **
41 **  TO BE CHANGED BY USER [yes/no]: no                                        **
42 **                                                                            **
43 *******************************************************************************/
44
45 /*******************************************************************************
46 **                      Author Identity                                       **
47 ********************************************************************************
48 **                                                                            **
49 ** Initials     Name                       Company                            **
50 ** --------     -------------------------  ---------------------------------- **
51 **  aw          Alexander Wenzel           BMW                                **
52 **  mk          Markus Klein               Fraunhofer ESK                     **
53 *******************************************************************************/\r
54 \r
55 /*******************************************************************************\r
56 **                      Revision Control History                              **\r
57 *******************************************************************************/\r
58 \r
59 /*\r
60  * $LastChangedRevision: 1670 $\r
61  * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $\r
62  * $LastChangedBy$\r
63  Initials    Date         Comment\r
64  aw          13.01.2010   initial\r
65  */\r
66
67 #include <stdio.h>      /* for printf() and fprintf() */
68 #include <float.h>
69 #include <stdlib.h>     /* for atoi(), abort() */
70 #include <string.h>     /* for memset() */
71 #include <ctype.h>      /* for isprint() */
72
73 #include "dlt.h"
74
75 #define DLT_TEST_NUM_CONTEXT 7
76
77 /* Test functions... */
78
79 /* for macro interface */
80 int test1m(void);
81 int test2m(void);
82 int test3m(void);
83 int test4m(void);
84 int test5m(void);
85 int test6m(void);
86 int test7m(void);
87
88 /* for function interface */
89 int test1f(void);
90 int test2f(void);
91 int test3f(void);
92 int test4f(void);
93 int test5f(void);
94 int test6f(void);
95 int test7f(void);
96
97 /* Declaration of callback functions */
98 int test_injection_macro_callback(uint32_t service_id, void *data, uint32_t length);
99 int test_injection_function_callback(uint32_t service_id, void *data, uint32_t length);
100
101 /* Context declaration.. */
102 DLT_DECLARE_CONTEXT(context_info);
103
104 /* for macro interface */
105 DLT_DECLARE_CONTEXT(context_macro_callback);
106 DLT_DECLARE_CONTEXT(context_macro_test[DLT_TEST_NUM_CONTEXT]);
107
108 /* for function interface */
109 DltContext context_function_callback;\r
110 DltContext context_function_test[DLT_TEST_NUM_CONTEXT];
111
112 DltContextData context_data;\r
113 \r
114 /**\r
115  * Print usage information of tool.\r
116  */\r
117 void usage()\r
118 {\r
119         char version[255];\r
120 \r
121         dlt_get_version(version);\r
122 \r
123         printf("Usage: dlt-test-user [options]\n");\r
124         printf("Test user application providing several Tests.\n");\r
125         printf("%s \n", version);\r
126         printf("Options:\n");\r
127         printf("  -v            Verbose mode\n");\r
128         printf("  -f filename   Use local log file instead of sending to daemon\n");\r
129         printf("  -n count      Repeats of tests (Default: 1)\n");\r
130         printf("Tests:\n");\r
131         printf("  1m: (Macro IF)    Test all log levels\n");
132         printf("  2m: (Macro IF)    Test all variable types (verbose) \n");
133         printf("  3m: (Macro IF)    Test all variable types (non-verbose) \n");
134         printf("  4m: (Macro IF)    Test different message sizes\n");
135         printf("  5m: (Macro IF)    Test high-level API\n");
136         printf("  6m: (Macro IF)    Test local printing\n");
137         printf("  7m: (Macro IF)    Test network trace\n");
138         printf("  1f: (Function IF) Test all log levels\n");
139         printf("  2f: (Function IF) Test all variable types (verbose) \n");
140         printf("  3f: (Function IF) Test all variable types (non-verbose) \n");
141         printf("  4f: (Function IF) Test different message sizes\n");
142         printf("  5f: (Function IF) Test high-level API\n");
143         printf("  6f: (Function IF) Test local printing\n");
144         printf("  7f: (Function IF) Test network trace\n");\r
145 }\r
146 \r
147 /**\r
148  * Main function of tool.\r
149  */\r
150 int main(int argc, char* argv[])\r
151 {\r
152     //int vflag = 0;\r
153     char *fvalue = 0;\r
154     char *nvalue = 0;
155 \r
156     int c;
157
158         int i;
159         char ctid[4], ctdesc[255];
160
161         int num,maxnum;\r
162 \r
163     opterr = 0;\r
164 \r
165     while ((c = getopt (argc, argv, "vf:n:")) != -1)
166         {\r
167         switch (c)\r
168         {\r
169         case 'v':
170         {\r
171             //vflag = 1;\r
172             break;\r
173         }
174         case 'f':\r
175         {
176             fvalue = optarg;\r
177             break;\r
178         }
179         case 'n':\r
180         {
181             nvalue = optarg;\r
182             break;\r
183         }
184         case '?':
185         {\r
186             if (optopt == 'd' || optopt == 'f' || optopt == 'n')\r
187             {
188                 fprintf (stderr, "Option -%c requires an argument.\n", optopt);\r
189             }
190             else if (isprint (optopt))\r
191             {
192                 fprintf (stderr, "Unknown option `-%c'.\n", optopt);\r
193             }
194             else\r
195             {
196                 fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt);\r
197             }
198             /* unknown or wrong option used, show usage information and terminate */\r
199             usage();\r
200             return -1;\r
201         }
202         default:\r
203         {
204             abort ();\r
205         }
206         }
207         }\r
208 \r
209     if (fvalue)\r
210     {\r
211         /* DLT is intialised automatically, except another output target will be used */\r
212         if (dlt_init_file(fvalue)<0) /* log to file */
213         {\r
214             return -1;
215         }\r
216     }
217 \r
218     if (nvalue)
219     {\r
220         maxnum = atoi(nvalue);\r
221     }
222     else\r
223     {
224         maxnum = 1;
225     }
226
227         /* Register APP */
228         DLT_REGISTER_APP("DIFT","DLT Interface Test");
229
230         /* Register CONTEXTS... */\r
231         DLT_REGISTER_CONTEXT(context_info,"INFO","Information context");
232
233         /* used for macro interface tests */
234         DLT_REGISTER_CONTEXT(context_macro_callback,"CBM","Callback Test context for macro interface");
235         for (i=0;i<DLT_TEST_NUM_CONTEXT;i++)
236         {
237                 snprintf(ctid,4,"TM%d",i+1);
238                 snprintf(ctdesc,255,"Test %d context for macro interface",i+1);
239                 DLT_REGISTER_CONTEXT(context_macro_test[i],ctid,ctdesc);
240         }
241
242         /* used for function interface tests */
243         dlt_register_context(&context_function_callback,"CBF","Callback Test context for function interface");
244         for (i=0;i<DLT_TEST_NUM_CONTEXT;i++)
245         {
246                 snprintf(ctid,4,"TF%d",i+1);
247                 snprintf(ctdesc,255,"Test %d context for function interface",i+1);
248                 dlt_register_context(&(context_function_test[i]),ctid,ctdesc);
249         }
250
251         /* Register callbacks... */
252
253         /* with macro interface */
254         DLT_LOG(context_macro_callback,DLT_LOG_INFO,DLT_STRING("Register callback (Macro Interface) for Injection ID: 0xFFF"));
255         DLT_REGISTER_INJECTION_CALLBACK(context_macro_callback, 0xFFF, test_injection_macro_callback);
256
257         /* with function interface */
258         if (dlt_user_log_write_start(&context_function_callback,&context_data,DLT_LOG_INFO))\r
259         {\r
260                 dlt_user_log_write_string(&context_data,"Register callback (Function Interface) for Injection ID: 0xFFF");\r
261                 dlt_user_log_write_finish(&context_data);\r
262     }
263         dlt_register_injection_callback(&context_function_callback, 0xFFF, test_injection_function_callback);
264 \r
265     /* Tests starting */\r
266     printf("Tests starting\n");\r
267     DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Tests starting"));\r
268 \r
269     /* wait 3 seconds before starting */\r
270     sleep(3);\r
271 \r
272     for (num=0;num<maxnum;num++)\r
273     {
274                 /* Execute tests... */
275
276                 /* with macro interface */
277                 test1m();\r
278                 test2m();\r
279                 test3m();
280                 test4m();\r
281                 test5m();
282                 test6m();
283                 test7m();
284
285                 /* with function interface */
286                 test1f();\r
287                 test2f();\r
288                 test3f();
289                 test4f();\r
290                 test5f();
291                 test6f();
292                 test7f();
293 \r
294                 /* wait 1 second before next repeat of tests */\r
295         sleep(1);\r
296     }\r
297 \r
298     /* Tests finished */\r
299     printf("Tests finished\n");\r
300     DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Tests finished"));\r
301 \r
302     /* wait 3 seconds before terminating application */\r
303     sleep(3);\r
304
305         /* Unregister CONTEXTS... */
306         DLT_UNREGISTER_CONTEXT(context_info);
307
308         /* used for macro interface tests */
309         for (i=0;i<DLT_TEST_NUM_CONTEXT;i++)
310         {
311                 DLT_UNREGISTER_CONTEXT(context_macro_test[i]);
312         }
313         DLT_UNREGISTER_CONTEXT(context_macro_callback);
314
315         /* used for function interface tests */
316         for (i=0;i<DLT_TEST_NUM_CONTEXT;i++)
317         {
318                 dlt_unregister_context(&(context_function_test[i]));
319         }
320         dlt_unregister_context(&context_function_callback);
321
322         /* Unregister APP */\r
323     DLT_UNREGISTER_APP();
324 \r
325     dlt_free();\r
326 \r
327     return 0;\r
328 }
329
330 /******************/
331 /* The test cases */
332 /******************/
333
334 int test1m(void)
335 {
336         /* Test 1: (Macro IF) Test all log levels */\r
337     printf("Test1m: (Macro IF) Test all log levels\n");\r
338     DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test1: (Macro IF) Test all log levels"));\r
339 \r
340     DLT_LOG(context_macro_test[0],DLT_LOG_FATAL,DLT_STRING("fatal"));\r
341     DLT_LOG(context_macro_test[0],DLT_LOG_ERROR,DLT_STRING("error"));\r
342     DLT_LOG(context_macro_test[0],DLT_LOG_WARN,DLT_STRING("warn"));\r
343     DLT_LOG(context_macro_test[0],DLT_LOG_INFO,DLT_STRING("info"));\r
344     DLT_LOG(context_macro_test[0],DLT_LOG_DEBUG,DLT_STRING("debug"));\r
345     DLT_LOG(context_macro_test[0],DLT_LOG_VERBOSE,DLT_STRING("verbose"));
346
347         /* wait 2 second before next test */\r
348     sleep(2);\r
349     DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test1: (Macro IF) finished"));
350
351         return 0;
352 }
353
354 int test2m(void)
355 {
356         char buffer[10];
357     int num2;
358
359         /* Test 2: (Macro IF) Test all variable types (verbose) */\r
360     printf("Test2m: (Macro IF) Test all variable types (verbose)\n");\r
361     DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test2: (Macro IF) Test all variable types (verbose)"));\r
362 \r
363     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("bool"),DLT_BOOL(1));\r
364     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("int"),DLT_INT(INT32_MIN));         /* (-2147483647-1) */\r
365     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("int8"),DLT_INT8(INT8_MIN));        /*          (-128) */\r
366     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("int16"),DLT_INT16(INT16_MIN));     /*      (-32767-1) */\r
367     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("int32"),DLT_INT32(INT32_MIN));     /* (-2147483647-1) */\r
368     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("int64"),DLT_INT64(INT64_MIN));     /* (-__INT64_C(9223372036854775807)-1) */\r
369     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("uint"),DLT_UINT(UINT32_MAX));      /*   (4294967295U) */\r
370     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("uint8"),DLT_UINT8(UINT8_MAX));     /*           (255) */\r
371     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("uint16"),DLT_UINT16(UINT16_MAX));  /*         (65535) */\r
372     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("uint32"),DLT_UINT32(UINT32_MAX));  /*   (4294967295U) */\r
373     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("uint64"),DLT_UINT64(UINT64_MAX));  /* (__UINT64_C(18446744073709551615)) */
374     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("float32"),DLT_FLOAT32(FLT_MIN),DLT_FLOAT32(FLT_MAX));
375     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("float64"),DLT_FLOAT64(DBL_MIN),DLT_FLOAT64(DBL_MAX));
376
377     for(num2=0;num2<10;num2++)
378     {\r
379         buffer[num2] = num2;\r
380     }
381
382     DLT_LOG(context_macro_test[1],DLT_LOG_INFO,DLT_STRING("raw"),DLT_RAW(buffer,10));
383
384         /* wait 2 second before next test */\r
385     sleep(2);
386         DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test2: (Macro IF) finished"));
387
388         return 0;
389 }
390
391 int test3m(void)
392 {
393         char buffer[10];
394     int num2;
395
396         /* Test 3: (Macro IF) Test all variable types (non-verbose) */\r
397     printf("Test3m: (Macro IF) Test all variable types (non-verbose)\n");\r
398     DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test3: (Macro IF) Test all variable types (non-verbose)"));\r
399
400         DLT_NONVERBOSE_MODE();
401 \r
402     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,1,DLT_STRING("bool"),DLT_BOOL(1));\r
403     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,2,DLT_STRING("int"),DLT_INT(INT32_MIN));         /* (-2147483647-1) */\r
404     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,3,DLT_STRING("int8"),DLT_INT8(INT8_MIN));        /*          (-128) */\r
405     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,4,DLT_STRING("int16"),DLT_INT16(INT16_MIN));     /*      (-32767-1) */\r
406     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,5,DLT_STRING("int32"),DLT_INT32(INT32_MIN));     /* (-2147483647-1) */\r
407     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,6,DLT_STRING("int64"),DLT_INT64(INT64_MIN));     /* (-__INT64_C(9223372036854775807)-1) */\r
408     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,7,DLT_STRING("uint"),DLT_UINT(UINT32_MAX));      /*   (4294967295U) */\r
409     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,8,DLT_STRING("uint8"),DLT_UINT8(UINT8_MAX));     /*           (255) */\r
410     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,9,DLT_STRING("uint16"),DLT_UINT16(UINT16_MAX));  /*         (65535) */\r
411     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,10,DLT_STRING("uint32"),DLT_UINT32(UINT32_MAX));  /*   (4294967295U) */\r
412     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,11,DLT_STRING("uint64"),DLT_UINT64(UINT64_MAX));  /* (__UINT64_C(18446744073709551615)) */
413     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,12,DLT_STRING("float32"),DLT_FLOAT32(FLT_MIN),DLT_FLOAT32(FLT_MAX));
414     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,13,DLT_STRING("float64"),DLT_FLOAT64(DBL_MIN),DLT_FLOAT64(DBL_MAX));
415 \r
416 \r
417     for(num2=0;num2<10;num2++)
418     {\r
419         buffer[num2] = num2;
420     }\r
421     DLT_LOG_ID(context_macro_test[2],DLT_LOG_INFO,14,DLT_STRING("raw"),DLT_RAW(buffer,10));
422
423         DLT_VERBOSE_MODE();
424
425         /* wait 2 second before next test */\r
426     sleep(2);
427         DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test3: (Macro IF) finished"));
428
429         return 0;
430 }
431
432 int test4m(void)
433 {
434         char buffer[1024];\r
435     int num;\r
436
437     for(num=0;num<1024;num++)
438     {\r
439         buffer[num] = num;
440     }
441
442         /* Test 4: (Macro IF) Message size test */\r
443     printf("Test4m: (Macro IF) Test different message sizes\n");\r
444     DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test4: (Macro IF) Test different message sizes"));\r
445 \r
446     DLT_LOG(context_macro_test[3],DLT_LOG_INFO,DLT_STRING("1"),DLT_RAW(buffer,1));\r
447     DLT_LOG(context_macro_test[3],DLT_LOG_INFO,DLT_STRING("16"),DLT_RAW(buffer,16));\r
448     DLT_LOG(context_macro_test[3],DLT_LOG_INFO,DLT_STRING("256"),DLT_RAW(buffer,256));\r
449     DLT_LOG(context_macro_test[3],DLT_LOG_INFO,DLT_STRING("1024"),DLT_RAW(buffer,1024));
450
451         /* wait 2 second before next test */\r
452     sleep(2);
453         DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test4: (Macro IF) finished"));
454
455         return 0;
456 }
457
458 int test5m(void)
459 {
460         char buffer[32];\r
461     int num;\r
462
463     for(num=0;num<32;num++)
464     {\r
465         buffer[num] = num;
466     }
467
468         /* Test 5: (Macro IF) Test high-level API */\r
469     printf("Test5m: (Macro IF) Test high-level API\n");\r
470     DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test5: (Macro IF) Test high-level API"));
471
472         DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_INT"));
473         DLT_LOG_INT(context_macro_test[4], DLT_LOG_INFO, -42);
474
475         DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_UINT"));
476         DLT_LOG_UINT(context_macro_test[4], DLT_LOG_INFO, 42);
477
478         DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_STRING"));
479         DLT_LOG_STRING(context_macro_test[4], DLT_LOG_INFO, "String output");
480
481         DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_RAW"));
482         DLT_LOG_RAW(context_macro_test[4],DLT_LOG_INFO, buffer,16);
483
484         DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_STRING_INT"));
485         DLT_LOG_STRING_INT(context_macro_test[4], DLT_LOG_INFO, "String output: ", -42);
486
487         DLT_LOG(context_macro_test[4],DLT_LOG_INFO,DLT_STRING("Next line: DLT_LOG_STRING_UINT"));
488         DLT_LOG_STRING_UINT(context_macro_test[4], DLT_LOG_INFO,"String output: ", 42);
489
490         /* wait 2 second before next test */\r
491     sleep(2);
492         DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test5: (Macro IF) finished"));
493
494         return 0;
495 }
496
497 int test6m(void)
498 {
499         /* Test 6: (Macro IF) Test local printing */
500         printf("Test6m: (Macro IF) Test local printing\n");\r
501     DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test 6: (Macro IF) Test local printing");
502
503         DLT_ENABLE_LOCAL_PRINT();
504         DLT_LOG_STRING(context_macro_test[5], DLT_LOG_INFO, "Message (visible: locally printed)");
505
506         DLT_DISABLE_LOCAL_PRINT();
507         DLT_LOG_STRING(context_macro_test[5], DLT_LOG_INFO, "Message (invisible: not locally printed)");
508
509          /* wait 2 second before next test */\r
510     sleep(2);
511         DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test6: (Macro IF) finished"));
512 \r
513         return 0;
514 }
515
516 int test7m(void)
517 {
518         char buffer[32];\r
519     int num;\r
520
521     for(num=0;num<32;num++)
522     {\r
523         buffer[num] = num;
524     }
525
526         /* Show all log messages and traces */
527         DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON);
528
529         /* Test 7: (Macro IF) Test network trace */
530         printf("Test7m: (Macro IF) Test network trace\n");\r
531     DLT_LOG_STRING(context_info, DLT_LOG_INFO, "Test 7: (Macro IF) Test network trace");
532
533         /* Dummy messages: 16 byte header, 32 byte payload */
534         DLT_TRACE_NETWORK(context_macro_test[6], DLT_NW_TRACE_IPC, 16, buffer, 32, buffer);
535         DLT_TRACE_NETWORK(context_macro_test[6], DLT_NW_TRACE_CAN, 16, buffer, 32, buffer);
536         DLT_TRACE_NETWORK(context_macro_test[6], DLT_NW_TRACE_FLEXRAY, 16, buffer, 32, buffer);
537         DLT_TRACE_NETWORK(context_macro_test[6], DLT_NW_TRACE_MOST, 16, buffer, 32, buffer);
538
539         /* wait 2 second before next test */\r
540     sleep(2);
541         DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test7: (Macro IF) finished"));\r
542
543         DLT_SET_APPLICATION_LL_TS_LIMIT(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
544         sleep(2);
545
546         return 0;
547 }
548
549 int test1f(void)
550 {
551         /* Test 1: (Function IF) Test all log levels */\r
552     printf("Test1f: (Function IF) Test all log levels\n");
553         if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO))\r
554         {\r
555                 dlt_user_log_write_string(&context_data,"Test1: (Function IF) Test all log levels");\r
556                 dlt_user_log_write_finish(&context_data);\r
557     }
558
559         if (dlt_user_log_write_start(&(context_function_test[0]),&context_data,DLT_LOG_FATAL))\r
560         {\r
561                 dlt_user_log_write_string(&context_data,"fatal");\r
562                 dlt_user_log_write_finish(&context_data);\r
563     }\r
564         if (dlt_user_log_write_start(&(context_function_test[0]),&context_data,DLT_LOG_ERROR))\r
565         {\r
566                 dlt_user_log_write_string(&context_data,"error");\r
567                 dlt_user_log_write_finish(&context_data);\r
568     }
569         if (dlt_user_log_write_start(&(context_function_test[0]),&context_data,DLT_LOG_WARN))\r
570         {\r
571                 dlt_user_log_write_string(&context_data,"warn");\r
572                 dlt_user_log_write_finish(&context_data);\r
573     }
574         if (dlt_user_log_write_start(&(context_function_test[0]),&context_data,DLT_LOG_INFO))\r
575         {\r
576                 dlt_user_log_write_string(&context_data,"info");\r
577                 dlt_user_log_write_finish(&context_data);\r
578     }
579         if (dlt_user_log_write_start(&(context_function_test[0]),&context_data,DLT_LOG_DEBUG))\r
580         {\r
581                 dlt_user_log_write_string(&context_data,"debug");\r
582                 dlt_user_log_write_finish(&context_data);\r
583     }
584         if (dlt_user_log_write_start(&(context_function_test[0]),&context_data,DLT_LOG_VERBOSE))\r
585         {\r
586                 dlt_user_log_write_string(&context_data,"verbose");\r
587                 dlt_user_log_write_finish(&context_data);\r
588     }\r
589
590         /* wait 2 second before next test */\r
591     sleep(2);
592         if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO))\r
593         {\r
594                 dlt_user_log_write_string(&context_data,"Test1: (Function IF) finished");\r
595                 dlt_user_log_write_finish(&context_data);\r
596     }
597
598         return 0;
599 }
600
601 int test2f(void)
602 {
603         char buffer[10];
604     int num2;
605
606         /* Test 2: (Function IF) Test all variable types (verbose) */\r
607     printf("Test2f: (Function IF) Test all variable types (verbose)\n");
608         if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO))\r
609         {\r
610                 dlt_user_log_write_string(&context_data,"Test2: (Function IF) Test all variable types (verbose)");\r
611                 dlt_user_log_write_finish(&context_data);\r
612     }\r
613
614         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
615         {\r
616                 dlt_user_log_write_string(&context_data,"bool");
617                 dlt_user_log_write_bool(&context_data,1);\r
618                 dlt_user_log_write_finish(&context_data);\r
619     }
620 \r
621         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
622         {\r
623                 dlt_user_log_write_string(&context_data,"int");
624                 dlt_user_log_write_int(&context_data,INT32_MIN);        /* (-2147483647-1) */\r
625                 dlt_user_log_write_finish(&context_data);\r
626     }
627         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
628         {\r
629                 dlt_user_log_write_string(&context_data,"int8");
630                 dlt_user_log_write_int8(&context_data,INT8_MIN);        /*          (-128) */\r
631                 dlt_user_log_write_finish(&context_data);\r
632     }
633         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
634         {\r
635                 dlt_user_log_write_string(&context_data,"int16");
636                 dlt_user_log_write_int16(&context_data,INT16_MIN);     /*      (-32767-1) */\r
637                 dlt_user_log_write_finish(&context_data);\r
638     }
639         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
640         {\r
641                 dlt_user_log_write_string(&context_data,"int32");
642                 dlt_user_log_write_int32(&context_data,INT32_MIN);     /* (-2147483647-1) */\r
643                 dlt_user_log_write_finish(&context_data);\r
644     }
645         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
646         {\r
647                 dlt_user_log_write_string(&context_data,"int64");
648                 dlt_user_log_write_int64(&context_data,INT64_MIN);     /* (-__INT64_C(9223372036854775807)-1) */\r
649                 dlt_user_log_write_finish(&context_data);\r
650     }
651
652         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
653         {\r
654                 dlt_user_log_write_string(&context_data,"uint");
655                 dlt_user_log_write_uint(&context_data,UINT32_MAX);     /*   (4294967295U) */\r
656                 dlt_user_log_write_finish(&context_data);\r
657     }
658         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
659         {\r
660                 dlt_user_log_write_string(&context_data,"uint8");
661                 dlt_user_log_write_uint8(&context_data,UINT8_MAX);     /*           (255) */\r
662                 dlt_user_log_write_finish(&context_data);\r
663     }
664         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
665         {\r
666                 dlt_user_log_write_string(&context_data,"uint16");
667                 dlt_user_log_write_uint16(&context_data,UINT16_MAX);   /*         (65535) */\r
668                 dlt_user_log_write_finish(&context_data);\r
669     }
670         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
671         {\r
672                 dlt_user_log_write_string(&context_data,"uint32");
673                 dlt_user_log_write_uint32(&context_data,UINT32_MAX);   /*   (4294967295U) */\r
674                 dlt_user_log_write_finish(&context_data);\r
675     }
676         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
677         {\r
678                 dlt_user_log_write_string(&context_data,"uint64");
679                 dlt_user_log_write_uint64(&context_data,UINT64_MAX);   /* (__UINT64_C(18446744073709551615)) */\r
680                 dlt_user_log_write_finish(&context_data);\r
681     }
682
683         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
684         {\r
685                 dlt_user_log_write_string(&context_data,"float32");
686                 dlt_user_log_write_float32(&context_data,FLT_MIN);
687                 dlt_user_log_write_float32(&context_data,FLT_MAX);\r
688                 dlt_user_log_write_finish(&context_data);\r
689     }
690         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
691         {\r
692                 dlt_user_log_write_string(&context_data,"float64");
693                 dlt_user_log_write_float64(&context_data,DBL_MIN);
694                 dlt_user_log_write_float64(&context_data,DBL_MAX);\r
695                 dlt_user_log_write_finish(&context_data);\r
696     }
697
698     for(num2=0;num2<10;num2++)
699     {\r
700         buffer[num2] = num2;
701     }
702
703         if (dlt_user_log_write_start(&(context_function_test[1]),&context_data,DLT_LOG_INFO))\r
704         {\r
705                 dlt_user_log_write_string(&context_data,"raw");
706                 dlt_user_log_write_raw(&context_data,buffer,10);\r
707                 dlt_user_log_write_finish(&context_data);\r
708     }
709
710         /* wait 2 second before next test */\r
711     sleep(2);
712         if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO))\r
713         {\r
714                 dlt_user_log_write_string(&context_data,"Test2: (Function IF) finished");\r
715                 dlt_user_log_write_finish(&context_data);\r
716     }
717
718         return 0;
719 }
720
721 int test3f(void)
722 {
723         char buffer[10];
724     int num2;
725
726         /* Test 3: (Function IF) Test all variable types (non-verbose) */\r
727     printf("Test3f: (Function IF) Test all variable types (non-verbose)\n");
728         if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO))\r
729         {\r
730                 dlt_user_log_write_string(&context_data,"Test3: (Function IF) Test all variable types (non-verbose)");\r
731                 dlt_user_log_write_finish(&context_data);\r
732     }
733
734         dlt_nonverbose_mode();\r
735
736         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,1))\r
737         {\r
738                 dlt_user_log_write_string(&context_data,"bool");
739                 dlt_user_log_write_bool(&context_data,1);\r
740                 dlt_user_log_write_finish(&context_data);\r
741     }
742 \r
743         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,2))\r
744         {\r
745                 dlt_user_log_write_string(&context_data,"int");
746                 dlt_user_log_write_int(&context_data,INT32_MIN);        /* (-2147483647-1) */\r
747                 dlt_user_log_write_finish(&context_data);\r
748     }
749         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,3))\r
750         {\r
751                 dlt_user_log_write_string(&context_data,"int8");
752                 dlt_user_log_write_int8(&context_data,INT8_MIN);        /*          (-128) */\r
753                 dlt_user_log_write_finish(&context_data);\r
754     }
755         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,4))\r
756         {\r
757                 dlt_user_log_write_string(&context_data,"int16");
758                 dlt_user_log_write_int16(&context_data,INT16_MIN);     /*      (-32767-1) */\r
759                 dlt_user_log_write_finish(&context_data);\r
760     }
761         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,5))\r
762         {\r
763                 dlt_user_log_write_string(&context_data,"int32");
764                 dlt_user_log_write_int32(&context_data,INT32_MIN);     /* (-2147483647-1) */\r
765                 dlt_user_log_write_finish(&context_data);\r
766     }
767         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,6))\r
768         {\r
769                 dlt_user_log_write_string(&context_data,"int64");
770                 dlt_user_log_write_int64(&context_data,INT64_MIN);     /* (-__INT64_C(9223372036854775807)-1) */\r
771                 dlt_user_log_write_finish(&context_data);\r
772     }
773
774         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,7))\r
775         {\r
776                 dlt_user_log_write_string(&context_data,"uint");
777                 dlt_user_log_write_uint(&context_data,UINT32_MAX);     /*   (4294967295U) */\r
778                 dlt_user_log_write_finish(&context_data);\r
779     }
780         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,8))\r
781         {\r
782                 dlt_user_log_write_string(&context_data,"uint8");
783                 dlt_user_log_write_uint8(&context_data,UINT8_MAX);     /*           (255) */\r
784                 dlt_user_log_write_finish(&context_data);\r
785     }
786         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,9))\r
787         {\r
788                 dlt_user_log_write_string(&context_data,"uint16");
789                 dlt_user_log_write_uint16(&context_data,UINT16_MAX);   /*         (65535) */\r
790                 dlt_user_log_write_finish(&context_data);\r
791     }
792         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,10))\r
793         {\r
794                 dlt_user_log_write_string(&context_data,"uint32");
795                 dlt_user_log_write_uint32(&context_data,UINT32_MAX);   /*   (4294967295U) */\r
796                 dlt_user_log_write_finish(&context_data);\r
797     }
798         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,11))\r
799         {\r
800                 dlt_user_log_write_string(&context_data,"uint64");
801                 dlt_user_log_write_uint64(&context_data,UINT64_MAX);   /* (__UINT64_C(18446744073709551615)) */\r
802                 dlt_user_log_write_finish(&context_data);\r
803     }
804
805         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,12))\r
806         {\r
807                 dlt_user_log_write_string(&context_data,"float32");
808                 dlt_user_log_write_float32(&context_data,FLT_MIN);
809                 dlt_user_log_write_float32(&context_data,FLT_MAX);\r
810                 dlt_user_log_write_finish(&context_data);\r
811     }
812         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,13))\r
813         {\r
814                 dlt_user_log_write_string(&context_data,"float64");
815                 dlt_user_log_write_float64(&context_data,DBL_MIN);
816                 dlt_user_log_write_float64(&context_data,DBL_MAX);\r
817                 dlt_user_log_write_finish(&context_data);\r
818     }
819 \r
820     for(num2=0;num2<10;num2++)
821     {\r
822         buffer[num2] = num2;
823         }
824
825         if (dlt_user_log_write_start_id(&(context_function_test[2]),&context_data,DLT_LOG_INFO,14))\r
826         {\r
827                 dlt_user_log_write_string(&context_data,"raw");
828                 dlt_user_log_write_raw(&context_data,buffer,10);\r
829                 dlt_user_log_write_finish(&context_data);\r
830     }
831
832         dlt_verbose_mode();
833
834         /* wait 2 second before next test */\r
835     sleep(2);
836         if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO))\r
837         {\r
838                 dlt_user_log_write_string(&context_data,"Test3: (Function IF) finished");\r
839                 dlt_user_log_write_finish(&context_data);\r
840     }
841
842         return 0;
843 }
844
845 int test4f(void)
846 {
847         char buffer[1024];\r
848     int num;
849 \r
850     for(num=0;num<1024;num++)
851     {\r
852         buffer[num] = num;
853     }
854
855         /* Test 4: (Function IF) Message size test */\r
856     printf("Test4f: (Function IF) Test different message sizes\n");
857         if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO))\r
858         {\r
859                 dlt_user_log_write_string(&context_data,"Test4: (Function IF) Test different message sizes");\r
860                 dlt_user_log_write_finish(&context_data);\r
861     }
862
863         if (dlt_user_log_write_start(&(context_function_test[3]),&context_data,DLT_LOG_INFO))\r
864         {\r
865                 dlt_user_log_write_string(&context_data,"1");
866                 dlt_user_log_write_raw(&context_data,buffer,1);\r
867                 dlt_user_log_write_finish(&context_data);\r
868     }\r
869         if (dlt_user_log_write_start(&(context_function_test[3]),&context_data,DLT_LOG_INFO))\r
870         {\r
871                 dlt_user_log_write_string(&context_data,"16");
872                 dlt_user_log_write_raw(&context_data,buffer,16);\r
873                 dlt_user_log_write_finish(&context_data);\r
874     }
875         if (dlt_user_log_write_start(&(context_function_test[3]),&context_data,DLT_LOG_INFO))\r
876         {\r
877                 dlt_user_log_write_string(&context_data,"256");
878                 dlt_user_log_write_raw(&context_data,buffer,256);\r
879                 dlt_user_log_write_finish(&context_data);\r
880     }
881         if (dlt_user_log_write_start(&(context_function_test[3]),&context_data,DLT_LOG_INFO))\r
882         {\r
883                 dlt_user_log_write_string(&context_data,"1024");
884                 dlt_user_log_write_raw(&context_data,buffer,1024);\r
885                 dlt_user_log_write_finish(&context_data);\r
886     }
887
888         /* wait 2 second before next test */\r
889     sleep(2);
890         if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO))\r
891         {\r
892                 dlt_user_log_write_string(&context_data,"Test4: (Function IF) finished");\r
893                 dlt_user_log_write_finish(&context_data);\r
894     }
895
896         return 0;
897 }
898
899 int test5f(void)
900 {
901         char buffer[32];\r
902     int num;\r
903
904     for(num=0;num<32;num++)
905     {\r
906         buffer[num] = num;
907     }
908
909         /* Test 5: (Function IF) Test high-level API */\r
910     printf("Test5f: (Function IF) Test high-level API\n");
911         dlt_log_string(&context_info,DLT_LOG_INFO,"Test5: (Function IF) Test high-level API");
912
913         dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO,"Next line: dlt_log_int()");
914         dlt_log_int(&(context_function_test[4]),DLT_LOG_INFO, -42);
915
916         dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO,"Next line: dlt_log_uint()");
917         dlt_log_uint(&(context_function_test[4]),DLT_LOG_INFO, 42);
918
919         dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO,"Next line: dlt_log_string()");
920         dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO, "String output");
921
922         dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO,"Next line: dlt_log_raw()");
923         dlt_log_raw(&(context_function_test[4]),DLT_LOG_INFO, buffer,16);
924
925         dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO,"Next line: dlt_log_string_int()");
926         dlt_log_string_int(&(context_function_test[4]), DLT_LOG_INFO, "String output: ", -42);
927
928         dlt_log_string(&(context_function_test[4]),DLT_LOG_INFO,"Next line: dlt_log_string_uint()");
929         dlt_log_string_uint(&(context_function_test[4]), DLT_LOG_INFO,"String output: ", 42);
930
931         /* wait 2 second before next test */\r
932     sleep(2);
933         dlt_log_string(&context_info,DLT_LOG_INFO,"Test5: (Function IF) finished");
934
935         return 0;
936 }
937
938 int test6f(void)
939 {
940         /* Test 6: (Function IF) Test local printing */
941         printf("Test6f: (Function IF) Test local printing\n");
942         if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO))\r
943         {\r
944                 dlt_user_log_write_string(&context_data,"Test 6: (Function IF) Test local printing");\r
945                 dlt_user_log_write_finish(&context_data);\r
946     }
947
948         dlt_enable_local_print();
949         if (dlt_user_log_write_start(&(context_function_test[5]),&context_data,DLT_LOG_INFO))\r
950         {\r
951                 dlt_user_log_write_string(&context_data,"Message (visible: locally printed)");\r
952                 dlt_user_log_write_finish(&context_data);\r
953     }
954
955         dlt_disable_local_print();
956         if (dlt_user_log_write_start(&(context_function_test[5]),&context_data,DLT_LOG_INFO))\r
957         {\r
958                 dlt_user_log_write_string(&context_data,"Message (invisible: not locally printed)");\r
959                 dlt_user_log_write_finish(&context_data);\r
960     }
961
962          /* wait 2 second before next test */\r
963     sleep(2);
964         if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO))\r
965         {\r
966                 dlt_user_log_write_string(&context_data,"Test6: (Function IF) finished");\r
967                 dlt_user_log_write_finish(&context_data);\r
968     }
969
970         return 0;
971 }
972
973 int test7f(void)
974 {
975         char buffer[32];\r
976     int num;
977 \r
978     for(num=0;num<32;num++)
979     {\r
980         buffer[num] = num;
981     }
982
983         /* Show all log messages and traces */
984         dlt_set_application_ll_ts_limit(DLT_LOG_VERBOSE, DLT_TRACE_STATUS_ON);
985
986         /* Test 7: (Function IF) Test network trace */
987         printf("Test7f: (Function IF) Test network trace\n");
988         if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO))\r
989         {\r
990                 dlt_user_log_write_string(&context_data,"Test 7: (Function IF) Test network trace");\r
991                 dlt_user_log_write_finish(&context_data);\r
992     }
993
994         /* Dummy message: 16 byte header, 32 byte payload */
995         dlt_user_trace_network(&(context_function_test[6]), DLT_NW_TRACE_IPC, 16, buffer, 32, buffer);
996         dlt_user_trace_network(&(context_function_test[6]), DLT_NW_TRACE_CAN, 16, buffer, 32, buffer);
997         dlt_user_trace_network(&(context_function_test[6]), DLT_NW_TRACE_FLEXRAY, 16, buffer, 32, buffer);
998         dlt_user_trace_network(&(context_function_test[6]), DLT_NW_TRACE_MOST, 16, buffer, 32, buffer);
999
1000         /* wait 2 second before next test */\r
1001     sleep(2);
1002         if (dlt_user_log_write_start(&context_info,&context_data,DLT_LOG_INFO))\r
1003         {\r
1004                 dlt_user_log_write_string(&context_data,"Test7: (Function IF) finished");\r
1005                 dlt_user_log_write_finish(&context_data);\r
1006     }
1007
1008         dlt_set_application_ll_ts_limit(DLT_LOG_DEFAULT, DLT_TRACE_STATUS_DEFAULT);
1009         sleep(2);\r
1010
1011         return 0;
1012 }
1013
1014 int test_injection_macro_callback(uint32_t service_id, void *data, uint32_t length)\r
1015 {\r
1016         char text[1024];
1017
1018         memset(text,0,1024);\r
1019 \r
1020         snprintf(text,1024,"Injection received (macro IF). ID: 0x%.4x, Length: %d",service_id,length);
1021         printf("%s \n", text);
1022
1023         memset(text,0,1024);
1024 \r
1025         if (length>0)\r
1026         {\r
1027                 dlt_print_mixed_string(text,1024,data,length,0);\r
1028                 printf("%s \n", text);\r
1029         }\r
1030 \r
1031         return 0;\r
1032 }
1033
1034 int test_injection_function_callback(uint32_t service_id, void *data, uint32_t length)
1035 {
1036         char text[1024];
1037
1038         memset(text,0,1024);\r
1039 \r
1040         snprintf(text,1024,"Injection received (function IF). ID: 0x%.4x, Length: %d",service_id,length);
1041         printf("%s \n", text);
1042
1043         memset(text,0,1024);
1044 \r
1045         if (length>0)\r
1046         {\r
1047                 dlt_print_mixed_string(text,1024,data,length,0);\r
1048                 printf("%s \n", text);\r
1049         }
1050
1051         return 0;
1052 }
1053
1054