Initial Import
[profile/ivi/automotive-dlt.git] / src / tests / dlt-test-client.c
1 /*
2  * Dlt Test Client - Diagnostic Log and Trace
3  * @licence app begin@
4  *
5  * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de>
6  * 
7  * This program is free software; you can redistribute it and/or modify it under the terms of the 
8  * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even 
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General 
11  * Public License, version 2.1, for more details.
12  * 
13  * You should have received a copy of the GNU Lesser General Public License, version 2.1, along 
14  * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
15  * 
16  * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may 
17  * also be applicable to programs even in cases in which the program is not a library in the technical sense.
18  * 
19  * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may 
20  * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to 
21  * license your linked modules under the GNU Lesser General Public License, version 2.1, you 
22  * may use the program under the following exception.
23  * 
24  * As a special exception, the copyright holders of DLT give you permission to combine DLT 
25  * with software programs or libraries that are released under any license unless such a combination is not
26  * permitted by the license of such a software program or library. You may copy and distribute such a 
27  * system following the terms of the GNU Lesser General Public License, version 2.1, including this
28  * special exception, for DLT and the licenses of the other code concerned.
29  * 
30  * Note that people who make modified versions of DLT are not obligated to grant this special exception 
31  * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, 
32  * version 2.1, gives permission to release a modified version without this exception; this exception 
33  * also makes it possible to release a modified version which carries forward this exception.
34  *
35  * @licence end@
36  */
37
38
39 /*******************************************************************************
40 **                                                                            **
41 **  SRC-MODULE: dlt-test-client.c                                             **
42 **                                                                            **
43 **  TARGET    : linux                                                         **
44 **                                                                            **
45 **  PROJECT   : DLT                                                           **
46 **                                                                            **
47 **  AUTHOR    : Alexander Wenzel Alexander.AW.Wenzel@bmw.de                   **
48 **              Markus Klein                                                  **
49 **                                                                            **
50 **  PURPOSE   :                                                               **
51 **                                                                            **
52 **  REMARKS   :                                                               **
53 **                                                                            **
54 **  PLATFORM DEPENDANT [yes/no]: yes                                          **
55 **                                                                            **
56 **  TO BE CHANGED BY USER [yes/no]: no                                        **
57 **                                                                            **
58 *******************************************************************************/
59
60 /*******************************************************************************
61 **                      Author Identity                                       **
62 ********************************************************************************
63 **                                                                            **
64 ** Initials     Name                       Company                            **
65 ** --------     -------------------------  ---------------------------------- **
66 **  aw          Alexander Wenzel           BMW                                **
67 **  mk          Markus Klein               Fraunhofer ESK                     **
68 *******************************************************************************/
69
70 /*******************************************************************************
71 **                      Revision Control History                              **
72 *******************************************************************************/
73
74 /*
75  * $LastChangedRevision: 1670 $
76  * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
77  * $LastChangedBy$
78  Initials    Date         Comment
79  aw          13.01.2010   initial
80  */
81
82 #include <ctype.h>      /* for isprint() */
83 #include <stdlib.h>     /* for atoi() */
84 #include <sys/stat.h>   /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */
85 #include <fcntl.h>      /* for open() */
86 #include <string.h>     /* for strcmp() */
87 #include <sys/uio.h>    /* for writev() */
88
89 #include "dlt_client.h"
90 #include "dlt_protocol.h"
91 #include "dlt_user.h"
92
93 #define DLT_TESTCLIENT_TEXTBUFSIZE 10024  /* Size of buffer for text output */
94 #define DLT_TESTCLIENT_ECU_ID     "ECU1"
95
96 #define DLT_TESTCLIENT_NUM_TESTS          7
97
98 /* Function prototypes */
99 int dlt_testclient_message_callback(DltMessage *message, void *data);
100
101 typedef struct
102 {
103     int aflag;
104     int sflag;
105     int xflag;
106     int mflag;
107     int vflag;
108     int yflag;
109     char *ovalue;
110     char *fvalue;
111     char *tvalue;
112     char *evalue;
113     int bvalue;
114
115     char ecuid[4];
116     int ohandle;
117
118     DltFile file;
119     DltFilter filter;
120
121     int running_test;
122
123     int test_counter_macro[DLT_TESTCLIENT_NUM_TESTS];
124     int test_counter_function[DLT_TESTCLIENT_NUM_TESTS];
125
126     int tests_passed;
127     int tests_failed;
128
129     int sock;
130 } DltTestclientData;
131
132 /**
133  * Print usage information of tool.
134  */
135 void usage()
136 {
137     char version[255];
138
139     dlt_get_version(version);
140
141     printf("Usage: dlt-test-client [options] hostname/serial_device_name\n");
142     printf("Test against received data from dlt-test-user.\n");
143     printf("%s \n", version);
144     printf("Options:\n");
145     printf("  -a            Print DLT messages; payload as ASCII\n");
146     printf("  -x            Print DLT messages; payload as hex\n");
147     printf("  -m            Print DLT messages; payload as hex and ASCII\n");
148     printf("  -s            Print DLT messages; only headers\n");
149     printf("  -v            Verbose mode\n");
150     printf("  -h            Usage\n");
151     printf("  -y            Serial device mode\n");
152     printf("  -b baudrate   Serial device baudrate (Default: 115200)\n");
153     printf("  -e ecuid      Set ECU ID (Default: ECU1)\n");
154     printf("  -o filename   Output messages in new DLT file\n");
155     printf("  -f filename   Enable filtering of messages\n");
156 }
157
158 /**
159  * Main function of tool.
160  */
161 int main(int argc, char* argv[])
162 {
163     DltClient       dltclient;
164     DltTestclientData dltdata;
165     int c,i;
166     int index;
167
168     /* Initialize dltdata */
169     dltdata.aflag = 0;
170     dltdata.sflag = 0;
171     dltdata.xflag = 0;
172     dltdata.mflag = 0;
173     dltdata.vflag = 0;
174     dltdata.yflag = 0;
175     dltdata.ovalue = 0;
176     dltdata.fvalue = 0;
177     dltdata.evalue = 0;
178     dltdata.bvalue = 0;
179     dltdata.ohandle=-1;
180
181     dltdata.running_test = 0;
182
183     for (i=0;i<DLT_TESTCLIENT_NUM_TESTS;i++)
184     {
185         dltdata.test_counter_macro[i]=0;
186         dltdata.test_counter_function[i]=0;
187     }
188
189     dltdata.tests_passed = 0;
190     dltdata.tests_failed = 0;
191
192     dltdata.sock = -1;
193
194     /* Fetch command line arguments */
195     opterr = 0;
196
197     while ((c = getopt (argc, argv, "vashyxmf:o:e:b:")) != -1)
198     {
199         switch (c)
200         {
201         case 'v':
202         {
203             dltdata.vflag = 1;
204             break;
205         }
206         case 'a':
207         {
208             dltdata.aflag = 1;
209             break;
210         }
211         case 's':
212         {
213             dltdata.sflag = 1;
214             break;
215         }
216         case 'x':
217         {
218             dltdata.xflag = 1;
219             break;
220         }
221         case 'm':
222         {
223             dltdata.mflag = 1;
224             break;
225         }
226         case 'h':
227         {
228             usage();
229             return -1;
230         }
231         case 'y':
232         {
233             dltdata.yflag = 1;
234             break;
235         }
236         case 'f':
237         {
238             dltdata.fvalue = optarg;
239             break;
240         }
241         case 'o':
242         {
243             dltdata.ovalue = optarg;
244             break;
245         }
246         case 'e':
247         {
248             dltdata.evalue = optarg;
249             break;
250         }
251         case 'b':
252         {
253             dltdata.bvalue = atoi(optarg);
254             break;
255         }
256         case '?':
257         {
258             if (optopt == 'o' || optopt == 'f' || optopt == 't')
259             {
260                 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
261             }
262             else if (isprint (optopt))
263             {
264                 fprintf (stderr, "Unknown option `-%c'.\n", optopt);
265             }
266             else
267             {
268                 fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt);
269             }
270             /* unknown or wrong option used, show usage information and terminate */
271             usage();
272             return -1;
273         }
274         default:
275         {
276             abort ();
277         }
278         }
279     }
280
281     /* Initialize DLT Client */
282     dlt_client_init(&dltclient, dltdata.vflag);
283
284     /* Register callback to be called when message was received */
285     dlt_client_register_message_callback(dlt_testclient_message_callback);
286
287     /* Setup DLT Client structure */
288     dltclient.serial_mode = dltdata.yflag;
289
290     if (dltclient.serial_mode==0)
291     {
292         for (index = optind; index < argc; index++)
293         {
294             dltclient.servIP = argv[index];
295         }
296
297         if (dltclient.servIP == 0)
298         {
299             /* no hostname selected, show usage and terminate */
300             fprintf(stderr,"ERROR: No hostname selected\n");
301             usage();
302             dlt_client_cleanup(&dltclient,dltdata.vflag);
303             return -1;
304         }
305     }
306     else
307     {
308         for (index = optind; index < argc; index++)
309         {
310             dltclient.serialDevice = argv[index];
311         }
312
313         if (dltclient.serialDevice == 0)
314         {
315             /* no serial device name selected, show usage and terminate */
316             fprintf(stderr,"ERROR: No serial device name specified\n");
317             usage();
318             return -1;
319         }
320
321                 dlt_client_setbaudrate(&dltclient,dltdata.bvalue);
322     }
323
324     /* initialise structure to use DLT file */
325     dlt_file_init(&(dltdata.file),dltdata.vflag);
326
327     /* first parse filter file if filter parameter is used */
328     dlt_filter_init(&(dltdata.filter),dltdata.vflag);
329
330     if (dltdata.fvalue)
331     {
332         if (dlt_filter_load(&(dltdata.filter),dltdata.fvalue,dltdata.vflag)<0)
333         {
334             dlt_file_free(&(dltdata.file),dltdata.vflag);
335             return -1;
336         }
337
338         dlt_file_set_filter(&(dltdata.file),&(dltdata.filter),dltdata.vflag);
339     }
340
341     /* open DLT output file */
342     if (dltdata.ovalue)
343     {
344         dltdata.ohandle = open(dltdata.ovalue,O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */
345
346         if (dltdata.ohandle == -1)
347         {
348             dlt_file_free(&(dltdata.file),dltdata.vflag);
349             fprintf(stderr,"ERROR: Output file %s cannot be opened!\n",dltdata.ovalue);
350             return -1;
351         }
352     }
353
354     if (dltdata.evalue)
355     {
356         dlt_set_id(dltdata.ecuid,dltdata.evalue);
357     }
358     else
359     {
360         dlt_set_id(dltdata.ecuid,DLT_TESTCLIENT_ECU_ID);
361     }
362
363     /* Connect to TCP socket or open serial device */
364     if (dlt_client_connect(&dltclient, dltdata.vflag)!=-1)
365     {
366         dltdata.sock = dltclient.sock;
367
368         /* Dlt Client Main Loop */
369         dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag);
370
371         /* Dlt Client Cleanup */
372         dlt_client_cleanup(&dltclient,dltdata.vflag);
373     }
374
375     /* dlt-receive cleanup */
376     if (dltdata.ovalue)
377     {
378         close(dltdata.ohandle);
379     }
380
381     dlt_file_free(&(dltdata.file),dltdata.vflag);
382
383     dlt_filter_free(&(dltdata.filter),dltdata.vflag);
384
385     return 0;
386 }
387
388 int dlt_testclient_message_callback(DltMessage *message, void *data)
389 {
390     static char text[DLT_TESTCLIENT_TEXTBUFSIZE];
391     int mtin;
392     DltTestclientData *dltdata;
393
394         uint32_t type_info, type_info_tmp;
395         int16_t length,length_tmp; /* the macro can set this variable to -1 */
396         uint8_t *ptr;
397         int32_t datalength;
398
399         uint32_t id,id_tmp;
400         int slen;
401         int tc_old;
402
403         struct iovec iov[2];
404         int bytes_written;
405
406     if ((message==0) || (data==0))
407     {
408         return -1;
409     }
410
411     dltdata = (DltTestclientData*)data;
412
413     /* prepare storage header */
414     if (DLT_IS_HTYP_WEID(message->standardheader->htyp))
415     {
416         dlt_set_storageheader(message->storageheader,message->headerextra.ecu);
417     }
418     else
419     {
420         dlt_set_storageheader(message->storageheader,dltdata->ecuid);
421     }
422
423     if ((dltdata->fvalue==0) || (dltdata->fvalue && dlt_message_filter_check(message,&(dltdata->filter),dltdata->vflag)==1))
424     {
425
426         dlt_message_header(message,text,sizeof(text),dltdata->vflag);
427         if (dltdata->aflag)
428         {
429             printf("%s ",text);
430         }
431         dlt_message_payload(message,text,sizeof(text),DLT_OUTPUT_ASCII,dltdata->vflag);
432         if (dltdata->aflag)
433         {
434             printf("[%s]\n",text);
435         }
436
437         if (strcmp(text,"Tests starting")==0)
438         {
439             printf("Tests starting\n");
440         }
441
442         /* check test 1m */
443         if (strcmp(text,"Test1: (Macro IF) Test all log levels")==0)
444         {
445             printf("Test1m: (Macro IF) Test all log levels\n");
446             dltdata->running_test = 1;
447             dltdata->test_counter_macro[0] = 0;
448         }
449         else if (strcmp(text,"Test1: (Macro IF) finished")==0)
450         {
451             /* >=4, as "info" is default log level */
452             if (dltdata->test_counter_macro[0]>=4)
453             {
454                 printf("Test1m PASSED\n");
455                 dltdata->tests_passed++;
456             }
457             else
458             {
459                 printf("Test1m FAILED\n");
460                 dltdata->tests_failed++;
461             }
462             dltdata->running_test = 0;
463         }
464         else if (dltdata->running_test==1)
465         {
466             if (DLT_IS_HTYP_UEH(message->standardheader->htyp))
467             {
468                 if ((DLT_GET_MSIN_MSTP(message->extendedheader->msin))==DLT_TYPE_LOG)
469                 {
470                     mtin=DLT_GET_MSIN_MTIN(message->extendedheader->msin);
471
472                     if (mtin==DLT_LOG_FATAL)
473                     {
474                         dltdata->test_counter_macro[0]++;
475                     }
476                     if (mtin==DLT_LOG_ERROR)
477                     {
478                         dltdata->test_counter_macro[0]++;
479                     }
480                     if (mtin==DLT_LOG_WARN)
481                     {
482                         dltdata->test_counter_macro[0]++;
483                     }
484                     if (mtin==DLT_LOG_INFO)
485                     {
486                         dltdata->test_counter_macro[0]++;
487                     }
488                     if (mtin==DLT_LOG_DEBUG)
489                     {
490                         dltdata->test_counter_macro[0]++;
491                     }
492                     if (mtin==DLT_LOG_VERBOSE)
493                     {
494                         dltdata->test_counter_macro[0]++;
495                     }
496                 }
497             }
498         }
499
500         /* check test 2m */
501         if (strcmp(text,"Test2: (Macro IF) Test all variable types (verbose)")==0)
502         {
503             printf("Test2m: (Macro IF) Test all variable types (verbose)\n");
504             dltdata->running_test = 2;
505             dltdata->test_counter_macro[1] = 0;
506         }
507         else if (strcmp(text,"Test2: (Macro IF) finished")==0)
508         {
509             if (dltdata->test_counter_macro[1]==14)
510             {
511                 printf("Test2m PASSED\n");
512                 dltdata->tests_passed++;
513             }
514             else
515             {
516                 printf("Test2m FAILED\n");
517                 dltdata->tests_failed++;
518             }
519             dltdata->running_test = 0;
520         }
521         else if (dltdata->running_test==2)
522         {
523             /* Verbose */
524             if (!(DLT_MSG_IS_NONVERBOSE(message)))
525             {
526                 type_info=0;
527                 type_info_tmp=0;
528                 length=0;  /* the macro can set this variable to -1 */
529                 length_tmp=0;
530                 ptr = message->databuffer;
531                 datalength = message->datasize;
532
533                 /* Log message */
534                 if ((DLT_GET_MSIN_MSTP(message->extendedheader->msin))==DLT_TYPE_LOG)
535                 {
536                     if (message->extendedheader->noar>=2)
537                     {
538                         /* get type of first argument: must be string */
539                         DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
540                         type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp);
541
542                         if (type_info & DLT_TYPE_INFO_STRG)
543                         {
544                             /* skip string */
545                             DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
546                             length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
547
548                             if (length>=0)
549                             {
550                                 ptr+=length;
551                                 datalength-=length;
552
553                                 /* read type of second argument: must be raw */
554                                 DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
555                                 type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp);
556
557                                 if (type_info & DLT_TYPE_INFO_BOOL)
558                                 {
559                                     if (datalength==sizeof(uint8_t))
560                                     {
561                                         dltdata->test_counter_macro[1]++;
562                                     }
563                                 }
564                                 else if (type_info & DLT_TYPE_INFO_SINT)
565                                 {
566                                     switch (type_info & DLT_TYPE_INFO_TYLE)
567                                     {
568                                     case DLT_TYLE_8BIT:
569                                     {
570                                         if (datalength==sizeof(int8_t))
571                                         {
572                                             dltdata->test_counter_macro[1]++;
573                                         }
574                                         break;
575                                     }
576                                     case DLT_TYLE_16BIT:
577                                     {
578                                         if (datalength==sizeof(int16_t))
579                                         {
580                                             dltdata->test_counter_macro[1]++;
581                                         }
582                                         break;
583                                     }
584                                     case DLT_TYLE_32BIT:
585                                     {
586                                         if (datalength==sizeof(int32_t))
587                                         {
588                                             dltdata->test_counter_macro[1]++;
589                                         }
590                                         break;
591                                     }
592                                     case DLT_TYLE_64BIT:
593                                     {
594                                         if (datalength==sizeof(int64_t))
595                                         {
596                                             dltdata->test_counter_macro[1]++;
597                                         }
598                                         break;
599                                     }
600                                     case DLT_TYLE_128BIT:
601                                     {
602                                         /* Not tested here */
603                                         break;
604                                     }
605                                     }
606                                 }
607                                 else if (type_info & DLT_TYPE_INFO_UINT)
608                                 {
609                                     switch (type_info & DLT_TYPE_INFO_TYLE)
610                                     {
611                                     case DLT_TYLE_8BIT:
612                                     {
613                                         if (datalength==sizeof(uint8_t))
614                                         {
615                                             dltdata->test_counter_macro[1]++;
616                                         }
617                                         break;
618                                     }
619                                     case DLT_TYLE_16BIT:
620                                     {
621                                         if (datalength==sizeof(uint16_t))
622                                         {
623                                             dltdata->test_counter_macro[1]++;
624                                         }
625                                         break;
626                                     }
627                                     case DLT_TYLE_32BIT:
628                                     {
629                                         if (datalength==sizeof(uint32_t))
630                                         {
631                                             dltdata->test_counter_macro[1]++;
632                                         }
633                                         break;
634                                     }
635                                     case DLT_TYLE_64BIT:
636                                     {
637                                         if (datalength==sizeof(uint64_t))
638                                         {
639                                             dltdata->test_counter_macro[1]++;
640                                         }
641                                         break;
642                                     }
643                                     case DLT_TYLE_128BIT:
644                                     {
645                                         /* Not tested here */
646                                         break;
647                                     }
648                                     }
649                                 }
650                                 else if (type_info & DLT_TYPE_INFO_FLOA)
651                                 {
652                                     switch (type_info & DLT_TYPE_INFO_TYLE)
653                                     {
654                                     case DLT_TYLE_8BIT:
655                                     {
656                                         /* Not tested here */
657                                         break;
658                                     }
659                                     case DLT_TYLE_16BIT:
660                                     {
661                                         /* Not tested here */
662                                         break;
663                                     }
664                                     case DLT_TYLE_32BIT:
665                                     {
666                                         if (datalength==(2*sizeof(float)+sizeof(uint32_t)))
667                                         {
668                                             dltdata->test_counter_macro[1]++;
669                                         }
670                                         break;
671                                     }
672                                     case DLT_TYLE_64BIT:
673                                     {
674                                         if (datalength==(2*sizeof(double)+sizeof(uint32_t)))
675                                         {
676                                             dltdata->test_counter_macro[1]++;
677                                         }
678                                         break;
679                                     }
680                                     case DLT_TYLE_128BIT:
681                                         /* Not tested here */
682                                         break;
683                                     }
684                                 }
685                                 else if (type_info & DLT_TYPE_INFO_RAWD)
686                                 {
687                                     /* Get length */
688                                     DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
689                                     length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
690                                     if ((length==datalength) && (length=10))
691                                     {
692                                         dltdata->test_counter_macro[1]++;
693                                     }
694                                 }
695                             }
696                         }
697                     }
698                 }
699             }
700         }
701
702         /* check test 3m */
703         if (strcmp(text,"Test3: (Macro IF) Test all variable types (non-verbose)")==0)
704         {
705             printf("Test3m: (Macro IF) Test all variable types (non-verbose)\n");
706             dltdata->running_test = 3;
707             dltdata->test_counter_macro[2]=0;
708         }
709         else if (strcmp(text,"Test3: (Macro IF) finished")==0)
710         {
711             if (dltdata->test_counter_macro[2]==14)
712             {
713                 printf("Test3m PASSED\n");
714                 dltdata->tests_passed++;
715             }
716             else
717             {
718                 printf("Test3m FAILED\n");
719                 dltdata->tests_failed++;
720             }
721             dltdata->running_test = 0;
722         }
723         else if (dltdata->running_test==3)
724         {
725             /* Nonverbose */
726             if (DLT_MSG_IS_NONVERBOSE(message))
727             {
728                 id=0;
729                 id_tmp=0;
730                 ptr = message->databuffer;
731                 datalength = message->datasize;
732                 slen=-1;
733
734                 tc_old=dltdata->test_counter_macro[2];
735
736                 /* Get message id */
737                 DLT_MSG_READ_VALUE(id_tmp,ptr,datalength,uint32_t);
738                 id=DLT_ENDIAN_GET_32(message->standardheader->htyp, id_tmp);
739
740                 /* Length of string */
741                 datalength-=sizeof(uint16_t);
742                 ptr+=sizeof(uint16_t);
743
744                 switch (id)
745                 {
746                 case  1:
747                 {
748                     slen=strlen("bool")+1;
749                     datalength-=slen;
750                     ptr+=slen;
751                     if (datalength==sizeof(uint8_t))
752                     {
753                         dltdata->test_counter_macro[2]++;
754                     }
755                     break;
756                 }
757                 case  2:
758                 {
759                     slen=strlen("int")+1;
760                     datalength-=slen;
761                     ptr+=slen;
762                     if (datalength==sizeof(int))
763                     {
764                         dltdata->test_counter_macro[2]++;
765                     }
766                     break;
767                 }
768                 case  3:
769                 {
770                     slen=strlen("int8")+1;
771                     datalength-=slen;
772                     ptr+=slen;
773                     if (datalength==sizeof(int8_t))
774                     {
775                         dltdata->test_counter_macro[2]++;
776                     }
777                     break;
778                 }
779                 case  4:
780                 {
781                     slen=strlen("int16")+1;
782                     datalength-=slen;
783                     ptr+=slen;
784                     if (datalength==sizeof(int16_t))
785                     {
786                         dltdata->test_counter_macro[2]++;
787                     }
788                     break;
789                 }
790                 case  5:
791                 {
792                     slen=strlen("int32")+1;
793                     datalength-=slen;
794                     ptr+=slen;
795                     if (datalength==sizeof(int32_t))
796                     {
797                         dltdata->test_counter_macro[2]++;
798                     }
799                     break;
800                 }
801                 case  6:
802                 {
803                     slen=strlen("int64")+1;
804                     datalength-=slen;
805                     ptr+=slen;
806                     if (datalength==sizeof(int64_t))
807                     {
808                         dltdata->test_counter_macro[2]++;
809                     }
810                     break;
811                 }
812                 case  7:
813                 {
814                     slen=strlen("uint")+1;
815                     datalength-=slen;
816                     ptr+=slen;
817                     if (datalength==sizeof(unsigned int))
818                     {
819                         dltdata->test_counter_macro[2]++;
820                     }
821                     break;
822                 }
823                 case  8:
824                 {
825                     slen=strlen("uint8")+1;
826                     datalength-=slen;
827                     ptr+=slen;
828                     if (datalength==sizeof(uint8_t))
829                     {
830                         dltdata->test_counter_macro[2]++;
831                     }
832                     break;
833                 }
834                 case  9:
835                 {
836                     slen=strlen("uint16")+1;
837                     datalength-=slen;
838                     ptr+=slen;
839                     if (datalength==sizeof(uint16_t))
840                     {
841                         dltdata->test_counter_macro[2]++;
842                     }
843                     break;
844                 }
845                 case 10:
846                 {
847                     slen=strlen("uint32")+1;
848                     datalength-=slen;
849                     ptr+=slen;
850                     if (datalength==sizeof(uint32_t))
851                     {
852                         dltdata->test_counter_macro[2]++;
853                     }
854                     break;
855                 }
856                 case 11:
857                 {
858                     slen=strlen("uint64")+1;
859                     datalength-=slen;
860                     ptr+=slen;
861                     if (datalength==sizeof(uint64_t))
862                     {
863                         dltdata->test_counter_macro[2]++;
864                     }
865                     break;
866                 }
867                 case 12:
868                 {
869                     slen=strlen("float32")+1;
870                     datalength-=slen;
871                     ptr+=slen;
872                     /* 2*, as the min and the max is transfered */
873                     if (datalength==2*sizeof(float))
874                     {
875                         dltdata->test_counter_macro[2]++;
876                     }
877                     break;
878                 }
879                 case 13:
880                 {
881                     slen=strlen("float64")+1;
882                     datalength-=slen;
883                     ptr+=slen;
884                     /* 2*, as the min and the max is transfered */
885                     if (datalength==2*sizeof(double))
886                     {
887                         dltdata->test_counter_macro[2]++;
888                     }
889                     break;
890                 }
891                 case 14:
892                 {
893                     slen=strlen("raw")+1;
894                     datalength-=slen;
895                     ptr+=slen;
896                     datalength-=sizeof(uint16_t);
897                     ptr+=sizeof(uint16_t);
898                     if (datalength==10)
899                     {
900                         dltdata->test_counter_macro[2]++;
901                     }
902                     break;
903                 }
904                 }
905
906                 if ((slen>=0) && (tc_old==dltdata->test_counter_macro[2]))
907                 {
908                     printf("ID=%d, Datalength=%d => Failed!",id,datalength);
909                 }
910             }
911         }
912
913         /* check test 4m */
914         if (strcmp(text,"Test4: (Macro IF) Test different message sizes")==0)
915         {
916             printf("Test4m: (Macro IF) Test different message sizes\n");
917             dltdata->running_test = 4;
918             dltdata->test_counter_macro[3]=0;
919         }
920         else if (strcmp(text,"Test4: (Macro IF) finished")==0)
921         {
922             if (dltdata->test_counter_macro[3]==4)
923             {
924                 printf("Test4m PASSED\n");
925                 dltdata->tests_passed++;
926             }
927             else
928             {
929                 printf("Test4m FAILED\n");
930                 dltdata->tests_failed++;
931             }
932             dltdata->running_test = 0;
933         }
934         else if (dltdata->running_test==4)
935         {
936             /* Extended header */
937             if (DLT_IS_HTYP_UEH(message->standardheader->htyp))
938             {
939                 /* Log message */
940                 if ((DLT_GET_MSIN_MSTP(message->extendedheader->msin))==DLT_TYPE_LOG)
941                 {
942                     /* Verbose */
943                     if (DLT_IS_MSIN_VERB(message->extendedheader->msin))
944                     {
945                         /* 2 arguments */
946                         if (message->extendedheader->noar==2)
947                         {
948                             /* verbose mode */
949                             type_info=0;
950                             type_info_tmp=0;
951                             length=0;
952                             length_tmp=0; /* the macro can set this variable to -1 */
953
954                             ptr = message->databuffer;
955                             datalength = message->datasize;
956
957                             /* first read the type info of the first argument: must be string */
958                             DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
959                             type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp);
960
961                             if (type_info & DLT_TYPE_INFO_STRG)
962                             {
963                                 /* skip string */
964                                 DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
965                                 length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
966
967                                 if (length>=0)
968                                 {
969                                     ptr+=length;
970                                     datalength-=length;
971
972                                     /* read type of second argument: must be raw */
973                                     DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
974                                     type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp);
975
976                                     if (type_info & DLT_TYPE_INFO_RAWD)
977                                     {
978                                         /* get length of raw data block */
979                                         DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
980                                         length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
981
982                                         if ((length>=0) && (length==datalength))
983                                         {
984                                             //printf("Raw data found in payload, length=");
985                                             //printf("%d, datalength=%d \n", length, datalength);
986                                             dltdata->test_counter_macro[3]++;
987                                         }
988                                     }
989                                 }
990                             }
991                         }
992                     }
993                 }
994             }
995         }
996
997         /* check test 5m */
998         if (strcmp(text,"Test5: (Macro IF) Test high-level API")==0)
999         {
1000             printf("Test5m: (Macro IF) Test high-level API\n");
1001             dltdata->running_test = 5;
1002             dltdata->test_counter_macro[4]=0;
1003         }
1004         else if (strcmp(text,"Test5: (Macro IF) finished")==0)
1005         {
1006             if (dltdata->test_counter_macro[4]==12)
1007             {
1008                 printf("Test5m PASSED\n");
1009                 dltdata->tests_passed++;
1010             }
1011             else
1012             {
1013                 printf("Test5m FAILED\n");
1014                 dltdata->tests_failed++;
1015             }
1016             dltdata->running_test = 0;
1017         }
1018         else if (dltdata->running_test==5)
1019         {
1020             if (strcmp(text,"Next line: DLT_LOG_INT")==0)
1021             {
1022                 dltdata->test_counter_macro[4]++;
1023             }
1024             if (strcmp(text,"-42")==0)
1025             {
1026                 dltdata->test_counter_macro[4]++;
1027             }
1028
1029             if (strcmp(text,"Next line: DLT_LOG_UINT")==0)
1030             {
1031                 dltdata->test_counter_macro[4]++;
1032             }
1033             if (strcmp(text,"42")==0)
1034             {
1035                 dltdata->test_counter_macro[4]++;
1036             }
1037
1038             if (strcmp(text,"Next line: DLT_LOG_STRING")==0)
1039             {
1040                 dltdata->test_counter_macro[4]++;
1041             }
1042             if (strcmp(text,"String output")==0)
1043             {
1044                 dltdata->test_counter_macro[4]++;
1045             }
1046
1047             if (strcmp(text,"Next line: DLT_LOG_RAW")==0)
1048             {
1049                 dltdata->test_counter_macro[4]++;
1050             }
1051             if (strcmp(text,"00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f")==0)
1052             {
1053                 dltdata->test_counter_macro[4]++;
1054             }
1055
1056             if (strcmp(text,"Next line: DLT_LOG_STRING_INT")==0)
1057             {
1058                 dltdata->test_counter_macro[4]++;
1059             }
1060             if (strcmp(text,"String output:  -42")==0)
1061             {
1062                 dltdata->test_counter_macro[4]++;
1063             }
1064
1065             if (strcmp(text,"Next line: DLT_LOG_STRING_UINT")==0)
1066             {
1067                 dltdata->test_counter_macro[4]++;
1068             }
1069             if (strcmp(text,"String output:  42")==0)
1070             {
1071                 dltdata->test_counter_macro[4]++;
1072             }
1073         }
1074
1075         /* check test 6m */
1076         if (strcmp(text,"Test 6: (Macro IF) Test local printing")==0)
1077         {
1078             printf("Test6m: (Macro IF) Test local printing\n");
1079             dltdata->running_test = 6;
1080             dltdata->test_counter_macro[5]=0;
1081         }
1082         else if (strcmp(text,"Test6: (Macro IF) finished")==0)
1083         {
1084             if (dltdata->test_counter_macro[5]==2)
1085             {
1086                 printf("Test6m PASSED\n");
1087                 dltdata->tests_passed++;
1088             }
1089             else
1090             {
1091                 printf("Test6m FAILED\n");
1092                 dltdata->tests_failed++;
1093             }
1094             dltdata->running_test = 0;
1095         }
1096         else if (dltdata->running_test==6)
1097         {
1098             dltdata->test_counter_macro[5]++;
1099         }
1100
1101         /* check test 7m */
1102         if (strcmp(text,"Test 7: (Macro IF) Test network trace")==0)
1103         {
1104             printf("Test7m: (Macro IF) Test network trace\n");
1105             dltdata->running_test = 7;
1106             dltdata->test_counter_macro[6]=0;
1107         }
1108         else if (strcmp(text,"Test7: (Macro IF) finished")==0)
1109         {
1110             if (dltdata->test_counter_macro[6]==8)
1111             {
1112                 printf("Test7m PASSED\n");
1113                 dltdata->tests_passed++;
1114             }
1115             else
1116             {
1117                 printf("Test7m FAILED\n");
1118                 dltdata->tests_failed++;
1119             }
1120             dltdata->running_test = 0;
1121         }
1122         else if (dltdata->running_test==7)
1123         {
1124             if (DLT_IS_HTYP_UEH(message->standardheader->htyp))
1125             {
1126                 if ((DLT_GET_MSIN_MSTP(message->extendedheader->msin))==DLT_TYPE_NW_TRACE)
1127                 {
1128                     /* Check message type information*/
1129                     /* Each correct message type increases the counter by 1 */
1130                     mtin=DLT_GET_MSIN_MTIN(message->extendedheader->msin);
1131
1132                     if (mtin==DLT_NW_TRACE_IPC)
1133                     {
1134                                                 dltdata->test_counter_macro[6]++;
1135                     }
1136                     if (mtin==DLT_NW_TRACE_CAN)
1137                     {
1138                         dltdata->test_counter_macro[6]++;
1139                     }
1140                     if (mtin==DLT_NW_TRACE_FLEXRAY)
1141                     {
1142                         dltdata->test_counter_macro[6]++;
1143                     }
1144                     if (mtin==DLT_NW_TRACE_MOST)
1145                     {
1146                         dltdata->test_counter_macro[6]++;
1147                     }
1148
1149                     /* Check payload, must be two arguments (2 raw data blocks) */
1150                     /* If the payload is correct, the counter is increased by 1 */
1151                     if (message->extendedheader->noar==2)
1152                     {
1153                         /* verbose mode */
1154                         type_info=0;
1155                         type_info_tmp=0;
1156                         length=0,length_tmp=0; /* the macro can set this variable to -1 */
1157
1158                         ptr = message->databuffer;
1159                         datalength = message->datasize;
1160
1161                         /* first read the type info of the first argument: must be string */
1162                         DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
1163                         type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp);
1164
1165                         if (type_info & DLT_TYPE_INFO_RAWD)
1166                         {
1167                             /* skip string */
1168                             DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
1169                             length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
1170
1171                             if (length>=0)
1172                             {
1173                                 ptr+=length;
1174                                 datalength-=length;
1175
1176                                 /* read type of second argument: must be raw */
1177                                 DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
1178                                 type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp);
1179
1180                                 if (type_info & DLT_TYPE_INFO_RAWD)
1181                                 {
1182                                     /* get length of raw data block */
1183                                     DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
1184                                     length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
1185
1186                                     if ((length>=0) && (length==datalength))
1187                                     {
1188                                         //printf("Raw data found in payload, length=");
1189                                         //printf("%d, datalength=%d \n", length, datalength);
1190                                         dltdata->test_counter_macro[6]++;
1191                                     }
1192                                 }
1193                             }
1194                         }
1195                     }
1196                 }
1197             }
1198         }
1199
1200         /* check test 1f */
1201         if (strcmp(text,"Test1: (Function IF) Test all log levels")==0)
1202         {
1203             printf("Test1f: (Function IF) Test all log levels\n");
1204             dltdata->running_test = 8;
1205             dltdata->test_counter_function[0] = 0;
1206         }
1207         else if (strcmp(text,"Test1: (Function IF) finished")==0)
1208         {
1209             /* >=4, as "info" is default log level */
1210             if (dltdata->test_counter_function[0]>=4)
1211             {
1212                 printf("Test1f PASSED\n");
1213                 dltdata->tests_passed++;
1214             }
1215             else
1216             {
1217                 printf("Test1f FAILED\n");
1218                 dltdata->tests_failed++;
1219             }
1220             dltdata->running_test = 0;
1221         }
1222         else if (dltdata->running_test==8)
1223         {
1224             if (DLT_IS_HTYP_UEH(message->standardheader->htyp))
1225             {
1226                 if ((DLT_GET_MSIN_MSTP(message->extendedheader->msin))==DLT_TYPE_LOG)
1227                 {
1228                     mtin=DLT_GET_MSIN_MTIN(message->extendedheader->msin);
1229
1230                     if (mtin==DLT_LOG_FATAL)
1231                     {
1232                         dltdata->test_counter_function[0]++;
1233                     }
1234                     if (mtin==DLT_LOG_ERROR)
1235                     {
1236                         dltdata->test_counter_function[0]++;
1237                     }
1238                     if (mtin==DLT_LOG_WARN)
1239                     {
1240                                                 dltdata->test_counter_function[0]++;
1241                     }
1242                     if (mtin==DLT_LOG_INFO)
1243                     {
1244                         dltdata->test_counter_function[0]++;
1245                     }
1246                     if (mtin==DLT_LOG_DEBUG)
1247                     {
1248                         dltdata->test_counter_function[0]++;
1249                     }
1250                     if (mtin==DLT_LOG_VERBOSE)
1251                     {
1252                         dltdata->test_counter_function[0]++;
1253                     }
1254                 }
1255             }
1256         }
1257
1258         /* check test 2f */
1259         if (strcmp(text,"Test2: (Function IF) Test all variable types (verbose)")==0)
1260         {
1261             printf("Test2f: (Function IF) Test all variable types (verbose)\n");
1262             dltdata->running_test = 9;
1263             dltdata->test_counter_function[1] = 0;
1264         }
1265         else if (strcmp(text,"Test2: (Function IF) finished")==0)
1266         {
1267             if (dltdata->test_counter_function[1]==14)
1268             {
1269                 printf("Test2f PASSED\n");
1270                 dltdata->tests_passed++;
1271             }
1272             else
1273             {
1274                 printf("Test2f FAILED\n");
1275                 dltdata->tests_failed++;
1276             }
1277             dltdata->running_test = 0;
1278         }
1279         else if (dltdata->running_test==9)
1280         {
1281             /* Verbose */
1282             if (!(DLT_MSG_IS_NONVERBOSE(message)))
1283             {
1284                 type_info=0;
1285                 type_info_tmp=0;
1286                 length=0;
1287                 length_tmp=0; /* the macro can set this variable to -1 */
1288                 ptr = message->databuffer;
1289                 datalength = message->datasize;
1290
1291                 /* Log message */
1292                 if ((DLT_GET_MSIN_MSTP(message->extendedheader->msin))==DLT_TYPE_LOG)
1293                 {
1294                     if (message->extendedheader->noar>=2)
1295                     {
1296                         /* get type of first argument: must be string */
1297                         DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
1298                         type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp);
1299
1300                         if (type_info & DLT_TYPE_INFO_STRG)
1301                         {
1302                             /* skip string */
1303                             DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
1304                             length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
1305
1306                             if (length>=0)
1307                             {
1308                                 ptr+=length;
1309                                 datalength-=length;
1310
1311                                 /* read type of second argument: must be raw */
1312                                 DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
1313                                 type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp);
1314
1315                                 if (type_info & DLT_TYPE_INFO_BOOL)
1316                                 {
1317                                     if (datalength==sizeof(uint8_t))
1318                                     {
1319                                         dltdata->test_counter_function[1]++;
1320                                     }
1321                                 }
1322                                 else if (type_info & DLT_TYPE_INFO_SINT)
1323                                 {
1324                                     switch (type_info & DLT_TYPE_INFO_TYLE)
1325                                     {
1326                                     case DLT_TYLE_8BIT:
1327                                     {
1328                                         if (datalength==sizeof(int8_t))
1329                                         {
1330                                             dltdata->test_counter_function[1]++;
1331                                         }
1332                                         break;
1333                                     }
1334                                     case DLT_TYLE_16BIT:
1335                                     {
1336                                         if (datalength==sizeof(int16_t))
1337                                         {
1338                                             dltdata->test_counter_function[1]++;
1339                                         }
1340                                         break;
1341                                     }
1342                                     case DLT_TYLE_32BIT:
1343                                     {
1344                                         if (datalength==sizeof(int32_t))
1345                                         {
1346                                             dltdata->test_counter_function[1]++;
1347                                         }
1348                                         break;
1349                                     }
1350                                     case DLT_TYLE_64BIT:
1351                                     {
1352                                         if (datalength==sizeof(int64_t))
1353                                         {
1354                                             dltdata->test_counter_function[1]++;
1355                                         }
1356                                         break;
1357                                     }
1358                                     case DLT_TYLE_128BIT:
1359                                     {
1360                                         /* Not tested here */
1361                                         break;
1362                                     }
1363                                     }
1364                                 }
1365                                 else if (type_info & DLT_TYPE_INFO_UINT)
1366                                 {
1367                                     switch (type_info & DLT_TYPE_INFO_TYLE)
1368                                     {
1369                                     case DLT_TYLE_8BIT:
1370                                     {
1371                                         if (datalength==sizeof(uint8_t))
1372                                         {
1373                                             dltdata->test_counter_function[1]++;
1374                                         }
1375                                         break;
1376                                     }
1377                                     case DLT_TYLE_16BIT:
1378                                     {
1379                                         if (datalength==sizeof(uint16_t))
1380                                         {
1381                                             dltdata->test_counter_function[1]++;
1382                                         }
1383                                         break;
1384                                     }
1385                                     case DLT_TYLE_32BIT:
1386                                     {
1387                                         if (datalength==sizeof(uint32_t))
1388                                         {
1389                                             dltdata->test_counter_function[1]++;
1390                                         }
1391                                         break;
1392                                     }
1393                                     case DLT_TYLE_64BIT:
1394                                     {
1395                                         if (datalength==sizeof(uint64_t))
1396                                         {
1397                                             dltdata->test_counter_function[1]++;
1398                                         }
1399                                         break;
1400                                     }
1401                                     case DLT_TYLE_128BIT:
1402                                     {
1403                                         /* Not tested here */
1404                                         break;
1405                                     }
1406                                     }
1407                                 }
1408                                 else if (type_info & DLT_TYPE_INFO_FLOA)
1409                                 {
1410                                     switch (type_info & DLT_TYPE_INFO_TYLE)
1411                                     {
1412                                     case DLT_TYLE_8BIT:
1413                                     {
1414                                         /* Not tested here */
1415                                         break;
1416                                     }
1417                                     case DLT_TYLE_16BIT:
1418                                     {
1419                                         /* Not tested here */
1420                                         break;
1421                                     }
1422                                     case DLT_TYLE_32BIT:
1423                                     {
1424                                         if (datalength==(2*sizeof(float)+sizeof(uint32_t)))
1425                                         {
1426                                             dltdata->test_counter_function[1]++;
1427                                         }
1428                                         break;
1429                                     }
1430                                     case DLT_TYLE_64BIT:
1431                                     {
1432                                         if (datalength==(2*sizeof(double)+sizeof(uint32_t)))
1433                                         {
1434                                             dltdata->test_counter_function[1]++;
1435                                         }
1436                                         break;
1437                                     }
1438                                     case DLT_TYLE_128BIT:
1439                                     {
1440                                         /* Not tested here */
1441                                         break;
1442                                     }
1443                                     }
1444                                 }
1445                                 else if (type_info & DLT_TYPE_INFO_RAWD)
1446                                 {
1447                                     /* Get length */
1448                                     DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
1449                                     length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
1450                                     if ((length==datalength) && (length=10))
1451                                     {
1452                                         dltdata->test_counter_function[1]++;
1453                                     }
1454                                 }
1455                             }
1456                         }
1457                     }
1458                 }
1459             }
1460         }
1461
1462         /* check test 3f */
1463         if (strcmp(text,"Test3: (Function IF) Test all variable types (non-verbose)")==0)
1464         {
1465             printf("Test3f: (Function IF) Test all variable types (non-verbose)\n");
1466             dltdata->running_test = 10;
1467             dltdata->test_counter_function[2]=0;
1468         }
1469         else if (strcmp(text,"Test3: (Function IF) finished")==0)
1470         {
1471             if (dltdata->test_counter_function[2]==14)
1472             {
1473                 printf("Test3f PASSED\n");
1474                 dltdata->tests_passed++;
1475             }
1476             else
1477             {
1478                 printf("Test3f FAILED\n");
1479                 dltdata->tests_failed++;
1480             }
1481             dltdata->running_test = 0;
1482         }
1483         else if (dltdata->running_test==10)
1484         {
1485             /* Nonverbose */
1486             if (DLT_MSG_IS_NONVERBOSE(message))
1487             {
1488                 id=0;
1489                 id_tmp=0;
1490                 ptr = message->databuffer;
1491                 datalength = message->datasize;
1492                 slen=-1;
1493
1494                 tc_old=dltdata->test_counter_function[2];
1495
1496                 /* Get message id */
1497                 DLT_MSG_READ_VALUE(id_tmp,ptr,datalength,uint32_t);
1498                 id=DLT_ENDIAN_GET_32(message->standardheader->htyp, id_tmp);
1499
1500                 /* Length of string */
1501                 datalength-=sizeof(uint16_t);
1502                 ptr+=sizeof(uint16_t);
1503
1504                 switch (id)
1505                 {
1506                 case  1:
1507                 {
1508                     slen=strlen("bool")+1;
1509                     datalength-=slen;
1510                     ptr+=slen;
1511                     if (datalength==sizeof(uint8_t))
1512                     {
1513                         dltdata->test_counter_function[2]++;
1514                     }
1515                     break;
1516                 }
1517                 case  2:
1518                 {
1519                     slen=strlen("int")+1;
1520                     datalength-=slen;
1521                     ptr+=slen;
1522                     if (datalength==sizeof(int))
1523                     {
1524                         dltdata->test_counter_function[2]++;
1525                     }
1526                     break;
1527                 }
1528                 case  3:
1529                 {
1530                     slen=strlen("int8")+1;
1531                     datalength-=slen;
1532                     ptr+=slen;
1533                     if (datalength==sizeof(int8_t))
1534                     {
1535                         dltdata->test_counter_function[2]++;
1536                     }
1537                     break;
1538                 }
1539                 case  4:
1540                 {
1541                     slen=strlen("int16")+1;
1542                     datalength-=slen;
1543                     ptr+=slen;
1544                     if (datalength==sizeof(int16_t))
1545                     {
1546                         dltdata->test_counter_function[2]++;
1547                     }
1548                     break;
1549                 }
1550                 case  5:
1551                 {
1552                     slen=strlen("int32")+1;
1553                     datalength-=slen;
1554                     ptr+=slen;
1555                     if (datalength==sizeof(int32_t))
1556                     {
1557                         dltdata->test_counter_function[2]++;
1558                     }
1559                     break;
1560                 }
1561                 case  6:
1562                 {
1563                     slen=strlen("int64")+1;
1564                     datalength-=slen;
1565                     ptr+=slen;
1566                     if (datalength==sizeof(int64_t))
1567                     {
1568                         dltdata->test_counter_function[2]++;
1569                     }
1570                     break;
1571                 }
1572                 case  7:
1573                 {
1574                     slen=strlen("uint")+1;
1575                     datalength-=slen;
1576                     ptr+=slen;
1577                     if (datalength==sizeof(unsigned int))
1578                     {
1579                         dltdata->test_counter_function[2]++;
1580                     }
1581                     break;
1582                 }
1583                 case  8:
1584                 {
1585                     slen=strlen("uint8")+1;
1586                     datalength-=slen;
1587                     ptr+=slen;
1588                     if (datalength==sizeof(uint8_t))
1589                     {
1590                         dltdata->test_counter_function[2]++;
1591                     }
1592                     break;
1593                 }
1594                 case  9:
1595                 {
1596                     slen=strlen("uint16")+1;
1597                     datalength-=slen;
1598                     ptr+=slen;
1599                     if (datalength==sizeof(uint16_t))
1600                     {
1601                         dltdata->test_counter_function[2]++;
1602                     }
1603                     break;
1604                 }
1605                 case 10:
1606                 {
1607                     slen=strlen("uint32")+1;
1608                     datalength-=slen;
1609                     ptr+=slen;
1610                     if (datalength==sizeof(uint32_t))
1611                     {
1612                         dltdata->test_counter_function[2]++;
1613                     }
1614                     break;
1615                 }
1616                 case 11:
1617                 {
1618                     slen=strlen("uint64")+1;
1619                     datalength-=slen;
1620                     ptr+=slen;
1621                     if (datalength==sizeof(uint64_t))
1622                     {
1623                         dltdata->test_counter_function[2]++;
1624                     }
1625                     break;
1626                 }
1627                 case 12:
1628                 {
1629                     slen=strlen("float32")+1;
1630                     datalength-=slen;
1631                     ptr+=slen;
1632                     /* 2*, as the min and the max is transfered */
1633                     if (datalength==2*sizeof(float))
1634                     {
1635                         dltdata->test_counter_function[2]++;
1636                     }
1637                     break;
1638                 }
1639                 case 13:
1640                 {
1641                     slen=strlen("float64")+1;
1642                     datalength-=slen;
1643                     ptr+=slen;
1644                     /* 2*, as the min and the max is transfered */
1645                     if (datalength==2*sizeof(double))
1646                     {
1647                         dltdata->test_counter_function[2]++;
1648                     }
1649                     break;
1650                 }
1651                 case 14:
1652                 {
1653                     slen=strlen("raw")+1;
1654                     datalength-=slen;
1655                     ptr+=slen;
1656                     datalength-=sizeof(uint16_t);
1657                     ptr+=sizeof(uint16_t);
1658                     if (datalength==10)
1659                     {
1660                         dltdata->test_counter_function[2]++;
1661                     }
1662                     break;
1663                 }
1664                 }
1665
1666                 if ((slen>=0) && (tc_old==dltdata->test_counter_function[2]))
1667                 {
1668                     printf("ID=%d, Datalength=%d => Failed!",id,datalength);
1669                 }
1670             }
1671         }
1672
1673         /* check test 4f */
1674         if (strcmp(text,"Test4: (Function IF) Test different message sizes")==0)
1675         {
1676             printf("Test4f: (Function IF) Test different message sizes\n");
1677             dltdata->running_test = 11;
1678             dltdata->test_counter_function[3]=0;
1679         }
1680         else if (strcmp(text,"Test4: (Function IF) finished")==0)
1681         {
1682             if (dltdata->test_counter_function[3]==4)
1683             {
1684                 printf("Test4f PASSED\n");
1685                 dltdata->tests_passed++;
1686             }
1687             else
1688             {
1689                 printf("Test4f FAILED\n");
1690                 dltdata->tests_failed++;
1691             }
1692             dltdata->running_test = 0;
1693         }
1694         else if (dltdata->running_test==11)
1695         {
1696             /* Extended header */
1697             if (DLT_IS_HTYP_UEH(message->standardheader->htyp))
1698             {
1699                 /* Log message */
1700                 if ((DLT_GET_MSIN_MSTP(message->extendedheader->msin))==DLT_TYPE_LOG)
1701                 {
1702                     /* Verbose */
1703                     if (DLT_IS_MSIN_VERB(message->extendedheader->msin))
1704                     {
1705                         /* 2 arguments */
1706                         if (message->extendedheader->noar==2)
1707                         {
1708                             /* verbose mode */
1709                             type_info=0;
1710                             type_info_tmp=0;
1711                             length=0;
1712                             length_tmp=0; /* the macro can set this variable to -1 */
1713
1714                             ptr = message->databuffer;
1715                             datalength = message->datasize;
1716
1717                             /* first read the type info of the first argument: should be string */
1718                             DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
1719                             type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp);
1720
1721                             if (type_info & DLT_TYPE_INFO_STRG)
1722                             {
1723                                 /* skip string */
1724                                 DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
1725                                 length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
1726
1727                                 if (length>=0)
1728                                 {
1729                                     ptr+=length;
1730                                     datalength-=length;
1731
1732                                     /* read type of second argument: should be raw */
1733                                     DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
1734                                     type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp);
1735
1736                                     if (type_info & DLT_TYPE_INFO_RAWD)
1737                                     {
1738                                         /* get length of raw data block */
1739                                         DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
1740                                         length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
1741
1742                                         if ((length>=0) && (length==datalength))
1743                                         {
1744                                             //printf("Raw data found in payload, length=");
1745                                             //printf("%d, datalength=%d \n", length, datalength);
1746                                             dltdata->test_counter_function[3]++;
1747                                         }
1748                                     }
1749                                 }
1750                             }
1751                         }
1752                     }
1753                 }
1754             }
1755         }
1756
1757         /* check test 5f */
1758         if (strcmp(text,"Test5: (Function IF) Test high-level API")==0)
1759         {
1760             printf("Test5f: (Function IF) Test high-level API\n");
1761             dltdata->running_test = 12;
1762             dltdata->test_counter_function[4]=0;
1763         }
1764         else if (strcmp(text,"Test5: (Function IF) finished")==0)
1765         {
1766             if (dltdata->test_counter_function[4]==12)
1767             {
1768                 printf("Test5f PASSED\n");
1769                 dltdata->tests_passed++;
1770             }
1771             else
1772             {
1773                 printf("Test5f FAILED\n");
1774                 dltdata->tests_failed++;
1775             }
1776             dltdata->running_test = 0;
1777         }
1778         else if (dltdata->running_test==12)
1779         {
1780             if (strcmp(text,"Next line: dlt_log_int()")==0)
1781             {
1782                 dltdata->test_counter_function[4]++;
1783             }
1784             if (strcmp(text,"-42")==0)
1785             {
1786                 dltdata->test_counter_function[4]++;
1787             }
1788
1789             if (strcmp(text,"Next line: dlt_log_uint()")==0)
1790             {
1791                 dltdata->test_counter_function[4]++;
1792             }
1793             if (strcmp(text,"42")==0)
1794             {
1795                 dltdata->test_counter_function[4]++;
1796             }
1797
1798             if (strcmp(text,"Next line: dlt_log_string()")==0)
1799             {
1800                 dltdata->test_counter_function[4]++;
1801             }
1802             if (strcmp(text,"String output")==0)
1803             {
1804                 dltdata->test_counter_function[4]++;
1805             }
1806
1807             if (strcmp(text,"Next line: dlt_log_raw()")==0)
1808             {
1809                 dltdata->test_counter_function[4]++;
1810             }
1811             if (strcmp(text,"00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f")==0)
1812             {
1813                 dltdata->test_counter_function[4]++;
1814             }
1815
1816             if (strcmp(text,"Next line: dlt_log_string_int()")==0)
1817             {
1818                 dltdata->test_counter_function[4]++;
1819             }
1820             if (strcmp(text,"String output:  -42")==0)
1821             {
1822                 dltdata->test_counter_function[4]++;
1823             }
1824
1825             if (strcmp(text,"Next line: dlt_log_string_uint()")==0)
1826             {
1827                 dltdata->test_counter_function[4]++;
1828             }
1829             if (strcmp(text,"String output:  42")==0)
1830             {
1831                 dltdata->test_counter_function[4]++;
1832             }
1833         }
1834
1835         /* check test 6f */
1836         if (strcmp(text,"Test 6: (Function IF) Test local printing")==0)
1837         {
1838             printf("Test6f: (Function IF) Test local printing\n");
1839             dltdata->running_test = 13;
1840             dltdata->test_counter_function[5]=0;
1841         }
1842         else if (strcmp(text,"Test6: (Function IF) finished")==0)
1843         {
1844             if (dltdata->test_counter_function[5]==2)
1845             {
1846                 printf("Test6f PASSED\n");
1847                 dltdata->tests_passed++;
1848             }
1849             else
1850             {
1851                 printf("Test6f FAILED\n");
1852                 dltdata->tests_failed++;
1853             }
1854             dltdata->running_test = 0;
1855         }
1856         else if (dltdata->running_test==13)
1857         {
1858             dltdata->test_counter_function[5]++;
1859         }
1860
1861         /* check test 7f */
1862         if (strcmp(text,"Test 7: (Function IF) Test network trace")==0)
1863         {
1864             printf("Test7f: (Function IF) Test network trace\n");
1865             dltdata->running_test = 14;
1866             dltdata->test_counter_function[6]=0;
1867         }
1868         else if (strcmp(text,"Test7: (Function IF) finished")==0)
1869         {
1870             if (dltdata->test_counter_function[6]==8)
1871             {
1872                 printf("Test7f PASSED\n");
1873                 dltdata->tests_passed++;
1874             }
1875             else
1876             {
1877                 printf("Test7f FAILED\n");
1878                 dltdata->tests_failed++;
1879             }
1880             dltdata->running_test = 0;
1881         }
1882         else if (dltdata->running_test==14)
1883         {
1884             if (DLT_IS_HTYP_UEH(message->standardheader->htyp))
1885             {
1886                 if ((DLT_GET_MSIN_MSTP(message->extendedheader->msin))==DLT_TYPE_NW_TRACE)
1887                 {
1888                     /* Check message type information*/
1889                     /* Each correct message type increases the counter by 1 */
1890                     mtin=DLT_GET_MSIN_MTIN(message->extendedheader->msin);
1891
1892                     if (mtin==DLT_NW_TRACE_IPC)
1893                     {
1894                                                 dltdata->test_counter_function[6]++;
1895                     }
1896                     if (mtin==DLT_NW_TRACE_CAN)
1897                     {
1898                                                 dltdata->test_counter_function[6]++;
1899                     }
1900                     if (mtin==DLT_NW_TRACE_FLEXRAY)
1901                     {
1902                         dltdata->test_counter_function[6]++;
1903                     }
1904                     if (mtin==DLT_NW_TRACE_MOST)
1905                     {
1906                         dltdata->test_counter_function[6]++;
1907                     }
1908
1909                     /* Check payload, must be two arguments (2 raw data blocks) */
1910                     /* If the payload is correct, the counter is increased by 1 */
1911                     if (message->extendedheader->noar==2)
1912                     {
1913                         /* verbose mode */
1914                         type_info=0;
1915                         type_info_tmp=0;
1916                         length=0;
1917                         length_tmp=0; /* the macro can set this variable to -1 */
1918
1919                         ptr = message->databuffer;
1920                         datalength = message->datasize;
1921
1922                         /* first read the type info of the first argument: should be string */
1923                         DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
1924                         type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp);
1925
1926                         if (type_info & DLT_TYPE_INFO_RAWD)
1927                         {
1928                             /* skip string */
1929                             DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
1930                             length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
1931
1932                             if (length>=0)
1933                             {
1934                                 ptr+=length;
1935                                 datalength-=length;
1936
1937                                 /* read type of second argument: should be raw */
1938                                 DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
1939                                 type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp);
1940
1941                                 if (type_info & DLT_TYPE_INFO_RAWD)
1942                                 {
1943                                     /* get length of raw data block */
1944                                     DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t);
1945                                     length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp);
1946
1947                                     if ((length>=0) && (length==datalength))
1948                                     {
1949                                         //printf("Raw data found in payload, length=");
1950                                         //printf("%d, datalength=%d \n", length, datalength);
1951                                         dltdata->test_counter_function[6]++;
1952                                     }
1953                                 }
1954                             }
1955                         }
1956                     }
1957                 }
1958             }
1959         }
1960
1961         if (strcmp(text,"Tests finished")==0)
1962         {
1963             printf("Tests finished\n");
1964             dltdata->running_test = 1;
1965
1966             printf("%d tests passed\n",dltdata->tests_passed);
1967             printf("%d tests failed\n",dltdata->tests_failed);
1968
1969             if (dltdata->sock!=-1)
1970             {
1971                 close(dltdata->sock);
1972             }
1973
1974             return 0;
1975         }
1976
1977         /* if no filter set or filter is matching display message */
1978         if (dltdata->xflag)
1979         {
1980             dlt_message_print_hex(message,text,DLT_TESTCLIENT_TEXTBUFSIZE,dltdata->vflag);
1981         }
1982         else if (dltdata->mflag)
1983         {
1984             dlt_message_print_mixed_plain(message,text,DLT_TESTCLIENT_TEXTBUFSIZE,dltdata->vflag);
1985         }
1986         else if (dltdata->sflag)
1987         {
1988             dlt_message_print_header(message,text,sizeof(text),dltdata->vflag);
1989         }
1990
1991         /* if file output enabled write message */
1992         if (dltdata->ovalue)
1993         {
1994             iov[0].iov_base = message->headerbuffer;
1995             iov[0].iov_len = message->headersize;
1996             iov[1].iov_base = message->databuffer;
1997             iov[1].iov_len = message->datasize;
1998
1999             bytes_written = writev(dltdata->ohandle, iov, 2);
2000         }
2001     }
2002
2003     return 0;
2004 }