diff options
author | whitespace / reindent <invalid@invalid.invalid> | 2017-07-17 14:03:14 +0200 |
---|---|---|
committer | whitespace / reindent <invalid@invalid.invalid> | 2017-07-17 14:04:07 +0200 |
commit | d62a17aedeb0eebdba98238874bb13d62c48dbf9 (patch) | |
tree | 3b319b1d61c8b85b4d1f06adf8b844bb8a9b5107 /tests/helpers | |
parent | *: add indent control files (diff) | |
download | frr-d62a17aedeb0eebdba98238874bb13d62c48dbf9.tar.xz frr-d62a17aedeb0eebdba98238874bb13d62c48dbf9.zip |
*: reindentreindent-master-after
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'tests/helpers')
-rw-r--r-- | tests/helpers/c/main.c | 250 | ||||
-rw-r--r-- | tests/helpers/c/prng.c | 103 | ||||
-rw-r--r-- | tests/helpers/c/prng.h | 10 | ||||
-rw-r--r-- | tests/helpers/c/tests.h | 4 |
4 files changed, 173 insertions, 194 deletions
diff --git a/tests/helpers/c/main.c b/tests/helpers/c/main.c index f842b0372..9bf56dde1 100644 --- a/tests/helpers/c/main.c +++ b/tests/helpers/c/main.c @@ -32,57 +32,50 @@ extern void test_init(); struct thread_master *master; -struct option longopts[] = -{ - { "daemon", no_argument, NULL, 'd'}, - { "config_file", required_argument, NULL, 'f'}, - { "help", no_argument, NULL, 'h'}, - { "vty_addr", required_argument, NULL, 'A'}, - { "vty_port", required_argument, NULL, 'P'}, - { "version", no_argument, NULL, 'v'}, - { 0 } -}; +struct option longopts[] = {{"daemon", no_argument, NULL, 'd'}, + {"config_file", required_argument, NULL, 'f'}, + {"help", no_argument, NULL, 'h'}, + {"vty_addr", required_argument, NULL, 'A'}, + {"vty_port", required_argument, NULL, 'P'}, + {"version", no_argument, NULL, 'v'}, + {0}}; DEFUN (daemon_exit, daemon_exit_cmd, "daemon-exit", "Make the daemon exit\n") { - exit(0); + exit(0); } static int timer_count; -static int -test_timer (struct thread *thread) +static int test_timer(struct thread *thread) { - int *count = THREAD_ARG(thread); - - printf ("run %d of timer\n", (*count)++); - thread_add_timer(master, test_timer, count, 5, NULL); - return 0; + int *count = THREAD_ARG(thread); + + printf("run %d of timer\n", (*count)++); + thread_add_timer(master, test_timer, count, 5, NULL); + return 0; } -static void -test_timer_init() +static void test_timer_init() { - thread_add_timer(master, test_timer, &timer_count, 10, NULL); + thread_add_timer(master, test_timer, &timer_count, 10, NULL); } -static void -test_vty_init() +static void test_vty_init() { - install_element (VIEW_NODE, &daemon_exit_cmd); + install_element(VIEW_NODE, &daemon_exit_cmd); } /* Help information display. */ -static void -usage (char *progname, int status) +static void usage(char *progname, int status) { - if (status != 0) - fprintf (stderr, "Try `%s --help' for more information.\n", progname); - else - { - printf ("Usage : %s [OPTION...]\n\ + if (status != 0) + fprintf(stderr, "Try `%s --help' for more information.\n", + progname); + else { + printf("Usage : %s [OPTION...]\n\ Daemon which does 'slow' things.\n\n\ -d, --daemon Runs in daemon mode\n\ -f, --config_file Set configuration file name\n\ @@ -91,110 +84,105 @@ Daemon which does 'slow' things.\n\n\ -v, --version Print program version\n\ -h, --help Display this help and exit\n\ \n\ -Report bugs to %s\n", progname, FRR_BUG_ADDRESS); - } - exit (status); +Report bugs to %s\n", + progname, FRR_BUG_ADDRESS); + } + exit(status); } /* main routine. */ -int -main (int argc, char **argv) +int main(int argc, char **argv) { - char *p; - char *vty_addr = NULL; - int vty_port = 4000; - int daemon_mode = 0; - char *progname; - struct thread thread; - char *config_file = NULL; - - /* Set umask before anything for security */ - umask (0027); - - /* get program name */ - progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); - - /* master init. */ - master = thread_master_create(NULL); - - while (1) - { - int opt; - - opt = getopt_long (argc, argv, "dhf:A:P:v", longopts, 0); - - if (opt == EOF) - break; - - switch (opt) - { - case 0: - break; - case 'f': - config_file = optarg; - break; - case 'd': - daemon_mode = 1; - break; - case 'A': - vty_addr = optarg; - break; - case 'P': - /* Deal with atoi() returning 0 on failure */ - if (strcmp(optarg, "0") == 0) - { - vty_port = 0; - break; - } - vty_port = atoi (optarg); - vty_port = (vty_port ? vty_port : 4000); - break; - case 'v': - print_version (progname); - exit (0); - break; - case 'h': - usage (progname, 0); - break; - default: - usage (progname, 1); - break; + char *p; + char *vty_addr = NULL; + int vty_port = 4000; + int daemon_mode = 0; + char *progname; + struct thread thread; + char *config_file = NULL; + + /* Set umask before anything for security */ + umask(0027); + + /* get program name */ + progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]); + + /* master init. */ + master = thread_master_create(NULL); + + while (1) { + int opt; + + opt = getopt_long(argc, argv, "dhf:A:P:v", longopts, 0); + + if (opt == EOF) + break; + + switch (opt) { + case 0: + break; + case 'f': + config_file = optarg; + break; + case 'd': + daemon_mode = 1; + break; + case 'A': + vty_addr = optarg; + break; + case 'P': + /* Deal with atoi() returning 0 on failure */ + if (strcmp(optarg, "0") == 0) { + vty_port = 0; + break; + } + vty_port = atoi(optarg); + vty_port = (vty_port ? vty_port : 4000); + break; + case 'v': + print_version(progname); + exit(0); + break; + case 'h': + usage(progname, 0); + break; + default: + usage(progname, 1); + break; + } } - } - - /* Library inits. */ - cmd_init (1); - vty_init (master); - memory_init (); - - /* OSPF vty inits. */ - test_vty_init (); - - /* Change to the daemon program. */ - if (daemon_mode && daemon (0, 0) < 0) - { - fprintf(stderr, "daemon failed: %s", strerror(errno)); - exit (1); - } - - /* Create VTY socket */ - vty_serv_sock (vty_addr, vty_port, "/tmp/.heavy.sock"); - - /* Configuration file read*/ - if (!config_file) - usage (progname, 1); - vty_read_config (config_file, NULL); - - test_timer_init(); - - test_init(); - - /* Fetch next active thread. */ - while (thread_fetch (master, &thread)) - thread_call (&thread); - - /* Not reached. */ - exit (0); -} + /* Library inits. */ + cmd_init(1); + vty_init(master); + memory_init(); + + /* OSPF vty inits. */ + test_vty_init(); + + /* Change to the daemon program. */ + if (daemon_mode && daemon(0, 0) < 0) { + fprintf(stderr, "daemon failed: %s", strerror(errno)); + exit(1); + } + + /* Create VTY socket */ + vty_serv_sock(vty_addr, vty_port, "/tmp/.heavy.sock"); + + /* Configuration file read*/ + if (!config_file) + usage(progname, 1); + vty_read_config(config_file, NULL); + + test_timer_init(); + + test_init(); + + /* Fetch next active thread. */ + while (thread_fetch(master, &thread)) + thread_call(&thread); + + /* Not reached. */ + exit(0); +} diff --git a/tests/helpers/c/prng.c b/tests/helpers/c/prng.c index 0f78366fc..e2173d451 100644 --- a/tests/helpers/c/prng.c +++ b/tests/helpers/c/prng.c @@ -31,20 +31,18 @@ #include "prng.h" -struct prng -{ - uint64_t state; +struct prng { + uint64_t state; }; -struct prng* -prng_new(unsigned long long seed) +struct prng *prng_new(unsigned long long seed) { - struct prng *rv = calloc(sizeof(*rv), 1); - assert(rv); + struct prng *rv = calloc(sizeof(*rv), 1); + assert(rv); - rv->state = seed; + rv->state = seed; - return rv; + return rv; } /* @@ -54,62 +52,57 @@ prng_new(unsigned long long seed) * It is a simple LCG which D.E. Knuth attributes to C.E. Haynes in * TAOCP Vol2 3.3.4 */ -int -prng_rand(struct prng *prng) +int prng_rand(struct prng *prng) { - prng->state = 6364136223846793005ULL*prng->state + 1; - return prng->state>>33; + prng->state = 6364136223846793005ULL * prng->state + 1; + return prng->state >> 33; } -const char * -prng_fuzz(struct prng *prng, - const char *string, - const char *charset, - unsigned int operations) +const char *prng_fuzz(struct prng *prng, const char *string, + const char *charset, unsigned int operations) { - static char buf[256]; - unsigned int charset_len; - unsigned int i; - unsigned int offset; - unsigned int op; - unsigned int character; + static char buf[256]; + unsigned int charset_len; + unsigned int i; + unsigned int offset; + unsigned int op; + unsigned int character; - assert(strlen(string) < sizeof(buf)); + assert(strlen(string) < sizeof(buf)); - strncpy(buf, string, sizeof(buf)); - charset_len = strlen(charset); + strncpy(buf, string, sizeof(buf)); + charset_len = strlen(charset); - for (i = 0; i < operations; i++) - { - offset = prng_rand(prng) % strlen(buf); - op = prng_rand(prng) % 3; + for (i = 0; i < operations; i++) { + offset = prng_rand(prng) % strlen(buf); + op = prng_rand(prng) % 3; - switch (op) - { - case 0: - /* replace */ - character = prng_rand(prng) % charset_len; - buf[offset] = charset[character]; - break; - case 1: - /* remove */ - memmove(buf + offset, buf + offset + 1, strlen(buf) - offset); - break; - case 2: - /* insert */ - assert(strlen(buf) + 1 < sizeof(buf)); + switch (op) { + case 0: + /* replace */ + character = prng_rand(prng) % charset_len; + buf[offset] = charset[character]; + break; + case 1: + /* remove */ + memmove(buf + offset, buf + offset + 1, + strlen(buf) - offset); + break; + case 2: + /* insert */ + assert(strlen(buf) + 1 < sizeof(buf)); - memmove(buf + offset + 1, buf + offset, strlen(buf) + 1 - offset); - character = prng_rand(prng) % charset_len; - buf[offset] = charset[character]; - break; - } - } - return buf; + memmove(buf + offset + 1, buf + offset, + strlen(buf) + 1 - offset); + character = prng_rand(prng) % charset_len; + buf[offset] = charset[character]; + break; + } + } + return buf; } -void -prng_free(struct prng *prng) +void prng_free(struct prng *prng) { - free(prng); + free(prng); } diff --git a/tests/helpers/c/prng.h b/tests/helpers/c/prng.h index 7b2ab924e..23f702b07 100644 --- a/tests/helpers/c/prng.h +++ b/tests/helpers/c/prng.h @@ -26,12 +26,10 @@ struct prng; -struct prng* prng_new(unsigned long long seed); -int prng_rand(struct prng*); -const char * prng_fuzz(struct prng*, - const char *string, - const char *charset, - unsigned int operations); +struct prng *prng_new(unsigned long long seed); +int prng_rand(struct prng *); +const char *prng_fuzz(struct prng *, const char *string, const char *charset, + unsigned int operations); void prng_free(struct prng *); #endif diff --git a/tests/helpers/c/tests.h b/tests/helpers/c/tests.h index aaf35c27d..53e9c7844 100644 --- a/tests/helpers/c/tests.h +++ b/tests/helpers/c/tests.h @@ -24,7 +24,7 @@ #ifndef _QUAGGA_TESTS_H #define _QUAGGA_TESTS_H -extern void test_init (void); -extern void test_init_cmd (void); +extern void test_init(void); +extern void test_init_cmd(void); #endif /* _QUAGGA_TESTS_H */ |