summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLassi Marttala <lassi.lm.marttala@partner.bmw.com>2012-01-23 15:22:52 +0100
committerLassi Marttala <lassi.lm.marttala@partner.bmw.com>2012-01-23 15:22:52 +0100
commit3c0d62da8e873b064cc2cc59a63dd34a60d96e4f (patch)
tree5f9745b31871afbf9f4d6e910ec6244a2aec972d
parenta49daa2ef8b4210add3d2f9f23259b5cf7a7ebd6 (diff)
downloadDLT-daemon-3c0d62da8e873b064cc2cc59a63dd34a60d96e4f.tar.gz
Suggested Changes to dlt-test-mutli-process:
sender: * Print default values in usage. * Each process should have own APPID * Each thread should have own CID client: * Make usage() useful * Also count headers to bytes transferred, * Serial device mode * Baudrate as option * Output to file * Limit number of messages to receive
-rw-r--r--src/tests/dlt-test-multi-process-client.c132
-rwxr-xr-xsrc/tests/dlt-test-multi-process.c39
2 files changed, 135 insertions, 36 deletions
diff --git a/src/tests/dlt-test-multi-process-client.c b/src/tests/dlt-test-multi-process-client.c
index 4bb0c08..13d777c 100644
--- a/src/tests/dlt-test-multi-process-client.c
+++ b/src/tests/dlt-test-multi-process-client.c
@@ -61,6 +61,8 @@
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
+#include <fcntl.h>
+#include <sys/uio.h>
// DLT Library includes
#include "dlt_client.h"
@@ -71,7 +73,14 @@
// Local data structures
typedef struct {
+ int max_messages;
int verbose;
+ int serial;
+ int baudrate;
+ char *output;
+ int output_handle;
+ int messages_left;
+ DltClient *client_ref;
} s_parameters;
typedef struct {
@@ -79,6 +88,7 @@ typedef struct {
int broken_messages_received;
int bytes_received;
int first_message_time;
+ int output_bytes;
} s_statistics;
// Forward declarations
@@ -88,14 +98,30 @@ int receive(DltMessage *msg, void *data);
* Print usage information
*/
void usage(char *name) {
- printf("Usage: %s [options] <remote address>\n", name);
+ char version[255];
+ dlt_get_version(version);
+
+ printf("Usage: %s [options] <remote address|serial device>\n", name);
+ printf("Receive messages from dlt-test-multi-process.\n");
+ printf("%s", version);
+ printf("Options:\n");
+ printf(" -m Total messages to receive. (Default: 10000)\n");
+ printf(" -y Serial device mode.\n");
+ printf(" -b baudrate Serial device baudrate. (Default: 115200)\n");
+ printf(" -v Verbose. Increases the verbosity level of dlt client library.\n");
+ printf(" -o filename Output messages in new DLT file.\n");
}
/**
* Initialize reasonable default parameters.
*/
void init_params(s_parameters *params) {
+ params->max_messages = 10000;
params->verbose = 0;
+ params->serial = 0;
+ params->output = NULL;
+ params->output_handle = -1;
+ params->baudrate = 115200;
}
/**
@@ -105,16 +131,28 @@ int read_params(s_parameters *params, int argc, char *argv[]) {
init_params(params);
int c;
opterr = 0;
- while ((c = getopt(argc, argv, "v")) != -1) {
+ while ((c = getopt(argc, argv, "m:yb:vo:")) != -1) {
switch (c) {
+ case 'm':
+ params->max_messages = atoi(optarg);
+ break;
+ case 'y':
+ params->serial = 1;
+ break;
+ case 'b':
+ params->baudrate = atoi(optarg);
+ break;
case 'v':
params->verbose = 1;
break;
+ case 'o':
+ params->output = optarg;
+ break;
case '?':
- /*if(optopt == '')
- {
- fprintf(stderr, "Option -%c requires an argument.\n", optopt);
- }*/
+ if(optopt == 'm' || optopt == 'b' || optopt == 'o')
+ {
+ fprintf(stderr, "Option -%c requires an argument.\n", optopt);
+ }
if (isprint(optopt)) {
fprintf(stderr, "Unknown option '-%c'.\n", optopt);
} else {
@@ -132,11 +170,20 @@ int read_params(s_parameters *params, int argc, char *argv[]) {
/**
* Set the connection parameters for dlt client
*/
-int init_dlt_connect(DltClient *client, int argc, char *argv[]) {
+int init_dlt_connect(DltClient *client, const s_parameters *params, int argc, char *argv[]) {
char id[4];
if (argc < 2)
return -1;
- client->servIP = argv[argc - 1];
+ if(params->serial > 0)
+ {
+ client->serial_mode = 1;
+ client->serialDevice = argv[argc - 1];
+ dlt_client_setbaudrate(client, params->baudrate);
+ }
+ else
+ {
+ client->servIP = argv[argc - 1];
+ }
dlt_set_id(id, ECUID);
return 0;
}
@@ -147,7 +194,7 @@ int init_dlt_connect(DltClient *client, int argc, char *argv[]) {
int main(int argc, char *argv[]) {
s_parameters params;
DltClient client;
-
+ params.client_ref = &client;
int err = read_params(&params, argc, argv);
if (err != 0) {
@@ -158,7 +205,7 @@ int main(int argc, char *argv[]) {
dlt_client_init(&client, params.verbose);
dlt_client_register_message_callback(receive);
- err = init_dlt_connect(&client, argc, argv);
+ err = init_dlt_connect(&client, &params, argc, argv);
if (err != 0) {
usage(argv[0]);
return err;
@@ -166,20 +213,44 @@ int main(int argc, char *argv[]) {
err = dlt_client_connect(&client, params.verbose);
if (err != 0) {
- printf("Failed to connect %s\n", client.servIP);
+ printf("Failed to connect %s.\n", client.serial_mode > 0 ? client.serialDevice : client.servIP);
return err;
}
- dlt_client_main_loop(&client, NULL, params.verbose);
+
+ if(params.output)
+ {
+ params.output_handle = open(params.output,O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ if (params.output_handle == -1)
+ {
+ fprintf(stderr,"Failed to open %s for writing.\n",params.output);
+ return -1;
+ }
+ }
+
+ params.messages_left = params.max_messages;
+
+ dlt_client_main_loop(&client, &params, params.verbose);
+
+ if(params.output_handle > 0)
+ {
+ close(params.output_handle);
+ }
return 0;
}
/**
* Print current test statistics
*/
-void print_stats(s_statistics stats)
+void print_stats(s_statistics stats, s_parameters params)
{
static int last_print_time;
- if(last_print_time >= time(NULL)) return; // Only print once a second
+ if(last_print_time >= time(NULL) && // Only print once a second
+ (stats.messages_received+stats.broken_messages_received) % 1000 != 0 &&
+ params.messages_left != 0) // Print also every 1000th message
+ {
+ return;
+ }
printf("\033[2J\033[1;1H"); // Clear screen.
printf("Statistics:\n");
printf(" Messages received : %d\n", stats.messages_received);
@@ -189,6 +260,14 @@ void print_stats(s_statistics stats)
printf(" Throughput (msgs/sec)/(B/sec) : %ld/%ld\n",
stats.messages_received/((time(NULL)-stats.first_message_time)+1),
(stats.bytes_received)/((time(NULL)-stats.first_message_time)+1));
+ if(params.messages_left == 0)
+ {
+ if(stats.broken_messages_received == 0)
+ printf("All messages received succesfully!\n");
+ else
+ printf("Test failure! There were %d broken messages.", stats.broken_messages_received);
+
+ }
fflush(stdout);
last_print_time = time(NULL);
}
@@ -198,12 +277,17 @@ void print_stats(s_statistics stats)
int receive(DltMessage *msg, void *data) {
static s_statistics stats;
char apid[5];
+ struct iovec iov[2];
+ s_parameters *params = (s_parameters *)data;
+
memset(apid, 0, 5);
memcpy(apid, msg->extendedheader->apid, 4);
- if(strcmp(apid, DMPT_NAME) != 0) // Skip other messages
+ if(apid[0] != 'M' || apid[1] != 'T') // TODO: Check through the app description
return 0;
+ params->messages_left--;
+
if(stats.first_message_time == 0)
{
stats.first_message_time = time(NULL);
@@ -223,10 +307,24 @@ int receive(DltMessage *msg, void *data) {
{
stats.broken_messages_received++;
}
- stats.bytes_received += buflen;
+ stats.bytes_received += msg->datasize+msg->headersize-sizeof(DltStorageHeader);;
free(buf);
- print_stats(stats);
+ print_stats(stats, *params);
+
+ if (params->output_handle > 0)
+ {
+ iov[0].iov_base = msg->headerbuffer;
+ iov[0].iov_len = msg->headersize;
+ iov[1].iov_base = msg->databuffer;
+ iov[1].iov_len = msg->datasize;
+
+ stats.output_bytes += writev(params->output_handle, iov, 2);
+ }
+ if(params->messages_left < 1)
+ {
+ dlt_client_cleanup(params->client_ref, params->verbose);
+ }
return 0;
}
diff --git a/src/tests/dlt-test-multi-process.c b/src/tests/dlt-test-multi-process.c
index d11cd1f..7af93c6 100755
--- a/src/tests/dlt-test-multi-process.c
+++ b/src/tests/dlt-test-multi-process.c
@@ -87,6 +87,7 @@ typedef struct {
} s_thread_data;
// Forward declarations
+void init_params(s_parameters * params);
void quit_handler(int signum);
void cleanup();
void do_forks(s_parameters params);
@@ -108,16 +109,18 @@ void usage(char *prog_name)
{
char version[255];
dlt_get_version(version);
+ s_parameters defaults;
+ init_params(&defaults);
printf("Usage: %s [options]\n", prog_name);
printf("Test application for stress testing the daemon with multiple processes and threads.\n");
printf("%s\n", version);
- printf("Options:\n");
- printf(" -m number Number of messages per thread to send.\n");
- printf(" -p number Number of processes to start. Max %d.\n", MAX_PROCS);
- printf(" -t number Number of threads per process. Max %d.\n", MAX_THREADS);
- printf(" -d delay Delay in milliseconds to wait between log messages.\n");
- printf(" -f delay Random fudge in milliseconds to add to delay.\n");
+ printf("Options (Default):\n");
+ printf(" -m number Number of messages per thread to send. (%d)\n", defaults.nmsgs);
+ printf(" -p number Number of processes to start. (%d), Max %d.\n", defaults.nprocs, MAX_PROCS);
+ printf(" -t number Number of threads per process. (%d), Max %d.\n", defaults.nthreads, MAX_THREADS);
+ printf(" -d delay Delay in milliseconds to wait between log messages. (%d)\n", defaults.delay);
+ printf(" -f delay Random fudge in milliseconds to add to delay. (%d)\n", defaults.delay_fudge);
}
/**
@@ -299,18 +302,20 @@ time_t mksleep_time(int delay, int fudge)
*/
void do_logging(s_thread_data *data)
{
- //__asm__ ("int $0xCC");
- int msgs_left = data->params.nmsgs;
- pid_t mypid = getpid();
-
+ DltContext mycontext;
+ char ctid[5];
- srand(mypid);
+ sprintf(ctid,"%.2x", rand() & 0x0000ffff);
+ DLT_REGISTER_CONTEXT(mycontext, ctid, "Child in dlt-test-multi-process");
+ data->ctx = mycontext;
+ int msgs_left = data->params.nmsgs;
while(msgs_left-- > 0)
{
DLT_LOG(data->ctx, DLT_LOG_INFO, DLT_STRING(PAYLOAD_DATA));
usleep(mksleep_time(data->params.delay, data->params.delay_fudge));
}
+ DLT_UNREGISTER_CONTEXT(mycontext);
}
/**
@@ -318,20 +323,16 @@ void do_logging(s_thread_data *data)
*/
void run_threads(s_parameters params)
{
- DltContext mycontext;
pthread_t thread[params.nthreads];
s_thread_data thread_data;
- char ctid[5];
+ char apid[5];
int i;
srand(getpid());
-
- DLT_REGISTER_APP(DMPT_NAME,"DLT daemon multi process test.");
- sprintf(ctid,"%.2x", rand() & 0x0000ffff);
- DLT_REGISTER_CONTEXT(mycontext, ctid, "Child in dlt-test-multi-process");
+ sprintf(apid,"MT%.1x", rand() & 0x000000ff);
+ DLT_REGISTER_APP(apid,DMPT_NAME);
thread_data.params = params;
- thread_data.ctx = mycontext;
for(i=0;i<params.nthreads;i++)
{
@@ -347,7 +348,7 @@ void run_threads(s_parameters params)
pthread_join(thread[i], NULL);
}
- DLT_UNREGISTER_CONTEXT(mycontext);
+
DLT_UNREGISTER_APP();
// We can exit now
exit(0);