automotive-dlt
dlt-test-stress-user.c
Go to the documentation of this file.
1 /*
2  * @licence app begin@
3  * SPDX license identifier: MPL-2.0
4  *
5  * Copyright (C) 2011-2015, BMW AG
6  *
7  * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
8  *
9  * This Source Code Form is subject to the terms of the
10  * Mozilla Public License (MPL), v. 2.0.
11  * If a copy of the MPL was not distributed with this file,
12  * You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  * For further information see http://www.genivi.org/.
15  * @licence end@
16  */
17 
28 /*******************************************************************************
29 ** **
30 ** SRC-MODULE: dlt-test-stress-user.c **
31 ** **
32 ** TARGET : linux **
33 ** **
34 ** PROJECT : DLT **
35 ** **
36 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
37 ** Markus Klein **
38 ** **
39 ** PURPOSE : **
40 ** **
41 ** REMARKS : **
42 ** **
43 ** PLATFORM DEPENDANT [yes/no]: yes **
44 ** **
45 ** TO BE CHANGED BY USER [yes/no]: no **
46 ** **
47 *******************************************************************************/
48 
49 /*******************************************************************************
50 ** Author Identity **
51 ********************************************************************************
52 ** **
53 ** Initials Name Company **
54 ** -------- ------------------------- ---------------------------------- **
55 ** aw Alexander Wenzel BMW **
56 ** mk Markus Klein Fraunhofer ESK **
57 *******************************************************************************/
58 
59 /*******************************************************************************
60 ** Revision Control History **
61 *******************************************************************************/
62 
63 /*
64  * $LastChangedRevision: 1670 $
65  * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
66  * $LastChangedBy$
67  Initials Date Comment
68  aw 13.01.2010 initial
69  */
70 
71 #include <stdio.h> /* for printf() and fprintf() */
72 #include <float.h>
73 #include <stdlib.h> /* for atoi(), abort() */
74 #include <string.h> /* for memset() */
75 #include <ctype.h> /* for isprint() */
76 
77 #include "dlt.h"
78 
79 #define DLT_TEST_NUM_CONTEXT 7
80 
81 /* Test functions... */
82 
83 int testall(int count,int repeat,int delay,int size);
84 
85 /* Context declaration.. */
86 DLT_DECLARE_CONTEXT(context_info)
87 
88 /* for macro interface */
89 DLT_DECLARE_CONTEXT(context_macro_callback)
90 DLT_DECLARE_CONTEXT(context_macro_test[DLT_TEST_NUM_CONTEXT])
91 
92 /* for function interface */
93 DltContext context_function_callback;
94 DltContext context_function_test[DLT_TEST_NUM_CONTEXT];
95 
96 DltContextData context_data;
97 
101 void usage()
102 {
103  char version[255];
104 
105  dlt_get_version(version,255);
106 
107  printf("Usage: dlt-test-stress-user [options]\n");
108  printf("Test user application providing Test messages.\n");
109  printf("%s \n", version);
110  printf("Options:\n");
111  printf(" -v Verbose mode\n");
112  printf(" -f filename Use local log file instead of sending to daemon\n");
113  printf(" -n count Number of messages to be sent per test (Default: 10000)\n");
114  printf(" -r repeat How often test is repeated (Default: 100)\n");
115  printf(" -d delay Delay between sent messages in uSec (Default: 1000)\n");
116  printf(" -s size Size of extra message data in bytes (Default: 100)\n");
117 }
118 
122 int main(int argc, char* argv[])
123 {
124  //int vflag = 0;
125  char *fvalue = 0;
126  int nvalue = 10000;
127  int rvalue = 100;
128  int dvalue = 1000;
129  int svalue = 100;
130 
131  int c;
132 
133  opterr = 0;
134 
135  while ((c = getopt (argc, argv, "vf:n:r:d:s:")) != -1)
136  {
137  switch (c)
138  {
139  case 'v':
140  {
141  //vflag = 1;
142  break;
143  }
144  case 'f':
145  {
146  fvalue = optarg;
147  break;
148  }
149  case 'n':
150  {
151  nvalue = atoi(optarg);
152  break;
153  }
154  case 'r':
155  {
156  rvalue = atoi(optarg);
157  break;
158  }
159  case 'd':
160  {
161  dvalue = atoi(optarg);
162  break;
163  }
164  case 's':
165  {
166  svalue = atoi(optarg);
167  break;
168  }
169  case '?':
170  {
171  if (optopt == 'd' || optopt == 'f' || optopt == 'n' || optopt == 'r' || optopt == 'd' || optopt == 's')
172  {
173  fprintf (stderr, "Option -%c requires an argument.\n", optopt);
174  }
175  else if (isprint (optopt))
176  {
177  fprintf (stderr, "Unknown option `-%c'.\n", optopt);
178  }
179  else
180  {
181  fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt);
182  }
183  /* unknown or wrong option used, show usage information and terminate */
184  usage();
185  return -1;
186  }
187  default:
188  {
189  abort ();
190  return -1;//for parasoft
191  }
192  }
193  }
194 
195  if (fvalue)
196  {
197  /* DLT is intialised automatically, except another output target will be used */
198  if (dlt_init_file(fvalue)<0) /* log to file */
199  {
200  return -1;
201  }
202  }
203 
204  /* Register APP */
205  DLT_REGISTER_APP("DIFT","DLT Interface Test");
206 
207  /* Register CONTEXTS... */
208  DLT_REGISTER_CONTEXT(context_info,"INFO","Information context");
209 
210  /* Tests starting */
211  printf("Tests starting\n");
212  //DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Tests starting"));
213 
214  /* wait 3 seconds before starting */
215  //sleep(3);
216 
217  testall(nvalue,rvalue,dvalue,svalue);
218 
219  /* Tests finished */
220  printf("Tests finished\n");
221  //DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Tests finished"));
222 
223  /* wait 3 seconds before terminating application */
224  //sleep(3);
225 
226  /* Unregister CONTEXTS... */
227  DLT_UNREGISTER_CONTEXT(context_info);
228 
229  /* Unregister APP */
231 
232  return 0;
233 }
234 
235 /******************/
236 /* The test cases */
237 /******************/
238 
239 int testall(int count,int repeat,int delay,int size)
240 {
241  char buffer[size];
242  int num,rnum;
243 
244  for(num=0;num< size;num++)
245  {
246  buffer[num] = num;
247  }
248 
249  /* Test All: Test all start */
250  //printf("Test1: Test all\n");
251  //DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test1: Test all"));
252 
253  for(rnum=0;rnum<repeat;rnum++)
254  {
255  for(num=1;num<=count;num++)
256  {
257  DLT_LOG(context_info,DLT_LOG_INFO,DLT_INT(num),DLT_RAW(buffer, size));
258  usleep(delay);
259  }
260  }
261 
262  /* wait 5 seconds after test */
263  //sleep(5);
264  //DLT_LOG(context_info,DLT_LOG_INFO,DLT_STRING("Test1: finished"));
265 
266  return 0;
267 }
268 
269 
270 
#define DLT_RAW(BUF, LEN)
#define DLT_UNREGISTER_APP()
void usage()
Definition: dlt-control.c:190
#define DLT_INT(INT_VAR)
DltReturnValue dlt_init_file(const char *name)
Definition: dlt_user.c:350
#define DLT_TEST_NUM_CONTEXT
#define DLT_REGISTER_APP(APPID, DESCRIPTION)
unsigned char buffer[BUFFER_SIZE]
Buffer for dlt file transfer. The size is defined by BUFFER_SIZE.
#define DLT_REGISTER_CONTEXT(CONTEXT, CONTEXTID, DESCRIPTION)
DLT_DECLARE_CONTEXT(context_info)
int testall(int count, int repeat, int delay, int size)
#define DLT_UNREGISTER_CONTEXT(CONTEXT)
#define DLT_LOG(CONTEXT, LOGLEVEL, ARGS...)
int main(int argc, char *argv[])
void dlt_get_version(char *buf, size_t size)
Definition: dlt_common.c:3239