]>
Commit | Line | Data |
---|---|---|
43313d05 | 1 | /* |
43313d05 | 2 | * This file is part of Quagga. |
3 | * | |
4 | * Quagga is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU General Public License as published by the | |
6 | * Free Software Foundation; either version 2, or (at your option) any | |
7 | * later version. | |
8 | * | |
9 | * Quagga is distributed in the hope that it will be useful, but | |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * General Public License for more details. | |
13 | * | |
896014f4 DL |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; see the file COPYING; if not, write to the Free Software | |
16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
43313d05 | 17 | */ |
18 | ||
19 | /* This programme shows the effects of 'heavy' long-running functions | |
20 | * on the cooperative threading model. | |
21 | * | |
22 | * Run it with a config file containing 'password whatever', telnet to it | |
23 | * (it defaults to port 4000) and enter the 'clear foo string' command. | |
24 | * then type whatever and observe that the vty interface is unresponsive | |
25 | * for quite a period of time, due to the clear_something command | |
26 | * taking a very long time to complete. | |
27 | */ | |
28 | #include <zebra.h> | |
29 | ||
43313d05 | 30 | #include "thread.h" |
31 | #include "vty.h" | |
32 | #include "command.h" | |
33 | #include "memory.h" | |
f4d062f8 | 34 | #include <math.h> |
43313d05 | 35 | |
9fc3f9b3 DL |
36 | #include "tests.h" |
37 | ||
d62a17ae | 38 | enum { ITERS_FIRST = 0, |
39 | ITERS_ERR = 100, | |
40 | ITERS_LATER = 400, | |
41 | ITERS_PRINT = 10, | |
42 | ITERS_MAX = 1000, | |
43313d05 | 43 | }; |
44 | ||
d62a17ae | 45 | static void slow_func(struct vty *vty, const char *str, const int i) |
43313d05 | 46 | { |
d62a17ae | 47 | double x = 1; |
48 | int j; | |
49 | ||
50 | for (j = 0; j < 300; j++) | |
51 | x += sin(x) * j; | |
52 | ||
53 | if ((i % ITERS_LATER) == 0) | |
54 | printf("%s: %d, temporary error, save this somehow and do it later..\n", | |
55 | __func__, i); | |
56 | ||
57 | if ((i % ITERS_ERR) == 0) | |
58 | printf("%s: hard error\n", __func__); | |
59 | ||
60 | if ((i % ITERS_PRINT) == 0) | |
61 | printf("%s did %d, x = %g\n", str, i, x); | |
43313d05 | 62 | } |
63 | ||
d62a17ae | 64 | static void clear_something(struct vty *vty, const char *str) |
43313d05 | 65 | { |
d62a17ae | 66 | int i; |
67 | ||
68 | /* this could be like iterating through 150k of route_table | |
69 | * or worse, iterating through a list of peers, to bgp_stop them with | |
70 | * each having 150k route tables to process... | |
71 | */ | |
72 | for (i = ITERS_FIRST; i < ITERS_MAX; i++) | |
73 | slow_func(vty, str, i); | |
f4d062f8 | 74 | } |
75 | ||
43313d05 | 76 | DEFUN (clear_foo, |
77 | clear_foo_cmd, | |
e961923c | 78 | "clear foo LINE...", |
43313d05 | 79 | "clear command\n" |
80 | "arbitrary string\n") | |
81 | { | |
d62a17ae | 82 | char *str; |
83 | if (!argc) { | |
84 | vty_out(vty, "%% string argument required\n"); | |
85 | return CMD_WARNING; | |
86 | } | |
87 | ||
88 | str = argv_concat(argv, argc, 0); | |
89 | ||
90 | clear_something(vty, str); | |
91 | XFREE(MTYPE_TMP, str); | |
92 | return CMD_SUCCESS; | |
43313d05 | 93 | } |
94 | ||
4d762f26 | 95 | static void slow_vty_init(void) |
43313d05 | 96 | { |
d62a17ae | 97 | install_element(VIEW_NODE, &clear_foo_cmd); |
43313d05 | 98 | } |
99 | ||
4d762f26 | 100 | void test_init(void) |
43313d05 | 101 | { |
d62a17ae | 102 | slow_vty_init(); |
43313d05 | 103 | } |