From dca8ab254aa0a687c32009079d85e4d8f960b213 Mon Sep 17 00:00:00 2001 From: Christoph Lipka Date: Thu, 20 Dec 2018 14:58:19 +0100 Subject: Code beautification using uncrustify Signed-off-by: Christoph Lipka --- src/tests/dlt-test-multi-process.c | 258 ++++++++++++++++++------------------- 1 file changed, 127 insertions(+), 131 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 0726b9a..5b508f3 100644 --- a/src/tests/dlt-test-multi-process.c +++ b/src/tests/dlt-test-multi-process.c @@ -58,30 +58,30 @@ #include "dlt_common.h" #include "dlt-test-multi-process.h" -// Constants +/* Constants */ #define MAX_PROCS 100 #define MAX_THREADS 100 #ifndef WAIT_ANY -#define WAIT_ANY -1 +# define WAIT_ANY -1 #endif -// Structs +/* 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 -void init_params(s_parameters * params); +/* Forward declarations */ +void init_params(s_parameters *params); void quit_handler(int signum); void cleanup(); void do_forks(s_parameters params); @@ -89,10 +89,10 @@ void run_threads(s_parameters params); void do_logging(s_thread_data *data); int wait_for_death(); -// State information +/* State information */ volatile sig_atomic_t in_handler = 0; -// Globals for cleanup from main and signal handler +/* Globals for cleanup from main and signal handler */ pid_t pids[MAX_PROCS]; unsigned int pidcount = 0; @@ -102,7 +102,7 @@ unsigned int pidcount = 0; void usage(char *prog_name) { char version[255]; - dlt_get_version(version,255); + dlt_get_version(version, 255); s_parameters defaults; init_params(&defaults); @@ -120,12 +120,13 @@ void usage(char *prog_name) /** * 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; +void init_params(s_parameters *params) +{ + params->nmsgs = 100; + params->nprocs = 10; + params->nthreads = 2; + params->delay = 1000; + params->delay_fudge = 100; } /** @@ -135,55 +136,52 @@ int read_cli(s_parameters *params, int argc, char **argv) { 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); - } + 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; - default: - abort(); - return -1;//for parasoft + } + + 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; } @@ -192,24 +190,27 @@ int read_cli(s_parameters *params, int argc, char **argv) */ int main(int argc, char **argv) { - // Prepare parameters + /* Prepare parameters */ s_parameters params; init_params(¶ms); - if(read_cli(¶ms, argc, argv) != 0) { + + if (read_cli(¶ms, argc, argv) != 0) { usage(argv[0]); exit(-1); } - // Launch the child processes + /* 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) + /* 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); @@ -227,30 +228,30 @@ void do_forks(s_parameters params) { int i; - // Launch child processes - for(i=0;iparams.nmsgs; - while(msgs_left-- > 0) - { + + 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); } @@ -324,38 +326,34 @@ 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()); - snprintf(apid,5,"MT%02u", pidcount); - snprintf(apid_name,256, "Apps %s.", apid); + snprintf(apid, 5, "MT%02u", pidcount); + snprintf(apid_name, 256, "Apps %s.", apid); DLT_REGISTER_APP(apid, apid_name); - thread_data.params = params; + thread_data.params = params; - for(i=0;i 0) - { + + while (pids_left > 0) { int status; pid_t w = waitpid(WAIT_ANY, &status, 0); - if(status < 0) - { + + if (status < 0) { return -1; } - else - { + else { unsigned int i; - for(i=0;i