summaryrefslogtreecommitdiff
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/cli/common_cli.c83
-rw-r--r--tests/lib/cli/common_cli.h22
-rw-r--r--tests/lib/cli/test_cli.c62
-rw-r--r--tests/lib/cli/test_commands.c575
-rw-r--r--tests/lib/test_buffer.c58
-rw-r--r--tests/lib/test_checksum.c694
-rw-r--r--tests/lib/test_heavy.c97
-rw-r--r--tests/lib/test_heavy_thread.c156
-rw-r--r--tests/lib/test_heavy_wq.c197
-rw-r--r--tests/lib/test_memory.c148
-rw-r--r--tests/lib/test_nexthop_iter.c359
-rw-r--r--tests/lib/test_privs.c192
-rw-r--r--tests/lib/test_segv.c33
-rw-r--r--tests/lib/test_sig.c68
-rw-r--r--tests/lib/test_srcdest_table.c629
-rw-r--r--tests/lib/test_stream.c83
-rw-r--r--tests/lib/test_table.c710
-rw-r--r--tests/lib/test_timer_correctness.c242
-rw-r--r--tests/lib/test_timer_performance.c116
19 files changed, 2149 insertions, 2375 deletions
diff --git a/tests/lib/cli/common_cli.c b/tests/lib/cli/common_cli.c
index 56db460438..93d6382a63 100644
--- a/tests/lib/cli/common_cli.c
+++ b/tests/lib/cli/common_cli.c
@@ -33,65 +33,62 @@
struct thread_master *master;
-int dump_args(struct vty *vty, const char *descr,
- int argc, struct cmd_token *argv[])
+int dump_args(struct vty *vty, const char *descr, int argc,
+ struct cmd_token *argv[])
{
- int i;
- vty_out (vty, "%s with %d args.%s", descr, argc, VTY_NEWLINE);
- for (i = 0; i < argc; i++)
- {
- vty_out (vty, "[%02d]: %s%s", i, argv[i]->arg, VTY_NEWLINE);
- }
-
- return CMD_SUCCESS;
+ int i;
+ vty_out(vty, "%s with %d args.%s", descr, argc, VTY_NEWLINE);
+ for (i = 0; i < argc; i++) {
+ vty_out(vty, "[%02d]: %s%s", i, argv[i]->arg, VTY_NEWLINE);
+ }
+
+ return CMD_SUCCESS;
}
static void vty_do_exit(void)
{
- printf ("\nend.\n");
- cmd_terminate ();
- vty_terminate ();
- thread_master_free (master);
- closezlog ();
-
- log_memstats_stderr ("testcli");
- exit (0);
+ printf("\nend.\n");
+ cmd_terminate();
+ vty_terminate();
+ thread_master_free(master);
+ closezlog();
+
+ log_memstats_stderr("testcli");
+ exit(0);
}
/* main routine. */
-int
-main (int argc, char **argv)
+int main(int argc, char **argv)
{
- struct thread thread;
+ struct thread thread;
- /* Set umask before anything for security */
- umask (0027);
+ /* Set umask before anything for security */
+ umask(0027);
- /* master init. */
- master = thread_master_create ();
+ /* master init. */
+ master = thread_master_create();
- openzlog("common-cli", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID,
- LOG_DAEMON);
- zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
- zlog_set_level(ZLOG_DEST_STDOUT, ZLOG_DISABLED);
- zlog_set_level(ZLOG_DEST_MONITOR, LOG_DEBUG);
+ openzlog("common-cli", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID,
+ LOG_DAEMON);
+ zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
+ zlog_set_level(ZLOG_DEST_STDOUT, ZLOG_DISABLED);
+ zlog_set_level(ZLOG_DEST_MONITOR, LOG_DEBUG);
- /* Library inits. */
- cmd_init (1);
- cmd_hostname_set ("test");
+ /* Library inits. */
+ cmd_init(1);
+ cmd_hostname_set("test");
- vty_init (master);
- memory_init ();
+ vty_init(master);
+ memory_init();
- test_init (argc, argv);
+ test_init(argc, argv);
- vty_stdio (vty_do_exit);
+ vty_stdio(vty_do_exit);
- /* Fetch next active thread. */
- while (thread_fetch (master, &thread))
- thread_call (&thread);
+ /* Fetch next active thread. */
+ while (thread_fetch(master, &thread))
+ thread_call(&thread);
- /* Not reached. */
- exit (0);
+ /* Not reached. */
+ exit(0);
}
-
diff --git a/tests/lib/cli/common_cli.h b/tests/lib/cli/common_cli.h
index 9e7fe99830..6ca1f1ba84 100644
--- a/tests/lib/cli/common_cli.h
+++ b/tests/lib/cli/common_cli.h
@@ -28,22 +28,24 @@
#include "command.h"
/* function to be implemented by test */
-extern void test_init (int argc, char **argv);
+extern void test_init(int argc, char **argv);
/* functions provided by common cli
* (includes main())
*/
extern struct thread_master *master;
-extern int dump_args(struct vty *vty, const char *descr,
- int argc, struct cmd_token *argv[]);
+extern int dump_args(struct vty *vty, const char *descr, int argc,
+ struct cmd_token *argv[]);
-#define DUMMY_HELPSTR \
- "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n" \
- "10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n" \
- "20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n"
-#define DUMMY_DEFUN(name, cmdstr) \
- DEFUN (name, name ## _cmd, cmdstr, DUMMY_HELPSTR) \
- { return dump_args(vty, #name, argc, argv); }
+#define DUMMY_HELPSTR \
+ "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n" \
+ "10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n" \
+ "20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n"
+#define DUMMY_DEFUN(name, cmdstr) \
+ DEFUN(name, name##_cmd, cmdstr, DUMMY_HELPSTR) \
+ { \
+ return dump_args(vty, #name, argc, argv); \
+ }
#endif /* _COMMON_CLI_H */
diff --git a/tests/lib/cli/test_cli.c b/tests/lib/cli/test_cli.c
index 54b34bc799..c8762362e4 100644
--- a/tests/lib/cli/test_cli.c
+++ b/tests/lib/cli/test_cli.c
@@ -24,15 +24,15 @@
#include "common_cli.h"
-DUMMY_DEFUN(cmd0, "arg ipv4 A.B.C.D");
-DUMMY_DEFUN(cmd1, "arg ipv4m A.B.C.D/M");
-DUMMY_DEFUN(cmd2, "arg ipv6 X:X::X:X");
-DUMMY_DEFUN(cmd3, "arg ipv6m X:X::X:X/M");
-DUMMY_DEFUN(cmd4, "arg range (5-15)");
-DUMMY_DEFUN(cmd5, "pat a < a|b>");
-DUMMY_DEFUN(cmd7, "pat c <a | b|c> A.B.C.D");
-DUMMY_DEFUN(cmd8, "pat d { foo A.B.C.D|bar X:X::X:X| baz }");
-DUMMY_DEFUN(cmd9, "pat e [ WORD ]");
+DUMMY_DEFUN(cmd0, "arg ipv4 A.B.C.D");
+DUMMY_DEFUN(cmd1, "arg ipv4m A.B.C.D/M");
+DUMMY_DEFUN(cmd2, "arg ipv6 X:X::X:X");
+DUMMY_DEFUN(cmd3, "arg ipv6m X:X::X:X/M");
+DUMMY_DEFUN(cmd4, "arg range (5-15)");
+DUMMY_DEFUN(cmd5, "pat a < a|b>");
+DUMMY_DEFUN(cmd7, "pat c <a | b|c> A.B.C.D");
+DUMMY_DEFUN(cmd8, "pat d { foo A.B.C.D|bar X:X::X:X| baz }");
+DUMMY_DEFUN(cmd9, "pat e [ WORD ]");
DUMMY_DEFUN(cmd10, "pat f [key]");
DUMMY_DEFUN(cmd11, "alt a WORD");
DUMMY_DEFUN(cmd12, "alt a A.B.C.D");
@@ -40,27 +40,27 @@ DUMMY_DEFUN(cmd13, "alt a X:X::X:X");
void test_init(int argc, char **argv)
{
- size_t repeat = argc > 1 ? strtoul(argv[1], NULL, 0) : 223;
+ size_t repeat = argc > 1 ? strtoul(argv[1], NULL, 0) : 223;
- install_element (ENABLE_NODE, &cmd0_cmd);
- install_element (ENABLE_NODE, &cmd1_cmd);
- install_element (ENABLE_NODE, &cmd2_cmd);
- install_element (ENABLE_NODE, &cmd3_cmd);
- install_element (ENABLE_NODE, &cmd4_cmd);
- install_element (ENABLE_NODE, &cmd5_cmd);
- install_element (ENABLE_NODE, &cmd7_cmd);
- install_element (ENABLE_NODE, &cmd8_cmd);
- install_element (ENABLE_NODE, &cmd9_cmd);
- install_element (ENABLE_NODE, &cmd10_cmd);
- install_element (ENABLE_NODE, &cmd11_cmd);
- install_element (ENABLE_NODE, &cmd12_cmd);
- install_element (ENABLE_NODE, &cmd13_cmd);
- for (size_t i = 0; i < repeat; i++) {
- uninstall_element (ENABLE_NODE, &cmd5_cmd);
- install_element (ENABLE_NODE, &cmd5_cmd);
- }
- for (size_t i = 0; i < repeat; i++) {
- uninstall_element (ENABLE_NODE, &cmd13_cmd);
- install_element (ENABLE_NODE, &cmd13_cmd);
- }
+ install_element(ENABLE_NODE, &cmd0_cmd);
+ install_element(ENABLE_NODE, &cmd1_cmd);
+ install_element(ENABLE_NODE, &cmd2_cmd);
+ install_element(ENABLE_NODE, &cmd3_cmd);
+ install_element(ENABLE_NODE, &cmd4_cmd);
+ install_element(ENABLE_NODE, &cmd5_cmd);
+ install_element(ENABLE_NODE, &cmd7_cmd);
+ install_element(ENABLE_NODE, &cmd8_cmd);
+ install_element(ENABLE_NODE, &cmd9_cmd);
+ install_element(ENABLE_NODE, &cmd10_cmd);
+ install_element(ENABLE_NODE, &cmd11_cmd);
+ install_element(ENABLE_NODE, &cmd12_cmd);
+ install_element(ENABLE_NODE, &cmd13_cmd);
+ for (size_t i = 0; i < repeat; i++) {
+ uninstall_element(ENABLE_NODE, &cmd5_cmd);
+ install_element(ENABLE_NODE, &cmd5_cmd);
+ }
+ for (size_t i = 0; i < repeat; i++) {
+ uninstall_element(ENABLE_NODE, &cmd13_cmd);
+ install_element(ENABLE_NODE, &cmd13_cmd);
+ }
}
diff --git a/tests/lib/cli/test_commands.c b/tests/lib/cli/test_commands.c
index 272e3d12b7..4bbddb5741 100644
--- a/tests/lib/cli/test_commands.c
+++ b/tests/lib/cli/test_commands.c
@@ -49,360 +49,297 @@ struct thread_master *master; /* dummy for libfrr*/
static vector test_cmds;
static char test_buf[32768];
-static struct cmd_node bgp_node =
-{
- BGP_NODE,
- "%s(config-router)# ",
+static struct cmd_node bgp_node = {
+ BGP_NODE, "%s(config-router)# ",
};
-static struct cmd_node rip_node =
-{
- RIP_NODE,
- "%s(config-router)# ",
+static struct cmd_node rip_node = {
+ RIP_NODE, "%s(config-router)# ",
};
-static struct cmd_node isis_node =
-{
- ISIS_NODE,
- "%s(config-router)# ",
+static struct cmd_node isis_node = {
+ ISIS_NODE, "%s(config-router)# ",
};
-static struct cmd_node interface_node =
-{
- INTERFACE_NODE,
- "%s(config-if)# ",
+static struct cmd_node interface_node = {
+ INTERFACE_NODE, "%s(config-if)# ",
};
-static struct cmd_node rmap_node =
-{
- RMAP_NODE,
- "%s(config-route-map)# "
-};
+static struct cmd_node rmap_node = {RMAP_NODE, "%s(config-route-map)# "};
-static struct cmd_node zebra_node =
-{
- ZEBRA_NODE,
- "%s(config-router)# "
-};
+static struct cmd_node zebra_node = {ZEBRA_NODE, "%s(config-router)# "};
-static struct cmd_node bgp_vpnv4_node =
-{
- BGP_VPNV4_NODE,
- "%s(config-router-af)# "
-};
+static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE,
+ "%s(config-router-af)# "};
-static struct cmd_node bgp_ipv4_node =
-{
- BGP_IPV4_NODE,
- "%s(config-router-af)# "
-};
+static struct cmd_node bgp_ipv4_node = {BGP_IPV4_NODE,
+ "%s(config-router-af)# "};
-static struct cmd_node bgp_ipv4m_node =
-{
- BGP_IPV4M_NODE,
- "%s(config-router-af)# "
-};
+static struct cmd_node bgp_ipv4m_node = {BGP_IPV4M_NODE,
+ "%s(config-router-af)# "};
-static struct cmd_node bgp_ipv6_node =
-{
- BGP_IPV6_NODE,
- "%s(config-router-af)# "
-};
+static struct cmd_node bgp_ipv6_node = {BGP_IPV6_NODE,
+ "%s(config-router-af)# "};
-static struct cmd_node bgp_ipv6m_node =
-{
- BGP_IPV6M_NODE,
- "%s(config-router-af)# "
-};
+static struct cmd_node bgp_ipv6m_node = {BGP_IPV6M_NODE,
+ "%s(config-router-af)# "};
-static struct cmd_node ospf_node =
-{
- OSPF_NODE,
- "%s(config-router)# "
-};
+static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# "};
-static struct cmd_node ripng_node =
-{
- RIPNG_NODE,
- "%s(config-router)# "
-};
+static struct cmd_node ripng_node = {RIPNG_NODE, "%s(config-router)# "};
-static struct cmd_node ospf6_node =
-{
- OSPF6_NODE,
- "%s(config-ospf6)# "
-};
+static struct cmd_node ospf6_node = {OSPF6_NODE, "%s(config-ospf6)# "};
-static struct cmd_node keychain_node =
-{
- KEYCHAIN_NODE,
- "%s(config-keychain)# "
-};
+static struct cmd_node keychain_node = {KEYCHAIN_NODE, "%s(config-keychain)# "};
-static struct cmd_node keychain_key_node =
-{
- KEYCHAIN_KEY_NODE,
- "%s(config-keychain-key)# "
-};
+static struct cmd_node keychain_key_node = {KEYCHAIN_KEY_NODE,
+ "%s(config-keychain-key)# "};
-static int
-test_callback(const struct cmd_element *cmd, struct vty *vty, int argc, struct cmd_token *argv[])
+static int test_callback(const struct cmd_element *cmd, struct vty *vty,
+ int argc, struct cmd_token *argv[])
{
- int offset;
- int rv;
- int i;
-
- offset = 0;
- rv = snprintf(test_buf, sizeof(test_buf), "'%s'", cmd->string);
- if (rv < 0)
- abort();
-
- offset += rv;
-
- for (i = 0; i < argc; i++)
- {
- rv = snprintf(test_buf + offset, sizeof(test_buf) - offset, "%s'%s'",
- (i == 0) ? ": " : ", ", argv[i]->arg);
- if (rv < 0)
- abort();
- offset += rv;
- }
-
- return CMD_SUCCESS;
+ int offset;
+ int rv;
+ int i;
+
+ offset = 0;
+ rv = snprintf(test_buf, sizeof(test_buf), "'%s'", cmd->string);
+ if (rv < 0)
+ abort();
+
+ offset += rv;
+
+ for (i = 0; i < argc; i++) {
+ rv = snprintf(test_buf + offset, sizeof(test_buf) - offset,
+ "%s'%s'", (i == 0) ? ": " : ", ", argv[i]->arg);
+ if (rv < 0)
+ abort();
+ offset += rv;
+ }
+
+ return CMD_SUCCESS;
}
-static void
-test_load(void)
+static void test_load(void)
{
- char line[4096];
-
- test_cmds = vector_init(VECTOR_MIN_SIZE);
-
- while (fgets(line, sizeof(line), stdin) != NULL)
- {
- if (strlen(line))
- line[strlen(line) - 1] = '\0';
- if (line[0] == '#')
- continue;
- vector_set(test_cmds, XSTRDUP(MTYPE_STRVEC, line));
- }
+ char line[4096];
+
+ test_cmds = vector_init(VECTOR_MIN_SIZE);
+
+ while (fgets(line, sizeof(line), stdin) != NULL) {
+ if (strlen(line))
+ line[strlen(line) - 1] = '\0';
+ if (line[0] == '#')
+ continue;
+ vector_set(test_cmds, XSTRDUP(MTYPE_STRVEC, line));
+ }
}
-static void
-test_init(void)
+static void test_init(void)
{
- unsigned int node;
- unsigned int i;
- struct cmd_node *cnode;
- struct cmd_element *cmd;
-
- cmd_init(1);
-
- install_node (&bgp_node, NULL);
- install_node (&rip_node, NULL);
- install_node (&interface_node, NULL);
- install_node (&rmap_node, NULL);
- install_node (&zebra_node, NULL);
- install_node (&bgp_vpnv4_node, NULL);
- install_node (&bgp_ipv4_node, NULL);
- install_node (&bgp_ipv4m_node, NULL);
- install_node (&bgp_ipv6_node, NULL);
- install_node (&bgp_ipv6m_node, NULL);
- install_node (&ospf_node, NULL);
- install_node (&ripng_node, NULL);
- install_node (&ospf6_node, NULL);
- install_node (&keychain_node, NULL);
- install_node (&keychain_key_node, NULL);
- install_node (&isis_node, NULL);
- install_node (&vty_node, NULL);
-
- test_init_cmd();
-
- for (node = 0; node < vector_active(cmdvec); node++)
- if ((cnode = vector_slot(cmdvec, node)) != NULL)
- for (i = 0; i < vector_active(cnode->cmd_vector); i++)
- if ((cmd = vector_slot(cnode->cmd_vector, i)) != NULL)
- {
- cmd->daemon = 0;
- cmd->func = test_callback;
- }
- test_load();
- vty_init_vtysh();
+ unsigned int node;
+ unsigned int i;
+ struct cmd_node *cnode;
+ struct cmd_element *cmd;
+
+ cmd_init(1);
+
+ install_node(&bgp_node, NULL);
+ install_node(&rip_node, NULL);
+ install_node(&interface_node, NULL);
+ install_node(&rmap_node, NULL);
+ install_node(&zebra_node, NULL);
+ install_node(&bgp_vpnv4_node, NULL);
+ install_node(&bgp_ipv4_node, NULL);
+ install_node(&bgp_ipv4m_node, NULL);
+ install_node(&bgp_ipv6_node, NULL);
+ install_node(&bgp_ipv6m_node, NULL);
+ install_node(&ospf_node, NULL);
+ install_node(&ripng_node, NULL);
+ install_node(&ospf6_node, NULL);
+ install_node(&keychain_node, NULL);
+ install_node(&keychain_key_node, NULL);
+ install_node(&isis_node, NULL);
+ install_node(&vty_node, NULL);
+
+ test_init_cmd();
+
+ for (node = 0; node < vector_active(cmdvec); node++)
+ if ((cnode = vector_slot(cmdvec, node)) != NULL)
+ for (i = 0; i < vector_active(cnode->cmd_vector); i++)
+ if ((cmd = vector_slot(cnode->cmd_vector, i))
+ != NULL) {
+ cmd->daemon = 0;
+ cmd->func = test_callback;
+ }
+ test_load();
+ vty_init_vtysh();
}
-static void
-test_terminate(void)
+static void test_terminate(void)
{
- unsigned int i;
+ unsigned int i;
- vty_terminate();
- for (i = 0; i < vector_active(test_cmds); i++)
- XFREE(MTYPE_STRVEC, vector_slot(test_cmds, i));
- vector_free(test_cmds);
- cmd_terminate();
+ vty_terminate();
+ for (i = 0; i < vector_active(test_cmds); i++)
+ XFREE(MTYPE_STRVEC, vector_slot(test_cmds, i));
+ vector_free(test_cmds);
+ cmd_terminate();
}
-static void
-test_run(struct prng *prng, struct vty *vty, const char *cmd, unsigned int edit_dist, unsigned int node_index, int verbose)
+static void test_run(struct prng *prng, struct vty *vty, const char *cmd,
+ unsigned int edit_dist, unsigned int node_index,
+ int verbose)
{
- const char *test_str;
- vector vline;
- int ret;
- unsigned int i;
- char **completions;
- unsigned int j;
- struct cmd_node *cnode;
- vector descriptions;
- int appended_null;
- int no_match;
-
- test_str = prng_fuzz(prng, cmd, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_:. /", edit_dist);
- vline = cmd_make_strvec(test_str);
-
- if (vline == NULL)
- return;
-
- appended_null = 0;
- for (i = 0; i < vector_active(cmdvec); i++)
- if ((cnode = vector_slot(cmdvec, i)) != NULL)
- {
- if (node_index != (unsigned int)-1 && i != node_index)
- continue;
-
- if (appended_null)
- {
- vector_unset(vline, vector_active(vline) - 1);
- appended_null = 0;
- }
- vty->node = cnode->node;
- test_buf[0] = '\0';
- ret = cmd_execute_command(vline, vty, NULL, 0);
- no_match = (ret == CMD_ERR_NO_MATCH);
- if (verbose || !no_match)
- printf("execute relaxed '%s'@%d: rv==%d%s%s\n",
- test_str,
- cnode->node,
- ret,
- (test_buf[0] != '\0') ? ", " : "",
- test_buf);
-
- vty->node = cnode->node;
- test_buf[0] = '\0';
- ret = cmd_execute_command_strict(vline, vty, NULL);
- if (verbose || !no_match)
- printf("execute strict '%s'@%d: rv==%d%s%s\n",
- test_str,
- cnode->node,
- ret,
- (test_buf[0] != '\0') ? ", " : "",
- test_buf);
-
- if (isspace((int) test_str[strlen(test_str) - 1]))
- {
- vector_set (vline, NULL);
- appended_null = 1;
- }
-
- vty->node = cnode->node;
- completions = cmd_complete_command(vline, vty, &ret);
- if (verbose || !no_match)
- printf("complete '%s'@%d: rv==%d\n",
- test_str,
- cnode->node,
- ret);
- if (completions != NULL)
- {
- for (j = 0; completions[j] != NULL; j++)
- {
- printf(" '%s'\n", completions[j]);
- XFREE(MTYPE_TMP, completions[j]);
- }
- XFREE(MTYPE_TMP, completions);
- }
-
- vty->node = cnode->node;
- descriptions = cmd_describe_command(vline, vty, &ret);
- if (verbose || !no_match)
- printf("describe '%s'@%d: rv==%d\n",
- test_str,
- cnode->node,
- ret);
- if (descriptions != NULL)
- {
- for (j = 0; j < vector_active(descriptions); j++)
- {
- struct cmd_token *cmd = vector_slot(descriptions, j);
- printf(" '%s' '%s'\n", cmd->text, cmd->desc);
- }
- vector_free(descriptions);
- }
- }
- cmd_free_strvec(vline);
+ const char *test_str;
+ vector vline;
+ int ret;
+ unsigned int i;
+ char **completions;
+ unsigned int j;
+ struct cmd_node *cnode;
+ vector descriptions;
+ int appended_null;
+ int no_match;
+
+ test_str = prng_fuzz(
+ prng, cmd,
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_:. /",
+ edit_dist);
+ vline = cmd_make_strvec(test_str);
+
+ if (vline == NULL)
+ return;
+
+ appended_null = 0;
+ for (i = 0; i < vector_active(cmdvec); i++)
+ if ((cnode = vector_slot(cmdvec, i)) != NULL) {
+ if (node_index != (unsigned int)-1 && i != node_index)
+ continue;
+
+ if (appended_null) {
+ vector_unset(vline, vector_active(vline) - 1);
+ appended_null = 0;
+ }
+ vty->node = cnode->node;
+ test_buf[0] = '\0';
+ ret = cmd_execute_command(vline, vty, NULL, 0);
+ no_match = (ret == CMD_ERR_NO_MATCH);
+ if (verbose || !no_match)
+ printf("execute relaxed '%s'@%d: rv==%d%s%s\n",
+ test_str, cnode->node, ret,
+ (test_buf[0] != '\0') ? ", " : "",
+ test_buf);
+
+ vty->node = cnode->node;
+ test_buf[0] = '\0';
+ ret = cmd_execute_command_strict(vline, vty, NULL);
+ if (verbose || !no_match)
+ printf("execute strict '%s'@%d: rv==%d%s%s\n",
+ test_str, cnode->node, ret,
+ (test_buf[0] != '\0') ? ", " : "",
+ test_buf);
+
+ if (isspace((int)test_str[strlen(test_str) - 1])) {
+ vector_set(vline, NULL);
+ appended_null = 1;
+ }
+
+ vty->node = cnode->node;
+ completions = cmd_complete_command(vline, vty, &ret);
+ if (verbose || !no_match)
+ printf("complete '%s'@%d: rv==%d\n", test_str,
+ cnode->node, ret);
+ if (completions != NULL) {
+ for (j = 0; completions[j] != NULL; j++) {
+ printf(" '%s'\n", completions[j]);
+ XFREE(MTYPE_TMP, completions[j]);
+ }
+ XFREE(MTYPE_TMP, completions);
+ }
+
+ vty->node = cnode->node;
+ descriptions = cmd_describe_command(vline, vty, &ret);
+ if (verbose || !no_match)
+ printf("describe '%s'@%d: rv==%d\n", test_str,
+ cnode->node, ret);
+ if (descriptions != NULL) {
+ for (j = 0; j < vector_active(descriptions);
+ j++) {
+ struct cmd_token *cmd =
+ vector_slot(descriptions, j);
+ printf(" '%s' '%s'\n", cmd->text,
+ cmd->desc);
+ }
+ vector_free(descriptions);
+ }
+ }
+ cmd_free_strvec(vline);
}
-int
-main(int argc, char **argv)
+int main(int argc, char **argv)
{
- int opt;
- struct prng *prng;
- struct vty *vty;
- unsigned int edit_distance;
- unsigned int max_edit_distance;
- unsigned int node_index;
- int verbose;
- unsigned int test_cmd;
- unsigned int iteration;
- unsigned int num_iterations;
-
- max_edit_distance = 3;
- node_index = -1;
- verbose = 0;
-
- while ((opt = getopt(argc, argv, "e:n:v")) != -1)
- {
- switch (opt)
- {
- case 'e':
- max_edit_distance = atoi(optarg);
- break;
- case 'n':
- node_index = atoi(optarg);
- break;
- case 'v':
- verbose++;
- break;
- default:
- fprintf(stderr, "Usage: %s [-e <edit_dist>] [-n <node_idx>] [-v]\n", argv[0]);
- exit(1);
- break;
- }
- }
-
- test_init();
- prng = prng_new(0);
-
- vty = vty_new();
- vty->type = VTY_TERM;
-
- fprintf(stderr, "Progress:\n0/%u", vector_active(test_cmds));
- for (test_cmd = 0; test_cmd < vector_active(test_cmds); test_cmd++)
- {
- for (edit_distance = 0;
- edit_distance <= max_edit_distance;
- edit_distance++)
- {
- num_iterations = 1 << edit_distance;
- num_iterations *= num_iterations * num_iterations;
-
- for (iteration = 0; iteration < num_iterations; iteration++)
- test_run(prng, vty, vector_slot(test_cmds, test_cmd), edit_distance, node_index, verbose);
- }
- fprintf(stderr, "\r%u/%u", test_cmd + 1, vector_active(test_cmds));
- }
- fprintf(stderr, "\nDone.\n");
-
- vty_close(vty);
- prng_free(prng);
- test_terminate();
- return 0;
+ int opt;
+ struct prng *prng;
+ struct vty *vty;
+ unsigned int edit_distance;
+ unsigned int max_edit_distance;
+ unsigned int node_index;
+ int verbose;
+ unsigned int test_cmd;
+ unsigned int iteration;
+ unsigned int num_iterations;
+
+ max_edit_distance = 3;
+ node_index = -1;
+ verbose = 0;
+
+ while ((opt = getopt(argc, argv, "e:n:v")) != -1) {
+ switch (opt) {
+ case 'e':
+ max_edit_distance = atoi(optarg);
+ break;
+ case 'n':
+ node_index = atoi(optarg);
+ break;
+ case 'v':
+ verbose++;
+ break;
+ default:
+ fprintf(stderr,
+ "Usage: %s [-e <edit_dist>] [-n <node_idx>] [-v]\n",
+ argv[0]);
+ exit(1);
+ break;
+ }
+ }
+
+ test_init();
+ prng = prng_new(0);
+
+ vty = vty_new();
+ vty->type = VTY_TERM;
+
+ fprintf(stderr, "Progress:\n0/%u", vector_active(test_cmds));
+ for (test_cmd = 0; test_cmd < vector_active(test_cmds); test_cmd++) {
+ for (edit_distance = 0; edit_distance <= max_edit_distance;
+ edit_distance++) {
+ num_iterations = 1 << edit_distance;
+ num_iterations *= num_iterations * num_iterations;
+
+ for (iteration = 0; iteration < num_iterations;
+ iteration++)
+ test_run(prng, vty,
+ vector_slot(test_cmds, test_cmd),
+ edit_distance, node_index, verbose);
+ }
+ fprintf(stderr, "\r%u/%u", test_cmd + 1,
+ vector_active(test_cmds));
+ }
+ fprintf(stderr, "\nDone.\n");
+
+ vty_close(vty);
+ prng_free(prng);
+ test_terminate();
+ return 0;
}
diff --git a/tests/lib/test_buffer.c b/tests/lib/test_buffer.c
index 67e4035806..7e124c1f56 100644
--- a/tests/lib/test_buffer.c
+++ b/tests/lib/test_buffer.c
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2004 Paul Jakma
*
* This file is part of Quagga.
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with Quagga; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
#include <zebra.h>
@@ -26,35 +26,33 @@
struct thread_master *master;
-int
-main(int argc, char **argv)
+int main(int argc, char **argv)
{
- struct buffer *b1, *b2;
- int n;
- char junk[3];
- char c = 'a';
+ struct buffer *b1, *b2;
+ int n;
+ char junk[3];
+ char c = 'a';
- memory_init();
-
- if ((argc != 2) || (sscanf(argv[1], "%d%1s", &n, junk) != 1))
- {
- fprintf(stderr, "Usage: %s <number of chars to simulate>\n", *argv);
- return 1;
- }
+ memory_init();
- b1 = buffer_new(0);
- b2 = buffer_new(1024);
-
- while (n-- > 0)
- {
- buffer_put(b1, &c, 1);
- buffer_put(b2, &c, 1);
- if (c++ == 'z')
- c = 'a';
- buffer_reset(b1);
- buffer_reset(b2);
- }
- buffer_free(b1);
- buffer_free(b2);
- return 0;
+ if ((argc != 2) || (sscanf(argv[1], "%d%1s", &n, junk) != 1)) {
+ fprintf(stderr, "Usage: %s <number of chars to simulate>\n",
+ *argv);
+ return 1;
+ }
+
+ b1 = buffer_new(0);
+ b2 = buffer_new(1024);
+
+ while (n-- > 0) {
+ buffer_put(b1, &c, 1);
+ buffer_put(b2, &c, 1);
+ if (c++ == 'z')
+ c = 'a';
+ buffer_reset(b1);
+ buffer_reset(b2);
+ }
+ buffer_free(b1);
+ buffer_free(b2);
+ return 0;
}
diff --git a/tests/lib/test_checksum.c b/tests/lib/test_checksum.c
index 53ab260e26..6abf5c1f9b 100644
--- a/tests/lib/test_checksum.c
+++ b/tests/lib/test_checksum.c
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* This file is part of Quagga.
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with Quagga; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
#include <zebra.h>
@@ -28,14 +28,14 @@
struct thread_master *master;
struct acc_vals {
- int c0;
- int c1;
+ int c0;
+ int c1;
};
struct csum_vals {
- struct acc_vals a;
- int x;
- int y;
+ struct acc_vals a;
+ int x;
+ int y;
};
static struct csum_vals ospfd_vals, isisd_vals;
@@ -47,26 +47,26 @@ typedef uint16_t testoff_t;
#define MODX 4102U
/* The final reduction phase.
- * This one should be the original ospfd version
+ * This one should be the original ospfd version
*/
-static u_int16_t
-reduce_ospfd (struct csum_vals *vals, testsz_t len, testoff_t off)
+static u_int16_t reduce_ospfd(struct csum_vals *vals, testsz_t len,
+ testoff_t off)
{
#define x vals->x
#define y vals->y
#define c0 vals->a.c0
#define c1 vals->a.c1
- x = ((len - off - 1) * c0 - c1) % 255;
-
- if (x <= 0)
- x += 255;
- y = 510 - c0 - x;
- if (y > 255)
- y -= 255;
+ x = ((len - off - 1) * c0 - c1) % 255;
- /* take care endian issue. */
- return htons ((x << 8) + y);
+ if (x <= 0)
+ x += 255;
+ y = 510 - c0 - x;
+ if (y > 255)
+ y -= 255;
+
+ /* take care endian issue. */
+ return htons((x << 8) + y);
#undef x
#undef y
#undef c0
@@ -74,23 +74,23 @@ reduce_ospfd (struct csum_vals *vals, testsz_t len, testoff_t off)
}
/* slightly different concatenation */
-static u_int16_t
-reduce_ospfd1 (struct csum_vals *vals, testsz_t len, testoff_t off)
+static u_int16_t reduce_ospfd1(struct csum_vals *vals, testsz_t len,
+ testoff_t off)
{
#define x vals->x
#define y vals->y
#define c0 vals->a.c0
#define c1 vals->a.c1
- x = ((len - off - 1) * c0 - c1) % 255;
- if (x <= 0)
- x += 255;
- y = 510 - c0 - x;
- if (y > 255)
- y -= 255;
+ x = ((len - off - 1) * c0 - c1) % 255;
+ if (x <= 0)
+ x += 255;
+ y = 510 - c0 - x;
+ if (y > 255)
+ y -= 255;
- /* take care endian issue. */
- return htons ((x << 8) | (y & 0xff));
+ /* take care endian issue. */
+ return htons((x << 8) | (y & 0xff));
#undef x
#undef y
#undef c0
@@ -98,33 +98,33 @@ reduce_ospfd1 (struct csum_vals *vals, testsz_t len, testoff_t off)
}
/* original isisd version */
-static u_int16_t
-reduce_isisd (struct csum_vals *vals, testsz_t len, testoff_t off)
+static u_int16_t reduce_isisd(struct csum_vals *vals, testsz_t len,
+ testoff_t off)
{
#define x vals->x
#define y vals->y
#define c0 vals->a.c0
#define c1 vals->a.c1
- u_int32_t mul;
-
- mul = (len - off)*(c0);
- x = mul - c0 - c1;
- y = c1 - mul - 1;
+ u_int32_t mul;
+
+ mul = (len - off) * (c0);
+ x = mul - c0 - c1;
+ y = c1 - mul - 1;
- if (y > 0)
- y++;
- if (x < 0)
- x--;
+ if (y > 0)
+ y++;
+ if (x < 0)
+ x--;
- x %= 255;
- y %= 255;
+ x %= 255;
+ y %= 255;
- if (x == 0)
- x = 255;
- if (y == 0)
- y = 1;
+ if (x == 0)
+ x = 255;
+ if (y == 0)
+ y = 1;
- return htons ((x << 8) | (y & 0xff));
+ return htons((x << 8) | (y & 0xff));
#undef x
#undef y
@@ -133,33 +133,33 @@ reduce_isisd (struct csum_vals *vals, testsz_t len, testoff_t off)
}
/* Is the -1 in y wrong perhaps? */
-static u_int16_t
-reduce_isisd_yfix (struct csum_vals *vals, testsz_t len, testoff_t off)
+static u_int16_t reduce_isisd_yfix(struct csum_vals *vals, testsz_t len,
+ testoff_t off)
{
#define x vals->x
#define y vals->y
#define c0 vals->a.c0
#define c1 vals->a.c1
- u_int32_t mul;
-
- mul = (len - off)*(c0);
- x = mul - c0 - c1;
- y = c1 - mul;
+ u_int32_t mul;
+
+ mul = (len - off) * (c0);
+ x = mul - c0 - c1;
+ y = c1 - mul;
- if (y > 0)
- y++;
- if (x < 0)
- x--;
+ if (y > 0)
+ y++;
+ if (x < 0)
+ x--;
- x %= 255;
- y %= 255;
+ x %= 255;
+ y %= 255;
- if (x == 0)
- x = 255;
- if (y == 0)
- y = 1;
+ if (x == 0)
+ x = 255;
+ if (y == 0)
+ y = 1;
- return htons ((x << 8) | (y & 0xff));
+ return htons((x << 8) | (y & 0xff));
#undef x
#undef y
@@ -168,33 +168,33 @@ reduce_isisd_yfix (struct csum_vals *vals, testsz_t len, testoff_t off)
}
/* Move the mods yp */
-static u_int16_t
-reduce_isisd_mod (struct csum_vals *vals, testsz_t len, testoff_t off)
+static u_int16_t reduce_isisd_mod(struct csum_vals *vals, testsz_t len,
+ testoff_t off)
{
#define x vals->x
#define y vals->y
#define c0 vals->a.c0
#define c1 vals->a.c1
- u_int32_t mul;
-
- mul = (len - off)*(c0);
- x = mul - c1 - c0;
- y = c1 - mul - 1;
+ u_int32_t mul;
- x %= 255;
- y %= 255;
+ mul = (len - off) * (c0);
+ x = mul - c1 - c0;
+ y = c1 - mul - 1;
- if (y > 0)
- y++;
- if (x < 0)
- x--;
+ x %= 255;
+ y %= 255;
- if (x == 0)
- x = 255;
- if (y == 0)
- y = 1;
+ if (y > 0)
+ y++;
+ if (x < 0)
+ x--;
- return htons ((x << 8) | (y & 0xff));
+ if (x == 0)
+ x = 255;
+ if (y == 0)
+ y = 1;
+
+ return htons((x << 8) | (y & 0xff));
#undef x
#undef y
@@ -203,33 +203,33 @@ reduce_isisd_mod (struct csum_vals *vals, testsz_t len, testoff_t off)
}
/* Move the mods up + fix y */
-static u_int16_t
-reduce_isisd_mody (struct csum_vals *vals, testsz_t len, testoff_t off)
+static u_int16_t reduce_isisd_mody(struct csum_vals *vals, testsz_t len,
+ testoff_t off)
{
#define x vals->x
#define y vals->y
#define c0 vals->a.c0
#define c1 vals->a.c1
- u_int32_t mul;
-
- mul = (len - off)*(c0);
- x = mul - c0 - c1;
- y = c1 - mul;
+ u_int32_t mul;
+
+ mul = (len - off) * (c0);
+ x = mul - c0 - c1;
+ y = c1 - mul;
- x %= 255;
- y %= 255;
+ x %= 255;
+ y %= 255;
- if (y > 0)
- y++;
- if (x < 0)
- x--;
+ if (y > 0)
+ y++;
+ if (x < 0)
+ x--;
- if (x == 0)
- x = 255;
- if (y == 0)
- y = 1;
+ if (x == 0)
+ x = 255;
+ if (y == 0)
+ y = 1;
- return htons ((x << 8) | (y & 0xff));
+ return htons((x << 8) | (y & 0xff));
#undef x
#undef y
@@ -238,184 +238,175 @@ reduce_isisd_mody (struct csum_vals *vals, testsz_t len, testoff_t off)
}
struct reductions_t {
- const char *name;
- u_int16_t (*f) (struct csum_vals *, testsz_t, testoff_t);
+ const char *name;
+ u_int16_t (*f)(struct csum_vals *, testsz_t, testoff_t);
} reducts[] = {
- { .name = "ospfd", .f = reduce_ospfd },
- { .name = "ospfd-1", .f = reduce_ospfd1 },
- { .name = "isisd", .f = reduce_isisd },
- { .name = "isisd-yfix", .f = reduce_isisd_yfix },
- { .name = "isisd-mod", .f = reduce_isisd_mod },
- { .name = "isisd-mody", .f = reduce_isisd_mody },
- { NULL, NULL },
+ {.name = "ospfd", .f = reduce_ospfd},
+ {.name = "ospfd-1", .f = reduce_ospfd1},
+ {.name = "isisd", .f = reduce_isisd},
+ {.name = "isisd-yfix", .f = reduce_isisd_yfix},
+ {.name = "isisd-mod", .f = reduce_isisd_mod},
+ {.name = "isisd-mody", .f = reduce_isisd_mody},
+ {NULL, NULL},
};
/* The original ospfd checksum */
-static u_int16_t
-ospfd_checksum (u_char *buffer, testsz_t len, testoff_t off)
+static u_int16_t ospfd_checksum(u_char *buffer, testsz_t len, testoff_t off)
{
- u_char *sp, *ep, *p, *q;
- int c0 = 0, c1 = 0;
- int x, y;
- u_int16_t checksum, *csum;
-
- csum = (u_int16_t *) (buffer + off);
- *(csum) = 0;
-
- sp = buffer;
-
- for (ep = sp + len; sp < ep; sp = q)
- {
- q = sp + MODX;
- if (q > ep)
- q = ep;
- for (p = sp; p < q; p++)
- {
- c0 += *p;
- c1 += c0;
- }
- c0 %= 255;
- c1 %= 255;
- }
-
- ospfd_vals.a.c0 = c0;
- ospfd_vals.a.c1 = c1;
-
- //printf ("%s: len %u, off %u, c0 %d, c1 %d\n",
- // __func__, len, off, c0, c1);
-
- x = ((int)(len - off - 1) * (int)c0 - (int)c1) % 255;
-
- if (x <= 0)
- x += 255;
- y = 510 - c0 - x;
- if (y > 255)
- y -= 255;
-
- ospfd_vals.x = x;
- ospfd_vals.y = y;
-
- buffer[off] = x;
- buffer[off + 1] = y;
-
- /* take care endian issue. */
- checksum = htons ((x << 8) | (y & 0xff));
-
- return (checksum);
+ u_char *sp, *ep, *p, *q;
+ int c0 = 0, c1 = 0;
+ int x, y;
+ u_int16_t checksum, *csum;
+
+ csum = (u_int16_t *)(buffer + off);
+ *(csum) = 0;
+
+ sp = buffer;
+
+ for (ep = sp + len; sp < ep; sp = q) {
+ q = sp + MODX;
+ if (q > ep)
+ q = ep;
+ for (p = sp; p < q; p++) {
+ c0 += *p;
+ c1 += c0;
+ }
+ c0 %= 255;
+ c1 %= 255;
+ }
+
+ ospfd_vals.a.c0 = c0;
+ ospfd_vals.a.c1 = c1;
+
+ // printf ("%s: len %u, off %u, c0 %d, c1 %d\n",
+ // __func__, len, off, c0, c1);
+
+ x = ((int)(len - off - 1) * (int)c0 - (int)c1) % 255;
+
+ if (x <= 0)
+ x += 255;
+ y = 510 - c0 - x;
+ if (y > 255)
+ y -= 255;
+
+ ospfd_vals.x = x;
+ ospfd_vals.y = y;
+
+ buffer[off] = x;
+ buffer[off + 1] = y;
+
+ /* take care endian issue. */
+ checksum = htons((x << 8) | (y & 0xff));
+
+ return (checksum);
}
/* the original, broken isisd checksum */
-static u_int16_t
-iso_csum_create (u_char * buffer, testsz_t len, testoff_t off)
+static u_int16_t iso_csum_create(u_char *buffer, testsz_t len, testoff_t off)
{
- u_int8_t *p;
- int x;
- int y;
- u_int32_t mul;
- u_int32_t c0;
- u_int32_t c1;
- u_int16_t checksum, *csum;
- int i, init_len, partial_len;
-
- checksum = 0;
-
- csum = (u_int16_t *) (buffer + off);
- *(csum) = checksum;
-
- p = buffer;
- c0 = 0;
- c1 = 0;
- init_len = len;
-
- while (len != 0)
- {
- partial_len = MIN(len, MODX);
-
- for (i = 0; i < partial_len; i++)
- {
- c0 = c0 + *(p++);
- c1 += c0;
+ u_int8_t *p;
+ int x;
+ int y;
+ u_int32_t mul;
+ u_int32_t c0;
+ u_int32_t c1;
+ u_int16_t checksum, *csum;
+ int i, init_len, partial_len;
+
+ checksum = 0;
+
+ csum = (u_int16_t *)(buffer + off);
+ *(csum) = checksum;
+
+ p = buffer;
+ c0 = 0;
+ c1 = 0;
+ init_len = len;
+
+ while (len != 0) {
+ partial_len = MIN(len, MODX);
+
+ for (i = 0; i < partial_len; i++) {
+ c0 = c0 + *(p++);
+ c1 += c0;
+ }
+
+ c0 = c0 % 255;
+ c1 = c1 % 255;
+
+ len -= partial_len;
}
- c0 = c0 % 255;
- c1 = c1 % 255;
-
- len -= partial_len;
- }
-
- isisd_vals.a.c0 = c0;
- isisd_vals.a.c1 = c1;
-
- mul = (init_len - off) * c0;
-
- x = mul - c1 - c0;
- y = c1 - mul - 1;
-
- if (y > 0)
- y++;
- if (x < 0)
- x--;
-
- x %= 255;
- y %= 255;
-
- if (x == 0)
- x = 255;
- if (y == 0)
- y = 1;
-
- isisd_vals.x = x;
- isisd_vals.y = y;
-
- checksum = htons((x << 8) | (y & 0xFF));
-
- *(csum) = checksum;
-
- /* return the checksum for user usage */
- return checksum;
+ isisd_vals.a.c0 = c0;
+ isisd_vals.a.c1 = c1;
+
+ mul = (init_len - off) * c0;
+
+ x = mul - c1 - c0;
+ y = c1 - mul - 1;
+
+ if (y > 0)
+ y++;
+ if (x < 0)
+ x--;
+
+ x %= 255;
+ y %= 255;
+
+ if (x == 0)
+ x = 255;
+ if (y == 0)
+ y = 1;
+
+ isisd_vals.x = x;
+ isisd_vals.y = y;
+
+ checksum = htons((x << 8) | (y & 0xFF));
+
+ *(csum) = checksum;
+
+ /* return the checksum for user usage */
+ return checksum;
}
-static int
-verify (u_char * buffer, testsz_t len)
+static int verify(u_char *buffer, testsz_t len)
{
- u_int8_t *p;
- u_int32_t c0;
- u_int32_t c1;
- int i, partial_len;
-
- p = buffer;
-
- c0 = 0;
- c1 = 0;
-
- while (len)
- {
- partial_len = MIN(len, 5803U);
-
- for (i = 0; i < partial_len; i++)
- {
- c0 = c0 + *(p++);
- c1 += c0;
- }
- c0 = c0 % 255;
- c1 = c1 % 255;
-
- len -= partial_len;
- }
-
- if (c0 == 0 && c1 == 0)
- return 0;
-
- return 1;
+ u_int8_t *p;
+ u_int32_t c0;
+ u_int32_t c1;
+ int i, partial_len;
+
+ p = buffer;
+
+ c0 = 0;
+ c1 = 0;
+
+ while (len) {
+ partial_len = MIN(len, 5803U);
+
+ for (i = 0; i < partial_len; i++) {
+ c0 = c0 + *(p++);
+ c1 += c0;
+ }
+ c0 = c0 % 255;
+ c1 = c1 % 255;
+
+ len -= partial_len;
+ }
+
+ if (c0 == 0 && c1 == 0)
+ return 0;
+
+ return 1;
}
-static int /* return checksum in low-order 16 bits */
-in_cksum_optimized(void *parg, int nbytes)
+static int /* return checksum in low-order 16 bits */
+ in_cksum_optimized(void *parg, int nbytes)
{
u_short *ptr = parg;
- register long sum; /* assumes long == 32 bits */
- register u_short answer; /* assumes u_short == 16 bits */
+ register long sum; /* assumes long == 32 bits */
+ register u_short answer; /* assumes u_short == 16 bits */
register int count;
/*
* Our algorithm is simple, using a 32-bit accumulator (sum),
@@ -425,126 +416,129 @@ in_cksum_optimized(void *parg, int nbytes)
sum = 0;
count = nbytes >> 1; /* div by 2 */
- for(ptr--; count; --count)
- sum += *++ptr;
+ for (ptr--; count; --count)
+ sum += *++ptr;
- if (nbytes & 1) /* Odd */
- sum += *(u_char *)(++ptr); /* one byte only */
+ if (nbytes & 1) /* Odd */
+ sum += *(u_char *)(++ptr); /* one byte only */
/*
* Add back carry outs from top 16 bits to low 16 bits.
*/
- sum = (sum >> 16) + (sum & 0xffff); /* add high-16 to low-16 */
- sum += (sum >> 16); /* add carry */
- answer = ~sum; /* ones-complement, then truncate to 16 bits */
- return(answer);
+ sum = (sum >> 16) + (sum & 0xffff); /* add high-16 to low-16 */
+ sum += (sum >> 16); /* add carry */
+ answer = ~sum; /* ones-complement, then truncate to 16 bits */
+ return (answer);
}
static int /* return checksum in low-order 16 bits */
-in_cksum_rfc(void *parg, int count)
+ in_cksum_rfc(void *parg, int count)
/* from RFC 1071 */
{
u_short *addr = parg;
/* Compute Internet Checksum for "count" bytes
* beginning at location "addr".
*/
- register long sum = 0;
+ register long sum = 0;
- while (count > 1) {
- /* This is the inner loop */
- sum += *addr++;
- count -= 2;
+ while (count > 1) {
+ /* This is the inner loop */
+ sum += *addr++;
+ count -= 2;
}
/* Add left-over byte, if any */
if (count > 0) {
- sum += *(u_char *)addr;
+ sum += *(u_char *)addr;
}
/* Fold 32-bit sum to 16 bits */
- while (sum>>16)
- sum = (sum & 0xffff) + (sum >> 16);
+ while (sum >> 16)
+ sum = (sum & 0xffff) + (sum >> 16);
return ~sum;
}
-int
-main(int argc, char **argv)
+int main(int argc, char **argv)
{
/* 60017 65629 702179 */
#define MAXDATALEN 60017
#define BUFSIZE MAXDATALEN + sizeof(u_int16_t)
- u_char buffer[BUFSIZE];
- int exercise = 0;
+ u_char buffer[BUFSIZE];
+ int exercise = 0;
#define EXERCISESTEP 257
-
- srandom (time (NULL));
-
- while (1) {
- u_int16_t ospfd, isisd, lib, in_csum, in_csum_res, in_csum_rfc;
- int i,j;
-
- exercise += EXERCISESTEP;
- exercise %= MAXDATALEN;
-
- for (i = 0; i < exercise; i += sizeof (long int)) {
- long int rand = random ();
-
- for (j = sizeof (long int); j > 0; j--)
- buffer[i + (sizeof (long int) - j)] = (rand >> (j * 8)) & 0xff;
- }
-
- in_csum = in_cksum(buffer, exercise);
- in_csum_res = in_cksum_optimized(buffer, exercise);
- in_csum_rfc = in_cksum_rfc(buffer, exercise);
- if (in_csum_res != in_csum || in_csum != in_csum_rfc)
- printf ("verify: in_chksum failed in_csum:%x, in_csum_res:%x,"
- "in_csum_rfc %x, len:%d\n",
- in_csum, in_csum_res, in_csum_rfc, exercise);
-
- ospfd = ospfd_checksum (buffer, exercise + sizeof(u_int16_t), exercise);
- if (verify (buffer, exercise + sizeof(u_int16_t)))
- printf ("verify: ospfd failed\n");
- isisd = iso_csum_create (buffer, exercise + sizeof(u_int16_t), exercise);
- if (verify (buffer, exercise + sizeof(u_int16_t)))
- printf ("verify: isisd failed\n");
- lib = fletcher_checksum (buffer, exercise + sizeof(u_int16_t), exercise);
- if (verify (buffer, exercise + sizeof(u_int16_t)))
- printf ("verify: lib failed\n");
-
- if (ospfd != lib) {
- printf ("Mismatch in values at size %u\n"
- "ospfd: 0x%04x\tc0: %d\tc1: %d\tx: %d\ty: %d\n"
- "isisd: 0x%04x\tc0: %d\tc1: %d\tx: %d\ty: %d\n"
- "lib: 0x%04x\n",
- exercise,
- ospfd, ospfd_vals.a.c0, ospfd_vals.a.c1, ospfd_vals.x, ospfd_vals.y,
- isisd, isisd_vals.a.c0, isisd_vals.a.c1, isisd_vals.x, isisd_vals.y,
- lib
- );
-
- /* Investigate reduction phase discrepencies */
- if (ospfd_vals.a.c0 == isisd_vals.a.c0
- && ospfd_vals.a.c1 == isisd_vals.a.c1) {
- printf ("\n");
- for (i = 0; reducts[i].name != NULL; i++) {
- ospfd = reducts[i].f (&ospfd_vals,
- exercise + sizeof (u_int16_t),
- exercise);
- printf ("%20s: x: %02x, y %02x, checksum 0x%04x\n",
- reducts[i].name, ospfd_vals.x & 0xff, ospfd_vals.y & 0xff, ospfd);
- }
- }
-
- printf ("\n u_char testdata [] = {\n ");
- for (i = 0; i < exercise; i++) {
- printf ("0x%02x,%s",
- buffer[i],
- (i + 1) % 8 ? " " : "\n ");
- }
- printf ("\n}\n");
- exit (1);
- }
- }
+ srandom(time(NULL));
+
+ while (1) {
+ u_int16_t ospfd, isisd, lib, in_csum, in_csum_res, in_csum_rfc;
+ int i, j;
+
+ exercise += EXERCISESTEP;
+ exercise %= MAXDATALEN;
+
+ for (i = 0; i < exercise; i += sizeof(long int)) {
+ long int rand = random();
+
+ for (j = sizeof(long int); j > 0; j--)
+ buffer[i + (sizeof(long int) - j)] =
+ (rand >> (j * 8)) & 0xff;
+ }
+
+ in_csum = in_cksum(buffer, exercise);
+ in_csum_res = in_cksum_optimized(buffer, exercise);
+ in_csum_rfc = in_cksum_rfc(buffer, exercise);
+ if (in_csum_res != in_csum || in_csum != in_csum_rfc)
+ printf("verify: in_chksum failed in_csum:%x, in_csum_res:%x,"
+ "in_csum_rfc %x, len:%d\n",
+ in_csum, in_csum_res, in_csum_rfc, exercise);
+
+ ospfd = ospfd_checksum(buffer, exercise + sizeof(u_int16_t),
+ exercise);
+ if (verify(buffer, exercise + sizeof(u_int16_t)))
+ printf("verify: ospfd failed\n");
+ isisd = iso_csum_create(buffer, exercise + sizeof(u_int16_t),
+ exercise);
+ if (verify(buffer, exercise + sizeof(u_int16_t)))
+ printf("verify: isisd failed\n");
+ lib = fletcher_checksum(buffer, exercise + sizeof(u_int16_t),
+ exercise);
+ if (verify(buffer, exercise + sizeof(u_int16_t)))
+ printf("verify: lib failed\n");
+
+ if (ospfd != lib) {
+ printf("Mismatch in values at size %u\n"
+ "ospfd: 0x%04x\tc0: %d\tc1: %d\tx: %d\ty: %d\n"
+ "isisd: 0x%04x\tc0: %d\tc1: %d\tx: %d\ty: %d\n"
+ "lib: 0x%04x\n",
+ exercise, ospfd, ospfd_vals.a.c0,
+ ospfd_vals.a.c1, ospfd_vals.x, ospfd_vals.y,
+ isisd, isisd_vals.a.c0, isisd_vals.a.c1,
+ isisd_vals.x, isisd_vals.y, lib);
+
+ /* Investigate reduction phase discrepencies */
+ if (ospfd_vals.a.c0 == isisd_vals.a.c0
+ && ospfd_vals.a.c1 == isisd_vals.a.c1) {
+ printf("\n");
+ for (i = 0; reducts[i].name != NULL; i++) {
+ ospfd = reducts[i].f(
+ &ospfd_vals,
+ exercise + sizeof(u_int16_t),
+ exercise);
+ printf("%20s: x: %02x, y %02x, checksum 0x%04x\n",
+ reducts[i].name,
+ ospfd_vals.x & 0xff,
+ ospfd_vals.y & 0xff, ospfd);
+ }
+ }
+
+ printf("\n u_char testdata [] = {\n ");
+ for (i = 0; i < exercise; i++) {
+ printf("0x%02x,%s", buffer[i],
+ (i + 1) % 8 ? " " : "\n ");
+ }
+ printf("\n}\n");
+ exit(1);
+ }
+ }
}
diff --git a/tests/lib/test_heavy.c b/tests/lib/test_heavy.c
index 6ba8d9aa6d..07cf602afe 100644
--- a/tests/lib/test_heavy.c
+++ b/tests/lib/test_heavy.c
@@ -38,46 +38,42 @@
#include "tests.h"
-enum
-{
- ITERS_FIRST = 0,
- ITERS_ERR = 100,
- ITERS_LATER = 400,
- ITERS_PRINT = 10,
- ITERS_MAX = 1000,
+enum { ITERS_FIRST = 0,
+ ITERS_ERR = 100,
+ ITERS_LATER = 400,
+ ITERS_PRINT = 10,
+ ITERS_MAX = 1000,
};
-static void
-slow_func (struct vty *vty, const char *str, const int i)
+static void slow_func(struct vty *vty, const char *str, const int i)
{
- double x = 1;
- int j;
-
- for (j = 0; j < 300; j++)
- x += sin(x)*j;
-
- if ((i % ITERS_LATER) == 0)
- printf ("%s: %d, temporary error, save this somehow and do it later..\n",
- __func__, i);
-
- if ((i % ITERS_ERR) == 0)
- printf ("%s: hard error\n", __func__);
-
- if ((i % ITERS_PRINT) == 0)
- printf ("%s did %d, x = %g%s", str, i, x, VTY_NEWLINE);
+ double x = 1;
+ int j;
+
+ for (j = 0; j < 300; j++)
+ x += sin(x) * j;
+
+ if ((i % ITERS_LATER) == 0)
+ printf("%s: %d, temporary error, save this somehow and do it later..\n",
+ __func__, i);
+
+ if ((i % ITERS_ERR) == 0)
+ printf("%s: hard error\n", __func__);
+
+ if ((i % ITERS_PRINT) == 0)
+ printf("%s did %d, x = %g%s", str, i, x, VTY_NEWLINE);
}
-static void
-clear_something (struct vty *vty, const char *str)
+static void clear_something(struct vty *vty, const char *str)
{
- int i;
-
- /* this could be like iterating through 150k of route_table
- * or worse, iterating through a list of peers, to bgp_stop them with
- * each having 150k route tables to process...
- */
- for (i = ITERS_FIRST; i < ITERS_MAX; i++)
- slow_func (vty, str, i);
+ int i;
+
+ /* this could be like iterating through 150k of route_table
+ * or worse, iterating through a list of peers, to bgp_stop them with
+ * each having 150k route tables to process...
+ */
+ for (i = ITERS_FIRST; i < ITERS_MAX; i++)
+ slow_func(vty, str, i);
}
DEFUN (clear_foo,
@@ -86,28 +82,25 @@ DEFUN (clear_foo,
"clear command\n"
"arbitrary string\n")
{
- char *str;
- if (!argc)
- {
- vty_out (vty, "%% string argument required%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- str = argv_concat (argv, argc, 0);
-
- clear_something (vty, str);
- XFREE (MTYPE_TMP, str);
- return CMD_SUCCESS;
+ char *str;
+ if (!argc) {
+ vty_out(vty, "%% string argument required%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ str = argv_concat(argv, argc, 0);
+
+ clear_something(vty, str);
+ XFREE(MTYPE_TMP, str);
+ return CMD_SUCCESS;
}
-static void
-slow_vty_init()
+static void slow_vty_init()
{
- install_element (VIEW_NODE, &clear_foo_cmd);
+ install_element(VIEW_NODE, &clear_foo_cmd);
}
-void
-test_init()
+void test_init()
{
- slow_vty_init();
+ slow_vty_init();
}
diff --git a/tests/lib/test_heavy_thread.c b/tests/lib/test_heavy_thread.c
index c43fa76c0e..e7af8dccc5 100644
--- a/tests/lib/test_heavy_thread.c
+++ b/tests/lib/test_heavy_thread.c
@@ -41,65 +41,59 @@
extern struct thread_master *master;
-enum
-{
- ITERS_FIRST = 0,
- ITERS_ERR = 100,
- ITERS_LATER = 400,
- ITERS_PRINT = 10,
- ITERS_MAX = 1000,
+enum { ITERS_FIRST = 0,
+ ITERS_ERR = 100,
+ ITERS_LATER = 400,
+ ITERS_PRINT = 10,
+ ITERS_MAX = 1000,
};
struct work_state {
- struct vty *vty;
- char *str;
- int i;
+ struct vty *vty;
+ char *str;
+ int i;
};
-static void
-slow_func (struct vty *vty, const char *str, const int i)
+static void slow_func(struct vty *vty, const char *str, const int i)
{
- double x = 1;
- int j;
-
- for (j = 0; j < 300; j++)
- x += sin(x)*j;
-
- if ((i % ITERS_LATER) == 0)
- printf ("%s: %d, temporary error, save this somehow and do it later..\n",
- __func__, i);
-
- if ((i % ITERS_ERR) == 0)
- printf ("%s: hard error\n", __func__);
-
- if ((i % ITERS_PRINT) == 0)
- printf ("%s did %d, x = %g\n", str, i, x);
+ double x = 1;
+ int j;
+
+ for (j = 0; j < 300; j++)
+ x += sin(x) * j;
+
+ if ((i % ITERS_LATER) == 0)
+ printf("%s: %d, temporary error, save this somehow and do it later..\n",
+ __func__, i);
+
+ if ((i % ITERS_ERR) == 0)
+ printf("%s: hard error\n", __func__);
+
+ if ((i % ITERS_PRINT) == 0)
+ printf("%s did %d, x = %g\n", str, i, x);
}
-static int
-clear_something (struct thread *thread)
+static int clear_something(struct thread *thread)
{
- struct work_state *ws = THREAD_ARG(thread);
-
- /* this could be like iterating through 150k of route_table
- * or worse, iterating through a list of peers, to bgp_stop them with
- * each having 150k route tables to process...
- */
- while (ws->i < ITERS_MAX)
- {
- slow_func(ws->vty, ws->str, ws->i);
- ws->i++;
- if (thread_should_yield(thread))
- {
- thread_add_background(master, clear_something, ws, 0);
- return 0;
- }
- }
-
- /* All done! */
- XFREE (MTYPE_TMP, ws->str);
- XFREE (MTYPE_TMP, ws);
- return 0;
+ struct work_state *ws = THREAD_ARG(thread);
+
+ /* this could be like iterating through 150k of route_table
+ * or worse, iterating through a list of peers, to bgp_stop them with
+ * each having 150k route tables to process...
+ */
+ while (ws->i < ITERS_MAX) {
+ slow_func(ws->vty, ws->str, ws->i);
+ ws->i++;
+ if (thread_should_yield(thread)) {
+ thread_add_background(master, clear_something, ws, 0);
+ return 0;
+ }
+ }
+
+ /* All done! */
+ XFREE(MTYPE_TMP, ws->str);
+ XFREE(MTYPE_TMP, ws);
+ return 0;
}
DEFUN (clear_foo,
@@ -108,40 +102,36 @@ DEFUN (clear_foo,
"clear command\n"
"arbitrary string\n")
{
- char *str;
- struct work_state *ws;
-
- if (!argc)
- {
- vty_out (vty, "%% string argument required%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- str = argv_concat (argv, argc, 0);
-
- if ((ws = XMALLOC(MTYPE_TMP, sizeof(*ws))) == NULL)
- {
- zlog_err ("%s: unable to allocate work_state", __func__);
- return CMD_WARNING;
- }
-
- if (!(ws->str = XSTRDUP (MTYPE_TMP, str)))
- {
- zlog_err ("%s: unable to xstrdup", __func__);
- XFREE (MTYPE_TMP, ws);
- return CMD_WARNING;
- }
-
- ws->vty = vty;
- ws->i = ITERS_FIRST;
-
- thread_add_background(master, clear_something, ws, 0);
-
- return CMD_SUCCESS;
+ char *str;
+ struct work_state *ws;
+
+ if (!argc) {
+ vty_out(vty, "%% string argument required%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ str = argv_concat(argv, argc, 0);
+
+ if ((ws = XMALLOC(MTYPE_TMP, sizeof(*ws))) == NULL) {
+ zlog_err("%s: unable to allocate work_state", __func__);
+ return CMD_WARNING;
+ }
+
+ if (!(ws->str = XSTRDUP(MTYPE_TMP, str))) {
+ zlog_err("%s: unable to xstrdup", __func__);
+ XFREE(MTYPE_TMP, ws);
+ return CMD_WARNING;
+ }
+
+ ws->vty = vty;
+ ws->i = ITERS_FIRST;
+
+ thread_add_background(master, clear_something, ws, 0);
+
+ return CMD_SUCCESS;
}
-void
-test_init()
+void test_init()
{
- install_element (VIEW_NODE, &clear_foo_cmd);
+ install_element(VIEW_NODE, &clear_foo_cmd);
}
diff --git a/tests/lib/test_heavy_wq.c b/tests/lib/test_heavy_wq.c
index 97371face1..7ccd1131c6 100644
--- a/tests/lib/test_heavy_wq.c
+++ b/tests/lib/test_heavy_wq.c
@@ -45,97 +45,88 @@ DEFINE_MTYPE_STATIC(TEST_HEAVYWQ, WQ_NODE_STR, "heavy_wq_node->str")
extern struct thread_master *master;
static struct work_queue *heavy_wq;
-struct heavy_wq_node
-{
- char *str;
- int i;
+struct heavy_wq_node {
+ char *str;
+ int i;
};
-enum
-{
- ITERS_FIRST = 0,
- ITERS_ERR = 100,
- ITERS_LATER = 400,
- ITERS_PRINT = 10,
- ITERS_MAX = 1000,
+enum { ITERS_FIRST = 0,
+ ITERS_ERR = 100,
+ ITERS_LATER = 400,
+ ITERS_PRINT = 10,
+ ITERS_MAX = 1000,
};
-static void
-heavy_wq_add (struct vty *vty, const char *str, int i)
+static void heavy_wq_add(struct vty *vty, const char *str, int i)
{
- struct heavy_wq_node *hn;
-
- if ((hn = XCALLOC (MTYPE_WQ_NODE, sizeof(struct heavy_wq_node))) == NULL)
- {
- zlog_err ("%s: unable to allocate hn", __func__);
- return;
- }
-
- hn->i = i;
- if (!(hn->str = XSTRDUP (MTYPE_WQ_NODE_STR, str)))
- {
- zlog_err ("%s: unable to xstrdup", __func__);
- XFREE (MTYPE_WQ_NODE, hn);
- return;
- }
-
- work_queue_add (heavy_wq, hn);
-
- return;
+ struct heavy_wq_node *hn;
+
+ if ((hn = XCALLOC(MTYPE_WQ_NODE, sizeof(struct heavy_wq_node)))
+ == NULL) {
+ zlog_err("%s: unable to allocate hn", __func__);
+ return;
+ }
+
+ hn->i = i;
+ if (!(hn->str = XSTRDUP(MTYPE_WQ_NODE_STR, str))) {
+ zlog_err("%s: unable to xstrdup", __func__);
+ XFREE(MTYPE_WQ_NODE, hn);
+ return;
+ }
+
+ work_queue_add(heavy_wq, hn);
+
+ return;
}
-static void
-slow_func_err (struct work_queue *wq, struct work_queue_item *item)
+static void slow_func_err(struct work_queue *wq, struct work_queue_item *item)
{
- printf ("%s: running error function\n", __func__);
+ printf("%s: running error function\n", __func__);
}
-static void
-slow_func_del (struct work_queue *wq, void *data)
+static void slow_func_del(struct work_queue *wq, void *data)
{
- struct heavy_wq_node *hn = data;
- assert (hn && hn->str);
- printf ("%s: %s\n", __func__, hn->str);
- XFREE (MTYPE_WQ_NODE_STR, hn->str);
- hn->str = NULL;
- XFREE(MTYPE_WQ_NODE, hn);
+ struct heavy_wq_node *hn = data;
+ assert(hn && hn->str);
+ printf("%s: %s\n", __func__, hn->str);
+ XFREE(MTYPE_WQ_NODE_STR, hn->str);
+ hn->str = NULL;
+ XFREE(MTYPE_WQ_NODE, hn);
}
-static wq_item_status
-slow_func (struct work_queue *wq, void *data)
+static wq_item_status slow_func(struct work_queue *wq, void *data)
{
- struct heavy_wq_node *hn = data;
- double x = 1;
- int j;
-
- assert (hn && hn->str);
-
- for (j = 0; j < 300; j++)
- x += sin(x)*j;
-
- if ((hn->i % ITERS_LATER) == 0)
- return WQ_RETRY_LATER;
-
- if ((hn->i % ITERS_ERR) == 0)
- return WQ_RETRY_NOW;
-
- if ((hn->i % ITERS_PRINT) == 0)
- printf ("%s did %d, x = %g\n", hn->str, hn->i, x);
-
- return WQ_SUCCESS;
+ struct heavy_wq_node *hn = data;
+ double x = 1;
+ int j;
+
+ assert(hn && hn->str);
+
+ for (j = 0; j < 300; j++)
+ x += sin(x) * j;
+
+ if ((hn->i % ITERS_LATER) == 0)
+ return WQ_RETRY_LATER;
+
+ if ((hn->i % ITERS_ERR) == 0)
+ return WQ_RETRY_NOW;
+
+ if ((hn->i % ITERS_PRINT) == 0)
+ printf("%s did %d, x = %g\n", hn->str, hn->i, x);
+
+ return WQ_SUCCESS;
}
-static void
-clear_something (struct vty *vty, const char *str)
+static void clear_something(struct vty *vty, const char *str)
{
- int i;
-
- /* this could be like iterating through 150k of route_table
- * or worse, iterating through a list of peers, to bgp_stop them with
- * each having 150k route tables to process...
- */
- for (i = ITERS_FIRST; i < ITERS_MAX; i++)
- heavy_wq_add (vty, str, i);
+ int i;
+
+ /* this could be like iterating through 150k of route_table
+ * or worse, iterating through a list of peers, to bgp_stop them with
+ * each having 150k route tables to process...
+ */
+ for (i = ITERS_FIRST; i < ITERS_MAX; i++)
+ heavy_wq_add(vty, str, i);
}
DEFUN (clear_foo,
@@ -144,41 +135,37 @@ DEFUN (clear_foo,
"clear command\n"
"arbitrary string\n")
{
- char *str;
- if (!argc)
- {
- vty_out (vty, "%% string argument required%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
-
- str = argv_concat (argv, argc, 0);
-
- clear_something (vty, str);
- XFREE (MTYPE_TMP, str);
- return CMD_SUCCESS;
+ char *str;
+ if (!argc) {
+ vty_out(vty, "%% string argument required%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ str = argv_concat(argv, argc, 0);
+
+ clear_something(vty, str);
+ XFREE(MTYPE_TMP, str);
+ return CMD_SUCCESS;
}
-static int
-heavy_wq_init ()
+static int heavy_wq_init()
{
- if (! (heavy_wq = work_queue_new (master, "heavy_work_queue")))
- {
- zlog_err ("%s: could not get new work queue!", __func__);
- return -1;
- }
-
- heavy_wq->spec.workfunc = &slow_func;
- heavy_wq->spec.errorfunc = &slow_func_err;
- heavy_wq->spec.del_item_data = &slow_func_del;
- heavy_wq->spec.max_retries = 3;
- heavy_wq->spec.hold = 1000;
-
- return 0;
+ if (!(heavy_wq = work_queue_new(master, "heavy_work_queue"))) {
+ zlog_err("%s: could not get new work queue!", __func__);
+ return -1;
+ }
+
+ heavy_wq->spec.workfunc = &slow_func;
+ heavy_wq->spec.errorfunc = &slow_func_err;
+ heavy_wq->spec.del_item_data = &slow_func_del;
+ heavy_wq->spec.max_retries = 3;
+ heavy_wq->spec.hold = 1000;
+
+ return 0;
}
-void
-test_init()
+void test_init()
{
- install_element (VIEW_NODE, &clear_foo_cmd);
- heavy_wq_init();
+ install_element(VIEW_NODE, &clear_foo_cmd);
+ heavy_wq_init();
}
diff --git a/tests/lib/test_memory.c b/tests/lib/test_memory.c
index 6849b9dceb..d1240ab59e 100644
--- a/tests/lib/test_memory.c
+++ b/tests/lib/test_memory.c
@@ -1,4 +1,4 @@
-/*
+/*
* This file is part of Quagga.
*
* Quagga is free software; you can redistribute it and/or modify it
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with Quagga; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
#include <zebra.h>
@@ -45,81 +45,77 @@ struct thread_master *master;
#define TIMES 10
-int
-main(int argc, char **argv)
+int main(int argc, char **argv)
{
- void *a[10];
- int i;
+ void *a[10];
+ int i;
- printf ("malloc x, malloc x, free, malloc x, free free\n\n");
- /* simple case, test cache */
- for (i = 0; i < TIMES; i++)
- {
- a[0] = XMALLOC (MTYPE_TEST, 1024);
- memset (a[0], 1, 1024);
- a[1] = XMALLOC (MTYPE_TEST, 1024);
- memset (a[1], 1, 1024);
- XFREE(MTYPE_TEST, a[0]); /* should go to cache */
- a[0] = XMALLOC (MTYPE_TEST, 1024); /* should be satisfied from cache */
- XFREE(MTYPE_TEST, a[0]);
- XFREE(MTYPE_TEST, a[1]);
- }
-
- printf ("malloc x, malloc y, free x, malloc y, free free\n\n");
- /* cache should go invalid, valid, invalid, etc.. */
- for (i = 0; i < TIMES; i++)
- {
- a[0] = XMALLOC (MTYPE_TEST, 512);
- memset (a[0], 1, 512);
- a[1] = XMALLOC (MTYPE_TEST, 1024); /* invalidate cache */
- memset (a[1], 1, 1024);
- XFREE(MTYPE_TEST, a[0]);
- a[0] = XMALLOC (MTYPE_TEST, 1024);
- XFREE(MTYPE_TEST, a[0]);
- XFREE(MTYPE_TEST, a[1]);
- /* cache should become valid again on next request */
- }
+ printf("malloc x, malloc x, free, malloc x, free free\n\n");
+ /* simple case, test cache */
+ for (i = 0; i < TIMES; i++) {
+ a[0] = XMALLOC(MTYPE_TEST, 1024);
+ memset(a[0], 1, 1024);
+ a[1] = XMALLOC(MTYPE_TEST, 1024);
+ memset(a[1], 1, 1024);
+ XFREE(MTYPE_TEST, a[0]); /* should go to cache */
+ a[0] = XMALLOC(MTYPE_TEST,
+ 1024); /* should be satisfied from cache */
+ XFREE(MTYPE_TEST, a[0]);
+ XFREE(MTYPE_TEST, a[1]);
+ }
- printf ("calloc\n\n");
- /* test calloc */
- for (i = 0; i < TIMES; i++)
- {
- a[0] = XCALLOC (MTYPE_TEST, 1024);
- memset (a[0], 1, 1024);
- a[1] = XCALLOC (MTYPE_TEST, 512); /* invalidate cache */
- memset (a[1], 1, 512);
- XFREE(MTYPE_TEST, a[1]);
- XFREE(MTYPE_TEST, a[0]);
- /* alloc == 0, cache can become valid again on next request */
- }
-
- printf ("calloc and realloc\n\n");
- /* check calloc + realloc */
- for (i = 0; i < TIMES; i++)
- {
- printf ("calloc a0 1024\n");
- a[0] = XCALLOC (MTYPE_TEST, 1024);
- memset (a[0], 1, 1024/2);
-
- printf ("calloc 1 1024\n");
- a[1] = XCALLOC (MTYPE_TEST, 1024);
- memset (a[1], 1, 1024/2);
-
- printf ("realloc 0 1024\n");
- a[3] = XREALLOC (MTYPE_TEST, a[0], 2048); /* invalidate cache */
- if (a[3] != NULL)
- a[0] = a[3];
- memset (a[0], 1, 1024);
-
- printf ("calloc 2 512\n");
- a[2] = XCALLOC (MTYPE_TEST, 512);
- memset (a[2], 1, 512);
-
- printf ("free 1 0 2\n");
- XFREE(MTYPE_TEST, a[1]);
- XFREE(MTYPE_TEST, a[0]);
- XFREE(MTYPE_TEST, a[2]);
- /* alloc == 0, cache valid next request */
- }
- return 0;
+ printf("malloc x, malloc y, free x, malloc y, free free\n\n");
+ /* cache should go invalid, valid, invalid, etc.. */
+ for (i = 0; i < TIMES; i++) {
+ a[0] = XMALLOC(MTYPE_TEST, 512);
+ memset(a[0], 1, 512);
+ a[1] = XMALLOC(MTYPE_TEST, 1024); /* invalidate cache */
+ memset(a[1], 1, 1024);
+ XFREE(MTYPE_TEST, a[0]);
+ a[0] = XMALLOC(MTYPE_TEST, 1024);
+ XFREE(MTYPE_TEST, a[0]);
+ XFREE(MTYPE_TEST, a[1]);
+ /* cache should become valid again on next request */
+ }
+
+ printf("calloc\n\n");
+ /* test calloc */
+ for (i = 0; i < TIMES; i++) {
+ a[0] = XCALLOC(MTYPE_TEST, 1024);
+ memset(a[0], 1, 1024);
+ a[1] = XCALLOC(MTYPE_TEST, 512); /* invalidate cache */
+ memset(a[1], 1, 512);
+ XFREE(MTYPE_TEST, a[1]);
+ XFREE(MTYPE_TEST, a[0]);
+ /* alloc == 0, cache can become valid again on next request */
+ }
+
+ printf("calloc and realloc\n\n");
+ /* check calloc + realloc */
+ for (i = 0; i < TIMES; i++) {
+ printf("calloc a0 1024\n");
+ a[0] = XCALLOC(MTYPE_TEST, 1024);
+ memset(a[0], 1, 1024 / 2);
+
+ printf("calloc 1 1024\n");
+ a[1] = XCALLOC(MTYPE_TEST, 1024);
+ memset(a[1], 1, 1024 / 2);
+
+ printf("realloc 0 1024\n");
+ a[3] = XREALLOC(MTYPE_TEST, a[0], 2048); /* invalidate cache */
+ if (a[3] != NULL)
+ a[0] = a[3];
+ memset(a[0], 1, 1024);
+
+ printf("calloc 2 512\n");
+ a[2] = XCALLOC(MTYPE_TEST, 512);
+ memset(a[2], 1, 512);
+
+ printf("free 1 0 2\n");
+ XFREE(MTYPE_TEST, a[1]);
+ XFREE(MTYPE_TEST, a[0]);
+ XFREE(MTYPE_TEST, a[2]);
+ /* alloc == 0, cache valid next request */
+ }
+ return 0;
}
diff --git a/tests/lib/test_nexthop_iter.c b/tests/lib/test_nexthop_iter.c
index 250379329b..8d3e3c509d 100644
--- a/tests/lib/test_nexthop_iter.c
+++ b/tests/lib/test_nexthop_iter.c
@@ -30,139 +30,119 @@
struct thread_master *master;
static int verbose;
-static void
-str_append(char **buf, const char *repr)
+static void str_append(char **buf, const char *repr)
{
- if (*buf)
- {
- *buf = realloc(*buf, strlen(*buf) + strlen(repr) + 1);
- assert(*buf);
- strncpy((*buf) + strlen(*buf), repr, strlen(repr) + 1);
- }
- else
- {
- *buf = strdup(repr);
- assert(*buf);
- }
+ if (*buf) {
+ *buf = realloc(*buf, strlen(*buf) + strlen(repr) + 1);
+ assert(*buf);
+ strncpy((*buf) + strlen(*buf), repr, strlen(repr) + 1);
+ } else {
+ *buf = strdup(repr);
+ assert(*buf);
+ }
}
-static void
-str_appendf(char **buf, const char *format, ...)
+static void str_appendf(char **buf, const char *format, ...)
{
- va_list ap;
- int rv;
- char *pbuf;
+ va_list ap;
+ int rv;
+ char *pbuf;
- va_start(ap, format);
- rv = vasprintf(&pbuf, format, ap);
- va_end(ap);
- assert(rv >= 0);
+ va_start(ap, format);
+ rv = vasprintf(&pbuf, format, ap);
+ va_end(ap);
+ assert(rv >= 0);
- str_append(buf, pbuf);
- free(pbuf);
+ str_append(buf, pbuf);
+ free(pbuf);
}
/* This structure contains a nexthop chain
* and its expected representation */
-struct nexthop_chain
-{
- /* Head of the chain */
- struct nexthop *head;
- /* Last nexthop in top chain */
- struct nexthop *current_top;
- /* Last nexthop in current recursive chain */
- struct nexthop *current_recursive;
- /* Expected string representation. */
- char *repr;
+struct nexthop_chain {
+ /* Head of the chain */
+ struct nexthop *head;
+ /* Last nexthop in top chain */
+ struct nexthop *current_top;
+ /* Last nexthop in current recursive chain */
+ struct nexthop *current_recursive;
+ /* Expected string representation. */
+ char *repr;
};
-static struct nexthop_chain*
-nexthop_chain_new(void)
+static struct nexthop_chain *nexthop_chain_new(void)
{
- struct nexthop_chain *rv;
+ struct nexthop_chain *rv;
- rv = calloc(sizeof(*rv), 1);
- assert(rv);
- return rv;
+ rv = calloc(sizeof(*rv), 1);
+ assert(rv);
+ return rv;
}
-static void
-nexthop_chain_add_top(struct nexthop_chain *nc)
+static void nexthop_chain_add_top(struct nexthop_chain *nc)
{
- struct nexthop *nh;
-
- nh = calloc(sizeof(*nh), 1);
- assert(nh);
-
- if (nc->head)
- {
- nc->current_top->next = nh;
- nh->prev = nc->current_top;
- nc->current_top = nh;
- }
- else
- {
- nc->head = nc->current_top = nh;
- }
- nc->current_recursive = NULL;
- str_appendf(&nc->repr, "%p\n", nh);
+ struct nexthop *nh;
+
+ nh = calloc(sizeof(*nh), 1);
+ assert(nh);
+
+ if (nc->head) {
+ nc->current_top->next = nh;
+ nh->prev = nc->current_top;
+ nc->current_top = nh;
+ } else {
+ nc->head = nc->current_top = nh;
+ }
+ nc->current_recursive = NULL;
+ str_appendf(&nc->repr, "%p\n", nh);
}
-static void
-nexthop_chain_add_recursive(struct nexthop_chain *nc)
+static void nexthop_chain_add_recursive(struct nexthop_chain *nc)
{
- struct nexthop *nh;
-
- nh = calloc(sizeof(*nh), 1);
- assert(nh);
-
- assert(nc->current_top);
- if (nc->current_recursive)
- {
- nc->current_recursive->next = nh;
- nh->prev = nc->current_recursive;
- nc->current_recursive = nh;
- }
- else
- {
- SET_FLAG(nc->current_top->flags, NEXTHOP_FLAG_RECURSIVE);
- nc->current_top->resolved = nh;
- nc->current_recursive = nh;
- }
- str_appendf(&nc->repr, " %p\n", nh);
+ struct nexthop *nh;
+
+ nh = calloc(sizeof(*nh), 1);
+ assert(nh);
+
+ assert(nc->current_top);
+ if (nc->current_recursive) {
+ nc->current_recursive->next = nh;
+ nh->prev = nc->current_recursive;
+ nc->current_recursive = nh;
+ } else {
+ SET_FLAG(nc->current_top->flags, NEXTHOP_FLAG_RECURSIVE);
+ nc->current_top->resolved = nh;
+ nc->current_recursive = nh;
+ }
+ str_appendf(&nc->repr, " %p\n", nh);
}
-static void
-nexthop_chain_clear(struct nexthop_chain *nc)
+static void nexthop_chain_clear(struct nexthop_chain *nc)
{
- struct nexthop *tcur, *tnext;
-
- for (tcur = nc->head; tcur; tcur = tnext)
- {
- tnext = tcur->next;
- if (CHECK_FLAG(tcur->flags, NEXTHOP_FLAG_RECURSIVE))
- {
- struct nexthop *rcur, *rnext;
- for (rcur = tcur->resolved; rcur; rcur = rnext)
- {
- rnext = rcur->next;
- free(rcur);
- }
- }
- free(tcur);
- }
- nc->head = nc->current_top = nc->current_recursive = NULL;
- free(nc->repr);
- nc->repr = NULL;
+ struct nexthop *tcur, *tnext;
+
+ for (tcur = nc->head; tcur; tcur = tnext) {
+ tnext = tcur->next;
+ if (CHECK_FLAG(tcur->flags, NEXTHOP_FLAG_RECURSIVE)) {
+ struct nexthop *rcur, *rnext;
+ for (rcur = tcur->resolved; rcur; rcur = rnext) {
+ rnext = rcur->next;
+ free(rcur);
+ }
+ }
+ free(tcur);
+ }
+ nc->head = nc->current_top = nc->current_recursive = NULL;
+ free(nc->repr);
+ nc->repr = NULL;
}
-static void
-nexthop_chain_free(struct nexthop_chain *nc)
+static void nexthop_chain_free(struct nexthop_chain *nc)
{
- if (!nc)
- return;
- nexthop_chain_clear(nc);
- free(nc);
+ if (!nc)
+ return;
+ nexthop_chain_clear(nc);
+ free(nc);
}
/* This function builds a string representation of
@@ -171,25 +151,24 @@ nexthop_chain_free(struct nexthop_chain *nc)
* correctly over the nexthop chain by comparing the
* generated representation with the expected representation.
*/
-static void
-nexthop_chain_verify_iter(struct nexthop_chain *nc)
+static void nexthop_chain_verify_iter(struct nexthop_chain *nc)
{
- struct nexthop *nh, *tnh;
- int recursing;
- char *repr = NULL;
-
- for (ALL_NEXTHOPS_RO(nc->head, nh, tnh, recursing))
- {
- if (recursing)
- str_appendf(&repr, " %p\n", nh);
- else
- str_appendf(&repr, "%p\n", nh);
- }
-
- if (repr && verbose)
- printf("===\n%s", repr);
- assert((!repr && !nc->repr) || (repr && nc->repr && !strcmp(repr, nc->repr)));
- free(repr);
+ struct nexthop *nh, *tnh;
+ int recursing;
+ char *repr = NULL;
+
+ for (ALL_NEXTHOPS_RO(nc->head, nh, tnh, recursing)) {
+ if (recursing)
+ str_appendf(&repr, " %p\n", nh);
+ else
+ str_appendf(&repr, "%p\n", nh);
+ }
+
+ if (repr && verbose)
+ printf("===\n%s", repr);
+ assert((!repr && !nc->repr)
+ || (repr && nc->repr && !strcmp(repr, nc->repr)));
+ free(repr);
}
/* This test run builds a simple nexthop chain
@@ -197,95 +176,91 @@ nexthop_chain_verify_iter(struct nexthop_chain *nc)
* the iterator works correctly in each stage along
* the way.
*/
-static void
-test_run_first(void)
+static void test_run_first(void)
{
- struct nexthop_chain *nc;
+ struct nexthop_chain *nc;
- nc = nexthop_chain_new();
- nexthop_chain_verify_iter(nc);
+ nc = nexthop_chain_new();
+ nexthop_chain_verify_iter(nc);
- nexthop_chain_add_top(nc);
- nexthop_chain_verify_iter(nc);
+ nexthop_chain_add_top(nc);
+ nexthop_chain_verify_iter(nc);
- nexthop_chain_add_top(nc);
- nexthop_chain_verify_iter(nc);
+ nexthop_chain_add_top(nc);
+ nexthop_chain_verify_iter(nc);
- nexthop_chain_add_recursive(nc);
- nexthop_chain_verify_iter(nc);
+ nexthop_chain_add_recursive(nc);
+ nexthop_chain_verify_iter(nc);
- nexthop_chain_add_recursive(nc);
- nexthop_chain_verify_iter(nc);
+ nexthop_chain_add_recursive(nc);
+ nexthop_chain_verify_iter(nc);
- nexthop_chain_add_top(nc);
- nexthop_chain_verify_iter(nc);
+ nexthop_chain_add_top(nc);
+ nexthop_chain_verify_iter(nc);
- nexthop_chain_add_top(nc);
- nexthop_chain_verify_iter(nc);
+ nexthop_chain_add_top(nc);
+ nexthop_chain_verify_iter(nc);
- nexthop_chain_add_top(nc);
- nexthop_chain_verify_iter(nc);
+ nexthop_chain_add_top(nc);
+ nexthop_chain_verify_iter(nc);
- nexthop_chain_add_recursive(nc);
- nexthop_chain_verify_iter(nc);
+ nexthop_chain_add_recursive(nc);
+ nexthop_chain_verify_iter(nc);
- nexthop_chain_add_recursive(nc);
- nexthop_chain_verify_iter(nc);
+ nexthop_chain_add_recursive(nc);
+ nexthop_chain_verify_iter(nc);
- nexthop_chain_add_recursive(nc);
- nexthop_chain_verify_iter(nc);
+ nexthop_chain_add_recursive(nc);
+ nexthop_chain_verify_iter(nc);
- nexthop_chain_free(nc);
+ nexthop_chain_free(nc);
}
/* This test run builds numerous random
* nexthop chain configurations and verifies
* that the iterator correctly progresses
* through each. */
-static void
-test_run_prng(void)
+static void test_run_prng(void)
{
- struct nexthop_chain *nc;
- struct prng *prng;
- int i;
-
- nc = nexthop_chain_new();
- prng = prng_new(0);
-
- for (i = 0; i < 1000000; i++)
- {
- switch (prng_rand(prng) % 10)
- {
- case 0:
- nexthop_chain_clear(nc);
- break;
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- nexthop_chain_add_top(nc);
- break;
- case 6:
- case 7:
- case 8:
- case 9:
- if (nc->current_top)
- nexthop_chain_add_recursive(nc);
- break;
- }
- nexthop_chain_verify_iter(nc);
- }
- nexthop_chain_free(nc);
- prng_free(prng);
+ struct nexthop_chain *nc;
+ struct prng *prng;
+ int i;
+
+ nc = nexthop_chain_new();
+ prng = prng_new(0);
+
+ for (i = 0; i < 1000000; i++) {
+ switch (prng_rand(prng) % 10) {
+ case 0:
+ nexthop_chain_clear(nc);
+ break;
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ nexthop_chain_add_top(nc);
+ break;
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ if (nc->current_top)
+ nexthop_chain_add_recursive(nc);
+ break;
+ }
+ nexthop_chain_verify_iter(nc);
+ }
+ nexthop_chain_free(nc);
+ prng_free(prng);
}
int main(int argc, char **argv)
{
- if (argc >= 2 && !strcmp("-v", argv[1]))
- verbose = 1;
- test_run_first();
- printf("Simple test passed.\n");
- test_run_prng();
- printf("PRNG test passed.\n");
+ if (argc >= 2 && !strcmp("-v", argv[1]))
+ verbose = 1;
+ test_run_first();
+ printf("Simple test passed.\n");
+ test_run_prng();
+ printf("PRNG test passed.\n");
}
diff --git a/tests/lib/test_privs.c b/tests/lib/test_privs.c
index c6ccc28e7a..57b5593ebf 100644
--- a/tests/lib/test_privs.c
+++ b/tests/lib/test_privs.c
@@ -27,127 +27,115 @@
#include "memory.h"
#include "memory_vty.h"
-zebra_capabilities_t _caps_p [] =
-{
- ZCAP_NET_RAW,
- ZCAP_BIND,
- ZCAP_NET_ADMIN,
- ZCAP_DAC_OVERRIDE,
+zebra_capabilities_t _caps_p[] = {
+ ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN, ZCAP_DAC_OVERRIDE,
};
-struct zebra_privs_t test_privs =
-{
+struct zebra_privs_t test_privs = {
#if defined(FRR_USER) && defined(FRR_GROUP)
- .user = FRR_USER,
- .group = FRR_GROUP,
+ .user = FRR_USER,
+ .group = FRR_GROUP,
#endif
#if defined(VTY_GROUP)
- .vty_group = VTY_GROUP,
+ .vty_group = VTY_GROUP,
#endif
- .caps_p = _caps_p,
- .cap_num_p = sizeof(_caps_p)/sizeof(_caps_p[0]),
- .cap_num_i = 0
-};
+ .caps_p = _caps_p,
+ .cap_num_p = sizeof(_caps_p) / sizeof(_caps_p[0]),
+ .cap_num_i = 0};
-struct option longopts[] =
-{
- { "help", no_argument, NULL, 'h'},
- { "user", required_argument, NULL, 'u'},
- { "group", required_argument, NULL, 'g'},
- { 0 }
-};
+struct option longopts[] = {{"help", no_argument, NULL, 'h'},
+ {"user", required_argument, NULL, 'u'},
+ {"group", required_argument, NULL, 'g'},
+ {0}};
/* 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\
-u, --user User to run as\n\
-g, --group Group to run as\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);
}
struct thread_master *master;
/* main routine. */
-int
-main (int argc, char **argv)
+int main(int argc, char **argv)
{
- char *p;
- char *progname;
- struct zprivs_ids_t ids;
-
- /* Set umask before anything for security */
- umask (0027);
-
- /* get program name */
- progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
-
- while (1)
- {
- int opt;
-
- opt = getopt_long (argc, argv, "hu:g:", longopts, 0);
-
- if (opt == EOF)
- break;
-
- switch (opt)
- {
- case 0:
- break;
- case 'u':
- test_privs.user = optarg;
- break;
- case 'g':
- test_privs.group = optarg;
- break;
- case 'h':
- usage (progname, 0);
- break;
- default:
- usage (progname, 1);
- break;
+ char *p;
+ char *progname;
+ struct zprivs_ids_t ids;
+
+ /* Set umask before anything for security */
+ umask(0027);
+
+ /* get program name */
+ progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]);
+
+ while (1) {
+ int opt;
+
+ opt = getopt_long(argc, argv, "hu:g:", longopts, 0);
+
+ if (opt == EOF)
+ break;
+
+ switch (opt) {
+ case 0:
+ break;
+ case 'u':
+ test_privs.user = optarg;
+ break;
+ case 'g':
+ test_privs.group = optarg;
+ break;
+ case 'h':
+ usage(progname, 0);
+ break;
+ default:
+ usage(progname, 1);
+ break;
+ }
}
- }
-
- /* Library inits. */
- memory_init ();
- zprivs_init (&test_privs);
-
-#define PRIV_STATE() \
- ((test_privs.current_state() == ZPRIVS_RAISED) ? "Raised" : "Lowered")
-
- printf ("%s\n", PRIV_STATE());
- test_privs.change(ZPRIVS_RAISE);
-
- printf ("%s\n", PRIV_STATE());
- test_privs.change(ZPRIVS_LOWER);
-
- printf ("%s\n", PRIV_STATE());
- zprivs_get_ids (&ids);
-
- /* terminate privileges */
- zprivs_terminate(&test_privs);
-
- /* but these should continue to work... */
- printf ("%s\n", PRIV_STATE());
- test_privs.change(ZPRIVS_RAISE);
-
- printf ("%s\n", PRIV_STATE());
- test_privs.change(ZPRIVS_LOWER);
-
- printf ("%s\n", PRIV_STATE());
- zprivs_get_ids (&ids);
-
- printf ("terminating\n");
- return 0;
+
+ /* Library inits. */
+ memory_init();
+ zprivs_init(&test_privs);
+
+#define PRIV_STATE() \
+ ((test_privs.current_state() == ZPRIVS_RAISED) ? "Raised" : "Lowered")
+
+ printf("%s\n", PRIV_STATE());
+ test_privs.change(ZPRIVS_RAISE);
+
+ printf("%s\n", PRIV_STATE());
+ test_privs.change(ZPRIVS_LOWER);
+
+ printf("%s\n", PRIV_STATE());
+ zprivs_get_ids(&ids);
+
+ /* terminate privileges */
+ zprivs_terminate(&test_privs);
+
+ /* but these should continue to work... */
+ printf("%s\n", PRIV_STATE());
+ test_privs.change(ZPRIVS_RAISE);
+
+ printf("%s\n", PRIV_STATE());
+ test_privs.change(ZPRIVS_LOWER);
+
+ printf("%s\n", PRIV_STATE());
+ zprivs_get_ids(&ids);
+
+ printf("terminating\n");
+ return 0;
}
diff --git a/tests/lib/test_segv.c b/tests/lib/test_segv.c
index dfc9d5f482..76e0361c79 100644
--- a/tests/lib/test_segv.c
+++ b/tests/lib/test_segv.c
@@ -29,32 +29,29 @@
#include "lib/log.h"
#include "lib/memory.h"
-struct quagga_signal_t sigs[] =
-{
-};
+struct quagga_signal_t sigs[] = {};
struct thread_master *master;
-static int
-threadfunc (struct thread *thread)
+static int threadfunc(struct thread *thread)
{
- int *null = NULL;
- *null += 1;
- return 0;
+ int *null = NULL;
+ *null += 1;
+ return 0;
}
-int
-main (void)
+int main(void)
{
- master = thread_master_create ();
- signal_init (master, array_size(sigs), sigs);
+ master = thread_master_create();
+ signal_init(master, array_size(sigs), sigs);
- openzlog("testsegv", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
- zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
- zlog_set_level(ZLOG_DEST_STDOUT, LOG_DEBUG);
- zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED);
+ openzlog("testsegv", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID,
+ LOG_DAEMON);
+ zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
+ zlog_set_level(ZLOG_DEST_STDOUT, LOG_DEBUG);
+ zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED);
- thread_execute (master, threadfunc, 0, 0);
+ thread_execute(master, threadfunc, 0, 0);
- exit (0);
+ exit(0);
}
diff --git a/tests/lib/test_sig.c b/tests/lib/test_sig.c
index 10bce2303e..f8749c1409 100644
--- a/tests/lib/test_sig.c
+++ b/tests/lib/test_sig.c
@@ -1,4 +1,4 @@
-/*
+/*
* This file is part of Quagga.
*
* Quagga is free software; you can redistribute it and/or modify it
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with Quagga; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
#include <zebra.h>
@@ -22,56 +22,50 @@
#include "lib/log.h"
#include "lib/memory.h"
-static void
-sighup (void)
+static void sighup(void)
{
- printf ("processed hup\n");
+ printf("processed hup\n");
}
-static void
-sigusr1 (void)
+static void sigusr1(void)
{
- printf ("processed usr1\n");
+ printf("processed usr1\n");
}
-static void
-sigusr2 (void)
+static void sigusr2(void)
{
- printf ("processed usr2\n");
+ printf("processed usr2\n");
}
-struct quagga_signal_t sigs[] =
-{
- {
- .signal = SIGHUP,
- .handler = &sighup,
- },
- {
- .signal = SIGUSR1,
- .handler = &sigusr1,
- },
- {
- .signal = SIGUSR2,
- .handler = &sigusr2,
- }
-};
+struct quagga_signal_t sigs[] = {{
+ .signal = SIGHUP,
+ .handler = &sighup,
+ },
+ {
+ .signal = SIGUSR1,
+ .handler = &sigusr1,
+ },
+ {
+ .signal = SIGUSR2,
+ .handler = &sigusr2,
+ }};
struct thread_master *master;
struct thread t;
-int
-main (void)
+int main(void)
{
- master = thread_master_create ();
- signal_init (master, array_size(sigs), sigs);
+ master = thread_master_create();
+ signal_init(master, array_size(sigs), sigs);
- openzlog("testsig", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
- zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
- zlog_set_level(ZLOG_DEST_STDOUT, LOG_DEBUG);
- zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED);
+ openzlog("testsig", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID,
+ LOG_DAEMON);
+ zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
+ zlog_set_level(ZLOG_DEST_STDOUT, LOG_DEBUG);
+ zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED);
- while (thread_fetch (master, &t))
- thread_call (&t);
+ while (thread_fetch(master, &t))
+ thread_call(&t);
- exit (0);
+ exit(0);
}
diff --git a/tests/lib/test_srcdest_table.c b/tests/lib/test_srcdest_table.c
index cfc2deb8d6..6c9c0c7250 100644
--- a/tests/lib/test_srcdest_table.c
+++ b/tests/lib/test_srcdest_table.c
@@ -48,410 +48,391 @@ struct thread_master *master;
/* This structure is copied from lib/srcdest_table.c to which it is
* private as far as other parts of Quagga are concerned.
*/
-struct srcdest_rnode
-{
- /* must be first in structure for casting to/from route_node */
- ROUTE_NODE_FIELDS;
+struct srcdest_rnode {
+ /* must be first in structure for casting to/from route_node */
+ ROUTE_NODE_FIELDS;
- struct route_table *src_table;
+ struct route_table *src_table;
};
-struct test_state
-{
- struct route_table *table;
- struct hash *log;
+struct test_state {
+ struct route_table *table;
+ struct hash *log;
};
-static char *
-format_srcdest(const struct prefix_ipv6 *dst_p,
- const struct prefix_ipv6 *src_p)
+static char *format_srcdest(const struct prefix_ipv6 *dst_p,
+ const struct prefix_ipv6 *src_p)
{
- char dst_str[BUFSIZ];
- char src_str[BUFSIZ];
- char *rv;
- int ec;
-
- prefix2str((const struct prefix*)dst_p, dst_str, sizeof(dst_str));
- if (src_p && src_p->prefixlen)
- prefix2str((const struct prefix*)src_p, src_str, sizeof(src_str));
- else
- src_str[0] = '\0';
-
- ec = asprintf(&rv, "%s%s%s", dst_str,
- (src_str[0] != '\0') ? " from " : "",
- src_str);
-
- assert(ec > 0);
- return rv;
+ char dst_str[BUFSIZ];
+ char src_str[BUFSIZ];
+ char *rv;
+ int ec;
+
+ prefix2str((const struct prefix *)dst_p, dst_str, sizeof(dst_str));
+ if (src_p && src_p->prefixlen)
+ prefix2str((const struct prefix *)src_p, src_str,
+ sizeof(src_str));
+ else
+ src_str[0] = '\0';
+
+ ec = asprintf(&rv, "%s%s%s", dst_str,
+ (src_str[0] != '\0') ? " from " : "", src_str);
+
+ assert(ec > 0);
+ return rv;
}
static unsigned int log_key(void *data)
{
- struct prefix *hash_entry = data;
- struct prefix_ipv6 *dst_p = (struct prefix_ipv6*) &hash_entry[0];
- struct prefix_ipv6 *src_p = (struct prefix_ipv6*) &hash_entry[1];
- unsigned int hash = 0;
- unsigned int i;
-
- hash = (hash * 33) ^ (unsigned int)dst_p->prefixlen;
- for (i = 0; i < 4; i++)
- hash = (hash * 33) ^ (unsigned int)dst_p->prefix.s6_addr32[i];
-
- hash = (hash * 33) ^ (unsigned int)src_p->prefixlen;
- if (src_p->prefixlen)
- for (i = 0; i < 4; i++)
- hash = (hash * 33) ^ (unsigned int)src_p->prefix.s6_addr32[i];
-
- return hash;
+ struct prefix *hash_entry = data;
+ struct prefix_ipv6 *dst_p = (struct prefix_ipv6 *)&hash_entry[0];
+ struct prefix_ipv6 *src_p = (struct prefix_ipv6 *)&hash_entry[1];
+ unsigned int hash = 0;
+ unsigned int i;
+
+ hash = (hash * 33) ^ (unsigned int)dst_p->prefixlen;
+ for (i = 0; i < 4; i++)
+ hash = (hash * 33) ^ (unsigned int)dst_p->prefix.s6_addr32[i];
+
+ hash = (hash * 33) ^ (unsigned int)src_p->prefixlen;
+ if (src_p->prefixlen)
+ for (i = 0; i < 4; i++)
+ hash = (hash * 33)
+ ^ (unsigned int)src_p->prefix.s6_addr32[i];
+
+ return hash;
}
-static int
-log_cmp(const void *a, const void *b)
+static int log_cmp(const void *a, const void *b)
{
- if (a == NULL && b != NULL)
- return 0;
- if (b == NULL && a != NULL)
- return 0;
+ if (a == NULL && b != NULL)
+ return 0;
+ if (b == NULL && a != NULL)
+ return 0;
- return !memcmp(a, b, 2 * sizeof(struct prefix));
+ return !memcmp(a, b, 2 * sizeof(struct prefix));
}
-static void
-log_free(void *data)
+static void log_free(void *data)
{
- XFREE(MTYPE_TMP, data);
+ XFREE(MTYPE_TMP, data);
}
-static void *
-log_alloc(void *data)
+static void *log_alloc(void *data)
{
- void *rv = XMALLOC(MTYPE_TMP, 2 * sizeof(struct prefix));
- memcpy(rv, data, 2 * sizeof(struct prefix));
- return rv;
+ void *rv = XMALLOC(MTYPE_TMP, 2 * sizeof(struct prefix));
+ memcpy(rv, data, 2 * sizeof(struct prefix));
+ return rv;
}
-static struct test_state *
-test_state_new(void)
+static struct test_state *test_state_new(void)
{
- struct test_state *rv;
+ struct test_state *rv;
- rv = XCALLOC(MTYPE_TMP, sizeof(*rv));
- assert(rv);
+ rv = XCALLOC(MTYPE_TMP, sizeof(*rv));
+ assert(rv);
- rv->table = srcdest_table_init();
- assert(rv->table);
+ rv->table = srcdest_table_init();
+ assert(rv->table);
- rv->log = hash_create(log_key, log_cmp);
- return rv;
+ rv->log = hash_create(log_key, log_cmp);
+ return rv;
}
-static void
-test_state_free(struct test_state *test)
+static void test_state_free(struct test_state *test)
{
- route_table_finish(test->table);
- hash_clean(test->log, log_free);
- hash_free(test->log);
- XFREE(MTYPE_TMP, test);
+ route_table_finish(test->table);
+ hash_clean(test->log, log_free);
+ hash_free(test->log);
+ XFREE(MTYPE_TMP, test);
}
-static void
-test_state_add_route(struct test_state *test,
- struct prefix_ipv6 *dst_p,
- struct prefix_ipv6 *src_p)
+static void test_state_add_route(struct test_state *test,
+ struct prefix_ipv6 *dst_p,
+ struct prefix_ipv6 *src_p)
{
- struct route_node *rn = srcdest_rnode_get(
- test->table, (struct prefix*)dst_p, src_p
- );
- struct prefix hash_entry[2];
-
- memset(hash_entry, 0, sizeof(hash_entry));
- memcpy(&hash_entry[0], dst_p, sizeof(*dst_p));
- memcpy(&hash_entry[1], src_p, sizeof(*src_p));
-
- if (rn->info) {
- route_unlock_node(rn);
- assert(hash_lookup(test->log, hash_entry) != NULL);
- return;
- } else {
- assert(hash_lookup(test->log, hash_entry) == NULL);
- }
-
- rn->info = (void*) 0xdeadbeef;
- hash_get(test->log, hash_entry, log_alloc);
+ struct route_node *rn =
+ srcdest_rnode_get(test->table, (struct prefix *)dst_p, src_p);
+ struct prefix hash_entry[2];
+
+ memset(hash_entry, 0, sizeof(hash_entry));
+ memcpy(&hash_entry[0], dst_p, sizeof(*dst_p));
+ memcpy(&hash_entry[1], src_p, sizeof(*src_p));
+
+ if (rn->info) {
+ route_unlock_node(rn);
+ assert(hash_lookup(test->log, hash_entry) != NULL);
+ return;
+ } else {
+ assert(hash_lookup(test->log, hash_entry) == NULL);
+ }
+
+ rn->info = (void *)0xdeadbeef;
+ hash_get(test->log, hash_entry, log_alloc);
};
-static void
-test_state_del_route(struct test_state *test,
- struct prefix_ipv6 *dst_p,
- struct prefix_ipv6 *src_p)
+static void test_state_del_route(struct test_state *test,
+ struct prefix_ipv6 *dst_p,
+ struct prefix_ipv6 *src_p)
{
- struct route_node *rn = srcdest_rnode_lookup(
- test->table, (struct prefix*)dst_p, src_p
- );
- struct prefix hash_entry[2];
-
- memset(hash_entry, 0, sizeof(hash_entry));
- memcpy(&hash_entry[0], dst_p, sizeof(*dst_p));
- memcpy(&hash_entry[1], src_p, sizeof(*src_p));
-
- if (!rn) {
- assert(!hash_lookup(test->log, hash_entry));
- return;
- }
-
- assert(rn->info == (void*)0xdeadbeef);
- rn->info = NULL;
- route_unlock_node(rn);
- route_unlock_node(rn);
-
- struct prefix *hash_entry_intern = hash_release(test->log, hash_entry);
- assert(hash_entry_intern != NULL);
- XFREE(MTYPE_TMP, hash_entry_intern);
+ struct route_node *rn = srcdest_rnode_lookup(
+ test->table, (struct prefix *)dst_p, src_p);
+ struct prefix hash_entry[2];
+
+ memset(hash_entry, 0, sizeof(hash_entry));
+ memcpy(&hash_entry[0], dst_p, sizeof(*dst_p));
+ memcpy(&hash_entry[1], src_p, sizeof(*src_p));
+
+ if (!rn) {
+ assert(!hash_lookup(test->log, hash_entry));
+ return;
+ }
+
+ assert(rn->info == (void *)0xdeadbeef);
+ rn->info = NULL;
+ route_unlock_node(rn);
+ route_unlock_node(rn);
+
+ struct prefix *hash_entry_intern = hash_release(test->log, hash_entry);
+ assert(hash_entry_intern != NULL);
+ XFREE(MTYPE_TMP, hash_entry_intern);
}
-static void
-verify_log(struct hash_backet* backet, void *arg)
+static void verify_log(struct hash_backet *backet, void *arg)
{
- struct test_state *test = arg;
- struct prefix *hash_entry = backet->data;
- struct prefix *dst_p = &hash_entry[0];
- struct prefix_ipv6 *src_p = (struct prefix_ipv6*)&hash_entry[1];
- struct route_node *rn = srcdest_rnode_lookup(test->table, dst_p, src_p);
+ struct test_state *test = arg;
+ struct prefix *hash_entry = backet->data;
+ struct prefix *dst_p = &hash_entry[0];
+ struct prefix_ipv6 *src_p = (struct prefix_ipv6 *)&hash_entry[1];
+ struct route_node *rn = srcdest_rnode_lookup(test->table, dst_p, src_p);
- assert(rn);
- assert(rn->info == (void*)0xdeadbeef);
+ assert(rn);
+ assert(rn->info == (void *)0xdeadbeef);
- route_unlock_node(rn);
+ route_unlock_node(rn);
}
-static void
-dump_log(struct hash_backet* backet, void *arg)
+static void dump_log(struct hash_backet *backet, void *arg)
{
- struct prefix *hash_entry = backet->data;
- struct prefix_ipv6 *dst_p = (struct prefix_ipv6*)&hash_entry[0];
- struct prefix_ipv6 *src_p = (struct prefix_ipv6*)&hash_entry[1];
- char *route_id = format_srcdest(dst_p, src_p);
+ struct prefix *hash_entry = backet->data;
+ struct prefix_ipv6 *dst_p = (struct prefix_ipv6 *)&hash_entry[0];
+ struct prefix_ipv6 *src_p = (struct prefix_ipv6 *)&hash_entry[1];
+ char *route_id = format_srcdest(dst_p, src_p);
- fprintf(stderr, " %s\n", route_id);
- free(route_id);
+ fprintf(stderr, " %s\n", route_id);
+ free(route_id);
}
-static void
-test_dump(struct test_state *test)
+static void test_dump(struct test_state *test)
{
- fprintf(stderr, "Contents of hash table:\n");
- hash_iterate(test->log, dump_log, test);
- fprintf(stderr, "\n");
+ fprintf(stderr, "Contents of hash table:\n");
+ hash_iterate(test->log, dump_log, test);
+ fprintf(stderr, "\n");
}
-static void
-test_failed(struct test_state *test, const char *message,
- struct prefix_ipv6 *dst_p, struct prefix_ipv6 *src_p)
+static void test_failed(struct test_state *test, const char *message,
+ struct prefix_ipv6 *dst_p, struct prefix_ipv6 *src_p)
{
- char *route_id = format_srcdest(dst_p, src_p);
+ char *route_id = format_srcdest(dst_p, src_p);
- fprintf(stderr, "Test failed. Error: %s\n", message);
- fprintf(stderr, "Route in question: %s\n", route_id);
- free(route_id);
+ fprintf(stderr, "Test failed. Error: %s\n", message);
+ fprintf(stderr, "Route in question: %s\n", route_id);
+ free(route_id);
- test_dump(test);
- assert(3 == 4);
+ test_dump(test);
+ assert(3 == 4);
}
-static void
-test_state_verify(struct test_state *test)
+static void test_state_verify(struct test_state *test)
{
- struct route_node *rn;
- struct prefix hash_entry[2];
-
- memset(hash_entry, 0, sizeof(hash_entry));
-
- /* Verify that there are no elements in the table which have never
- * been added */
- for (rn = route_top(test->table); rn; rn = srcdest_route_next(rn))
- {
- struct prefix_ipv6 *dst_p, *src_p;
-
- /* While we are iterating, we hold a lock on the current route_node,
- * so all the lock counts we check for take that into account; in idle
- * state all the numbers will be exactly one less.
- *
- * Also this makes quite some assumptions based on the current
- * implementation details of route_table and srcdest_table - another
- * valid implementation might trigger assertions here.
- */
-
- if (rnode_is_dstnode(rn))
- {
- struct srcdest_rnode *srn = (struct srcdest_rnode *)rn;
- unsigned int expected_lock = 1; /* We are in the loop */
-
- if (rn->info != NULL) /* The route node is not internal */
- expected_lock++;
- if (srn->src_table != NULL) /* There's a source table associated with rn */
- expected_lock++;
-
- if (rn->lock != expected_lock)
- test_failed(test, "Dest rnode lock count doesn't match expected count!",
- (struct prefix_ipv6*)&rn->p, NULL);
- }
- else
- {
- unsigned int expected_lock = 1; /* We are in the loop */
-
- if (rn->info != NULL) /* The route node is not internal */
- expected_lock++;
-
- if (rn->lock != expected_lock)
- {
- struct prefix_ipv6 *dst_p, *src_p;
- srcdest_rnode_prefixes(rn, (struct prefix**)&dst_p,
- (struct prefix**)&src_p);
-
- test_failed(test, "Src rnode lock count doesn't match expected count!",
- dst_p, src_p);
- }
- }
-
- if (!rn->info)
- continue;
-
- assert(rn->info == (void*)0xdeadbeef);
-
- srcdest_rnode_prefixes(rn, (struct prefix**)&dst_p, (struct prefix**)&src_p);
- memcpy(&hash_entry[0], dst_p, sizeof(*dst_p));
- if (src_p)
- memcpy(&hash_entry[1], src_p, sizeof(*src_p));
- else
- memset(&hash_entry[1], 0, sizeof(hash_entry[1]));
-
- if (hash_lookup(test->log, hash_entry) == NULL)
- test_failed(test, "Route is missing in hash", dst_p, src_p);
- }
-
- /* Verify that all added elements are still in the table */
- hash_iterate(test->log, verify_log, test);
+ struct route_node *rn;
+ struct prefix hash_entry[2];
+
+ memset(hash_entry, 0, sizeof(hash_entry));
+
+ /* Verify that there are no elements in the table which have never
+ * been added */
+ for (rn = route_top(test->table); rn; rn = srcdest_route_next(rn)) {
+ struct prefix_ipv6 *dst_p, *src_p;
+
+ /* While we are iterating, we hold a lock on the current
+ * route_node,
+ * so all the lock counts we check for take that into account;
+ * in idle
+ * state all the numbers will be exactly one less.
+ *
+ * Also this makes quite some assumptions based on the current
+ * implementation details of route_table and srcdest_table -
+ * another
+ * valid implementation might trigger assertions here.
+ */
+
+ if (rnode_is_dstnode(rn)) {
+ struct srcdest_rnode *srn = (struct srcdest_rnode *)rn;
+ unsigned int expected_lock = 1; /* We are in the loop */
+
+ if (rn->info
+ != NULL) /* The route node is not internal */
+ expected_lock++;
+ if (srn->src_table != NULL) /* There's a source table
+ associated with rn */
+ expected_lock++;
+
+ if (rn->lock != expected_lock)
+ test_failed(
+ test,
+ "Dest rnode lock count doesn't match expected count!",
+ (struct prefix_ipv6 *)&rn->p, NULL);
+ } else {
+ unsigned int expected_lock = 1; /* We are in the loop */
+
+ if (rn->info
+ != NULL) /* The route node is not internal */
+ expected_lock++;
+
+ if (rn->lock != expected_lock) {
+ struct prefix_ipv6 *dst_p, *src_p;
+ srcdest_rnode_prefixes(
+ rn, (struct prefix **)&dst_p,
+ (struct prefix **)&src_p);
+
+ test_failed(
+ test,
+ "Src rnode lock count doesn't match expected count!",
+ dst_p, src_p);
+ }
+ }
+
+ if (!rn->info)
+ continue;
+
+ assert(rn->info == (void *)0xdeadbeef);
+
+ srcdest_rnode_prefixes(rn, (struct prefix **)&dst_p,
+ (struct prefix **)&src_p);
+ memcpy(&hash_entry[0], dst_p, sizeof(*dst_p));
+ if (src_p)
+ memcpy(&hash_entry[1], src_p, sizeof(*src_p));
+ else
+ memset(&hash_entry[1], 0, sizeof(hash_entry[1]));
+
+ if (hash_lookup(test->log, hash_entry) == NULL)
+ test_failed(test, "Route is missing in hash", dst_p,
+ src_p);
+ }
+
+ /* Verify that all added elements are still in the table */
+ hash_iterate(test->log, verify_log, test);
}
-static void
-get_rand_prefix(struct prng *prng, struct prefix_ipv6 *p)
+static void get_rand_prefix(struct prng *prng, struct prefix_ipv6 *p)
{
- int i;
+ int i;
- memset(p, 0, sizeof(*p));
+ memset(p, 0, sizeof(*p));
- for (i = 0; i < 4; i++)
- p->prefix.s6_addr32[i] = prng_rand(prng);
- p->prefixlen = prng_rand(prng) % 129;
- p->family = AF_INET6;
+ for (i = 0; i < 4; i++)
+ p->prefix.s6_addr32[i] = prng_rand(prng);
+ p->prefixlen = prng_rand(prng) % 129;
+ p->family = AF_INET6;
- apply_mask((struct prefix*)p);
+ apply_mask((struct prefix *)p);
}
-static void
-get_rand_prefix_pair(struct prng *prng, struct prefix_ipv6 *dst_p,
- struct prefix_ipv6 *src_p)
+static void get_rand_prefix_pair(struct prng *prng, struct prefix_ipv6 *dst_p,
+ struct prefix_ipv6 *src_p)
{
- get_rand_prefix(prng, dst_p);
- if ((prng_rand(prng) % 4) == 0)
- {
- get_rand_prefix(prng, src_p);
- if (src_p->prefixlen)
- return;
- }
-
- memset(src_p, 0, sizeof(*src_p));
+ get_rand_prefix(prng, dst_p);
+ if ((prng_rand(prng) % 4) == 0) {
+ get_rand_prefix(prng, src_p);
+ if (src_p->prefixlen)
+ return;
+ }
+
+ memset(src_p, 0, sizeof(*src_p));
}
-static void
-test_state_add_rand_route(struct test_state *test,
- struct prng *prng)
+static void test_state_add_rand_route(struct test_state *test,
+ struct prng *prng)
{
- struct prefix_ipv6 dst_p, src_p;
+ struct prefix_ipv6 dst_p, src_p;
- get_rand_prefix_pair(prng, &dst_p, &src_p);
- test_state_add_route(test, &dst_p, &src_p);
+ get_rand_prefix_pair(prng, &dst_p, &src_p);
+ test_state_add_route(test, &dst_p, &src_p);
}
-static void
-test_state_del_rand_route(struct test_state *test,
- struct prng *prng)
+static void test_state_del_rand_route(struct test_state *test,
+ struct prng *prng)
{
- struct prefix_ipv6 dst_p, src_p;
+ struct prefix_ipv6 dst_p, src_p;
- get_rand_prefix_pair(prng, &dst_p, &src_p);
- test_state_del_route(test, &dst_p, &src_p);
+ get_rand_prefix_pair(prng, &dst_p, &src_p);
+ test_state_del_route(test, &dst_p, &src_p);
}
-static void
-test_state_del_one_route(struct test_state *test,
- struct prng *prng)
+static void test_state_del_one_route(struct test_state *test, struct prng *prng)
{
- unsigned int which_route = prng_rand(prng) % test->log->count;
- struct route_node *rn;
- struct prefix *dst_p, *src_p;
- struct prefix_ipv6 dst6_p, src6_p;
-
- for (rn = route_top(test->table); rn; rn = srcdest_route_next(rn))
- {
- if (!rn->info)
- continue;
- if (!which_route) {
- route_unlock_node(rn);
- break;
- }
- which_route--;
- }
-
- assert(rn);
- srcdest_rnode_prefixes(rn, &dst_p, &src_p);
- memcpy(&dst6_p, dst_p, sizeof(dst6_p));
- if (src_p)
- memcpy(&src6_p, src_p, sizeof(src6_p));
- else
- memset(&src6_p, 0, sizeof(src6_p));
-
- test_state_del_route(test, &dst6_p, &src6_p);
+ unsigned int which_route = prng_rand(prng) % test->log->count;
+ struct route_node *rn;
+ struct prefix *dst_p, *src_p;
+ struct prefix_ipv6 dst6_p, src6_p;
+
+ for (rn = route_top(test->table); rn; rn = srcdest_route_next(rn)) {
+ if (!rn->info)
+ continue;
+ if (!which_route) {
+ route_unlock_node(rn);
+ break;
+ }
+ which_route--;
+ }
+
+ assert(rn);
+ srcdest_rnode_prefixes(rn, &dst_p, &src_p);
+ memcpy(&dst6_p, dst_p, sizeof(dst6_p));
+ if (src_p)
+ memcpy(&src6_p, src_p, sizeof(src6_p));
+ else
+ memset(&src6_p, 0, sizeof(src6_p));
+
+ test_state_del_route(test, &dst6_p, &src6_p);
}
-static void
-run_prng_test(void)
+static void run_prng_test(void)
{
- struct test_state *test = test_state_new();
- struct prng *prng = prng_new(0);
- size_t i;
-
- for (i = 0; i < 1000; i++)
- {
- switch (prng_rand(prng) % 10)
- {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- test_state_add_rand_route(test, prng);
- break;
- case 5:
- case 6:
- case 7:
- test_state_del_one_route(test, prng);
- break;
- case 8:
- case 9:
- test_state_del_rand_route(test, prng);
- break;
- }
- test_state_verify(test);
- }
-
- prng_free(prng);
- test_state_free(test);
+ struct test_state *test = test_state_new();
+ struct prng *prng = prng_new(0);
+ size_t i;
+
+ for (i = 0; i < 1000; i++) {
+ switch (prng_rand(prng) % 10) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ test_state_add_rand_route(test, prng);
+ break;
+ case 5:
+ case 6:
+ case 7:
+ test_state_del_one_route(test, prng);
+ break;
+ case 8:
+ case 9:
+ test_state_del_rand_route(test, prng);
+ break;
+ }
+ test_state_verify(test);
+ }
+
+ prng_free(prng);
+ test_state_free(test);
}
int main(int argc, char *argv[])
{
- run_prng_test();
- printf("PRNG Test successful.\n");
- return 0;
+ run_prng_test();
+ printf("PRNG Test successful.\n");
+ return 0;
}
diff --git a/tests/lib/test_stream.c b/tests/lib/test_stream.c
index 3ac45eb203..ad7615696c 100644
--- a/tests/lib/test_stream.c
+++ b/tests/lib/test_stream.c
@@ -1,5 +1,5 @@
/* Simple stream test.
- *
+ *
* Copyright (C) 2006 Sun Microsystems, Inc.
*
* This file is part of Quagga.
@@ -17,7 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with Quagga; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*/
#include <zebra.h>
@@ -27,50 +27,45 @@
static unsigned long long ham = 0xdeadbeefdeadbeef;
struct thread_master *master;
-static void
-print_stream (struct stream *s)
+static void print_stream(struct stream *s)
{
- size_t getp = stream_get_getp (s);
-
- printf ("endp: %zu, readable: %zu, writeable: %zu\n",
- stream_get_endp (s),
- STREAM_READABLE (s),
- STREAM_WRITEABLE (s));
-
- while (STREAM_READABLE (s))
- {
- printf ("0x%x ", *stream_pnt (s));
- stream_forward_getp (s, 1);
- }
-
- printf ("\n");
-
- /* put getp back to where it was */
- stream_set_getp (s, getp);
+ size_t getp = stream_get_getp(s);
+
+ printf("endp: %zu, readable: %zu, writeable: %zu\n", stream_get_endp(s),
+ STREAM_READABLE(s), STREAM_WRITEABLE(s));
+
+ while (STREAM_READABLE(s)) {
+ printf("0x%x ", *stream_pnt(s));
+ stream_forward_getp(s, 1);
+ }
+
+ printf("\n");
+
+ /* put getp back to where it was */
+ stream_set_getp(s, getp);
}
-int
-main (void)
+int main(void)
{
- struct stream *s;
-
- s = stream_new (1024);
-
- stream_putc (s, ham);
- stream_putw (s, ham);
- stream_putl (s, ham);
- stream_putq (s, ham);
-
- print_stream (s);
-
- stream_resize (s, stream_get_endp (s));
-
- print_stream (s);
-
- printf ("c: 0x%hhx\n", stream_getc (s));
- printf ("w: 0x%hx\n", stream_getw (s));
- printf ("l: 0x%x\n", stream_getl (s));
- printf ("q: 0x%" PRIx64 "\n", stream_getq (s));
-
- return 0;
+ struct stream *s;
+
+ s = stream_new(1024);
+
+ stream_putc(s, ham);
+ stream_putw(s, ham);
+ stream_putl(s, ham);
+ stream_putq(s, ham);
+
+ print_stream(s);
+
+ stream_resize(s, stream_get_endp(s));
+
+ print_stream(s);
+
+ printf("c: 0x%hhx\n", stream_getc(s));
+ printf("w: 0x%hx\n", stream_getw(s));
+ printf("l: 0x%x\n", stream_getl(s));
+ printf("q: 0x%" PRIx64 "\n", stream_getq(s));
+
+ return 0;
}
diff --git a/tests/lib/test_table.c b/tests/lib/test_table.c
index 4042e1aaa2..b049542eb8 100644
--- a/tests/lib/test_table.c
+++ b/tests/lib/test_table.c
@@ -30,14 +30,13 @@
*
* Information that is kept for each node in the radix tree.
*/
-typedef struct test_node_t_
-{
+typedef struct test_node_t_ {
- /*
- * Human readable representation of the string. Allocated using
- * malloc()/dup().
- */
- char *prefix_str;
+ /*
+ * Human readable representation of the string. Allocated using
+ * malloc()/dup().
+ */
+ char *prefix_str;
} test_node_t;
struct thread_master *master;
@@ -47,32 +46,29 @@ struct thread_master *master;
*
* Add the given prefix (passed in as a string) to the given table.
*/
-static void
-add_node (struct route_table *table, const char *prefix_str)
+static void add_node(struct route_table *table, const char *prefix_str)
{
- struct prefix_ipv4 p;
- test_node_t *node;
- struct route_node *rn;
-
- assert (prefix_str);
-
- if (str2prefix_ipv4 (prefix_str, &p) <= 0)
- {
- assert (0);
- }
-
- rn = route_node_get (table, (struct prefix *) &p);
- if (rn->info)
- {
- assert (0);
- return;
- }
-
- node = malloc (sizeof (test_node_t));
- assert (node);
- node->prefix_str = strdup (prefix_str);
- assert (node->prefix_str);
- rn->info = node;
+ struct prefix_ipv4 p;
+ test_node_t *node;
+ struct route_node *rn;
+
+ assert(prefix_str);
+
+ if (str2prefix_ipv4(prefix_str, &p) <= 0) {
+ assert(0);
+ }
+
+ rn = route_node_get(table, (struct prefix *)&p);
+ if (rn->info) {
+ assert(0);
+ return;
+ }
+
+ node = malloc(sizeof(test_node_t));
+ assert(node);
+ node->prefix_str = strdup(prefix_str);
+ assert(node->prefix_str);
+ rn->info = node;
}
/*
@@ -83,22 +79,20 @@ add_node (struct route_table *table, const char *prefix_str)
* The arguments must be prefixes in string format, with a NULL as the
* last argument.
*/
-static void
-add_nodes (struct route_table *table, ...)
+static void add_nodes(struct route_table *table, ...)
{
- va_list arglist;
- char *prefix;
+ va_list arglist;
+ char *prefix;
- va_start (arglist, table);
+ va_start(arglist, table);
- prefix = va_arg (arglist, char *);
- while (prefix)
- {
- add_node (table, prefix);
- prefix = va_arg (arglist, char *);
- }
+ prefix = va_arg(arglist, char *);
+ while (prefix) {
+ add_node(table, prefix);
+ prefix = va_arg(arglist, char *);
+ }
- va_end (arglist);
+ va_end(arglist);
}
/*
@@ -108,35 +102,31 @@ add_nodes (struct route_table *table, ...)
*
* @see print_table
*/
-static void
-print_subtree (struct route_node *rn, const char *legend, int indent_level)
+static void print_subtree(struct route_node *rn, const char *legend,
+ int indent_level)
{
- char buf[PREFIX2STR_BUFFER];
- int i;
-
- /*
- * Print this node first.
- */
- for (i = 0; i < indent_level; i++)
- {
- printf (" ");
- }
-
- prefix2str (&rn->p, buf, sizeof (buf));
- printf ("%s: %s", legend, buf);
- if (!rn->info)
- {
- printf (" (internal)");
- }
- printf ("\n");
- if (rn->l_left)
- {
- print_subtree (rn->l_left, "Left", indent_level + 1);
- }
- if (rn->l_right)
- {
- print_subtree (rn->l_right, "Right", indent_level + 1);
- }
+ char buf[PREFIX2STR_BUFFER];
+ int i;
+
+ /*
+ * Print this node first.
+ */
+ for (i = 0; i < indent_level; i++) {
+ printf(" ");
+ }
+
+ prefix2str(&rn->p, buf, sizeof(buf));
+ printf("%s: %s", legend, buf);
+ if (!rn->info) {
+ printf(" (internal)");
+ }
+ printf("\n");
+ if (rn->l_left) {
+ print_subtree(rn->l_left, "Left", indent_level + 1);
+ }
+ if (rn->l_right) {
+ print_subtree(rn->l_right, "Right", indent_level + 1);
+ }
}
/*
@@ -144,20 +134,18 @@ print_subtree (struct route_node *rn, const char *legend, int indent_level)
*
* Function that prints out the internal structure of a route table.
*/
-static void
-print_table (struct route_table *table)
+static void print_table(struct route_table *table)
{
- struct route_node *rn;
+ struct route_node *rn;
- rn = table->top;
+ rn = table->top;
- if (!rn)
- {
- printf ("<Empty Table>\n");
- return;
- }
+ if (!rn) {
+ printf("<Empty Table>\n");
+ return;
+ }
- print_subtree (rn, "Top", 0);
+ print_subtree(rn, "Top", 0);
}
/*
@@ -165,31 +153,28 @@ print_table (struct route_table *table)
*
* Remove all nodes from the given table.
*/
-static void
-clear_table (struct route_table *table)
+static void clear_table(struct route_table *table)
{
- route_table_iter_t iter;
- struct route_node *rn;
- test_node_t *node;
-
- route_table_iter_init (&iter, table);
-
- while ((rn = route_table_iter_next (&iter)))
- {
- node = rn->info;
- if (!node)
- {
- continue;
+ route_table_iter_t iter;
+ struct route_node *rn;
+ test_node_t *node;
+
+ route_table_iter_init(&iter, table);
+
+ while ((rn = route_table_iter_next(&iter))) {
+ node = rn->info;
+ if (!node) {
+ continue;
+ }
+ rn->info = NULL;
+ route_unlock_node(rn);
+ free(node->prefix_str);
+ free(node);
}
- rn->info = NULL;
- route_unlock_node (rn);
- free (node->prefix_str);
- free (node);
- }
- route_table_iter_cleanup (&iter);
+ route_table_iter_cleanup(&iter);
- assert (table->top == NULL);
+ assert(table->top == NULL);
}
/*
@@ -199,29 +184,26 @@ clear_table (struct route_table *table)
* target_pfx is the expected one. Note that target_pfx may not be
* present in the tree.
*/
-static void
-verify_next_by_iterating (struct route_table *table,
- struct prefix *target_pfx, struct prefix *next_pfx)
+static void verify_next_by_iterating(struct route_table *table,
+ struct prefix *target_pfx,
+ struct prefix *next_pfx)
{
- route_table_iter_t iter;
- struct route_node *rn;
-
- route_table_iter_init (&iter, table);
- while ((rn = route_table_iter_next (&iter)))
- {
- if (route_table_prefix_iter_cmp (&rn->p, target_pfx) > 0)
- {
- assert (!prefix_cmp (&rn->p, next_pfx));
- break;
+ route_table_iter_t iter;
+ struct route_node *rn;
+
+ route_table_iter_init(&iter, table);
+ while ((rn = route_table_iter_next(&iter))) {
+ if (route_table_prefix_iter_cmp(&rn->p, target_pfx) > 0) {
+ assert(!prefix_cmp(&rn->p, next_pfx));
+ break;
+ }
}
- }
- if (!rn)
- {
- assert (!next_pfx);
- }
+ if (!rn) {
+ assert(!next_pfx);
+ }
- route_table_iter_cleanup (&iter);
+ route_table_iter_cleanup(&iter);
}
/*
@@ -230,200 +212,190 @@ verify_next_by_iterating (struct route_table *table,
* Verifies that route_table_get_next() returns the expected result
* (result) for the prefix string 'target'.
*/
-static void
-verify_next (struct route_table *table, const char *target, const char *next)
+static void verify_next(struct route_table *table, const char *target,
+ const char *next)
{
- struct prefix_ipv4 target_pfx, next_pfx;
- struct route_node *rn;
- char result_buf[PREFIX2STR_BUFFER];
-
- if (str2prefix_ipv4 (target, &target_pfx) <= 0)
- {
- assert (0);
- }
-
- rn = route_table_get_next (table, (struct prefix *) &target_pfx);
- if (rn)
- {
- prefix2str (&rn->p, result_buf, sizeof (result_buf));
- }
- else
- {
- snprintf (result_buf, sizeof (result_buf), "(Null)");
- }
-
- printf ("\n");
- print_table (table);
- printf ("Verifying successor of %s. Expected: %s, Result: %s\n", target,
- next ? next : "(Null)", result_buf);
-
- if (!rn)
- {
- assert (!next);
- verify_next_by_iterating (table, (struct prefix *) &target_pfx, NULL);
- return;
- }
-
- assert (next);
-
- if (str2prefix_ipv4 (next, &next_pfx) <= 0)
- {
- assert (0);
- }
-
- if (prefix_cmp (&rn->p, (struct prefix *) &next_pfx))
- {
- assert (0);
- }
- route_unlock_node (rn);
-
- verify_next_by_iterating (table, (struct prefix *) &target_pfx,
- (struct prefix *) &next_pfx);
+ struct prefix_ipv4 target_pfx, next_pfx;
+ struct route_node *rn;
+ char result_buf[PREFIX2STR_BUFFER];
+
+ if (str2prefix_ipv4(target, &target_pfx) <= 0) {
+ assert(0);
+ }
+
+ rn = route_table_get_next(table, (struct prefix *)&target_pfx);
+ if (rn) {
+ prefix2str(&rn->p, result_buf, sizeof(result_buf));
+ } else {
+ snprintf(result_buf, sizeof(result_buf), "(Null)");
+ }
+
+ printf("\n");
+ print_table(table);
+ printf("Verifying successor of %s. Expected: %s, Result: %s\n", target,
+ next ? next : "(Null)", result_buf);
+
+ if (!rn) {
+ assert(!next);
+ verify_next_by_iterating(table, (struct prefix *)&target_pfx,
+ NULL);
+ return;
+ }
+
+ assert(next);
+
+ if (str2prefix_ipv4(next, &next_pfx) <= 0) {
+ assert(0);
+ }
+
+ if (prefix_cmp(&rn->p, (struct prefix *)&next_pfx)) {
+ assert(0);
+ }
+ route_unlock_node(rn);
+
+ verify_next_by_iterating(table, (struct prefix *)&target_pfx,
+ (struct prefix *)&next_pfx);
}
/*
* test_get_next
*/
-static void
-test_get_next (void)
+static void test_get_next(void)
{
- struct route_table *table;
-
- printf ("\n\nTesting route_table_get_next()\n");
- table = route_table_init ();
-
- /*
- * Target exists in tree, but has no successor.
- */
- add_nodes (table, "1.0.1.0/24", NULL);
- verify_next (table, "1.0.1.0/24", NULL);
- clear_table (table);
-
- /*
- * Target exists in tree, and there is a node in its left subtree.
- */
- add_nodes (table, "1.0.1.0/24", "1.0.1.0/25", NULL);
- verify_next (table, "1.0.1.0/24", "1.0.1.0/25");
- clear_table (table);
-
- /*
- * Target exists in tree, and there is a node in its right subtree.
- */
- add_nodes (table, "1.0.1.0/24", "1.0.1.128/25", NULL);
- verify_next (table, "1.0.1.0/24", "1.0.1.128/25");
- clear_table (table);
-
- /*
- * Target exists in the tree, next node is outside subtree.
- */
- add_nodes (table, "1.0.1.0/24", "1.1.0.0/16", NULL);
- verify_next (table, "1.0.1.0/24", "1.1.0.0/16");
- clear_table (table);
-
- /*
- * The target node does not exist in the tree for all the test cases
- * below this point.
- */
-
- /*
- * There is no successor in the tree.
- */
- add_nodes (table, "1.0.0.0/16", NULL);
- verify_next (table, "1.0.1.0/24", NULL);
- clear_table (table);
-
- /*
- * There exists a node that would be in the target's left subtree.
- */
- add_nodes (table, "1.0.0.0/16", "1.0.1.0/25", NULL);
- verify_next (table, "1.0.1.0/24", "1.0.1.0/25");
- clear_table (table);
-
- /*
- * There exists a node would be in the target's right subtree.
- */
- add_nodes (table, "1.0.0.0/16", "1.0.1.128/25", NULL);
- verify_next (table, "1.0.1.0/24", "1.0.1.128/25");
- clear_table (table);
-
- /*
- * A search for the target reaches a node where there are no child
- * nodes in the direction of the target (left), but the node has a
- * right child.
- */
- add_nodes (table, "1.0.0.0/16", "1.0.128.0/17", NULL);
- verify_next (table, "1.0.0.0/17", "1.0.128.0/17");
- clear_table (table);
-
- /*
- * A search for the target reaches a node with no children. We have
- * to go upwards in the tree to find a successor.
- */
- add_nodes (table, "1.0.0.0/16", "1.0.0.0/24", "1.0.1.0/24",
- "1.0.128.0/17", NULL);
- verify_next (table, "1.0.1.0/25", "1.0.128.0/17");
- clear_table (table);
-
- /*
- * A search for the target reaches a node where neither the node nor
- * the target prefix contain each other.
- *
- * In first case below the node succeeds the target.
- *
- * In the second case, the node comes before the target, so we have
- * to go up the tree looking for a successor.
- */
- add_nodes (table, "1.0.0.0/16", "1.0.1.0/24", NULL);
- verify_next (table, "1.0.0.0/24", "1.0.1.0/24");
- clear_table (table);
-
- add_nodes (table, "1.0.0.0/16", "1.0.0.0/24", "1.0.1.0/25",
- "1.0.128.0/17", NULL);
- verify_next (table, "1.0.1.128/25", "1.0.128.0/17");
- clear_table (table);
-
- route_table_finish (table);
+ struct route_table *table;
+
+ printf("\n\nTesting route_table_get_next()\n");
+ table = route_table_init();
+
+ /*
+ * Target exists in tree, but has no successor.
+ */
+ add_nodes(table, "1.0.1.0/24", NULL);
+ verify_next(table, "1.0.1.0/24", NULL);
+ clear_table(table);
+
+ /*
+ * Target exists in tree, and there is a node in its left subtree.
+ */
+ add_nodes(table, "1.0.1.0/24", "1.0.1.0/25", NULL);
+ verify_next(table, "1.0.1.0/24", "1.0.1.0/25");
+ clear_table(table);
+
+ /*
+ * Target exists in tree, and there is a node in its right subtree.
+ */
+ add_nodes(table, "1.0.1.0/24", "1.0.1.128/25", NULL);
+ verify_next(table, "1.0.1.0/24", "1.0.1.128/25");
+ clear_table(table);
+
+ /*
+ * Target exists in the tree, next node is outside subtree.
+ */
+ add_nodes(table, "1.0.1.0/24", "1.1.0.0/16", NULL);
+ verify_next(table, "1.0.1.0/24", "1.1.0.0/16");
+ clear_table(table);
+
+ /*
+ * The target node does not exist in the tree for all the test cases
+ * below this point.
+ */
+
+ /*
+ * There is no successor in the tree.
+ */
+ add_nodes(table, "1.0.0.0/16", NULL);
+ verify_next(table, "1.0.1.0/24", NULL);
+ clear_table(table);
+
+ /*
+ * There exists a node that would be in the target's left subtree.
+ */
+ add_nodes(table, "1.0.0.0/16", "1.0.1.0/25", NULL);
+ verify_next(table, "1.0.1.0/24", "1.0.1.0/25");
+ clear_table(table);
+
+ /*
+ * There exists a node would be in the target's right subtree.
+ */
+ add_nodes(table, "1.0.0.0/16", "1.0.1.128/25", NULL);
+ verify_next(table, "1.0.1.0/24", "1.0.1.128/25");
+ clear_table(table);
+
+ /*
+ * A search for the target reaches a node where there are no child
+ * nodes in the direction of the target (left), but the node has a
+ * right child.
+ */
+ add_nodes(table, "1.0.0.0/16", "1.0.128.0/17", NULL);
+ verify_next(table, "1.0.0.0/17", "1.0.128.0/17");
+ clear_table(table);
+
+ /*
+ * A search for the target reaches a node with no children. We have
+ * to go upwards in the tree to find a successor.
+ */
+ add_nodes(table, "1.0.0.0/16", "1.0.0.0/24", "1.0.1.0/24",
+ "1.0.128.0/17", NULL);
+ verify_next(table, "1.0.1.0/25", "1.0.128.0/17");
+ clear_table(table);
+
+ /*
+ * A search for the target reaches a node where neither the node nor
+ * the target prefix contain each other.
+ *
+ * In first case below the node succeeds the target.
+ *
+ * In the second case, the node comes before the target, so we have
+ * to go up the tree looking for a successor.
+ */
+ add_nodes(table, "1.0.0.0/16", "1.0.1.0/24", NULL);
+ verify_next(table, "1.0.0.0/24", "1.0.1.0/24");
+ clear_table(table);
+
+ add_nodes(table, "1.0.0.0/16", "1.0.0.0/24", "1.0.1.0/25",
+ "1.0.128.0/17", NULL);
+ verify_next(table, "1.0.1.128/25", "1.0.128.0/17");
+ clear_table(table);
+
+ route_table_finish(table);
}
/*
* verify_prefix_iter_cmp
*/
-static void
-verify_prefix_iter_cmp (const char *p1, const char *p2, int exp_result)
+static void verify_prefix_iter_cmp(const char *p1, const char *p2,
+ int exp_result)
{
- struct prefix_ipv4 p1_pfx, p2_pfx;
- int result;
+ struct prefix_ipv4 p1_pfx, p2_pfx;
+ int result;
- if (str2prefix_ipv4 (p1, &p1_pfx) <= 0)
- {
- assert (0);
- }
+ if (str2prefix_ipv4(p1, &p1_pfx) <= 0) {
+ assert(0);
+ }
- if (str2prefix_ipv4 (p2, &p2_pfx) <= 0)
- {
- assert (0);
- }
+ if (str2prefix_ipv4(p2, &p2_pfx) <= 0) {
+ assert(0);
+ }
- result = route_table_prefix_iter_cmp ((struct prefix *) &p1_pfx,
- (struct prefix *) &p2_pfx);
+ result = route_table_prefix_iter_cmp((struct prefix *)&p1_pfx,
+ (struct prefix *)&p2_pfx);
- printf ("Verifying cmp(%s, %s) returns %d\n", p1, p2, exp_result);
+ printf("Verifying cmp(%s, %s) returns %d\n", p1, p2, exp_result);
- assert (exp_result == result);
+ assert(exp_result == result);
- /*
- * Also check the reverse comparision.
- */
- result = route_table_prefix_iter_cmp ((struct prefix *) &p2_pfx,
- (struct prefix *) &p1_pfx);
+ /*
+ * Also check the reverse comparision.
+ */
+ result = route_table_prefix_iter_cmp((struct prefix *)&p2_pfx,
+ (struct prefix *)&p1_pfx);
- if (exp_result)
- {
- exp_result = -exp_result;
- }
+ if (exp_result) {
+ exp_result = -exp_result;
+ }
- printf ("Verifying cmp(%s, %s) returns %d\n", p1, p2, exp_result);
- assert (result == exp_result);
+ printf("Verifying cmp(%s, %s) returns %d\n", p1, p2, exp_result);
+ assert(result == exp_result);
}
/*
@@ -431,16 +403,15 @@ verify_prefix_iter_cmp (const char *p1, const char *p2, int exp_result)
*
* Tests comparision of prefixes according to order of iteration.
*/
-static void
-test_prefix_iter_cmp ()
+static void test_prefix_iter_cmp()
{
- printf ("\n\nTesting route_table_prefix_iter_cmp()\n");
+ printf("\n\nTesting route_table_prefix_iter_cmp()\n");
- verify_prefix_iter_cmp ("1.0.0.0/8", "1.0.0.0/8", 0);
+ verify_prefix_iter_cmp("1.0.0.0/8", "1.0.0.0/8", 0);
- verify_prefix_iter_cmp ("1.0.0.0/8", "1.0.0.0/16", -1);
+ verify_prefix_iter_cmp("1.0.0.0/8", "1.0.0.0/16", -1);
- verify_prefix_iter_cmp ("1.0.0.0/16", "1.128.0.0/16", -1);
+ verify_prefix_iter_cmp("1.0.0.0/16", "1.128.0.0/16", -1);
}
/*
@@ -450,105 +421,92 @@ test_prefix_iter_cmp ()
* iterator that pauses at each node. Verifies that the two methods
* yield the same results.
*/
-static void
-verify_iter_with_pause (struct route_table *table)
+static void verify_iter_with_pause(struct route_table *table)
{
- unsigned long num_nodes;
- struct route_node *rn, *iter_rn;
- route_table_iter_t iter_space;
- route_table_iter_t *iter = &iter_space;
-
- route_table_iter_init (iter, table);
- num_nodes = 0;
-
- for (rn = route_top (table); rn; rn = route_next (rn))
- {
- num_nodes++;
- route_table_iter_pause (iter);
-
- assert (iter->current == NULL);
- if (route_table_iter_started (iter))
- {
- assert (iter->state == RT_ITER_STATE_PAUSED);
- }
- else
- {
- assert (rn == table->top);
- assert (iter->state == RT_ITER_STATE_INIT);
+ unsigned long num_nodes;
+ struct route_node *rn, *iter_rn;
+ route_table_iter_t iter_space;
+ route_table_iter_t *iter = &iter_space;
+
+ route_table_iter_init(iter, table);
+ num_nodes = 0;
+
+ for (rn = route_top(table); rn; rn = route_next(rn)) {
+ num_nodes++;
+ route_table_iter_pause(iter);
+
+ assert(iter->current == NULL);
+ if (route_table_iter_started(iter)) {
+ assert(iter->state == RT_ITER_STATE_PAUSED);
+ } else {
+ assert(rn == table->top);
+ assert(iter->state == RT_ITER_STATE_INIT);
+ }
+
+ iter_rn = route_table_iter_next(iter);
+
+ /*
+ * Make sure both iterations return the same node.
+ */
+ assert(rn == iter_rn);
}
- iter_rn = route_table_iter_next (iter);
-
- /*
- * Make sure both iterations return the same node.
- */
- assert (rn == iter_rn);
- }
+ assert(num_nodes == route_table_count(table));
- assert (num_nodes == route_table_count (table));
+ route_table_iter_pause(iter);
+ iter_rn = route_table_iter_next(iter);
- route_table_iter_pause (iter);
- iter_rn = route_table_iter_next (iter);
+ assert(iter_rn == NULL);
+ assert(iter->state == RT_ITER_STATE_DONE);
- assert (iter_rn == NULL);
- assert (iter->state == RT_ITER_STATE_DONE);
+ assert(route_table_iter_next(iter) == NULL);
+ assert(iter->state == RT_ITER_STATE_DONE);
- assert (route_table_iter_next (iter) == NULL);
- assert (iter->state == RT_ITER_STATE_DONE);
+ route_table_iter_cleanup(iter);
- route_table_iter_cleanup (iter);
-
- print_table (table);
- printf ("Verified pausing iteration on tree with %lu nodes\n", num_nodes);
+ print_table(table);
+ printf("Verified pausing iteration on tree with %lu nodes\n",
+ num_nodes);
}
/*
* test_iter_pause
*/
-static void
-test_iter_pause (void)
+static void test_iter_pause(void)
{
- struct route_table *table;
- int i, num_prefixes;
- const char *prefixes[] = {
- "1.0.1.0/24",
- "1.0.1.0/25",
- "1.0.1.128/25",
- "1.0.2.0/24",
- "2.0.0.0/8"
- };
-
- num_prefixes = sizeof (prefixes) / sizeof (prefixes[0]);
-
- printf ("\n\nTesting that route_table_iter_pause() works as expected\n");
- table = route_table_init ();
- for (i = 0; i < num_prefixes; i++)
- {
- add_nodes (table, prefixes[i], NULL);
- }
-
- verify_iter_with_pause (table);
-
- clear_table (table);
- route_table_finish (table);
+ struct route_table *table;
+ int i, num_prefixes;
+ const char *prefixes[] = {"1.0.1.0/24", "1.0.1.0/25", "1.0.1.128/25",
+ "1.0.2.0/24", "2.0.0.0/8"};
+
+ num_prefixes = sizeof(prefixes) / sizeof(prefixes[0]);
+
+ printf("\n\nTesting that route_table_iter_pause() works as expected\n");
+ table = route_table_init();
+ for (i = 0; i < num_prefixes; i++) {
+ add_nodes(table, prefixes[i], NULL);
+ }
+
+ verify_iter_with_pause(table);
+
+ clear_table(table);
+ route_table_finish(table);
}
/*
* run_tests
*/
-static void
-run_tests (void)
+static void run_tests(void)
{
- test_prefix_iter_cmp ();
- test_get_next ();
- test_iter_pause ();
+ test_prefix_iter_cmp();
+ test_get_next();
+ test_iter_pause();
}
/*
* main
*/
-int
-main (void)
+int main(void)
{
- run_tests ();
+ run_tests();
}
diff --git a/tests/lib/test_timer_correctness.c b/tests/lib/test_timer_correctness.c
index e523929be1..31d936d8a4 100644
--- a/tests/lib/test_timer_correctness.c
+++ b/tests/lib/test_timer_correctness.c
@@ -56,142 +56,136 @@ static int timers_pending;
static void terminate_test(void)
{
- int exit_code;
-
- if (strcmp(log_buf, expected_buf))
- {
- fprintf(stderr, "Expected output and received output differ.\n");
- fprintf(stderr, "---Expected output: ---\n%s", expected_buf);
- fprintf(stderr, "---Actual output: ---\n%s", log_buf);
- exit_code = 1;
- }
- else
- {
- printf("Expected output and actual output match.\n");
- exit_code = 0;
- }
-
- thread_master_free(master);
- XFREE(MTYPE_TMP, log_buf);
- XFREE(MTYPE_TMP, expected_buf);
- prng_free(prng);
- XFREE(MTYPE_TMP, timers);
-
- exit(exit_code);
+ int exit_code;
+
+ if (strcmp(log_buf, expected_buf)) {
+ fprintf(stderr,
+ "Expected output and received output differ.\n");
+ fprintf(stderr, "---Expected output: ---\n%s", expected_buf);
+ fprintf(stderr, "---Actual output: ---\n%s", log_buf);
+ exit_code = 1;
+ } else {
+ printf("Expected output and actual output match.\n");
+ exit_code = 0;
+ }
+
+ thread_master_free(master);
+ XFREE(MTYPE_TMP, log_buf);
+ XFREE(MTYPE_TMP, expected_buf);
+ prng_free(prng);
+ XFREE(MTYPE_TMP, timers);
+
+ exit(exit_code);
}
static int timer_func(struct thread *thread)
{
- int rv;
+ int rv;
- rv = snprintf(log_buf + log_buf_pos, log_buf_len - log_buf_pos,
- "%s\n", (char*)thread->arg);
- assert(rv >= 0);
- log_buf_pos += rv;
- assert(log_buf_pos < log_buf_len);
- XFREE(MTYPE_TMP, thread->arg);
+ rv = snprintf(log_buf + log_buf_pos, log_buf_len - log_buf_pos, "%s\n",
+ (char *)thread->arg);
+ assert(rv >= 0);
+ log_buf_pos += rv;
+ assert(log_buf_pos < log_buf_len);
+ XFREE(MTYPE_TMP, thread->arg);
- timers_pending--;
- if (!timers_pending)
- terminate_test();
+ timers_pending--;
+ if (!timers_pending)
+ terminate_test();
- return 0;
+ return 0;
}
-static int cmp_timeval(const void* a, const void *b)
+static int cmp_timeval(const void *a, const void *b)
{
- const struct timeval *ta = *(struct timeval * const *)a;
- const struct timeval *tb = *(struct timeval * const *)b;
-
- if (timercmp(ta, tb, <))
- return -1;
- if (timercmp(ta, tb, >))
- return 1;
- return 0;
+ const struct timeval *ta = *(struct timeval * const *)a;
+ const struct timeval *tb = *(struct timeval * const *)b;
+
+ if (timercmp(ta, tb, <))
+ return -1;
+ if (timercmp(ta, tb, >))
+ return 1;
+ return 0;
}
int main(int argc, char **argv)
{
- int i, j;
- struct thread t;
- struct timeval **alarms;
-
- master = thread_master_create();
-
- log_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1;
- log_buf_pos = 0;
- log_buf = XMALLOC(MTYPE_TMP, log_buf_len);
-
- expected_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1;
- expected_buf_pos = 0;
- expected_buf = XMALLOC(MTYPE_TMP, expected_buf_len);
-
- prng = prng_new(0);
-
- timers = XMALLOC(MTYPE_TMP, SCHEDULE_TIMERS * sizeof(*timers));
-
- for (i = 0; i < SCHEDULE_TIMERS; i++)
- {
- long interval_msec;
- int ret;
- char *arg;
-
- /* Schedule timers to expire in 0..5 seconds */
- interval_msec = prng_rand(prng) % 5000;
- arg = XMALLOC(MTYPE_TMP, TIMESTR_LEN + 1);
- timers[i] = thread_add_timer_msec(master, timer_func, arg, interval_msec);
- ret = snprintf(arg, TIMESTR_LEN + 1, "%lld.%06lld",
- (long long)timers[i]->u.sands.tv_sec,
- (long long)timers[i]->u.sands.tv_usec);
- assert(ret > 0);
- assert((size_t)ret < TIMESTR_LEN + 1);
- timers_pending++;
- }
-
- for (i = 0; i < REMOVE_TIMERS; i++)
- {
- int index;
-
- index = prng_rand(prng) % SCHEDULE_TIMERS;
- if (!timers[index])
- continue;
-
- XFREE(MTYPE_TMP, timers[index]->arg);
- thread_cancel(timers[index]);
- timers[index] = NULL;
- timers_pending--;
- }
-
- /* We create an array of pointers to the alarm times and sort
- * that array. That sorted array is used to generate a string
- * representing the expected "output" of the timers when they
- * are run. */
- j = 0;
- alarms = XMALLOC(MTYPE_TMP, timers_pending * sizeof(*alarms));
- for (i = 0; i < SCHEDULE_TIMERS; i++)
- {
- if (!timers[i])
- continue;
- alarms[j++] = &timers[i]->u.sands;
- }
- qsort(alarms, j, sizeof(*alarms), cmp_timeval);
- for (i = 0; i < j; i++)
- {
- int ret;
-
- ret = snprintf(expected_buf + expected_buf_pos,
- expected_buf_len - expected_buf_pos,
- "%lld.%06lld\n",
- (long long)alarms[i]->tv_sec,
- (long long)alarms[i]->tv_usec);
- assert(ret > 0);
- expected_buf_pos += ret;
- assert(expected_buf_pos < expected_buf_len);
- }
- XFREE(MTYPE_TMP, alarms);
-
- while (thread_fetch(master, &t))
- thread_call(&t);
-
- return 0;
+ int i, j;
+ struct thread t;
+ struct timeval **alarms;
+
+ master = thread_master_create();
+
+ log_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1;
+ log_buf_pos = 0;
+ log_buf = XMALLOC(MTYPE_TMP, log_buf_len);
+
+ expected_buf_len = SCHEDULE_TIMERS * (TIMESTR_LEN + 1) + 1;
+ expected_buf_pos = 0;
+ expected_buf = XMALLOC(MTYPE_TMP, expected_buf_len);
+
+ prng = prng_new(0);
+
+ timers = XMALLOC(MTYPE_TMP, SCHEDULE_TIMERS * sizeof(*timers));
+
+ for (i = 0; i < SCHEDULE_TIMERS; i++) {
+ long interval_msec;
+ int ret;
+ char *arg;
+
+ /* Schedule timers to expire in 0..5 seconds */
+ interval_msec = prng_rand(prng) % 5000;
+ arg = XMALLOC(MTYPE_TMP, TIMESTR_LEN + 1);
+ timers[i] = thread_add_timer_msec(master, timer_func, arg,
+ interval_msec);
+ ret = snprintf(arg, TIMESTR_LEN + 1, "%lld.%06lld",
+ (long long)timers[i]->u.sands.tv_sec,
+ (long long)timers[i]->u.sands.tv_usec);
+ assert(ret > 0);
+ assert((size_t)ret < TIMESTR_LEN + 1);
+ timers_pending++;
+ }
+
+ for (i = 0; i < REMOVE_TIMERS; i++) {
+ int index;
+
+ index = prng_rand(prng) % SCHEDULE_TIMERS;
+ if (!timers[index])
+ continue;
+
+ XFREE(MTYPE_TMP, timers[index]->arg);
+ thread_cancel(timers[index]);
+ timers[index] = NULL;
+ timers_pending--;
+ }
+
+ /* We create an array of pointers to the alarm times and sort
+ * that array. That sorted array is used to generate a string
+ * representing the expected "output" of the timers when they
+ * are run. */
+ j = 0;
+ alarms = XMALLOC(MTYPE_TMP, timers_pending * sizeof(*alarms));
+ for (i = 0; i < SCHEDULE_TIMERS; i++) {
+ if (!timers[i])
+ continue;
+ alarms[j++] = &timers[i]->u.sands;
+ }
+ qsort(alarms, j, sizeof(*alarms), cmp_timeval);
+ for (i = 0; i < j; i++) {
+ int ret;
+
+ ret = snprintf(expected_buf + expected_buf_pos,
+ expected_buf_len - expected_buf_pos,
+ "%lld.%06lld\n", (long long)alarms[i]->tv_sec,
+ (long long)alarms[i]->tv_usec);
+ assert(ret > 0);
+ expected_buf_pos += ret;
+ assert(expected_buf_pos < expected_buf_len);
+ }
+ XFREE(MTYPE_TMP, alarms);
+
+ while (thread_fetch(master, &t))
+ thread_call(&t);
+
+ return 0;
}
diff --git a/tests/lib/test_timer_performance.c b/tests/lib/test_timer_performance.c
index a7d09beecc..f3878532c4 100644
--- a/tests/lib/test_timer_performance.c
+++ b/tests/lib/test_timer_performance.c
@@ -39,67 +39,65 @@ struct thread_master *master;
static int dummy_func(struct thread *thread)
{
- return 0;
+ return 0;
}
int main(int argc, char **argv)
{
- struct prng *prng;
- int i;
- struct thread **timers;
- struct timeval tv_start, tv_lap, tv_stop;
- unsigned long t_schedule, t_remove;
-
- master = thread_master_create();
- prng = prng_new(0);
- timers = calloc(SCHEDULE_TIMERS, sizeof(*timers));
-
- /* create thread structures so they won't be allocated during the
- * time measurement */
- for (i = 0; i < SCHEDULE_TIMERS; i++)
- timers[i] = thread_add_timer_msec(master, dummy_func, NULL, 0);
- for (i = 0; i < SCHEDULE_TIMERS; i++)
- thread_cancel(timers[i]);
-
- monotime(&tv_start);
-
- for (i = 0; i < SCHEDULE_TIMERS; i++)
- {
- long interval_msec;
-
- interval_msec = prng_rand(prng) % (100 * SCHEDULE_TIMERS);
- timers[i] = thread_add_timer_msec(master, dummy_func,
- NULL, interval_msec);
- }
-
- monotime(&tv_lap);
-
- for (i = 0; i < REMOVE_TIMERS; i++)
- {
- int index;
-
- index = prng_rand(prng) % SCHEDULE_TIMERS;
- if (timers[index])
- thread_cancel(timers[index]);
- timers[index] = NULL;
- }
-
- monotime(&tv_stop);
-
- t_schedule = 1000 * (tv_lap.tv_sec - tv_start.tv_sec);
- t_schedule += (tv_lap.tv_usec - tv_start.tv_usec) / 1000;
-
- t_remove = 1000 * (tv_stop.tv_sec - tv_lap.tv_sec);
- t_remove += (tv_stop.tv_usec - tv_lap.tv_usec) / 1000;
-
- printf("Scheduling %d random timers took %ld.%03ld seconds.\n",
- SCHEDULE_TIMERS, t_schedule/1000, t_schedule%1000);
- printf("Removing %d random timers took %ld.%03ld seconds.\n",
- REMOVE_TIMERS, t_remove/1000, t_remove%1000);
- fflush(stdout);
-
- free(timers);
- thread_master_free(master);
- prng_free(prng);
- return 0;
+ struct prng *prng;
+ int i;
+ struct thread **timers;
+ struct timeval tv_start, tv_lap, tv_stop;
+ unsigned long t_schedule, t_remove;
+
+ master = thread_master_create();
+ prng = prng_new(0);
+ timers = calloc(SCHEDULE_TIMERS, sizeof(*timers));
+
+ /* create thread structures so they won't be allocated during the
+ * time measurement */
+ for (i = 0; i < SCHEDULE_TIMERS; i++)
+ timers[i] = thread_add_timer_msec(master, dummy_func, NULL, 0);
+ for (i = 0; i < SCHEDULE_TIMERS; i++)
+ thread_cancel(timers[i]);
+
+ monotime(&tv_start);
+
+ for (i = 0; i < SCHEDULE_TIMERS; i++) {
+ long interval_msec;
+
+ interval_msec = prng_rand(prng) % (100 * SCHEDULE_TIMERS);
+ timers[i] = thread_add_timer_msec(master, dummy_func, NULL,
+ interval_msec);
+ }
+
+ monotime(&tv_lap);
+
+ for (i = 0; i < REMOVE_TIMERS; i++) {
+ int index;
+
+ index = prng_rand(prng) % SCHEDULE_TIMERS;
+ if (timers[index])
+ thread_cancel(timers[index]);
+ timers[index] = NULL;
+ }
+
+ monotime(&tv_stop);
+
+ t_schedule = 1000 * (tv_lap.tv_sec - tv_start.tv_sec);
+ t_schedule += (tv_lap.tv_usec - tv_start.tv_usec) / 1000;
+
+ t_remove = 1000 * (tv_stop.tv_sec - tv_lap.tv_sec);
+ t_remove += (tv_stop.tv_usec - tv_lap.tv_usec) / 1000;
+
+ printf("Scheduling %d random timers took %ld.%03ld seconds.\n",
+ SCHEDULE_TIMERS, t_schedule / 1000, t_schedule % 1000);
+ printf("Removing %d random timers took %ld.%03ld seconds.\n",
+ REMOVE_TIMERS, t_remove / 1000, t_remove % 1000);
+ fflush(stdout);
+
+ free(timers);
+ thread_master_free(master);
+ prng_free(prng);
+ return 0;
}