X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=app%2Ftest%2Ftest_cmdline_lib.c;h=bd72df0da2b4d9ef1b17b38637eca79d3c0f3219;hb=23ea199b732bf54861aaea49e52c1089334b29ae;hp=65b823a726bec4720c85474f51b292f5bf9a1615;hpb=3031749c2df04a63cdcef186dcce3781e61436e8;p=dpdk.git diff --git a/app/test/test_cmdline_lib.c b/app/test/test_cmdline_lib.c index 65b823a726..bd72df0da2 100644 --- a/app/test/test_cmdline_lib.c +++ b/app/test/test_cmdline_lib.c @@ -1,34 +1,5 @@ -/*- - * BSD LICENSE - * - * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation */ #include @@ -41,6 +12,8 @@ #include #include +#include + #include #include #include @@ -52,18 +25,18 @@ /****************************************************************/ /* static functions required for some tests */ static void -valid_buffer(__attribute__((unused))struct rdline *rdl, - __attribute__((unused))const char *buf, - __attribute__((unused)) unsigned int size) +valid_buffer(__rte_unused struct rdline *rdl, + __rte_unused const char *buf, + __rte_unused unsigned int size) { } static int -complete_buffer(__attribute__((unused)) struct rdline *rdl, - __attribute__((unused)) const char *buf, - __attribute__((unused)) char *dstbuf, - __attribute__((unused)) unsigned int dstsize, - __attribute__((unused)) int *state) +complete_buffer(__rte_unused struct rdline *rdl, + __rte_unused const char *buf, + __rte_unused char *dstbuf, + __rte_unused unsigned int dstsize, + __rte_unused int *state) { return 0; } @@ -73,22 +46,29 @@ complete_buffer(__attribute__((unused)) struct rdline *rdl, static int test_cmdline_parse_fns(void) { - struct cmdline cl; + struct cmdline *cl; + cmdline_parse_ctx_t ctx; int i = 0; char dst[CMDLINE_TEST_BUFSIZE]; + cl = cmdline_new(&ctx, "prompt", -1, -1); + if (cl == NULL) { + printf("Error: cannot create cmdline to test parse fns!\n"); + return -1; + } + if (cmdline_parse(NULL, "buffer") >= 0) goto error; - if (cmdline_parse(&cl, NULL) >= 0) + if (cmdline_parse(cl, NULL) >= 0) goto error; if (cmdline_complete(NULL, "buffer", &i, dst, sizeof(dst)) >= 0) goto error; - if (cmdline_complete(&cl, NULL, &i, dst, sizeof(dst)) >= 0) + if (cmdline_complete(cl, NULL, &i, dst, sizeof(dst)) >= 0) goto error; - if (cmdline_complete(&cl, "buffer", NULL, dst, sizeof(dst)) >= 0) + if (cmdline_complete(cl, "buffer", NULL, dst, sizeof(dst)) >= 0) goto error; - if (cmdline_complete(&cl, "buffer", &i, NULL, sizeof(dst)) >= 0) + if (cmdline_complete(cl, "buffer", &i, NULL, sizeof(dst)) >= 0) goto error; return 0; @@ -193,11 +173,11 @@ static int test_cmdline_fns(void) { cmdline_parse_ctx_t ctx; - struct cmdline cl, *tmp; + struct cmdline *cl; memset(&ctx, 0, sizeof(ctx)); - tmp = cmdline_new(&ctx, "test", -1, -1); - if (tmp == NULL) + cl = cmdline_new(&ctx, "test", -1, -1); + if (cl == NULL) goto error; if (cmdline_new(NULL, "prompt", 0, 0) != NULL) @@ -206,7 +186,7 @@ test_cmdline_fns(void) goto error; if (cmdline_in(NULL, "buffer", CMDLINE_TEST_BUFSIZE) >= 0) goto error; - if (cmdline_in(&cl, NULL, CMDLINE_TEST_BUFSIZE) >= 0) + if (cmdline_in(cl, NULL, CMDLINE_TEST_BUFSIZE) >= 0) goto error; if (cmdline_write_char(NULL, 0) >= 0) goto error; @@ -215,30 +195,15 @@ test_cmdline_fns(void) cmdline_set_prompt(NULL, "prompt"); cmdline_free(NULL); cmdline_printf(NULL, "format"); - /* this should fail as stream handles are invalid */ - cmdline_printf(tmp, "format"); cmdline_interact(NULL); cmdline_quit(NULL); - /* check if void calls change anything when they should fail */ - cl = *tmp; - - cmdline_printf(&cl, NULL); - if (memcmp(&cl, tmp, sizeof(cl))) goto mismatch; - cmdline_set_prompt(&cl, NULL); - if (memcmp(&cl, tmp, sizeof(cl))) goto mismatch; - cmdline_in(&cl, NULL, CMDLINE_TEST_BUFSIZE); - if (memcmp(&cl, tmp, sizeof(cl))) goto mismatch; - - cmdline_free(tmp); - return 0; error: printf("Error: function accepted null parameter!\n"); - return -1; -mismatch: - printf("Error: data changed!\n"); + if (cl != NULL) + cmdline_free(cl); return -1; }