From 1236195e9b93aeb6bfa625956fa027f96003756d Mon Sep 17 00:00:00 2001 From: Lutz Helwing Date: Wed, 15 Jul 2015 14:14:19 +0200 Subject: DLT daemon improvement - dlt_init()-check DLT daemon improvement - parameter value range check Adapt unit tests to check for enum return values Changed C version to gnu99 and C++ version to gnu++0c Signed-off-by: Alexander Wenzel --- src/tests/dlt-test-multi-process.c | 398 ++++++++++++++++++------------------- 1 file changed, 199 insertions(+), 199 deletions(-) (limited to 'src/tests/dlt-test-multi-process.c') diff --git a/src/tests/dlt-test-multi-process.c b/src/tests/dlt-test-multi-process.c index 93fd069..c5c8ddd 100644 --- a/src/tests/dlt-test-multi-process.c +++ b/src/tests/dlt-test-multi-process.c @@ -64,16 +64,16 @@ // Structs typedef struct { - int nmsgs; // Number of messages to send - int nprocs; // Number of processes to start - int nthreads; // Number of threads to start - int delay; // Delay between logs messages for each process - int delay_fudge; // Fudge the delay by 0-n to cause desynchronization + int nmsgs; // Number of messages to send + int nprocs; // Number of processes to start + int nthreads; // Number of threads to start + int delay; // Delay between logs messages for each process + int delay_fudge; // Fudge the delay by 0-n to cause desynchronization } s_parameters; typedef struct { - s_parameters params; - DltContext ctx; + s_parameters params; + DltContext ctx; } s_thread_data; // Forward declarations @@ -97,31 +97,31 @@ unsigned int pidcount = 0; */ void usage(char *prog_name) { - char version[255]; - dlt_get_version(version,255); - 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 (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); + char version[255]; + dlt_get_version(version,255); + 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 (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); } /** * Set nice default values for parameters */ void init_params(s_parameters * params) { - params->nmsgs = 100; - params->nprocs = 10; - params->nthreads = 2; - params->delay = 1000; - params->delay_fudge = 100; + params->nmsgs = 100; + params->nprocs = 10; + params->nthreads = 2; + params->delay = 1000; + params->delay_fudge = 100; } /** @@ -129,58 +129,58 @@ void init_params(s_parameters * params) { */ int read_cli(s_parameters *params, int argc, char **argv) { - int c; - opterr = 0; + int c; + opterr = 0; while ((c = getopt (argc, argv, "m:p:t:d:f:")) != -1) - { - switch(c) - { - case 'm': - params->nmsgs = atoi(optarg); - break; - case 'p': - params->nprocs = atoi(optarg); - if(params->nprocs > MAX_PROCS) - { - fprintf(stderr, "Too many processes selected.\n"); - return -1; - } - break; - case 't': - params->nthreads = atoi(optarg); - if(params->nprocs > MAX_PROCS) - { - fprintf(stderr, "Too many threads selected.\n"); - return -1; - } - break; - case 'd': - params->delay = atoi(optarg); - break; - case 'f': - params->delay_fudge = atoi(optarg); - break; - case '?': - if(optopt == 'n' || optopt == 'd' || optopt == 'f') - { - fprintf(stderr, "Option -%c requires an argument.\n", optopt); - } - else if(isprint(optopt)) - { - fprintf(stderr, "Unknown option '-%c'.\n", optopt); - } - else - { - fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt); - } - return -1; - break; - default: - abort(); + { + switch(c) + { + case 'm': + params->nmsgs = atoi(optarg); + break; + case 'p': + params->nprocs = atoi(optarg); + if(params->nprocs > MAX_PROCS) + { + fprintf(stderr, "Too many processes selected.\n"); + return -1; + } + break; + case 't': + params->nthreads = atoi(optarg); + if(params->nprocs > MAX_PROCS) + { + fprintf(stderr, "Too many threads selected.\n"); + return -1; + } + break; + case 'd': + params->delay = atoi(optarg); + break; + case 'f': + params->delay_fudge = atoi(optarg); + break; + case '?': + if(optopt == 'n' || optopt == 'd' || optopt == 'f') + { + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + } + else if(isprint(optopt)) + { + fprintf(stderr, "Unknown option '-%c'.\n", optopt); + } + else + { + fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt); + } + return -1; + break; + default: + abort(); return -1;//for parasoft - } - } - return 0; + } + } + return 0; } /** @@ -188,31 +188,31 @@ int read_cli(s_parameters *params, int argc, char **argv) */ int main(int argc, char **argv) { - // Prepare parameters - s_parameters params; - init_params(¶ms); - if(read_cli(¶ms, argc, argv) != 0) { - usage(argv[0]); - exit(-1); - } - - // Launch the child processes - do_forks(params); - - // Register signal handlers - if(signal(SIGINT, quit_handler) == SIG_IGN) - signal(SIGINT, SIG_IGN); // C-c - if(signal(SIGHUP, quit_handler) == SIG_IGN) - signal(SIGHUP, SIG_IGN); // Terminal closed - if(signal(SIGTERM, quit_handler) == SIG_IGN) - signal(SIGTERM, SIG_IGN); // kill (nice) - - printf("Setup done. Listening. My pid: %d\n", getpid()); - fflush(stdout); - - int err = wait_for_death(); - cleanup(); - return err; + // Prepare parameters + s_parameters params; + init_params(¶ms); + if(read_cli(¶ms, argc, argv) != 0) { + usage(argv[0]); + exit(-1); + } + + // Launch the child processes + do_forks(params); + + // Register signal handlers + if(signal(SIGINT, quit_handler) == SIG_IGN) + signal(SIGINT, SIG_IGN); // C-c + if(signal(SIGHUP, quit_handler) == SIG_IGN) + signal(SIGHUP, SIG_IGN); // Terminal closed + if(signal(SIGTERM, quit_handler) == SIG_IGN) + signal(SIGTERM, SIG_IGN); // kill (nice) + + printf("Setup done. Listening. My pid: %d\n", getpid()); + fflush(stdout); + + int err = wait_for_death(); + cleanup(); + return err; } /** @@ -223,34 +223,34 @@ void do_forks(s_parameters params) { int i; - // Launch child processes - for(i=0;iparams.nmsgs; - while(msgs_left-- > 0) - { - DLT_LOG(mycontext, DLT_LOG_INFO, DLT_STRING(PAYLOAD_DATA)); - usleep(mksleep_time(data->params.delay, data->params.delay_fudge)); - } - DLT_UNREGISTER_CONTEXT(mycontext); + snprintf(ctid_name,256, "Child %s in dlt-test-multi-process", ctid); + DLT_REGISTER_CONTEXT(mycontext, ctid, ctid_name); + + int msgs_left = data->params.nmsgs; + while(msgs_left-- > 0) + { + DLT_LOG(mycontext, DLT_LOG_INFO, DLT_STRING(PAYLOAD_DATA)); + usleep(mksleep_time(data->params.delay, data->params.delay_fudge)); + } + DLT_UNREGISTER_CONTEXT(mycontext); } /** @@ -320,39 +320,39 @@ void do_logging(s_thread_data *data) */ void run_threads(s_parameters params) { - pthread_t thread[params.nthreads]; - s_thread_data thread_data; - char apid[5]; - char apid_name[256]; - int i; + pthread_t thread[params.nthreads]; + s_thread_data thread_data; + char apid[5]; + char apid_name[256]; + int i; - srand(getpid()); + srand(getpid()); snprintf(apid,5,"MT%02u", pidcount); snprintf(apid_name,256, "Apps %s.", apid); - DLT_REGISTER_APP(apid, apid_name); + DLT_REGISTER_APP(apid, apid_name); - thread_data.params = params; + thread_data.params = params; - for(i=0;i 0) - { - int status; - pid_t w = waitpid(WAIT_ANY, &status, 0); - if(status < 0) - { - return -1; - } - else - { - unsigned int i; - for(i=0;i 0) + { + int status; + pid_t w = waitpid(WAIT_ANY, &status, 0); + if(status < 0) + { + return -1; + } + else + { + unsigned int i; + for(i=0;i