X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest%2Fcommands.c;h=76f6ee5d233a45b0aaf8427ab4159e0a3cf03382;hb=88caad251c8de3a84e353b0b2a27014bc303df87;hp=94fbc310ed818b42e9815f6ff48d9a969733d303;hpb=a9de470cc7c0649221e156fc5f30a2dbdfe7c166;p=dpdk.git diff --git a/app/test/commands.c b/app/test/commands.c index 94fbc310ed..76f6ee5d23 100644 --- a/app/test/commands.c +++ b/app/test/commands.c @@ -10,11 +10,6 @@ #include #include #include -#ifndef __linux__ -#ifndef __FreeBSD__ -#include -#endif -#endif #include #include #include @@ -44,6 +39,7 @@ #include #include #include +#include #include "test.h" @@ -63,8 +59,8 @@ struct cmd_autotest_result { }; static void cmd_autotest_parsed(void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - __attribute__((unused)) void *data) + __rte_unused struct cmdline *cl, + __rte_unused void *data) { struct test_command *t; struct cmd_autotest_result *res = parsed_result; @@ -116,8 +112,8 @@ dump_struct_sizes(void) } static void cmd_dump_parsed(void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - __attribute__((unused)) void *data) + __rte_unused struct cmdline *cl, + __rte_unused void *data) { struct cmd_dump_result *res = parsed_result; @@ -171,7 +167,7 @@ struct cmd_dump_one_result { }; static void cmd_dump_one_parsed(void *parsed_result, struct cmdline *cl, - __attribute__((unused)) void *data) + __rte_unused void *data) { struct cmd_dump_one_result *res = parsed_result; @@ -220,9 +216,9 @@ struct cmd_quit_result { }; static void -cmd_quit_parsed(__attribute__((unused)) void *parsed_result, +cmd_quit_parsed(__rte_unused void *parsed_result, struct cmdline *cl, - __attribute__((unused)) void *data) + __rte_unused void *data) { cmdline_quit(cl); } @@ -249,7 +245,7 @@ struct cmd_set_rxtx_result { }; static void cmd_set_rxtx_parsed(void *parsed_result, struct cmdline *cl, - __attribute__((unused)) void *data) + __rte_unused void *data) { struct cmd_set_rxtx_result *res = parsed_result; if (test_set_rxtx_conf(res->mode) < 0) @@ -285,7 +281,7 @@ struct cmd_set_rxtx_anchor { static void cmd_set_rxtx_anchor_parsed(void *parsed_result, struct cmdline *cl, - __attribute__((unused)) void *data) + __rte_unused void *data) { struct cmd_set_rxtx_anchor *res = parsed_result; if (test_set_rxtx_anchor(res->type) < 0) @@ -322,7 +318,7 @@ struct cmd_set_rxtx_sc { static void cmd_set_rxtx_sc_parsed(void *parsed_result, struct cmdline *cl, - __attribute__((unused)) void *data) + __rte_unused void *data) { struct cmd_set_rxtx_sc *res = parsed_result; if (test_set_rxtx_sc(res->type) < 0) @@ -365,24 +361,34 @@ cmdline_parse_ctx_t main_ctx[] = { int commands_init(void) { struct test_command *t; - char *commands, *ptr; + char *commands; int commands_len = 0; TAILQ_FOREACH(t, &commands_list, next) { commands_len += strlen(t->command) + 1; } - commands = malloc(commands_len + 1); + commands = (char *)calloc(commands_len, sizeof(char)); if (!commands) return -1; - ptr = commands; TAILQ_FOREACH(t, &commands_list, next) { - ptr += sprintf(ptr, "%s#", t->command); + strlcat(commands, t->command, commands_len); + if (TAILQ_NEXT(t, next) != NULL) + strlcat(commands, "#", commands_len); } - ptr--; - ptr[0] = '\0'; cmd_autotest_autotest.string_data.str = commands; return 0; } + +int command_valid(const char *cmd) +{ + struct test_command *t; + + TAILQ_FOREACH(t, &commands_list, next) { + if (strcmp(t->command, cmd) == 0) + return 1; + } + return 0; +}