From 357378f12fdaa0bb9f51d73bf3b3b997458c7750 Mon Sep 17 00:00:00 2001 From: Alexander Wenzel Date: Fri, 23 Sep 2011 09:58:29 +0200 Subject: Added stress test including performance measurement. --- src/tests/dlt-test-stress-client.c | 576 +++++++++++++++++++++++++++++++++++++ 1 file changed, 576 insertions(+) create mode 100644 src/tests/dlt-test-stress-client.c (limited to 'src/tests/dlt-test-stress-client.c') diff --git a/src/tests/dlt-test-stress-client.c b/src/tests/dlt-test-stress-client.c new file mode 100644 index 0000000..89c49be --- /dev/null +++ b/src/tests/dlt-test-stress-client.c @@ -0,0 +1,576 @@ +/* + * Dlt Test Stress Client - Diagnostic Log and Trace + * @licence app begin@ + * + * Copyright (C) 2011, BMW AG - Alexander Wenzel + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License, version 2.1, for more details. + * + * You should have received a copy of the GNU Lesser General Public License, version 2.1, along + * with this program; if not, see . + * + * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may + * also be applicable to programs even in cases in which the program is not a library in the technical sense. + * + * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may + * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to + * license your linked modules under the GNU Lesser General Public License, version 2.1, you + * may use the program under the following exception. + * + * As a special exception, the copyright holders of DLT give you permission to combine DLT + * with software programs or libraries that are released under any license unless such a combination is not + * permitted by the license of such a software program or library. You may copy and distribute such a + * system following the terms of the GNU Lesser General Public License, version 2.1, including this + * special exception, for DLT and the licenses of the other code concerned. + * + * Note that people who make modified versions of DLT are not obligated to grant this special exception + * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, + * version 2.1, gives permission to release a modified version without this exception; this exception + * also makes it possible to release a modified version which carries forward this exception. + * + * @licence end@ + */ + + +/******************************************************************************* +** ** +** SRC-MODULE: dlt-test-stress-client.c ** +** ** +** TARGET : linux ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** Markus Klein ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + +/******************************************************************************* +** Author Identity ** +******************************************************************************** +** ** +** Initials Name Company ** +** -------- ------------------------- ---------------------------------- ** +** aw Alexander Wenzel BMW ** +** mk Markus Klein Fraunhofer ESK ** +*******************************************************************************/ + +/******************************************************************************* +** Revision Control History ** +*******************************************************************************/ + +/* + * $LastChangedRevision: 1670 $ + * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $ + * $LastChangedBy$ + Initials Date Comment + aw 13.01.2010 initial + */ + +#include /* for isprint() */ +#include /* for atoi() */ +#include /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */ +#include /* for open() */ +#include /* for strcmp() */ +#include /* for writev() */ + +#include "dlt_client.h" +#include "dlt_protocol.h" +#include "dlt_user.h" + +#define DLT_TESTCLIENT_TEXTBUFSIZE 10024 /* Size of buffer for text output */ +#define DLT_TESTCLIENT_ECU_ID "ECU1" + +#define DLT_TESTCLIENT_NUM_TESTS 7 + +/* Function prototypes */ +int dlt_testclient_message_callback(DltMessage *message, void *data); + +typedef struct +{ + int aflag; + int sflag; + int xflag; + int mflag; + int vflag; + int yflag; + char *ovalue; + char *fvalue; + char *tvalue; + char *evalue; + int nvalue; + int bvalue; + + char ecuid[4]; + int ohandle; + + DltFile file; + DltFilter filter; + + int running_test; + + int test_counter_macro[DLT_TESTCLIENT_NUM_TESTS]; + int test_counter_function[DLT_TESTCLIENT_NUM_TESTS]; + + int tests_passed; + int tests_failed; + + int sock; + + // test values + unsigned long bytes_received; + unsigned long time_elapsed; + int last_value; + int count_received_messages; + int count_not_received_messages; + +} DltTestclientData; + +/** + * Print usage information of tool. + */ +void usage() +{ + char version[255]; + + dlt_get_version(version); + + printf("Usage: dlt-test-stress-client [options] hostname/serial_device_name\n"); + printf("Test against received data from dlt-test-stress-user.\n"); + printf("%s \n", version); + printf("Options:\n"); + printf(" -a Print DLT messages; payload as ASCII\n"); + printf(" -x Print DLT messages; payload as hex\n"); + printf(" -m Print DLT messages; payload as hex and ASCII\n"); + printf(" -s Print DLT messages; only headers\n"); + printf(" -v Verbose mode\n"); + printf(" -h Usage\n"); + printf(" -y Serial device mode\n"); + printf(" -b baudrate Serial device baudrate (Default: 115200)\n"); + printf(" -e ecuid Set ECU ID (Default: ECU1)\n"); + printf(" -o filename Output messages in new DLT file\n"); + printf(" -f filename Enable filtering of messages\n"); + printf(" -n messages Number of messages to be received per test(Default: 10000)\n"); +} + +/** + * Main function of tool. + */ +int main(int argc, char* argv[]) +{ + DltClient dltclient; + DltTestclientData dltdata; + int c,i; + int index; + + /* Initialize dltdata */ + dltdata.aflag = 0; + dltdata.sflag = 0; + dltdata.xflag = 0; + dltdata.mflag = 0; + dltdata.vflag = 0; + dltdata.yflag = 0; + dltdata.ovalue = 0; + dltdata.fvalue = 0; + dltdata.evalue = 0; + dltdata.bvalue = 0; + dltdata.nvalue = 10000; + dltdata.ohandle= -1; + + dltdata.running_test = 0; + + for (i=0;istandardheader->htyp)) + { + dlt_set_storageheader(message->storageheader,message->headerextra.ecu); + } + else + { + dlt_set_storageheader(message->storageheader,dltdata->ecuid); + } + + if ((dltdata->fvalue==0) || (dltdata->fvalue && dlt_message_filter_check(message,&(dltdata->filter),dltdata->vflag)==1)) + { + + dlt_message_header(message,text,sizeof(text),dltdata->vflag); + if (dltdata->aflag) + { + printf("%s ",text); + } + dlt_message_payload(message,text,sizeof(text),DLT_OUTPUT_ASCII,dltdata->vflag); + if (dltdata->aflag) + { + printf("[%s]\n",text); + } + + /* do something here */ + + // Count number of received bytes + dltdata->bytes_received += message->datasize+message->headersize-sizeof(DltStorageHeader); + + // print number of received bytes + if((dlt_uptime() - dltdata->time_elapsed) > 10000) + { + printf("Received %lu Bytes/s\n",dltdata->bytes_received*10000/(dlt_uptime()-dltdata->time_elapsed)); + dltdata->time_elapsed = dlt_uptime(); + dltdata->bytes_received = 0; + } + + /* Extended header */ + if (DLT_IS_HTYP_UEH(message->standardheader->htyp)) + { + /* Log message */ + if ((DLT_GET_MSIN_MSTP(message->extendedheader->msin))==DLT_TYPE_LOG) + { + /* Verbose */ + if (DLT_IS_MSIN_VERB(message->extendedheader->msin)) + { + /* 2 arguments */ + if (message->extendedheader->noar==2) + { + /* verbose mode */ + type_info=0; + type_info_tmp=0; + length=0; + length_tmp=0; /* the macro can set this variable to -1 */ + + ptr = message->databuffer; + datalength = message->datasize; + + /* first read the type info of the first argument: must be string */ + DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t); + type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp); + + if (type_info & DLT_TYPE_INFO_SINT) + { + /* read value */ + DLT_MSG_READ_VALUE(value_tmp,ptr,datalength,int32_t); + value=DLT_ENDIAN_GET_32(message->standardheader->htyp, value_tmp); + //printf("%d\n",value); + + if(value < dltdata->last_value) + { + if(dltdata->nvalue == dltdata->count_received_messages) + printf("PASSED: %d Msg received, %d not received\n",dltdata->count_received_messages,dltdata->count_not_received_messages); + else + printf("FAILED: %d Msg received, %d not received\n",dltdata->count_received_messages,dltdata->count_not_received_messages); + + dltdata->last_value = 0; + dltdata->count_received_messages = 0; + dltdata->count_not_received_messages = value -1; + } + else + { + dltdata->count_not_received_messages += value - dltdata->last_value -1; + } + dltdata->last_value = value; + dltdata->count_received_messages++; + + if (length>=0) + { + ptr+=length; + datalength-=length; + + /* read type of second argument: must be raw */ + DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t); + type_info=DLT_ENDIAN_GET_32(message->standardheader->htyp, type_info_tmp); + + if (type_info & DLT_TYPE_INFO_RAWD) + { + /* get length of raw data block */ + DLT_MSG_READ_VALUE(length_tmp,ptr,datalength,uint16_t); + length=DLT_ENDIAN_GET_16(message->standardheader->htyp, length_tmp); + + if ((length>=0) && (length==datalength)) + { + //printf("Raw data found in payload, length="); + //printf("%d, datalength=%d \n", length, datalength); + dltdata->test_counter_macro[3]++; + } + } + } + } + } + } + } + } + + /* if no filter set or filter is matching display message */ + if (dltdata->xflag) + { + dlt_message_print_hex(message,text,DLT_TESTCLIENT_TEXTBUFSIZE,dltdata->vflag); + } + else if (dltdata->mflag) + { + dlt_message_print_mixed_plain(message,text,DLT_TESTCLIENT_TEXTBUFSIZE,dltdata->vflag); + } + else if (dltdata->sflag) + { + dlt_message_print_header(message,text,sizeof(text),dltdata->vflag); + } + + /* if file output enabled write message */ + if (dltdata->ovalue) + { + iov[0].iov_base = message->headerbuffer; + iov[0].iov_len = message->headersize; + iov[1].iov_base = message->databuffer; + iov[1].iov_len = message->datasize; + + bytes_written = writev(dltdata->ohandle, iov, 2); + } + } + + return 0; +} -- cgit v1.2.1