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 483D2A0540; Mon, 12 Dec 2022 07:43:32 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 427B942D37; Mon, 12 Dec 2022 07:43: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 7E96740A84 for ; Mon, 12 Dec 2022 07:43:05 +0100 (CET) Received: from kwepemm600004.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NVsQv4YC0zqT39; Mon, 12 Dec 2022 14:38:47 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 12 Dec 2022 14:43:02 +0800 From: Huisong Li To: CC: , , , , , , Subject: [PATCH V3 03/11] test: add test cases for adding u32 value API Date: Mon, 12 Dec 2022 14:42:58 +0800 Message-ID: <20221212064306.39232-4-lihuisong@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20221212064306.39232-1-lihuisong@huawei.com> References: <20221208080540.62913-1-lihuisong@huawei.com> <20221212064306.39232-1-lihuisong@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600004.china.huawei.com (7.193.23.242) 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 test cases for adding u32 value API. Cc: stable@dpdk.org Signed-off-by: Huisong Li Acked-by: Morten Brørup Acked-by: Chengwen Feng --- app/test/test_telemetry_data.c | 85 +++++++++++++++++++++++++++++++++- app/test/test_telemetry_json.c | 23 ++++++++- 2 files changed, 104 insertions(+), 4 deletions(-) diff --git a/app/test/test_telemetry_data.c b/app/test/test_telemetry_data.c index d92667a527..8ab3441cbe 100644 --- a/app/test/test_telemetry_data.c +++ b/app/test/test_telemetry_data.c @@ -278,6 +278,17 @@ test_array_with_array_string_values(void) return CHECK_OUTPUT("[[\"aaaa\"],[\"bbbb\"]]"); } +static int +test_case_array_u32(void) +{ + uint32_t i; + + rte_tel_data_start_array(&response_data, RTE_TEL_U32_VAL); + for (i = 0; i < 5; i++) + rte_tel_data_add_array_u32(&response_data, i); + return CHECK_OUTPUT("[0,1,2,3,4]"); +} + static int test_case_array_u64(void) { @@ -289,6 +300,21 @@ test_case_array_u64(void) return CHECK_OUTPUT("[0,1,2,3,4]"); } +static int +test_case_add_dict_u32(void) +{ + uint32_t i = 0; + char name_of_value[8]; + + rte_tel_data_start_dict(&response_data); + + for (i = 0; i < 5; i++) { + sprintf(name_of_value, "dict_%u", i); + rte_tel_data_add_dict_u32(&response_data, name_of_value, i); + } + return CHECK_OUTPUT("{\"dict_0\":0,\"dict_1\":1,\"dict_2\":2,\"dict_3\":3,\"dict_4\":4}"); +} + static int test_case_add_dict_u64(void) { @@ -304,6 +330,32 @@ test_case_add_dict_u64(void) return CHECK_OUTPUT("{\"dict_0\":0,\"dict_1\":1,\"dict_2\":2,\"dict_3\":3,\"dict_4\":4}"); } +static int +test_dict_with_array_u32_values(void) +{ + uint32_t i; + + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_U32_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_U32_VAL); + + rte_tel_data_start_dict(&response_data); + + for (i = 0; i < 10; i++) { + rte_tel_data_add_array_u32(child_data, i); + rte_tel_data_add_array_u32(child_data2, i); + } + + rte_tel_data_add_dict_container(&response_data, "dict_0", + child_data, 0); + rte_tel_data_add_dict_container(&response_data, "dict_1", + child_data2, 0); + + return CHECK_OUTPUT("{\"dict_0\":[0,1,2,3,4,5,6,7,8,9],\"dict_1\":[0,1,2,3,4,5,6,7,8,9]}"); +} + static int test_dict_with_array_u64_values(void) { @@ -330,6 +382,29 @@ test_dict_with_array_u64_values(void) return CHECK_OUTPUT("{\"dict_0\":[0,1,2,3,4,5,6,7,8,9],\"dict_1\":[0,1,2,3,4,5,6,7,8,9]}"); } +static int +test_array_with_array_u32_values(void) +{ + uint32_t i; + + struct rte_tel_data *child_data = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data, RTE_TEL_U32_VAL); + + struct rte_tel_data *child_data2 = rte_tel_data_alloc(); + rte_tel_data_start_array(child_data2, RTE_TEL_U32_VAL); + + rte_tel_data_start_array(&response_data, RTE_TEL_CONTAINER); + + for (i = 0; i < 5; i++) { + rte_tel_data_add_array_u32(child_data, i); + rte_tel_data_add_array_u32(child_data2, i); + } + rte_tel_data_add_array_container(&response_data, child_data, 0); + rte_tel_data_add_array_container(&response_data, child_data2, 0); + + return CHECK_OUTPUT("[[0,1,2,3,4],[0,1,2,3,4]]"); +} + static int test_array_with_array_u64_values(void) { @@ -428,14 +503,20 @@ telemetry_data_autotest(void) test_null_return, test_simple_string, test_case_array_string, - test_case_array_int, test_case_array_u64, - test_case_add_dict_int, test_case_add_dict_u64, + test_case_array_int, + test_case_array_u32, + test_case_array_u64, + test_case_add_dict_int, + test_case_add_dict_u32, + test_case_add_dict_u64, test_case_add_dict_string, test_dict_with_array_int_values, + test_dict_with_array_u32_values, test_dict_with_array_u64_values, test_dict_with_array_string_values, test_dict_with_dict_values, test_array_with_array_int_values, + test_array_with_array_u32_values, test_array_with_array_u64_values, test_array_with_array_string_values, test_string_char_escaping, diff --git a/app/test/test_telemetry_json.c b/app/test/test_telemetry_json.c index 184c3ba9f1..e25442f8f0 100644 --- a/app/test/test_telemetry_json.c +++ b/app/test/test_telemetry_json.c @@ -31,7 +31,25 @@ test_basic_array(void) } static int -test_basic_obj(void) +test_basic_obj_u32(void) +{ + const char *expected = "{\"weddings\":4,\"funerals\":1}"; + char buf[1024]; + int used = 0; + + used = rte_tel_json_add_obj_u32(buf, sizeof(buf), used, + "weddings", 4); + used = rte_tel_json_add_obj_u32(buf, sizeof(buf), used, + "funerals", 1); + + printf("%s: buf = '%s', expected = '%s'\n", __func__, buf, expected); + if (used != (int)strlen(expected)) + return -1; + return strncmp(expected, buf, sizeof(buf)); +} + +static int +test_basic_obj_u64(void) { const char *expected = "{\"weddings\":4,\"funerals\":1}"; char buf[1024]; @@ -195,7 +213,8 @@ test_telemetry_json(void) unsigned int i; test_fn fns[] = { test_basic_array, - test_basic_obj, + test_basic_obj_u32, + test_basic_obj_u64, test_overflow_array, test_overflow_obj, test_large_array_element, -- 2.33.0