]>
git.proxmox.com Git - mirror_frr.git/blob - tests/lib/test_heavy.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 /* This programme shows the effects of 'heavy' long-running functions
6 * on the cooperative threading model.
8 * Run it with a config file containing 'password whatever', telnet to it
9 * (it defaults to port 4000) and enter the 'clear foo string' command.
10 * then type whatever and observe that the vty interface is unresponsive
11 * for quite a period of time, due to the clear_something command
12 * taking a very long time to complete.
24 enum { ITERS_FIRST
= 0,
31 static void slow_func(struct vty
*vty
, const char *str
, const int i
)
36 for (j
= 0; j
< 300; j
++)
39 if ((i
% ITERS_LATER
) == 0)
40 printf("%s: %d, temporary error, save this somehow and do it later..\n",
43 if ((i
% ITERS_ERR
) == 0)
44 printf("%s: hard error\n", __func__
);
46 if ((i
% ITERS_PRINT
) == 0)
47 printf("%s did %d, x = %g\n", str
, i
, x
);
50 static void clear_something(struct vty
*vty
, const char *str
)
54 /* this could be like iterating through 150k of route_table
55 * or worse, iterating through a list of peers, to bgp_stop them with
56 * each having 150k route tables to process...
58 for (i
= ITERS_FIRST
; i
< ITERS_MAX
; i
++)
59 slow_func(vty
, str
, i
);
70 vty_out(vty
, "%% string argument required\n");
74 str
= argv_concat(argv
, argc
, 0);
76 clear_something(vty
, str
);
77 XFREE(MTYPE_TMP
, str
);
81 static void slow_vty_init(void)
83 install_element(VIEW_NODE
, &clear_foo_cmd
);