82 #define DLT_TESTCLIENT_TEXTBUFSIZE 10024 83 #define DLT_TESTCLIENT_ECU_ID "ECU1" 85 #define DLT_TESTCLIENT_NUM_TESTS 9 132 printf(
"Usage: dlt-test-client [options] hostname/serial_device_name\n");
133 printf(
"Test against received data from dlt-test-user.\n");
134 printf(
"%s \n", version);
135 printf(
"Options:\n");
136 printf(
" -a Print DLT messages; payload as ASCII\n");
137 printf(
" -x Print DLT messages; payload as hex\n");
138 printf(
" -m Print DLT messages; payload as hex and ASCII\n");
139 printf(
" -s Print DLT messages; only headers\n");
140 printf(
" -v Verbose mode\n");
141 printf(
" -h Usage\n");
142 printf(
" -y Serial device mode\n");
143 printf(
" -b baudrate Serial device baudrate (Default: 115200)\n");
144 printf(
" -e ecuid Set ECU ID (Default: ECU1)\n");
145 printf(
" -o filename Output messages in new DLT file\n");
146 printf(
" -f filename Enable filtering of messages\n");
152 int main(
int argc,
char* argv[])
188 while ((c = getopt (argc, argv,
"vashyxmf:o:e:b:")) != -1)
244 dltdata.
bvalue = atoi(optarg);
249 if (optopt ==
'o' || optopt ==
'f' || optopt ==
't')
251 fprintf (stderr,
"Option -%c requires an argument.\n", optopt);
253 else if (isprint (optopt))
255 fprintf (stderr,
"Unknown option `-%c'.\n", optopt);
259 fprintf (stderr,
"Unknown option character `\\x%x'.\n",optopt);
282 if (dltclient.
mode==0)
284 for (index = optind; index < argc; index++)
288 fprintf(stderr,
"set server ip didn't succeed\n");
293 if (dltclient.
servIP == 0)
296 fprintf(stderr,
"ERROR: No hostname selected\n");
304 for (index = optind; index < argc; index++)
308 fprintf(stderr,
"set serial device didn't succeed\n");
316 fprintf(stderr,
"ERROR: No serial device name specified\n");
344 dltdata.
ohandle = open(dltdata.
ovalue,O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
349 fprintf(stderr,
"ERROR: Output file %s cannot be opened!\n",dltdata.
ovalue);
394 uint32_t type_info, type_info_tmp;
395 int16_t length,length_tmp;
396 uint32_t length_tmp32 = 0;
407 if ((message==0) || (data==0))
435 printf(
"[%s]\n",text);
438 if (strcmp(text,
"Tests starting")==0)
440 printf(
"Tests starting\n");
444 if (strcmp(text,
"Test1: (Macro IF) Test all log levels")==0)
446 printf(
"Test1m: (Macro IF) Test all log levels\n");
450 else if (strcmp(text,
"Test1: (Macro IF) finished")==0)
455 printf(
"Test1m PASSED\n");
460 printf(
"Test1m FAILED\n");
502 if (strcmp(text,
"Test2: (Macro IF) Test all variable types (verbose)")==0)
504 printf(
"Test2m: (Macro IF) Test all variable types (verbose)\n");
508 else if (strcmp(text,
"Test2: (Macro IF) finished")==0)
512 printf(
"Test2m PASSED\n");
517 printf(
"Test2m FAILED\n");
560 if (datalength==(
sizeof(uint16_t)+strlen(
"Hello world")+1))
565 else if ((type_info & DLT_TYPE_INFO_STRG) && ((type_info & DLT_TYPE_INFO_SCOD) ==
DLT_SCOD_UTF8))
567 if (datalength==(
sizeof(uint16_t)+strlen(
"Hello world")+1))
574 if (datalength==
sizeof(uint8_t))
585 if (datalength==
sizeof(int8_t))
593 if (datalength==
sizeof(int16_t))
601 if (datalength==
sizeof(int32_t))
609 if (datalength==
sizeof(int64_t))
628 if (datalength==
sizeof(uint8_t))
636 if (datalength==
sizeof(uint16_t))
644 if (datalength==
sizeof(uint32_t))
652 if (datalength==
sizeof(uint64_t))
681 if (datalength==(2*
sizeof(
float)+
sizeof(uint32_t)))
689 if (datalength==(2*
sizeof(
double)+
sizeof(uint32_t)))
705 if ((length==datalength) && (10 == length))
718 if (strcmp(text,
"Test3: (Macro IF) Test all variable types (non-verbose)")==0)
720 printf(
"Test3m: (Macro IF) Test all variable types (non-verbose)\n");
724 else if (strcmp(text,
"Test3: (Macro IF) finished")==0)
728 printf(
"Test3m PASSED\n");
733 printf(
"Test3m FAILED\n");
756 datalength-=
sizeof(uint16_t);
757 ptr+=
sizeof(uint16_t);
763 slen=strlen(
"string")+1;
766 if (datalength==
sizeof(uint16_t)+strlen(
"Hello world")+1)
774 slen=strlen(
"utf8")+1;
777 if (datalength==
sizeof(uint16_t)+strlen(
"Hello world")+1)
785 slen=strlen(
"bool")+1;
788 if (datalength==
sizeof(uint8_t))
796 slen=strlen(
"int")+1;
799 if (datalength==
sizeof(
int))
807 slen=strlen(
"int8")+1;
810 if (datalength==
sizeof(int8_t))
818 slen=strlen(
"int16")+1;
821 if (datalength==
sizeof(int16_t))
829 slen=strlen(
"int32")+1;
832 if (datalength==
sizeof(int32_t))
840 slen=strlen(
"int64")+1;
843 if (datalength==
sizeof(int64_t))
851 slen=strlen(
"uint")+1;
854 if (datalength==
sizeof(
unsigned int))
862 slen=strlen(
"uint8")+1;
865 if (datalength==
sizeof(uint8_t))
873 slen=strlen(
"uint16")+1;
876 if (datalength==
sizeof(uint16_t))
884 slen=strlen(
"uint32")+1;
887 if (datalength==
sizeof(uint32_t))
895 slen=strlen(
"uint64")+1;
898 if (datalength==
sizeof(uint64_t))
906 slen=strlen(
"float32")+1;
910 if (datalength==2*
sizeof(
float))
918 slen=strlen(
"float64")+1;
922 if (datalength==2*
sizeof(
double))
930 slen=strlen(
"raw")+1;
933 datalength-=
sizeof(uint16_t);
934 ptr+=
sizeof(uint16_t);
945 printf(
"ID=%d, Datalength=%d => Failed!",
id,datalength);
951 if (strcmp(text,
"Test4: (Macro IF) Test different message sizes")==0)
953 printf(
"Test4m: (Macro IF) Test different message sizes\n");
957 else if (strcmp(text,
"Test4: (Macro IF) finished")==0)
961 printf(
"Test4m PASSED\n");
966 printf(
"Test4m FAILED\n");
1019 if ((length>=0) && (length==datalength))
1035 if (strcmp(text,
"Test5: (Macro IF) Test high-level API")==0)
1037 printf(
"Test5m: (Macro IF) Test high-level API\n");
1041 else if (strcmp(text,
"Test5: (Macro IF) finished")==0)
1045 printf(
"Test5m PASSED\n");
1050 printf(
"Test5m FAILED\n");
1057 if (strcmp(text,
"Next line: DLT_LOG_INT")==0)
1061 if (strcmp(text,
"-42")==0)
1066 if (strcmp(text,
"Next line: DLT_LOG_UINT")==0)
1070 if (strcmp(text,
"42")==0)
1075 if (strcmp(text,
"Next line: DLT_LOG_STRING")==0)
1079 if (strcmp(text,
"String output")==0)
1084 if (strcmp(text,
"Next line: DLT_LOG_RAW")==0)
1088 if (strcmp(text,
"00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f")==0)
1093 if (strcmp(text,
"Next line: DLT_LOG_STRING_INT")==0)
1097 if (strcmp(text,
"String output: -42")==0)
1102 if (strcmp(text,
"Next line: DLT_LOG_STRING_UINT")==0)
1106 if (strcmp(text,
"String output: 42")==0)
1113 if (strcmp(text,
"Test 6: (Macro IF) Test local printing")==0)
1115 printf(
"Test6m: (Macro IF) Test local printing\n");
1119 else if (strcmp(text,
"Test6: (Macro IF) finished")==0)
1123 printf(
"Test6m PASSED\n");
1128 printf(
"Test6m FAILED\n");
1135 if (strcmp(text,
"Message (visible: locally printed)")==0)
1137 printf(
"Message (visible: locally printed)\n");
1140 if (strcmp(text,
"Message (invisible: not locally printed)")==0)
1142 printf(
"Message (invisible: not locally printed)\n");
1148 if (strcmp(text,
"Test 7: (Macro IF) Test network trace")==0)
1150 printf(
"Test7m: (Macro IF) Test network trace\n");
1154 else if (strcmp(text,
"Test7: (Macro IF) finished")==0)
1158 printf(
"Test7m PASSED\n");
1163 printf(
"Test7m FAILED\n");
1202 length=0,length_tmp=0;
1226 if (type_info & DLT_TYPE_INFO_RAWD)
1232 if ((length>=0) && (length==datalength))
1247 if (strcmp(text,
"Test 8: (Macro IF) Test truncated network trace")==0)
1249 printf(
"Test8m: (Macro IF) Test truncated network trace\n");
1253 else if (strcmp(text,
"Test8: (Macro IF) finished")==0)
1257 printf(
"Test8m PASSED\n");
1262 printf(
"Test8m FAILED\n");
1300 length=0,length_tmp=0;
1315 if(strcmp((
char *)chdr,
"NWTR")==0)
1329 if(length == 16 && hdr[15] == 15)
1341 if(orig_size == 1024*5)
1348 if(type_info & DLT_TYPE_INFO_RAWD)
1368 if (strcmp(text,
"Test 9: (Macro IF) Test segmented network trace")==0)
1370 printf(
"Test9m: (Macro IF) Test segmented network trace\n");
1374 else if (strcmp(text,
"Test9: (Macro IF) finished")==0)
1379 printf(
"Test9m PASSED\n");
1384 printf(
"Test9m FAILED\n");
1422 length=0,length_tmp=0;
1436 if(strcmp((
char *)chdr,
"NWST")==0)
1474 if(type_info & DLT_TYPE_INFO_UINT)
1489 if(type_info & DLT_TYPE_INFO_UINT)
1504 if(type_info & DLT_TYPE_INFO_UINT)
1527 length=0,length_tmp=0;
1541 if(strcmp((
char *)chdr,
"NWCH")==0)
1562 if(type_info & DLT_TYPE_INFO_UINT)
1593 length=0,length_tmp=0;
1607 if(strcmp((
char *)chdr,
"NWEN")==0)
1632 if (strcmp(text,
"Test1: (Function IF) Test all log levels")==0)
1634 printf(
"Test1f: (Function IF) Test all log levels\n");
1638 else if (strcmp(text,
"Test1: (Function IF) finished")==0)
1643 printf(
"Test1f PASSED\n");
1648 printf(
"Test1f FAILED\n");
1690 if (strcmp(text,
"Test2: (Function IF) Test all variable types (verbose)")==0)
1692 printf(
"Test2f: (Function IF) Test all variable types (verbose)\n");
1696 else if (strcmp(text,
"Test2: (Function IF) finished")==0)
1700 printf(
"Test2f PASSED\n");
1705 printf(
"Test2f FAILED\n");
1748 if (datalength==
sizeof(uint8_t))
1759 if (datalength==
sizeof(int8_t))
1767 if (datalength==
sizeof(int16_t))
1775 if (datalength==
sizeof(int32_t))
1783 if (datalength==
sizeof(int64_t))
1802 if (datalength==
sizeof(uint8_t))
1810 if (datalength==
sizeof(uint16_t))
1818 if (datalength==
sizeof(uint32_t))
1826 if (datalength==
sizeof(uint64_t))
1855 if (datalength==(2*
sizeof(
float)+
sizeof(uint32_t)))
1863 if (datalength==(2*
sizeof(
double)+
sizeof(uint32_t)))
1881 if ((length==datalength) && (length==10))
1894 if (strcmp(text,
"Test3: (Function IF) Test all variable types (non-verbose)")==0)
1896 printf(
"Test3f: (Function IF) Test all variable types (non-verbose)\n");
1900 else if (strcmp(text,
"Test3: (Function IF) finished")==0)
1904 printf(
"Test3f PASSED\n");
1909 printf(
"Test3f FAILED\n");
1932 datalength-=
sizeof(uint16_t);
1933 ptr+=
sizeof(uint16_t);
1939 slen=strlen(
"bool")+1;
1942 if (datalength==
sizeof(uint8_t))
1950 slen=strlen(
"int")+1;
1953 if (datalength==
sizeof(
int))
1961 slen=strlen(
"int8")+1;
1964 if (datalength==
sizeof(int8_t))
1972 slen=strlen(
"int16")+1;
1975 if (datalength==
sizeof(int16_t))
1983 slen=strlen(
"int32")+1;
1986 if (datalength==
sizeof(int32_t))
1994 slen=strlen(
"int64")+1;
1997 if (datalength==
sizeof(int64_t))
2005 slen=strlen(
"uint")+1;
2008 if (datalength==
sizeof(
unsigned int))
2016 slen=strlen(
"uint8")+1;
2019 if (datalength==
sizeof(uint8_t))
2027 slen=strlen(
"uint16")+1;
2030 if (datalength==
sizeof(uint16_t))
2038 slen=strlen(
"uint32")+1;
2041 if (datalength==
sizeof(uint32_t))
2049 slen=strlen(
"uint64")+1;
2052 if (datalength==
sizeof(uint64_t))
2060 slen=strlen(
"float32")+1;
2064 if (datalength==2*
sizeof(
float))
2072 slen=strlen(
"float64")+1;
2076 if (datalength==2*
sizeof(
double))
2084 slen=strlen(
"raw")+1;
2087 datalength-=
sizeof(uint16_t);
2088 ptr+=
sizeof(uint16_t);
2099 printf(
"ID=%d, Datalength=%d => Failed!",
id,datalength);
2105 if (strcmp(text,
"Test4: (Function IF) Test different message sizes")==0)
2107 printf(
"Test4f: (Function IF) Test different message sizes\n");
2111 else if (strcmp(text,
"Test4: (Function IF) finished")==0)
2115 printf(
"Test4f PASSED\n");
2120 printf(
"Test4f FAILED\n");
2173 if ((length>=0) && (length==datalength))
2189 if (strcmp(text,
"Test5: (Function IF) Test high-level API")==0)
2191 printf(
"Test5f: (Function IF) Test high-level API\n");
2195 else if (strcmp(text,
"Test5: (Function IF) finished")==0)
2199 printf(
"Test5f PASSED\n");
2204 printf(
"Test5f FAILED\n");
2211 if (strcmp(text,
"Next line: dlt_log_int()")==0)
2215 if (strcmp(text,
"-42")==0)
2220 if (strcmp(text,
"Next line: dlt_log_uint()")==0)
2224 if (strcmp(text,
"42")==0)
2229 if (strcmp(text,
"Next line: dlt_log_string()")==0)
2233 if (strcmp(text,
"String output")==0)
2238 if (strcmp(text,
"Next line: dlt_log_raw()")==0)
2242 if (strcmp(text,
"00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f")==0)
2247 if (strcmp(text,
"Next line: dlt_log_string_int()")==0)
2251 if (strcmp(text,
"String output: -42")==0)
2256 if (strcmp(text,
"Next line: dlt_log_string_uint()")==0)
2260 if (strcmp(text,
"String output: 42")==0)
2267 if (strcmp(text,
"Test 6: (Function IF) Test local printing")==0)
2269 printf(
"Test6f: (Function IF) Test local printing\n");
2273 else if (strcmp(text,
"Test6: (Function IF) finished")==0)
2277 printf(
"Test6f PASSED\n");
2282 printf(
"Test6f FAILED\n");
2289 if (strcmp(text,
"Message (visible: locally printed)")==0)
2291 printf(
"Message (visible: locally printed)\n");
2294 if (strcmp(text,
"Message (invisible: not locally printed)")==0)
2296 printf(
"Message (invisible: not locally printed)\n");
2302 if (strcmp(text,
"Test 7: (Function IF) Test network trace")==0)
2304 printf(
"Test7f: (Function IF) Test network trace\n");
2308 else if (strcmp(text,
"Test7: (Function IF) finished")==0)
2312 printf(
"Test7f PASSED\n");
2317 printf(
"Test7f FAILED\n");
2381 if (type_info & DLT_TYPE_INFO_RAWD)
2387 if ((length>=0) && (length==datalength))
2402 if (strcmp(text,
"Test 8: (Function IF) Test truncated network trace")==0)
2404 printf(
"Test8f: (Function IF) Test truncated network trace\n");
2408 else if (strcmp(text,
"Test8: (Function IF) finished")==0)
2412 printf(
"Test8f PASSED\n");
2417 printf(
"Test8f FAILED\n");
2455 length=0,length_tmp=0;
2470 if(strcmp((
char *)chdr,
"NWTR")==0)
2484 if(length == 16 && hdr[15] == 15)
2496 if(orig_size == 1024*5)
2503 if(type_info & DLT_TYPE_INFO_RAWD)
2522 if (strcmp(text,
"Test 9: (Function IF) Test segmented network trace")==0)
2524 printf(
"Test9f: (Function IF) Test segmented network trace\n");
2528 else if (strcmp(text,
"Test9: (Function IF) finished")==0)
2533 printf(
"Test9f PASSED\n");
2538 printf(
"Test9f FAILED\n");
2576 length=0,length_tmp=0;
2590 if(strcmp((
char *)chdr,
"NWST")==0)
2628 if(type_info & DLT_TYPE_INFO_UINT)
2643 if(type_info & DLT_TYPE_INFO_UINT)
2658 if(type_info & DLT_TYPE_INFO_UINT)
2681 length=0,length_tmp=0;
2695 if(strcmp((
char *)chdr,
"NWCH")==0)
2716 if(type_info & DLT_TYPE_INFO_UINT)
2747 length=0,length_tmp=0;
2761 if(strcmp((
char *)chdr,
"NWEN")==0)
2784 if (strcmp(text,
"Tests finished")==0)
2786 printf(
"Tests finished\n");
2792 if (dltdata->
sock!=-1)
2794 close(dltdata->
sock);
2807 else if (dltdata->
mflag)
2811 else if (dltdata->
sflag)
2822 iov[1].iov_len = message->
datasize;
2824 bytes_written = writev(dltdata->
ohandle, iov, 2);
2825 if (0 > bytes_written){
2826 printf(
"dlt_testclient_message_callback, error in: writev(dltdata->ohandle, iov, 2)\n");
#define DLT_ENDIAN_GET_32(htyp, x)
DltReturnValue dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose)
#define DLT_TYPE_INFO_SINT
DltStorageHeader * storageheader
void dlt_set_id(char *id, const char *text)
void dlt_client_register_message_callback(int(*registerd_callback)(DltMessage *message, void *data))
DltReturnValue dlt_file_set_filter(DltFile *file, DltFilter *filter, int verbose)
#define DLT_GET_MSIN_MTIN(msin)
DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose)
int test_counter_macro[DLT_TESTCLIENT_NUM_TESTS]
int dlt_client_set_server_ip(DltClient *client, char *ipaddr)
#define DLT_TESTCLIENT_NUM_TESTS
DltReturnValue dlt_message_filter_check(DltMessage *msg, DltFilter *filter, int verbose)
#define DLT_MSG_READ_VALUE(dst, src, length, type)
#define DLT_GET_MSIN_MSTP(msin)
DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate)
DltReturnValue dlt_filter_init(DltFilter *filter, int verbose)
DltExtendedHeader * extendedheader
int dlt_client_set_serial_device(DltClient *client, char *serial_device)
#define DLT_IS_MSIN_VERB(msin)
#define DLT_ENDIAN_GET_16(htyp, x)
int dlt_testclient_message_callback(DltMessage *message, void *data)
static char data[kDataSize]
DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu)
#define DLT_IS_HTYP_UEH(htyp)
DltReturnValue dlt_client_init(DltClient *client, int verbose)
#define DLT_MSG_IS_NONVERBOSE(MSG)
DltReturnValue dlt_filter_free(DltFilter *filter, int verbose)
#define DLT_TYPE_NW_TRACE
DltReturnValue dlt_client_cleanup(DltClient *client, int verbose)
DltReturnValue dlt_client_connect(DltClient *client, int verbose)
#define DLT_TESTCLIENT_TEXTBUFSIZE
DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verbose)
#define DLT_TYPE_INFO_FLOA
int test_counter_function[DLT_TESTCLIENT_NUM_TESTS]
uint8_t headerbuffer[sizeof(DltStorageHeader)+sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]
#define DLT_IS_HTYP_WEID(htyp)
#define DLT_TYPE_INFO_STRG
DltStandardHeaderExtra headerextra
int main(int argc, char *argv[])
#define DLT_TESTCLIENT_ECU_ID
DltReturnValue dlt_file_init(DltFile *file, int verbose)
DltReturnValue dlt_message_payload(DltMessage *msg, char *text, int textlength, int type, int verbose)
DltReturnValue dlt_file_free(DltFile *file, int verbose)
DltStandardHeader * standardheader
#define DLT_TYPE_INFO_BOOL
#define DLT_TYPE_INFO_RAWD
void dlt_get_version(char *buf, size_t size)
#define DLT_USER_BUF_MAX_SIZE
DltReturnValue dlt_message_header(DltMessage *msg, char *text, int textlength, int verbose)
#define DLT_TYPE_INFO_UINT
DltReturnValue dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose)
#define DLT_TYPE_INFO_TYLE
DltReturnValue dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose)
#define DLT_TYPE_INFO_SCOD
#define DLT_MSG_READ_STRING(dst, src, maxlength, length)