From 9f3f7a1145a42942b28bae6b68163d805bb91b56 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 25 Apr 2005 16:42:24 +0000 Subject: 2004-05-25 Paul Jakma * main.c: new file, common 'main' portion which then calls test_init. * heavy.c: remove common portions now in 'main. * heavy-wq.c: ditto * heavy-thread.c: ditto * heavy*.c: Set the slow_function iteration number lower, to 300, it was several orders of magnitude too 'slow' to be useful. :) * Makefile.am: main is a source of the tests. heavy should link to the math library. --- tests/heavy-thread.c | 171 ++------------------------------------------------- 1 file changed, 5 insertions(+), 166 deletions(-) (limited to 'tests/heavy-thread.c') diff --git a/tests/heavy-thread.c b/tests/heavy-thread.c index 252c2960..cd3a3b9d 100644 --- a/tests/heavy-thread.c +++ b/tests/heavy-thread.c @@ -1,5 +1,5 @@ /* - * $Id: heavy-thread.c,v 1.1 2005/04/22 00:50:08 paul Exp $ + * $Id: heavy-thread.c,v 1.2 2005/04/25 16:42:24 paul Exp $ * * This file is part of Quagga. * @@ -31,26 +31,13 @@ #include #include -#include -#include "getopt.h" #include "thread.h" #include "vty.h" #include "command.h" #include "memory.h" #include "log.h" -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 } -}; +extern struct thread_master *master; enum { @@ -73,7 +60,7 @@ slow_func (struct vty *vty, const char *str, const int i) double x = 1; int j; - for (j = 0; j < 30000; j++) + for (j = 0; j < 300; j++) x += sin(x)*j; if ((i % ITERS_LATER) == 0) @@ -113,14 +100,6 @@ clear_something (struct thread *thread) return 0; } -DEFUN (daemon_exit, - daemon_exit_cmd, - "daemon-exit", - "Make the daemon exit\n") -{ - exit(0); -} - DEFUN (clear_foo, clear_foo_cmd, "clear foo .LINE", @@ -159,148 +138,8 @@ DEFUN (clear_foo, return CMD_SUCCESS; } -static int timer_count; -int -heavy_timer (struct thread *thread) -{ - int *count = THREAD_ARG(thread); - - printf ("run %d of timer\n", (*count)++); - thread_add_timer (master, heavy_timer, count, 5); - return 0; -} - -static void -heavy_timer_init() -{ - thread_add_timer (master, heavy_timer, &timer_count, 5); -} - -static void -slow_vty_init() +void +test_init() { install_element (VIEW_NODE, &clear_foo_cmd); - install_element (VIEW_NODE, &daemon_exit_cmd); -} - -/* Help information display. */ -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\ -Daemon which does 'slow' things.\n\n\ --d, --daemon Runs in daemon mode\n\ --f, --config_file Set configuration file name\n\ --A, --vty_addr Set vty's bind address\n\ --P, --vty_port Set vty's port number\n\ --v, --version Print program version\n\ --h, --help Display this help and exit\n\ -\n\ -Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS); - } - exit (status); } - - -/* main routine. */ -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 (); - - 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. */ - slow_vty_init (); - - sort_node (); - - /* Change to the daemon program. */ - if (daemon_mode) - daemon (0, 0); - - /* 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); - - heavy_timer_init(); - - /* Fetch next active thread. */ - while (thread_fetch (master, &thread)) - thread_call (&thread); - - /* Not reached. */ - exit (0); -} - -- cgit v1.2.1