From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8621B43922; Mon, 22 Jan 2024 05:03:08 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5E30D40A84; Mon, 22 Jan 2024 05:03:08 +0100 (CET) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by mails.dpdk.org (Postfix) with ESMTP id E5E0940A80 for ; Mon, 22 Jan 2024 05:03:05 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TJGjt3qsYz29kbd; Mon, 22 Jan 2024 12:01:22 +0800 (CST) Received: from dggpeml500024.china.huawei.com (unknown [7.185.36.10]) by mail.maildlp.com (Postfix) with ESMTPS id CE7F61A016C; Mon, 22 Jan 2024 12:02:49 +0800 (CST) Received: from localhost.localdomain (10.50.165.33) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 22 Jan 2024 12:01:50 +0800 From: Chengwen Feng To: , , , CC: Subject: [PATCH 10/12] test/argparse: add parse unsigned base type test Date: Mon, 22 Jan 2024 03:58:00 +0000 Message-ID: <20240122035802.31491-11-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240122035802.31491-1-fengchengwen@huawei.com> References: <20231121122651.7078-1-fengchengwen@huawei.com> <20240122035802.31491-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500024.china.huawei.com (7.185.36.10) 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 This commit adds parsing unsigned base type (u8/u16/u32/u64) test. Signed-off-by: Chengwen Feng --- app/test/test_argparse.c | 59 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/app/test/test_argparse.c b/app/test/test_argparse.c index 98c6cd6b80..470c1bd2b6 100644 --- a/app/test/test_argparse.c +++ b/app/test/test_argparse.c @@ -733,19 +733,68 @@ static int test_argparse_parse_type(void) { char *str_erange = test_strdup("9999999999999999999999999999999999"); + char *str_erange_u32 = test_strdup("4294967296"); + char *str_erange_u16 = test_strdup("65536"); + char *str_erange_u8 = test_strdup("256"); char *str_invalid = test_strdup("1a"); char *str_ok = test_strdup("123"); - int value; + uint16_t val_u16; + uint32_t val_u32; + uint64_t val_u64; + uint8_t val_u8; + int val_int; int ret; /* test for int parsing */ - ret = rte_argparse_parse_type(str_erange, RTE_ARGPARSE_ARG_VALUE_INT, &value); + ret = rte_argparse_parse_type(str_erange, RTE_ARGPARSE_ARG_VALUE_INT, &val_int); TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); - ret = rte_argparse_parse_type(str_invalid, RTE_ARGPARSE_ARG_VALUE_INT, &value); + ret = rte_argparse_parse_type(str_invalid, RTE_ARGPARSE_ARG_VALUE_INT, &val_int); TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); - ret = rte_argparse_parse_type(str_ok, RTE_ARGPARSE_ARG_VALUE_INT, &value); + ret = rte_argparse_parse_type(str_ok, RTE_ARGPARSE_ARG_VALUE_INT, &val_int); TEST_ASSERT(ret == 0, "Argparse parse type expect failed!"); - TEST_ASSERT(value == 123, "Argparse parse type expect failed!"); + TEST_ASSERT(val_int == 123, "Argparse parse type expect failed!"); + + /* test for u8 parsing */ + ret = rte_argparse_parse_type(str_erange, RTE_ARGPARSE_ARG_VALUE_U8, &val_u8); + TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); + ret = rte_argparse_parse_type(str_erange_u8, RTE_ARGPARSE_ARG_VALUE_U8, &val_u8); + TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); + ret = rte_argparse_parse_type(str_invalid, RTE_ARGPARSE_ARG_VALUE_U8, &val_u8); + TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); + ret = rte_argparse_parse_type(str_ok, RTE_ARGPARSE_ARG_VALUE_U8, &val_u8); + TEST_ASSERT(ret == 0, "Argparse parse type expect failed!"); + TEST_ASSERT(val_u8 == 123, "Argparse parse type expect failed!"); + + /* test for u16 parsing */ + ret = rte_argparse_parse_type(str_erange, RTE_ARGPARSE_ARG_VALUE_U16, &val_u16); + TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); + ret = rte_argparse_parse_type(str_erange_u16, RTE_ARGPARSE_ARG_VALUE_U16, &val_u16); + TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); + ret = rte_argparse_parse_type(str_invalid, RTE_ARGPARSE_ARG_VALUE_U16, &val_u16); + TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); + ret = rte_argparse_parse_type(str_ok, RTE_ARGPARSE_ARG_VALUE_U16, &val_u16); + TEST_ASSERT(ret == 0, "Argparse parse type expect failed!"); + TEST_ASSERT(val_u16 == 123, "Argparse parse type expect failed!"); + + /* test for u32 parsing */ + ret = rte_argparse_parse_type(str_erange, RTE_ARGPARSE_ARG_VALUE_U32, &val_u32); + TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); + ret = rte_argparse_parse_type(str_erange_u32, RTE_ARGPARSE_ARG_VALUE_U32, &val_u32); + TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); + ret = rte_argparse_parse_type(str_invalid, RTE_ARGPARSE_ARG_VALUE_U32, &val_u32); + TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); + ret = rte_argparse_parse_type(str_ok, RTE_ARGPARSE_ARG_VALUE_U32, &val_u32); + TEST_ASSERT(ret == 0, "Argparse parse type expect failed!"); + TEST_ASSERT(val_u32 == 123, "Argparse parse type expect failed!"); + + /* test for u64 parsing */ + ret = rte_argparse_parse_type(str_erange, RTE_ARGPARSE_ARG_VALUE_U64, &val_u64); + TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); + ret = rte_argparse_parse_type(str_invalid, RTE_ARGPARSE_ARG_VALUE_U64, &val_u64); + TEST_ASSERT(ret != 0, "Argparse parse type expect failed!"); + ret = rte_argparse_parse_type(str_ok, RTE_ARGPARSE_ARG_VALUE_U64, &val_u64); + TEST_ASSERT(ret == 0, "Argparse parse type expect failed!"); + TEST_ASSERT(val_u64 == 123, "Argparse parse type expect failed!"); return 0; } -- 2.17.1