From patchwork Fri Nov 3 09:53:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 133826 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1775E43279; Fri, 3 Nov 2023 10:56:27 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 355CD42D28; Fri, 3 Nov 2023 10:56:12 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id D332F4027F for ; Fri, 3 Nov 2023 10:56:08 +0100 (CET) Received: from dggpeml100024.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SMGN325srzvQbS; Fri, 3 Nov 2023 17:56:03 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml100024.china.huawei.com (7.185.36.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 3 Nov 2023 17:56:04 +0800 From: Chengwen Feng To: , CC: Subject: [PATCH 1/7] app/test: introduce UT suite framework for kvargs Date: Fri, 3 Nov 2023 09:53:19 +0000 Message-ID: <20231103095325.47843-2-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231103095325.47843-1-fengchengwen@huawei.com> References: <20231103095325.47843-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml100024.china.huawei.com (7.185.36.115) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Introduce unit test suite framework for test_kvargs.c. Signed-off-by: Chengwen Feng --- app/test/test_kvargs.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/test/test_kvargs.c b/app/test/test_kvargs.c index 7a60cac4c1..9aeb9aa0aa 100644 --- a/app/test/test_kvargs.c +++ b/app/test/test_kvargs.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright 2014 6WIND S.A. + * Copyright(c) 2023 HiSilicon Limited */ #include @@ -280,16 +281,21 @@ static int test_invalid_kvargs(void) return -1; } +static struct unit_test_suite kvargs_test_suite = { + .suite_name = "Kvargs Unit Test Suite", + .setup = NULL, + .teardown = NULL, + .unit_test_cases = { + TEST_CASE(test_valid_kvargs), + TEST_CASE(test_invalid_kvargs), + TEST_CASES_END() /**< NULL terminate unit test array */ + } +}; + static int test_kvargs(void) { - printf("== test valid case ==\n"); - if (test_valid_kvargs() < 0) - return -1; - printf("== test invalid case ==\n"); - if (test_invalid_kvargs() < 0) - return -1; - return 0; + return unit_test_suite_runner(&kvargs_test_suite); } REGISTER_FAST_TEST(kvargs_autotest, true, true, test_kvargs); From patchwork Fri Nov 3 09:53:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 133827 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 67D3843279; Fri, 3 Nov 2023 10:56:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2CC4B42D83; Fri, 3 Nov 2023 10:56:13 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id DDEAD402EB for ; Fri, 3 Nov 2023 10:56:08 +0100 (CET) Received: from dggpeml100024.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SMGN32K1qzvQbZ; Fri, 3 Nov 2023 17:56:03 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml100024.china.huawei.com (7.185.36.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 3 Nov 2023 17:56:04 +0800 From: Chengwen Feng To: , CC: Subject: [PATCH 2/7] app/test: extract basic token count testcase for kvargs Date: Fri, 3 Nov 2023 09:53:20 +0000 Message-ID: <20231103095325.47843-3-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231103095325.47843-1-fengchengwen@huawei.com> References: <20231103095325.47843-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml100024.china.huawei.com (7.185.36.115) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The test_valid_kvargs() function is too long to understand, extract the basic token count tests as one stand-alone testcase. Signed-off-by: Chengwen Feng --- app/test/test_kvargs.c | 120 ++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 75 deletions(-) diff --git a/app/test/test_kvargs.c b/app/test/test_kvargs.c index 9aeb9aa0aa..a27b2aabfb 100644 --- a/app/test/test_kvargs.c +++ b/app/test/test_kvargs.c @@ -36,25 +36,6 @@ static int check_handler(const char *key, const char *value, return 0; } -/* test parsing. */ -static int test_kvargs_parsing(const char *args, unsigned int n) -{ - struct rte_kvargs *kvlist; - - kvlist = rte_kvargs_parse(args, NULL); - if (kvlist == NULL) { - printf("rte_kvargs_parse() error: %s\n", args); - return -1; - } - if (kvlist->count != n) { - printf("invalid count value %d: %s\n", kvlist->count, args); - rte_kvargs_free(kvlist); - return -1; - } - rte_kvargs_free(kvlist); - return 0; -} - /* test a valid case */ static int test_valid_kvargs(void) { @@ -62,29 +43,6 @@ static int test_valid_kvargs(void) const char *args; const char *valid_keys_list[] = { "foo", "check", NULL }; const char **valid_keys; - static const struct { - unsigned int expected; - const char *input; - } valid_inputs[] = { - { 2, "foo=1,foo=" }, - { 2, "foo=1,foo=" }, - { 2, "foo=1,foo" }, - { 2, "foo=1,=2" }, - { 1, "foo=[1,2" }, - { 1, ",=" }, - { 1, "foo=[" }, - }; - unsigned int i; - - /* empty args is valid */ - args = ""; - valid_keys = NULL; - kvlist = rte_kvargs_parse(args, valid_keys); - if (kvlist == NULL) { - printf("rte_kvargs_parse() error"); - goto fail; - } - rte_kvargs_free(kvlist); /* first test without valid_keys */ args = "foo=1234,check=value0,check=value1"; @@ -128,14 +86,6 @@ static int test_valid_kvargs(void) rte_kvargs_free(kvlist); goto fail; } - /* count all entries */ - count = rte_kvargs_count(kvlist, NULL); - if (count != 3) { - printf("invalid count value %d after rte_kvargs_count(NULL)\n", - count); - rte_kvargs_free(kvlist); - goto fail; - } /* count all entries with key="nonexistent_key" */ count = rte_kvargs_count(kvlist, "nonexistent_key"); if (count != 0) { @@ -190,19 +140,6 @@ static int test_valid_kvargs(void) } rte_kvargs_free(kvlist); - /* test using empty string (it is valid) */ - args = ""; - kvlist = rte_kvargs_parse(args, NULL); - if (kvlist == NULL) { - printf("rte_kvargs_parse() error\n"); - goto fail; - } - if (rte_kvargs_count(kvlist, NULL) != 0) { - printf("invalid count value\n"); - goto fail; - } - rte_kvargs_free(kvlist); - /* test using empty elements (it is valid) */ args = "foo=1,,check=value2,,"; kvlist = rte_kvargs_parse(args, NULL); @@ -210,10 +147,6 @@ static int test_valid_kvargs(void) printf("rte_kvargs_parse() error\n"); goto fail; } - if (rte_kvargs_count(kvlist, NULL) != 2) { - printf("invalid count value\n"); - goto fail; - } if (rte_kvargs_count(kvlist, "foo") != 1) { printf("invalid count value for 'foo'\n"); goto fail; @@ -224,14 +157,6 @@ static int test_valid_kvargs(void) } rte_kvargs_free(kvlist); - valid_keys = NULL; - - for (i = 0; i < RTE_DIM(valid_inputs); ++i) { - args = valid_inputs[i].input; - if (test_kvargs_parsing(args, valid_inputs[i].expected)) - goto fail; - } - return 0; fail: @@ -246,6 +171,50 @@ static int test_valid_kvargs(void) return -1; } +static int +test_basic_token_count(void) +{ + static const struct { + unsigned int expected; + const char *input; + } valid_inputs[] = { + { 3, "foo=1,check=1,check=2" }, + { 3, "foo=1,check,check=2" }, + { 2, "foo=1,foo=" }, + { 2, "foo=1,foo=" }, + { 2, "foo=1,foo" }, + { 2, "foo=1,=2" }, + { 2, "foo=1,,foo=2,," }, + { 1, "foo=[1,2" }, + { 1, ",=" }, + { 1, "foo=[" }, + { 0, "" }, + }; + struct rte_kvargs *kvlist; + unsigned int count; + const char *args; + unsigned int i; + + for (i = 0; i < RTE_DIM(valid_inputs); i++) { + args = valid_inputs[i].input; + kvlist = rte_kvargs_parse(args, NULL); + if (kvlist == NULL) { + printf("rte_kvargs_parse() error: %s\n", args); + return -1; + } + count = rte_kvargs_count(kvlist, NULL); + if (count != valid_inputs[i].expected) { + printf("invalid count value %u (expected %u): %s\n", + count, valid_inputs[i].expected, args); + rte_kvargs_free(kvlist); + return -1; + } + rte_kvargs_free(kvlist); + } + + return 0; +} + /* test several error cases */ static int test_invalid_kvargs(void) { @@ -287,6 +256,7 @@ static struct unit_test_suite kvargs_test_suite = { .teardown = NULL, .unit_test_cases = { TEST_CASE(test_valid_kvargs), + TEST_CASE(test_basic_token_count), TEST_CASE(test_invalid_kvargs), TEST_CASES_END() /**< NULL terminate unit test array */ } From patchwork Fri Nov 3 09:53:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 133825 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D9ED143279; Fri, 3 Nov 2023 10:56:20 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1A34A40ED8; Fri, 3 Nov 2023 10:56:11 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 292F9402E8 for ; Fri, 3 Nov 2023 10:56:08 +0100 (CET) Received: from dggpeml100024.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SMGN32ZNlzvQbj; Fri, 3 Nov 2023 17:56:03 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml100024.china.huawei.com (7.185.36.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 3 Nov 2023 17:56:05 +0800 From: Chengwen Feng To: , CC: Subject: [PATCH 3/7] app/test: extract without keys testcase for kvargs Date: Fri, 3 Nov 2023 09:53:21 +0000 Message-ID: <20231103095325.47843-4-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231103095325.47843-1-fengchengwen@huawei.com> References: <20231103095325.47843-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml100024.china.huawei.com (7.185.36.115) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The test_valid_kvargs() function is too long to understand, extract the without keys tests as one stand-alone testcase. Signed-off-by: Chengwen Feng --- app/test/test_kvargs.c | 115 ++++++++++++++++++++++------------------- 1 file changed, 63 insertions(+), 52 deletions(-) diff --git a/app/test/test_kvargs.c b/app/test/test_kvargs.c index a27b2aabfb..7ab4becc0b 100644 --- a/app/test/test_kvargs.c +++ b/app/test/test_kvargs.c @@ -44,58 +44,6 @@ static int test_valid_kvargs(void) const char *valid_keys_list[] = { "foo", "check", NULL }; const char **valid_keys; - /* first test without valid_keys */ - args = "foo=1234,check=value0,check=value1"; - valid_keys = NULL; - kvlist = rte_kvargs_parse(args, valid_keys); - if (kvlist == NULL) { - printf("rte_kvargs_parse() error"); - goto fail; - } - /* call check_handler() for all entries with key="check" */ - count = 0; - if (rte_kvargs_process(kvlist, "check", check_handler, NULL) < 0) { - printf("rte_kvargs_process() error\n"); - rte_kvargs_free(kvlist); - goto fail; - } - if (count != 2) { - printf("invalid count value %d after rte_kvargs_process(check)\n", - count); - rte_kvargs_free(kvlist); - goto fail; - } - count = 0; - /* call check_handler() for all entries with key="nonexistent_key" */ - if (rte_kvargs_process(kvlist, "nonexistent_key", check_handler, NULL) < 0) { - printf("rte_kvargs_process() error\n"); - rte_kvargs_free(kvlist); - goto fail; - } - if (count != 0) { - printf("invalid count value %d after rte_kvargs_process(nonexistent_key)\n", - count); - rte_kvargs_free(kvlist); - goto fail; - } - /* count all entries with key="foo" */ - count = rte_kvargs_count(kvlist, "foo"); - if (count != 1) { - printf("invalid count value %d after rte_kvargs_count(foo)\n", - count); - rte_kvargs_free(kvlist); - goto fail; - } - /* count all entries with key="nonexistent_key" */ - count = rte_kvargs_count(kvlist, "nonexistent_key"); - if (count != 0) { - printf("invalid count value %d after rte_kvargs_count(nonexistent_key)\n", - count); - rte_kvargs_free(kvlist); - goto fail; - } - rte_kvargs_free(kvlist); - /* second test using valid_keys */ args = "foo=droids,check=value0,check=value1,check=wrong_value"; valid_keys = valid_keys_list; @@ -215,6 +163,68 @@ test_basic_token_count(void) return 0; } +static int +test_parse_without_valid_keys(void) +{ + const char *args = "foo=1234,check=value0,check=value1"; + struct rte_kvargs *kvlist; + + kvlist = rte_kvargs_parse(args, NULL); + if (kvlist == NULL) { + printf("rte_kvargs_parse() error\n"); + return -1; + } + + /* call check_handler() for all entries with key="check" */ + count = 0; + if (rte_kvargs_process(kvlist, "check", check_handler, NULL) < 0) { + printf("rte_kvargs_process(check) error\n"); + rte_kvargs_free(kvlist); + return -1; + } + if (count != 2) { + printf("invalid count value %u after rte_kvargs_process(check)\n", + count); + rte_kvargs_free(kvlist); + return -1; + } + + /* call check_handler() for all entries with key="nonexistent_key" */ + count = 0; + if (rte_kvargs_process(kvlist, "nonexistent_key", check_handler, NULL) < 0) { + printf("rte_kvargs_process(nonexistent_key) error\n"); + rte_kvargs_free(kvlist); + return -1; + } + if (count != 0) { + printf("invalid count value %d after rte_kvargs_process(nonexistent_key)\n", + count); + rte_kvargs_free(kvlist); + return -1; + } + + /* count all entries with key="foo" */ + count = rte_kvargs_count(kvlist, "foo"); + if (count != 1) { + printf("invalid count value %d after rte_kvargs_count(foo)\n", + count); + rte_kvargs_free(kvlist); + return -1; + } + + /* count all entries with key="nonexistent_key" */ + count = rte_kvargs_count(kvlist, "nonexistent_key"); + if (count != 0) { + printf("invalid count value %d after rte_kvargs_count(nonexistent_key)\n", + count); + rte_kvargs_free(kvlist); + return -1; + } + + rte_kvargs_free(kvlist); + return 0; +} + /* test several error cases */ static int test_invalid_kvargs(void) { @@ -257,6 +267,7 @@ static struct unit_test_suite kvargs_test_suite = { .unit_test_cases = { TEST_CASE(test_valid_kvargs), TEST_CASE(test_basic_token_count), + TEST_CASE(test_parse_without_valid_keys), TEST_CASE(test_invalid_kvargs), TEST_CASES_END() /**< NULL terminate unit test array */ } From patchwork Fri Nov 3 09:53:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 133828 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 220D143279; Fri, 3 Nov 2023 10:56:40 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 533B842D9F; Fri, 3 Nov 2023 10:56:14 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 84B1240A73 for ; Fri, 3 Nov 2023 10:56:09 +0100 (CET) Received: from dggpeml100024.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SMGN32q1jzvQbr; Fri, 3 Nov 2023 17:56:03 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml100024.china.huawei.com (7.185.36.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 3 Nov 2023 17:56:05 +0800 From: Chengwen Feng To: , CC: Subject: [PATCH 4/7] app/test: extract with keys testcase for kvargs Date: Fri, 3 Nov 2023 09:53:22 +0000 Message-ID: <20231103095325.47843-5-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231103095325.47843-1-fengchengwen@huawei.com> References: <20231103095325.47843-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml100024.china.huawei.com (7.185.36.115) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The test_valid_kvargs() function is too long to understand, extract the with keys tests as one stand-alone testcase. Signed-off-by: Chengwen Feng --- app/test/test_kvargs.c | 59 +++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/app/test/test_kvargs.c b/app/test/test_kvargs.c index 7ab4becc0b..28b93680f0 100644 --- a/app/test/test_kvargs.c +++ b/app/test/test_kvargs.c @@ -44,30 +44,6 @@ static int test_valid_kvargs(void) const char *valid_keys_list[] = { "foo", "check", NULL }; const char **valid_keys; - /* second test using valid_keys */ - args = "foo=droids,check=value0,check=value1,check=wrong_value"; - valid_keys = valid_keys_list; - kvlist = rte_kvargs_parse(args, valid_keys); - if (kvlist == NULL) { - printf("rte_kvargs_parse() error"); - goto fail; - } - /* call check_handler() on all entries with key="check", it - * should fail as the value is not recognized by the handler */ - if (rte_kvargs_process(kvlist, "check", check_handler, NULL) == 0) { - printf("rte_kvargs_process() is success but should not\n"); - rte_kvargs_free(kvlist); - goto fail; - } - count = rte_kvargs_count(kvlist, "check"); - if (count != 3) { - printf("invalid count value %d after rte_kvargs_count(check)\n", - count); - rte_kvargs_free(kvlist); - goto fail; - } - rte_kvargs_free(kvlist); - /* third test using list as value */ args = "foo=[0,1],check=value2"; valid_keys = valid_keys_list; @@ -225,6 +201,40 @@ test_parse_without_valid_keys(void) return 0; } +static int +test_parse_with_valid_keys(void) +{ + const char *args = "foo=droids,check=value0,check=value1,check=wrong_value"; + const char *valid_keys[] = { "foo", "check", NULL }; + struct rte_kvargs *kvlist; + + kvlist = rte_kvargs_parse(args, valid_keys); + if (kvlist == NULL) { + printf("rte_kvargs_parse() error\n"); + return -1; + } + + /* call check_handler() on all entries with key="check", it + * should fail as the value is not recognized by the handler + */ + if (rte_kvargs_process(kvlist, "check", check_handler, NULL) == 0) { + printf("rte_kvargs_process(check) is success but should not\n"); + rte_kvargs_free(kvlist); + return -1; + } + + count = rte_kvargs_count(kvlist, "check"); + if (count != 3) { + printf("invalid count value %u after rte_kvargs_count(check)\n", + count); + rte_kvargs_free(kvlist); + return -1; + } + + rte_kvargs_free(kvlist); + return 0; +} + /* test several error cases */ static int test_invalid_kvargs(void) { @@ -268,6 +278,7 @@ static struct unit_test_suite kvargs_test_suite = { TEST_CASE(test_valid_kvargs), TEST_CASE(test_basic_token_count), TEST_CASE(test_parse_without_valid_keys), + TEST_CASE(test_parse_with_valid_keys), TEST_CASE(test_invalid_kvargs), TEST_CASES_END() /**< NULL terminate unit test array */ } From patchwork Fri Nov 3 09:53:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 133824 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7A18543279; Fri, 3 Nov 2023 10:56:14 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 10D8840DDC; Fri, 3 Nov 2023 10:56:10 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 1A7F240284 for ; Fri, 3 Nov 2023 10:56:08 +0100 (CET) Received: from dggpeml100024.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SMGN332nPzvQcH; Fri, 3 Nov 2023 17:56:03 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml100024.china.huawei.com (7.185.36.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 3 Nov 2023 17:56:05 +0800 From: Chengwen Feng To: , CC: Subject: [PATCH 5/7] app/test: extract parse list value testcase for kvargs Date: Fri, 3 Nov 2023 09:53:23 +0000 Message-ID: <20231103095325.47843-6-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231103095325.47843-1-fengchengwen@huawei.com> References: <20231103095325.47843-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml100024.china.huawei.com (7.185.36.115) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Extract parse list value test as one stand-alone testcase. Signed-off-by: Chengwen Feng --- app/test/test_kvargs.c | 54 +++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/app/test/test_kvargs.c b/app/test/test_kvargs.c index 28b93680f0..f4257c176f 100644 --- a/app/test/test_kvargs.c +++ b/app/test/test_kvargs.c @@ -41,28 +41,7 @@ static int test_valid_kvargs(void) { struct rte_kvargs *kvlist; const char *args; - const char *valid_keys_list[] = { "foo", "check", NULL }; - const char **valid_keys; - - /* third test using list as value */ - args = "foo=[0,1],check=value2"; - valid_keys = valid_keys_list; - kvlist = rte_kvargs_parse(args, valid_keys); - if (kvlist == NULL) { - printf("rte_kvargs_parse() error\n"); - goto fail; - } - if (strcmp(kvlist->pairs[0].value, "[0,1]") != 0) { - printf("wrong value %s", kvlist->pairs[0].value); - goto fail; - } - count = kvlist->count; - if (count != 2) { - printf("invalid count value %d\n", count); - rte_kvargs_free(kvlist); - goto fail; - } - rte_kvargs_free(kvlist); + const char **valid_keys = NULL; /* test using empty elements (it is valid) */ args = "foo=1,,check=value2,,"; @@ -235,6 +214,36 @@ test_parse_with_valid_keys(void) return 0; } +static int +test_parse_list_value(void) +{ + const char *valid_keys[] = { "foo", "check", NULL }; + const char *args = "foo=[0,1],check=value2"; + struct rte_kvargs *kvlist; + + kvlist = rte_kvargs_parse(args, valid_keys); + if (kvlist == NULL) { + printf("rte_kvargs_parse() error\n"); + return -1; + } + + count = kvlist->count; + if (count != 2) { + printf("invalid count value %u\n", count); + rte_kvargs_free(kvlist); + return -1; + } + + if (strcmp(kvlist->pairs[0].value, "[0,1]") != 0) { + printf("wrong value %s", kvlist->pairs[0].value); + rte_kvargs_free(kvlist); + return -1; + } + + rte_kvargs_free(kvlist); + return 0; +} + /* test several error cases */ static int test_invalid_kvargs(void) { @@ -279,6 +288,7 @@ static struct unit_test_suite kvargs_test_suite = { TEST_CASE(test_basic_token_count), TEST_CASE(test_parse_without_valid_keys), TEST_CASE(test_parse_with_valid_keys), + TEST_CASE(test_parse_list_value), TEST_CASE(test_invalid_kvargs), TEST_CASES_END() /**< NULL terminate unit test array */ } From patchwork Fri Nov 3 09:53:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 133829 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 614EC43279; Fri, 3 Nov 2023 10:56:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7158D42DC0; Fri, 3 Nov 2023 10:56:15 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 69EA44067B for ; Fri, 3 Nov 2023 10:56:09 +0100 (CET) Received: from dggpeml100024.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SMGN33jdlzvQcN; Fri, 3 Nov 2023 17:56:03 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml100024.china.huawei.com (7.185.36.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 3 Nov 2023 17:56:05 +0800 From: Chengwen Feng To: , CC: Subject: [PATCH 6/7] app/test: extract parse empty elements testcase for kvargs Date: Fri, 3 Nov 2023 09:53:24 +0000 Message-ID: <20231103095325.47843-7-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231103095325.47843-1-fengchengwen@huawei.com> References: <20231103095325.47843-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml100024.china.huawei.com (7.185.36.115) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Extract parse empty elements test as one stand-alone testcase. And also fix the kvlist was not released when the branch fails. Signed-off-by: Chengwen Feng --- app/test/test_kvargs.c | 68 ++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/app/test/test_kvargs.c b/app/test/test_kvargs.c index f4257c176f..8cd84fcec0 100644 --- a/app/test/test_kvargs.c +++ b/app/test/test_kvargs.c @@ -36,44 +36,6 @@ static int check_handler(const char *key, const char *value, return 0; } -/* test a valid case */ -static int test_valid_kvargs(void) -{ - struct rte_kvargs *kvlist; - const char *args; - const char **valid_keys = NULL; - - /* test using empty elements (it is valid) */ - args = "foo=1,,check=value2,,"; - kvlist = rte_kvargs_parse(args, NULL); - if (kvlist == NULL) { - printf("rte_kvargs_parse() error\n"); - goto fail; - } - if (rte_kvargs_count(kvlist, "foo") != 1) { - printf("invalid count value for 'foo'\n"); - goto fail; - } - if (rte_kvargs_count(kvlist, "check") != 1) { - printf("invalid count value for 'check'\n"); - goto fail; - } - rte_kvargs_free(kvlist); - - return 0; - - fail: - printf("while processing <%s>", args); - if (valid_keys != NULL && *valid_keys != NULL) { - printf(" using valid_keys=<%s", *valid_keys); - while (*(++valid_keys) != NULL) - printf(",%s", *valid_keys); - printf(">"); - } - printf("\n"); - return -1; -} - static int test_basic_token_count(void) { @@ -244,6 +206,34 @@ test_parse_list_value(void) return 0; } +static int +test_parse_empty_elements(void) +{ + const char *args = "foo=1,,check=value2,,"; + struct rte_kvargs *kvlist; + + kvlist = rte_kvargs_parse(args, NULL); + if (kvlist == NULL) { + printf("rte_kvargs_parse() error\n"); + return -1; + } + + if (rte_kvargs_count(kvlist, "foo") != 1) { + printf("invalid count value for 'foo'\n"); + rte_kvargs_free(kvlist); + return -1; + } + + if (rte_kvargs_count(kvlist, "check") != 1) { + printf("invalid count value for 'check'\n"); + rte_kvargs_free(kvlist); + return -1; + } + + rte_kvargs_free(kvlist); + return 0; +} + /* test several error cases */ static int test_invalid_kvargs(void) { @@ -284,11 +274,11 @@ static struct unit_test_suite kvargs_test_suite = { .setup = NULL, .teardown = NULL, .unit_test_cases = { - TEST_CASE(test_valid_kvargs), TEST_CASE(test_basic_token_count), TEST_CASE(test_parse_without_valid_keys), TEST_CASE(test_parse_with_valid_keys), TEST_CASE(test_parse_list_value), + TEST_CASE(test_parse_empty_elements), TEST_CASE(test_invalid_kvargs), TEST_CASES_END() /**< NULL terminate unit test array */ } From patchwork Fri Nov 3 09:53:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: fengchengwen X-Patchwork-Id: 133830 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2F69343279; Fri, 3 Nov 2023 10:56:52 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8C5FB42DD4; Fri, 3 Nov 2023 10:56:16 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 809EF4067D for ; Fri, 3 Nov 2023 10:56:09 +0100 (CET) Received: from dggpeml100024.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SMGN33yH4zvQcP; Fri, 3 Nov 2023 17:56:03 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml100024.china.huawei.com (7.185.36.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 3 Nov 2023 17:56:05 +0800 From: Chengwen Feng To: , CC: Subject: [PATCH 7/7] maintainers: update for kvargs library Date: Fri, 3 Nov 2023 09:53:25 +0000 Message-ID: <20231103095325.47843-8-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231103095325.47843-1-fengchengwen@huawei.com> References: <20231103095325.47843-1-fengchengwen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml100024.china.huawei.com (7.185.36.115) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add myself for voluntary maintenance of the kvargs library. Signed-off-by: Chengwen Feng --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 4083658697..81f97a5e1e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1651,6 +1651,7 @@ F: examples/cmdline/ F: doc/guides/sample_app_ug/cmd_line.rst Key/Value parsing +M: Chengwen Feng F: lib/kvargs/ F: app/test/test_kvargs.c